merge Alexandre's branch
continuous-integration/drone/push Build is passing Details

pull/65/head
Roxane ROSSETTO 2 years ago
commit 825acb7707

@ -39,12 +39,13 @@ namespace ConsoleApp.Menu
Recipe recipe = new Recipe( Recipe recipe = new Recipe(
title: title, title: title,
type: RecipeType.Unspecified,
id: null, id: null,
authorMail: masterMgr.CurrentConnectedUser?.Mail, authorMail: masterMgr.CurrentConnectedUser?.Mail,
picture: "", picture: null)
ingredients: new List<Ingredient>(), {
preparationSteps: steps.ToArray() PreparationSteps = steps
); };
masterMgr.AddRecipe(recipe); masterMgr.AddRecipe(recipe);
return null; return null;

@ -37,6 +37,7 @@ namespace DataPersistence
KnownTypes = new[] KnownTypes = new[]
{ {
typeof(Recipe), typeof(Recipe),
typeof(RecipeType),
typeof(Review), typeof(Review),
typeof(User), typeof(User),
typeof(Ingredient), typeof(Ingredient),

@ -45,6 +45,7 @@ namespace DataPersistence
KnownTypes = new Type[] KnownTypes = new Type[]
{ {
typeof(Recipe), typeof(Recipe),
typeof(RecipeType),
typeof(Review), typeof(Review),
typeof(User), typeof(User),
typeof(Ingredient), typeof(Ingredient),

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DataPersistence namespace DataPersistence
@ -21,77 +22,123 @@ namespace DataPersistence
nameof(Recipe), nameof(Recipe),
new List<object>(new[] new List<object>(new[]
{ {
new Recipe( new Recipe("Cookies classiques", RecipeType.Dessert, null, "admin@mctg.fr", "")
title: "Cookies classiques", {
id: 50, Ingredients = new List<Ingredient>
authorMail: "admin@mctg.fr",
picture : "room_service_icon.png",
ingredients: new List<Ingredient>(new[]
{ {
new Ingredient("Patates", new Quantity(23, Unit.unit)), new Ingredient("Patates", new Quantity(23, Unit.unit)),
new Ingredient("Farine", new Quantity(23, Unit.G)) new Ingredient("Farine", new Quantity(23, Unit.G))
}), },
preparationSteps: new[] PreparationSteps = new List<PreparationStep>
{ {
new PreparationStep(1, "Faire cuire."), new PreparationStep(1, "Faire cuire."),
new PreparationStep(2, "Manger.") new PreparationStep(2, "Manger.")
}), },
Reviews = new List<Review>
{
new Review(4, "Bonne recette, je recommande !"),
new Review(3, "Bof bof, mais mangeable...")
}
},
new Recipe( new Recipe(
authorMail: "admin@mctg.fr",
title: "Cookies au chocolat", title: "Cookies au chocolat",
id: null, type: RecipeType.Dessert)
preparationSteps: new[] {
Ingredients = new List<Ingredient>
{
new Ingredient("Farine", new Quantity(200, Unit.G))
},
PreparationSteps = new List<PreparationStep>()
{ {
new PreparationStep(1, "Moulinez la pâte."), new PreparationStep(1, "Moulinez la pâte."),
new PreparationStep(2, "Faire cuire pendant une bonne heure."), new PreparationStep(2, "Faire cuire pendant une bonne heure."),
new PreparationStep(3, "Sortir du four et mettre dans un plat.") new PreparationStep(3, "Sortir du four et mettre dans un plat.")
}), }
},
new Recipe( new Recipe(
title: "Gateau nature", id: null, title: "Gateau nature",
authorMail: "admin@mctg.fr", type: RecipeType.Dessert)
preparationSteps: new[] {
Ingredients = new List<Ingredient>
{
new Ingredient("Farine", new Quantity(200, Unit.G)),
new Ingredient("Lait", new Quantity(2, Unit.L))
},
PreparationSteps = new List<PreparationStep>
{ {
new PreparationStep(1, "Achetez les ingrédients."), new PreparationStep(1, "Achetez les ingrédients."),
new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."), new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."),
new PreparationStep(3, "Pleurez.") new PreparationStep(3, "Pleurez.")
}), },
Reviews = new List<Review>
{
new Review("pedrosamigos@hotmail.com", 5, "C'était vraiment IN-CROY-ABLE !!!")
}
},
new Recipe( new Recipe(
title: "Gateau au pommes", id: null, title: "Gateau au pommes",
authorMail: "admin@mctg.fr", type: RecipeType.Dessert)
preparationSteps: new[] {
PreparationSteps = new List<PreparationStep>
{ {
new PreparationStep(1, "Achetez les légumes."), new PreparationStep(1, "Achetez les légumes."),
new PreparationStep(2, "Préparez le plat. Ustensiles et préchauffez le four."), new PreparationStep(2, "Préparez le plat. Ustensiles et préchauffez le four."),
new PreparationStep(3, "Coupez les pommes en morceaux et disposez-les sur le plat."), new PreparationStep(3, "Coupez les pommes en morceaux et disposez-les sur le plat."),
new PreparationStep(4, "Mettez enfin le plat au four, puis une fois cuit, dégustez !") new PreparationStep(4, "Mettez enfin le plat au four, puis une fois cuit, dégustez !")
}), }
},
new Recipe( new Recipe(
title: "Gateau au chocolat", id: null, title: "Gateau au chocolat",
authorMail: "pedrosamigos@hotmail.com", type: RecipeType.Dessert,
preparationSteps: new[] id: null, authorMail: "pedrosamigos@hotmail.com")
{
Ingredients = new List<Ingredient>
{
new Ingredient("Mais", new Quantity(2, Unit.kG)),
new Ingredient("Sachet pépites de chocolat", new Quantity(1, Unit.unit)),
new Ingredient("Dinde", new Quantity(2, Unit.G))
},
PreparationSteps = new List<PreparationStep>
{ {
new PreparationStep(1, "Ajouter les oeufs."), new PreparationStep(1, "Ajouter les oeufs."),
new PreparationStep(2, "Ajouter la farine."), new PreparationStep(2, "Ajouter la farine."),
new PreparationStep(3, "Ajouter 100g de chocolat fondu."), new PreparationStep(3, "Ajouter 100g de chocolat fondu."),
new PreparationStep(4, "Mélanger le tout."), new PreparationStep(4, "Mélanger le tout."),
new PreparationStep(5, "Faire cuire 45h au four traditionnel.") new PreparationStep(5, "Faire cuire 45h au four traditionnel.")
}), }
},
new Recipe( new Recipe(
title: "Dinde au jambon", title: "Dinde au jambon",
id: null, type: RecipeType.Dish,
authorMail: "pedrosamigos@hotmail.com", id: null, authorMail: "pedrosamigos@hotmail.com")
preparationSteps: new[] {
Ingredients = new List<Ingredient>
{
new Ingredient("Morceaux de bois", new Quantity(2, Unit.unit)),
new Ingredient("Sachet gélatine", new Quantity(1, Unit.unit)),
new Ingredient("Jambon", new Quantity(2, Unit.kG))
},
PreparationSteps = new List<PreparationStep>
{ {
new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"), new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"),
new PreparationStep(2, "Mettre la dinde au frigo."), new PreparationStep(2, "Mettre la dinde au frigo."),
new PreparationStep(3, "Mettre le jambon dans le micro-onde."), new PreparationStep(3, "Mettre le jambon dans le micro-onde."),
new PreparationStep(4, "Faire chauffer 3min."), new PreparationStep(4, "Faire chauffer 3min."),
new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !") new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !")
}), }
},
new Recipe( new Recipe(
title: "Poulet au curry", id: null, title: "Poulet au curry",
authorMail: "pedrosamigos@hotmail.com", type: RecipeType.Dish,
preparationSteps: new[] id: null, authorMail: "pedrosamigos@hotmail.com")
{
Ingredients = new List<Ingredient>
{
new Ingredient("Pissenlis", new Quantity(200, Unit.unit)),
new Ingredient("Boule de pétanque", new Quantity(10, Unit.unit)),
new Ingredient("Poivre", new Quantity(4, Unit.mG))
},
PreparationSteps = new List<PreparationStep>
{ {
new PreparationStep(1, "Trouvez des épices de curry."), new PreparationStep(1, "Trouvez des épices de curry."),
new PreparationStep(2, "Trouvez maintenant du poulet."), new PreparationStep(2, "Trouvez maintenant du poulet."),
@ -99,7 +146,12 @@ namespace DataPersistence
new PreparationStep(4, "Parsemez d'épices curry la tête de la poule."), new PreparationStep(4, "Parsemez d'épices curry la tête de la poule."),
new PreparationStep(5, "Mettre le tout au four traditionnel 30min."), new PreparationStep(5, "Mettre le tout au four traditionnel 30min."),
new PreparationStep(6, "Dégustez en famille !") new PreparationStep(6, "Dégustez en famille !")
}) },
Reviews = new List<Review>
{
new Review(5, "Meilleure recette que j'ai avalé de tout les temps !!!!!!!")
}
}
}) })
#endregion #endregion
}, },

