Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Room list #40

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ <h1 class="mb-4">Create Apartment</h1>
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" rows="3" required [(ngModel)]="apartment.description" name="description" style="resize: vertical; min-height: 100px; max-height: 300px;"></textarea>
</div>
<app-room-list [apartment]="apartment" [maxRooms]="5"></app-room-list>
<div class="mb-3">
<a href="/room/create"><button type="button" class="btn btn-secondary">Add Room</button></a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import { ErrorMessageService } from '../../error-handler/error-message.service';
import { CommonModule } from '@angular/common';
import { ApartmentService } from '../apartment.service';
import { ApartmentDetails } from '../apartment-details';
import { RoomListComponent } from '../../room/room-list/room-list.component';

@Component({
selector: 'app-apartment-create',
standalone: true,
imports: [FormsModule, CommonModule],
imports: [FormsModule, CommonModule, RoomListComponent],
templateUrl: './apartment-create.component.html',
styleUrls: ['./apartment-create.component.css']
})
Expand Down
13 changes: 7 additions & 6 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { UserDetailComponent } from './user/user-detail/user-detail.component';
import { UserRegisterComponent } from './user/user-register/user-register.component';
import { UserEditComponent } from './user/user-edit/user-edit.component';
import { UserDeleteComponent } from './user/user-delete/user-delete.component';
import {ApartmentListComponent} from './apartment/apartment-list/apartment-list.component';
import {ApartmentCreateComponent} from './apartment/apartment-create/apartment-create.component';
import {ApartmentUpdateComponent} from './apartment/apartment-update/apartment-update.component';
import {ApartmentDeleteComponent} from './apartment/apartment-delete/apartment-delete.component';
import {VisitStatusComponent} from './visit/visit-status/visit-status.component';

import { ApartmentListComponent } from './apartment/apartment-list/apartment-list.component';
import { ApartmentCreateComponent } from './apartment/apartment-create/apartment-create.component';
import { ApartmentUpdateComponent } from './apartment/apartment-update/apartment-update.component';
import { ApartmentDeleteComponent } from './apartment/apartment-delete/apartment-delete.component';
import { VisitStatusComponent } from './visit/visit-status/visit-status.component';
import { RoomListComponent } from './room/room-list/room-list.component';

const routes: Routes = [
{ path: 'users/create', component: UserRegisterComponent},
Expand All @@ -27,6 +27,7 @@ const routes: Routes = [
{ path: 'apartment/:id/update', component: ApartmentUpdateComponent},
{ path: 'apartment/:id/delete', component: ApartmentDeleteComponent},
{ path: 'visit/:id/status', component: VisitStatusComponent},
{ path: 'rooms', component: RoomListComponent},
{ path: '404', component: NotFoundComponent},
{ path: '', redirectTo: 'about', pathMatch: 'full'},
];
Expand Down
Empty file.
16 changes: 16 additions & 0 deletions src/app/room/room-list/room-list.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="container w-10 p-3">
<h4 class="mb-1">List of Rooms</h4>

<div *ngIf="rooms.length > 0" class="list-group">
<div *ngFor="let room of rooms; let i = index" class="list-group-item">
<h5 class="mb-1">Room {{ i + 1 }}</h5>
<p class="mb-1">Surface: {{ room.surface }} m²</p>
<small *ngIf="room.isOccupied">Occupied</small>
<small *ngIf="!room.isOccupied">Available</small>
</div>
</div>

<div *ngIf="rooms.length === 0" class="alert alert-info" role="alert">
No rooms available for this apartment.
</div>
</div>
23 changes: 23 additions & 0 deletions src/app/room/room-list/room-list.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 { RoomListComponent } from './room-list.component';

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

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

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
36 changes: 36 additions & 0 deletions src/app/room/room-list/room-list.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Component, Input, OnInit } from '@angular/core';
import { RoomService } from '../room.service';
import { Room } from '../room';
import { Apartment } from '../../apartment/apartment';
import { CommonModule } from '@angular/common';

@Component({
selector: 'app-room-list',
standalone: true,
imports: [CommonModule],
templateUrl: './room-list.component.html',
styleUrls: ['./room-list.component.css']
})
export class RoomListComponent implements OnInit {
@Input() apartment!: Apartment;
// Max number of rooms to show, set to -1 to show all
@Input() maxRooms: number = 10;
rooms: Room[] = [];

constructor(private roomService: RoomService) {}

ngOnInit(): void {
if (this.apartment) {
this.roomService.findByApartment(this.apartment).subscribe({
next: (collection) => {
if (this.maxRooms === -1) {
this.rooms = collection.resources;
} else {
this.rooms = collection.resources.slice(0, this.maxRooms);
}
},
error: (err) => console.error('Error fetching rooms:', err),
});
}
}
}
26 changes: 26 additions & 0 deletions src/app/room/room.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { HateoasResourceOperation, ResourceCollection } from "@lagoshny/ngx-hateoas-client";
import { Room } from "./room";
import { Apartment } from "./../apartment/apartment";
import { User } from "../login-basic/user";

@Injectable({ providedIn: "root" })
export class RoomService extends HateoasResourceOperation<Room> {

constructor() {
super(Room);
}

public findById(roomId: string): Observable<Room> {
return this.getResource(roomId);
}

public findByApartment(apartment: Apartment): Observable<ResourceCollection<Room>> {
return this.searchCollection("findByApart", { params: { apartment: apartment } });
}

public findByOwner(owner: User): Observable<ResourceCollection<Room>> {
return this.searchCollection("findByOwner", { params: { owner: owner } });
}
}
Loading