ADD : number books/author + filter by date

commands-19-09
Lou BRODA 1 year ago
parent cfe11f537b
commit ad5d0b50df

@ -48,6 +48,10 @@
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<Compile Remove="ViewModel\PublishDateVM.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="5.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />

@ -26,6 +26,7 @@ public static class MauiProgram
.AddSingleton<BibliothequeView>()
.AddSingleton<TousView>()
.AddSingleton<FiltrageAuteurView>()
.AddSingleton<FiltrageDateView>()
.AddSingleton<NavigatorVM>()
@ -36,7 +37,8 @@ public static class MauiProgram
.AddSingleton<ManagerVM>()
.AddSingleton<TousVM>()
.AddSingleton<FiltrageAuteurVM>();
.AddSingleton<FiltrageAuteurVM>()
.AddSingleton<FiltrageDateVM>();
#if DEBUG
builder.Logging.AddDebug();

@ -35,13 +35,16 @@
<VerticalStackLayout Grid.Row="2">
<contentView:SeparatorEntireView/>
<CollectionView ItemsSource="{Binding FiltrageAuteurVM.Manager.AllAuthors}">
<CollectionView ItemsSource="{Binding FiltrageAuteurVM.Manager.AllAuthors}"
SelectedItem="{Binding FiltrageAuteurVM.Manager.SelectedAuthor}"
SelectionChangedCommand="{Binding FiltrageAuteurVM.Navigator.NavigationCommand}"
SelectionChangedCommandParameter="/tous">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:AuthorVM">
<VerticalStackLayout>
<contentView:HomeButtonView ButtonTitle="{Binding Name}"
ButtonIcon="book.png"
ButtonNumber="2"
ButtonNumber="{Binding NbBooksWritten}"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>

@ -4,6 +4,7 @@
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:view="clr-namespace:LivreLand.View"
xmlns:contentView="clr-namespace:LivreLand.View.ContentViews"
xmlns:viewModel="clr-namespace:ViewModels;assembly=ViewModels"
x:Class="LivreLand.View.FiltrageDateView"
Title="FiltrageDateView">
@ -33,105 +34,23 @@
<VerticalStackLayout Grid.Row="2">
<contentView:SeparatorEntireView/>
<!--2022-->
<contentView:HomeButtonView ButtonTitle="2022"
<CollectionView ItemsSource="{Binding FiltrageDateVM.Manager.AllPublishDates}"
SelectionChangedCommand="{Binding FiltrageDateVM.Navigator.NavigationCommand}"
SelectionChangedCommandParameter="/tous">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:PublishDateVM">
<VerticalStackLayout>
<contentView:HomeButtonView ButtonTitle="{Binding PublishDate, StringFormat='{}{0:yyyy}'}"
ButtonIcon="book.png"
ButtonNumber="1"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--2021-->
<contentView:HomeButtonView ButtonTitle="2021"
ButtonIcon="book.png"
ButtonNumber="6"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--2020-->
<contentView:HomeButtonView ButtonTitle="2020"
ButtonIcon="book.png"
ButtonNumber="6"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--2019-->
<contentView:HomeButtonView ButtonTitle="2019"
ButtonIcon="book.png"
ButtonNumber="3"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--2018-->
<contentView:HomeButtonView ButtonTitle="2018"
ButtonIcon="book.png"
ButtonNumber="2"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--2016-->
<contentView:HomeButtonView ButtonTitle="2016"
ButtonIcon="book.png"
ButtonNumber="4"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--2015-->
<contentView:HomeButtonView ButtonTitle="2015"
ButtonIcon="book.png"
ButtonNumber="4"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--2012-->
<contentView:HomeButtonView ButtonTitle="2012"
ButtonIcon="book.png"
ButtonNumber="1"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--2010-->
<contentView:HomeButtonView ButtonTitle="2010"
ButtonIcon="book.png"
ButtonNumber="1"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--2004-->
<contentView:HomeButtonView ButtonTitle="2004"
ButtonIcon="book.png"
ButtonNumber="1"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
<!--1997-->
<contentView:HomeButtonView ButtonTitle="1997"
ButtonIcon="book.png"
ButtonNumber="1"
ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/>
</VerticalStackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ScrollView>
</Grid>

@ -1,9 +1,34 @@
using LivreLand.ViewModel;
namespace LivreLand.View;
public partial class FiltrageDateView : ContentPage
{
public FiltrageDateView()
#region Properties
public FiltrageDateVM FiltrageDateVM { get; set; }
#endregion
#region Constructor
public FiltrageDateView(FiltrageDateVM filtrageDateVM)
{
FiltrageDateVM = filtrageDateVM;
InitializeComponent();
BindingContext = this;
}
#endregion
#region Methods
protected override void OnAppearing()
{
base.OnAppearing();
FiltrageDateVM.Manager.GetAllPublishDatesCommand.Execute(null);
}
#endregion
}

