minor changes

This commit is contained in:
Constantin Simonis 2024-12-03 09:56:02 +01:00
parent f0c62cc586
commit 71612b1a9c
Signed by: csimonis
GPG Key ID: 758DD9C506603183
18 changed files with 26 additions and 123 deletions

View File

@ -1,13 +1,13 @@
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {HotelsComponent} from "./hotel/hotels.component";
import {IdkComponent} from "./idek/idk.component";
import {filter, from, map, reduce} from "rxjs"; import {filter, from, map, reduce} from "rxjs";
import {RouterOutlet} from "@angular/router"; import {RouterOutlet} from "@angular/router";
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
standalone: true, standalone: true,
imports: [HotelsComponent, IdkComponent, RouterOutlet], imports: [
RouterOutlet
],
template: ` template: `
<router-outlet /> <router-outlet />
` `

View File

@ -7,7 +7,7 @@ import localeCn from "@angular/common/locales/en"
import localeJap from "@angular/common/locales/en" import localeJap from "@angular/common/locales/en"
import {provideHttpClient} from "@angular/common/http"; import {provideHttpClient} from "@angular/common/http";
import {InMemoryWebApiModule} from "angular-in-memory-web-api"; import {InMemoryWebApiModule} from "angular-in-memory-web-api";
import {HotelDataService} from "./service/HotelData.service"; import {HotelDataService} from "./hotel/service/HotelData.service";
registerLocaleData(localeDe, 'de-DE') registerLocaleData(localeDe, 'de-DE')
registerLocaleData(localeCn, 'cn-CN') registerLocaleData(localeCn, 'cn-CN')

View File

