Compare commits

..

5 Commits

24 changed files with 4776 additions and 4018 deletions

8482
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
<button type="button">{{ text }}</button> <button type="button" class="px-6 py-2 bg-blue-500 text-white font-semibold rounded-lg shadow-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-opacity-75">{{ text }}</button>

@ -1,4 +1,4 @@
<h1>Child</h1> <h1 class="text-2xl font-bold mb-4">Child</h1>
<p>Balance: {{balance}}</p> <p class="text-lg mb-2">Balance: {{balance}}</p>
<p [class.hidden]="!isBroke">Im broke. Now im about as poor as Jan-Marlon.</p> <p [class.hidden]="!isBroke" class="text-red-500 mb-4">I'm broke. Now I'm about as poor as Jan-Marlon.</p>
<button type="button" (click)=takeMoney() class="button">Take Money</button> <button type="button" (click)="takeMoney()" class="px-6 py-2 bg-blue-500 text-white font-semibold rounded-lg shadow-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-opacity-75">Take Money</button>

@ -1,11 +1,8 @@
<p>Name: {{hotel.hotelName}}</p> <p class="text-2xl font-bold text-gray-800 mb-2">Name: {{hotel.hotelName}}</p>
<p>Description: {{hotel.description}}</p> <p class="text-base text-gray-600 mb-4">Description: {{hotel.description}}</p>
<p>Price: {{hotel.price | currency : getCurrencyCode(selectedLanguage) : "symbol" : "2.2-2" : selectedLanguage}}</p> <p class="text-lg font-medium text-green-600 mb-4">Price: {{hotel.price | currency : getCurrencyCode(selectedLanguage) : "symbol" : "2.2-2" : selectedLanguage}}</p>
<select [ngModel]="selectedLanguage" (ngModelChange)="languageChange($event)"> <select [ngModel]="selectedLanguage" (ngModelChange)="languageChange($event)" class="block w-full p-2 border border-gray-300 rounded-md mb-4 focus:border-blue-500 focus:ring focus:ring-blue-200">
@for (lang of langs; track lang.lang) { <option *ngFor="let lang of langs" [value]="lang.code" [selected]="lang.lang == 'de'">{{lang.lang}}</option>
<option value="{{lang.code}}" [selected]="lang.lang == 'de'">{{lang.lang}}</option>
}
</select> </select>
<img src="{{hotel.imageUrl}}" alt="Hotel"> <img src="{{hotel.imageUrl}}" alt="Hotel" class="w-full h-auto rounded-lg shadow-lg mb-4">
<a *ngIf="!isDetail" routerLink="/hotels/{{hotel.id}}">Details</a> <a *ngIf="!isDetail" routerLink="/hotels/{{hotel.id}}" class="text-blue-600 hover:text-blue-800 hover:underline mb-4 block">Details</a>
<app-star-rating [rating]="hotel.rating"></app-star-rating>

