ADD : Loan & Borrowing selection fonctionnel (ALirePlusTard Book Details ToDo)

commands-19-09
Lou BRODA 1 year ago
parent 456b275a84
commit 5c9c0e67fb

@ -16,6 +16,7 @@ public partial class AppShell : Shell
Routing.RegisterRoute("library/note/", typeof(FiltrageNoteView)); Routing.RegisterRoute("library/note/", typeof(FiltrageNoteView));
Routing.RegisterRoute("library/contacts/", typeof(ContactsView)); Routing.RegisterRoute("library/contacts/", typeof(ContactsView));
Routing.RegisterRoute("library/tous/details/", typeof(DetailsLivreView)); Routing.RegisterRoute("library/tous/details/", typeof(DetailsLivreView));
Routing.RegisterRoute("library/add/", typeof(AddBookView));
InitializeComponent(); InitializeComponent();
} }
} }

@ -65,6 +65,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<MauiXaml Update="View\AddBookView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="View\ALirePlusTardView.xaml"> <MauiXaml Update="View\ALirePlusTardView.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>

@ -42,8 +42,10 @@
Grid.Column="1"/> Grid.Column="1"/>
</Grid> </Grid>
<CollectionView ItemsSource="{Binding ALirePlusTardVM.Manager.ToBeReadBooks}" <CollectionView ItemsSource="{Binding ALirePlusTardVM.Manager.ToBeReadBooks}"
SelectedItem="{Binding ALirePlusTardVM.Manager.SelectedBook}"
SelectionMode="Single" SelectionMode="Single"
SelectionChanged="OnSelectionChanged" SelectionChangedCommand="{Binding ALirePlusTardVM.OnSelectionChangedCommand}"
SelectionChangedCommandParameter="{Binding ALirePlusTardVM.Manager.SelectedBook}"
Grid.Row="2"> Grid.Row="2">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:BookVM"> <DataTemplate x:DataType="viewModel:BookVM">

@ -24,11 +24,6 @@ public partial class ALirePlusTardView : ContentPage
#region Methods #region Methods
void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
//App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView());
}
protected override void OnAppearing() protected override void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LivreLand.View.AddBookView"
Title="AddBookView">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentPage>

@ -0,0 +1,9 @@
namespace LivreLand.View;
public partial class AddBookView : ContentPage
{
public AddBookView()
{
InitializeComponent();
}
}

@ -26,6 +26,10 @@
Margin="10,5,10,5"> Margin="10,5,10,5">
<Label Text="Ajouter un livre" <Label Text="Ajouter un livre"
Style="{StaticResource MasterStateBookText}"/> Style="{StaticResource MasterStateBookText}"/>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Navigator.NavigationCommand}"
CommandParameter="/add"/>
</Grid.GestureRecognizers>
</Grid> </Grid>
<contentView:SeparatorEntireView Grid.Row="1"/> <contentView:SeparatorEntireView Grid.Row="1"/>

@ -22,7 +22,7 @@
HeaderSwitchButtonVisible="False" HeaderSwitchButtonVisible="False"
HeaderColor="{StaticResource HeaderGray}" HeaderColor="{StaticResource HeaderGray}"
ButtonPlusTappedCommand="{Binding DetailsLivreVM.Navigator.PopupHomePlusNavigationCommand}" ButtonPlusTappedCommand="{Binding DetailsLivreVM.Navigator.PopupHomePlusNavigationCommand}"
ButtonBackTappedCommand="{Binding DetailsLivreVM.Navigator.PopupBackButtonNavigationCommand}"/> ButtonBackTappedCommand="{Binding DetailsLivreVM.BackButtonCommand}"/>
<contentView:SeparatorEntireView/> <contentView:SeparatorEntireView/>
</VerticalStackLayout> </VerticalStackLayout>
@ -140,31 +140,31 @@
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Label Text="Maison d'édition" <Label Text="Maison d'édition"
Style="{StaticResource DetailsLivreTitle}" Style="{StaticResource DetailsLivreTitle}"
Grid.Row="0" Grid.Row="0"/>
Grid.Column="0"/> <Grid Grid.Row="1">
<Grid Grid.Row="1" <Grid.ColumnDefinitions>
Grid.Column="1"> <ColumnDefinition Width="auto"/>
<CollectionView ItemsSource="{Binding DetailsLivreVM.Book.Publishers}"> <ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<CollectionView ItemsSource="{Binding DetailsLivreVM.Book.Publishers}"
Grid.Column="0">
<CollectionView.ItemsLayout> <CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal" /> <LinearItemsLayout Orientation="Horizontal" />
</CollectionView.ItemsLayout> </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Label Text="oui" <Label Text="{Binding .}"
Style="{StaticResource DetailsLivreBody}" Style="{StaticResource DetailsLivreBody}"
Margin="0,0,5,0" Margin="0,0,5,0"
Grid.Row="1"/> Grid.Row="1"/>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<Label Text="{Binding DetailsLivreVM.Book.PublishDate,StringFormat=' ({0:yyyy})'}"/> <Label Text="{Binding DetailsLivreVM.Book.PublishDate,StringFormat=' ({0:yyyy})'}"
Grid.Column="1"/>
</Grid> </Grid>
</Grid> </Grid>
@ -223,7 +223,7 @@
<Label Text="Langue" <Label Text="Langue"
Style="{StaticResource DetailsLivreBody}" Style="{StaticResource DetailsLivreBody}"
Grid.Column="0"/> Grid.Column="0"/>
<Label Text="français" <Label Text="{Binding DetailsLivreVM.Book.Language}"
Style="{StaticResource DetailsLivreBody}" Style="{StaticResource DetailsLivreBody}"
Grid.Column="2"/> Grid.Column="2"/>
</Grid> </Grid>

