ADD : Ajout de méthode pour avoir les livres selon date/auteur/note

commands-19-09
Lou BRODA 1 year ago
parent dccbbbf8a0
commit 3b2d64ed04

@ -35,8 +35,9 @@
<contentView:SeparatorEntireView/> <contentView:SeparatorEntireView/>
<CollectionView ItemsSource="{Binding FiltrageDateVM.Manager.AllPublishDates}" <CollectionView ItemsSource="{Binding FiltrageDateVM.Manager.AllPublishDates}"
SelectedItem="{Binding FiltrageDateVM.Manager.SelectedDate}"
SelectionChangedCommand="{Binding FiltrageDateVM.Navigator.NavigationCommand}" SelectionChangedCommand="{Binding FiltrageDateVM.Navigator.NavigationCommand}"
SelectionChangedCommandParameter="/tous"> SelectionChangedCommandParameter="{Binding FiltrageDateVM.Manager.SelectedDate}">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:PublishDateVM"> <DataTemplate x:DataType="viewModel:PublishDateVM">
<VerticalStackLayout> <VerticalStackLayout>

@ -28,7 +28,7 @@
SelectionMode="Single" SelectionMode="Single"
SelectionChanged="OnSelectionChanged" SelectionChanged="OnSelectionChanged"
Grid.Row="2"> Grid.Row="2">
<!--<CollectionView.GroupHeaderTemplate> <CollectionView.GroupHeaderTemplate>
<DataTemplate x:DataType="viewModel:BookVM"> <DataTemplate x:DataType="viewModel:BookVM">
<Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}" <Grid BackgroundColor="{AppThemeBinding Light={StaticResource HeaderGray}, Dark={StaticResource Gray900}}"
Grid.Row="0"> Grid.Row="0">
@ -44,7 +44,7 @@
Grid.Column="1"/> Grid.Column="1"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</CollectionView.GroupHeaderTemplate>--> </CollectionView.GroupHeaderTemplate>
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="viewModel:BookVM"> <DataTemplate x:DataType="viewModel:BookVM">
<VerticalStackLayout Margin="10" <VerticalStackLayout Margin="10"

@ -15,6 +15,7 @@
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<view:HeaderPage HeaderTitle="Tous" <view:HeaderPage HeaderTitle="Tous"
@ -24,7 +25,7 @@
Grid.Row="0" Grid.Row="0"
ButtonPlusTappedCommand="{Binding TousVM.Navigator.PopupHomePlusNavigationCommand}" ButtonPlusTappedCommand="{Binding TousVM.Navigator.PopupHomePlusNavigationCommand}"
ButtonBackTappedCommand="{Binding TousVM.Navigator.PopupBackButtonNavigationCommand}"/> ButtonBackTappedCommand="{Binding TousVM.Navigator.PopupBackButtonNavigationCommand}"/>
<ScrollView Grid.Row="2"> <ScrollView Grid.Row="1">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="40"/> <RowDefinition Height="40"/>
@ -121,7 +122,7 @@
<DataTemplate x:DataType="viewModel:AuthorVM"> <DataTemplate x:DataType="viewModel:AuthorVM">
<Label Text="{Binding Name}" <Label Text="{Binding Name}"
Style="{StaticResource MasterAuthorBookText}" Style="{StaticResource MasterAuthorBookText}"
Margin="5,0,5,0"/> Margin="0,0,5,0"/>
</DataTemplate> </DataTemplate>
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>

