Compare commits

..

30 Commits

Author SHA1 Message Date
Dorian HODIN ff74739558 Mise à jour de 'daidokoro/Dockerfile'
continuous-integration/drone/push Build is passing Details
1 year ago
Dorian HODIN 0c0d626934 Supprimer 'daidokoro/nginx.conf'
continuous-integration/drone/push Build was killed Details
1 year ago
Dorian HODIN 477d303184 Transférer les fichiers vers 'daidokoro'
continuous-integration/drone/push Build is failing Details
1 year ago
Dorian HODIN e60455b494 Mise à jour de 'daidokoro/Dockerfile'
continuous-integration/drone/push Build is failing Details
1 year ago
Dorian HODIN 998d4c4860 Mise à jour de 'daidokoro/Dockerfile'
continuous-integration/drone/push Build is passing Details
1 year ago
Dorian HODIN b0e716aced Mise à jour de 'daidokoro/Dockerfile'
continuous-integration/drone/push Build is passing Details
1 year ago
Corentin RICHARD 995335e259 Publish ReadMe
continuous-integration/drone/push Build is passing Details
1 year ago
Corentin RICHARD 9315764d01 test deploy
continuous-integration/drone/push Build is failing Details
1 year ago
Dorian HODIN 4cf018fedd Adding Command section, local storage exceed problem, adding error managing
continuous-integration/drone/push Build is failing Details
1 year ago
Dorian HODIN 0e5f4b300c Adding recipe-details front
continuous-integration/drone/push Build is failing Details
1 year ago
Dorian HODIN 18c4c617de Adding Ingredients from API, add and edit working good, front of the ingredients page
continuous-integration/drone/push Build is passing Details
1 year ago
Dorian HODIN 49ae2dc7f6 Merge pull request 'formFront' (#6) from formFront into master
continuous-integration/drone/push Build is passing Details
1 year ago
Dorian HODIN 4f6bdfb558 Adding Form front with the new form
continuous-integration/drone/push Build is passing Details
1 year ago
Dorian HODIN eb5dc52a84 Merge branch 'refs/heads/master' into formFront
1 year ago
Corentin RICHARD e038252020 Merge pull request 'Adding image to Recipe and one ingredient checker' (#5) from formImage into master
continuous-integration/drone/push Build is passing Details
1 year ago
Corentin RICHARD cd07d96d44 Adding image to Recipe and one ingredient checker
continuous-integration/drone/push Build is passing Details
1 year ago
Corentin RICHARD 45a802414e Merge pull request 'listIngredients' (#4) from listIngredients into master
continuous-integration/drone/push Build is passing Details
1 year ago
Corentin RICHARD 51580432bd Adding list of ingredients with guards and detail of recipe
continuous-integration/drone/push Build is passing Details
1 year ago
Corentin RICHARD dafff55563 Adding list of ingredients with guards and detail of recipe
1 year ago
Corentin RICHARD 62b1b37320 Merge pull request 'formAdvanced' (#3) from formAdvanced into master
continuous-integration/drone/push Build is passing Details
1 year ago
Corentin RICHARD e2cd09bb99 Adding login and giuard
continuous-integration/drone/push Build is passing Details
1 year ago
Corentin RICHARD 95ee995051 Merge branch 'master' of https://codefirst.iut.uca.fr/git/dorian.hodin/Daidokoro into formAdvanced
1 year ago
Corentin RICHARD 016118938c Adding logging
1 year ago
Corentin RICHARD 46da11e3c8 Adding routing
1 year ago
Dorian HODIN 4f43477810 Adding Form Front, and verification of empty field or not
continuous-integration/drone/push Build is passing Details
1 year ago
Dorian HODIN 7cc4820475 Merge branch 'refs/heads/formAdvanced' into formFront
1 year ago
Corentin RICHARD 2b85d50087 Adding ingredients in form
continuous-integration/drone/push Build is passing Details
1 year ago
Dorian HODIN 370b3467b2 Adding new gitignore for workspace
continuous-integration/drone/push Build is passing Details
1 year ago
Dorian HODIN 61e915eca0 Adding good front and pagination
continuous-integration/drone/push Build is passing Details
1 year ago
Corentin RICHARD 23edc7adda Merge pull request 'formRecipe' (#2) from formRecipe into master
continuous-integration/drone/push Build is passing Details
1 year ago

@ -1,32 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="e26b532a-2e1d-44b6-8438-5d55a88b6611" name="Changes" comment="" />
<list default="true" id="c5a06892-a370-4c6a-a9cf-5d61f93a285b" name="Changes" comment="Adding Command section, local storage exceed problem, adding error managing">
<change afterPath="$PROJECT_DIR$/daidokoro/src/app/service/command.service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/daidokoro/src/app/component/command/command.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/daidokoro/src/app/component/command/command.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/daidokoro/src/app/component/command/command.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/daidokoro/src/app/component/command/command.component.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/daidokoro/src/app/component/recipe-list/recipe-list.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/daidokoro/src/app/component/recipe-list/recipe-list.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/daidokoro/src/app/component/recipe-list/recipe-list.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/daidokoro/src/app/component/recipe-list/recipe-list.component.ts" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="TypeScript File" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="formFront" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 2
}]]></component>
<component name="ProjectId" id="2i0RBJa4QzAvGYd8vYvrfEV0WHe" />
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 7
}</component>
<component name="ProjectId" id="2hxUMd4IvFZ2RBuUoixQsBySsiP" />
<component name="ProjectLevelVcsManager">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "master",
"last_opened_file_path": "/home/Koroh/Repos/Daidokoro/daidokoro",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;master&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/dorian/Documents/but3/Angular/Daidokoro&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;,
&quot;ts.external.directory.path&quot;: &quot;/home/dorian/Documents/but3/Angular/Daidokoro/daidokoro/node_modules/typescript/lib&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/daidokoro/public" />
<recent name="$PROJECT_DIR$/daidokoro/src/app" />
</key>
</component>
<component name="SharedIndexes">
<attachedChunks>
<set>
@ -37,13 +75,76 @@
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="e26b532a-2e1d-44b6-8438-5d55a88b6611" name="Changes" comment="" />
<created>1718625373590</created>
<changelist id="c5a06892-a370-4c6a-a9cf-5d61f93a285b" name="Changes" comment="" />
<created>1718535175328</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1718625373590</updated>
<workItem from="1718625376418" duration="43000" />
<updated>1718535175328</updated>
<workItem from="1718535176543" duration="94000" />
<workItem from="1718535276928" duration="51000" />
<workItem from="1718535331746" duration="130000" />
<workItem from="1718624272278" duration="96000" />
<workItem from="1718625479373" duration="4985000" />
<workItem from="1719217543390" duration="31000" />
<workItem from="1719217580949" duration="135000" />
<workItem from="1719755658119" duration="6807000" />
</task>
<task id="LOCAL-00001" summary="Adding Front">
<option name="closed" value="true" />
<created>1718630357884</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1718630357884</updated>
</task>
<task id="LOCAL-00002" summary="Adding Form front with the new form">
<option name="closed" value="true" />
<created>1719666928847</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1719666928847</updated>
</task>
<task id="LOCAL-00003" summary="Adding Ingredients from API, add and edit working good, front of the ingredients page">
<option name="closed" value="true" />
<created>1719757925681</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1719757925681</updated>
</task>
<task id="LOCAL-00004" summary="Adding recipe-details front">
<option name="closed" value="true" />
<created>1719760748129</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1719760748129</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="Adding Front" />
<MESSAGE value="Adding Form front with the new form" />
<MESSAGE value="Adding Ingredients from API, add and edit working good, front of the ingredients page" />
<MESSAGE value="Adding recipe-details front" />
<MESSAGE value="Adding Command section, local storage exceed problem, adding error managing" />
<option name="LAST_COMMIT_MESSAGE" value="Adding Command section, local storage exceed problem, adding error managing" />
</component>
</project>

@ -12,9 +12,72 @@
![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)
</div>
# :bookmark: Présentation
# Daidokoro
## Lancer l'application
Pour lancer l'application, veuillez suivre les étapes suivantes :
1. Cloner le repository du projet.
2. Se rendre dans le dossier `daidokoro`.
3. Exécuter la commande suivante : `ng serve --open`.
## Présentation rapide du projet
Daidokoro est un projet réalisé en Angular. Il s'agit d'une application web de gestion de recettes et d'ingrédients.
Les fonctionnalités incluent la gestion des utilisateurs, la consultation, l'ajout, la modification et la suppression d'ingrédients, ainsi que la création et la commande de recettes.
Le projet est conçu pour être intuitif et facile à utiliser, avec une interface utilisateur agréable et des fonctionnalités robustes.
## Prérequis demandés
Pour ce projet, les fonctionnalités suivantes étaient requises :
- Une barre de navigation commune à tout le site avec :
- Une page de connexion (/login) permettant de créer un cookie ou un local storage avec une valeur `isAdmin = true` et une redirection vers la page des ingrédients. Le bouton de connexion n'apparaît que si la valeur `isAdmin` est `false` ou inexistante.
- Une page de déconnexion (/logout) ayant le comportement inverse de la connexion.
- Un bouton vers la page des ingrédients avec une guard qui vérifie la valeur `isAdmin`. Si `true`, l'accès est permis, sinon, redirection vers la page d'accueil.
- Listing des ingrédients existants.
- Ajout d'un ingrédient.
- Modification d'un ingrédient.
- Connexion à une API pour les ingrédients, remplaçant le stub actuel.
- Sur la page d'accueil :
- Liste de recettes chargées depuis le local storage avec une image enregistrée ou un placeholder (`placehold.co/50x50`).
- Pagination de la liste de recettes.
- Un bouton pour ajouter une recette, faisant apparaître un formulaire avec :
- Nom
- Image
- Description
- Liste d'ingrédients avec possibilité de rajouter et de supprimer des ingrédients, au moins un devant être sélectionné.
- Un bouton "Commander" sur chaque recette qui ajoute la recette commandée à une liste "Commande en cours" sur la page d'accueil.
- Un bouton "Détail" redirigeant vers `/recettes/:id` et affichant la recette avec tous ses attributs.
## Réalisation des prérequis
Nous avons mis en œuvre toutes les fonctionnalités demandées :
- **Barre de navigation :** Elle est présente sur toutes les pages et comprend les boutons de connexion et de déconnexion. La gestion de `isAdmin` est effectuée via le local storage.
- **Guard d'accès aux ingrédients :** Nous avons implémenté une guard qui vérifie si l'utilisateur est connecté avant de permettre l'accès à la page des ingrédients.
- **Gestion des ingrédients :** Nous avons créé des pages pour lister, ajouter et modifier les ingrédients via l'API.
- **Page d'accueil :** La liste des recettes est chargée depuis le local storage et paginée. Un formulaire d'ajout de recette permet de créer de nouvelles recettes avec tous les champs requis. Chaque recette a des boutons "Commander" et "Détail".
## Fonctionnalités supplémentaires
En plus des fonctionnalités de base demandées, nous avons :
- Implémenté un style personnalisé pour l'application afin d'améliorer l'expérience utilisateur.
## Difficultés
Nous avons aussi rencontrer certaines difficultés :
- L'application a du mal à stocker dans le local storage à partir d'un certain quota, il est limité.
- Nous avons tenté de déployer l'application mais sans succès, le hub de codefirst était surchargé.
## Organisation du travail
Nous avons utilisé un système de branches et de merge requests pour organiser notre travail de manière efficace. Chaque fonctionnalité a été développée sur une branche dédiée et intégrée dans la branche principale via des merge requests. Cela nous a permis de travailler en parallèle tout en maintenant un code base stable et propre.
## Conclusion
Le projet Daidokoro a été une expérience enrichissante, nous permettant d'acquérir des connaissances en Angular et en gestion de projets.
このプロジェクトはレシピを閲覧・追加できるサイトを目指したプロジェクトです!あなたの作品を世界と共有しましょう!
# :construction: Développeurs

@ -1,5 +1,5 @@
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.
.idea/workspace.xml
# Compiled output
/dist
/tmp

@ -8,4 +8,6 @@ RUN npm install -g @angular/cli
RUN npm install
ENTRYPOINT ["ng", "serve", "--host", "0.0.0.0","--port","80"]
EXPOSE 4200
ENTRYPOINT ["ng", "serve", "--host", "0.0.0.0"]

@ -1,2 +1,53 @@
<app-accueil></app-accueil>
<!-- <app-recipe-form></app-recipe-form> -->
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Daidokoro</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Karma">
<style>
body, h1, h2, h3, h4, h5, h6 {
font-family: "Karma", sans-serif;
margin: 0;
padding: 0;
}
.navbar {
display: flex;
justify-content: space-around;
align-items: center;
background-color: #333;
padding: 1em;
}
.navbar a {
color: white;
text-decoration: none;
padding: 0.5em 1em;
}
.navbar a:hover {
background-color: #ddd;
color: black;
}
.recipe-container h2 {
font-size: 3em;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="navbar">
<div *ngIf="isLogged()">
<a href="/" (click)="onClickLogout($event)">Logout</a>
</div>
<div *ngIf="!isLogged()">
<a href="" (click)="onClickLogin($event)">Login</a>
</div>
<div *ngFor="let link of links">
<a routerLink="{{link.$link}}" routerLinkActive="active" ariaCurrentWhenActive="page">{{link.$name}}</a>
</div>
</div>
<router-outlet></router-outlet>
</body>
</html>

@ -1,15 +1,36 @@
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import {Component, NgModule} from '@angular/core';
import {Router, RouterLink, RouterLinkActive, RouterOutlet} from '@angular/router';
import {RecipeFormComponent} from "./component/recipe-form/recipe-form.component";
import {AccueilComponent} from "./component/accueil/accueil.component";
import {NgForOf, NgIf} from "@angular/common";
import {RecipeListComponent} from "./component/recipe-list/recipe-list.component";
import {LoginService} from "./service/login.service";
import {Link} from "./model/link.model";
import {LinkService} from "./service/link.service";
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, AccueilComponent,RecipeFormComponent],
imports: [RouterOutlet, AccueilComponent, RecipeFormComponent, NgForOf, NgIf, RecipeListComponent, RouterLink, RouterLinkActive],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent {
title = 'daidokoro';
links : Link[] = this.linkService.getLinks()
constructor(private loginService: LoginService,private linkService: LinkService) {
}
onClickLogin(event: Event): void {
event.preventDefault();
this.loginService.login();
}
onClickLogout(event: Event): void {
event.preventDefault();
this.loginService.logout();
}
isLogged(): boolean {
return this.loginService.isLogged();
}
}

@ -1,8 +1,13 @@
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import {provideRouter, withComponentInputBinding} from '@angular/router';
import { routes } from './app.routes';
import { provideHttpClient } from "@angular/common/http";
export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes)]
providers: [
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes,withComponentInputBinding()),
provideHttpClient()
]
};

