From 6d16193450ad6c89bd195fafba4eb036c3b925c7 Mon Sep 17 00:00:00 2001 From: lobroda Date: Thu, 19 Oct 2023 11:03:24 +0100 Subject: [PATCH] ADD : Avancements multiples en TP --- LivreLand/AppShell.xaml.cs | 1 - LivreLand/LivreLand.csproj | 3 -- LivreLand/MauiProgram.cs | 4 +- LivreLand/View/ALirePlusTardView.xaml.cs | 7 --- LivreLand/View/AddBookView.xaml | 12 ----- LivreLand/View/AddBookView.xaml.cs | 9 ---- LivreLand/View/BibliothequeView.xaml | 12 ++--- LivreLand/View/ContactsView.xaml.cs | 7 --- .../View/ContentViews/PopupISBNView.xaml | 4 +- .../View/ContentViews/PopupISBNView.xaml.cs | 4 +- LivreLand/View/DetailsLivreView.xaml | 4 +- LivreLand/View/EmpruntsPretsView.xaml.cs | 8 --- LivreLand/View/FavorisView.xaml.cs | 7 --- LivreLand/View/StatutLectureView.xaml.cs | 7 --- LivreLand/ViewModel/BibliothequeVM.cs | 37 +++++++++++++ LivreLand/ViewModel/ContactsVM.cs | 4 +- LivreLand/ViewModel/DetailsLivreVM.cs | 13 +++++ LivreLand/ViewModel/NavigatorVM.cs | 2 +- LivreLand/ViewModel/PopupISBNVM.cs | 52 +++++++++++++++++++ ViewModels/ManagerVM.cs | 48 ++++++++++++----- 20 files changed, 156 insertions(+), 89 deletions(-) delete mode 100644 LivreLand/View/AddBookView.xaml delete mode 100644 LivreLand/View/AddBookView.xaml.cs create mode 100644 LivreLand/ViewModel/PopupISBNVM.cs diff --git a/LivreLand/AppShell.xaml.cs b/LivreLand/AppShell.xaml.cs index 363e8d7..3a9374d 100644 --- a/LivreLand/AppShell.xaml.cs +++ b/LivreLand/AppShell.xaml.cs @@ -16,7 +16,6 @@ public partial class AppShell : Shell Routing.RegisterRoute("library/note/", typeof(FiltrageNoteView)); Routing.RegisterRoute("library/contacts/", typeof(ContactsView)); Routing.RegisterRoute("library/tous/details/", typeof(DetailsLivreView)); - Routing.RegisterRoute("library/add/", typeof(AddBookView)); InitializeComponent(); } } diff --git a/LivreLand/LivreLand.csproj b/LivreLand/LivreLand.csproj index e044fb1..47c0609 100644 --- a/LivreLand/LivreLand.csproj +++ b/LivreLand/LivreLand.csproj @@ -65,9 +65,6 @@ - - MSBuild:Compile - MSBuild:Compile diff --git a/LivreLand/MauiProgram.cs b/LivreLand/MauiProgram.cs index 315f5ff..64b132b 100644 --- a/LivreLand/MauiProgram.cs +++ b/LivreLand/MauiProgram.cs @@ -34,6 +34,7 @@ public static class MauiProgram .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton() @@ -52,7 +53,8 @@ public static class MauiProgram .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton(); + .AddSingleton() + .AddSingleton(); #if DEBUG builder.Logging.AddDebug(); diff --git a/LivreLand/View/ALirePlusTardView.xaml.cs b/LivreLand/View/ALirePlusTardView.xaml.cs index e7f43e7..ebe53c4 100644 --- a/LivreLand/View/ALirePlusTardView.xaml.cs +++ b/LivreLand/View/ALirePlusTardView.xaml.cs @@ -24,12 +24,5 @@ public partial class ALirePlusTardView : ContentPage #region Methods - protected override void OnAppearing() - { - base.OnAppearing(); - - ALirePlusTardVM.Manager.GetToBeReadBooksCommand.Execute(null); - } - #endregion } \ No newline at end of file diff --git a/LivreLand/View/AddBookView.xaml b/LivreLand/View/AddBookView.xaml deleted file mode 100644 index fa59fda..0000000 --- a/LivreLand/View/AddBookView.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - \ No newline at end of file diff --git a/LivreLand/View/AddBookView.xaml.cs b/LivreLand/View/AddBookView.xaml.cs deleted file mode 100644 index e08baaa..0000000 --- a/LivreLand/View/AddBookView.xaml.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace LivreLand.View; - -public partial class AddBookView : ContentPage -{ - public AddBookView() - { - InitializeComponent(); - } -} \ No newline at end of file diff --git a/LivreLand/View/BibliothequeView.xaml b/LivreLand/View/BibliothequeView.xaml index eaf0c42..9b4f594 100644 --- a/LivreLand/View/BibliothequeView.xaml +++ b/LivreLand/View/BibliothequeView.xaml @@ -65,8 +65,7 @@ ButtonNumber="1" ButtonRedIconVisible="False" ButtonBlackIconVisible="True" - ButtonTappedCommand="{Binding BibliothequeVM.Navigator.NavigationCommand}" - CommandParameter="pret/"/> + ButtonTappedCommand="{Binding BibliothequeVM.AllLoansBorrowingsNavigateCommand}"/> @@ -75,8 +74,7 @@ ButtonIcon="arrow_forward.png" ButtonRedIconVisible="False" ButtonBlackIconVisible="True" - ButtonTappedCommand="{Binding BibliothequeVM.Navigator.NavigationCommand}" - CommandParameter="later/"/> + ButtonTappedCommand="{Binding BibliothequeVM.AllToReadBooksNavigateCommand}"/> @@ -85,8 +83,7 @@ ButtonIcon="eyeglasses.png" ButtonRedIconVisible="False" ButtonBlackIconVisible="True" - ButtonTappedCommand="{Binding BibliothequeVM.Navigator.NavigationCommand}" - CommandParameter="statut/"/> + ButtonTappedCommand="{Binding BibliothequeVM.AllStatusBooksNavigateCommand}"/> @@ -95,8 +92,7 @@ ButtonIcon="heart_fill.png" ButtonRedIconVisible="False" ButtonBlackIconVisible="True" - ButtonTappedCommand="{Binding BibliothequeVM.Navigator.NavigationCommand}" - CommandParameter="favoris/"/> + ButtonTappedCommand="{Binding BibliothequeVM.AllFavorisBooksNavigateCommand}"/> diff --git a/LivreLand/View/ContactsView.xaml.cs b/LivreLand/View/ContactsView.xaml.cs index a7f04eb..97ae24e 100644 --- a/LivreLand/View/ContactsView.xaml.cs +++ b/LivreLand/View/ContactsView.xaml.cs @@ -23,12 +23,5 @@ public partial class ContactsView : ContentPage #region Methods - protected override void OnAppearing() - { - base.OnAppearing(); - - ContactsVM.Manager.GetContactsCommand.Execute(null); - } - #endregion } \ No newline at end of file diff --git a/LivreLand/View/ContentViews/PopupISBNView.xaml b/LivreLand/View/ContentViews/PopupISBNView.xaml index 4190417..458088c 100644 --- a/LivreLand/View/ContentViews/PopupISBNView.xaml +++ b/LivreLand/View/ContentViews/PopupISBNView.xaml @@ -23,7 +23,9 @@ - + diff --git a/LivreLand/View/ContentViews/PopupISBNView.xaml.cs b/LivreLand/View/ContentViews/PopupISBNView.xaml.cs index 75a9dac..1828be5 100644 --- a/LivreLand/View/ContentViews/PopupISBNView.xaml.cs +++ b/LivreLand/View/ContentViews/PopupISBNView.xaml.cs @@ -1,12 +1,14 @@ using CommunityToolkit.Maui.Views; +using LivreLand.ViewModel; namespace LivreLand.View.ContentViews; public partial class PopupISBNView : Popup { - public PopupISBNView() + public PopupISBNView(PopupISBNVM popupISBNVM) { InitializeComponent(); + BindingContext = popupISBNVM; Size = new Size(0.8 * (DeviceDisplay.Current.MainDisplayInfo.Width / DeviceDisplay.Current.MainDisplayInfo.Density), 0.5 * (DeviceDisplay.Current.MainDisplayInfo.Width / DeviceDisplay.Current.MainDisplayInfo.Density)); } } \ No newline at end of file diff --git a/LivreLand/View/DetailsLivreView.xaml b/LivreLand/View/DetailsLivreView.xaml index a52fbee..acb7c94 100644 --- a/LivreLand/View/DetailsLivreView.xaml +++ b/LivreLand/View/DetailsLivreView.xaml @@ -333,8 +333,8 @@ + ButtonCommand="{Binding DetailsLivreVM.LoanBookCommand}" + ButtonCommandParameter="{Binding DetailsLivreVM.Book}"/> diff --git a/LivreLand/View/EmpruntsPretsView.xaml.cs b/LivreLand/View/EmpruntsPretsView.xaml.cs index 90bc22b..75d55e8 100644 --- a/LivreLand/View/EmpruntsPretsView.xaml.cs +++ b/LivreLand/View/EmpruntsPretsView.xaml.cs @@ -24,13 +24,5 @@ public partial class EmpruntsPretsView : ContentPage #region Methods - protected override void OnAppearing() - { - base.OnAppearing(); - - EmpruntsPretsVM.Manager.GetCurrentLoansCommand.Execute(null); - EmpruntsPretsVM.Manager.GetCurrentBorrowingsCommand.Execute(null); - } - #endregion } \ No newline at end of file diff --git a/LivreLand/View/FavorisView.xaml.cs b/LivreLand/View/FavorisView.xaml.cs index 7cc68b0..7d635a7 100644 --- a/LivreLand/View/FavorisView.xaml.cs +++ b/LivreLand/View/FavorisView.xaml.cs @@ -29,12 +29,5 @@ public partial class FavorisView : ContentPage //App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView()); } - protected override void OnAppearing() - { - base.OnAppearing(); - - FavorisVM.Manager.GetFavoriteBooksCommand.Execute(null); - } - #endregion } \ No newline at end of file diff --git a/LivreLand/View/StatutLectureView.xaml.cs b/LivreLand/View/StatutLectureView.xaml.cs index ef77f83..c112ade 100644 --- a/LivreLand/View/StatutLectureView.xaml.cs +++ b/LivreLand/View/StatutLectureView.xaml.cs @@ -24,12 +24,5 @@ public partial class StatutLectureView : ContentPage #region Methods - protected override void OnAppearing() - { - base.OnAppearing(); - - StatutLectureVM.Manager.GetBooksFromCollectionCommand.Execute(null); - } - #endregion } \ No newline at end of file diff --git a/LivreLand/ViewModel/BibliothequeVM.cs b/LivreLand/ViewModel/BibliothequeVM.cs index 47fe84c..a8650fd 100644 --- a/LivreLand/ViewModel/BibliothequeVM.cs +++ b/LivreLand/ViewModel/BibliothequeVM.cs @@ -19,6 +19,14 @@ namespace LivreLand.ViewModel public ICommand AllBooksNavigateCommand { get; private set; } + public ICommand AllLoansBorrowingsNavigateCommand { get; private set; } + + public ICommand AllFavorisBooksNavigateCommand { get; private set; } + + public ICommand AllStatusBooksNavigateCommand { get; private set; } + + public ICommand AllToReadBooksNavigateCommand { get; private set; } + public ICommand AllAuthorsNavigateCommand { get; private set; } public ICommand AllDatesNavigateCommand { get; private set; } @@ -34,6 +42,10 @@ namespace LivreLand.ViewModel Navigator = navigatorVM; Manager = managerVM; AllBooksNavigateCommand = new RelayCommand(() => AllBooksNavigate()); + AllLoansBorrowingsNavigateCommand = new RelayCommand(() => AllLoansBorrowingsNavigate()); + AllFavorisBooksNavigateCommand = new RelayCommand(() => AllFavorisBooksNavigate()); + AllStatusBooksNavigateCommand = new RelayCommand(() => AllStatusBooksNavigate()); + AllToReadBooksNavigateCommand = new RelayCommand(() => AllToReadBooksNavigate()); AllAuthorsNavigateCommand = new RelayCommand(() => AllAuthorsNavigate()); AllDatesNavigateCommand = new RelayCommand(() => AllDatesNavigate()); AllRatingsNavigateCommand = new RelayCommand(() => AllRatingsNavigate()); @@ -49,6 +61,31 @@ namespace LivreLand.ViewModel Navigator.NavigationCommand.Execute("/tous"); } + private void AllLoansBorrowingsNavigate() + { + Manager.GetCurrentLoansCommand.Execute(null); + Manager.GetCurrentBorrowingsCommand.Execute(null); + Navigator.NavigationCommand.Execute("/pret"); + } + + private void AllFavorisBooksNavigate() + { + Manager.GetFavoriteBooksCommand.Execute(null); + Navigator.NavigationCommand.Execute("/favoris"); + } + + private void AllStatusBooksNavigate() + { + Manager.GetBooksFromCollectionCommand.Execute(null); + Navigator.NavigationCommand.Execute("/statut"); + } + + private void AllToReadBooksNavigate() + { + Manager.GetToBeReadBooksCommand.Execute(null); + Navigator.NavigationCommand.Execute("/later"); + } + private void AllAuthorsNavigate() { Manager.GetAllAuthorsCommand.Execute(null); diff --git a/LivreLand/ViewModel/ContactsVM.cs b/LivreLand/ViewModel/ContactsVM.cs index 85ea91c..4d430be 100644 --- a/LivreLand/ViewModel/ContactsVM.cs +++ b/LivreLand/ViewModel/ContactsVM.cs @@ -69,7 +69,9 @@ namespace LivreLand.ViewModel var toast = Toast.Make("Livre prêté !", CommunityToolkit.Maui.Core.ToastDuration.Short); await toast.Show(); - Navigator.PopupBackButtonNavigationCommand.Execute(null); + Manager.GetCurrentLoansCommand.Execute(null); + Manager.GetCurrentBorrowingsCommand.Execute(null); + Navigator.NavigationCommand.Execute("/pret"); } #endregion diff --git a/LivreLand/ViewModel/DetailsLivreVM.cs b/LivreLand/ViewModel/DetailsLivreVM.cs index 12feba5..f5204f3 100644 --- a/LivreLand/ViewModel/DetailsLivreVM.cs +++ b/LivreLand/ViewModel/DetailsLivreVM.cs @@ -73,6 +73,8 @@ namespace LivreLand.ViewModel public ICommand AddBookToReadListCommand { get; private set; } + public ICommand LoanBookCommand { get; private set; } + public ICommand RemoveBookCommand { get; private set; } #endregion @@ -88,6 +90,7 @@ namespace LivreLand.ViewModel ShowPickerCommand = new RelayCommand(() => ShowPicker()); AddRemoveBookToFavoritesCommand = new RelayCommand((bookVM) => AddRemoveBookToFavorites(bookVM)); AddBookToReadListCommand = new RelayCommand((bookVM) => AddBookToReadList(bookVM)); + LoanBookCommand = new RelayCommand((bookVM) => LoanBook(bookVM)); RemoveBookCommand = new RelayCommand((bookVM) => RemoveBook(bookVM)); } @@ -118,6 +121,7 @@ namespace LivreLand.ViewModel var toast = Toast.Make("Livre ajouté aux favoris !", CommunityToolkit.Maui.Core.ToastDuration.Short); await toast.Show(); + Manager.GetFavoriteBooksCommand.Execute(null); Navigator.NavigationCommand.Execute("/favoris"); } else @@ -129,6 +133,7 @@ namespace LivreLand.ViewModel var toast = Toast.Make("Livre supprimé des favoris !", CommunityToolkit.Maui.Core.ToastDuration.Short); await toast.Show(); + Manager.GetFavoriteBooksCommand.Execute(null); Navigator.NavigationCommand.Execute("/favoris"); } } @@ -140,9 +145,17 @@ namespace LivreLand.ViewModel var toast = Toast.Make("Livre ajouté à la liste À lire plus tard !", CommunityToolkit.Maui.Core.ToastDuration.Short); await toast.Show(); + Manager.GetToBeReadBooksCommand.Execute(null); Navigator.NavigationCommand.Execute("/later"); } + private void LoanBook(BookVM bookVM) + { + Manager.SelectedBook = bookVM; + Manager.GetContactsCommand.Execute(null); + Navigator.NavigationCommand.Execute("contacts"); + } + private async Task RemoveBook(BookVM bookVM) { Manager.RemoveBookCommand.Execute(bookVM); diff --git a/LivreLand/ViewModel/NavigatorVM.cs b/LivreLand/ViewModel/NavigatorVM.cs index fef5cbb..a93d9e4 100644 --- a/LivreLand/ViewModel/NavigatorVM.cs +++ b/LivreLand/ViewModel/NavigatorVM.cs @@ -28,7 +28,7 @@ namespace LivreLand.ViewModel NavigationCommand = new Command(async (target) => await Shell.Current.GoToAsync($"//library/{target}")); PopupHomePlusNavigationCommand = new Command(() => App.Current.MainPage.ShowPopup(new PopupHomePlusButtonView(this))); - PopupISBNNavigationCommand = new Command(() => App.Current.MainPage.ShowPopup(new PopupISBNView())); + PopupISBNNavigationCommand = new Command(() => App.Current.MainPage.ShowPopup(new PopupISBNView(Application.Current.Handler.MauiContext.Services.GetService()))); PopupBackButtonNavigationCommand = new Command(() => App.Current.MainPage.Navigation.PopAsync()); } diff --git a/LivreLand/ViewModel/PopupISBNVM.cs b/LivreLand/ViewModel/PopupISBNVM.cs new file mode 100644 index 0000000..557ae31 --- /dev/null +++ b/LivreLand/ViewModel/PopupISBNVM.cs @@ -0,0 +1,52 @@ +using CommunityToolkit.Maui.Alerts; +using Model; +using PersonalMVVMToolkit; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; +using ViewModels; + +namespace LivreLand.ViewModel +{ + public class PopupISBNVM : BaseViewModel + { + #region Properties + + public NavigatorVM Navigator { get; private set; } + + public ManagerVM Manager { get; private set; } + + public ICommand AddBookCommand { get; private set; } + + #endregion + + #region Constructor + + public PopupISBNVM(NavigatorVM navigatorVM, ManagerVM managerVM) + { + Navigator = navigatorVM; + Manager = managerVM; + AddBookCommand = new RelayCommand((text) => AddBook(text)); + } + + #endregion + + #region Methods + + private async Task AddBook(string entryText) + { + Manager.AddBookCommand.Execute(entryText); + + var toast = Toast.Make("Livre ajouté !", CommunityToolkit.Maui.Core.ToastDuration.Short); + await toast.Show(); + + Manager.GetBooksFromCollectionCommand.Execute(null); + Navigator.NavigationCommand.Execute("/tous"); + } + + #endregion + } +} diff --git a/ViewModels/ManagerVM.cs b/ViewModels/ManagerVM.cs index aef6194..e0e0a55 100644 --- a/ViewModels/ManagerVM.cs +++ b/ViewModels/ManagerVM.cs @@ -48,6 +48,7 @@ namespace ViewModels private ContactVM selectedContact; private LoanVM selectedLoan; private BorrowingVM selectedBorrowing; + private string entryText; private string givenFirstName; private string givenLastName; @@ -257,6 +258,19 @@ namespace ViewModels } } + public string EntryText + { + get { return entryText; } + set + { + if (entryText != value) + { + entryText = value; + OnPropertyChanged(nameof(EntryText)); + } + } + } + public string GivenFirstName { get { return givenFirstName; } @@ -383,7 +397,7 @@ namespace ViewModels PreviousCommand = new RelayCommand(() => Previous()); NextCommand = new RelayCommand(() => Next()); GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection()); - AddBookCommand = new RelayCommand((bookVM) => AddBook(bookVM)); + AddBookCommand = new RelayCommand((isbn) => AddBook(isbn)); UpdateBookCommand = new RelayCommand((bookVM) => UpdateBook(bookVM)); UpdateStatusBookCommand = new RelayCommand((bookVM) => UpdateStatusBook(bookVM)); UpdateToBeReadBookCommand = new RelayCommand((bookVM) => UpdateToBeReadBook(bookVM)); @@ -450,10 +464,13 @@ namespace ViewModels OnPropertyChanged(nameof(AllBooks)); } - private async Task AddBook(BookVM bookVM) + private async Task AddBook(string isbn) { - await Model.AddBookToCollection(bookVM.Id); - GetBooksFromCollectionCommand.Execute(null); + var result = await Model.GetBookByISBN(isbn); + if (result != null) + { + await Model.AddBookToCollection(result.Id); + } } private async Task UpdateBook(BookVM bookVM) @@ -493,13 +510,14 @@ namespace ViewModels foreach (var b in someBooks.Select(b => new BookVM(b))) { books.Add(b); + GroupedBooks = AllBooks.GroupBy(b => b.Author).OrderBy(group => group.Key); } OnPropertyChanged(nameof(AllBooks)); } private async Task GetAllAuthors() { - var result = await Model.GetBooksFromCollection(0, 20); + var result = await Model.GetBooksFromCollection(0, 1000); IEnumerable someBooks = result.books; books.Clear(); authors.Clear(); @@ -522,9 +540,10 @@ namespace ViewModels books.Clear(); foreach (var b in someBooks.Select(b => new BookVM(b))) { - if (b.PublishDate == SelectedDate.PublishDate) + if (b.PublishDate.Year == SelectedDate.PublishDate.Year) { books.Add(b); + GroupedBooks = AllBooks.GroupBy(b => b.Author).OrderBy(group => group.Key); } } OnPropertyChanged(nameof(AllBooks)); @@ -532,7 +551,7 @@ namespace ViewModels private async Task GetAllPublishDates() { - var result = await Model.GetBooksFromCollection(0, 20); + var result = await Model.GetBooksFromCollection(0, 1000); IEnumerable someBooks = result.books; books.Clear(); publishDates.Clear(); @@ -559,17 +578,20 @@ namespace ViewModels NbBooks = result.count; IEnumerable someBooks = result.books; books.Clear(); - var filteredBooks = someBooks.Where(b => b.UserRating.HasValue && Math.Floor(b.UserRating.Value) == SelectedRating.Average); - foreach (var book in filteredBooks) + foreach (var book in someBooks.Select(b => new BookVM(b))) { - books.Add(new BookVM(book)); + if (book.UserRating == SelectedRating.Average) + { + //books.Add(new BookVM(book)); + GroupedBooks = AllBooks.GroupBy(b => b.Author).OrderBy(group => group.Key); + } } OnPropertyChanged(nameof(AllBooks)); } private async Task GetAllRatings() { - var result = await Model.GetBooksFromCollection(0, 20); + var result = await Model.GetBooksFromCollection(0, 1000); IEnumerable someBooks = result.books; books.Clear(); ratings.Clear(); @@ -621,7 +643,7 @@ namespace ViewModels private async Task GetToBeReadBooks() { - var result = await Model.GetBooksFromCollection(0, 20); + var result = await Model.GetBooksFromCollection(0, 1000); IEnumerable someBooks = result.books; books.Clear(); toBeReadBooks.Clear(); @@ -637,7 +659,7 @@ namespace ViewModels private async Task GetFavoriteBooks() { - var result = await Model.GetFavoritesBooks(Index, Count); + var result = await Model.GetFavoritesBooks(0, 1000); IEnumerable someBooks = result.books; books.Clear(); favoriteBooks.Clear();