@ -74,6 +74,10 @@ namespace ViewModels
public AuthorVM SelectedAuthor { get; private set; } public AuthorVM SelectedAuthor { get; private set; }
public PublishDateVM SelectedDate { get; private set; }
public RatingsVM SelectedRating { get; private set; }
public string SearchTitle { get; private set; } public string SearchTitle { get; private set; }
public int Index public int Index
@ -107,6 +111,8 @@ namespace ViewModels
public ICommand GetAllAuthorsCommand { get; private set; } public ICommand GetAllAuthorsCommand { get; private set; }
public ICommand GetBooksByDateCommand { get; private set; }
public ICommand GetAllPublishDatesCommand { get; private set; } public ICommand GetAllPublishDatesCommand { get; private set; }
public ICommand GetAllRatingsCommand { get; private set; } public ICommand GetAllRatingsCommand { get; private set; }
@ -121,6 +127,8 @@ namespace ViewModels
public ICommand GetPastBorrowingsCommand { get; private set; } public ICommand GetPastBorrowingsCommand { get; private set; }
public ICommand GetBooksByRatingCommand { get; private set; }
#endregion #endregion
#region Constructor #region Constructor
@ -132,7 +140,9 @@ namespace ViewModels
GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection()); GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection());
GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor()); GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor());
GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors()); GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors());
GetBooksByDateCommand = new RelayCommand(() => GetBooksByDate());
GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates()); GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates());
GetBooksByRatingCommand = new RelayCommand(() => GetBooksByRating());
GetAllRatingsCommand = new RelayCommand(() => GetAllRatings()); GetAllRatingsCommand = new RelayCommand(() => GetAllRatings());
GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks()); GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks());
GetCurrentLoansCommand = new RelayCommand(() => GetCurrentLoans()); GetCurrentLoansCommand = new RelayCommand(() => GetCurrentLoans());
@ -171,6 +181,7 @@ namespace ViewModels
var result = await Model.GetBooksFromCollection(Index, Count); var result = await Model.GetBooksFromCollection(Index, Count);
NbBooks = result.count; NbBooks = result.count;
IEnumerable<Book> someBooks = result.books; IEnumerable<Book> someBooks = result.books;
someBooks = someBooks.OrderBy(b => b.Status);
books.Clear(); books.Clear();
foreach (var b in someBooks.Select(b => new BookVM(b))) foreach (var b in someBooks.Select(b => new BookVM(b)))
{ {
@ -209,6 +220,22 @@ namespace ViewModels
OnPropertyChanged(nameof(AllAuthors)); OnPropertyChanged(nameof(AllAuthors));
} }
private async Task GetBooksByDate()
{
var result = await Model.GetBooksFromCollection(Index, Count);
NbBooks = result.count;
IEnumerable<Book> someBooks = result.books;
books.Clear();
foreach (var b in someBooks.Select(b => new BookVM(b)))
{
if (b.PublishDate == SelectedDate.PublishDate)
{
books.Add(b);
}
}
OnPropertyChanged(nameof(AllBooks));
}
private async Task GetAllPublishDates() private async Task GetAllPublishDates()
{ {
var result = await Model.GetBooksFromCollection(0, 20); var result = await Model.GetBooksFromCollection(0, 20);
@ -232,29 +259,59 @@ namespace ViewModels
OnPropertyChanged(nameof(AllPublishDates)); OnPropertyChanged(nameof(AllPublishDates));
} }
private async Task GetBooksByRating()
{
var result = await Model.GetBooksFromCollection(Index, Count);
NbBooks = result.count;
IEnumerable<Book> 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)
{
books.Add(new BookVM(book));
}
OnPropertyChanged(nameof(AllBooks));
}
private async Task GetAllRatings() private async Task GetAllRatings()
{ {
var result = await Model.GetBooksFromCollection(0, 20); var result = await Model.GetBooksFromCollection(0, 20);
IEnumerable<Book> someBooks = result.books; IEnumerable<Book> someBooks = result.books;
books.Clear(); books.Clear();
ratings.Clear(); ratings.Clear();
Dictionary<string, List<BookVM>> groupedBooks = new Dictionary<string, List<BookVM>>();
foreach (var b in someBooks.Select(b => new BookVM(b))) foreach (var b in someBooks.Select(b => new BookVM(b)))
{ {
var rating = new RatingsVM { Average = b.UserRating}; var rating = new RatingsVM { Average = b.UserRating };
if (rating.Average != null) if (rating.Average != null)
{ {
rating.NbBooksWritten++; string noteKey = Math.Floor(rating.Average.Value).ToString("0");
ratings.Add(rating);
foreach (var r in ratings) if (!groupedBooks.ContainsKey(noteKey))
{ {
if (rating.Average == r.Average && !rating.Equals(r)) groupedBooks[noteKey] = new List<BookVM>();
{
r.NbBooksWritten++;
ratings.Remove(rating);
}
} }
groupedBooks[noteKey].Add(b);
} }
} }
foreach (var entry in groupedBooks)
{
var noteKey = entry.Key;
var booksWithSameRating = entry.Value;
var rating = new RatingsVM
{
Average = float.Parse(noteKey),
NbBooksWritten = booksWithSameRating.Count
};
ratings.Add(rating);
}
OnPropertyChanged(nameof(AllRatings)); OnPropertyChanged(nameof(AllRatings));
} }

Loading…
Cancel
Save