ADD : Order Books By Author, Loaner or Owner & Status in different pages (Header Style ToFix)

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

@ -125,7 +125,7 @@
<DataTemplate x:DataType="viewModel:AuthorVM"> <DataTemplate x:DataType="viewModel:AuthorVM">
<Label Text="{Binding Name}" <Label Text="{Binding Name}"
Style="{StaticResource DetailsLivreBody}" Style="{StaticResource DetailsLivreBody}"
Margin="0,0,5,0" Margin="0,0,1,0"
Grid.Row="1"/> Grid.Row="1"/>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
@ -145,26 +145,24 @@
Style="{StaticResource DetailsLivreTitle}" Style="{StaticResource DetailsLivreTitle}"
Grid.Row="0"/> Grid.Row="0"/>
<Grid Grid.Row="1"> <Grid Grid.Row="1">
<Grid.ColumnDefinitions> <HorizontalStackLayout>
<ColumnDefinition Width="auto"/> <CollectionView ItemsSource="{Binding DetailsLivreVM.Book.Publishers}"
<ColumnDefinition Width="auto"/> Grid.Column="0">
</Grid.ColumnDefinitions> <CollectionView.ItemsLayout>
<CollectionView ItemsSource="{Binding DetailsLivreVM.Book.Publishers}" <LinearItemsLayout Orientation="Horizontal" />
Grid.Column="0"> </CollectionView.ItemsLayout>
<CollectionView.ItemsLayout> <CollectionView.ItemTemplate>
<LinearItemsLayout Orientation="Horizontal" /> <DataTemplate>
</CollectionView.ItemsLayout> <Label Text="{Binding .}"
<CollectionView.ItemTemplate> Style="{StaticResource DetailsLivreBody}"
<DataTemplate> Margin="0,0,1,0"
<Label Text="{Binding .}" Grid.Row="1"/>
Style="{StaticResource DetailsLivreBody}" </DataTemplate>
Margin="0,0,5,0" </CollectionView.ItemTemplate>
Grid.Row="1"/> </CollectionView>
</DataTemplate> <Label Text="{Binding DetailsLivreVM.Book.PublishDate,StringFormat=' ({0:yyyy})'}"
</CollectionView.ItemTemplate> Grid.Column="1"/>
</CollectionView> </HorizontalStackLayout>
<Label Text="{Binding DetailsLivreVM.Book.PublishDate,StringFormat=' ({0:yyyy})'}"
Grid.Column="1"/>
</Grid> </Grid>
</Grid> </Grid>

