From c759185df0536b4ba270618dbc4d1163e53f4689 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Tue, 7 Jun 2022 17:18:47 +0200 Subject: [PATCH] add: insert food after one food --- src/app/app.component.css | 11 ++++++++--- src/app/app.component.html | 12 ++++++++++-- src/app/app.component.ts | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/app/app.component.css b/src/app/app.component.css index db34983..a4f2d04 100644 --- a/src/app/app.component.css +++ b/src/app/app.component.css @@ -105,13 +105,18 @@ h2 { font-size: 1.1em; } - .foodmenu .button:nth-child(odd) { + .foodmenu .button:nth-child(4) { + grid-column: 1/2; + text-align: center; + } + + .foodmenu .button:nth-child(5) { grid-column: 2/3; text-align: center; } - .foodmenu .button:nth-child(even) { - grid-column: 1/2; + .foodmenu .button:nth-child(6) { + grid-column: 3/4; text-align: center; } } diff --git a/src/app/app.component.html b/src/app/app.component.html index 371fb96..d06f6db 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -68,12 +68,17 @@ + @@ -98,6 +103,9 @@ + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index ca02bfc..674e106 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -13,6 +13,8 @@ import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; export class AppComponent { + private insertIndicies: Array = [ -1, -1, -1 ]; + public foodcard: IFoodCard = { Titles: [] }; public title: ITitle = { Title: "", Subtitles: [] }; public subtitle: ISubtitle = { Subtitle: "", Foods: [] }; @@ -60,6 +62,16 @@ export class AppComponent return false; } + public disableByInsertMode(): boolean + { + for (let i = 0; i < this.insertIndicies.length; i++) { + if (this.insertIndicies[i] > -1) + return true; + } + + return false; + } + public exportJson(): void { let json = JSON.stringify(this.foodcard); @@ -143,6 +155,26 @@ export class AppComponent this.edit = true; } + public insertFoodAfter(): void + { + let title = this.foodcard.Titles[this.insertIndicies[0]]; + let subtitle = title.Subtitles[this.insertIndicies[1]]; + subtitle.Foods.splice(this.insertIndicies[2] + 1, 0, this.food); + this.food = { Food: "", sideDish: "", price: "" }; + this.insertIndicies = [ -1, -1, -1 ]; + this.formFoodVisible = false; + } + + public insertFood(title: ITitle, subtitle: ISubtitle, food: IFood): void + { + let titleIndex = this.foodcard.Titles.indexOf(title); + let subtitleIndex = title.Subtitles.indexOf(subtitle); + let foodIndex = subtitle.Foods.indexOf(food); + + this.insertIndicies = [ titleIndex, subtitleIndex, foodIndex ]; + this.formFoodVisible = true; + } + public removeFood(subtitle: ISubtitle, foodindex: number): void { subtitle.Foods.splice(foodindex, 1); -- 2.39.5