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

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

@ -3,68 +3,91 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Views.AddRecipe"
Title="AddRecipe"
xmlns:local="clr-namespace:Views">
<VerticalStackLayout>
<local:MiniHeader
xmlns:local="clr-namespace:Views"
x:Name="nAddRecipe">
<ScrollView>
<VerticalStackLayout BindingContext="{Binding RecipeToAdd}">
<local:MiniHeader
TitleMini="Ajouter une recette"
NeedReturn="True"
HeightRequest="100"/>
<Grid ColumnDefinitions="auto, auto"
<Grid ColumnDefinitions="auto, auto"
RowDefinitions="auto,auto,auto,auto,auto,auto, auto, auto, auto,auto"
Margin="50,20,20,20">
<Label Text="Titre de la recette :"/>
<Entry Placeholder="Saisie du texte de la recette correspondante"
Grid.Row="1"
Margin="10"/>
<Label Text="Type de la recette" Grid.Row="2"/>
<CheckBox x:Name="CheckEntree" Grid.Row="3" Margin="10,0,20,0" />
<Label Text="Entrée" Grid.Row="3" Margin="40,20"/>
<CheckBox x:Name="CheckPlat" Grid.Row="3" Margin="90,0" />
<Label Text="Plat" Grid.Row="3" Margin="120,20"/>
<CheckBox x:Name="CheckDessert" Grid.Row="3" Margin="155,0" />
<Label Text="Dessert" Grid.Row="3" Margin="185,20"/>
<Button Text="pick photo" Clicked="PickPhoto" Grid.Row="1" Grid.Column="1"/>
<Label Text="Type de priorité :" Grid.Row="4" Margin="0,10,0,20"/>
<VerticalStackLayout Grid.Row="5">
<HorizontalStackLayout>
<Label Text="Recettes Economiques" VerticalOptions="Center"/>
<CheckBox x:Name="checkEconomique"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label Text="Recettes Rapides" VerticalOptions="Center"/>
<CheckBox x:Name="checkFast"/>
<Label Text="Titre de la recette :"/>
<Entry Placeholder="Saisie du texte de la recette correspondante"
Grid.Row="1"
Margin="10"
Text="{Binding Title}"
x:Name="RecipeName"/>
<Label Text="Type de la recette" Grid.Row="2"/>
<RadioButton x:Name="CheckEntree" Grid.Row="3" Margin="10,0,20,0" />
<Label Text="Entrée" Grid.Row="3" Margin="40,20"/>
<RadioButton x:Name="CheckPlat" Grid.Row="3" Margin="90,0" />
<Label Text="Plat" Grid.Row="3" Margin="120,20"/>
<RadioButton x:Name="CheckDessert" Grid.Row="3" Margin="155,0" />
<Label Text="Dessert" Grid.Row="3" Margin="185,20"/>
<Button Text="pick photo" Clicked="PickPhoto" Grid.Row="1" Grid.Column="1"/>
<Label Text="Type de priorité :" Grid.Row="4" Margin="0,10,0,20"/>
<VerticalStackLayout Grid.Row="5">
<HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
<Label Text="Recettes Economiques" VerticalOptions="Center"/>
<RadioButton x:Name="checkEconomique"/>
</HorizontalStackLayout>
<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>
<Label Text="Recettes Faciles" VerticalOptions="Center"/>
<CheckBox x:Name="checkEasy"/>
<HorizontalStackLayout Grid.Row="8" Margin="20">
<Button WidthRequest="100" Text="Ajouter" TextColor="Black" Margin="20,0,20,0" Clicked="AddStepRecipe"/>
<Button WidthRequest="100" Text="Précédent" TextColor="Black" Margin="20,0" Clicked="RemoveStepRecipe"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label Text="Recettes Légères" VerticalOptions="Center"/>
<CheckBox x:Name="checkLight"/>
<Label Text="Saisir les ingrédients de la recette (nom, quantité, unité)" Grid.Row="6" Grid.Column="1" Margin="50,15"/>
<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>
<Label Text="Recettes Gourmandes" VerticalOptions="Center"/>
<CheckBox x:Name="checkGourmet"/>
<HorizontalStackLayout Grid.Row="8" Grid.Column="1" Margin="20">
<Button WidthRequest="100" Text="Ajouter" TextColor="Black" Margin="20,0,20,0" Clicked="AddIngredient"/>
<Button WidthRequest="100" Text="Précédent" TextColor="Black" Margin="20,0" Clicked="RemoveIngredient"/>
</HorizontalStackLayout>
</VerticalStackLayout>
<Label Text="Saisir les étapes de la recette " Grid.Row="6" Margin="0,15"/>
<Entry Placeholder="Etape de la recette" Grid.Row="7" Margin="12,0"/>
<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>
<Button Grid.Row="10" Grid.ColumnSpan="2" Text="Validé" TextColor="Black" Clicked="AddRecipeValidation"/>
</Grid>
</VerticalStackLayout>
<Label Text="Saisir les ingrédients de la recette (nom, quantité, unité)" Grid.Row="6" Grid.Column="1" Margin="50,15"/>
<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>
</ScrollView>
</ContentPage>

