Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
|
ff74739558 | 10 months ago |
|
0c0d626934 | 10 months ago |
|
477d303184 | 10 months ago |
|
e60455b494 | 10 months ago |
|
998d4c4860 | 10 months ago |
|
b0e716aced | 10 months ago |
|
995335e259 | 10 months ago |
|
9315764d01 | 10 months ago |
|
4cf018fedd | 10 months ago |
|
0e5f4b300c | 10 months ago |
|
18c4c617de | 10 months ago |
|
49ae2dc7f6 | 10 months ago |
@ -0,0 +1,51 @@
|
||||
<style>
|
||||
.command-list {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.recipe-item {
|
||||
background-color: #fff;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
margin: 10px 0;
|
||||
padding: 10px 20px;
|
||||
width: 80%;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.recipe-item h3 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.recipe-item button {
|
||||
background-color: #ff5252;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
padding: 5px 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.recipe-item button:hover {
|
||||
background-color: #ff0000;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="command-list">
|
||||
<h2>Ma Commande</h2>
|
||||
<div *ngFor="let recipe of recipes" class="recipe-item">
|
||||
<img src="{{recipe.$image}}" width="10%" alt="ImageRecipe"
|
||||
onerror="this.onerror=null;this.src='https://placehold.co/100x100/black/white?text=Not+Found';">
|
||||
<h3>{{ recipe.$name }}</h3>
|
||||
<button (click)="removeRecipe(recipe)">Retirer</button>
|
||||
</div>
|
||||
<p *ngIf="recipes.length === 0">Aucune recette dans la commande.</p>
|
||||
</div>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CommandComponent } from './command.component';
|
||||
|
||||
describe('CommandComponent', () => {
|
||||
let component: CommandComponent;
|
||||
let fixture: ComponentFixture<CommandComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [CommandComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(CommandComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,25 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { CommandService } from '../../service/command.service';
|
||||
import { Recipe } from '../../model/recipe.model';
|
||||
import {NgFor, NgIf} from '@angular/common';
|
||||
import { RouterLink } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-command',
|
||||
standalone: true,
|
||||
imports: [NgFor, RouterLink, NgIf],
|
||||
templateUrl: './command.component.html'
|
||||
})
|
||||
export class CommandComponent {
|
||||
recipes: Recipe[] = [];
|
||||
errorMessage: string | null = null;
|
||||
|
||||
constructor(private commandService: CommandService) {
|
||||
this.recipes = this.commandService.getRecipes();
|
||||
}
|
||||
|
||||
removeRecipe(recipe: Recipe) {
|
||||
this.commandService.removeRecipe(recipe);
|
||||
this.recipes = this.commandService.getRecipes();
|
||||
}
|
||||
}
|
@ -1,45 +1,62 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { IngredientService } from "../../service/ingredient.service";
|
||||
import { Ingredient } from "../../model/ingredient.model";
|
||||
import {NgFor} from "@angular/common";
|
||||
import {LoginService} from "../../service/login.service";
|
||||
import {Link} from "../../model/link.model";
|
||||
import {LinkService} from "../../service/link.service";
|
||||
import { NgFor, NgIf } from "@angular/common";
|
||||
import { FormsModule } from "@angular/forms";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
|
||||
@Component({
|
||||
selector: 'app-ingredients',
|
||||
standalone: true,
|
||||
imports: [
|
||||
NgFor,
|
||||
NgIf,
|
||||
FormsModule
|
||||
],
|
||||
providers: [IngredientService, HttpClient],
|
||||
templateUrl: './ingredients.component.html',
|
||||
styleUrl: './ingredients.component.css'
|
||||
})
|
||||
export class IngredientsComponent implements OnInit {
|
||||
|
||||
ingredients: Ingredient[] = [];
|
||||
links: Link[] = this.linkService.getLinks()
|
||||
newIngredient: Ingredient = { id: '0', name: '', description: '' };
|
||||
editIngredient: Ingredient | null = null;
|
||||
|
||||
constructor(private ingredientService : IngredientService,private loginService: LoginService,private linkService : LinkService) {}
|
||||
constructor(private ingredientService: IngredientService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.loadIngredients();
|
||||
}
|
||||
|
||||
loadIngredients() {
|
||||
this.ingredientService.getAll().subscribe(ingredients => {
|
||||
this.ingredients = ingredients;
|
||||
});
|
||||
}
|
||||
|
||||
onClickLogin(event: Event): void {
|
||||
event.preventDefault(); // Prevent the default anchor behavior
|
||||
this.loginService.login();
|
||||
addIngredient() {
|
||||
this.ingredientService.add(this.newIngredient).subscribe(ingredient => {
|
||||
this.ingredients.push(ingredient);
|
||||
this.newIngredient = { id: '0', name: '', description: '' };
|
||||
});
|
||||
}
|
||||
|
||||
onClickLogout(event: Event): void {
|
||||
event.preventDefault(); // Prevent the default anchor behavior
|
||||
this.loginService.logout();
|
||||
edit(ingredient: Ingredient) {
|
||||
this.editIngredient = { ...ingredient };
|
||||
}
|
||||
|
||||
isLogged(): boolean {
|
||||
return this.loginService.isLogged();
|
||||
updateIngredient() {
|
||||
if (this.editIngredient) {
|
||||
this.ingredientService.update(this.editIngredient).subscribe(updatedIngredient => {
|
||||
const index = this.ingredients.findIndex(i => i.id === updatedIngredient.id);
|
||||
this.ingredients[index] = updatedIngredient;
|
||||
this.editIngredient = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
cancelEdit() {
|
||||
this.editIngredient = null;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,85 @@
|
||||
<h1>{{recipe?.$name}}</h1>
|
||||
<p> {{recipe?.$createdAt}}</p>
|
||||
<style>
|
||||
.recipe-details {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #bab6b6;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
<h3>{{recipe?.$description}}</h3>
|
||||
.recipe-card {
|
||||
background-color: #fff;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
transition: transform 0.2s;
|
||||
width: 80%;
|
||||
margin: 20px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
<img [src]="recipe?.$image" alt="Recette 1" class="recipe-image"
|
||||
onerror="this.onerror=null;this.src='https://placehold.co/100x100/black/white?text=Not+Found';">
|
||||
.recipe-card:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.recipe-image {
|
||||
width: 100%;
|
||||
max-width: 300px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.recipe-content {
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.recipe-title {
|
||||
font-size: 2em;
|
||||
margin: 0 0 10px;
|
||||
}
|
||||
|
||||
.recipe-date {
|
||||
color: #777;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.recipe-description {
|
||||
font-size: 1.2em;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.ingredient-list {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.ingredient-item {
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
<div class="recipe-details">
|
||||
<div class="recipe-card">
|
||||
<h1 class="recipe-title">{{ recipe?.$name }}</h1>
|
||||
<p class="recipe-date">{{ recipe?.$createdAt }}</p>
|
||||
<img [src]="recipe?.$image" alt="{{ recipe?.$name }}" class="recipe-image"
|
||||
onerror="this.onerror=null;this.src='https://placehold.co/300x300/black/white?text=Not+Found';">
|
||||
<div class="recipe-content">
|
||||
<h3 class="recipe-description">{{ recipe?.$description }}</h3>
|
||||
<h4>Ingrédients</h4>
|
||||
<ul class="ingredient-list">
|
||||
<li class="ingredient-item" *ngFor="let ingredient of ingredients">
|
||||
{{ ingredient.ingredient.name }} : {{ ingredient.quantity }} {{ ingredient.unit }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
export interface Ingredient {
|
||||
$id : number,
|
||||
$name : string
|
||||
id : string,
|
||||
name : string,
|
||||
description : string,
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
import { Unity } from "./unity";
|
||||
import { Ingredient } from "./ingredient.model";
|
||||
import { QuantifiedIngredient } from "./quantified-ingredient.model";
|
||||
|
||||
export class QuantifiedIngredientGetter implements QuantifiedIngredient {
|
||||
constructor(
|
||||
public $quantity: number,
|
||||
public $unit: Unity,
|
||||
public $ingredient: Ingredient
|
||||
) {}
|
||||
|
||||
get quantity(): number {
|
||||
return this.$quantity;
|
||||
}
|
||||
|
||||
get unit(): Unity {
|
||||
return this.$unit;
|
||||
}
|
||||
|
||||
get ingredient(): Ingredient {
|
||||
return this.$ingredient;
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
import {QuantifiedIngredient} from "./quantified-ingredient.model";
|
||||
import {QuantifiedIngredientGetter} from "./quantified-ingredient-getter.model";
|
||||
|
||||
export interface Recipe {
|
||||
$id : number,
|
||||
$name : string,
|
||||
$description: string,
|
||||
$createdAt : Date,
|
||||
$ingredients: QuantifiedIngredient[],
|
||||
$ingredients: QuantifiedIngredientGetter[],
|
||||
$image?: string
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Recipe } from "../model/recipe.model";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CommandService {
|
||||
private recipes: Recipe[] = JSON.parse(localStorage.getItem('command') || '[]');
|
||||
|
||||
addRecipe(recipe: Recipe) {
|
||||
this.recipes.push(recipe);
|
||||
localStorage.setItem('command', JSON.stringify(this.recipes));
|
||||
}
|
||||
|
||||
getRecipes(): Recipe[] {
|
||||
return this.recipes;
|
||||
}
|
||||
|
||||
removeRecipe(recipe: Recipe) {
|
||||
const index = this.recipes.indexOf(recipe);
|
||||
if (index > -1) {
|
||||
this.recipes.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,26 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Ingredient } from "../model/ingredient.model";
|
||||
import {$INGREDIENTS} from "../data/ingredient.stub";
|
||||
import {Observable, of} from "rxjs";
|
||||
|
||||
import { Observable } from "rxjs";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class IngredientService {
|
||||
|
||||
private apiUrl = 'https://664ba07f35bbda10987d9f99.mockapi.io/api/ingredients';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getAll(): Observable<Ingredient[]> {
|
||||
return of($INGREDIENTS);
|
||||
return this.http.get<Ingredient[]>(this.apiUrl);
|
||||
}
|
||||
|
||||
add(ingredient: Ingredient): Observable<Ingredient> {
|
||||
return this.http.post<Ingredient>(this.apiUrl, ingredient);
|
||||
}
|
||||
|
||||
update(ingredient: Ingredient): Observable<Ingredient> {
|
||||
return this.http.put<Ingredient>(`${this.apiUrl}/${ingredient.id}`, ingredient);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue