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.
This commit is contained in:
2025-05-20 22:02:51 +02:00
parent 92768ceda6
commit 45fb44712e
4 changed files with 26 additions and 9 deletions

View File

@@ -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) {

View File

@@ -13,8 +13,8 @@
<mat-card-content>
<ul>
<li *ngFor="let i of ls.defaultItems.sn">{{i}}</li>
<li *ngFor="let i of getsn.fancy">{{i.charAt(0).toUpperCase()+i.substring(1)}}</li>
<li *ngIf="getsn.second">{{getsn.second.charAt(0).toUpperCase()+getsn.second.substring(1)}}</li>
<li *ngFor="let i of getsn.fancy">{{capitalize(i)}}</li>
<li *ngIf="getsn.second">{{capitalize(getsn.second)}}</li>
</ul>
</mat-card-content>
</mat-card>
@@ -51,7 +51,7 @@
<button mat-icon-button (click)="vote('kol', '-')"><mat-icon [color]="menu!.kolv == '-' ? 'warn' : null">thumb_down</mat-icon></button>
</mat-card-actions>
</mat-card>
<mat-card *ngIf="!(getkol || getob || getsn || loading)">
<mat-card *ngIf="!(getkol || getob || getsn || loading || gettitle)">
<mat-card-content id="no-data">
Brak danych, wybierz inny dzień.
</mat-card-content>

View File

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

View File

@@ -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;