@ -1,8 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -12,14 +14,28 @@ namespace Model.Managers
/// <summary> /// <summary>
/// The Main manager of the model. /// The Main manager of the model.
/// </summary> /// </summary>
public class MasterManager public class MasterManager : INotifyPropertyChanged
{ {
#region Attributes & Properties #region Attributes & Properties
public event PropertyChangedEventHandler? PropertyChanged;
private RecipeCollection _recipesInSearch = new RecipeCollection("");
/// <summary> /// <summary>
/// The currently connected user. 'null' if no user is connected. /// The currently connected user. 'null' if no user is connected.
/// </summary> /// </summary>
public User? CurrentConnectedUser { get; private set; } public User? CurrentConnectedUser { get; private set; }
public RecipeCollection RecipesInSearch
{
get => _recipesInSearch;
set
{
_recipesInSearch = value;
OnPropertyChange();
}
}
/// <summary> /// <summary>
/// The collection of all recipes loaded. /// The collection of all recipes loaded.
/// </summary> /// </summary>
@ -46,6 +62,7 @@ namespace Model.Managers
DataMgr = new DataManager(dataManager); DataMgr = new DataManager(dataManager);
CurrentConnectedUser = null; CurrentConnectedUser = null;
Recipes = DataMgr.GetRecipes("all recipes"); Recipes = DataMgr.GetRecipes("all recipes");
RecipesInSearch = DataMgr.GetRecipes("search on");
Users = DataMgr.GetUsers(); Users = DataMgr.GetUsers();
} }
#endregion #endregion
@ -63,11 +80,13 @@ namespace Model.Managers
if (Users is null || Users.Count == 0) if (Users is null || Users.Count == 0)
throw new ArgumentNullException("There is no users registred."); throw new ArgumentNullException("There is no users registred.");
#if DEBUG
if (mail == "admin") if (mail == "admin")
{ {
CurrentConnectedUser = Users.FirstOrDefault(u => u.Mail == "admin@mctg.fr"); CurrentConnectedUser = Users.FirstOrDefault(u => u.Mail == "admin@mctg.fr");
return true; return true;
} }
#endif
User? user = Users.Find(u => u.Mail == mail); User? user = Users.Find(u => u.Mail == mail);
@ -129,7 +148,14 @@ namespace Model.Managers
/// <returns>The current connected user's personal recipes.</returns> /// <returns>The current connected user's personal recipes.</returns>
public RecipeCollection GetCurrentUserRecipes() public RecipeCollection GetCurrentUserRecipes()
=> new RecipeCollection("User recipes", => new RecipeCollection("User recipes",
DataMgr.GetRecipes().FindAll(r => r.AuthorMail == CurrentConnectedUser?.Mail).ToArray()); DataMgr.GetRecipes().ToList().FindAll(r => r.AuthorMail == CurrentConnectedUser?.Mail).ToArray());
/// <summary>
/// Notify property change handler.
/// </summary>
/// <param name="propertyName">the name of the property that change.</param>
public void OnPropertyChange([CallerMemberName] string propertyName = "")
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
#endregion #endregion
} }

