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) public RecipeCollection SearchRecipeByTitle(string title)
{ {
IEnumerable<Recipe> recipes = from Recipe recipe in _dataManager.GetFromData<Recipe>() IEnumerable<Recipe> recipes = from Recipe recipe in _dataManager.GetFromData<Recipe>()
where recipe.Title.Contains(title) where recipe.Title.ToLower().Contains(title.ToLower())
select recipe; select recipe;
return new RecipeCollection( return new RecipeCollection(
$"Search for '{title}'", recipes.ToArray()); $"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/><remarks><i>The setter is actually public for testing purpose. It will be private after.</i></remarks>
/// <br/>See: <see cref="IDataSerializer"/> /// <br/>See: <see cref="IDataSerializer"/>
/// </summary> /// </summary>
IDataSerializer Serializer { get; } IDataSerializer Serializer { get; set; }
/// <summary> /// <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. /// 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 public class User : IEquatable<User> , INotifyPropertyChanged
{ {
#region Private Attributes #region Private Attributes
[DataMember] private string _name = ""; [DataMember(Name = "name")] private string _name = "";
[DataMember] private string _surname = ""; [DataMember(Name = "surname")] private string _surname = "";
[DataMember] private string _mail = ""; [DataMember(Name = "mail")] private string _mail = "";
[DataMember(Name = "priorities")] [DataMember(Name = "priorities")]
public ObservableCollection<Priority> _priorities { get; private set; } = new ObservableCollection<Priority> private readonly List<Priority> _priorities = new List<Priority>
{ {
Priority.Gourmet, Priority.Gourmet,
Priority.Economic, Priority.Economic,
@ -28,6 +28,8 @@ namespace Model
Priority.Easy Priority.Easy
}; };
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
#endregion #endregion
@ -98,7 +100,7 @@ namespace Model
/// This is the list of priorities specific tu the user. This list is initiate /// This is the list of priorities specific tu the user. This list is initiate
/// by default. User could change it at will. /// by default. User could change it at will.
/// </summary> /// </summary>
public ReadOnlyObservableCollection<Priority> Priorities { get; private set; } public List<Priority> Priorities => _priorities;
#endregion #endregion
#region Methods #region Methods
@ -150,7 +152,7 @@ namespace Model
Surname = surname; Surname = surname;
Mail = mail; Mail = mail;
Password = hashedPassword; Password = hashedPassword;
Priorities = new ReadOnlyObservableCollection<Priority>(_priorities);
} }
/// <inheritdoc cref="User.User"/> /// <inheritdoc cref="User.User"/>
@ -176,7 +178,6 @@ namespace Model
Mail = user.Mail; Mail = user.Mail;
Password = user.Password; Password = user.Password;
_priorities = user._priorities; _priorities = user._priorities;
Priorities = new ReadOnlyObservableCollection<Priority>(_priorities);
ProfilePict = user.ProfilePict; ProfilePict = user.ProfilePict;
} }
#endregion #endregion

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

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

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

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