Fix binding on MyProfil finished. Add all bindings on AddRecipe page, remain only the validation button to add the new recipe to our datafile
continuous-integration/drone/push Build is passing Details

pull/65/head
Roxane 2 years ago
parent 143c8b0dba
commit 14465aecfe

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -8,7 +10,7 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
[DataContract(Name = "ingredient")] [DataContract(Name = "ingredient")]
public class Ingredient public class Ingredient : INotifyPropertyChanged
{ {
#region Attributes #region Attributes
[DataMember(Name = "id")] [DataMember(Name = "id")]
@ -17,6 +19,7 @@ namespace Model
[DataMember(Name = "quantity")] [DataMember(Name = "quantity")]
private Quantity _quantity = new Quantity(1, Unit.unit); private Quantity _quantity = new Quantity(1, Unit.unit);
public event PropertyChangedEventHandler? PropertyChanged;
#endregion #endregion
#region Properties #region Properties
@ -33,6 +36,7 @@ namespace Model
throw new ArgumentNullException("Impossible de ne pas avoir de nom pour l'ingrédient"); throw new ArgumentNullException("Impossible de ne pas avoir de nom pour l'ingrédient");
} }
_name = value; _name = value;
OnPropertyChanged();
} }
} }
@ -41,8 +45,12 @@ namespace Model
/// </summary> /// </summary>
public Quantity QuantityI public Quantity QuantityI
{ {
get => _quantity; get { return _quantity; }
set => _quantity = value; set
{
_quantity = value;
OnPropertyChanged();
}
} }
@ -62,6 +70,12 @@ namespace Model
Name = name; Name = name;
QuantityI = quantity; QuantityI = quantity;
} }
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion #endregion
public override string ToString() public override string ToString()

@ -56,7 +56,7 @@ namespace Model
/// Priority of this recipe. /// Priority of this recipe.
/// </summary> /// </summary>
[DataMember(Name = "priority")] [DataMember(Name = "priority")]
public Priority Priority { get; private set; } public Priority Priority { get; set; }
/// <summary> /// <summary>
/// The Title of the recipe. <br/> /// The Title of the recipe. <br/>
@ -107,7 +107,7 @@ namespace Model
/// The type of recipe. /// The type of recipe.
/// </summary> /// </summary>
[DataMember(Name = "type")] [DataMember(Name = "type")]
public RecipeType Type { get; private set; } public RecipeType Type { get; set; }
#endregion #endregion
#region Constructors #region Constructors