@ -19,6 +19,9 @@ namespace Model
[DataMember(Name = "image")] [DataMember(Name = "image")]
private string _image = ""; private string _image = "";
[DataMember(Name = "authorMail")]
private string _authorMail = "";
#endregion #endregion
#region Properties #region Properties
@ -32,15 +35,22 @@ namespace Model
/// List of reviews of this recipe. /// List of reviews of this recipe.
/// </summary> /// </summary>
[DataMember(Name = "reviews")] [DataMember(Name = "reviews")]
public List<Review> Reviews { get; private set; } public List<Review> Reviews { get; set; }
/// <summary> /// <summary>
/// AuthorMail's mail of the recipe. /// AuthorMail's mail of the recipe.
/// </summary> /// </summary>
[DataMember(Name = "authorMail")] public string? AuthorMail
public string? AuthorMail { get; private set; } {
get => _authorMail;
public string Toto { get; set; } = "Coucou"; set
{
if (string.IsNullOrEmpty(value))
_authorMail = "admin@mctg.fr";
else
_authorMail = value;
}
}
/// <summary> /// <summary>
/// The Title of the recipe. <br/> /// The Title of the recipe. <br/>
@ -74,6 +84,7 @@ namespace Model
} }
} }
/// <summary>
/// The list of ingredients. /// The list of ingredients.
/// </summary> /// </summary>
[DataMember(Name = "ingredient")] [DataMember(Name = "ingredient")]
@ -85,30 +96,34 @@ namespace Model
/// </summary> /// </summary>
[DataMember(Name = "preparation-steps")] [DataMember(Name = "preparation-steps")]
public List<PreparationStep> PreparationSteps { get; set; } public List<PreparationStep> PreparationSteps { get; set; }
/// <summary>
/// The type of recipe.
/// </summary>
[DataMember(Name = "type")]
public RecipeType Type { get; private set; }
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Construct a new recipe. /// Construct a new recipe.
/// </summary> /// </summary>
/// <param _name="title">The title of the recipe</param> /// <param name="title">The title of the recipe</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param> /// <param name="type">The type of the recipe.</param>
/// <param _name="authorMail">The name of the user that create this recipe.</param> /// <param name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="picture"> The image that represent the recipe</param> /// <param name="authorMail">The name of the user that create this recipe.</param>
/// <param _name="reviews">Thr list of reviews.</param> /// <param name="picture"> The image that represent the recipe</param>
/// <param _name="ingredients">Thr list of ingredients.</param> public Recipe(string title, RecipeType type, int? id, string? authorMail, string? picture)
/// <param _name="preparationSteps">The steps of the preparation of the meal</param>
public Recipe(string title, int? id, string? authorMail, string? picture,
List<Review> reviews, List<Ingredient> ingredients,
params PreparationStep[] preparationSteps)
{ {
Title = title; Title = title;
Type = type;
Image = picture; Image = picture;
PreparationSteps = new List<PreparationStep>(preparationSteps);
Ingredients = ingredients;
Reviews = reviews;
AuthorMail = authorMail; AuthorMail = authorMail;
PreparationSteps = new List<PreparationStep>();
Ingredients = new List<Ingredient>();
Reviews = new List<Review>();
if (id == null) if (id == null)
{ {
var randomGenerator = RandomNumberGenerator.Create(); var randomGenerator = RandomNumberGenerator.Create();
@ -119,46 +134,20 @@ namespace Model
else Id = (int)id; else Id = (int)id;
} }
public Recipe(string title, RecipeType type, int? id, string? authorMail)
/// <summary> : this(title, type, id, authorMail, null)
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary>
/// <param _name="title">The title of the recipe.</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="authorMail">Mail of the user that create the recipe</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, string? authorMail, params PreparationStep[] preparationSteps)
: this(title, id, authorMail, null, new List<Review>(), new List<Ingredient>(), preparationSteps)
{ {
} }
/// <summary> public Recipe(string title, RecipeType type)
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> : this(title, type, null, null)
/// </summary>
/// <param _name="title">The title of the recipe.</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="authorMail">Mail of the user that create the recipe</param>
/// <param _name="picture">Mail of the user that create the recipe</param>
/// <param _name="ingredients">List of ingredients that compose the recipe. </param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, string? authorMail, string? picture, List<Ingredient> ingredients, params PreparationStep[] preparationSteps)
: this(title, id, authorMail, picture, new List<Review>(), ingredients, preparationSteps)
{ {
} }
/// <summary> public Recipe(string title)
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> : this(title, RecipeType.Unspecified)
/// </summary>
/// <param _name="title">The title of the recipe.</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="picture">Image that reppresent the recipe.</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe()
: this("", null, null, null, new List<Review>(), new List<Ingredient>(),new PreparationStep[0])
{ {
} }
#endregion #endregion
#region Methods #region Methods

@ -8,9 +8,10 @@ namespace Model
{ {
/// <summary> /// <summary>
/// Define a collection of <see cref="Recipe"/>. /// Define a collection of <see cref="Recipe"/>.
/// <br/>This class implement <see cref="IList"/> and <see cref="IEquatable{T}"/>. /// <br/>This class is derived from <see cref="ObservableCollection{Recipe}"/>
/// and implement <see cref="IEquatable{RecipeCollection}"/> and <see cref="ICloneable"/>.
/// </summary> /// </summary>
public class RecipeCollection : List<Recipe>, IEquatable<RecipeCollection> public class RecipeCollection : ObservableCollection<Recipe>, IEquatable<RecipeCollection>, ICloneable
{ {
#region Attributes #region Attributes
private string _description = ""; private string _description = "";
@ -56,7 +57,8 @@ namespace Model
/// <exception cref="ArgumentException"/> /// <exception cref="ArgumentException"/>
public Recipe? GetRecipeById(int id) public Recipe? GetRecipeById(int id)
{ {
Recipe? recipe = this.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;
} }
@ -68,9 +70,12 @@ namespace Model
/// <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))
return this;
return new RecipeCollection( return new RecipeCollection(
description: $"Results of the research: {str}", description: $"Results of the research: {str}",
recipes: this.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)
@ -101,6 +106,13 @@ namespace Model
} }
return sb.ToString(); return sb.ToString();
} }
public object Clone()
{
return new RecipeCollection(
description: this.Description,
recipes: this.ToArray());
}
#endregion #endregion
} }
} }

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public enum RecipeType
{
Unspecified,
Starter,
Dish,
Dessert
}
}

