add suggestion button, fix priority persistence

pull/56/head
Alexandre AGOSTINHO 2 years ago
parent 3b2101f2fe
commit e87ddf566a

@ -56,7 +56,7 @@ namespace Managers
public RecipeCollection SearchRecipeByTitle(string title)
{
IEnumerable<Recipe> recipes = from Recipe recipe in _dataManager.GetFromData<Recipe>()
where recipe.Title.Contains(title)
where recipe.Title.ToLower().Contains(title.ToLower())
select recipe;
return new RecipeCollection(
$"Search for '{title}'", recipes.ToArray());

@ -17,7 +17,7 @@ namespace Model
/// <br/><remarks><i>The setter is actually public for testing purpose. It will be private after.</i></remarks>
/// <br/>See: <see cref="IDataSerializer"/>
/// </summary>
IDataSerializer Serializer { get; }
IDataSerializer Serializer { get; set; }
/// <summary>
/// The collection of all data. Each line of this dictionary has the type of the data as it key and the data for values.

@ -14,12 +14,12 @@ namespace Model
public class User : IEquatable<User> , INotifyPropertyChanged
{
#region Private Attributes
[DataMember] private string _name = "";
[DataMember] private string _surname = "";
[DataMember] private string _mail = "";
[DataMember(Name = "name")] private string _name = "";
[DataMember(Name = "surname")] private string _surname = "";
[DataMember(Name = "mail")] private string _mail = "";
[DataMember(Name = "priorities")]
public ObservableCollection<Priority> _priorities { get; private set; } = new ObservableCollection<Priority>
private readonly List<Priority> _priorities = new List<Priority>
{
Priority.Gourmet,
Priority.Economic,
@ -28,6 +28,8 @@ namespace Model
Priority.Easy
};
public event PropertyChangedEventHandler? PropertyChanged;
#endregion
@ -98,7 +100,7 @@ namespace Model
/// This is the list of priorities specific tu the user. This list is initiate
/// by default. User could change it at will.
/// </summary>
public ReadOnlyObservableCollection<Priority> Priorities { get; private set; }
public List<Priority> Priorities => _priorities;
#endregion
#region Methods
@ -150,7 +152,7 @@ namespace Model
Surname = surname;
Mail = mail;
Password = hashedPassword;
Priorities = new ReadOnlyObservableCollection<Priority>(_priorities);
}
/// <inheritdoc cref="User.User"/>
@ -176,7 +178,6 @@ namespace Model
Mail = user.Mail;
Password = user.Password;
_priorities = user._priorities;
Priorities = new ReadOnlyObservableCollection<Priority>(_priorities);
ProfilePict = user.ProfilePict;
}
#endregion

@ -177,7 +177,6 @@ namespace FakePersistance
surname: "Amigos",
mail: "pedrosamigos@hotmail.com",
hashedPassword: psswdMgr.HashPassword("pamigos"))
})
#endregion
}

@ -42,9 +42,7 @@ namespace Views
// Change the data serializer if the one in place is 'Stubs'
if (Master.Data.Serializer.GetType() == typeof(Stubs))
{
var data = Master.Data.Data;
dataManager = new DataDefaultManager(dataSerializer, data);
Master = new MasterManager(dataManager, recipeManager, userManager);
Master.Data.Serializer = dataSerializer;
}
// Save data.

@ -25,6 +25,12 @@
SearchButtonPressed="SearchBar_SearchButtonPressed"/>
<!-- Direct research -->
<Button
Text="Suggestions"
ImageSource="home_icon.png"
Style="{StaticResource button1}"
Clicked="Suggestions_Clicked"
IsVisible="{Binding IsConnected, Source={x:Reference container_base}}"/>
<Button
Text="Toutes les recettes"
ImageSource="home_icon.png"

@ -1,4 +1,5 @@
using Model;
using AppException;
using Model;
using System.Collections.ObjectModel;
namespace Views
@ -9,12 +10,18 @@ namespace Views
private readonly RecipeCollection _recipesDisplayed;
public ReadOnlyObservableRecipeCollection RecipesDisplayed { get; private set; }
public string Description => _recipesDisplayed.Description;
public Home()
{
Master.User.LogIn("admin", "");
_recipesDisplayed = Master.Recipe.GetAllRecipes();
if (Master.User.CurrentConnected is null)
_recipesDisplayed.Description = "Toutes les recettes";
else
_recipesDisplayed.Description = "Suggestions";
RecipesDisplayed = new ReadOnlyObservableRecipeCollection(_recipesDisplayed);
InitializeComponent();
@ -39,6 +46,7 @@ namespace Views
string searchStr = (sender as SearchBar).Text;
ModifyRecipesDisplayed(Master.Recipe.SearchRecipeByTitle(searchStr));
}
public void OnImageClicked(object sender, EventArgs e)
{
Master.Recipe.CurrentSelected = (Recipe)(sender as ImageButton).BindingContext;
@ -74,7 +82,17 @@ namespace Views
private void AllRecipes_Clicked(object sender, EventArgs e)
{
ModifyRecipesDisplayed(Master.Recipe.GetAllRecipes());
ModifyRecipesDisplayed(new RecipeCollection("Toutes les recettes", Master.Recipe.GetAllRecipes()));
}
private void Suggestions_Clicked(object sender, EventArgs e)
{
if (Master.User.CurrentConnected is null)
throw new NoUserConnectedException();
ModifyRecipesDisplayed(new RecipeCollection(
description: "Suggestions",
recipes: Master.Recipe.GetRecipesByPriorityOrder(Master.User.CurrentConnected.Priorities)));
}
}
}

Loading…
Cancel
Save