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,8 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Views.AddRecipe"
Title="AddRecipe"
xmlns:local="clr-namespace:Views">
<VerticalStackLayout>
xmlns:local="clr-namespace:Views"
x:Name="nAddRecipe">
<ScrollView>
<VerticalStackLayout BindingContext="{Binding RecipeToAdd}">
<local:MiniHeader
TitleMini="Ajouter une recette"
NeedReturn="True"
@ -15,56 +17,77 @@
<Label Text="Titre de la recette :"/>
<Entry Placeholder="Saisie du texte de la recette correspondante"
Grid.Row="1"
Margin="10"/>
Margin="10"
Text="{Binding Title}"
x:Name="RecipeName"/>
<Label Text="Type de la recette" Grid.Row="2"/>
<CheckBox x:Name="CheckEntree" Grid.Row="3" Margin="10,0,20,0" />
<RadioButton 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" />
<RadioButton 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" />
<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>
<HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
<Label Text="Recettes Economiques" VerticalOptions="Center"/>
<CheckBox x:Name="checkEconomique"/>
<RadioButton x:Name="checkEconomique"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
<Label Text="Recettes Rapides" VerticalOptions="Center"/>
<CheckBox x:Name="checkFast"/>
<RadioButton x:Name="checkFast"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
<Label Text="Recettes Faciles" VerticalOptions="Center"/>
<CheckBox x:Name="checkEasy"/>
<RadioButton x:Name="checkEasy"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
<Label Text="Recettes Légères" VerticalOptions="Center"/>
<CheckBox x:Name="checkLight"/>
<RadioButton x:Name="checkLight"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<HorizontalStackLayout RadioButtonGroup.GroupName="PriorityGroup">
<Label Text="Recettes Gourmandes" VerticalOptions="Center"/>
<CheckBox x:Name="checkGourmet"/>
<RadioButton x:Name="checkGourmet"/>
</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"/>
<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 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"/>
<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>
<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 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 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"/>
<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>
<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)
{
@ -37,22 +34,119 @@ 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,8 +5,10 @@
xmlns:local="clr-namespace:Views"
Title="ViewRecette"
x:Name="nrecipe">
<ScrollView>
<VerticalStackLayout BindingContext="{Binding Recipe}">
<local:MiniHeader
BindingContext="{Binding Recipe, Source={x:Reference nrecipe}}"
TitleMini="{Binding Title}"
NeedReturn="True"
HeightRequest="100"/>
@ -48,7 +50,6 @@
FontAttributes="Bold"/>
<ListView Margin="10,30,0,0"
Grid.Column="1"
ItemsSource="{Binding PreparationSteps}">
<ListView.ItemTemplate>
<DataTemplate>
@ -57,12 +58,7 @@
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
<Border VerticalOptions="End"
HorizontalOptions="FillAndExpand"
Stroke="#C49B33"
@ -101,8 +97,7 @@
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Border>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
Loading…
Cancel
Save