diff --git a/sources/PocketBook/Applicative_VM/FilterVM.cs b/sources/PocketBook/Applicative_VM/FilterVM.cs index 7bcbeea..9e0d8f6 100644 --- a/sources/PocketBook/Applicative_VM/FilterVM.cs +++ b/sources/PocketBook/Applicative_VM/FilterVM.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -14,12 +15,19 @@ namespace PocketBook.Applicative_VM public ICommand MarkCommand { get; private set; } public ICommand YearCommand { get; private set; } public ICommand FilterCommand { get; private set; } + public ICommand FilterLoadDataAuthor { get; private set; } + public ICommand FilterLoadDataYear { get; private set; } + public ICommand FilterLoadDataMark { get; private set; } public ManagerVM Manager { get; private set; } - public FilterVM(ManagerVM manager) + public NavigatorVM Navigator { get; private set; } + + public FilterVM(ManagerVM manager,NavigatorVM navigator) { Manager = manager; - + Navigator = navigator; + string currentRoute = (Application.Current.MainPage as NavigationPage)?.CurrentPage?.ToString(); + Debug.WriteLine(currentRoute); FilterCommand = new Command(option => { switch (option) @@ -47,6 +55,21 @@ namespace PocketBook.Applicative_VM { await Manager.GetMarkFromCollection(); }); + FilterLoadDataAuthor = new Command(async type => + { + Manager.Index = 0; + await Manager.GetBooksFromAuthor(type); + }); + FilterLoadDataMark = new Command(async type => + { + Manager.Index = 0; + await Manager.GetBooksFromMark(type); + }); + FilterLoadDataYear = new Command(async type => + { + Manager.Index = 0; + await Manager.GetBooksFromYears(type); + }); } diff --git a/sources/PocketBook/Applicative_VM/NavigatorAndFilterVM.cs b/sources/PocketBook/Applicative_VM/NavigatorAndFilterVM.cs new file mode 100644 index 0000000..0d36a0d --- /dev/null +++ b/sources/PocketBook/Applicative_VM/NavigatorAndFilterVM.cs @@ -0,0 +1,44 @@ +using System; +using System.Windows.Input; + +namespace PocketBook.Applicative_VM +{ + public class NavigatorAndFilterVM + { + public NavigatorVM NavigateCommandBooks { get; private set; } + public FilterVM FilterVM { get; private set; } + public ICommand NavigateAndLoad { get; private set; } + public ICommand NavigateAndLoadData { get; private set; } + + public string ActualTypeFilter { get; private set; } + + public NavigatorAndFilterVM(FilterVM filterVM, NavigatorVM navigator) + { + NavigateCommandBooks = navigator; + FilterVM = filterVM; + NavigateAndLoad = new Command(o => + { + ActualTypeFilter = o; + FilterVM.FilterCommand.Execute(o); + NavigateCommandBooks.Navigateto.Execute("Filter"); + }); + NavigateAndLoadData = new Command(o => + { + switch (ActualTypeFilter) + { + case "Author": + FilterVM.FilterLoadDataAuthor.Execute(o);; + break; + case "Mark": + FilterVM.FilterLoadDataMark.Execute(o); ; + break; + case "Year": + FilterVM.FilterLoadDataYear.Execute(o); ; + break; + } + NavigateCommandBooks.Navigateto.Execute("TousPage"); + }); + } + } +} + diff --git a/sources/PocketBook/Applicative_VM/NavigatorVM.cs b/sources/PocketBook/Applicative_VM/NavigatorVM.cs index 05b94a1..ae3fd04 100644 --- a/sources/PocketBook/Applicative_VM/NavigatorVM.cs +++ b/sources/PocketBook/Applicative_VM/NavigatorVM.cs @@ -10,18 +10,13 @@ namespace PocketBook.Applicative_VM { public ICommand Navigateto { get; private set; } public ICommand NavigatetoFilter { get; private set; } - public FilterVM FilterVM { get; private set; } - public NavigatorVM(FilterVM filterVM) + public NavigatorVM() { - 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/TousPageVM.cs b/sources/PocketBook/Applicative_VM/TousPageVM.cs index 5fb947f..39fb56b 100644 --- a/sources/PocketBook/Applicative_VM/TousPageVM.cs +++ b/sources/PocketBook/Applicative_VM/TousPageVM.cs @@ -8,7 +8,9 @@ namespace PocketBook.Applicative_VM { public class TousPageVM : BaseViewModel { + public ICommand NavigateAndLoadData { get; private set; } public ICommand NavigateDetailPage { get; private set; } + public NavigatorVM NavigateCommandBooks { get; private set; } public ButtonsVM ButtonsVM { get; private set; } public ManagerVM Manager { get; private set; } @@ -20,13 +22,18 @@ namespace PocketBook.Applicative_VM ButtonsVM = buttonsVM; Manager = manager; PaginationVM = paginationVM; - Manager.LoadBooksFromManager(); NavigateCommandBooks = navigation; + //Manager.LoadBooksFromManager(); NavigateDetailPage = new Command(book => { Manager.SelectedBook = book; NavigateCommandBooks.Navigateto.Execute("BookDetail"); + }); + NavigateAndLoadData = new Command(o => + { + Manager.LoadBooksFromManager(); + NavigateCommandBooks.Navigateto.Execute("TousPage"); }); } } diff --git a/sources/PocketBook/MauiProgram.cs b/sources/PocketBook/MauiProgram.cs index 956f661..2e64d92 100644 --- a/sources/PocketBook/MauiProgram.cs +++ b/sources/PocketBook/MauiProgram.cs @@ -48,6 +48,7 @@ public static class MauiProgram .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() diff --git a/sources/PocketBook/Pages/Composants/ContentView/Filtrage.xaml b/sources/PocketBook/Pages/Composants/ContentView/Filtrage.xaml index b8f175d..239e433 100644 --- a/sources/PocketBook/Pages/Composants/ContentView/Filtrage.xaml +++ b/sources/PocketBook/Pages/Composants/ContentView/Filtrage.xaml @@ -2,6 +2,7 @@ @@ -10,8 +11,8 @@ - diff --git a/sources/PocketBook/Pages/Composants/ContentView/Filtrage.xaml.cs b/sources/PocketBook/Pages/Composants/ContentView/Filtrage.xaml.cs index 5bf4b25..0342e43 100644 --- a/sources/PocketBook/Pages/Composants/ContentView/Filtrage.xaml.cs +++ b/sources/PocketBook/Pages/Composants/ContentView/Filtrage.xaml.cs @@ -1,4 +1,6 @@ -namespace PocketBook; +using System.Windows.Input; + +namespace PocketBook; public partial class Filtrage : ContentView { @@ -9,6 +11,23 @@ public partial class Filtrage : ContentView public static readonly BindableProperty NumberDataProperty = BindableProperty.Create(nameof(NumberData), typeof(string), typeof(Filtrage), string.Empty); + public static readonly BindableProperty CommandProperty = + BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(Filtrage)); + + public static readonly BindableProperty CommandParameterProperty = + BindableProperty.Create(nameof(CommandParameter), typeof(string), typeof(Filtrage)); + + public string CommandParameter + { + get { return (string)GetValue(CommandParameterProperty); } + set { SetValue(CommandParameterProperty, value); } + } + + public ICommand Command + { + get { return (ICommand)GetValue(CommandProperty); } + set { SetValue(CommandProperty, value); } + } public string Dataname { @@ -26,8 +45,5 @@ public partial class Filtrage : ContentView public Filtrage() { InitializeComponent(); - - dataname.SetBinding(Label.TextProperty, new Binding(nameof(Dataname), source: this)); - numberData.SetBinding(Label.TextProperty, new Binding(nameof(NumberData), source: this)); } } diff --git a/sources/PocketBook/Pages/Filter.xaml b/sources/PocketBook/Pages/Filter.xaml index e5d0e45..849c954 100644 --- a/sources/PocketBook/Pages/Filter.xaml +++ b/sources/PocketBook/Pages/Filter.xaml @@ -25,7 +25,7 @@ - + diff --git a/sources/PocketBook/Pages/Filter.xaml.cs b/sources/PocketBook/Pages/Filter.xaml.cs index 1349ad8..2c83070 100644 --- a/sources/PocketBook/Pages/Filter.xaml.cs +++ b/sources/PocketBook/Pages/Filter.xaml.cs @@ -5,14 +5,12 @@ 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) + public NavigatorAndFilterVM NavigatorAndFilterVM { get; private set; } + public Filter(NavigatorAndFilterVM navigatorAndFilterVM) { - FilterVM=filterVM; - NavigateCommandBooks = navigator; + NavigatorAndFilterVM = navigatorAndFilterVM; InitializeComponent(); - BindingContext = this; + BindingContext = NavigatorAndFilterVM; } } \ No newline at end of file diff --git a/sources/PocketBook/Pages/MainPage.xaml b/sources/PocketBook/Pages/MainPage.xaml index c06caa3..1f883ba 100644 --- a/sources/PocketBook/Pages/MainPage.xaml +++ b/sources/PocketBook/Pages/MainPage.xaml @@ -35,23 +35,23 @@ - + - + - - - @@ -59,14 +59,14 @@ - - - diff --git a/sources/PocketBook/Pages/MainPage.xaml.cs b/sources/PocketBook/Pages/MainPage.xaml.cs index 75aa5b8..0de43d1 100644 --- a/sources/PocketBook/Pages/MainPage.xaml.cs +++ b/sources/PocketBook/Pages/MainPage.xaml.cs @@ -6,12 +6,15 @@ namespace PocketBook; public partial class MainPage : ContentPage { public NavigatorVM NavigateCommandBooks { get; private set; } - - public MainPage(NavigatorVM navigation) + public NavigatorAndFilterVM NavigatorAndFilterVM { get; private set; } + public TousPageVM TousPageVM { get; private set; } + public MainPage(NavigatorVM navigation, NavigatorAndFilterVM navigatorAndFilterVM, TousPageVM tousPageVM) { + TousPageVM = tousPageVM; + NavigatorAndFilterVM = navigatorAndFilterVM; NavigateCommandBooks = navigation; InitializeComponent(); - BindingContext = NavigateCommandBooks; + BindingContext = this; } } diff --git a/sources/ViewModel/BookVM.cs b/sources/ViewModel/BookVM.cs index b9073d1..d63ed68 100644 --- a/sources/ViewModel/BookVM.cs +++ b/sources/ViewModel/BookVM.cs @@ -106,7 +106,9 @@ namespace ViewModel { BookFirstAuthor = BookAuthors.First().Name; } - else BookFirstAuthor = "Unknown"; + else { + BookFirstAuthor = "Unknown"; + } if (BookPublishers.Count() > 0) { diff --git a/sources/ViewModel/ManagerVM.cs b/sources/ViewModel/ManagerVM.cs index cb784a0..e540df1 100644 --- a/sources/ViewModel/ManagerVM.cs +++ b/sources/ViewModel/ManagerVM.cs @@ -116,6 +116,48 @@ public class ManagerVM : BaseViewModel OnPropertyChanged(nameof(filters)); } + public async Task GetBooksFromAuthor(string author) + { + var result=await Model.GetBooksByAuthor(author,index,5); + NbBook = (int)result.count; + books.Clear(); + + foreach (Book book in result.books) + { + books.Add(new BookVM(book)); + } + Refresh(); + } + + public async Task GetBooksFromYears(string year) + { + var result = await Model.GetBooksFromCollection(0, 1000); + NbBook = 0; + books.Clear(); + + foreach (Book book in result.books) + { + var bookVM = new BookVM(book); + if (bookVM.Annee == year) { books.Add(bookVM); NbBook++; } + } + Refresh(); + } + + public async Task GetBooksFromMark(string mark) + { + var result = await Model.GetBooksFromCollection(0, 1000); + NbBook = 0; + books.Clear(); + + foreach (Book book in result.books) + { + var bookVM = new BookVM(book); + if (bookVM.UserRatingString == mark) { books.Add(bookVM); NbBook++; } + } + Refresh(); + } + + public void ChangeStatut(string statut) { switch (statut)