add button all recipes, supp search button
continuous-integration/drone/push Build is passing Details

pull/65/head
Alexandre AGOSTINHO 2 years ago
parent 596e699382
commit 4b1a597f9b

@ -1,110 +1,110 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Text; using System.Text;
namespace Model namespace Model
{ {
/// <summary> /// <summary>
/// Define a collection of <see cref="Recipe"/>. /// Define a collection of <see cref="Recipe"/>.
/// <br/>This class is derived from <see cref="ObservableCollection{Recipe}"/> /// <br/>This class is derived from <see cref="ObservableCollection{Recipe}"/>
/// and implement <see cref="IEquatable{RecipeCollection}"/> and <see cref="ICloneable"/>. /// and implement <see cref="IEquatable{RecipeCollection}"/> and <see cref="ICloneable"/>.
/// </summary> /// </summary>
public class RecipeCollection : ObservableCollection<Recipe>, IEquatable<RecipeCollection>, ICloneable public class RecipeCollection : ObservableCollection<Recipe>, IEquatable<RecipeCollection>, ICloneable
{ {
#region Attributes #region Attributes
private string _description = ""; private string _description = "";
#endregion #endregion
#region Properties #region Properties
/// <summary> /// <summary>
/// A short description of what this collection contain. <br/> /// A short description of what this collection contain. <br/>
/// Set to "No description." when the value passed is null, empty or contain white spaces. /// Set to "No description." when the value passed is null, empty or contain white spaces.
/// </summary> /// </summary>
public string Description public string Description
{ {
get => _description; get => _description;
set set
{ {
if (string.IsNullOrWhiteSpace(value)) if (string.IsNullOrWhiteSpace(value))
_description = "No description."; _description = "No description.";
else else
_description = value; _description = value;
} }
} }
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Construct a new collection of _recipes. /// Construct a new collection of _recipes.
/// </summary> /// </summary>
/// <param _name="description">A short description of what this list will contain</param> /// <param _name="description">A short description of what this list will contain</param>
/// <param _name="recipes">Recipes to add in this new collection</param> /// <param _name="recipes">Recipes to add in this new collection</param>
public RecipeCollection(string description, params Recipe[] recipes) public RecipeCollection(string description, params Recipe[] recipes)
: base(recipes) : base(recipes)
{ {
Description = description; Description = description;
} }
#endregion #endregion
#region Methods #region Methods
/// <summary> /// <summary>
/// Find a recipe in this list by giving the id. /// Find a recipe in this list by giving the id.
/// </summary> /// </summary>
/// <param _name="id">The id of the list we are looking for</param> /// <param _name="id">The id of the list we are looking for</param>
/// <returns>The recipe of the id given</returns> /// <returns>The recipe of the id given</returns>
/// <exception cref="ArgumentException"/> /// <exception cref="ArgumentException"/>
public Recipe? GetRecipeById(int id) public Recipe? GetRecipeById(int id)
{ {
Recipe? recipe = this.ToList().Find(r => r.Id == id); Recipe? recipe = this.ToList().Find(r => r.Id == id);
if (recipe == null) throw new ArgumentException("No _recipes match the given id."); if (recipe == null) throw new ArgumentException("No _recipes match the given id.");
return recipe; return recipe;
} }
/// <summary> /// <summary>
/// Utility to find a recipe by his _name. /// Utility to find a recipe by his _name.
/// </summary> /// </summary>
/// <param _name="str">The string for the search</param> /// <param _name="str">The string for the search</param>
/// <returns>A collection of Recipe where their Title contain the string.</returns> /// <returns>A collection of Recipe where their Title contain the string.</returns>
public RecipeCollection ResearchByName(string str) public RecipeCollection ResearchByName(string str)
{ {
if (string.IsNullOrEmpty(str)) if (string.IsNullOrEmpty(str))
return this; return this;
return new RecipeCollection( return new RecipeCollection(
description: $"Results of the research: {str}", description: $"Results of the research: {str}",
recipes: this.ToList().FindAll(x => x.Title.ToLower().Contains(str.ToLower())).ToArray()); recipes: this.ToList().FindAll(x => x.Title.ToLower().Contains(str.ToLower())).ToArray());
} }
public virtual bool Equals(RecipeCollection? other) public virtual bool Equals(RecipeCollection? other)
{ {
if (other == null) return false; if (other == null) return false;
if (other == this) return true; if (other == this) return true;
return this.Description.Equals(other.Description); return this.Description.Equals(other.Description);
} }
public override bool Equals(object? obj) public override bool Equals(object? obj)
{ {
var item = obj as RecipeCollection; var item = obj as RecipeCollection;
if (item == null) return false; if (item == null) return false;
return Equals(obj); return Equals(obj);
} }
public override int GetHashCode() public override int GetHashCode()
{ {
return Description.GetHashCode(); return Description.GetHashCode();
} }
public override string ToString() public override string ToString()
{ {
StringBuilder sb = new StringBuilder($"[RecipeCollection] - {Description}:\n"); StringBuilder sb = new StringBuilder($"[RecipeCollection] - {Description}:\n");
foreach (Recipe r in this) foreach (Recipe r in this)
{ {
sb.AppendFormat("\t - {0}\n", r.ToString()); sb.AppendFormat("\t - {0}\n", r.ToString());
} }
return sb.ToString(); return sb.ToString();
} }
public object Clone() public object Clone()
@ -113,6 +113,6 @@ namespace Model
description: this.Description, description: this.Description,
recipes: this.ToArray()); recipes: this.ToArray());
} }
#endregion #endregion
} }
} }