@ -1,7 +1,7 @@
import {Routes} from '@angular/router'; import {Routes} from '@angular/router';
import {HotelsComponent} from "./hotel/hotels.component"; import {HotelsComponent} from "./hotel/component/hotels.component";
import {HotelComponent} from "./hotel/hotel.component"; import {HotelComponent} from "./hotel/component/hotel.component";
import {CreateHotelComponent} from "./hotel/create-hotel.component"; import {CreateHotelComponent} from "./hotel/component/create-hotel.component";
export const routes: Routes = [ export const routes: Routes = [
{ {

View File

@ -1,6 +1,6 @@
import {Component, EventEmitter, Output} from "@angular/core"; import {Component, EventEmitter, Output} from "@angular/core";
import {FormsModule, ReactiveFormsModule} from "@angular/forms"; import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {Lang} from "../idek/lang"; import {Lang} from "./lang";
@Component({ @Component({

View File

@ -1,5 +1,5 @@
import {Component, inject} from "@angular/core"; import {Component, inject} from "@angular/core";
import {Hotel} from "./hotel"; import {Hotel} from "../model/hotel";
import {HotelService} from "../service/hotel.service"; import {HotelService} from "../service/hotel.service";
import {EditHotelComponent} from "./edit-hotel.component"; import {EditHotelComponent} from "./edit-hotel.component";
import {Router} from "@angular/router"; import {Router} from "@angular/router";

View File

@ -8,10 +8,9 @@ import {
ReactiveFormsModule, ReactiveFormsModule,
Validators Validators
} from "@angular/forms"; } from "@angular/forms";
import {Hotel} from "./hotel"; import {Hotel} from "../model/hotel";
import {RouterLink} from "@angular/router"; import {RouterLink} from "@angular/router";
import {NgForOf} from "@angular/common"; import {NgForOf} from "@angular/common";
import {TagComponent} from "./tag.component";
@Component({ @Component({
selector: 'app-edit-hotel', selector: 'app-edit-hotel',
@ -21,7 +20,6 @@ import {TagComponent} from "./tag.component";
ReactiveFormsModule, ReactiveFormsModule,
RouterLink, RouterLink,
NgForOf, NgForOf,
TagComponent
], ],
template: ` template: `
<ng-form [formGroup]="form" (ngSubmit)="submit()"> <ng-form [formGroup]="form" (ngSubmit)="submit()">
@ -73,7 +71,6 @@ export class EditHotelComponent implements OnInit {
tags.push(new FormControl(tag, [Validators.required])); tags.push(new FormControl(tag, [Validators.required]));
} }
console.log(tags)
this.form = new FormGroup({ this.form = new FormGroup({
name: new FormControl(this.hotel?.hotelName, [Validators.required]), name: new FormControl(this.hotel?.hotelName, [Validators.required]),
description: new FormControl(this.hotel?.description, [Validators.required]), description: new FormControl(this.hotel?.description, [Validators.required]),
@ -85,8 +82,11 @@ export class EditHotelComponent implements OnInit {
submit() { submit() {
if (!this.form.valid) { if (!this.form.valid) {
console.error('Form invalid'); console.error('Form invalid: ');
for (const key in this.form.controls) {
console.error(key, this.form.controls[key].errors);
}
return;
} }
const hotel: Hotel = { const hotel: Hotel = {
@ -98,7 +98,7 @@ export class EditHotelComponent implements OnInit {
id: this.hotel?.id ?? 0, id: this.hotel?.id ?? 0,
tags: this.form.value.tags ?? [] tags: this.form.value.tags ?? []
}; };
console.log(hotel)
this.updateHotel.emit(hotel) this.updateHotel.emit(hotel)
this.hotel = hotel; this.hotel = hotel;

View File

@ -1,8 +1,8 @@
import {Component, inject, OnInit} from "@angular/core"; import {Component, inject, OnInit} from "@angular/core";
import {Hotel} from "./hotel" import {Hotel} from "../model/hotel"
import {CurrencyPipe, NgOptimizedImage} from "@angular/common"; import {CurrencyPipe, NgOptimizedImage} from "@angular/common";
import {Lang} from "../idek/lang"; import {Lang} from "../../currency/lang";
import {StarComponent} from "../star/star.component"; import {StarComponent} from "./star.component";
import {ActivatedRoute} from "@angular/router"; import {ActivatedRoute} from "@angular/router";
import {HotelService} from "../service/hotel.service"; import {HotelService} from "../service/hotel.service";
import {catchError, EMPTY} from "rxjs"; import {catchError, EMPTY} from "rxjs";

View File

@ -1,14 +1,14 @@
import {Component, inject} from "@angular/core"; import {Component, inject} from "@angular/core";
import {HotelComponent} from "./hotel.component"; import {HotelComponent} from "./hotel.component";
import {Hotel} from "./hotel"; import {Hotel} from "../model/hotel";
import {FormsModule} from "@angular/forms"; import {FormsModule} from "@angular/forms";
import {Lang} from "../idek/lang"; import {Lang} from "../../currency/lang";
import {HotelService} from "../service/hotel.service"; import {HotelService} from "../service/hotel.service";
import {filter, Observable, toArray} from "rxjs"; import {filter, Observable, toArray} from "rxjs";
import {AsyncPipe} from "@angular/common"; import {AsyncPipe} from "@angular/common";
import {CurrencyComponent} from "../currency/currency.component"; import {CurrencyComponent} from "../../currency/currency.component";
import {RouterLink} from "@angular/router"; import {RouterLink} from "@angular/router";
import {StarComponent} from "../star/star.component"; import {StarComponent} from "./star.component";
@Component({ @Component({
standalone: true, standalone: true,

View File

@ -1,5 +1,5 @@
import {InMemoryDbService} from "angular-in-memory-web-api"; import {InMemoryDbService} from "angular-in-memory-web-api";
import {Hotel} from "../hotel/hotel"; import {Hotel} from "../model/hotel";
export class HotelDataService implements InMemoryDbService{ export class HotelDataService implements InMemoryDbService{

View File

@ -1,7 +1,7 @@
import {HttpClient} from "@angular/common/http"; import {HttpClient} from "@angular/common/http";
import {inject, Injectable} from "@angular/core"; import {inject, Injectable} from "@angular/core";
import {Observable} from "rxjs"; import {Observable} from "rxjs";
import {Hotel} from "../hotel/hotel"; import {Hotel} from "../model/hotel";
@Injectable({ @Injectable({
providedIn: "root", providedIn: "root",

View File

@ -1,33 +0,0 @@
import {Component, EventEmitter, Input, Output} from "@angular/core";
import {AbstractControl, ControlContainer, FormGroupDirective, ReactiveFormsModule} from "@angular/forms";
import {JsonPipe} from "@angular/common";
@Component({
standalone: true,
selector: 'app-tag',
imports: [
ReactiveFormsModule,
JsonPipe
],
viewProviders: [
{
provide: ControlContainer,
useExisting: FormGroupDirective
}
],
template: `
`
})
export class TagComponent {
@Input()
tagElement!: AbstractControl;
@Output()
deleteEvent: EventEmitter<AbstractControl> = new EventEmitter();
delete() {
this.deleteEvent.emit(this.tagElement);
}
}

View File

@ -1,53 +0,0 @@
import {Component} from "@angular/core";
import {CurrencyPipe} from "@angular/common";
import {FormsModule} from "@angular/forms";
import {Lang} from "./lang";
@Component({
selector: 'app-idk',
standalone: true,
imports: [CurrencyPipe, FormsModule],
template: `
<select [ngModel]="currency" (ngModelChange)="setCurrency($event)">
@for (currency of currencies; track null) {
<option value="{{currency.name}}">{{currency.name}}</option>
}
</select>
{{ 234 | currency : currency.currency : 'symbol' : '2.2-2' : currency.code }}
`
})
export class IdkComponent {
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 setCurrency(currencyInput: string): void {
for (const currency of this.currencies) {
if (currency.name === currencyInput) {
this.currency = currency;
break;
}
}
}
}

View File

@ -1,11 +0,0 @@
import {Pipe, PipeTransform} from "@angular/core";
@Pipe({
name: 'idk',
standalone: true,
})
export class TestPipe implements PipeTransform {
transform(value: string): string {
return value.toLowerCase().replaceAll('l', 'p');
}
}

View File

@ -1,6 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { StarComponent } from './star.component'; import { StarComponent } from '../hotel/component/star.component';
describe('StarComponent', () => { describe('StarComponent', () => {
let component: StarComponent; let component: StarComponent;