@ -8,9 +8,8 @@ namespace Model_UnitTests
public void TestVoidConstructor() public void TestVoidConstructor()
{ {
Recipe r = new Recipe( Recipe r = new Recipe(
title: "test recipe", title: "test recipe", type: RecipeType.Unspecified);
id: null,
authorMail: "test@test.fr");
Assert.NotNull(r.Title); Assert.NotNull(r.Title);
} }
} }

@ -35,31 +35,14 @@ namespace Views
//collection de recette de l'application //collection de recette de l'application
public RecipeCollection AllRecipes { get; set; } public RecipeCollection AllRecipes { get; set; }
//const int WindowWidth = 1200;
//const int WindowHeight = 800;
public App() public App()
{ {
CurrentUser = MasterMgr.DataMgr.GetUsers().Last(); CurrentUser = MasterMgr.CurrentConnectedUser;
AllRecipes = MasterMgr.DataMgr.GetRecipes("All recipes"); AllRecipes = MasterMgr.DataMgr.GetRecipes("All recipes");
CurrentRecipe = MasterMgr.DataMgr.GetRecipes().First(); CurrentRecipe = MasterMgr.DataMgr.GetRecipes().First();
InitializeComponent(); InitializeComponent();
// Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
// {
//#if WINDOWS
// var mauiWindow = handler.VirtualView;
// var nativeWindow = handler.PlatformView;
// nativeWindow.Activate();
// IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow);
// WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
// AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
// appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight));
//#endif
// });
/* - Comment(ctrl-k + ctrl-c)/Uncomment(ctrl-k + ctrl-u) to change page - */
UserAppTheme = AppTheme.Light; UserAppTheme = AppTheme.Light;
MainPage = new MyProfil(); MainPage = new MyProfil();
//MainPage = new MyPosts(); //MainPage = new MyPosts();

@ -21,13 +21,15 @@
CornerRadius="50" Margin="0, 30, 0, 10" CornerRadius="50" Margin="0, 30, 0, 10"
BorderWidth="5" BorderColor="Black" BorderWidth="5" BorderColor="Black"
IsEnabled="{Binding IsNotConnected, Source={x:Reference fl}}" IsEnabled="{Binding IsNotConnected, Source={x:Reference fl}}"
Grid.RowSpan="2"/> Grid.RowSpan="2"
Clicked="ProfileButton_Clicked"/>
</Grid> </Grid>
<Button Text="Connection" ImageSource="login_icon.png" <Button Text="Connection" ImageSource="login_icon.png"
Style="{StaticResource button2}" Style="{StaticResource button2}"
IsVisible="{Binding IsNotConnected, Source={x:Reference fl}}" IsVisible="{Binding IsNotConnected, Source={x:Reference fl}}"
IsEnabled="{Binding IsNotConnected, Source={x:Reference fl}}"/> IsEnabled="{Binding IsNotConnected, Source={x:Reference fl}}"
Clicked="ConnectionButton_Clicked"/>
<StackLayout BindingContext="{Binding user}"> <StackLayout BindingContext="{Binding user}">
<Label Text="{Binding Name}" <Label Text="{Binding Name}"
HorizontalOptions="Center" Margin="0,15" HorizontalOptions="Center" Margin="0,15"
@ -41,7 +43,6 @@
IsVisible="{Binding IsNotConnected, Converter={toolkit:InvertedBoolConverter} ,Source={x:Reference fl}}"/> IsVisible="{Binding IsNotConnected, Converter={toolkit:InvertedBoolConverter} ,Source={x:Reference fl}}"/>
</StackLayout> </StackLayout>
</VerticalStackLayout> </VerticalStackLayout>
<!-- Content --> <!-- Content -->

@ -17,6 +17,7 @@ public partial class ContainerFlyout : ContentView
} }
#region Bindable XAML Properties
// Bind MyFlyoutContent // Bind MyFlyoutContent
public static readonly BindableProperty MyFlyoutContentProperty = public static readonly BindableProperty MyFlyoutContentProperty =
BindableProperty.Create("MyFlyoutContent", typeof(View), typeof(ContainerFlyout), new Grid()); BindableProperty.Create("MyFlyoutContent", typeof(View), typeof(ContainerFlyout), new Grid());
@ -46,4 +47,15 @@ public partial class ContainerFlyout : ContentView
get => (bool)GetValue(NeedReturnProperty); get => (bool)GetValue(NeedReturnProperty);
set => SetValue(NeedReturnProperty, value); set => SetValue(NeedReturnProperty, value);
} }
#endregion
public async void ProfileButton_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new MyProfil());
}
public async void ConnectionButton_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new Login());
}
} }

