From 45fb44712ecba57a8c20c4c46cd4281d9d92b962 Mon Sep 17 00:00:00 2001 From: Jan Szumotalski Date: Tue, 20 May 2025 22:02:51 +0200 Subject: [PATCH] fix: Made menu empty if no items. Not too elegant of a solution, but works. Going to do the same in print display of backend. Probably not gonna be elegant aswell. --- .../admin-view/menu-new/menu-new.component.ts | 4 ++-- src/app/app-view/menu/menu.component.html | 6 +++--- src/app/app-view/menu/menu.component.ts | 21 +++++++++++++++++-- src/app/types/menu.ts | 4 ++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/app/admin-view/menu-new/menu-new.component.ts b/src/app/admin-view/menu-new/menu-new.component.ts index 41361c0..41a2e49 100644 --- a/src/app/admin-view/menu-new/menu-new.component.ts +++ b/src/app/admin-view/menu-new/menu-new.component.ts @@ -101,11 +101,11 @@ export class MenuNewComponent { } editSn(id: string) { - this.ac.menu.editSn(id, this.dataSource.data.find(v => v._id == id)?.sn).subscribe(s => this.refreshIfGood(s)) + this.ac.menu.editSn(id, this.dataSource.data.find(v => v._id == id)!.sn).subscribe(s => this.refreshIfGood(s)) } editOb(id: string) { - this.ac.menu.editOb(id, this.dataSource.data.find(v => v._id == id)?.ob).subscribe(s => this.refreshIfGood(s)) + this.ac.menu.editOb(id, this.dataSource.data.find(v => v._id == id)!.ob).subscribe(s => this.refreshIfGood(s)) } editKol(id: string) { diff --git a/src/app/app-view/menu/menu.component.html b/src/app/app-view/menu/menu.component.html index 269bcda..8810f42 100644 --- a/src/app/app-view/menu/menu.component.html +++ b/src/app/app-view/menu/menu.component.html @@ -13,8 +13,8 @@ @@ -51,7 +51,7 @@ - + Brak danych, wybierz inny dzieƄ. diff --git a/src/app/app-view/menu/menu.component.ts b/src/app/app-view/menu/menu.component.ts index d7fa30c..ca0eb09 100644 --- a/src/app/app-view/menu/menu.component.ts +++ b/src/app/app-view/menu/menu.component.ts @@ -32,17 +32,34 @@ export class MenuComponent { } menu?: Menu; - get getsn() {return (this.menu && this.menu.sn) ? this.menu.sn : null} - get getob() {return (this.menu && this.menu.ob) ? this.menu.ob : null} + get getsn() {return (this.menu && this.checkIfAnyProperty(this.menu.sn)) ? this.menu.sn : null} + get getob() {return (this.menu && this.checkIfAnyProperty(this.menu.ob)) ? this.menu.ob : null} get getkol() {return (this.menu && this.menu.kol) ? this.menu.kol : null} get gettitle() {return (this.menu && this.menu.dayTitle && this.menu.dayTitle != "") ? this.menu.dayTitle : null} + private checkIfAnyProperty(obj: { [x: string]: string | string[];}) { + for (let i in obj) { + if (Array.isArray(obj[i])) { + if (obj[i].length > 0) return true + } else { + if (!!obj[i]) return true + } + } + return false + } + + capitalize(str: string) { + return str.charAt(0).toUpperCase()+str.substring(1) + } + updateMenu(silent?: boolean) { this.loading = !silent if (!silent) this.menu = undefined this.uc.getMenu(this.day).subscribe(m => { this.loading = false this.menu = m + console.log(m); + }) } diff --git a/src/app/types/menu.ts b/src/app/types/menu.ts index 4b79dd3..9cc5c00 100644 --- a/src/app/types/menu.ts +++ b/src/app/types/menu.ts @@ -3,11 +3,11 @@ import { Moment } from "moment"; export interface Menu { _id: string; day: Moment; - sn?: { + sn: { fancy: string[]; second: string; }; - ob?: { + ob: { soup: string; vege: string; meal: string;