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)" /> <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Remove="ViewModel\PublishDateVM.cs" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="5.3.0" /> <PackageReference Include="CommunityToolkit.Maui" Version="5.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />

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

@ -35,13 +35,16 @@
<VerticalStackLayout Grid.Row="2"> <VerticalStackLayout Grid.Row="2">
<contentView:SeparatorEntireView/> <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> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:AuthorVM"> <DataTemplate x:DataType="viewModel:AuthorVM">
<VerticalStackLayout> <VerticalStackLayout>
<contentView:HomeButtonView ButtonTitle="{Binding Name}" <contentView:HomeButtonView ButtonTitle="{Binding Name}"
ButtonIcon="book.png" ButtonIcon="book.png"
ButtonNumber="2" ButtonNumber="{Binding NbBooksWritten}"
ButtonRedIconVisible="True" ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/> ButtonBlackIconVisible="False"/>
<contentView:SeparatorBigCutStartView/> <contentView:SeparatorBigCutStartView/>

@ -4,6 +4,7 @@
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:view="clr-namespace:LivreLand.View" xmlns:view="clr-namespace:LivreLand.View"
xmlns:contentView="clr-namespace:LivreLand.View.ContentViews" xmlns:contentView="clr-namespace:LivreLand.View.ContentViews"
xmlns:viewModel="clr-namespace:ViewModels;assembly=ViewModels"
x:Class="LivreLand.View.FiltrageDateView" x:Class="LivreLand.View.FiltrageDateView"
Title="FiltrageDateView"> Title="FiltrageDateView">
@ -33,105 +34,23 @@
<VerticalStackLayout Grid.Row="2"> <VerticalStackLayout Grid.Row="2">
<contentView:SeparatorEntireView/> <contentView:SeparatorEntireView/>
<!--2022--> <CollectionView ItemsSource="{Binding FiltrageDateVM.Manager.AllPublishDates}"
<contentView:HomeButtonView ButtonTitle="2022" 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" ButtonIcon="book.png"
ButtonNumber="1" ButtonNumber="1"
ButtonRedIconVisible="True" ButtonRedIconVisible="True"
ButtonBlackIconVisible="False"/> 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/> <contentView:SeparatorBigCutStartView/>
</VerticalStackLayout> </VerticalStackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ScrollView> </ScrollView>
</Grid> </Grid>

@ -1,9 +1,34 @@
using LivreLand.ViewModel;
namespace LivreLand.View; namespace LivreLand.View;
public partial class FiltrageDateView : ContentPage public partial class FiltrageDateView : ContentPage
{ {
public FiltrageDateView() #region Properties
public FiltrageDateVM FiltrageDateVM { get; set; }
#endregion
#region Constructor
public FiltrageDateView(FiltrageDateVM filtrageDateVM)
{ {
FiltrageDateVM = filtrageDateVM;
InitializeComponent(); 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 #region Fields
private int nbBooksWritten { get; set; }
#endregion #endregion
#region Properties #region Properties
@ -26,6 +28,15 @@ namespace ViewModels
} }
} }
public int NbBooksWritten
{
get => nbBooksWritten;
set
{
nbBooksWritten = value;
}
}
#endregion #endregion
#region Constructor #region Constructor

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