Skip to content

Commit

Permalink
completed
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanu committed Dec 4, 2023
1 parent 7cf38fa commit ac04dbf
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 13 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@angular/platform-browser": "^17.0.0",
"@angular/platform-browser-dynamic": "^17.0.0",
"@angular/router": "^17.0.0",
"bootstrap": "^5.3.2",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.2"
Expand All @@ -40,4 +41,4 @@
"tailwindcss": "^3.3.5",
"typescript": "~5.2.2"
}
}
}
1 change: 1 addition & 0 deletions src/app/app-nav/app-nav.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<a mat-list-item routerLink="home">Home</a>
<a mat-list-item routerLink="rooms">Room</a>
<a mat-list-item routerLink="employee">Employee</a>
<a mat-list-item routerLink="rooms/add/addRoom">AddRoom</a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
Expand Down
6 changes: 6 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EmployeeComponent } from './employee/employee.component';
import { NotFoundComponent } from './not-found/not-found.component';
import { RoomsBookingComponent } from './rooms/rooms-booking/rooms-booking.component';
import { AuthGuard } from './shared/auth/auth.guard';
import { RoomAddComponent } from './rooms/room-add/room-add.component';

const routes: Routes = [
{
Expand All @@ -23,6 +24,11 @@ const routes: Routes = [
{
path:'rooms/:id',component:RoomsBookingComponent,canActivate:[AuthGuard]
},
{
path:'rooms/add/addRoom',component:RoomAddComponent ,canActivate:[AuthGuard]
},

//lazy loading
{ path: 'a', loadChildren: () => import('./modulea/modulea.module').then(m => m.ModuleaModule) },
{ path: 'b', loadChildren: () => import('./moduleb/moduleb.module').then(m => m.ModulebModule) },
{
Expand Down
4 changes: 0 additions & 4 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
<app-app-nav></app-app-nav>

<!-- <a [routerLink]="'home'">Home</a>
<a [routerLink]="'rooms'">Room</a>
<a [routerLink]="'employee'">Employee</a> -->
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class AppComponent implements OnInit{
constructor(private newsService:NewsService) { }
//acces to the element with the #name
//@ViewChild('name', { static: true }) name!: ElementRef;
title = 'App2';
//title = 'App2';

ngOnInit(): void {
//this.name.nativeElement.value = 'Hello World';
Expand Down
6 changes: 4 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { RoomsBookingComponent } from './rooms/rooms-booking/rooms-booking.compo
import { AuthService } from './service/auth.service';
import { NewsService } from './service/news.service';
import { AuthGuard } from './shared/auth/auth.guard';
import { RoomAddComponent } from './rooms/room-add/room-add.component';


@NgModule({
Expand All @@ -42,8 +43,9 @@ import { AuthGuard } from './shared/auth/auth.guard';
AppNavComponent,
NotFoundComponent,
RoomsBookingComponent,
RoomsBookingComponent
],
RoomsBookingComponent,
RoomAddComponent,
],

imports: [
BrowserModule,
Expand Down
4 changes: 4 additions & 0 deletions src/app/modulea/modulea-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ const routes: Routes = [
exports: [RouterModule]
})
export class ModuleaRoutingModule { }

//create module for each compoent instead of app.module.ts
//single responsibility principle
//lazy loading
4 changes: 4 additions & 0 deletions src/app/rooms/room-add/room-add.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.form-group .form-control {
margin-top: 5px;
margin-bottom: 5px;
}
50 changes: 50 additions & 0 deletions src/app/rooms/room-add/room-add.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<form (ngSubmit)="onSubmit()" #f="ngForm" novalidate>
<div class="form-group">
<label for="">Firstname</label>
<input #name="ngModel" [ngClass]="{
'is-invalid':
name.invalid && (name.invalid || name.touched),
'is-valid':
name.valid && (name.invalid || name.touched)
}" minlength="1" required class="form-control" type="text" [(ngModel)]="roomModel.name"
placeholder="name" name="firstName" ngModel />
<div class="invalid-feedback">
<p *ngIf="name.errors">Please fill name!</p>
</div>
</div>

<div class="form-group">
<label for="">toISO</label>
<input #isOn="ngModel" [ngClass]="{
'is-invalid':
isOn.invalid && (isOn.invalid || isOn.touched),
'is-valid':
isOn.valid && (isOn.invalid || isOn.touched)
}" minlength="1" required class="form-control" type="text" [(ngModel)]="roomModel.isOn"
placeholder="isOn" name="isOn" ngModel />
<div class="invalid-feedback">
<p *ngIf="isOn.errors">Please fill isOn</p>
</div>
</div>

<div class="form-group">
<label for="">Temparature</label>
<input #temperature="ngModel" [ngClass]="{
'is-invalid':
temperature.invalid && ( temperature.invalid || temperature.touched),
'is-valid':
temperature.valid && ( temperature.invalid || temperature.touched)
}" minlength="1" required class="form-control" type="text" [(ngModel)]="roomModel.temperature"
placeholder=" temperature" name=" temperature" ngModel />
<div class="invalid-feedback">
<p *ngIf="temperature.errors">Please fill temperature</p>
</div>
</div>

<button [disabled]="f.invalid" class="btn btn-primary" type="submit" value="submit">
Submit
</button>

<p *ngIf="!f.invalid">{{ f.value | json }}</p>

</form>
23 changes: 23 additions & 0 deletions src/app/rooms/room-add/room-add.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { RoomAddComponent } from './room-add.component';

describe('RoomAddComponent', () => {
let component: RoomAddComponent;
let fixture: ComponentFixture<RoomAddComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [RoomAddComponent]
})
.compileComponents();

fixture = TestBed.createComponent(RoomAddComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
28 changes: 28 additions & 0 deletions src/app/rooms/room-add/room-add.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { room } from '../../shared/interface/room';

@Component({
selector: 'app-room-add',
templateUrl: './room-add.component.html',
styleUrl: './room-add.component.css'
})
export class RoomAddComponent implements OnInit{
constructor(private ref: ElementRef) { }
@ViewChild('f') form: any;
b: boolean = false;
roomModel: room = {};
ngOnInit(): void {}

onSubmit(): void {
if (this.form.invalid) {
alert('please enter valid data!');
return;
}
//pass the form object to backend via the service
alert('success');
console.log(this.form.controls);

//reset form value after hit the submit button
this.form.reset();
}
}
1 change: 0 additions & 1 deletion src/app/rooms/rooms-booking/rooms-booking.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export class RoomsBookingComponent implements OnInit{
constructor(private route: ActivatedRoute) { }
ngOnInit(): void {
console.log(this.id);

}

id: number = this.route.snapshot.params['id'];
Expand Down
8 changes: 4 additions & 4 deletions src/app/shared/interface/room.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export interface room{
id: number,
name: string,
isOn: boolean,
temperature: number,
id?:number,
name?: string,
isOn?: boolean,
temperature?: number,
}


Expand Down
1 change: 1 addition & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
@tailwind utilities;
html, body { height: 100%; }
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
@import url("../node_modules/bootstrap/dist/css/bootstrap.min.css");

0 comments on commit ac04dbf

Please sign in to comment.