@ -3,68 +3,91 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Views.AddRecipe" x:Class="Views.AddRecipe"
Title="AddRecipe" Title="AddRecipe"
xmlns:local="clr-namespace:Views"> xmlns:local="clr-namespace:Views"
<VerticalStackLayout> x:Name="nAddRecipe">
<local:MiniHeader <ScrollView>
<VerticalStackLayout BindingContext="{Binding RecipeToAdd}">
<local:MiniHeader
TitleMini="Ajouter une recette" TitleMini="Ajouter une recette"
NeedReturn="True" NeedReturn="True"
HeightRequest="100"/> HeightRequest="100"/>
<Grid ColumnDefinitions="auto, auto" <Grid ColumnDefinitions="auto, auto"
RowDefinitions="auto,auto,auto,auto,auto,auto, auto, auto, auto,auto" RowDefinitions="auto,auto,auto,auto,auto,auto, auto, auto, auto,auto"
Margin="50,20,20,20"> Margin="50,20,20,20">
<Label Text="Titre de la recette :"/> <Label Text="Titre de la recette :"/>
<Entry Placeholder="Saisie du texte de la recette correspondante" <Entry Placeholder="Saisie du texte de la recette correspondante"
Grid.Row="1" Grid.Row="1"
Margin="10"/> Margin="10"
<Label Text="Type de la recette" Grid.Row="2"/> Text="{Binding Title}"
<CheckBox x:Name="CheckEntree" Grid.Row="3" Margin="10,0,20,0" /> x:Name="RecipeName"/>
<Label Text="Entrée" Grid.Row="3" Margin="40,20"/> <Label Text="Type de la recette" Grid.Row="2"/>
<CheckBox x:Name="CheckPlat" Grid.Row="3" Margin="90,0" /> <RadioButton x:Name="CheckEntree" Grid.Row="3" Margin="10,0,20,0" />
<Label Text="Plat" Grid.Row="3" Margin="120,20"/> <Label Text="Entrée" Grid.Row="3" Margin="40,20"/>
<CheckBox x:Name="CheckDessert" Grid.Row="3" Margin="155,0" /> <RadioButton x:Name="CheckPlat" Grid.Row="3" Margin="90,0" />
<Label Text="Dessert" Grid.Row="3" Margin="185,20"/> <Label Text="Plat" Grid.Row="3" Margin="120,20"/>
<Button Text="pick photo" Clicked="PickPhoto" Grid.Row="1" Grid.Column="1"/> <RadioButton x:Name="CheckDessert" Grid.Row="3" Margin="155,0" />
<Label Text="Type de priorité :" Grid.Row="4" Margin="0,10,0,20"/> <Label Text="Dessert" Grid.Row="3" Margin="185,20"/>
<VerticalStackLayout Grid.Row="5"> <Button Text="pick photo" Clicked="PickPhoto" Grid.Row="1" Grid.Column="1"/>
<HorizontalStackLayout> <Label Text="Type de priorité :" Grid.Row="4" Margin="0,10,0,20"/>
<Label Text="Recettes Economiques" VerticalOptions="Center"/> <VerticalStackLayout Grid.Row="5">
<CheckBox x:Name="checkEconomique"/> <HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
</HorizontalStackLayout> <Label Text="Recettes Economiques" VerticalOptions="Center"/>
<HorizontalStackLayout> <RadioButton x:Name="checkEconomique"/>
<Label Text="Recettes Rapides" VerticalOptions="Center"/> </HorizontalStackLayout>
<CheckBox x:Name="checkFast"/> <HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
<Label Text="Recettes Rapides" VerticalOptions="Center"/>
<RadioButton x:Name="checkFast"/>
</HorizontalStackLayout>
<HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
<Label Text="Recettes Faciles" VerticalOptions="Center"/>
<RadioButton x:Name="checkEasy"/>
</HorizontalStackLayout>
<HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
<Label Text="Recettes Légères" VerticalOptions="Center"/>
<RadioButton x:Name="checkLight"/>
</HorizontalStackLayout>
<HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
<Label Text="Recettes Gourmandes" VerticalOptions="Center"/>
<RadioButton x:Name="checkGourmet"/>
</HorizontalStackLayout>
</VerticalStackLayout>
<Label Text="Saisir les étapes de la recette " Grid.Row="6" Margin="0,15" />
<HorizontalStackLayout Grid.Row="7" BindingContext="{Binding PreparationStep}">
<Editor Placeholder="Description de l'étape de la recette"
Text ="{Binding Description}"
x:Name="PreparationDescription"
MaximumWidthRequest="300"
MinimumWidthRequest="299"
AutoSize="TextChanges"/>
<Entry Placeholder="N° Etape"
Margin="12,0"
Text ="{Binding Order}"
x:Name="PreparationOrder"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout Grid.Row="8" Margin="20">
<Label Text="Recettes Faciles" VerticalOptions="Center"/> <Button WidthRequest="100" Text="Ajouter" TextColor="Black" Margin="20,0,20,0" Clicked="AddStepRecipe"/>
<CheckBox x:Name="checkEasy"/> <Button WidthRequest="100" Text="Précédent" TextColor="Black" Margin="20,0" Clicked="RemoveStepRecipe"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout>
<Label Text="Recettes Légères" VerticalOptions="Center"/> <Label Text="Saisir les ingrédients de la recette (nom, quantité, unité)" Grid.Row="6" Grid.Column="1" Margin="50,15"/>
<CheckBox x:Name="checkLight"/> <HorizontalStackLayout Grid.Row="7" Grid.Column="1" BindingContext="{Binding Ingredient}">
<Entry Placeholder="Nom de l'ingrédient"
Margin="12,0,0,0" WidthRequest="500"
Text="{Binding Name, Mode=OneWayToSource}"
x:Name="nameIngredient"/>
<Entry Placeholder="1"
Text="{Binding QuantityI.Number , Mode=OneWayToSource}"
x:Name="quantityNumber"/>
<Picker ItemsSource= "{Binding UnitList, Source={x:Reference nAddRecipe}}" x:Name="UnitPicker"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout Grid.Row="8" Grid.Column="1" Margin="20">
<Label Text="Recettes Gourmandes" VerticalOptions="Center"/> <Button WidthRequest="100" Text="Ajouter" TextColor="Black" Margin="20,0,20,0" Clicked="AddIngredient"/>
<CheckBox x:Name="checkGourmet"/> <Button WidthRequest="100" Text="Précédent" TextColor="Black" Margin="20,0" Clicked="RemoveIngredient"/>
</HorizontalStackLayout> </HorizontalStackLayout>
</VerticalStackLayout> <Button Grid.Row="10" Grid.ColumnSpan="2" Text="Validé" TextColor="Black" Clicked="AddRecipeValidation"/>
<Label Text="Saisir les étapes de la recette " Grid.Row="6" Margin="0,15"/> </Grid>
<Entry Placeholder="Etape de la recette" Grid.Row="7" Margin="12,0"/> </VerticalStackLayout>
<HorizontalStackLayout Grid.Row="8" Margin="20">
<Button WidthRequest="100" Text="Précédent" TextColor="Black" Margin="20,0,20,0" Clicked="AddStepRecipe"/>
<Button WidthRequest="100" Text="Ajouter" TextColor="Black" Margin="20,0" Clicked="RemoveStepRecipe"/>
</HorizontalStackLayout>
<Label Text="Saisir les ingrédients de la recette (nom, quantité, unité)" Grid.Row="6" Grid.Column="1" Margin="50,15"/> </ScrollView>
<HorizontalStackLayout Grid.Row="7" Grid.Column="1">
<Entry Placeholder="Nom de l'ingrédient" Margin="12,0,0,0" WidthRequest="500"/>
<Entry Placeholder="1" />
<Picker ItemsSource= "{Binding UnitList}"/>
</HorizontalStackLayout>
<HorizontalStackLayout Grid.Row="8" Grid.Column="1" Margin="20">
<Button WidthRequest="100" Text="Précédent" TextColor="Black" Margin="20,0,20,0" Clicked="AddIngredient"/>
<Button WidthRequest="100" Text="Ajouter" TextColor="Black" Margin="20,0" Clicked="RemoveIngredient"/>
</HorizontalStackLayout>
<Button Grid.Row="10" Grid.ColumnSpan="2" Text="Validé" TextColor="Black" Clicked="AddRecipeValidation"/>
</Grid>
</VerticalStackLayout>
</ContentPage> </ContentPage>