@ -32,12 +32,35 @@
EmpruntsButtonCommand="{Binding EmpruntsPretsVM.EmpruntsButtonCommand}"/> EmpruntsButtonCommand="{Binding EmpruntsPretsVM.EmpruntsButtonCommand}"/>
<ScrollView Grid.Row="4"> <ScrollView Grid.Row="4">
<Grid> <Grid>
<CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentLoans}" <CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentGroupedLoans}"
SelectedItem="{Binding EmpruntsPretsVM.Manager.SelectedLoan}" SelectedItem="{Binding EmpruntsPretsVM.Manager.SelectedLoan}"
SelectionMode="Single" SelectionMode="Single"
SelectionChangedCommand="{Binding EmpruntsPretsVM.OnSelectionLoanChangedCommand}" SelectionChangedCommand="{Binding EmpruntsPretsVM.OnSelectionLoanChangedCommand}"
SelectionChangedCommandParameter="{Binding EmpruntsPretsVM.Manager.SelectedBook}" SelectionChangedCommandParameter="{Binding EmpruntsPretsVM.Manager.SelectedBook}"
IsVisible="{Binding EmpruntsPretsVM.PretCollectionIsVisible}"> IsVisible="{Binding EmpruntsPretsVM.PretCollectionIsVisible}"
IsGrouped="True">
<CollectionView.GroupHeaderTemplate>
<DataTemplate>
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}"
Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label VerticalOptions="Center"
Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1">
<Label.Text>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="Key.FirstName" />
<Binding Path="Key.LastName" />
</MultiBinding>
</Label.Text>
</Label>
</Grid>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:LoanVM"> <DataTemplate x:DataType="viewModel:LoanVM">
<VerticalStackLayout Margin="10" <VerticalStackLayout Margin="10"
@ -110,12 +133,35 @@
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
<CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentBorrowings}" <CollectionView ItemsSource="{Binding EmpruntsPretsVM.Manager.AllCurrentGroupedBorrowings}"
SelectedItem="{Binding EmpruntsPretsVM.Manager.SelectedBorrowing}" SelectedItem="{Binding EmpruntsPretsVM.Manager.SelectedBorrowing}"
SelectionMode="Single" SelectionMode="Single"
SelectionChangedCommand="{Binding EmpruntsPretsVM.OnSelectionBorrowingChangedCommand}" SelectionChangedCommand="{Binding EmpruntsPretsVM.OnSelectionBorrowingChangedCommand}"
SelectionChangedCommandParameter="{Binding EmpruntsPretsVM.Manager.SelectedBorrowing}" SelectionChangedCommandParameter="{Binding EmpruntsPretsVM.Manager.SelectedBorrowing}"
IsVisible="{Binding EmpruntsPretsVM.EmpruntCollectionIsVisible}"> IsVisible="{Binding EmpruntsPretsVM.EmpruntCollectionIsVisible}"
IsGrouped="True">
<CollectionView.GroupHeaderTemplate>
<DataTemplate>
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}"
Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label VerticalOptions="Center"
Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1">
<Label.Text>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="Key.FirstName" />
<Binding Path="Key.LastName" />
</MultiBinding>
</Label.Text>
</Label>
</Grid>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:BorrowingVM"> <DataTemplate x:DataType="viewModel:BorrowingVM">
<VerticalStackLayout Margin="10" <VerticalStackLayout Margin="10"

@ -26,14 +26,15 @@
<contentView:SearchBarView Grid.Row="2"/> <contentView:SearchBarView Grid.Row="2"/>
<ScrollView Grid.Row="4"> <ScrollView Grid.Row="4">
<Grid> <Grid>
<CollectionView ItemsSource="{Binding StatutLectureVM.Manager.AllBooks}" <CollectionView ItemsSource="{Binding StatutLectureVM.Manager.GroupedStatusBooks}"
SelectedItem="{Binding StatutLectureVM.Manager.SelectedBook}" SelectedItem="{Binding StatutLectureVM.Manager.SelectedBook}"
SelectionMode="Single" SelectionMode="Single"
SelectionChangedCommand="{Binding StatutLectureVM.OnSelectionChangedCommand}" SelectionChangedCommand="{Binding StatutLectureVM.OnSelectionChangedCommand}"
SelectionChangedCommandParameter="{Binding StatutLectureVM.Manager.SelectedBook}" SelectionChangedCommandParameter="{Binding StatutLectureVM.Manager.SelectedBook}"
IsGrouped="True"
Grid.Row="2"> Grid.Row="2">
<CollectionView.GroupHeaderTemplate> <CollectionView.GroupHeaderTemplate>
<DataTemplate x:DataType="viewModel:BookVM"> <DataTemplate>
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}" <Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}"
Grid.Row="0"> Grid.Row="0">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@ -41,8 +42,7 @@
<ColumnDefinition Width="auto"/> <ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label Text="{Binding Key}"
<Label Text="{Binding Status}"
VerticalOptions="Center" VerticalOptions="Center"
Style="{StaticResource HeaderCollectionViewText}" Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1"/> Grid.Column="1"/>