@ -4,46 +4,55 @@
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:local="clr-namespace:Views" xmlns:local="clr-namespace:Views"
xmlns:model="clr-namespace:Model;assembly=Model" xmlns:model="clr-namespace:Model;assembly=Model"
x:Class="Views.Home"> x:Class="Views.Home"
x:Name="homepage">
<local:ContainerBase <local:ContainerBase
IsNotConnected="True"> IsNotConnected="{Binding IsNotConnected, Source={x:Reference homepage}}"
NeedReturn="{Binding NeedReturn, Source={x:Reference homepage}}">
<!-- Flyout --> <!-- Flyout -->
<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"
BackgroundColor="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Gray300}}" BackgroundColor="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Gray300}}"
Margin="15, 10, 15, 40"/> Margin="15, 10, 15, 40"
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"
Style="{StaticResource button1}"/> Style="{StaticResource button1}"
Clicked="Entrees_Clicked"/>
<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>
<!-- Master --> <!-- Master -->
<local:ContainerBase.MyContent> <local:ContainerBase.MyContent>
<ScrollView> <ScrollView>
<StackLayout BindingContext="{Binding AllRecipes}" MinimumWidthRequest="400"> <StackLayout BindingContext="{Binding RecipesDisplayed}" MinimumWidthRequest="400">
<!--Modification du prof apportée sur le stacklayout pour empecher l'affichage d'une seule case recipe--> <!--Modification du prof apportée sur le stacklayout pour empecher l'affichage d'une seule case recipe-->
<Label <Label
Text="{Binding Description}" Text="{Binding Description}"
@ -62,42 +71,14 @@
<BindableLayout.ItemTemplate> <BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:Recipe"> <DataTemplate x:DataType="model:Recipe">
<Border Style="{StaticResource recipeCase}">
<Grid RowDefinitions="*, 40">
<!--<local:RecipeCase
CaseImageSource="room_service_icon.png"
Title="{Binding Title}"/>-->
<ImageButton <local:RecipeCase
Grid.Row="0" VerticalOptions="Fill" CaseImageSource="{Binding Image}"
Source="{Binding Image}" RecipeTitle="{Binding Title}"/>
Clicked="OnImageClicked"/>
<Label
Text="{Binding Title}" FontSize="18"
Grid.Row="1" HorizontalOptions="Center"/>
</Grid>
</Border>
</DataTemplate> </DataTemplate>
</BindableLayout.ItemTemplate> </BindableLayout.ItemTemplate>
<!--<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>-->
</FlexLayout> </FlexLayout>
</StackLayout> </StackLayout>
</ScrollView> </ScrollView>

