From 4f651c68c348a387043c86fb42d0fac5d31a9f82 Mon Sep 17 00:00:00 2001 From: apuente Date: Fri, 21 Jun 2024 13:08:16 +0200 Subject: [PATCH] Groups add delete functionallity --- ogWebconsole/src/app/app.module.ts | 4 +++- .../src/app/components/groups/data.service.ts | 13 +++++++++++ .../components/groups/groups.component.html | 4 ++-- .../app/components/groups/groups.component.ts | 23 +++++++++++++++---- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/ogWebconsole/src/app/app.module.ts b/ogWebconsole/src/app/app.module.ts index 6a50c12..9881dfd 100644 --- a/ogWebconsole/src/app/app.module.ts +++ b/ogWebconsole/src/app/app.module.ts @@ -39,6 +39,7 @@ import { CreateOrganizationalUnitComponent } from './components/groups/organizat import {MatStepperModule} from '@angular/material/stepper'; import { MatSlideToggleModule } from '@angular/material/slide-toggle'; import { CreateClientComponent } from './components/groups/clients/create-client/create-client.component'; +import { DeleteModalComponent } from './components/groups/delete-modal/delete-modal.component'; @NgModule({ declarations: [ @@ -60,7 +61,8 @@ import { CreateClientComponent } from './components/groups/clients/create-client ChangePasswordModalComponent, GroupsComponent, CreateOrganizationalUnitComponent, - CreateClientComponent + CreateClientComponent, + DeleteModalComponent ], bootstrap: [AppComponent], imports: [BrowserModule, diff --git a/ogWebconsole/src/app/components/groups/data.service.ts b/ogWebconsole/src/app/components/groups/data.service.ts index 6e8ae9d..ee41398 100644 --- a/ogWebconsole/src/app/components/groups/data.service.ts +++ b/ogWebconsole/src/app/components/groups/data.service.ts @@ -71,5 +71,18 @@ export class DataService { ); } + deleteElement(uuid: string, type: string): Observable { + const url = type === 'client' + ? `http://127.0.0.1:8080/clients/${uuid}` + : `http://127.0.0.1:8080/organizational-units/${uuid}`; + return this.http.delete(url).pipe( + catchError(error => { + console.error('Error deleting element', error); + return throwError(error); + }) + ); + } + + } diff --git a/ogWebconsole/src/app/components/groups/groups.component.html b/ogWebconsole/src/app/components/groups/groups.component.html index d468caf..133871e 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.html +++ b/ogWebconsole/src/app/components/groups/groups.component.html @@ -17,7 +17,7 @@ edit - delete + delete @@ -58,7 +58,7 @@ edit - delete + delete diff --git a/ogWebconsole/src/app/components/groups/groups.component.ts b/ogWebconsole/src/app/components/groups/groups.component.ts index 54b4fae..c8ec8a2 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.ts +++ b/ogWebconsole/src/app/components/groups/groups.component.ts @@ -3,6 +3,7 @@ import { DataService } from './data.service'; import { UnidadOrganizativa } from './model'; import { MatDialog } from '@angular/material/dialog'; import { CreateOrganizationalUnitComponent } from './organizational-units/create-organizational-unit/create-organizational-unit.component'; +import { DeleteModalComponent } from './delete-modal/delete-modal.component'; @Component({ selector: 'app-groups', @@ -40,8 +41,10 @@ export class GroupsComponent implements OnInit { loadChildrenAndClients(uuid: string): void { this.dataService.getChildren(uuid).subscribe( childrenData => { + console.log('Children data:', childrenData); // Depuración this.dataService.getClients(uuid).subscribe( clientsData => { + console.log('Clients data:', clientsData); // Depuración const newChildren = [...childrenData, ...clientsData]; if (newChildren.length > 0) { this.children = newChildren; @@ -57,7 +60,6 @@ export class GroupsComponent implements OnInit { ); } - addOU(): void { this.dialog.open(CreateOrganizationalUnitComponent); } @@ -79,9 +81,22 @@ export class GroupsComponent implements OnInit { } } - onDeleteClick(uuid: string): void { - console.log('UUID del elemento a eliminar:', uuid); - // Aquí puedes agregar lógica adicional para eliminar el elemento si es necesario + onDeleteClick(uuid: string, name: string, type: string): void { + const dialogRef = this.dialog.open(DeleteModalComponent, { + width: '250px', + data: { name } + }); + + dialogRef.afterClosed().subscribe(result => { + if (result) { + this.dataService.deleteElement(uuid, type).subscribe( + () => { + this.loadChildrenAndClients(this.selectedUnidad?.uuid || ''); + }, + error => console.error('Error deleting element', error) + ); + } + }); } onEditClick(type: any, uuid: string): void {