@ -1,6 +1,7 @@
using Model; using Model;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.Maui.Media; using Microsoft.Maui.Media;
using Microsoft.Maui.Controls;
namespace Views namespace Views
{ {
@ -8,28 +9,24 @@ namespace Views
{ {
private List<Ingredient> ingredientList; private List<Ingredient> ingredientList;
private List<PreparationStep> preparationStepList; private List<PreparationStep> preparationStepList;
private Recipe recipeToAdd;
private Ingredient ingredient;
private PreparationStep preparationStep;
public MasterManager Master => (Application.Current as App).Master; public MasterManager Master => (Application.Current as App).Master;
public Recipe RecipeToAdd{ get=> recipeToAdd; set => recipeToAdd = value; }
public List<Unit> UnitList { get; set; } = new List<Unit> { Unit.unit, Unit.kG, Unit.mG, Unit.G, Unit.L, Unit.cL, Unit.mL }; public List<Unit> UnitList { get; set; } = new List<Unit> { Unit.unit, Unit.kG, Unit.mG, Unit.G, Unit.L, Unit.cL, Unit.mL };
public List<Ingredient> IngredientList { get => ingredientList; set => ingredientList = value; } public List<Ingredient> IngredientList { get => ingredientList; set => ingredientList = value; }
public List<PreparationStep> PreparationStepList { get => preparationStepList; set => preparationStepList = value; } public List<PreparationStep> PreparationStepList { get => preparationStepList; set => preparationStepList = value; }
public AddRecipe(List<PreparationStep> preparationStepList) public Ingredient Ingredient { get => ingredient; set => ingredient = value ; }
{ public PreparationStep PreparationStepAdd { get => preparationStep; set => preparationStep = value; }
PreparationStepList = preparationStepList;
}
public AddRecipe(List<Ingredient> ingredientList)
{
IngredientList = ingredientList;
}
public bool IsCaptureSupported => throw new NotImplementedException();
public AddRecipe() public AddRecipe()
{ {
InitializeComponent(); InitializeComponent();
BindingContext = this; BindingContext = this;
RecipeToAdd = new Recipe("Nouvelle Recette");
IngredientList = new List<Ingredient>();
PreparationStepList = new List<PreparationStep>();
} }
private void PickPhoto(object sender, EventArgs e) private void PickPhoto(object sender, EventArgs e)
{ {
@ -38,21 +35,118 @@ namespace Views
private void AddRecipeValidation(object sender, EventArgs e) private void AddRecipeValidation(object sender, EventArgs e)
{ {
if (IsCaptureSupported)
{
}
} }
private void AddStepRecipe(object sender, EventArgs e) private void AddStepRecipe(object sender, EventArgs e)
{ {
string description = PreparationDescription.Text;
int order = Convert.ToInt32(PreparationOrder.Text);
PreparationStep PreparationStepAdd = new PreparationStep
(
order,
description
);
PreparationStepList.Add( PreparationStepAdd );
PreparationDescription.Text = string.Empty;
PreparationOrder.Text = string.Empty;
} }
private void RemoveStepRecipe(object sender, EventArgs e) private void RemoveStepRecipe(object sender, EventArgs e)
{ {
if (PreparationStepList.Count > 0)
{
PreparationStepList.RemoveAt(PreparationStepList.Count - 1);
DisplayAlert("Suppression", "La suppression de l'étape de la recette est effectuée avec succès", "Ok");
}
else
{
DisplayAlert("Liste d'étape vide", "Suppression impossible car la liste des étapes de description est vide.", "Ok");
}
}
private void AddIngredient(object sender, EventArgs e)
{
string ingredientName = nameIngredient.Text;
int numberQuantity = Convert.ToInt32(quantityNumber.Text);
Unit unitQuantity = (Unit)UnitPicker.SelectedItem;
Ingredient newIngredient = new Ingredient
(
ingredientName,
new Quantity
(
numberQuantity,
unitQuantity
)
);
IngredientList.Add( newIngredient );
nameIngredient.Text = string.Empty;
quantityNumber.Text = string.Empty;
UnitPicker.SelectedItem = null;
}
private void RemoveIngredient(object sender, EventArgs e)
{
if (IngredientList.Count > 0)
{
IngredientList.RemoveAt(IngredientList.Count - 1);
DisplayAlert("Suppression", "La suppression de l'ingrédient est effectuée avec succès", "Ok");
}
else
{
DisplayAlert("Liste d'ingrédient vide", "Suppression impossible car la liste des ingrédients est vide.", "Ok");
}
}
private RecipeType GetSelectedRecipeType()
{
if (CheckEntree.IsChecked)
{
return RecipeType.Starter;
}
else if (CheckPlat.IsChecked)
{
return RecipeType.Dish;
}
else if (CheckDessert.IsChecked)
{
return RecipeType.Dessert;
}
else
{
return RecipeType.Unspecified;
}
}
private Priority GetSelectedPriority()
{
if (checkEconomique.IsChecked)
{
return Priority.Economic;
}
else if (checkFast.IsChecked)
{
return Priority.Fast;
}
else if (checkEasy.IsChecked)
{
return Priority.Easy;
}
else if (checkLight.IsChecked)
{
return Priority.Light;
}
else if (checkGourmet.IsChecked)
{
return Priority.Gourmet;
}
else
{
return Priority.Gourmet;
}
} }
} }
} }

@ -5,65 +5,61 @@
xmlns:local="clr-namespace:Views" xmlns:local="clr-namespace:Views"
Title="ViewRecette" Title="ViewRecette"
x:Name="nrecipe"> x:Name="nrecipe">
<VerticalStackLayout BindingContext="{Binding Recipe}"> <ScrollView>
<local:MiniHeader <VerticalStackLayout BindingContext="{Binding Recipe}">
<local:MiniHeader
BindingContext="{Binding Recipe, Source={x:Reference nrecipe}}"
TitleMini="{Binding Title}" TitleMini="{Binding Title}"
NeedReturn="True" NeedReturn="True"
HeightRequest="100"/> HeightRequest="100"/>
<Image <Image
Source="{Binding Image}" Source="{Binding Image}"
HeightRequest="150" HeightRequest="150"
Aspect="AspectFill"/> Aspect="AspectFill"/>
<Grid ColumnDefinitions="200,*"> <Grid ColumnDefinitions="200,*">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Margin="10,20,0,0" <Label Margin="10,20,0,0"
Text="Ingrédients :" Text="Ingrédients :"
FontSize="Subtitle" FontSize="Subtitle"
FontAttributes="Bold"/> FontAttributes="Bold"/>
<ListView Margin="10,60,20,0" <ListView Margin="10,60,20,0"
Grid.RowSpan="4" Grid.RowSpan="4"
ItemsSource="{Binding Ingredients}"> ItemsSource="{Binding Ingredients}">
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<ViewCell> <ViewCell>
<Grid ColumnDefinitions="auto,auto, auto" <Grid ColumnDefinitions="auto,auto, auto"
RowDefinitions="auto"> RowDefinitions="auto">
<Label Text="{Binding QuantityI}" Grid.Column="0" Grid.Row="0"/> <Label Text="{Binding QuantityI}" Grid.Column="0" Grid.Row="0"/>
<Label Text="{Binding Name}" Grid.Column=" 1" Grid.Row="0"/> <Label Text="{Binding Name}" Grid.Column=" 1" Grid.Row="0"/>
</Grid> </Grid>
</ViewCell> </ViewCell>
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
<Label Margin="10,0,20,20" <Label Margin="10,0,20,20"
Grid.Column="1" Grid.Column="1"
Grid.Row="0" Grid.Row="0"
Text="Préparation :" Text="Préparation :"
FontSize="Subtitle" FontSize="Subtitle"
FontAttributes="Bold"/> FontAttributes="Bold"/>
<ListView Margin="10,30,0,0" <ListView Margin="10,30,0,0"
Grid.Column="1" Grid.Column="1"
ItemsSource="{Binding PreparationSteps}"> ItemsSource="{Binding PreparationSteps}">
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextCell Text="{Binding Order, StringFormat='Etape {0}'}" <TextCell Text="{Binding Order, StringFormat='Etape {0}'}"
Detail="{Binding Description}"/> Detail="{Binding Description}"/>
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
</Grid>
<Border VerticalOptions="End"
</Grid>
<Border VerticalOptions="End"
HorizontalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
Stroke="#C49B33" Stroke="#C49B33"
StrokeThickness="2" StrokeThickness="2"
@ -71,20 +67,20 @@
Padding="20,10,80,20" Padding="20,10,80,20"
Margin="50,100,50,0" Margin="50,100,50,0"
MinimumHeightRequest="200"> MinimumHeightRequest="200">
<ListView ItemsSource="{Binding Reviews}"> <ListView ItemsSource="{Binding Reviews}">
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid ColumnDefinitions="600,*" > <Grid ColumnDefinitions="600,*" >
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Grid.ColumnSpan="2" <Label Grid.ColumnSpan="2"
Grid.Row="0" Grid.Row="0"
Text=" Meilleure revue : " Text=" Meilleure revue : "
FontAttributes="Bold"/> FontAttributes="Bold"/>
<Label <Label
Background="#FFCB9A" Background="#FFCB9A"
Grid.Column="0" Grid.Column="0"
Grid.Row="1" Grid.Row="1"
@ -92,17 +88,16 @@
Padding="10,10,10,10" Padding="10,10,10,10"
Text="{Binding Content}" Text="{Binding Content}"
Margin="0,0,15,0"/> Margin="0,0,15,0"/>
<Button Grid.Column="1" <Button Grid.Column="1"
Grid.Row="2" Grid.Row="2"
Background="#FFCB9A" Background="#FFCB9A"
Text="Voir plus" Text="Voir plus"
TextColor="Black"/> TextColor="Black"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
</Border>
</Border> </VerticalStackLayout>
</ScrollView>
</VerticalStackLayout>
</ContentPage> </ContentPage>
Loading…
Cancel
Save