@ -36,14 +36,15 @@
<RowDefinition Height="10"/> <RowDefinition Height="10"/>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<CollectionView ItemsSource="{Binding TousVM.Manager.AllBooks}" <CollectionView ItemsSource="{Binding TousVM.Manager.GroupedBooks}"
SelectedItem="{Binding TousVM.Manager.SelectedBook}" SelectedItem="{Binding TousVM.Manager.SelectedBook}"
SelectionMode="Single" SelectionMode="Single"
SelectionChangedCommand="{Binding TousVM.OnSelectionChangedCommand}" SelectionChangedCommand="{Binding TousVM.OnSelectionChangedCommand}"
SelectionChangedCommandParameter="{Binding TousVM.Manager.SelectedBook}" SelectionChangedCommandParameter="{Binding TousVM.Manager.SelectedBook}"
IsGrouped="True"
Grid.Row="2"> Grid.Row="2">
<CollectionView.GroupHeaderTemplate> <CollectionView.GroupHeaderTemplate>
<DataTemplate x:DataType="viewModel:BookVM"> <DataTemplate>
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}" <Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}"
Grid.Row="0"> Grid.Row="0">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@ -51,7 +52,7 @@
<ColumnDefinition Width="auto"/> <ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label Text="Alain Damasio" <Label Text="{Binding Key}"
VerticalOptions="Center" VerticalOptions="Center"
Style="{StaticResource HeaderCollectionViewText}" Style="{StaticResource HeaderCollectionViewText}"
Grid.Column="1"/> Grid.Column="1"/>

@ -20,31 +20,26 @@ namespace ViewModels
public string Id public string Id
{ {
get => Model.Id; get => Model.Id;
set => SetProperty(Model.Id, value, v => Model.Id = value);
} }
public string ISBN13 public string ISBN13
{ {
get => Model.ISBN13; get => Model.ISBN13;
set => SetProperty(Model.ISBN13, value, v => Model.ISBN13 = value);
} }
public string Title public string Title
{ {
get => Model.Title; get => Model.Title;
set => SetProperty(Model.Title, value, v => Model.Title = value);
} }
public List<string> Publishers public List<string> Publishers
{ {
get => Model.Publishers; get => Model.Publishers;
set => SetProperty(Model.Publishers, value, v => Model.Publishers = value);
} }
public DateTime PublishDate public DateTime PublishDate
{ {
get => Model.PublishDate; get => Model.PublishDate;
set => SetProperty(Model.PublishDate, value, v => Model.PublishDate = value);
} }
public List<AuthorVM> Authors public List<AuthorVM> Authors
@ -52,22 +47,21 @@ namespace ViewModels
get => Model.Authors.Select(a => new AuthorVM(a)).ToList(); get => Model.Authors.Select(a => new AuthorVM(a)).ToList();
} }
public string Author => Model.Authors.Count > 0 ? Model.Authors.First().Name : "Auteur inconnu";
public Status Status public Status Status
{ {
get => Model.Status; get => Model.Status;
set => SetProperty(Model.Status, value, v => Model.Status = value);
} }
public int NbPages public int NbPages
{ {
get => Model.NbPages; get => Model.NbPages;
set => SetProperty(Model.NbPages, value, v => Model.NbPages = value);
} }
public Languages Language public Languages Language
{ {
get => Model.Language; get => Model.Language;
set => SetProperty(Model.Language, value, v => Model.Language = value);
} }
public string ImageSmall public string ImageSmall

