Merge pull request 'Enhance details style' (#5) from detail_interface into main
Reviewed-on: https://codefirst.iut.uca.fr/git/clement.freville2/tiramisu/pulls/5
This commit is contained in:
@@ -1,21 +1,26 @@
|
|||||||
<form [formGroup]="createForm" (ngSubmit)="onSubmit()">
|
<form [formGroup]="createForm" (ngSubmit)="onSubmit()">
|
||||||
<mat-form-field>
|
<div>
|
||||||
<label for="name">Nom</label>
|
<mat-form-field>
|
||||||
<input matInput id="name" type="text" formControlName="name" required>
|
<label for="name">Nom</label>
|
||||||
@if (createForm.controls.name.errors?.['minlength']) {
|
<input matInput id="name" type="text" formControlName="name" required>
|
||||||
<mat-error>Le nom doit contenir au moins {{ createForm.controls.name.errors!['minlength'].requiredLength }} caractères.</mat-error>
|
@if (createForm.controls.name.errors?.['minlength']) {
|
||||||
}
|
<mat-error>Le nom doit contenir au moins {{ createForm.controls.name.errors!['minlength'].requiredLength }} caractères.</mat-error>
|
||||||
@if (createForm.controls.name.errors?.['maxlength']) {
|
}
|
||||||
<mat-error>Le nom ne peut dépasser {{ createForm.controls.name.errors!['maxlength'].requiredLength }} caractères.</mat-error>
|
@if (createForm.controls.name.errors?.['maxlength']) {
|
||||||
}
|
<mat-error>Le nom ne peut dépasser {{ createForm.controls.name.errors!['maxlength'].requiredLength }} caractères.</mat-error>
|
||||||
</mat-form-field>
|
}
|
||||||
<mat-form-field>
|
</mat-form-field>
|
||||||
<label for="description">Description</label>
|
</div>
|
||||||
<textarea matInput id="description" type="text" formControlName="description" required></textarea>
|
<div>
|
||||||
@if (createForm.controls.description.errors?.['maxlength']) {
|
<mat-form-field>
|
||||||
<mat-error>La description ne peut dépasser {{ createForm.controls.description.errors!['maxlength'].requiredLength }} caractères.</mat-error>
|
<label for="description">Description</label>
|
||||||
}
|
<textarea matInput id="description" type="text" formControlName="description" required></textarea>
|
||||||
</mat-form-field>
|
@if (createForm.controls.description.errors?.['maxlength']) {
|
||||||
|
<mat-error>La description ne peut dépasser {{ createForm.controls.description.errors!['maxlength'].requiredLength }} caractères.</mat-error>
|
||||||
|
}
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="image">Image</label>
|
<label for="image">Image</label>
|
||||||
<button type="button" mat-raised-button (click)="fileInput.click()">Téléverser</button>
|
<button type="button" mat-raised-button (click)="fileInput.click()">Téléverser</button>
|
||||||
@@ -26,14 +31,21 @@
|
|||||||
<label for="description">Ingrédients</label>
|
<label for="description">Ingrédients</label>
|
||||||
<ul>
|
<ul>
|
||||||
@for (ingredient of ingredientEntries; track ingredient.idIngredient) {
|
@for (ingredient of ingredientEntries; track ingredient.idIngredient) {
|
||||||
<li>#{{ ingredient.idIngredient }} <input [(ngModel)]="ingredient.quantity" type="number" [ngModelOptions]="{standalone: true}"></li>
|
<li>
|
||||||
|
{{ getIngredient(ingredient.idIngredient).name }}
|
||||||
|
<mat-form-field>
|
||||||
|
<input matInput [(ngModel)]="ingredient.quantity" type="number" [ngModelOptions]="{standalone: true}">
|
||||||
|
</mat-form-field>
|
||||||
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
<select id="selectedIngredient" formControlName="selectedIngredient">
|
<mat-form-field>
|
||||||
@for (ingredient of ingredients; track ingredient.id) {
|
<mat-select matInput id="selectedIngredient" formControlName="selectedIngredient">
|
||||||
<option [ngValue]="ingredient.id">{{ ingredient.name }}</option>
|
@for (ingredient of ingredients; track ingredient.id) {
|
||||||
}
|
<mat-option value="{{ingredient.id}}">{{ ingredient.name }}</mat-option>
|
||||||
</select>
|
}
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
<button mat-button type="button" (click)="onAddIngredient()">Add</button>
|
<button mat-button type="button" (click)="onAddIngredient()">Add</button>
|
||||||
</div>
|
</div>
|
||||||
<button mat-flat-button class="button" type="submit">{{ recipeId === -1 ? 'Ajouter' : 'Éditer' }}</button>
|
<button mat-flat-button class="button" type="submit">{{ recipeId === -1 ? 'Ajouter' : 'Éditer' }}</button>
|
||||||
|
@@ -6,11 +6,13 @@ import { RecipeService } from '../recipe.service';
|
|||||||
import { MatInputModule } from '@angular/material/input';
|
import { MatInputModule } from '@angular/material/input';
|
||||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
import { MatButton } from '@angular/material/button';
|
import { MatButton } from '@angular/material/button';
|
||||||
|
import { MatOption } from '@angular/material/core';
|
||||||
|
import { MatSelect } from '@angular/material/select';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-recipe-add',
|
selector: 'app-recipe-add',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [ReactiveFormsModule, FormsModule, MatFormFieldModule, MatInputModule, MatButton, MatFormFieldModule],
|
imports: [ReactiveFormsModule, FormsModule, MatFormFieldModule, MatOption, MatSelect, MatInputModule, MatButton, MatFormFieldModule],
|
||||||
templateUrl: './recipe-add.component.html',
|
templateUrl: './recipe-add.component.html',
|
||||||
})
|
})
|
||||||
export class RecipeAddComponent {
|
export class RecipeAddComponent {
|
||||||
@@ -22,12 +24,12 @@ export class RecipeAddComponent {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ingredientEntries: IngredientEntry[] = [];
|
ingredientEntries: IngredientEntry[] = [];
|
||||||
ingredients: Ingredient[] = [{
|
ingredients: Ingredient[] = [];
|
||||||
id: 1,
|
|
||||||
name: 'Paprika',
|
|
||||||
}];
|
|
||||||
|
|
||||||
selectedFilename: string = '';
|
selectedFilename: string = '';
|
||||||
|
getIngredient(n: number): Ingredient {
|
||||||
|
return this.ingredients.find(v => v.id === n)!
|
||||||
|
}
|
||||||
|
|
||||||
#recipeId: number = -1;
|
#recipeId: number = -1;
|
||||||
@Input()
|
@Input()
|
||||||
@@ -48,7 +50,9 @@ export class RecipeAddComponent {
|
|||||||
return this.#recipeId;
|
return this.#recipeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(private formBuilder: FormBuilder, private recipes: RecipeService, private router: Router) {}
|
constructor(private formBuilder: FormBuilder, private recipes: RecipeService, private router: Router) {
|
||||||
|
this.ingredients = this.recipes.getAllIngredients();
|
||||||
|
}
|
||||||
|
|
||||||
onSubmit(): void {
|
onSubmit(): void {
|
||||||
if (this.createForm.invalid) {
|
if (this.createForm.invalid) {
|
||||||
@@ -71,6 +75,8 @@ export class RecipeAddComponent {
|
|||||||
|
|
||||||
onAddIngredient(): void {
|
onAddIngredient(): void {
|
||||||
const value = this.createForm.value;
|
const value = this.createForm.value;
|
||||||
|
console.log(value);
|
||||||
|
|
||||||
if (!value.selectedIngredient) {
|
if (!value.selectedIngredient) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,15 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Recipe } from '../cookbook/type';
|
import { Ingredient, Recipe } from '../cookbook/type';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class RecipeService {
|
export class RecipeService {
|
||||||
#recipes: Recipe[] = [
|
#recipes: Recipe[] = [
|
||||||
{ id: 0, name: 'crepe1', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
|
{ id: 0, name: 'crepe1', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [
|
||||||
|
{idIngredient:1,idRecipe:0,quantity:10},
|
||||||
|
{idIngredient:2,idRecipe:0,quantity:15}
|
||||||
|
] },
|
||||||
{ id: 1, name: 'crepe2', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
|
{ id: 1, name: 'crepe2', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
|
||||||
{ id: 2, name: 'crepe3', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
|
{ id: 2, name: 'crepe3', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
|
||||||
{ id: 3, name: 'crepe4', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
|
{ id: 3, name: 'crepe4', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
|
||||||
@@ -22,14 +25,27 @@ export class RecipeService {
|
|||||||
{ id: 13, name: 'crepe14', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
|
{ id: 13, name: 'crepe14', description: 'La meilleure recette de pâte à crêpes', image: '', ingredients: [] },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
#ingredients: Ingredient[] = [
|
||||||
|
{ id:1, name:'Sucre'},
|
||||||
|
{ id:2, name:'Farine'}
|
||||||
|
]
|
||||||
|
|
||||||
getAll(): Recipe[] {
|
getAll(): Recipe[] {
|
||||||
return this.#recipes;
|
return this.#recipes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAllIngredients(): Ingredient[] {
|
||||||
|
return this.#ingredients;
|
||||||
|
}
|
||||||
|
|
||||||
get(id: number): Recipe | null {
|
get(id: number): Recipe | null {
|
||||||
return this.#recipes.find((recipe) => recipe.id === id) || null;
|
return this.#recipes.find((recipe) => recipe.id === id) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getIngredientById(id: number): Ingredient | null {
|
||||||
|
return this.#ingredients.find((ingredient) => ingredient.id === id) || null;
|
||||||
|
}
|
||||||
|
|
||||||
add(recipe: Omit<Recipe, 'id'>): void {
|
add(recipe: Omit<Recipe, 'id'>): void {
|
||||||
const id = this.#recipes.length ? Math.max(...this.#recipes.map((recipe) => recipe.id)) + 1 : 1;
|
const id = this.#recipes.length ? Math.max(...this.#recipes.map((recipe) => recipe.id)) + 1 : 1;
|
||||||
this.#recipes.push({
|
this.#recipes.push({
|
||||||
|
@@ -1,4 +1,39 @@
|
|||||||
<p>{{recipe.id}}</p>
|
<style>
|
||||||
<p>{{recipe.name}}</p>
|
.container {
|
||||||
<p>{{recipe.description}}</p>
|
background-color: #fff;
|
||||||
|
position: relative;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 300px 600px;
|
||||||
|
}
|
||||||
|
.container img {
|
||||||
|
width: 300px;
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container_text {
|
||||||
|
padding: 40px 40px 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<img ng-if="recipe.image" src="https://placehold.co/200x200" alt={{recipe.name}}/>
|
||||||
|
|
||||||
|
<div class="container_text">
|
||||||
|
|
||||||
|
<h1>{{recipe.name}}</h1>
|
||||||
|
<p>
|
||||||
|
{{recipe.description}}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Ingredients</h3>
|
||||||
|
<p>
|
||||||
|
<li *ngFor="let ingredient of recipe.ingredients">
|
||||||
|
{{ this.recipes.getIngredientById(ingredient.idIngredient)?.name }}: {{ ingredient.quantity }}g
|
||||||
|
</li>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
import { Recipe } from '../../cookbook/type';
|
import { Recipe } from '../../cookbook/type';
|
||||||
import { RecipeService } from '../recipe.service';
|
import { RecipeService } from '../recipe.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-recipe',
|
selector: 'app-recipe',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [],
|
imports: [CommonModule],
|
||||||
templateUrl: './recipe.component.html',
|
templateUrl: './recipe.component.html',
|
||||||
})
|
})
|
||||||
export class RecipeComponent {
|
export class RecipeComponent {
|
||||||
|
Reference in New Issue
Block a user