@ -1,3 +1,13 @@
import { Routes } from '@angular/router';
import {AuthGuard} from "./guard.guard";
import {IngredientsComponent} from "./component/ingredients/ingredients.component";
import {AccueilComponent} from "./component/accueil/accueil.component";
import {RecipeDetailComponent} from "./component/recipe-detail/recipe-detail.component";
import {CommandComponent} from "./component/command/command.component";
export const routes: Routes = [];
export const routes: Routes = [
{path: 'ingredients', component:IngredientsComponent,canActivate: [AuthGuard]},
{path: 'recipe/:id', component: RecipeDetailComponent},
{path: '', component:AccueilComponent},
{path: 'command', component: CommandComponent}
];

@ -10,54 +10,50 @@
margin: 0;
padding: 0;
}
.navbar {
display: flex;
justify-content: space-around;
align-items: center;
background-color: #333;
padding: 1em;
}
.navbar a {
color: white;
text-decoration: none;
padding: 0.5em 1em;
}
.navbar a:hover {
background-color: #ddd;
color: black;
}
.content {
padding: 20px;
display: flex;
gap: 20px;
}
.recipe-container {
.recipe-container, .form-container {
background-color: #bab6b6;
color: black;
padding: 20px;
margin-top: 0;
flex: 1;
}
.recipe-container {
display: flex;
flex-direction: column;
}
.recipe-container h2 {
font-size: 3em;
margin-bottom: 10px;
}
.form-container {
display: none;
flex-direction: column;
}
.show-form .form-container {
display: flex;
}
.show-form .recipe-container, .show-form .form-container {
flex: 1;
}
.button-container {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="navbar">
<a href="#home">Accueil</a>
<a href="#recipes">Recettes</a>
<a href="#about">À Propos</a>
<a href="#contact">Contact</a>
</div>
<div class="content">
<div class="content" [class.show-form]="isFormVisible">
<div class="recipe-container">
<h2>Liste Recettes</h2>
<app-recipe-list></app-recipe-list>
<div class="button-container">
<button (click)="toggleForm()">Ajouter une recette</button>
</div>
<app-recipe-list [isFormVisible]="isFormVisible"></app-recipe-list>
</div>
<div>
<div class="form-container" *ngIf="isFormVisible">
<app-recipe-form (formSubmitted)="onRecipeSubmitted($event)"></app-recipe-form>
</div>
</div>

@ -3,20 +3,38 @@ import {RecipeListComponent} from "../recipe-list/recipe-list.component";
import {RecipeFormComponent} from "../recipe-form/recipe-form.component";
import {Recipe} from "../../model/recipe.model";
import {RecipeService} from "../../service/recipe.service";
import {NgForOf, NgIf} from "@angular/common";
import {LinkService} from "../../service/link.service";
import {LoginService} from "../../service/login.service";
import {CommonModule} from "@angular/common";
@Component({
selector: 'app-accueil',
standalone: true,
imports: [
RecipeListComponent,
RecipeFormComponent
RecipeFormComponent,
CommonModule,
NgForOf,
],
templateUrl: './accueil.component.html'
})
export class AccueilComponent {
isFormVisible: boolean = false;
constructor(private recipeService: RecipeService) {
}
constructor(private recipeService: RecipeService){}
onRecipeSubmitted(recipe : Recipe){
this.recipeService.addRecipe(recipe);
}
toggleForm() {
this.isFormVisible = !this.isFormVisible;
}
}

@ -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();
}
}

