Merge pull request 'formRecipe' (#2) from formRecipe into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #2
pull/3/head
Corentin RICHARD 10 months ago
commit 23edc7adda

@ -1,69 +1,32 @@
<?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="c5a06892-a370-4c6a-a9cf-5d61f93a285b" name="Changes" comment="Adding Front">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/daidokoro/.vscode/extensions.json" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/daidokoro/.vscode/launch.json" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/daidokoro/.vscode/tasks.json" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/daidokoro/public/favicon.ico" beforeDir="false" afterPath="$PROJECT_DIR$/daidokoro/public/favicon.ico" afterDir="false" />
</list>
<list default="true" id="e26b532a-2e1d-44b6-8438-5d55a88b6611" name="Changes" comment="" />
<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="front" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 7
}</component>
<component name="ProjectId" id="2hxUMd4IvFZ2RBuUoixQsBySsiP" />
<component name="ProjectLevelVcsManager">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 2
}]]></component>
<component name="ProjectId" id="2i0RBJa4QzAvGYd8vYvrfEV0WHe" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<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 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>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/daidokoro/public" />
<recent name="$PROJECT_DIR$/daidokoro/src/app" />
</key>
</component>
}]]></component>
<component name="SharedIndexes">
<attachedChunks>
<set>
@ -74,47 +37,13 @@
<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="c5a06892-a370-4c6a-a9cf-5d61f93a285b" name="Changes" comment="" />
<created>1718535175328</created>
<changelist id="e26b532a-2e1d-44b6-8438-5d55a88b6611" name="Changes" comment="" />
<created>1718625373590</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<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" />
<updated>1718625373590</updated>
<workItem from="1718625376418" duration="43000" />
</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>
<option name="localTasksCounter" value="2" />
<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" />
<option name="LAST_COMMIT_MESSAGE" value="Adding Front" />
</component>
</project>

@ -1,14 +0,0 @@
import { Component } from '@angular/core';
import {RecipeListComponent} from "../recipe-list/recipe-list.component";
@Component({
selector: 'app-accueil',
standalone: true,
imports: [
RecipeListComponent
],
templateUrl: './accueil.component.html'
})
export class AccueilComponent {
}

@ -1,123 +0,0 @@
<style>
body {
font-family: Arial, sans-serif;
background-color: #bab6b6;
margin: 0;
padding: 20px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.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 {
transform: scale(1.05);
}
.recipe-image {
width: 100%;
height: 200px;
object-fit: cover;
}
.recipe-content {
padding: 15px;
}
.recipe-title {
font-size: 1.5em;
margin: 0 0 10px;
}
.recipe-description {
font-size: 1em;
color: #666;
}
.details-button {
display: inline-block;
padding: 10px 15px;
background-color: black;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
}
.details-button:hover {
background-color: #525259;
}
@media (max-width: 768px) {
.recipe-card {
width: calc(50% - 20px);
}
}
@media (max-width: 480px) {
.recipe-card {
width: calc(100% - 20px);
margin: 10px 0;
}
}
</style>
<body>
<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';">
<div class="recipe-content">
<h2 class="recipe-title">Recette 1</h2>
<p class="recipe-description">Description courte de la recette 1.</p>
<button class="details-button" onclick="toggleDetails(this)">Détails</button>
</div>
</div>
<div class="recipe-card">
<img src="image2.jpg" alt="Recette 2" 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">Recette 2</h2>
<p class="recipe-description">Description courte de la recette 2.</p>
<button class="details-button" onclick="toggleDetails(this)">Détails</button>
</div>
</div>
<div class="recipe-card">
<img src="image3.jpg" alt="Recette 3" 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">Recette 3</h2>
<p class="recipe-description">Description courte de la recette 3.</p>
<button class="details-button" onclick="toggleDetails(this)">Détails</button>
</div>
</div>
<div class="recipe-card">
<img src="image4.jpg" alt="Recette 4" 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">Recette 4</h2>
<p class="recipe-description">Description courte de la recette 4.</p>
<button class="details-button" onclick="toggleDetails(this)">Détails</button>
</div>
</div>
<div class="recipe-card">
<img src="image5.jpg" alt="Recette 5" 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">Recette 5</h2>
<p class="recipe-description">Description courte de la recette 5.</p>
<button class="details-button" onclick="toggleDetails(this)">Détails</button>
</div>
</div>
<div class="recipe-card">
<img src="image6.jpg" alt="Recette 6" 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">Recette 6</h2>
<p class="recipe-description">Description courte de la recette 6.</p>
<button class="details-button" onclick="toggleDetails(this)">Détails</button>
</div>
</div>
</body>

@ -1,6 +0,0 @@
export interface Recipe {
name: string;
date: string;
image: string;
ingredients: { name: string; quantity: string }[];
}

@ -1,18 +0,0 @@
import { Injectable } from '@angular/core';
import { Recipe } from '../Model/recipe.model';
@Injectable({
providedIn: 'root'
})
export class RecipeService {
private recipes: Recipe[] = JSON.parse(localStorage.getItem('recipes') || '[]');
getRecipes(): Recipe[] {
return this.recipes;
}
addRecipe(recipe: Recipe): void {
this.recipes.push(recipe);
localStorage.setItem('recipes', JSON.stringify(this.recipes));
}
}

@ -1 +1,2 @@
<app-accueil></app-accueil>
<!-- <app-recipe-form></app-recipe-form> -->

@ -1,11 +1,12 @@
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import {AccueilComponent} from "./Component/accueil/accueil.component";
import {RecipeFormComponent} from "./component/recipe-form/recipe-form.component";
import {AccueilComponent} from "./component/accueil/accueil.component";
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, AccueilComponent],
imports: [RouterOutlet, AccueilComponent,RecipeFormComponent],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})

