From 90e4ffdcb00017fc3dc0131136fb0d5f63a7fccb Mon Sep 17 00:00:00 2001 From: luevard Date: Sun, 22 Oct 2023 11:28:49 +0200 Subject: [PATCH] =?UTF-8?q?:sparkles:=20d=C3=A9but=20de=20gestion=20des=20?= =?UTF-8?q?filtres?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/PocketBook/AppShell.xaml.cs | 4 +- sources/PocketBook/Applicative_VM/FilterVM.cs | 49 +++++++++++++++ .../PocketBook/Applicative_VM/LaterPageVM.cs | 6 +- .../PocketBook/Applicative_VM/NavigatorVM.cs | 9 ++- .../PocketBook/Applicative_VM/ScanMenuVM.cs | 4 +- .../PocketBook/Applicative_VM/TousPageVM.cs | 6 +- sources/PocketBook/MauiProgram.cs | 7 +-- sources/PocketBook/Pages/Auteur.xaml | 58 ----------------- sources/PocketBook/Pages/Auteur.xaml.cs | 15 ----- sources/PocketBook/Pages/DatePublic.xaml | 63 ------------------- sources/PocketBook/Pages/DatePublic.xaml.cs | 15 ----- sources/PocketBook/Pages/Filter.xaml | 38 +++++++++++ sources/PocketBook/Pages/Filter.xaml.cs | 18 ++++++ sources/PocketBook/Pages/MainPage.xaml | 6 +- sources/PocketBook/Pages/MarkPage.xaml | 44 ------------- sources/PocketBook/Pages/MarkPage.xaml.cs | 15 ----- sources/PocketBook/Pages/TousPage.xaml | 4 +- sources/PocketBook/PocketBook.csproj | 11 ++-- sources/ViewModel/BookVM.cs | 6 ++ sources/ViewModel/ManagerVM.cs | 34 +++++++--- 20 files changed, 165 insertions(+), 247 deletions(-) create mode 100644 sources/PocketBook/Applicative_VM/FilterVM.cs delete mode 100644 sources/PocketBook/Pages/Auteur.xaml delete mode 100644 sources/PocketBook/Pages/Auteur.xaml.cs delete mode 100644 sources/PocketBook/Pages/DatePublic.xaml delete mode 100644 sources/PocketBook/Pages/DatePublic.xaml.cs create mode 100644 sources/PocketBook/Pages/Filter.xaml create mode 100644 sources/PocketBook/Pages/Filter.xaml.cs delete mode 100644 sources/PocketBook/Pages/MarkPage.xaml delete mode 100644 sources/PocketBook/Pages/MarkPage.xaml.cs diff --git a/sources/PocketBook/AppShell.xaml.cs b/sources/PocketBook/AppShell.xaml.cs index 5857bce..689ee14 100644 --- a/sources/PocketBook/AppShell.xaml.cs +++ b/sources/PocketBook/AppShell.xaml.cs @@ -9,9 +9,7 @@ public partial class AppShell : Shell Routing.RegisterRoute("SharePage", typeof(SharePage)); Routing.RegisterRoute("LaterPage", typeof(LaterPage)); Routing.RegisterRoute("LikePage", typeof(LikePage)); - Routing.RegisterRoute("Auteur", typeof(SharePage)); - Routing.RegisterRoute("DatePublic", typeof(DatePublic)); - Routing.RegisterRoute("MarkPage", typeof(MarkPage)); + Routing.RegisterRoute("Filter", typeof(Filter)); Routing.RegisterRoute("BookDetail", typeof(BookDetail)); InitializeComponent(); } diff --git a/sources/PocketBook/Applicative_VM/FilterVM.cs b/sources/PocketBook/Applicative_VM/FilterVM.cs new file mode 100644 index 0000000..c963dbb --- /dev/null +++ b/sources/PocketBook/Applicative_VM/FilterVM.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; +using ViewModel; + +namespace PocketBook.Applicative_VM +{ + public class FilterVM + { + public ICommand AuthorCommand { get; private set; } + public ICommand MarkCommand { get; private set; } + public ICommand YearCommand { get; private set; } + public ICommand FilterCommand { get; private set; } + + public ManagerVM Manager { get; private set; } + public FilterVM(ManagerVM manager) + { + Manager = manager; + + FilterCommand = new Command(option => + { + switch (option) + { + case "Author": + AuthorCommand.Execute(null); + break; + case "Mark": + MarkCommand.Execute(null); + break; + case "Year": + YearCommand.Execute(null); + break; + } + }); + AuthorCommand = new Command(() => + { + }); + YearCommand = new Command( async () => + { + await Manager.GetDatesFromCollection(); + }); + } + + + } +} diff --git a/sources/PocketBook/Applicative_VM/LaterPageVM.cs b/sources/PocketBook/Applicative_VM/LaterPageVM.cs index 218883f..c919e03 100644 --- a/sources/PocketBook/Applicative_VM/LaterPageVM.cs +++ b/sources/PocketBook/Applicative_VM/LaterPageVM.cs @@ -9,14 +9,14 @@ namespace PocketBook.Applicative_VM { public ICommand NavigateDetailPage { get; private set; } public NavigatorVM NavigateCommandBooks { get; private set; } - public ScanMenuVM ScanMenuVM { get; private set; } + public ButtonsVM ButtonsVM { get; private set; } public ManagerVM Manager { get; private set; } public PaginationVM PaginationVM { get; private set; } - public LaterPageVM(NavigatorVM navigation, ManagerVM manager, ScanMenuVM scanMenuVM, PaginationVM paginationVM) + public LaterPageVM(NavigatorVM navigation, ManagerVM manager, ButtonsVM buttonsVM, PaginationVM paginationVM) { - ScanMenuVM = scanMenuVM; + ButtonsVM = buttonsVM; Manager = manager; PaginationVM = paginationVM; NavigateCommandBooks = navigation; diff --git a/sources/PocketBook/Applicative_VM/NavigatorVM.cs b/sources/PocketBook/Applicative_VM/NavigatorVM.cs index 886d98c..05b94a1 100644 --- a/sources/PocketBook/Applicative_VM/NavigatorVM.cs +++ b/sources/PocketBook/Applicative_VM/NavigatorVM.cs @@ -9,12 +9,19 @@ namespace PocketBook.Applicative_VM public class NavigatorVM { public ICommand Navigateto { get; private set; } + public ICommand NavigatetoFilter { get; private set; } + public FilterVM FilterVM { get; private set; } - public NavigatorVM() + public NavigatorVM(FilterVM filterVM) { + FilterVM = filterVM; Navigateto = new Command(execute:async page => { await Shell.Current.GoToAsync(page); }); + NavigatetoFilter = new Command(execute: async filtertype => { + FilterVM.FilterCommand.Execute(filtertype); + await Shell.Current.GoToAsync("Filter"); + }); } } } diff --git a/sources/PocketBook/Applicative_VM/ScanMenuVM.cs b/sources/PocketBook/Applicative_VM/ScanMenuVM.cs index 9a1c954..262deb7 100644 --- a/sources/PocketBook/Applicative_VM/ScanMenuVM.cs +++ b/sources/PocketBook/Applicative_VM/ScanMenuVM.cs @@ -8,7 +8,7 @@ using ViewModel; namespace PocketBook.Applicative_VM { - public class ScanMenuVM : BaseViewModel + public class ButtonsVM : BaseViewModel { public ICommand ShowScanMenu { get; private set; } public ICommand ModalISBN { get; private set; } @@ -22,7 +22,7 @@ namespace PocketBook.Applicative_VM set => SetProperty(ref scanMenuIsVisible,value); } - public ScanMenuVM(ManagerVM manager) + public ButtonsVM(ManagerVM manager) { Manager = manager; ShowScanMenu = new Command(() => diff --git a/sources/PocketBook/Applicative_VM/TousPageVM.cs b/sources/PocketBook/Applicative_VM/TousPageVM.cs index 613e419..5fb947f 100644 --- a/sources/PocketBook/Applicative_VM/TousPageVM.cs +++ b/sources/PocketBook/Applicative_VM/TousPageVM.cs @@ -10,14 +10,14 @@ namespace PocketBook.Applicative_VM { public ICommand NavigateDetailPage { get; private set; } public NavigatorVM NavigateCommandBooks { get; private set; } - public ScanMenuVM ScanMenuVM { get; private set; } + public ButtonsVM ButtonsVM { get; private set; } public ManagerVM Manager { get; private set; } public PaginationVM PaginationVM { get; private set; } - public TousPageVM(NavigatorVM navigation,ManagerVM manager, ScanMenuVM scanMenuVM, PaginationVM paginationVM) + public TousPageVM(NavigatorVM navigation,ManagerVM manager, ButtonsVM buttonsVM, PaginationVM paginationVM) { - ScanMenuVM = scanMenuVM; + ButtonsVM = buttonsVM; Manager = manager; PaginationVM = paginationVM; Manager.LoadBooksFromManager(); diff --git a/sources/PocketBook/MauiProgram.cs b/sources/PocketBook/MauiProgram.cs index defb278..956f661 100644 --- a/sources/PocketBook/MauiProgram.cs +++ b/sources/PocketBook/MauiProgram.cs @@ -45,7 +45,7 @@ public static class MauiProgram .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -53,14 +53,13 @@ public static class MauiProgram .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() + .AddSingleton() ; #if DEBUG builder.Logging.AddDebug(); diff --git a/sources/PocketBook/Pages/Auteur.xaml b/sources/PocketBook/Pages/Auteur.xaml deleted file mode 100644 index 9ec3630..0000000 --- a/sources/PocketBook/Pages/Auteur.xaml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sources/PocketBook/Pages/Auteur.xaml.cs b/sources/PocketBook/Pages/Auteur.xaml.cs deleted file mode 100644 index 7dda99e..0000000 --- a/sources/PocketBook/Pages/Auteur.xaml.cs +++ /dev/null @@ -1,15 +0,0 @@ -using PocketBook.Applicative_VM; - -namespace PocketBook; - -public partial class Auteur : ContentPage -{ - public NavigatorVM NavigateCommandBooks { get; private set; } - - public Auteur(NavigatorVM navigator) - { - NavigateCommandBooks = navigator; - InitializeComponent(); - } - -} \ No newline at end of file diff --git a/sources/PocketBook/Pages/DatePublic.xaml b/sources/PocketBook/Pages/DatePublic.xaml deleted file mode 100644 index 847aa47..0000000 --- a/sources/PocketBook/Pages/DatePublic.xaml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sources/PocketBook/Pages/DatePublic.xaml.cs b/sources/PocketBook/Pages/DatePublic.xaml.cs deleted file mode 100644 index e2e392f..0000000 --- a/sources/PocketBook/Pages/DatePublic.xaml.cs +++ /dev/null @@ -1,15 +0,0 @@ -using PocketBook.Applicative_VM; - -namespace PocketBook; - -public partial class DatePublic : ContentPage -{ - public NavigatorVM NavigateCommandBooks { get; private set; } - - public DatePublic(NavigatorVM navigator) - { - NavigateCommandBooks = navigator; - InitializeComponent(); - } - -} diff --git a/sources/PocketBook/Pages/Filter.xaml b/sources/PocketBook/Pages/Filter.xaml new file mode 100644 index 0000000..377e969 --- /dev/null +++ b/sources/PocketBook/Pages/Filter.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sources/PocketBook/Pages/Filter.xaml.cs b/sources/PocketBook/Pages/Filter.xaml.cs new file mode 100644 index 0000000..1349ad8 --- /dev/null +++ b/sources/PocketBook/Pages/Filter.xaml.cs @@ -0,0 +1,18 @@ +using PocketBook.Applicative_VM; +using ViewModel; + +namespace PocketBook; + +public partial class Filter : ContentPage +{ + public NavigatorVM NavigateCommandBooks { get; private set; } + public FilterVM FilterVM { get; private set; } + public Filter(NavigatorVM navigator, FilterVM filterVM) + { + FilterVM=filterVM; + NavigateCommandBooks = navigator; + InitializeComponent(); + BindingContext = this; + } + +} \ No newline at end of file diff --git a/sources/PocketBook/Pages/MainPage.xaml b/sources/PocketBook/Pages/MainPage.xaml index 9a8f232..5055222 100644 --- a/sources/PocketBook/Pages/MainPage.xaml +++ b/sources/PocketBook/Pages/MainPage.xaml @@ -59,14 +59,14 @@ - - - diff --git a/sources/PocketBook/Pages/MarkPage.xaml b/sources/PocketBook/Pages/MarkPage.xaml deleted file mode 100644 index bf9254f..0000000 --- a/sources/PocketBook/Pages/MarkPage.xaml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sources/PocketBook/Pages/MarkPage.xaml.cs b/sources/PocketBook/Pages/MarkPage.xaml.cs deleted file mode 100644 index d0f5fcb..0000000 --- a/sources/PocketBook/Pages/MarkPage.xaml.cs +++ /dev/null @@ -1,15 +0,0 @@ -using CommunityToolkit.Maui.Views; -using PocketBook.Applicative_VM; - -namespace PocketBook; - -public partial class MarkPage : ContentPage -{ - public NavigatorVM NavigateCommandBooks { get; private set; } - - public MarkPage(NavigatorVM navigator) - { - NavigateCommandBooks = navigator; - InitializeComponent(); - } -} \ No newline at end of file diff --git a/sources/PocketBook/Pages/TousPage.xaml b/sources/PocketBook/Pages/TousPage.xaml index 1436786..090ffa9 100644 --- a/sources/PocketBook/Pages/TousPage.xaml +++ b/sources/PocketBook/Pages/TousPage.xaml @@ -13,13 +13,13 @@ + Order="Primary" IconImageSource="plus.png" Command="{Binding TousPageVM.ButtonsVM.ShowScanMenu}"/> - diff --git a/sources/PocketBook/PocketBook.csproj b/sources/PocketBook/PocketBook.csproj index a901e25..0316738 100644 --- a/sources/PocketBook/PocketBook.csproj +++ b/sources/PocketBook/PocketBook.csproj @@ -59,7 +59,7 @@ MSBuild:Compile - + MSBuild:Compile @@ -80,9 +80,6 @@ MSBuild:Compile - - MSBuild:Compile - MSBuild:Compile @@ -204,13 +201,13 @@ + + Filter.xaml + StatutPage.xaml - - - diff --git a/sources/ViewModel/BookVM.cs b/sources/ViewModel/BookVM.cs index f23fff5..a22149c 100644 --- a/sources/ViewModel/BookVM.cs +++ b/sources/ViewModel/BookVM.cs @@ -32,6 +32,12 @@ namespace ViewModel set => SetProperty(Model.PublishDate, value, v => Model.PublishDate = v); } + public string Annee + { + get => Model.PublishDate.ToString("yyyy"); + set { } + } + public Languages Language { get => Model.Language; diff --git a/sources/ViewModel/ManagerVM.cs b/sources/ViewModel/ManagerVM.cs index 7d25e93..573768f 100644 --- a/sources/ViewModel/ManagerVM.cs +++ b/sources/ViewModel/ManagerVM.cs @@ -8,13 +8,13 @@ using MyToolkitMVVM; public class ManagerVM : BaseViewModel { public ReadOnlyObservableCollection Books { get; set; } - private readonly ObservableCollection books = new ObservableCollection(); - public RelayCommand LoadBooks { get; private set; } - public IEnumerable> GroupedBooks => books.GroupBy(b => b.BookFirstAuthor).OrderBy(group => group.Key); public IEnumerable> GroupedLaterBooks => books.Where(book => book.BookStatus == Status.ToBeRead).GroupBy(book => book.BookFirstAuthor).OrderBy(group => group.Key); + public ReadOnlyObservableCollection> Filters { get; private set; } + private readonly ObservableCollection> filters = new ObservableCollection>(); + public BookVM SelectedBook { get => selectedBook; @@ -56,6 +56,28 @@ public class ManagerVM : BaseViewModel Refresh(); } + public async Task GetDatesFromCollection() + { + var result = await Model.GetBooksFromCollection(0, 1000); + IEnumerable resAuthors = result.books.Select(b => new BookVM(b)); + + var groupedBooksByDate = resAuthors.GroupBy(book => book.Annee).OrderByDescending(group => group.Key); + + var dates = groupedBooksByDate.Select(group => + new Tuple(group.Key, group.Count()) + ); + + filters.Clear(); + + foreach (var date in dates) + { + filters.Add(date); + Debug.WriteLine(date); + } + OnPropertyChanged(nameof(filters)); + OnPropertyChanged(nameof(Filters)); + } + public void ChangeStatut(string statut) { switch (statut) @@ -83,10 +105,6 @@ public class ManagerVM : BaseViewModel { OnPropertyChanged(nameof(GroupedBooks)); OnPropertyChanged(nameof(GroupedLaterBooks)); - OnPropertyChanged(nameof(Books)); - OnPropertyChanged(nameof(books)); - //NbBookLater=books.Where(book => book.BookStatus == Status.ToBeRead).Count(); - //Debug.WriteLine(NbBookLater); } public ManagerVM(Manager model) : base(model) @@ -99,8 +117,6 @@ public class ManagerVM : BaseViewModel { var result= Model.GetBookByISBN(isbn).Result; if (result != null) { - Debug.WriteLine(result.ToString()); - //books.Add(new BookVM(result)); Model.AddBookToCollection(result.Id); LoadBooksFromManager(); Refresh();