Add(Back-End): SearchBar
continuous-integration/drone/push Build is failing Details

Back-End
Louis DUFOUR 1 year ago
parent 2469160920
commit e76d6724de

@ -5,7 +5,7 @@
xmlns:vm="clr-namespace:BookApp.ViewModel" xmlns:vm="clr-namespace:BookApp.ViewModel"
xmlns:model="clr-namespace:Model;assembly=Model" xmlns:model="clr-namespace:Model;assembly=Model"
x:Class="BookApp.Composants.CollectionFiltrage"> x:Class="BookApp.Composants.CollectionFiltrage">
<CollectionView ItemsSource="{Binding authorList}"> <CollectionView ItemsSource="{Binding AuthorList}" x:Name="collectionView">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Author"> <DataTemplate x:DataType="model:Author">
<StackLayout Padding="5"> <StackLayout Padding="5">
@ -22,7 +22,7 @@
</Image.Behaviors> </Image.Behaviors>
</Image> </Image>
<Label Grid.Column="1" Margin="10,0,0,0" VerticalTextAlignment="Center" Text="{Binding Name}"/> <Label Grid.Column="1" Margin="10,0,0,0" VerticalTextAlignment="Center" Text="{Binding Name}"/>
<!-- <Label Grid.Column="2" VerticalTextAlignment="Center" Margin="0,0,40,0" HorizontalTextAlignment="End" Text="{Binding NbLivre}"/> --> <Label Grid.Column="2" VerticalTextAlignment="Center" Margin="0,0,40,0" HorizontalTextAlignment="End" Text="{Binding Source={x:Reference collectionView}, Path=BindingContext.TotalBooks}"/>
<Button Grid.Column="2" <Button Grid.Column="2"
ImageSource="chevron_right.svg" ImageSource="chevron_right.svg"
HeightRequest="35" HeightRequest="35"

@ -7,7 +7,7 @@ public partial class ToggleSwitchView : ContentView
InitializeComponent(); InitializeComponent();
} }
// Gestionnaire d'événements pour le changement d'état du switch // Gestionnaire d'<EFBFBD>v<EFBFBD>nements pour le changement d'<27>tat du switch
private void OnToggled(object sender, ToggledEventArgs e) private void OnToggled(object sender, ToggledEventArgs e)
{ {
if (e.Value) // Si c'est ON if (e.Value) // Si c'est ON

@ -32,7 +32,6 @@ namespace BookApp
builder.Services.AddSingleton<IUserLibraryManager, UserLibraryStub>(); builder.Services.AddSingleton<IUserLibraryManager, UserLibraryStub>();
builder.Services.AddSingleton<BooksViewModel>(); builder.Services.AddSingleton<BooksViewModel>();
builder.Services.AddSingleton<FilterViewModel>(); builder.Services.AddSingleton<FilterViewModel>();
builder.Services.AddSingleton<SearchBarViewModel>();
builder.Services.AddSingleton<DetailBookViewModel>(); builder.Services.AddSingleton<DetailBookViewModel>();
builder.Services.AddSingleton<ViewModelDetailProvider>(); builder.Services.AddSingleton<ViewModelDetailProvider>();
@ -47,8 +46,6 @@ namespace BookApp
builder.Services.AddSingleton<MainPage>(); builder.Services.AddSingleton<MainPage>();
builder.Services.AddSingleton<EmpruntsPrets>(); builder.Services.AddSingleton<EmpruntsPrets>();
// transient pour recharger la data à l'execute
return builder.Build(); return builder.Build();
} }
} }

@ -55,7 +55,10 @@
<ContentPage.Content> <ContentPage.Content>
<StackLayout> <StackLayout>
<Rectangle HeightRequest="1" BackgroundColor="LightGray"/> <Rectangle HeightRequest="1" BackgroundColor="LightGray"/>
<SearchBar Placeholder="Search items..."/> <SearchBar Placeholder="Rechercher des auteurs..."
Text="{Binding SearchQuery, Mode=TwoWay}"
SearchCommand="{Binding SearchCommand}"
SearchCommandParameter="{Binding Text, Source={x:Reference Name=SearchBar}}"/>
<composants:CollectionFiltrage/> <composants:CollectionFiltrage/>
</StackLayout> </StackLayout>
</ContentPage.Content> </ContentPage.Content>