@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Input; using System.Windows.Input;
using static System.Reflection.Metadata.BlobBuilder;
namespace ViewModels namespace ViewModels
{ {
@ -13,17 +14,29 @@ namespace ViewModels
#region Fields #region Fields
private readonly ObservableCollection<BookVM> books = new ObservableCollection<BookVM>(); private readonly ObservableCollection<BookVM> books = new ObservableCollection<BookVM>();
private IEnumerable<IGrouping<string, BookVM>> groupedBooks;
private IEnumerable<IGrouping<Status, BookVM>> groupedStatusBooks;
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 readonly ObservableCollection<PublishDateVM> publishDates = new ObservableCollection<PublishDateVM>();
private readonly ObservableCollection<RatingsVM> ratings = new ObservableCollection<RatingsVM>(); private readonly ObservableCollection<RatingsVM> ratings = new ObservableCollection<RatingsVM>();
private readonly ObservableCollection<BookVM> toBeReadBooks = new ObservableCollection<BookVM>(); private readonly ObservableCollection<BookVM> toBeReadBooks = new ObservableCollection<BookVM>();
private readonly ObservableCollection<BookVM> favoriteBooks = new ObservableCollection<BookVM>(); private readonly ObservableCollection<BookVM> favoriteBooks = new ObservableCollection<BookVM>();
private readonly ObservableCollection<LoanVM> currentLoans = new ObservableCollection<LoanVM>(); private readonly ObservableCollection<LoanVM> currentLoans = new ObservableCollection<LoanVM>();
private IEnumerable<IGrouping<ContactVM, LoanVM>> currentGroupedLoans;
private readonly ObservableCollection<LoanVM> pastLoans = new ObservableCollection<LoanVM>(); private readonly ObservableCollection<LoanVM> pastLoans = new ObservableCollection<LoanVM>();
private readonly ObservableCollection<BorrowingVM> pastBorrowings = new ObservableCollection<BorrowingVM>(); private IEnumerable<IGrouping<ContactVM, LoanVM>> pastGroupedLoans;
private readonly ObservableCollection<BorrowingVM> currentBorrowings = new ObservableCollection<BorrowingVM>(); private readonly ObservableCollection<BorrowingVM> currentBorrowings = new ObservableCollection<BorrowingVM>();
private IEnumerable<IGrouping<ContactVM, BorrowingVM>> currentGroupedBorrowings;
private readonly ObservableCollection<BorrowingVM> pastBorrowings = new ObservableCollection<BorrowingVM>();
private IEnumerable<IGrouping<ContactVM, BorrowingVM>> pastGroupedBorrowings;
private readonly ObservableCollection<ContactVM> contacts = new ObservableCollection<ContactVM>(); private readonly ObservableCollection<ContactVM> contacts = new ObservableCollection<ContactVM>();
private readonly ObservableCollection<Status> status = new ObservableCollection<Status>(); private readonly ObservableCollection<Status> status = new ObservableCollection<Status>();
private int index; private int index;
private long nbBooks; private long nbBooks;
@ -49,6 +62,18 @@ namespace ViewModels
get => books; get => books;
} }
public IEnumerable<IGrouping<string, BookVM>> GroupedBooks
{
get => groupedBooks;
set => SetProperty(ref groupedBooks, value);
}
public IEnumerable<IGrouping<Status, BookVM>> GroupedStatusBooks
{
get => groupedStatusBooks;
set => SetProperty(ref groupedStatusBooks, value);
}
public ObservableCollection<AuthorVM> AllAuthors public ObservableCollection<AuthorVM> AllAuthors
{ {
get => authors; get => authors;
@ -79,21 +104,45 @@ namespace ViewModels
get => currentLoans; get => currentLoans;
} }
public IEnumerable<IGrouping<ContactVM, LoanVM>> AllCurrentGroupedLoans
{
get => currentGroupedLoans;
set => SetProperty(ref currentGroupedLoans, value);
}
public ObservableCollection<LoanVM> AllPastLoans public ObservableCollection<LoanVM> AllPastLoans
{ {
get => pastLoans; get => pastLoans;
} }
public IEnumerable<IGrouping<ContactVM, LoanVM>> AllPastGroupedLoans
{
get => pastGroupedLoans;
set => SetProperty(ref pastGroupedLoans, value);
}
public ObservableCollection<BorrowingVM> AllCurrentBorrowings public ObservableCollection<BorrowingVM> AllCurrentBorrowings
{ {
get => currentBorrowings; get => currentBorrowings;
} }
public IEnumerable<IGrouping<ContactVM, BorrowingVM>> AllCurrentGroupedBorrowings
{
get => currentGroupedBorrowings;
set => SetProperty(ref currentGroupedBorrowings, value);
}
public ObservableCollection<BorrowingVM> AllPastBorrowings public ObservableCollection<BorrowingVM> AllPastBorrowings
{ {
get => pastBorrowings; get => pastBorrowings;
} }
public IEnumerable<IGrouping<ContactVM, BorrowingVM>> AllPastGroupedBorrowings
{
get => pastGroupedBorrowings;
set => SetProperty(ref pastGroupedBorrowings, value);
}
public ObservableCollection<ContactVM> AllContacts public ObservableCollection<ContactVM> AllContacts
{ {
get => contacts; get => contacts;
@ -267,7 +316,7 @@ namespace ViewModels
} }
} }
public int NbPages => (int)(NbBooks / Count); public int NbPages => (int)((NbBooks - 1) / Count);
public ICommand PreviousCommand { get; private set; } public ICommand PreviousCommand { get; private set; }
@ -394,7 +443,9 @@ namespace ViewModels
books.Clear(); books.Clear();
foreach (var b in someBooks.Select(b => new BookVM(b))) foreach (var b in someBooks.Select(b => new BookVM(b)))
{ {
books.Add(b); books.Add(b);
GroupedBooks = AllBooks.GroupBy(b => b.Author).OrderBy(group => group.Key);
GroupedStatusBooks = AllBooks.GroupBy(b => b.Status).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(AllBooks)); OnPropertyChanged(nameof(AllBooks));
} }
@ -628,48 +679,52 @@ namespace ViewModels
private async Task GetCurrentLoans() private async Task GetCurrentLoans()
{ {
var result = await Model.GetCurrentLoans(0, 20); var result = await Model.GetCurrentLoans(0, 1000);
IEnumerable<Loan> someLoans = result.loans; IEnumerable<Loan> someLoans = result.loans;
currentLoans.Clear(); currentLoans.Clear();
foreach (var l in someLoans.Select(l => new LoanVM(l))) foreach (var l in someLoans.Select(l => new LoanVM(l)))
{ {
currentLoans.Add(l); currentLoans.Add(l);
AllCurrentGroupedLoans = AllCurrentLoans.GroupBy(l => l.Loaner).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(AllCurrentLoans)); OnPropertyChanged(nameof(AllCurrentLoans));
} }
private async Task GetPastLoans() private async Task GetPastLoans()
{ {
var result = await Model.GetPastLoans(0, 20); var result = await Model.GetPastLoans(0, 1000);
IEnumerable<Loan> someLoans = result.loans; IEnumerable<Loan> someLoans = result.loans;
pastLoans.Clear(); pastLoans.Clear();
foreach (var l in someLoans.Select(l => new LoanVM(l))) foreach (var l in someLoans.Select(l => new LoanVM(l)))
{ {
pastLoans.Add(l); pastLoans.Add(l);
AllPastGroupedLoans = AllPastLoans.GroupBy(l => l.Loaner).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(AllPastLoans)); OnPropertyChanged(nameof(AllPastLoans));
} }
private async Task GetCurrentBorrowings() private async Task GetCurrentBorrowings()
{ {
var result = await Model.GetCurrentBorrowings(0, 20); var result = await Model.GetCurrentBorrowings(0, 1000);
IEnumerable<Borrowing> someBorrowings = result.borrowings; IEnumerable<Borrowing> someBorrowings = result.borrowings;
currentBorrowings.Clear(); currentBorrowings.Clear();
foreach (var b in someBorrowings.Select(b => new BorrowingVM(b))) foreach (var b in someBorrowings.Select(b => new BorrowingVM(b)))
{ {
currentBorrowings.Add(b); currentBorrowings.Add(b);
AllCurrentGroupedBorrowings = AllCurrentBorrowings.GroupBy(b => b.Owner).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(AllCurrentBorrowings)); OnPropertyChanged(nameof(AllCurrentBorrowings));
} }
private async Task GetPastBorrowings() private async Task GetPastBorrowings()
{ {
var result = await Model.GetPastBorrowings(0, 20); var result = await Model.GetPastBorrowings(0, 1000);
IEnumerable<Borrowing> someBorrowings = result.borrowings; IEnumerable<Borrowing> someBorrowings = result.borrowings;
pastBorrowings.Clear(); pastBorrowings.Clear();
foreach (var b in someBorrowings.Select(b => new BorrowingVM(b))) foreach (var b in someBorrowings.Select(b => new BorrowingVM(b)))
{ {
pastBorrowings.Add(b); pastBorrowings.Add(b);
AllPastGroupedBorrowings = AllPastBorrowings.GroupBy(b => b.Owner).OrderBy(group => group.Key);
} }
OnPropertyChanged(nameof(AllPastBorrowings)); OnPropertyChanged(nameof(AllPastBorrowings));
} }

Loading…
Cancel
Save