@ -15,11 +15,9 @@
<local:ContainerBase.MyFlyoutContent> <local:ContainerBase.MyFlyoutContent>
<VerticalStackLayout Grid.Row="1"> <VerticalStackLayout Grid.Row="1">
<!-- Research --> <!-- Research -->
<Button <Label
Text="Recherche" Text="Recherche de recettes :" FontSize="14"
ImageSource="search_icon.png" Margin="20, 10, 15, 0"/>
MaximumHeightRequest="20"
Style="{StaticResource button1}"/>
<SearchBar <SearchBar
Placeholder="Mots-clés (ex.: rapide, fromage)" Placeholder="Mots-clés (ex.: rapide, fromage)"
FontAttributes="Italic" TextColor="Black" FontAttributes="Italic" TextColor="Black"
@ -28,6 +26,11 @@
SearchButtonPressed="SearchBar_SearchButtonPressed"/> SearchButtonPressed="SearchBar_SearchButtonPressed"/>
<!-- Direct research --> <!-- Direct research -->
<Button
Text="Toutes les recettes"
ImageSource="home_icon.png"
Style="{StaticResource button1}"
Clicked="AllRecipes_Clicked"/>
<Button <Button
Text="Entrées" Text="Entrées"
ImageSource="flatware_icon.png" ImageSource="flatware_icon.png"
@ -36,11 +39,13 @@
<Button <Button
Text="Plats" Text="Plats"
ImageSource="room_service_icon.png" ImageSource="room_service_icon.png"
Style="{StaticResource button1}"/> Style="{StaticResource button1}"
Clicked="Plats_Clicked"/>
<Button <Button
Text="Desserts" Text="Desserts"
ImageSource="coffee_icon.png" ImageSource="coffee_icon.png"
Style="{StaticResource button1}"/> Style="{StaticResource button1}"
Clicked="Desserts_Clicked"/>
</VerticalStackLayout> </VerticalStackLayout>
</local:ContainerBase.MyFlyoutContent> </local:ContainerBase.MyFlyoutContent>

@ -57,6 +57,7 @@ namespace Views
private void ModifyRecipesDisplayed(RecipeCollection recipes) private void ModifyRecipesDisplayed(RecipeCollection recipes)
{ {
_recipesDisplayed.Clear(); _recipesDisplayed.Clear();
_recipesDisplayed.Description = recipes.Description;
foreach (Recipe recipe in recipes) foreach (Recipe recipe in recipes)
{ {
_recipesDisplayed.Add(recipe); _recipesDisplayed.Add(recipe);
@ -76,7 +77,22 @@ namespace Views
private void Entrees_Clicked(object sender, EventArgs e) private void Entrees_Clicked(object sender, EventArgs e)
{ {
return; ModifyRecipesDisplayed(new RecipeCollection("Entrées", AllRecipe.ToList().FindAll(r => r.Type == RecipeType.Starter).ToArray()));
}
private void Plats_Clicked(object sender, EventArgs e)
{
ModifyRecipesDisplayed(new RecipeCollection("Plats", AllRecipe.ToList().FindAll(r => r.Type == RecipeType.Dish).ToArray()));
}
private void Desserts_Clicked(object sender, EventArgs e)
{
ModifyRecipesDisplayed(new RecipeCollection("Desserts", AllRecipe.ToList().FindAll(r => r.Type == RecipeType.Dessert).ToArray()));
}
private void AllRecipes_Clicked(object sender, EventArgs e)
{
ModifyRecipesDisplayed(AllRecipe);
} }
} }
} }

Loading…
Cancel
Save