@ -2,29 +2,97 @@
using DataPersistence; using DataPersistence;
using Model; using Model;
using Model.Managers; using Model.Managers;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace Views namespace Views
{ {
public partial class Home : ContentPage public partial class Home : ContentPage
{ {
public MasterManager MasterMgr => (App.Current as App).MasterMgr; public MasterManager MasterMgr => (App.Current as App).MasterMgr;
public User user => (App.Current as App).CurrentUser; public User? user => (App.Current as App).CurrentUser;
public Recipe Recipe => (App.Current as App).CurrentRecipe; public RecipeCollection AllRecipe => (App.Current as App).AllRecipes;
public RecipeCollection AllRecipes => (App.Current as App).AllRecipes;
private readonly RecipeCollection _recipesDisplayed;
public ReadOnlyObservableCollection<Recipe> RecipesDisplayed { get; private set; }
public static readonly BindableProperty IsNotConnectedProperty =
BindableProperty.Create("IsNotConnected", typeof(bool), typeof(bool));
public bool IsNotConnected
{
get => (bool)GetValue(IsNotConnectedProperty);
set => SetValue(IsNotConnectedProperty, value);
}
public static readonly BindableProperty NeedReturnProperty =
BindableProperty.Create("NeedReturn", typeof(bool), typeof(bool));
public bool NeedReturn
{
get => (bool)GetValue(NeedReturnProperty);
set => SetValue(NeedReturnProperty, value);
}
public Home() public Home()
{ {
//DataMgr = new DataManager(new Stubs()); _recipesDisplayed = (RecipeCollection)AllRecipe.Clone();
//AllRecipes = new RecipeCollection("Toutes les recettes", DataMgr.Data[nameof(Recipe)].Cast<Recipe>().ToArray()); RecipesDisplayed = new ReadOnlyObservableCollection<Recipe>(_recipesDisplayed);
InitializeComponent();
BindingContext = this;
IsNotConnected = true;
NeedReturn = false;
}
public Home(RecipeCollection recipesDisplayed)
{
_recipesDisplayed = recipesDisplayed;
InitializeComponent(); InitializeComponent();
BindingContext = this; BindingContext = this;
IsNotConnected = true;
NeedReturn = true;
}
private void ModifyRecipesDisplayed(RecipeCollection recipes)
{
_recipesDisplayed.Clear();
_recipesDisplayed.Description = recipes.Description;
foreach (Recipe recipe in recipes)
{
_recipesDisplayed.Add(recipe);
}
}
private void SearchBar_SearchButtonPressed(object sender, EventArgs e)
{
string searchStr = (sender as SearchBar).Text;
ModifyRecipesDisplayed(AllRecipe.ResearchByName(searchStr));
} }
public void OnImageClicked(object sender, EventArgs e) public void OnImageClicked(object sender, EventArgs e)
{ {
(App.Current as App).CurrentRecipe = (Recipe)(sender as ImageButton).BindingContext; (App.Current as App).CurrentRecipe = (Recipe)(sender as ImageButton).BindingContext;
Navigation.PushModalAsync(new ViewRecette()); Navigation.PushModalAsync(new ViewRecette());
}
private void Entrees_Clicked(object sender, EventArgs e)
{
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);
}
} }
} }