@ -7,8 +7,6 @@ namespace BookApp.Pages
[QueryProperty(nameof(Title), "Title")] [QueryProperty(nameof(Title), "Title")]
public partial class Filtrage : ContentPage public partial class Filtrage : ContentPage
{ {
SearchBar searchBar = new SearchBar { Placeholder = "Search items..." };
private readonly string Title; private readonly string Title;
public ViewModelNavigation Nav { get; } = new ViewModelNavigation(); public ViewModelNavigation Nav { get; } = new ViewModelNavigation();

@ -20,7 +20,12 @@ namespace BookApp.UseCase
return string.Empty; return string.Empty;
} }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(
object value,
Type targetType,
object parameter,
CultureInfo culture
)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

@ -40,17 +40,25 @@ namespace BookApp.ViewModel
// Command Pop-up // Command Pop-up
public ICommand _popUpCommand; public ICommand _popUpCommand;
public ICommand PopUpCommand => public ICommand PopUpCommand => _popUpCommand ??= new CommandPersonnal(ShowPopUP);
_popUpCommand ??= new CommandPersonnal(ShowPopUP);
public ViewModelDetailProvider(DetailBookViewModel detailBookViewModel) public ViewModelDetailProvider(DetailBookViewModel detailBookViewModel)
{ {
_detailBookViewModel = _detailBookViewModel =
detailBookViewModel ?? throw new ArgumentNullException(nameof(detailBookViewModel)); detailBookViewModel ?? throw new ArgumentNullException(nameof(detailBookViewModel));
} }
private async void ShowPopUP() private async void ShowPopUP()
{ {
string action = await DisplayActionSheet("Quel est le statut du livre ?", "Cancel", null, "Finished", "Reading", "NotRead", "ToBeRead"); string action = await DisplayActionSheet(
"Quel est le statut du livre ?",
"Cancel",
null,
"Finished",
"Reading",
"NotRead",
"ToBeRead"
);
switch (action) switch (action)
{ {
case "Finished": case "Finished":
@ -81,13 +89,22 @@ namespace BookApp.ViewModel
BookDetail.Status = Status.Unknown; BookDetail.Status = Status.Unknown;
OnPropertyChanged(nameof(BookDetail)); OnPropertyChanged(nameof(BookDetail));
break; break;
} }
} }
public async Task<string> DisplayActionSheet(string title, string cancel, string destruction, params string[] buttons) public async Task<string> DisplayActionSheet(
string title,
string cancel,
string destruction,
params string[] buttons
)
{ {
return await Application.Current.MainPage.DisplayActionSheet(title, cancel, destruction, buttons); return await Application.Current.MainPage.DisplayActionSheet(
title,
cancel,
destruction,
buttons
);
} }
private async void LoadBookDetailAsync(string bookId) private async void LoadBookDetailAsync(string bookId)

@ -102,8 +102,9 @@ namespace BookApp.ViewModel
private void SelectTab(string route) private void SelectTab(string route)
{ {
var shellItem = Shell.Current.Items.FirstOrDefault(item => var shellItem = Shell.Current.Items.FirstOrDefault(
item.Items.Any(section => section.Route.Contains(route))); item => item.Items.Any(section => section.Route.Contains(route))
);
if (shellItem != null) if (shellItem != null)
{ {

@ -5,7 +5,6 @@ namespace ToolKit
{ {
public class ObservableBook : BaseViewModel public class ObservableBook : BaseViewModel
{ {
private Book _book; private Book _book;
public Book Book public Book Book
{ {

@ -64,7 +64,6 @@ namespace VMWrapper
var observableBooks = new ObservableCollection<Book>(books); var observableBooks = new ObservableCollection<Book>(books);
AuteurGroups.Add(new AuteurGroup(author.Name, observableBooks)); AuteurGroups.Add(new AuteurGroup(author.Name, observableBooks));
} }
} }
catch (Exception ex) catch (Exception ex)
@ -84,7 +83,6 @@ namespace VMWrapper
} }
} }
public async Task RemoveBookById(string bookId) public async Task RemoveBookById(string bookId)
{ {
await userLibraryManager.RemoveBook(bookId); await userLibraryManager.RemoveBook(bookId);
@ -105,7 +103,5 @@ namespace VMWrapper
} }
OnPropertyChanged(nameof(AuteurGroups)); OnPropertyChanged(nameof(AuteurGroups));
} }
} }
} }