@ -0,0 +1,118 @@
<style>
.ingredients {
font-family: Arial, sans-serif;
background-color: #bab6b6;
margin: 0;
padding: 20px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.ingredient-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: 200px;
margin: 20px;
}
.ingredient-card:hover {
transform: scale(1.05);
}
.ingredient-content {
padding: 15px;
}
.ingredient-title {
font-size: 1em;
margin: 0 0 10px;
}
.ingredient-actions {
margin-top: 10px;
}
.ingredient-actions button {
margin-right: 5px;
}
.general-form-add {
margin-top: 2%;
background-color: #bab6b6;
float: left;
width: 49%;
}
.general-form-edit {
margin-top: 2%;
background-color: #bab6b6;
float: right;
width: 49%;
}
.form-group {
margin-bottom: 10px;
margin-right: 2%;
margin-left: 2%
}
.form-group label {
display: block;
margin-bottom: 5px;
}
.form-group input, .form-group textarea {
width: 100%;
padding: 8px;
box-sizing: border-box;
}
.button-form{
margin-left: 2%;
}
</style>
<body>
<div class="ingredients">
<div class="ingredient-card" *ngFor="let ingredient of ingredients">
<div class="ingredient-content">
<h2 class="ingredient-title">{{ ingredient.name }}</h2>
<p>{{ ingredient.description }}</p>
<div class="ingredient-actions">
<button (click)="edit(ingredient)">Modifier</button>
</div>
</div>
</div>
</div>
<div class="general-form-add">
<h2>Ajouter un ingrédient</h2>
<div class="form-group">
<label for="newName">Nom:</label>
<input id="newName" [(ngModel)]="newIngredient.name" required>
</div>
<div class="form-group">
<label for="newDescription">Description:</label>
<textarea id="newDescription" [(ngModel)]="newIngredient.description" required></textarea>
</div>
<button class="button-form" (click)="addIngredient()">Ajouter</button>
</div>
<div *ngIf="editIngredient" class="general-form-edit">
<h2>Modifier l'ingrédient</h2>
<div class="form-group">
<label for="editName">Nom:</label>
<input id="editName" [(ngModel)]="editIngredient.name">
</div>
<div class="form-group">
<label for="editDescription">Description:</label>
<textarea id="editDescription" [(ngModel)]="editIngredient.description"></textarea>
</div>
<button class="button-form" (click)="updateIngredient()">Enregistrer</button>
<button class="button-form" (click)="cancelEdit()">Annuler</button>
</div>
</body>

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { IngredientsComponent } from './ingredients.component';
describe('IngredientsComponent', () => {
let component: IngredientsComponent;
let fixture: ComponentFixture<IngredientsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [IngredientsComponent]
})
.compileComponents();
fixture = TestBed.createComponent(IngredientsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -0,0 +1,62 @@
import { Component, OnInit } from '@angular/core';
import { IngredientService } from "../../service/ingredient.service";
import { Ingredient } from "../../model/ingredient.model";
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[] = [];
newIngredient: Ingredient = { id: '0', name: '', description: '' };
editIngredient: Ingredient | null = null;
constructor(private ingredientService: IngredientService) {}
ngOnInit() {
this.loadIngredients();
}
loadIngredients() {
this.ingredientService.getAll().subscribe(ingredients => {
this.ingredients = ingredients;
});
}
addIngredient() {
this.ingredientService.add(this.newIngredient).subscribe(ingredient => {
this.ingredients.push(ingredient);
this.newIngredient = { id: '0', name: '', description: '' };
});
}
edit(ingredient: Ingredient) {
this.editIngredient = { ...ingredient };
}
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;
}
}