@ -1,7 +1,7 @@
import { Component, Injectable, Input } from "@angular/core"; import { Component, Injectable, Input } from "@angular/core";
import { ChildComponent } from "../Child/child.component"; import { ChildComponent } from "../Child/child.component";
import { Hotel } from "./hotel"; import { Hotel } from "./hotel";
import { CurrencyPipe, NgIf } from "@angular/common"; import { CurrencyPipe, NgFor, NgIf } from "@angular/common";
import { FormsModule } from "@angular/forms"; import { FormsModule } from "@angular/forms";
import { StarRatingComponent } from "../star-rating/star-rating.component"; import { StarRatingComponent } from "../star-rating/star-rating.component";
import { HttpClient } from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
@ -11,7 +11,7 @@ import { RouterLink } from "@angular/router";
selector: 'app-hotel-item', selector: 'app-hotel-item',
standalone: true, standalone: true,
templateUrl: './HotelItem.component.html', templateUrl: './HotelItem.component.html',
imports: [ChildComponent, CurrencyPipe, FormsModule, StarRatingComponent, NgIf, RouterLink], imports: [ChildComponent, CurrencyPipe, FormsModule, StarRatingComponent, NgIf, RouterLink, NgFor],
}) })
export class HotelItem { export class HotelItem {

@ -1 +1 @@
<input [(ngModel)]="input" (ngModelChange)="update($event)" class="border border-black" type="search"> <input [(ngModel)]="input" (ngModelChange)="update($event)" class="border border-gray-300 rounded-md p-2 w-full focus:border-blue-500 focus:ring focus:ring-blue-200" type="search">

@ -1,6 +1,8 @@
import { Routes } from '@angular/router'; import { Routes } from '@angular/router';
import { HotelDetailsComponent } from './hotel-details/hotel-details.component'; import { HotelDetailsComponent } from './hotel-details/hotel-details.component';
import { HotelListComponent } from './hotel-list/hotel-list.component'; import { HotelListComponent } from './hotel-list/hotel-list.component';
import { TestComponent } from './test/test.component';
import { NewHotelComponent } from './new-hotel/new-hotel.component';
export const routes: Routes = [ export const routes: Routes = [
{ {
@ -11,4 +13,12 @@ export const routes: Routes = [
path: "hotels/:id", path: "hotels/:id",
component: HotelDetailsComponent, component: HotelDetailsComponent,
}, },
{
path: "testing",
component: TestComponent,
},
{
path: "new",
component: NewHotelComponent,
}
]; ];

@ -1 +1,5 @@
<app-hotel-item [hotel]="hotel" [isDetail]="true"></app-hotel-item> @if (hotel != null) {
<app-hotel-item [hotel]="hotel" [isDetail]="true"></app-hotel-item>
<app-hotel-form [hotel]="hotel"></app-hotel-form>
<button (click)="delete()">DELETE</button>
}

@ -2,15 +2,16 @@ import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { Hotel } from '../HotelItem/hotel'; import { Hotel } from '../HotelItem/hotel';
import { CurrencyPipe } from '@angular/common'; import { CurrencyPipe, NgFor, NgForOf, NgIf } from '@angular/common';
import { StarRatingComponent } from '../star-rating/star-rating.component'; import { StarRatingComponent } from '../star-rating/star-rating.component';
import { HotelItem } from '../HotelItem/HotelItem.component'; import { HotelItem } from '../HotelItem/HotelItem.component';
import { catchError, EMPTY } from 'rxjs'; import { catchError, EMPTY } from 'rxjs';
import { HotelFormComponent } from '../hotel-form/hotel-form.component';
@Component({ @Component({
selector: 'app-hotel-details', selector: 'app-hotel-details',
standalone: true, standalone: true,
imports: [CurrencyPipe, StarRatingComponent, HotelItem], imports: [CurrencyPipe, StarRatingComponent, HotelItem, HotelFormComponent, NgIf, NgForOf],
templateUrl: './hotel-details.component.html', templateUrl: './hotel-details.component.html',
styleUrl: './hotel-details.component.css' styleUrl: './hotel-details.component.css'
}) })
@ -19,6 +20,13 @@ export class HotelDetailsComponent implements OnInit {
constructor(private route: ActivatedRoute, private http: HttpClient, private router: Router) { } constructor(private route: ActivatedRoute, private http: HttpClient, private router: Router) { }
delete(): void {
if (confirm("Are u sure u want to delete this hotel")) {
this.http.delete<Hotel>("/api/hotels/" + this.route.snapshot.paramMap.get("id")).subscribe();
this.router.navigate(["/"]);
}
}
ngOnInit(): void { ngOnInit(): void {
const routeParams = this.route.snapshot.paramMap; const routeParams = this.route.snapshot.paramMap;
const hotelId = routeParams.get("id"); const hotelId = routeParams.get("id");

@ -0,0 +1,12 @@
<p>hotel-form works!</p>
<form [formGroup]="hotelForm">
<label for="name">Name</label>
<input type="text" class="border-red-500" [class.border-8]='hotelForm.get("name")?.invalid' id="name" formControlName="name">
<label for="description">Description</label>
<input type="text" class="border-red-500" [class.border-8]='hotelForm.get("description")?.invalid' id="description" formControlName="description">
<label for="price">Price</label>
<input type="price" class="border-red-500" [class.border-8]='hotelForm.get("price")?.invalid && hotelForm.get("price")?.touched' id="price" formControlName="price">
<button (click)="submit()" [disabled]="!hotelForm.valid" type="submit">Submit</button>
<a routerLink="/">Cancel</a>
</form>

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HotelFormComponent } from './hotel-form.component';
describe('HotelFormComponent', () => {
let component: HotelFormComponent;
let fixture: ComponentFixture<HotelFormComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HotelFormComponent]
})
.compileComponents();
fixture = TestBed.createComponent(HotelFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -0,0 +1,39 @@
import { Component, Input } from '@angular/core';
import { Hotel } from '../HotelItem/hotel';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { NgFor, NgIf } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Router, RouterLink } from '@angular/router';
@Component({
selector: 'app-hotel-form',
standalone: true,
imports: [ReactiveFormsModule, NgIf, NgFor, RouterLink],
templateUrl: './hotel-form.component.html',
styleUrl: './hotel-form.component.css'
})
export class HotelFormComponent {
@Input() public hotel!: Hotel;
public hotelForm!: FormGroup
constructor(public http: HttpClient, public router: Router) {
}
ngOnInit(): void {
this.hotelForm = new FormGroup({
name: new FormControl(this.hotel.hotelName, Validators.required),
description: new FormControl(this.hotel.description, Validators.required),
price: new FormControl(this.hotel.price, Validators.required),
})
}
submit(): void {
this.hotel.hotelName = this.hotelForm.get("name")?.value;
this.hotel.description = this.hotelForm.get("description")?.value;
this.hotel.price = this.hotelForm.get("price")?.value;
console.log(this.hotelForm.value);
this.http.put("/api/hotels/" + this.hotel.id, this.hotel).subscribe();
this.router.navigate(["/"]);
}
}

@ -1,7 +1,10 @@
<h1>{{'hello' | uppercase | text}}</h1> <div class="container p-4 mx-auto max-w-4xl">
<app-search [(input)]="search"></app-search> <h1>{{'hello' | uppercase | text}}</h1>
@if (hotels[0].hotelName) { <a routerLink="/new">CREATE NEW HOTEL</a>
<div *ngFor="let hotel of hotels"> <app-search [(input)]="search"></app-search>
<app-hotel-item *ngIf="hotel.hotelName.includes(search)" [hotel]="hotel"></app-hotel-item> @if (hotels[0].hotelName) {
<div *ngFor="let hotel of hotels">
<app-hotel-item *ngIf="hotel.hotelName.toLowerCase().includes(search.toLowerCase())" [hotel]="hotel"></app-hotel-item>
</div>
}
</div> </div>
}

@ -7,6 +7,7 @@ import { Hotel } from '../HotelItem/hotel';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { filter, from, last, map, Observable, scan } from 'rxjs'; import { filter, from, last, map, Observable, scan } from 'rxjs';
import { HotelItem } from '../HotelItem/HotelItem.component'; import { HotelItem } from '../HotelItem/HotelItem.component';
import { RouterLink } from '@angular/router';
interface User { interface User {
name: string; name: string;
@ -16,7 +17,7 @@ interface User {
@Component({ @Component({
selector: 'app-hotel-list', selector: 'app-hotel-list',
standalone: true, standalone: true,
imports: [UpperCasePipe, TextPipe, SearchComponent, HotelItem, NgFor, NgIf], imports: [UpperCasePipe, TextPipe, SearchComponent, HotelItem, NgFor, NgIf, RouterLink],
templateUrl: './hotel-list.component.html', templateUrl: './hotel-list.component.html',
styleUrl: './hotel-list.component.css' styleUrl: './hotel-list.component.css'
}) })

@ -0,0 +1,16 @@
<p>Create Hotel</p>
<form [formGroup]="hotelForm">
<label for="name">Name</label>
<input type="text" class="border-red-500" [class.border-8]='hotelForm.get("name")?.invalid && hotelForm.get("name")?.touched' id="name" formControlName="name">
<label for="description">Description</label>
<input type="text" class="border-red-500" [class.border-8]='hotelForm.get("description")?.invalid && hotelForm.get("description")?.touched' id="description" formControlName="description">
<label for="imageUrl">Image</label>
<input type="url" class="border-red-500" [class.border-8]='hotelForm.get("imageUel")?.invalid && hotelForm.get("imageUrl")?.touched' id="imageUrl" formControlName="imageUrl">
<label for="price">Price</label>
<input type="price" class="border-red-500" [class.border-8]='hotelForm.get("price")?.invalid' id="price" formControlName="price">
<label for="rating">Rating</label>
<input type="rating" class="border-red-500" [class.border-8]='hotelForm.get("rating")?.invalid' id="rating" formControlName="rating">
<button (click)="submit()" [disabled]="!hotelForm.valid" type="submit">Submit</button>
<a routerLink="/">Cancel</a>
</form>

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NewHotelComponent } from './new-hotel.component';
describe('NewHotelComponent', () => {
let component: NewHotelComponent;
let fixture: ComponentFixture<NewHotelComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [NewHotelComponent]
})
.compileComponents();
fixture = TestBed.createComponent(NewHotelComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -0,0 +1,47 @@
import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { Router, RouterLink } from '@angular/router';
import { Hotel } from '../HotelItem/hotel';
import { NgFor, NgIf } from '@angular/common';
@Component({
selector: 'app-new-hotel',
standalone: true,
imports: [ReactiveFormsModule, NgIf, NgFor, RouterLink],
templateUrl: './new-hotel.component.html',
styleUrl: './new-hotel.component.css'
})
export class NewHotelComponent {
public hotelForm!: FormGroup
public hotel!: Hotel
ngOnInit(): void {
this.hotelForm = new FormGroup({
name: new FormControl("", Validators.required),
description: new FormControl("", Validators.required),
price: new FormControl(0, Validators.required),
imageUrl: new FormControl("", Validators.required),
rating: new FormControl(0, Validators.required),
})
}
constructor(public http: HttpClient, public router: Router) {
}
submit(): void {
console.log(this.hotelForm.value);
const hotel: Hotel = {
id: 0,
hotelName: this.hotelForm.get("name")?.value,
description: this.hotelForm.get("description")?.value,
price: this.hotelForm.get("price")?.value,
imageUrl: this.hotelForm.get("imageUrl")?.value,
rating: this.hotelForm.get("rating")?.value,
tags: []
}
this.http.post("/api/hotels/", hotel).subscribe();
this.router.navigate(["/"]);
}
}

@ -0,0 +1,10 @@
<p>test works!</p>
<form [formGroup]="loginForm">
<label for="username">Username</label>
<input type="text" id="username" autocomplete="username" formControlName="username">
<label for="password">Password</label>
<input type="password" id="password" formControlName="password">
<button (click)="submit()" type="submit">Login</button>
<button type="reset" (click)="reset()">Reset</button>
</form>

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TestComponent } from './test.component';
describe('TestComponent', () => {
let component: TestComponent;
let fixture: ComponentFixture<TestComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TestComponent]
})
.compileComponents();
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -0,0 +1,34 @@
import { Component } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
@Component({
selector: 'app-test',
standalone: true,
imports: [ReactiveFormsModule],
templateUrl: './test.component.html',
styleUrl: './test.component.css'
})
export class TestComponent {
public loginForm!: FormGroup;
public ngOnInit(): void {
this.loginForm = this.setUpLoginForm();
console.log(this.loginForm);
}
setUpLoginForm(): FormGroup {
return new FormGroup({
username: new FormControl("Jan"),
password: new FormControl('')
});
}
reset(): void {
this.loginForm = this.setUpLoginForm();
}
submit(): void {
console.log(this.loginForm.value);
}
}

@ -8,7 +8,7 @@
<link rel="icon" type="image/x-icon" href="favicon.ico"> <link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="./styles.css"> <link rel="stylesheet" href="./styles.css">
</head> </head>
<body> <body class="bg-pink-600">
<app-root></app-root> <app-root></app-root>
</body> </body>
</html> </html>