diff --git a/src/app/HotelItem/HotelItem.component.ts b/src/app/HotelItem/HotelItem.component.ts index 0e5d136..934de63 100644 --- a/src/app/HotelItem/HotelItem.component.ts +++ b/src/app/HotelItem/HotelItem.component.ts @@ -1,7 +1,7 @@ import { Component, Injectable, Input } from "@angular/core"; import { ChildComponent } from "../Child/child.component"; import { Hotel } from "./hotel"; -import { CurrencyPipe, NgIf } from "@angular/common"; +import { CurrencyPipe, NgFor, NgIf } from "@angular/common"; import { FormsModule } from "@angular/forms"; import { StarRatingComponent } from "../star-rating/star-rating.component"; import { HttpClient } from "@angular/common/http"; @@ -11,7 +11,7 @@ import { RouterLink } from "@angular/router"; selector: 'app-hotel-item', standalone: true, templateUrl: './HotelItem.component.html', - imports: [ChildComponent, CurrencyPipe, FormsModule, StarRatingComponent, NgIf, RouterLink], + imports: [ChildComponent, CurrencyPipe, FormsModule, StarRatingComponent, NgIf, RouterLink, NgFor], }) export class HotelItem { diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index eaaae27..f9ab109 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -1,6 +1,7 @@ import { Routes } from '@angular/router'; import { HotelDetailsComponent } from './hotel-details/hotel-details.component'; import { HotelListComponent } from './hotel-list/hotel-list.component'; +import { TestComponent } from './test/test.component'; export const routes: Routes = [ { @@ -11,4 +12,8 @@ export const routes: Routes = [ path: "hotels/:id", component: HotelDetailsComponent, }, + { + path: "testing", + component: TestComponent, + } ]; diff --git a/src/app/hotel-details/hotel-details.component.html b/src/app/hotel-details/hotel-details.component.html index 3a1c644..9185215 100644 --- a/src/app/hotel-details/hotel-details.component.html +++ b/src/app/hotel-details/hotel-details.component.html @@ -1 +1,4 @@ - +@if (hotel != null) { + + +} diff --git a/src/app/hotel-details/hotel-details.component.ts b/src/app/hotel-details/hotel-details.component.ts index 2d3c396..2227551 100644 --- a/src/app/hotel-details/hotel-details.component.ts +++ b/src/app/hotel-details/hotel-details.component.ts @@ -2,15 +2,16 @@ import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; 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 { HotelItem } from '../HotelItem/HotelItem.component'; import { catchError, EMPTY } from 'rxjs'; +import { HotelFormComponent } from '../hotel-form/hotel-form.component'; @Component({ selector: 'app-hotel-details', standalone: true, - imports: [CurrencyPipe, StarRatingComponent, HotelItem], + imports: [CurrencyPipe, StarRatingComponent, HotelItem, HotelFormComponent, NgIf, NgForOf], templateUrl: './hotel-details.component.html', styleUrl: './hotel-details.component.css' }) diff --git a/src/app/hotel-form/hotel-form.component.css b/src/app/hotel-form/hotel-form.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/hotel-form/hotel-form.component.html b/src/app/hotel-form/hotel-form.component.html new file mode 100644 index 0000000..8b92ece --- /dev/null +++ b/src/app/hotel-form/hotel-form.component.html @@ -0,0 +1,12 @@ +

hotel-form works!

+ +
+ + + + + + + + Cancel +
diff --git a/src/app/hotel-form/hotel-form.component.spec.ts b/src/app/hotel-form/hotel-form.component.spec.ts new file mode 100644 index 0000000..3f1f5bd --- /dev/null +++ b/src/app/hotel-form/hotel-form.component.spec.ts @@ -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; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [HotelFormComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(HotelFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/hotel-form/hotel-form.component.ts b/src/app/hotel-form/hotel-form.component.ts new file mode 100644 index 0000000..a0b2a53 --- /dev/null +++ b/src/app/hotel-form/hotel-form.component.ts @@ -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(["/"]); + } +} diff --git a/src/app/test/test.component.css b/src/app/test/test.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/test/test.component.html b/src/app/test/test.component.html new file mode 100644 index 0000000..f0778f5 --- /dev/null +++ b/src/app/test/test.component.html @@ -0,0 +1,10 @@ +

test works!

+ +
+ + + + + + +
diff --git a/src/app/test/test.component.spec.ts b/src/app/test/test.component.spec.ts new file mode 100644 index 0000000..d233ca5 --- /dev/null +++ b/src/app/test/test.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TestComponent } from './test.component'; + +describe('TestComponent', () => { + let component: TestComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [TestComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(TestComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/test/test.component.ts b/src/app/test/test.component.ts new file mode 100644 index 0000000..bf2a97a --- /dev/null +++ b/src/app/test/test.component.ts @@ -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); + } +}