@ -8,12 +8,14 @@
<Border Style="{StaticResource recipeCase}"> <Border Style="{StaticResource recipeCase}">
<Grid RowDefinitions="*, 40"> <Grid RowDefinitions="*, 40">
<Image <ImageButton
Grid.Row="0" VerticalOptions="Fill" Grid.Row="0" VerticalOptions="Fill"
Source="{Binding CaseImageSource, Source={x:Reference rCase}}"/> Source="{Binding CaseImageSource, Source={x:Reference rCase}}"
Clicked="ImageButton_Clicked"/>
<Label Text="Recette 1" FontSize="18" <Label
Grid.Row="1" HorizontalOptions="Center"/> Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center"
Text="{Binding RecipeTitle, Source={x:Reference rCase}}"/>
</Grid> </Grid>
</Border> </Border>

@ -15,4 +15,18 @@ public partial class RecipeCase : ContentView
get => (ImageSource)GetValue(CaseImageSourceProperty); get => (ImageSource)GetValue(CaseImageSourceProperty);
set => SetValue(CaseImageSourceProperty, value); set => SetValue(CaseImageSourceProperty, value);
} }
public static readonly BindableProperty RecipeTitleProperty =
BindableProperty.Create("RecipeTitle", typeof(string), typeof(Label));
public string RecipeTitle
{
get => (string)GetValue(RecipeTitleProperty);
set => SetValue(RecipeTitleProperty, value);
}
private async void ImageButton_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new ViewRecette());
}
} }

@ -30,7 +30,7 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion> <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<Configurations>Debug;Release;CI</Configurations> <Configurations>Debug;Release</Configurations>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save