From 9ea44e50499cee906d7ff3e03f83c1e13b325c4e Mon Sep 17 00:00:00 2001 From: Hdelegido Date: Sat, 18 May 2024 12:39:51 +0200 Subject: [PATCH] role details and delete done --- src/app/app-routing.module.ts | 4 +++ src/app/app.module.ts | 4 +++ .../role-delete/role-delete.component.html | 14 ++++++++ .../role/role-delete/role-delete.component.ts | 34 +++++++++++++++++++ .../role-detail/role-detail.component.html | 28 +++++++++++++++ .../role/role-detail/role-detail.component.ts | 32 +++++++++++++++++ .../role/role-list/role-list.component.html | 31 +++++++++++------ src/app/role/role-list/role-list.component.ts | 1 + src/app/role/role.ts | 7 +++- src/app/role/roleService.ts | 7 +++- 10 files changed, 150 insertions(+), 12 deletions(-) create mode 100644 src/app/role/role-delete/role-delete.component.html create mode 100644 src/app/role/role-delete/role-delete.component.ts create mode 100644 src/app/role/role-detail/role-detail.component.html create mode 100644 src/app/role/role-detail/role-detail.component.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index bada1a6..0c9462c 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -11,6 +11,8 @@ import { UserDeleteComponent } from './user/user-delete/user-delete.component'; import { ShelterListComponent } from './shelter/shelter-list/shelter-list.component' import {RoleListComponent} from "./role/role-list/role-list.component"; import {RoleCreateComponent} from "./role/role-create/role-create.component" +import {RoleDeleteComponent} from "./role/role-delete/role-delete.component"; +import {RoleDetailComponent} from "./role/role-detail/role-detail.component"; const routes: Routes = [ { path: 'users/create', component: UserRegisterComponent}, @@ -24,6 +26,8 @@ const routes: Routes = [ { path: 'shelters', component: ShelterListComponent}, {path: 'role', component:RoleListComponent}, {path: 'role/create', component:RoleCreateComponent}, + {path:'role/:id/delete', component:RoleDeleteComponent}, + {path:'role/:id', component:RoleDetailComponent}, ]; @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 0fc2a13..a5d08df 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -26,6 +26,8 @@ import {UserService} from './user/user.service'; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; import {RoleListComponent} from './role/role-list/role-list.component'; import {RoleCreateComponent} from './role/role-create/role-create.component'; +import {RoleDeleteComponent} from "./role/role-delete/role-delete.component"; +import {RoleDetailComponent} from "./role/role-detail/role-detail.component"; @NgModule({ declarations: [ @@ -41,6 +43,8 @@ import {RoleCreateComponent} from './role/role-create/role-create.component'; UserSearchComponent, RoleListComponent, RoleCreateComponent, + RoleDeleteComponent, + RoleDetailComponent, ], imports: [ BrowserModule, diff --git a/src/app/role/role-delete/role-delete.component.html b/src/app/role/role-delete/role-delete.component.html new file mode 100644 index 0000000..fb0b82d --- /dev/null +++ b/src/app/role/role-delete/role-delete.component.html @@ -0,0 +1,14 @@ +
+
+
Please, confirm deletion:
+
+
+
+ + +
+
+
+ diff --git a/src/app/role/role-delete/role-delete.component.ts b/src/app/role/role-delete/role-delete.component.ts new file mode 100644 index 0000000..a216819 --- /dev/null +++ b/src/app/role/role-delete/role-delete.component.ts @@ -0,0 +1,34 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { RoleService } from '../roleService'; +import { Role } from '../role'; + +@Component({ + selector: 'app-role-delete', + templateUrl: './role-delete.component.html' +}) +export class RoleDeleteComponent implements OnInit { + public role: Role = new Role(); + private id: string; + + constructor( + private route: ActivatedRoute, + private router: Router, + private roleService: RoleService + ) {} + + ngOnInit(): void { + this.id = this.route.snapshot.paramMap.get('id'); + this.roleService.getResource(this.id).subscribe( + role => this.role = role + ); + } + + delete(): void { + this.roleService.deleteResource(this.role).subscribe( + () => { + this.router.navigate(['/role']); + } + ); + } +} diff --git a/src/app/role/role-detail/role-detail.component.html b/src/app/role/role-detail/role-detail.component.html new file mode 100644 index 0000000..0237045 --- /dev/null +++ b/src/app/role/role-detail/role-detail.component.html @@ -0,0 +1,28 @@ +
+
+

{{role.name}}

+
+
+
Role Name
+

{{role.name}}

+
+
+
Role ID
+

{{role.id}}

+
+ +
+ +
+
+ diff --git a/src/app/role/role-detail/role-detail.component.ts b/src/app/role/role-detail/role-detail.component.ts new file mode 100644 index 0000000..8cc168a --- /dev/null +++ b/src/app/role/role-detail/role-detail.component.ts @@ -0,0 +1,32 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { RoleService } from '../roleService'; // Asegúrate de que la ruta sea correcta +import { Role } from '../role'; +import { AuthenticationBasicService } from '../../login-basic/authentication-basic.service'; + +@Component({ + selector: 'app-role-detail', + templateUrl: './role-detail.component.html' +}) +export class RoleDetailComponent implements OnInit { + public role: Role = new Role(); + + constructor( + private route: ActivatedRoute, + private roleService: RoleService, + private authenticationService: AuthenticationBasicService + ) {} + + ngOnInit(): void { + const id = this.route.snapshot.paramMap.get('id'); + this.roleService.getResource(id).subscribe( + role => { + this.role = role; + } + ); + } + + getCurrentRole(): Role { + return this.roleService.getCurrentRole(); + } +} diff --git a/src/app/role/role-list/role-list.component.html b/src/app/role/role-list/role-list.component.html index b29ee64..38a7269 100644 --- a/src/app/role/role-list/role-list.component.html +++ b/src/app/role/role-list/role-list.component.html @@ -1,14 +1,25 @@ -
-
-
-
-
Name
- {{role.name}} +
+ +
+
+

Role List

+
+
+ + +
+
+
+
+
Name
+ {{role.name}} +
-
- + + +
diff --git a/src/app/role/role-list/role-list.component.ts b/src/app/role/role-list/role-list.component.ts index 4b6bce0..147fe55 100644 --- a/src/app/role/role-list/role-list.component.ts +++ b/src/app/role/role-list/role-list.component.ts @@ -26,6 +26,7 @@ export class RoleListComponent implements OnInit { }) .subscribe((page: PagedResourceCollection) => { this.roles = page.resources; + console.log(this.roles); this.totalRoles = page.totalElements; }); } diff --git a/src/app/role/role.ts b/src/app/role/role.ts index 06c24c6..2568c3e 100644 --- a/src/app/role/role.ts +++ b/src/app/role/role.ts @@ -2,11 +2,16 @@ import { HateoasResource, Resource } from '@lagoshny/ngx-hateoas-client'; @HateoasResource('roles') export class Role extends Resource { - id: number; name: string; + uri: string; constructor(values: object = {}) { super(); Object.assign(this as any, values); } + + public get id (): String { + let uriArray =this.uri.split('/'); + return uriArray.pop(); +} } diff --git a/src/app/role/roleService.ts b/src/app/role/roleService.ts index aa78d5c..81a0358 100644 --- a/src/app/role/roleService.ts +++ b/src/app/role/roleService.ts @@ -1,7 +1,8 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { HateoasResourceOperation, ResourceCollection } from '@lagoshny/ngx-hateoas-client'; -import { Role } from "./role"; // Asegúrate de importar la clase Role correctamente +import { Role } from "./role"; +import {User} from "../login-basic/user"; // Asegúrate de importar la clase Role correctamente @Injectable({ providedIn: 'root' }) export class RoleService extends HateoasResourceOperation { @@ -13,4 +14,8 @@ export class RoleService extends HateoasResourceOperation { public findByName(query: string): Observable> { return this.searchCollection('findByName', { params: { text: query } }); } + + getCurrentRole(): Role { + return new Role(JSON.parse(localStorage.getItem('currentRole'))); + } }