@ -28,13 +28,14 @@
}
.content {
padding: 20px;
display: flex;
gap: 20px;
}
.recipe-container {
background-color: #bab6b6;
color: black;
padding: 20px;
margin-top: 0;
margin-right: 50%;
}
.recipe-container h2 {
font-size: 3em;
@ -56,6 +57,9 @@
<h2>Liste Recettes</h2>
<app-recipe-list></app-recipe-list>
</div>
<div>
<app-recipe-form (formSubmitted)="onRecipeSubmitted($event)"></app-recipe-form>
</div>
</div>
</body>

@ -0,0 +1,22 @@
import { Component } from '@angular/core';
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";
@Component({
selector: 'app-accueil',
standalone: true,
imports: [
RecipeListComponent,
RecipeFormComponent
],
templateUrl: './accueil.component.html'
})
export class AccueilComponent {
constructor(private recipeService: RecipeService){}
onRecipeSubmitted(recipe : Recipe){
this.recipeService.addRecipe(recipe);
}
}

@ -0,0 +1,14 @@
<form [formGroup]="recipeForm" (ngSubmit)="onSubmit()">
<label for="id">ID: </label>
<input id="id" type="number" formControlName="id">
<label for="name">name: </label>
<input id="name" type="text" formControlName="name">
<label for="description">description: </label>
<input id="description" type="text" formControlName="description">
<p>Complete the form to enable the button.</p>
<button type="submit" [disabled]="!recipeForm.valid">Submit</button>
</form>

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

@ -0,0 +1,37 @@
import {Component, EventEmitter, Output} from '@angular/core';
import {Recipe} from "../../model/recipe.model";
import {FormControl, FormGroup, ReactiveFormsModule} from "@angular/forms";
@Component({
selector: 'app-recipe-form',
standalone: true,
imports: [ReactiveFormsModule],
templateUrl: './recipe-form.component.html',
styleUrl: './recipe-form.component.css'
})
export class RecipeFormComponent {
@Output() formSubmitted = new EventEmitter<Recipe>();
recipeForm = new FormGroup({
id: new FormControl('', { nonNullable: true }),
name: new FormControl('', { nonNullable: true }),
description: new FormControl('', { nonNullable: true }),
});
onSubmit() {
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: []
};
this.formSubmitted.emit(recipe);
this.recipeForm.reset()
}
}
}

@ -0,0 +1,77 @@
<style>
body {
font-family: Arial, sans-serif;
background-color: #bab6b6;
margin: 0;
padding: 20px;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.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 {
transform: scale(1.05);
}
.recipe-image {
width: 100%;
height: 200px;
object-fit: cover;
}
.recipe-content {
padding: 15px;
}
.recipe-title {
font-size: 1.5em;
margin: 0 0 10px;
}
.recipe-description {
font-size: 1em;
color: #666;
}
.details-button {
display: inline-block;
padding: 10px 15px;
background-color: black;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
}
.details-button:hover {
background-color: #525259;
}
@media (max-width: 768px) {
.recipe-card {
width: calc(50% - 20px);
}
}
@media (max-width: 480px) {
.recipe-card {
width: calc(100% - 20px);
margin: 10px 0;
}
}
</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';">
<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>
</div>
</div>
</body>

@ -1,13 +1,15 @@
import { Component, OnInit } from '@angular/core';
import { RecipeService } from '../../Service/recipe.service';
import { Recipe } from '../../Model/recipe.model';
import { RecipeService } from '../../service/recipe.service';
import { Recipe } from '../../model/recipe.model';
import {NgOptimizedImage} from "@angular/common";
import {NgFor} from "@angular/common";
@Component({
selector: 'app-recipe-list',
templateUrl: './recipe-list.component.html',
imports: [
NgOptimizedImage
NgOptimizedImage,
NgFor
],
standalone: true
})

@ -1,8 +1,8 @@
import {Unite} from "./unity";
import {Unity} from "./unity";
import {Ingredient} from "./ingredient.model";
export interface QuantifiedIngredient {
$quantity : number,
$unit : Unite,
$unit : Unity,
$ingredient : Ingredient
}

@ -1,15 +1,18 @@
import { Injectable } from '@angular/core';
import {Recipe} from "../model/recipe.model";
import {$RECEPIES} from "../data/recipe.stub";
import { Recipe } from '../model/recipe.model';
@Injectable({
providedIn: 'root'
})
export class RecipeService {
private recipes: Recipe[] = JSON.parse(localStorage.getItem('recipes') || '[]');
constructor() { }
getRecipes(): Recipe[] {
return this.recipes;
}
getAll() : Recipe[]{
return $RECEPIES;
addRecipe(recipe: Recipe): void {
this.recipes.push(recipe);
localStorage.setItem('recipes', JSON.stringify(this.recipes));
}
}

Loading…
Cancel
Save