@ -1,6 +1,7 @@
using Model;
using System.Diagnostics;
using Microsoft.Maui.Media;
using Microsoft.Maui.Controls;
namespace Views
{
@ -8,28 +9,24 @@ namespace Views
{
private List<Ingredient> ingredientList;
private List<PreparationStep> preparationStepList;
private Recipe recipeToAdd;
private Ingredient ingredient;
private PreparationStep preparationStep;
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<Ingredient> IngredientList { get => ingredientList; set => ingredientList = value; }
public List<PreparationStep> PreparationStepList { get => preparationStepList; set => preparationStepList = value; }
public AddRecipe(List<PreparationStep> preparationStepList)
{
PreparationStepList = preparationStepList;
}
public AddRecipe(List<Ingredient> ingredientList)
{
IngredientList = ingredientList;
}
public bool IsCaptureSupported => throw new NotImplementedException();
public Ingredient Ingredient { get => ingredient; set => ingredient = value ; }
public PreparationStep PreparationStepAdd { get => preparationStep; set => preparationStep = value; }
public AddRecipe()
{
InitializeComponent();
BindingContext = this;
RecipeToAdd = new Recipe("Nouvelle Recette");
IngredientList = new List<Ingredient>();
PreparationStepList = new List<PreparationStep>();
}
private void PickPhoto(object sender, EventArgs e)
{
@ -38,21 +35,118 @@ namespace Views
private void AddRecipeValidation(object sender, EventArgs e)
{
if (IsCaptureSupported)
{
}
}
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)
{
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"
Title="ViewRecette"
x:Name="nrecipe">
<VerticalStackLayout BindingContext="{Binding Recipe}">
<local:MiniHeader
<ScrollView>
<VerticalStackLayout BindingContext="{Binding Recipe}">
<local:MiniHeader
BindingContext="{Binding Recipe, Source={x:Reference nrecipe}}"
TitleMini="{Binding Title}"
NeedReturn="True"
HeightRequest="100"/>
<Image
<Image
Source="{Binding Image}"
HeightRequest="150"
Aspect="AspectFill"/>
<Grid ColumnDefinitions="200,*">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Margin="10,20,0,0"
<Grid ColumnDefinitions="200,*">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Margin="10,20,0,0"
Text="Ingrédients :"
FontSize="Subtitle"
FontAttributes="Bold"/>
<ListView Margin="10,60,20,0"
<ListView Margin="10,60,20,0"
Grid.RowSpan="4"
ItemsSource="{Binding Ingredients}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid ColumnDefinitions="auto,auto, auto"
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid ColumnDefinitions="auto,auto, auto"
RowDefinitions="auto">
<Label Text="{Binding QuantityI}" Grid.Column="0" Grid.Row="0"/>
<Label Text="{Binding Name}" Grid.Column=" 1" Grid.Row="0"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Label Margin="10,0,20,20"
<Label Text="{Binding QuantityI}" Grid.Column="0" Grid.Row="0"/>
<Label Text="{Binding Name}" Grid.Column=" 1" Grid.Row="0"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Label Margin="10,0,20,20"
Grid.Column="1"
Grid.Row="0"
Text="Préparation :"
FontSize="Subtitle"
FontAttributes="Bold"/>
<ListView Margin="10,30,0,0"
<ListView Margin="10,30,0,0"
Grid.Column="1"
ItemsSource="{Binding PreparationSteps}">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Order, StringFormat='Etape {0}'}"
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Order, StringFormat='Etape {0}'}"
Detail="{Binding Description}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
<Border VerticalOptions="End"
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
<Border VerticalOptions="End"
HorizontalOptions="FillAndExpand"
Stroke="#C49B33"
StrokeThickness="2"
@ -71,20 +67,20 @@
Padding="20,10,80,20"
Margin="50,100,50,0"
MinimumHeightRequest="200">
<ListView ItemsSource="{Binding Reviews}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid ColumnDefinitions="600,*" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.ColumnSpan="2"
<ListView ItemsSource="{Binding Reviews}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid ColumnDefinitions="600,*" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.ColumnSpan="2"
Grid.Row="0"
Text=" Meilleure revue : "
FontAttributes="Bold"/>
<Label
<Label
Background="#FFCB9A"
Grid.Column="0"
Grid.Row="1"
@ -92,17 +88,16 @@
Padding="10,10,10,10"
Text="{Binding Content}"
Margin="0,0,15,0"/>
<Button Grid.Column="1"
<Button Grid.Column="1"
Grid.Row="2"
Background="#FFCB9A"
Text="Voir plus"
TextColor="Black"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Border>
</VerticalStackLayout>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Border>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
Loading…
Cancel
Save