Use proper source, only update menus when changing week/today not whole restaurant

This commit is contained in:
zvon 2020-09-15 22:57:03 +02:00
parent bf315a174e
commit 1186bc8508
3 changed files with 21 additions and 9 deletions

View File

@ -1,6 +1,6 @@
<h1>Restaurants</h1>
<div class="controls">
<button type="button" class="btn btn-info" (click)="getAllDays()" style="margin-right: 10px;">Show whole week</button>
<button type="button" class="btn btn-info" (click)="getTodayOnly()">Only show today</button>
<button type="button" class="btn btn-info" (click)="getAllDaysUpdate()" style="margin-right: 10px;">Show whole week</button>
<button type="button" class="btn btn-info" (click)="getTodayOnlyUpdate()">Only show today</button>
</div>
<app-restaurant *ngFor="let restaurant of restaurants; let i = index" [restaurant]="restaurant" [index]="i"></app-restaurant>

View File

@ -19,12 +19,6 @@ export class RestaurantsComponent implements OnInit {
this.getTodayOnly();
}
getAllDays(): void {
this.lunchService.getRestaurants().subscribe( restaurants => {
this.restaurants = restaurants;
});
}
getTodayOnly(): void {
const d = new Date();
const dayName = this.days[d.getDay()];
@ -33,4 +27,22 @@ export class RestaurantsComponent implements OnInit {
});
}
getTodayOnlyUpdate(): void {
const d = new Date();
const dayName = this.days[d.getDay()];
this.lunchService.getRestaurantsForDay(dayName).subscribe( restaurants => {
for (let i = 0; i < restaurants.length; i++) {
this.restaurants[i].menus = restaurants[i].menus;
}
});
}
getAllDaysUpdate(): void {
this.lunchService.getRestaurants().subscribe( restaurants => {
for (let i = 0; i < restaurants.length; i++) {
this.restaurants[i].menus = restaurants[i].menus;
}
});
}
}

View File

@ -20,7 +20,7 @@ export class LunchService {
private restaurantAdapter: RestaurantAdapter,
private menuAdapter: MenuAdapter,
private mealAdapter: MealAdapter) {
this.serviceUri = 'http://localhost:1984/';
this.serviceUri = 'https://lunch.zvon.tech:1985/';
this.getUri = 'get';
this.getRestaurantParam = 'restaurant';
this.getDayParam = 'day';