@ -33,8 +33,10 @@
<ScrollView Grid.Row="4"> <ScrollView Grid.Row="4">
<Grid> <Grid>
<CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentLoans}" <CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentLoans}"
SelectedItem="{Binding EmpruntsPretsVM.Manager.SelectedLoan}"
SelectionMode="Single" SelectionMode="Single"
SelectionChanged="OnSelectionChanged" SelectionChangedCommand="{Binding EmpruntsPretsVM.OnSelectionLoanChangedCommand}"
SelectionChangedCommandParameter="{Binding EmpruntsPretsVM.Manager.SelectedBook}"
IsVisible="{Binding EmpruntsPretsVM.PretCollectionIsVisible}"> IsVisible="{Binding EmpruntsPretsVM.PretCollectionIsVisible}">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:LoanVM"> <DataTemplate x:DataType="viewModel:LoanVM">
@ -109,8 +111,10 @@
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentBorrowings}" <CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentBorrowings}"
SelectedItem="{Binding EmpruntsPretsVM.Manager.SelectedBorrowing}"
SelectionMode="Single" SelectionMode="Single"
SelectionChanged="OnSelectionChanged" SelectionChangedCommand="{Binding EmpruntsPretsVM.OnSelectionBorrowingChangedCommand}"
SelectionChangedCommandParameter="{Binding EmpruntsPretsVM.Manager.SelectedBorrowing}"
IsVisible="{Binding EmpruntsPretsVM.EmpruntCollectionIsVisible}"> IsVisible="{Binding EmpruntsPretsVM.EmpruntCollectionIsVisible}">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:BorrowingVM"> <DataTemplate x:DataType="viewModel:BorrowingVM">

@ -24,11 +24,6 @@ public partial class EmpruntsPretsView : ContentPage
#region Methods #region Methods
void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
//App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView());
}
protected override void OnAppearing() protected override void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();

@ -27,8 +27,10 @@
<ScrollView Grid.Row="4"> <ScrollView Grid.Row="4">
<Grid> <Grid>
<CollectionView ItemsSource="{Binding StatutLectureVM.Manager.AllBooks}" <CollectionView ItemsSource="{Binding StatutLectureVM.Manager.AllBooks}"
SelectedItem="{Binding StatutLectureVM.Manager.SelectedBook}"
SelectionMode="Single" SelectionMode="Single"
SelectionChanged="OnSelectionChanged" SelectionChangedCommand="{Binding StatutLectureVM.OnSelectionChangedCommand}"
SelectionChangedCommandParameter="{Binding StatutLectureVM.Manager.SelectedBook}"
Grid.Row="2"> Grid.Row="2">
<CollectionView.GroupHeaderTemplate> <CollectionView.GroupHeaderTemplate>
<DataTemplate x:DataType="viewModel:BookVM"> <DataTemplate x:DataType="viewModel:BookVM">

@ -31,10 +31,5 @@ public partial class StatutLectureView : ContentPage
StatutLectureVM.Manager.GetBooksFromCollectionCommand.Execute(null); StatutLectureVM.Manager.GetBooksFromCollectionCommand.Execute(null);
} }
void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
//App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView());
}
#endregion #endregion
} }

@ -1,9 +1,11 @@
using PersonalMVVMToolkit; using LivreLand.View;
using PersonalMVVMToolkit;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using ViewModels; using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
@ -16,6 +18,8 @@ namespace LivreLand.ViewModel
public ManagerVM Manager { get; private set; } public ManagerVM Manager { get; private set; }
public ICommand OnSelectionChangedCommand { get; private set; }
#endregion #endregion
#region Constructor #region Constructor
@ -24,6 +28,20 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
OnSelectionChangedCommand = new RelayCommand<BookVM>((bookVM) => OnSelectionChanged(bookVM));
}
#endregion
#region Methods
private void OnSelectionChanged(BookVM bookVM)
{
if (bookVM != null)
{
var result = new DetailsLivreVM(Manager, Navigator, bookVM);
App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView(result));
}
} }
#endregion #endregion

