Compare commits

..

3 Commits

Author SHA1 Message Date
0a0378e1c4
feat: add hotel form and test components with routing 2024-11-19 11:32:02 +01:00
21eb309acc Merge pull request 'update styling and fix search to include lowercase' (#15) from styling_lowercase_search into main
Reviewed-on: #15
Reviewed-by: Jan Gleytenhoover <krisellp9@gmail.com>
2024-11-19 07:43:38 +00:00
Jan-Marlon Leibl
85dbe967ee update styling and fix search to include lowercase 2024-11-19 08:28:09 +01:00
19 changed files with 178 additions and 29 deletions

BIN
bun.lockb

Binary file not shown.

@ -29,7 +29,7 @@
"@angular/compiler-cli": "^18.2.3",
"@types/jasmine": "~5.1.0",
"autoprefixer": "^10.4.20",
"jasmine-core": "~5.4.0",
"jasmine-core": "~5.1.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
@ -37,6 +37,6 @@
"karma-jasmine-html-reporter": "~2.1.0",
"postcss": "^8.4.41",
"tailwindcss": "^3.4.10",
"typescript": "~5.6.0"
"typescript": "~5.5.2"
}
}

@ -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>
<p>Balance: {{balance}}</p>
<p [class.hidden]="!isBroke">Im broke. Now im about as poor as Jan-Marlon.</p>
<button type="button" (click)=takeMoney() class="button">Take Money</button>
<h1 class="text-2xl font-bold mb-4">Child</h1>
<p class="text-lg mb-2">Balance: {{balance}}</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="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>Description: {{hotel.description}}</p>
<p>Price: {{hotel.price | currency : getCurrencyCode(selectedLanguage) : "symbol" : "2.2-2" : selectedLanguage}}</p>
<select [ngModel]="selectedLanguage" (ngModelChange)="languageChange($event)">
@for (lang of langs; track lang.lang) {
<option value="{{lang.code}}" [selected]="lang.lang == 'de'">{{lang.lang}}</option>
}
<p class="text-2xl font-bold text-gray-800 mb-2">Name: {{hotel.hotelName}}</p>
<p class="text-base text-gray-600 mb-4">Description: {{hotel.description}}</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)" class="block w-full p-2 border border-gray-300 rounded-md mb-4 focus:border-blue-500 focus:ring focus:ring-blue-200">
<option *ngFor="let lang of langs" [value]="lang.code" [selected]="lang.lang == 'de'">{{lang.lang}}</option>
</select>
<img src="{{hotel.imageUrl}}" alt="Hotel">
<a *ngIf="!isDetail" routerLink="/hotels/{{hotel.id}}">Details</a>
<app-star-rating [rating]="hotel.rating"></app-star-rating>
<img src="{{hotel.imageUrl}}" alt="Hotel" class="w-full h-auto rounded-lg shadow-lg mb-4">
<a *ngIf="!isDetail" routerLink="/hotels/{{hotel.id}}" class="text-blue-600 hover:text-blue-800 hover:underline mb-4 block">Details</a>

@ -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 {

@ -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,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,
}
];

@ -1 +1,4 @@
<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>
}

@ -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'
})

@ -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' id="price" formControlName="price">
<button (click)="submit()" [disabled]="!hotelForm.valid" type="submit">Update</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,9 @@
<h1>{{'hello' | uppercase | text}}</h1>
<app-search [(input)]="search"></app-search>
@if (hotels[0].hotelName) {
<div *ngFor="let hotel of hotels">
<app-hotel-item *ngIf="hotel.hotelName.includes(search)" [hotel]="hotel"></app-hotel-item>
<div class="container p-4 mx-auto max-w-4xl">
<h1>{{'hello' | uppercase | text}}</h1>
<app-search [(input)]="search"></app-search>
@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>
}

@ -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);
}
}