@ -2,53 +2,135 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
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 ToolKit;
using static System.Runtime.InteropServices.JavaScript.JSType; using static System.Runtime.InteropServices.JavaScript.JSType;
namespace VMWrapper namespace VMWrapper
{ {
public class FilterViewModel public class FilterViewModel: BaseViewModel
{ {
private readonly ILibraryManager data; private readonly ILibraryManager data;
public ObservableCollection<Author> authorList { get; private set; } = public ObservableCollection<Author> AuthorList { get; private set; } =
new ObservableCollection<Author>(); new ObservableCollection<Author>();
public ObservableCollection<Book> bookList { get; private set; } = public ObservableCollection<Book> BookList { get; private set; } =
new ObservableCollection<Book>(); new ObservableCollection<Book>();
private long _totalBooks;
public long TotalBooks
{
get { return _totalBooks; }
set
{
_totalBooks = value;
OnPropertyChanged();
}
}
private string _searchQuery;
public string SearchQuery
{
get => _searchQuery;
set
{
if (_searchQuery != value)
{
_searchQuery = value;
OnPropertyChanged(nameof(SearchQuery));
_ = SearchAuthors(SearchQuery);
}
}
}
private ICommand _searchCommand;
public ICommand SearchCommand =>
_searchCommand ??= new CommandPersonnal<string>(
async (query) => await SearchAuthors(query)
);
public FilterViewModel(ILibraryManager data) public FilterViewModel(ILibraryManager data)
{ {
this.data = data; this.data = data;
GetAuthors(); _ = GetAuthorsAsync();
} }
private async void GetDatePublish() private async Task GetDatePublish()
{ {
try try
{ {
var books = data.GetBooksByAuthor("", 0, 5).Result.Item2; var result = await data.GetBooksByAuthor("", 0, 5);
var books = result.Item2;
BookList.Clear();
foreach (Book book in books) foreach (Book book in books)
{ {
bookList.Add(book); BookList.Add(book);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
System.Diagnostics.Debug.WriteLine(ex.Message); Debug.WriteLine(ex.Message);
} }
} }
public void GetAuthors() public async Task GetAuthorsAsync()
{
try
{ {
var objet = data.GetAuthorsByName("", 0, 10).Result.Item2; var result = await data.GetAuthorsByName("", 0, 10);
var authors = result.Item2;
authorList.Clear(); AuthorList.Clear();
foreach (var author in objet) foreach (var author in authors)
{
AuthorList.Add(author);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
private async Task SearchAuthors(string query)
{
try
{
if (!string.IsNullOrWhiteSpace(query))
{
TotalBooks = 0;
var (total, authors) = await data.GetAuthorsByName(query, 0, 10);
AuthorList.Clear();
foreach (Author author in authors)
{
var (totalB, books) = data.GetBooksByAuthor(author.Name, 0, 10).Result;
TotalBooks += totalB;
}
foreach (var author in authors)
{
AuthorList.Add(author);
}
}
else
{
_ = GetAuthorsAsync();
}
}
catch (Exception ex)
{ {
authorList.Add(author); Debug.WriteLine(ex.Message);
} }
} }
} }

@ -1,56 +0,0 @@
using Model;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using ToolKit;
namespace VMWrapper
{
public class SearchBarViewModel : BaseViewModel
{
private readonly ILibraryManager data;
public SearchBarViewModel(ILibraryManager data)
{
this.data = data;
}
/* public ICommand PerformSearch => new Command<string>((string query) =>
{
SearchResults = DataService.GetSearchResults(query);
});
private List<string> searchResults = DataService.Fruits;
public List<string> SearchResults
{
get
{
return searchResults;
}
set
{
searchResults = value;
NotifyPropertyChanged();
}
}*/
public async void SearchAuthor(string nomSearch)
{
try
{
var (totalA, authors) = await data.GetAuthorsByName(nomSearch, 0, 5);
/*foreach (Author author in authors)
{
var books = data.GetBooksByAuthor(author.Name, 0, 5).Result.Item2;
var observableBooks = new ObservableCollection<Book>(books);
AuteurGroups.Add(new AuteurGroup(author.Name, observableBooks));
}*/
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
}
}
Loading…
Cancel
Save