This commit is contained in:
csimonis 2024-09-17 10:18:51 +02:00
parent 763d01d561
commit 27feb24461
11 changed files with 186 additions and 7 deletions

View file

@ -2,15 +2,21 @@ import {Component} from "@angular/core";
import {HotelComponent} from "./hotel.component";
import {Hotel} from "./hotel";
import {FormsModule} from "@angular/forms";
import {Lang} from "../idek/lang";
@Component({
standalone: true,
template: `
<select [ngModel]="currency" (ngModelChange)="setCurrency($event)">
@for (currency of currencies; track null) {
<option value="{{currency.name}}">{{currency.name}}</option>
}
</select>
<form>
<input name="search" [ngModel]="search" (ngModelChange)="searchEvent($event)">
</form>
@for (hotel of matchingHotels; track hotel.hotelId) {
<app-hotel [hotel]="hotel"></app-hotel>
<app-hotel [hotel]="hotel" [currency]="currency"></app-hotel>
<hr>
} @empty {
<h1>no matching results for {{search}}</h1>
@ -22,12 +28,46 @@ import {FormsModule} from "@angular/forms";
export class HotelsComponent {
public search: string = '';
public currency: Lang = {name: 'de', code: 'de-DE', currency: 'EUR'};
public currencies: Lang[] = [
{
name: 'de',
code: 'de-DE',
currency: 'EUR'
},
{
name: 'en',
code: 'en-US',
currency: 'USD'
},
{
name: 'jap',
code: 'ja-JP',
currency: 'JPY'
},
{
name: 'cn',
code: 'cn-CN',
currency: 'CNY'
}
]
public matchingHotels: Hotel[] = [];
constructor() {
this.matchingHotels = this.hotels;
}
public setCurrency(currencyInput: string): void {
for (const currency of this.currencies) {
if (currency.name === currencyInput) {
this.currency = currency;
break;
}
}
}
public searchEvent(input: string) {
this.search = input.toLowerCase();
this.matchingHotels = []