@ -65,6 +65,8 @@ namespace LivreLand.ViewModel
} }
} }
public ICommand BackButtonCommand { get; private set; }
public ICommand ShowPickerCommand { get; private set; } public ICommand ShowPickerCommand { get; private set; }
public ICommand AddRemoveBookToFavoritesCommand { get; private set; } public ICommand AddRemoveBookToFavoritesCommand { get; private set; }
@ -82,6 +84,7 @@ namespace LivreLand.ViewModel
Manager = managerVM; Manager = managerVM;
Navigator = navigatorVM; Navigator = navigatorVM;
Book = bookVM; Book = bookVM;
BackButtonCommand = new RelayCommand(() => BackButton());
ShowPickerCommand = new RelayCommand(() => ShowPicker()); ShowPickerCommand = new RelayCommand(() => ShowPicker());
AddRemoveBookToFavoritesCommand = new RelayCommand<BookVM>((bookVM) => AddRemoveBookToFavorites(bookVM)); AddRemoveBookToFavoritesCommand = new RelayCommand<BookVM>((bookVM) => AddRemoveBookToFavorites(bookVM));
AddBookToReadListCommand = new RelayCommand<BookVM>((bookVM) => AddBookToReadList(bookVM)); AddBookToReadListCommand = new RelayCommand<BookVM>((bookVM) => AddBookToReadList(bookVM));
@ -92,6 +95,11 @@ namespace LivreLand.ViewModel
#region Methods #region Methods
private void BackButton()
{
Navigator.PopupBackButtonNavigationCommand.Execute(null);
}
private void ShowPicker() private void ShowPicker()
{ {
Manager.GetAllStatusCommand.Execute(null); Manager.GetAllStatusCommand.Execute(null);

@ -1,4 +1,6 @@
using PersonalMVVMToolkit; using LivreLand.View;
using Model;
using PersonalMVVMToolkit;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -106,6 +108,10 @@ namespace LivreLand.ViewModel
} }
} }
public ICommand OnSelectionLoanChangedCommand { get; private set; }
public ICommand OnSelectionBorrowingChangedCommand { get; private set; }
public ICommand PretsButtonCommand { get; private set; } public ICommand PretsButtonCommand { get; private set; }
public ICommand EmpruntsButtonCommand { get; private set; } public ICommand EmpruntsButtonCommand { get; private set; }
@ -118,6 +124,8 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
OnSelectionLoanChangedCommand = new RelayCommand<LoanVM>((loanVM) => OnSelectionLoanChanged(loanVM));
OnSelectionBorrowingChangedCommand = new RelayCommand<BorrowingVM>((borrowingVM) => OnSelectionBorrowingChanged(borrowingVM));
PretsButtonCommand = new RelayCommand(() => PretsButtonClicked()); PretsButtonCommand = new RelayCommand(() => PretsButtonClicked());
EmpruntsButtonCommand = new RelayCommand(() => EmpruntsButtonClicked()); EmpruntsButtonCommand = new RelayCommand(() => EmpruntsButtonClicked());
} }
@ -126,6 +134,38 @@ namespace LivreLand.ViewModel
#region Methods #region Methods
private void OnSelectionLoanChanged(LoanVM loanVM)
{
if (loanVM == null)
{
foreach (var b in Manager.AllCurrentLoans)
{
if (b.Book.Id == loanVM.Book.Id)
{
var bookCorresponding = b.Book;
var result = new DetailsLivreVM(Manager, Navigator, bookCorresponding);
App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView(result));
}
}
}
}
private void OnSelectionBorrowingChanged(BorrowingVM borrowingVM)
{
if (borrowingVM != null)
{
foreach (var b in Manager.AllCurrentBorrowings)
{
if (b.Book.Id == borrowingVM.Book.Id)
{
var bookCorresponding = b.Book;
var result = new DetailsLivreVM(Manager, Navigator, bookCorresponding);
App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView(result));
}
}
}
}
public void PretsButtonClicked() public void PretsButtonClicked()
{ {
if (App.Current.PlatformAppTheme == AppTheme.Light) if (App.Current.PlatformAppTheme == AppTheme.Light)

@ -1,9 +1,11 @@
using PersonalMVVMToolkit; using LivreLand.View;
using PersonalMVVMToolkit;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using ViewModels; using ViewModels;
namespace LivreLand.ViewModel namespace LivreLand.ViewModel
@ -16,6 +18,8 @@ namespace LivreLand.ViewModel
public ManagerVM Manager { get; private set; } public ManagerVM Manager { get; private set; }
public ICommand OnSelectionChangedCommand { get; private set; }
#endregion #endregion
#region Constructor #region Constructor
@ -24,6 +28,20 @@ namespace LivreLand.ViewModel
{ {
Navigator = navigatorVM; Navigator = navigatorVM;
Manager = managerVM; Manager = managerVM;
OnSelectionChangedCommand = new RelayCommand<BookVM>((bookVM) => OnSelectionChanged(bookVM));
}
#endregion
#region Methods
private void OnSelectionChanged(BookVM bookVM)
{
if (bookVM != null)
{
var result = new DetailsLivreVM(Manager, Navigator, bookVM);
App.Current.MainPage.Navigation.PushAsync(new DetailsLivreView(result));
}
} }
#endregion #endregion

@ -19,6 +19,7 @@ namespace LivreLand.ViewModel
public ManagerVM Manager { get; private set; } public ManagerVM Manager { get; private set; }
public ICommand OnSelectionChangedCommand { get; private set; } public ICommand OnSelectionChangedCommand { get; private set; }
#endregion #endregion
#region Constructor #region Constructor

@ -64,6 +64,12 @@ namespace ViewModels
set => SetProperty(Model.NbPages, value, v => Model.NbPages = value); set => SetProperty(Model.NbPages, value, v => Model.NbPages = value);
} }
public Languages Language
{
get => Model.Language;
set => SetProperty(Model.Language, value, v => Model.Language = value);
}
public string ImageSmall public string ImageSmall
{ {
get => Model.ImageSmall; get => Model.ImageSmall;

@ -33,6 +33,8 @@ namespace ViewModels
private RatingsVM selectedRating; private RatingsVM selectedRating;
private Status selectedStatus; private Status selectedStatus;
private ContactVM selectedContact; private ContactVM selectedContact;
private LoanVM selectedLoan;
private BorrowingVM selectedBorrowing;
private string givenFirstName; private string givenFirstName;
private string givenLastName; private string givenLastName;
@ -180,6 +182,32 @@ namespace ViewModels
} }
} }
public LoanVM SelectedLoan
{
get { return selectedLoan; }
set
{
if (selectedLoan != value)
{
selectedLoan = value;
OnPropertyChanged(nameof(SelectedLoan));
}
}
}
public BorrowingVM SelectedBorrowing
{
get { return selectedBorrowing; }
set
{
if (selectedBorrowing != value)
{
selectedBorrowing = value;
OnPropertyChanged(nameof(SelectedBorrowing));
}
}
}
public string GivenFirstName public string GivenFirstName
{ {
get { return givenFirstName; } get { return givenFirstName; }
@ -249,6 +277,8 @@ namespace ViewModels
public ICommand GetBooksFromCollectionCommand { get; private set; } public ICommand GetBooksFromCollectionCommand { get; private set; }
public ICommand AddBookCommand { get; private set; }
public ICommand UpdateBookCommand { get; private set; } public ICommand UpdateBookCommand { get; private set; }
public ICommand UpdateStatusBookCommand { get; private set; } public ICommand UpdateStatusBookCommand { get; private set; }
@ -304,6 +334,7 @@ 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());
AddBookCommand = new RelayCommand<BookVM>((bookVM) => AddBook(bookVM));
UpdateBookCommand = new RelayCommand<BookVM>((bookVM) => UpdateBook(bookVM)); UpdateBookCommand = new RelayCommand<BookVM>((bookVM) => UpdateBook(bookVM));
UpdateStatusBookCommand = new RelayCommand<BookVM>((bookVM) => UpdateStatusBook(bookVM)); UpdateStatusBookCommand = new RelayCommand<BookVM>((bookVM) => UpdateStatusBook(bookVM));
UpdateToBeReadBookCommand = new RelayCommand<BookVM>((bookVM) => UpdateToBeReadBook(bookVM)); UpdateToBeReadBookCommand = new RelayCommand<BookVM>((bookVM) => UpdateToBeReadBook(bookVM));
@ -368,6 +399,12 @@ namespace ViewModels
OnPropertyChanged(nameof(AllBooks)); OnPropertyChanged(nameof(AllBooks));
} }
private async Task AddBook(BookVM bookVM)
{
await Model.AddBookToCollection(bookVM.Id);
GetBooksFromCollectionCommand.Execute(null);
}
private async Task UpdateBook(BookVM bookVM) private async Task UpdateBook(BookVM bookVM)
{ {
var book = await Model.GetBookById(bookVM.Id); var book = await Model.GetBookById(bookVM.Id);

Loading…
Cancel
Save