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:model="clr-namespace:Model;assembly=Model"
x:Class="BookApp.Composants.CollectionFiltrage">
<CollectionView ItemsSource="{Binding authorList}">
<CollectionView ItemsSource="{Binding AuthorList}" x:Name="collectionView">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Author">
<StackLayout Padding="5">
@ -22,7 +22,7 @@
</Image.Behaviors>
</Image>
<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"
ImageSource="chevron_right.svg"
HeightRequest="35"

@ -7,7 +7,7 @@ public partial class ToggleSwitchView : ContentView
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)
{
if (e.Value) // Si c'est ON
@ -21,4 +21,4 @@ public partial class ToggleSwitchView : ContentView
OffLabel.Opacity = 1;
}
}
}
}

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

@ -55,7 +55,10 @@
<ContentPage.Content>
<StackLayout>
<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/>
</StackLayout>
</ContentPage.Content>

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

@ -20,7 +20,12 @@ namespace BookApp.UseCase
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();
}

@ -40,17 +40,25 @@ namespace BookApp.ViewModel
// Command Pop-up
public ICommand _popUpCommand;
public ICommand PopUpCommand =>
_popUpCommand ??= new CommandPersonnal(ShowPopUP);
public ICommand PopUpCommand => _popUpCommand ??= new CommandPersonnal(ShowPopUP);
public ViewModelDetailProvider(DetailBookViewModel detailBookViewModel)
{
_detailBookViewModel =
detailBookViewModel ?? throw new ArgumentNullException(nameof(detailBookViewModel));
}
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)
{
case "Finished":
@ -81,13 +89,22 @@ namespace BookApp.ViewModel
BookDetail.Status = Status.Unknown;
OnPropertyChanged(nameof(BookDetail));
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)

@ -64,8 +64,8 @@ namespace BookApp.ViewModel
var navigationParameter = new Dictionary<string, object> { { "Title", Title } };
await Shell.Current.GoToAsync(selectedItem.Route, navigationParameter);
Shell.Current.ForceLayout();
Shell.Current.ForceLayout();
}
catch (Exception ex)
{
@ -102,8 +102,9 @@ namespace BookApp.ViewModel
private void SelectTab(string route)
{
var shellItem = Shell.Current.Items.FirstOrDefault(item =>
item.Items.Any(section => section.Route.Contains(route)));
var shellItem = Shell.Current.Items.FirstOrDefault(
item => item.Items.Any(section => section.Route.Contains(route))
);
if (shellItem != null)
{

@ -5,7 +5,6 @@ namespace ToolKit
{
public class ObservableBook : BaseViewModel
{
private Book _book;
public Book Book
{
@ -129,7 +128,7 @@ namespace ToolKit
}
}
public Languages Language
public Languages Language
{
get => _book.Language;
set
@ -142,7 +141,7 @@ namespace ToolKit
}
}
public List<Contributor> Contributors
public List<Contributor> Contributors
{
get => _book.Contributors;
set
@ -184,7 +183,7 @@ namespace ToolKit
}
}
public Status Status
public Status Status
{
get => _book.Status;
set

@ -7,7 +7,7 @@ using ToolKit;
namespace VMWrapper
{
public class BooksViewModel: BaseViewModel
public class BooksViewModel : BaseViewModel
{
private readonly ILibraryManager data;
private readonly IUserLibraryManager userLibraryManager;
@ -64,7 +64,6 @@ namespace VMWrapper
var observableBooks = new ObservableCollection<Book>(books);
AuteurGroups.Add(new AuteurGroup(author.Name, observableBooks));
}
}
catch (Exception ex)
@ -84,7 +83,6 @@ namespace VMWrapper
}
}
public async Task RemoveBookById(string bookId)
{
await userLibraryManager.RemoveBook(bookId);
@ -100,12 +98,10 @@ namespace VMWrapper
{
AuteurGroups.RemoveAt(i);
}
break;
break;
}
}
OnPropertyChanged(nameof(AuteurGroups));
}
}
}

@ -2,53 +2,135 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ToolKit;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace VMWrapper
{
public class FilterViewModel
public class FilterViewModel: BaseViewModel
{
private readonly ILibraryManager data;
public ObservableCollection<Author> authorList { get; private set; } =
public ObservableCollection<Author> AuthorList { get; private set; } =
new ObservableCollection<Author>();
public ObservableCollection<Book> bookList { get; private set; } =
public ObservableCollection<Book> BookList { get; private set; } =
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)
{
this.data = data;
GetAuthors();
_ = GetAuthorsAsync();
}
private async void GetDatePublish()
private async Task GetDatePublish()
{
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)
{
bookList.Add(book);
BookList.Add(book);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
public async Task GetAuthorsAsync()
{
try
{
var result = await data.GetAuthorsByName("", 0, 10);
var authors = result.Item2;
AuthorList.Clear();
foreach (var author in authors)
{
AuthorList.Add(author);
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.Message);
}
}
public void GetAuthors()
private async Task SearchAuthors(string query)
{
var objet = data.GetAuthorsByName("", 0, 10).Result.Item2;
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;
authorList.Clear();
foreach (var author in objet)
}
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