@ -0,0 +1,31 @@
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ViewModels;
namespace LivreLand.ViewModel
{
public class FiltrageDateVM : BaseViewModel
{
#region Properties
public NavigatorVM Navigator { get; private set; }
public ManagerVM Manager { get; private set; }
#endregion
#region Constructor
public FiltrageDateVM(NavigatorVM navigatorVM, ManagerVM managerVM)
{
Navigator = navigatorVM;
Manager = managerVM;
}
#endregion
}
}

@ -0,0 +1,29 @@
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LivreLand.ViewModel
{
public class PublishDateVM : BaseViewModel
{
#region Properties
public DateTime PublishDate { get; set; }
public int NbBooksWritten { get; set; }
#endregion
#region Constructor
public PublishDateVM()
{
}
#endregion
}
}

@ -13,6 +13,8 @@ namespace ViewModels
#region Fields
private int nbBooksWritten { get; set; }
#endregion
#region Properties
@ -26,6 +28,15 @@ namespace ViewModels
}
}
public int NbBooksWritten
{
get => nbBooksWritten;
set
{
nbBooksWritten = value;
}
}
#endregion
#region Constructor

@ -12,6 +12,7 @@ namespace ViewModels
private readonly ObservableCollection<BookVM> books = new ObservableCollection<BookVM>();
private readonly ObservableCollection<AuthorVM> authors = new ObservableCollection<AuthorVM>();
private readonly ObservableCollection<PublishDateVM> publishDates = new ObservableCollection<PublishDateVM>();
private int index;
private long nbBooks;
@ -29,6 +30,13 @@ namespace ViewModels
get => authors;
}
public ObservableCollection<PublishDateVM> AllPublishDates
{
get => publishDates;
}
public AuthorVM SelectedAuthor { get; private set; }
public string SearchTitle { get; private set; }
public int Index
@ -58,8 +66,12 @@ namespace ViewModels
public ICommand GetBooksFromCollectionCommand { get; private set; }
public ICommand GetBooksByAuthorCommand { get; private set; }
public ICommand GetAllAuthorsCommand { get; private set; }
public ICommand GetAllPublishDatesCommand { get; private set; }
#endregion
#region Constructor
@ -69,7 +81,9 @@ namespace ViewModels
PreviousCommand = new RelayCommand(() => Previous());
NextCommand = new RelayCommand(() => Next());
GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection());
GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor());
GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors());
GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates());
//GetBooksByTitleCommand = new RelayCommand(() => AllBooks = model.GetBooksByTitle(SearchTitle, Index, Count).Result.books.Select(book => new BookVM(book)));
}
@ -110,6 +124,19 @@ namespace ViewModels
OnPropertyChanged(nameof(AllBooks));
}
private async Task GetBooksByAuthor()
{
var result = await Model.GetBooksByAuthor(SelectedAuthor.Name, Index, Count);
NbBooks = result.count;
IEnumerable<Book> someBooks = result.books;
books.Clear();
foreach (var b in someBooks.Select(b => new BookVM(b)))
{
books.Add(b);
}
OnPropertyChanged(nameof(AllBooks));
}
private async Task GetAllAuthors()
{
var result = await Model.GetBooksFromCollection(0, 20);
@ -121,11 +148,25 @@ namespace ViewModels
foreach (var a in b.Authors)
{
authors.Add(a);
a.NbBooksWritten++;
}
}
OnPropertyChanged(nameof(AllAuthors));
}
private async Task GetAllPublishDates()
{
var result = await Model.GetBooksFromCollection(0, 20);
IEnumerable<Book> someBooks = result.books;
books.Clear();
publishDates.Clear();
foreach (var b in someBooks.Select(b => new BookVM(b)))
{
var date = new PublishDateVM { PublishDate = b.PublishDate };
publishDates.Add(date);
}
OnPropertyChanged(nameof(AllPublishDates));
}
#endregion
}
}

@ -0,0 +1,29 @@
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewModels
{
public class PublishDateVM : BaseViewModel
{
#region Properties
public DateTime PublishDate { get; set; }
public int NbBooksWritten { get; set; }
#endregion
#region Constructor
public PublishDateVM()
{
}
#endregion
}
}
Loading…
Cancel
Save