-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 8-publish-advertisement
- Loading branch information
Showing
16 changed files
with
595 additions
and
49 deletions.
There are no files selected for viewing
46 changes: 45 additions & 1 deletion
46
src/app/apartment/apartment-list/apartment-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,45 @@ | ||
<p>apartment-list works!</p> | ||
<div class="apartment-list-container"> | ||
<h2> My apartments</h2> | ||
|
||
<div *ngIf="apartments.length === 0" class="no-apartments"> | ||
<p>No hay apartamentos disponibles.</p> | ||
</div> | ||
|
||
<div *ngIf="apartments.length > 0" class="table-responsive"> | ||
<table class="table table-striped table-bordered"> | ||
<thead class="thead-dark"> | ||
<tr> | ||
<th>ID</th> | ||
<th>Name</th> | ||
<th>Address</th> | ||
<th>Floor</th> | ||
<th>Postal Code</th> | ||
<th>Registration date</th> | ||
<th>Description</th> | ||
<th>Note</th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let apartment of apartments"> | ||
<td>{{ apartment.getIdFromLinks() }}</td> | ||
<td>{{ apartment.name }}</td> | ||
<td>{{ apartment.address }}, {{ apartment.city }}, {{ apartment.country }}</td> | ||
<td>{{ apartment.floor }}</td> | ||
<td>{{ apartment.postalCode }}</td> | ||
<td>{{ apartment.registrationDate | date }}</td> | ||
<td>{{ apartment.description || 'N/A' }}</td> | ||
<td>{{ apartment.note || 'N/A' }}</td> | ||
<td> | ||
<button class="deleteButton" (click)="deleteApartment(apartment.getIdFromLinks())"><span class = "deleteSpan">Delete</span></button> | ||
</td> | ||
<td> | ||
<button class="updateButton" (click)="updateApartment(apartment.getIdFromLinks())"><span class = "updateSpan">Edit</span></button> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<button class="createButton" (click)="createApartment()"><span class="createSpan">Create</span></button> | ||
</div> | ||
</div> |
83 changes: 79 additions & 4 deletions
83
src/app/apartment/apartment-list/apartment-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,87 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Apartment } from '../apartment'; | ||
import { ApartmentService } from '../apartment.service'; | ||
import { Router } from '@angular/router'; | ||
import { CommonModule } from '@angular/common'; | ||
import { User } from '../../login-basic/user'; | ||
import { AuthenticationBasicService } from '../../login-basic/authentication-basic.service'; | ||
import { ErrorMessageService } from '../../error-handler/error-message.service'; | ||
|
||
@Component({ | ||
selector: 'app-apartment-list', | ||
standalone: true, | ||
imports: [], | ||
imports: [CommonModule], | ||
templateUrl: './apartment-list.component.html', | ||
styleUrl: './apartment-list.component.css' | ||
styleUrls: ['./apartment-list.component.css'] | ||
}) | ||
export class ApartmentListComponent { | ||
export class ApartmentListComponent implements OnInit { | ||
|
||
public apartments: Apartment[] = []; // Almacena la lista de apartamentos | ||
public currentUser: User = new User(); | ||
public isShowed: boolean = false; | ||
|
||
constructor( | ||
private router: Router, | ||
private apartmentService: ApartmentService, | ||
private authenticationService: AuthenticationBasicService, | ||
private errorMessageService: ErrorMessageService, | ||
) { | ||
} | ||
|
||
ngOnInit(): void { | ||
this.currentUser = this.authenticationService.getCurrentUser(); | ||
this.isShowed = this.isOwner(); | ||
|
||
if (!this.isShowed) { | ||
this.onNotShowed(); | ||
return; | ||
} | ||
|
||
if (this.currentUser) { | ||
// Llama al servicio para obtener los apartamentos del usuario actual | ||
this.apartmentService.findByOwner(this.currentUser).subscribe({ | ||
|
||
next: (resourceCollection) => { | ||
|
||
this.apartments = resourceCollection.resources || []; // Asegúrate de asignar un arreglo | ||
}, | ||
error: (err) => { | ||
console.error('Error fetching apartments:', err); | ||
this.errorMessageService.showErrorMessage('Failed to load apartments'); | ||
}, | ||
}); | ||
} else { | ||
console.log('User not authenticated'); | ||
} | ||
} | ||
|
||
private isOwner(): boolean { | ||
return this.currentUser.getRoles().includes('owner'); | ||
} | ||
|
||
private onNotShowed(): void { | ||
this.errorMessageService.showErrorMessage('You are not an owner'); | ||
this.router.navigate(['/apartments']); | ||
} | ||
|
||
deleteApartment(apartmentId: string): void { | ||
if (apartmentId) { | ||
console.log('Apartment ID:', apartmentId); | ||
this.router.navigate([`/apartment/${apartmentId}/delete`]); | ||
} else { | ||
console.error('Invalid apartment ID'); | ||
} | ||
} | ||
|
||
updateApartment(apartmentId: string): void { | ||
if (apartmentId) { | ||
console.log('Apartment ID:', apartmentId); | ||
this.router.navigate([`/apartment/${apartmentId}/update`]); | ||
} else { | ||
console.error('Invalid apartment ID'); | ||
} | ||
} | ||
createApartment(): void { | ||
this.router.navigate(['/apartment/create']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,39 @@ | ||
<nav class="navbar navbar-expand-lg navbar-light bg-light"> | ||
<a class="navbar-brand ms-3" [routerLink]="['/about']"><b>My</b>Apartments</a> | ||
<button class="navbar-toggler" type="button" (click)="isCollapsed = !isCollapsed" | ||
[attr.aria-expanded]="!isCollapsed" aria-controls="navbarContent" aria-label="Toggle navigation"> | ||
<a class="navbar-brand ms-3" [routerLink]="['/about']"><b>My</b>Apartments</a> | ||
<button class="navbar-toggler" type="button" (click)="isCollapsed = !isCollapsed" [attr.aria-expanded]="!isCollapsed" aria-controls="navbarContent" aria-label="Toggle navigation"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
|
||
<div class="collapse navbar-collapse" id="navbarContent" [ngbCollapse]="isCollapsed"> | ||
<ul class="navbar-nav"> | ||
<li class="nav-item" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"> | ||
<a class="nav-link" [routerLink]="['/advertisements']">Advertisements</a> | ||
</li> | ||
<li class="nav-item" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"> | ||
<a class="nav-link" [routerLink]="['/about']">About</a> | ||
</li> | ||
|
||
<!--LIST APARTMENT--> | ||
<li class="nav-item" *ngIf="isRole('user') || isRole('owner')" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"> | ||
<a class="nav-link" [routerLink]="['/apartments']">Apartments list</a> | ||
</li> | ||
<div class="collapse navbar-collapse" id="navbarContent" [ngbCollapse]="isCollapsed"> | ||
<ul class="navbar-nav"> | ||
|
||
<li class="nav-item" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"> | ||
<a class="nav-link" [routerLink]="['/about']">About</a> | ||
</li> | ||
|
||
<!--LIST ADVERTISEMENTS--> | ||
<li class="nav-item" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"> | ||
<a class="nav-link" [routerLink]="['/advertisements']">Advertisements List</a> | ||
</li> | ||
|
||
<!--CREATE APARTMENT--> | ||
<li class="nav-item" *ngIf="isRole('owner')" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"> | ||
<a class="nav-link" [routerLink]="['/apartment/create']">Create apartment</a> | ||
</li> | ||
<!--LIST APARTMENT--> | ||
<li class="nav-item" *ngIf="isRole('owner')" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"> | ||
<a class="nav-link" [routerLink]="['/apartments']">Apartments list</a> | ||
</li> | ||
|
||
<li class="nav-item" *ngIf="isRole('user')" ngbDropdown> | ||
<a class="nav-link dropdown-toggle" id="playerDropdown" role="button" | ||
aria-haspopup="true" aria-expanded="false" ngbDropdownToggle>Users</a> | ||
<div class="dropdown-menu" aria-labelledby="playDropdown" ngbDropdownMenu> | ||
<a class="dropdown-item" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }" | ||
[routerLink]="['/users']"><span class="fas fa-user-circle"></span> List</a> | ||
</div> | ||
</li> | ||
</ul> | ||
<ul class="navbar-nav ms-auto me-3" app-login-navbar></ul> | ||
</div> | ||
</nav> | ||
<!--CREATE APARTMENT--> | ||
<li class="nav-item" *ngIf="isRole('owner')" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }"> | ||
<a class="nav-link" [routerLink]="['/apartment/create']">Create apartment</a> | ||
</li> | ||
|
||
<li class="nav-item" *ngIf="isRole('user')" ngbDropdown> | ||
<a class="nav-link dropdown-toggle" id="playerDropdown" role="button" aria-haspopup="true" aria-expanded="false" ngbDropdownToggle>Users</a> | ||
<div class="dropdown-menu" aria-labelledby="playDropdown" ngbDropdownMenu> | ||
<a class="dropdown-item" [routerLinkActive]="'active'" [routerLinkActiveOptions]="{ exact: true }" [routerLink]="['/users']"><span class="fas fa-user-circle"></span> List</a> | ||
</div> | ||
</li> | ||
</ul> | ||
<ul class="navbar-nav ms-auto me-3" app-login-navbar></ul> | ||
</div> | ||
</nav> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<div *ngIf="canCreateRoom" class="container mt-5 w-50 p-3"> | ||
<h1 class="mb-4">Create Apartment</h1> | ||
|
||
<form (ngSubmit)="onSubmit()" #roomForm="ngForm"> | ||
<div class="mb-3"> | ||
<label for="name" class="form-label">Select apartment</label> | ||
<select class="form-select" id="apartmentSelect" required [(ngModel)]="apartmentId" (ngModelChange)="onApartmentChange()"> | ||
<option value="" disabled>Select...</option> | ||
<option *ngFor="let apartment_value of apartments" [value]="apartment_value.id"> | ||
{{ apartment_value.name }} | ||
</option> | ||
</select> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="name" class="form-label">Is ocuppied ?</label> | ||
<select class="form-control" id="trueFalseSelectOcupied" required [(ngModel)]="room.isOccupied"> | ||
<option value="" disabled>Select...</option> | ||
<option [value]="true">True</option> | ||
<option [value]="false">False</option> | ||
</select> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="name" class="form-label">Has bed ?</label> | ||
<select class="form-control" id="trueFalseSelectHasBed" required [(ngModel)]="room.hasBed"> | ||
<option value="" disabled>Select...</option> | ||
<option [value]="true">True</option> | ||
<option [value]="false">False</option> | ||
</select> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="name" class="form-label">Has window ?</label> | ||
<select class="form-control" id="trueFalseSelectHasWindow" required [(ngModel)]="room.hasWindow"> | ||
<option value="" disabled>Select...</option> | ||
<option [value]="true">True</option> | ||
<option [value]="false">False</option> | ||
</select> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="name" class="form-label">Has desk ?</label> | ||
<select class="form-control" id="trueFalseSelectHasDesk" required [(ngModel)]="room.hasDesk"> | ||
<option value="" disabled>Select...</option> | ||
<option [value]="true">True</option> | ||
<option [value]="false">False</option> | ||
</select> | ||
</div> | ||
|
||
|
||
|
||
<button type="submit" class="btn btn-primary mt-3">Submit</button> | ||
</form> | ||
</div> | ||
|
||
<div *ngIf="!canCreateRoom" class="container mt-5 w-50 p-3"> | ||
<div class="alert alert-danger" role="alert"> | ||
You are not authorized to create a Room. | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { RoomCreateComponent } from './room-create.component'; | ||
|
||
describe('RoomCreateComponent', () => { | ||
let component: RoomCreateComponent; | ||
let fixture: ComponentFixture<RoomCreateComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [RoomCreateComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(RoomCreateComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.