@ -0,0 +1,85 @@
<style>
.recipe-details {
font-family: Arial, sans-serif;
background-color: #bab6b6;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.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;
}
.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>

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RecipeDetailComponent } from './recipe-detail.component';
describe('RecipeDetailComponent', () => {
let component: RecipeDetailComponent;
let fixture: ComponentFixture<RecipeDetailComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RecipeDetailComponent]
})
.compileComponents();
fixture = TestBed.createComponent(RecipeDetailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -0,0 +1,31 @@
import {Component, Input} from '@angular/core';
import {Recipe} from "../../model/recipe.model";
import {RecipeService} from "../../service/recipe.service";
import {RouterLink, RouterLinkActive, RouterOutlet} from "@angular/router";
import {NgFor} from "@angular/common";
import {QuantifiedIngredientGetter} from "../../model/quantified-ingredient-getter.model";
@Component({
selector: 'app-recipe-detail',
standalone: true,
imports: [RouterOutlet,RouterLink, RouterLinkActive,NgFor],
templateUrl: './recipe-detail.component.html',
styleUrl: './recipe-detail.component.css'
})
export class RecipeDetailComponent {
recipe : Recipe|null = null;
ingredients : QuantifiedIngredientGetter[] = [];
constructor(private recipeService : RecipeService) {
}
@Input()
set id(id: number) {
this.recipe = this.recipeService.getRecipe(id)!;
this.ingredients = this.recipe.$ingredients;
}
}

@ -1,14 +1,138 @@
<form [formGroup]="recipeForm" (ngSubmit)="onSubmit()">
<style>
body {
font-family: Arial, sans-serif;
background-color: #bab6b6;
margin: 0;
padding: 20px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.form-container {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 100%;
}
.form-container h2 {
margin-top: 0;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
}
.form-group input,
.form-group select,
.form-group button {
width: 97%;
padding: 10px;
margin-top: 5px;
border: 1px solid #ccc;
border-radius: 5px;
}
.form-group button {
background-color: black;
color: white;
border: none;
cursor: pointer;
}
.form-group button:hover {
background-color: #525259;
}
.form-group .remove-button {
background-color: red;
}
.form-group .remove-button:hover {
background-color: darkred;
}
.add-ingredient-button {
background-color: #4CAF50;
color: white;
}
.add-ingredient-button:hover {
background-color: #45a049;
}
.submit-button {
background-color: black;
color: white;
}
.submit-button:hover {
background-color: #525259;
}
.error-message {
color: red;
font-size: 0.9em;
margin-top: 5px;
}
.form-group.invalid input,
.form-group.invalid select {
border-color: red;
}
</style>
<body>
<div class="form-container">
<h2>Ajouter une Recette</h2>
<form [formGroup]="recipeForm" (ngSubmit)="onSubmit()">
<div class="form-group" [class.invalid]="recipeForm.get('id')?.invalid && recipeForm.get('id')?.touched">
<label for="id">ID: </label>
<input id="id" type="number" formControlName="id">
<input id="id" type="number" formControlName="id" required>
<div class="error-message" *ngIf="recipeForm.get('id')?.invalid && recipeForm.get('id')?.touched">
L'ID est requis.
</div>
</div>
<div class="form-group" [class.invalid]="recipeForm.get('name')?.invalid && recipeForm.get('name')?.touched">
<label for="name">Name: </label>
<input id="name" type="text" formControlName="name" required>
<div class="error-message" *ngIf="recipeForm.get('name')?.invalid && recipeForm.get('name')?.touched">
Le nom est requis.
</div>
</div>
<div class="form-group" [class.invalid]="recipeForm.get('description')?.invalid && recipeForm.get('description')?.touched">
<label for="description">Description: </label>
<input id="description" type="text" formControlName="description" required>
<div class="error-message" *ngIf="recipeForm.get('description')?.invalid && recipeForm.get('description')?.touched">
La description est requise.
</div>
</div>
<label for="image">Image: </label>
<input id="image" type="file" (change)="onFileChange($event)">
<br>
<div *ngIf="imageBase64">
<img [src]="imageBase64" alt="Selected Image" style="max-width: 200px; max-height: 200px;">
</div>
<br>
<div formArrayName="ingredients">
<div *ngFor="let ingredient of ingredients.controls; let i=index" [formGroupName]="i" class="form-group">
<label for="ingredient-quantity">Quantity:</label>
<input id="ingredient-quantity" type="number" formControlName="quantity" required>
<label for="ingredient-unit">Unit:</label>
<select id="ingredient-unit" formControlName="unit" required>
<option *ngFor="let unit of unity" [value]="unit">{{ unit }}</option>
</select>
<label for="name">name: </label>
<input id="name" type="text" formControlName="name">
<label for="ingredient-name">Ingredient:</label>
<select id="ingredient-name" formControlName="ingredient" required>
<option *ngFor="let ingredient of ingredientsList" [value]="ingredient.name">{{ ingredient.name }}</option>
</select>
<label for="description">description: </label>
<input id="description" type="text" formControlName="description">
<button type="button" class="remove-button" (click)="removeIngredient(i)">Remove</button>
</div>
</div>
<button type="button" class="add-ingredient-button" (click)="addIngredient()">Add Ingredient</button>
<p>Complete the form to enable the button.</p>
<button type="submit" [disabled]="!recipeForm.valid">Submit</button>
</form>
<button type="submit" class="submit-button">Submit</button>
</form>
</div>
</body>

@ -1,37 +1,99 @@
import {Component, EventEmitter, Output} from '@angular/core';
import {Recipe} from "../../model/recipe.model";
import {FormControl, FormGroup, ReactiveFormsModule} from "@angular/forms";
import { Component, EventEmitter, Output } from '@angular/core';
import { Recipe } from "../../model/recipe.model";
import { FormControl, FormGroup, ReactiveFormsModule, FormArray, FormBuilder, Validators } from "@angular/forms";
import { Ingredient } from '../../model/ingredient.model';
import { Unity } from '../../model/unity';
import { IngredientService } from '../../service/ingredient.service';
import {NgFor, NgIf} from "@angular/common";
@Component({
selector: 'app-recipe-form',
standalone: true,
imports: [ReactiveFormsModule],
templateUrl: './recipe-form.component.html',
styleUrl: './recipe-form.component.css'
imports: [ReactiveFormsModule, NgFor, NgIf],
templateUrl: './recipe-form.component.html'
})
export class RecipeFormComponent {
@Output() formSubmitted = new EventEmitter<Recipe>();
ingredientsList: Ingredient[] = [];
unity = Object.values(Unity);
imageBase64: string | null = null;
recipeForm = new FormGroup({
id: new FormControl('', { nonNullable: true }),
name: new FormControl('', { nonNullable: true }),
description: new FormControl('', { nonNullable: true }),
constructor(private formBuilder: FormBuilder, private ingredientService: IngredientService) { }
ngOnInit(): void {
this.ingredientService.getAll().subscribe(ingredients => {
this.ingredientsList = ingredients;
});
}
recipeForm: FormGroup = this.formBuilder.group({
id: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
name: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
description: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
ingredients: this.formBuilder.array([this.newIngredient()]),
image: new FormControl('', {nonNullable: false})
});
get ingredients(): FormArray {
return this.recipeForm.get('ingredients') as FormArray;
}
newIngredient(): FormGroup {
return this.formBuilder.group({
quantity: new FormControl(0, { nonNullable: true, validators: [Validators.required] }),
unit: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
ingredient: new FormControl('', { nonNullable: true, validators: [Validators.required] })
});
}
addIngredient() {
this.ingredients.push(this.newIngredient());
}
removeIngredient(index: number) {
if (this.ingredients.length > 1) {
this.ingredients.removeAt(index);
} else {
}
}
onFileChange(event: Event) {
const input = event.target as HTMLInputElement;
if (input.files && input.files[0]) {
const file = input.files[0];
const reader = new FileReader();
reader.onload = () => {
this.imageBase64 = reader.result as string;
this.recipeForm.patchValue({image: this.imageBase64});
};
reader.readAsDataURL(file);
}
}
onSubmit() {
if(this.recipeForm.valid){
if (this.recipeForm.valid) {
const recipe: Recipe = {
$id: parseInt(this.recipeForm.value.id!),
$name: this.recipeForm.value.name!,
$description: this.recipeForm.value.description!,
$createdAt: new Date(),
$ingredients: []
$ingredients: this.recipeForm.value.ingredients!.map((ingredient: any) => ({
quantity: ingredient.quantity,
unit: ingredient.unit,
ingredient: this.ingredientsList.find(ing => ing.name === ingredient.ingredient)
})),
$image: this.recipeForm.value.image
};
this.formSubmitted.emit(recipe);
this.recipeForm.reset()
this.ingredients.clear()
this.imageBase64 = null;
this.addIngredient()
}else{
alert("Veuillez remplir tous les champs")
}
}
}

@ -1,5 +1,4 @@
<style>
<style>
body {
font-family: Arial, sans-serif;
background-color: #bab6b6;
@ -9,13 +8,16 @@
flex-wrap: wrap;
justify-content: center;
}
.recipe-container {
display: grid;
gap: 20px;
width: 100%;
}
.recipe-card {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
margin: 10px;
overflow: hidden;
width: calc(33.33% - 20px);
transition: transform 0.2s;
}
.recipe-card:hover {
@ -50,28 +52,48 @@
.details-button:hover {
background-color: #525259;
}
@media (max-width: 768px) {
.recipe-card {
width: calc(50% - 20px);
.four-column {
grid-template-columns: repeat(4, 1fr);
}
.two-column {
grid-template-columns: repeat(2, 1fr);
}
@media (max-width: 480px) {
.recipe-card {
width: calc(100% - 20px);
margin: 10px 0;
.pagination {
display: flex;
justify-content: center;
margin-top: 20px;
}
.page-link {
padding: 10px;
margin: 0 5px;
cursor: pointer;
background-color: #ddd;
border: 1px solid #bbb;
border-radius: 5px;
}
.error-message {
color: red;
font-weight: bold;
margin-bottom: 4%;
}
</style>
<body *ngFor="let recipe of recipes">
<div class="recipe-card">
<img src="image1.jpg" alt="Recette 1" class="recipe-image" onerror="this.onerror=null;this.src='https://placehold.co/100x100/black/white?text=Not+Found';">
</style>
<body>
<div *ngIf="errorMessageDisplay" class="error-message">{{ errorMessage }}</div>
<div [ngClass]="{'four-column': !isFormVisible, 'two-column': isFormVisible}" class="recipe-container">
<div class="recipe-card" *ngFor="let recipe of paginatedRecipes">
<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';">
<div class="recipe-content">
<h2 class="recipe-title">{{recipe.$name}}</h2>
<p class="recipe-description">{{recipe.$description}}</p>é
<button class="details-button" onclick="toggleDetails(this)">Détails</button>
<p class="recipe-description">{{recipe.$description}}</p>
<button (click)="detailsRecipe(recipe.$id)" class="details-button">Détails</button>
<button (click)="addToCommand(recipe)" class="details-button" >Ajouter à ma commande</button>
</div>
</div>
</div>
<div class="pagination">
<button class="page-link" (click)="previousPage()" [disabled]="currentPage === 0">Précédent</button>
<p>{{ currentPage +1 }}</p>
<button class="page-link" (click)="nextPage()" [disabled]="currentPage === totalPages - 1">Suivant</button>
</div>
</body>

@ -1,24 +1,78 @@
import { Component, OnInit } from '@angular/core';
import {Component, Input, OnInit} from '@angular/core';
import { RecipeService } from '../../service/recipe.service';
import { Recipe } from '../../model/recipe.model';
import {NgOptimizedImage} from "@angular/common";
import {NgClass, NgIf, NgOptimizedImage} from "@angular/common";
import {NgFor} from "@angular/common";
import {Router, RouterLinkActive} from "@angular/router";
import {CommandService} from "../../service/command.service";
@Component({
selector: 'app-recipe-list',
templateUrl: './recipe-list.component.html',
imports: [
NgOptimizedImage,
NgFor
NgFor,
NgClass,
RouterLinkActive,
NgIf
],
standalone: true
})
export class RecipeListComponent implements OnInit {
recipes: Recipe[] = [];
errorMessageDisplay: boolean = false;
errorMessage: string | null = null;
constructor(private recipeService: RecipeService) {}
@Input() isFormVisible!: boolean;
currentPage: number = 0;
pageSize: number = 4;
totalPages: any = 0;
constructor(private recipeService: RecipeService,private router : Router, private commandService: CommandService) {}
ngOnInit(): void {
this.recipes = this.recipeService.getRecipes();
this.totalPages = Math.ceil(this.recipes.length / this.pageSize);
}
get paginatedRecipes(): any[] {
const startIndex = this.currentPage * this.pageSize;
return this.recipes.slice(startIndex, startIndex + this.pageSize);
}
changePage(index: number): void {
this.currentPage = index;
}
previousPage(): void {
if (this.currentPage > 0) {
this.currentPage--;
}
}
nextPage(): void {
if (this.currentPage < this.totalPages - 1) {
this.currentPage++;
}
}
detailsRecipe(id : number){
this.router.navigateByUrl('/recipe/'+id);
}
addToCommand(recipe: Recipe) {
try {
this.commandService.addRecipe(recipe);
this.errorMessageDisplay = false;
} catch (e) {
if (e instanceof DOMException && e.name === 'QuotaExceededError') {
this.errorMessageDisplay = true;
this.errorMessage = 'Local Storage saturé, impossible d\'ajouter la recette dans le local storage des commandes.';
} else {
throw e;
}
}
}
}

@ -1,9 +1,56 @@
import {Ingredient} from "../model/ingredient.model";
export var $INGREDIENTS : Ingredient[] = [
{$id:1,$name:'Patate'},
{$id:2,$name:'Gruyere'},
{$id:3,$name:'Quenelle'},
{$id:4,$name:'Faux-filet de Boeuf'},
{$id:5,$name:'Concassé de tomates'}
{ $id: 1, $name: 'Patate' },
{ $id: 2, $name: 'Gruyere' },
{ $id: 3, $name: 'Quenelle' },
{ $id: 4, $name: 'Faux-filet de Boeuf' },
{ $id: 5, $name: 'Concassé de tomates' },
{ $id: 6, $name: 'Carotte' },
// { $id: 7, $name: 'Oignon' },
// { $id: 8, $name: 'Ail' },
// { $id: 9, $name: 'Poivron' },
// { $id: 10, $name: 'Courgette' },
// { $id: 11, $name: 'Champignon' },
// { $id: 12, $name: 'Céleri' },
// { $id: 13, $name: 'Épinard' },
// { $id: 14, $name: 'Tomate' },
// { $id: 15, $name: 'Poulet' },
// { $id: 16, $name: 'Poisson' },
// { $id: 17, $name: 'Crevette' },
// { $id: 18, $name: 'Pâtes' },
// { $id: 19, $name: 'Riz' },
// { $id: 20, $name: 'Lait' },
// { $id: 21, $name: 'Crème' },
// { $id: 22, $name: 'Fromage' },
// { $id: 23, $name: 'Beurre' },
// { $id: 24, $name: 'Huile dolive' },
// { $id: 25, $name: 'Sel' },
// { $id: 26, $name: 'Poivre' },
// { $id: 27, $name: 'Paprika' },
// { $id: 28, $name: 'Cumin' },
// { $id: 29, $name: 'Curcuma' },
// { $id: 30, $name: 'Thym' },
// { $id: 31, $name: 'Laurier' },
// { $id: 32, $name: 'Persil' },
// { $id: 33, $name: 'Basilic' },
// { $id: 34, $name: 'Coriandre' },
// { $id: 35, $name: 'Gingembre' },
// { $id: 36, $name: 'Citron' },
// { $id: 37, $name: 'Pomme de terre' },
// { $id: 38, $name: 'Betterave' },
// { $id: 39, $name: 'Radis' },
// { $id: 40, $name: 'Chou-fleur' },
// { $id: 41, $name: 'Brocoli' },
// { $id: 42, $name: 'Haricot vert' },
// { $id: 43, $name: 'Pois' },
// { $id: 44, $name: 'Lentille' },
// { $id: 45, $name: 'Noix' },
// { $id: 46, $name: 'Amandes' },
// { $id: 47, $name: 'Noisettes' },
// { $id: 48, $name: 'Chocolat' },
// { $id: 49, $name: 'Vanille' },
// { $id: 50, $name: 'Sucre' }
]

@ -1,6 +1,8 @@
import {Link} from "../model/link.model";
export var LINKS :Link[] = [
{$name:"Lien1",$link:"Lien1"},
{$name:"Lien2",$link:'Lien2'}
]
{$name:"Accueil",$link:""},
{$name:"Ingredients",$link:"/ingredients"},
{$name:"Commande",$link:"/command"}
]

@ -0,0 +1,15 @@
import {CanActivateFn, Router} from '@angular/router';
import {LoginService} from "./service/login.service";
import {inject} from "@angular/core";
export const AuthGuard: CanActivateFn = (route, state) => {
const auth = inject(LoginService)
const router = inject(Router);
if(!auth.isLogged()){
router.navigateByUrl('/');
return false;
}
return true;
};

@ -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,8 +1,8 @@
import {Unity} from "./unity";
import {Ingredient} from "./ingredient.model";
import { Unity } from "./unity";
import { Ingredient } from "./ingredient.model";
export interface QuantifiedIngredient {
$quantity : number,
$unit : Unity,
$ingredient : Ingredient
$quantity: number;
$unit: Unity;
$ingredient: Ingredient;
}

@ -1,9 +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,16 +1,26 @@
import { Injectable } from '@angular/core';
import {Ingredient} from "../model/ingredient.model";
import {$INGREDIENTS} from "../data/ingredient.stub";
import { Ingredient } from "../model/ingredient.model";
import { Observable } from "rxjs";
import { HttpClient } from "@angular/common/http";
@Injectable({
providedIn: 'root'
})
export class IngredientService {
constructor() { }
private apiUrl = 'https://664ba07f35bbda10987d9f99.mockapi.io/api/ingredients';
constructor(private http: HttpClient) { }
getAll(): Observable<Ingredient[]> {
return this.http.get<Ingredient[]>(this.apiUrl);
}
add(ingredient: Ingredient): Observable<Ingredient> {
return this.http.post<Ingredient>(this.apiUrl, ingredient);
}
getAll() : Ingredient[] {
return $INGREDIENTS;
update(ingredient: Ingredient): Observable<Ingredient> {
return this.http.put<Ingredient>(`${this.apiUrl}/${ingredient.id}`, ingredient);
}
}

@ -0,0 +1,20 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class LoginService {
login(): void {
localStorage.setItem('login', 'true');
}
logout(): void {
localStorage.setItem('login', 'false');
}
isLogged(): boolean {
const login = localStorage.getItem('login');
return login === 'true';
}
}

@ -15,4 +15,7 @@ export class RecipeService {
this.recipes.push(recipe);
localStorage.setItem('recipes', JSON.stringify(this.recipes));
}
getRecipe($id:number):Recipe{
return this.recipes.find(x => x.$id == $id)!
}
}

@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { AppComponent } from '../../app/app.component';
describe('AppComponent', () => {
beforeEach(async () => {

@ -0,0 +1,17 @@
import { TestBed } from '@angular/core/testing';
import { CanActivateFn } from '@angular/router';
import { AuthGuard } from '../../app/guard.guard';
describe('guardGuard', () => {
const executeGuard: CanActivateFn = (...guardParameters) =>
TestBed.runInInjectionContext(() => AuthGuard(...guardParameters));
beforeEach(() => {
TestBed.configureTestingModule({});
});
it('should be created', () => {
expect(executeGuard).toBeTruthy();
});
});

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { LoginService } from '../../app/service/login.service';
describe('LoginService', () => {
let service: LoginService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(LoginService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
Loading…
Cancel
Save