Groups add delete functionallity
parent
844fd23bb4
commit
4f651c68c3
|
@ -39,6 +39,7 @@ import { CreateOrganizationalUnitComponent } from './components/groups/organizat
|
||||||
import {MatStepperModule} from '@angular/material/stepper';
|
import {MatStepperModule} from '@angular/material/stepper';
|
||||||
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
|
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
|
||||||
import { CreateClientComponent } from './components/groups/clients/create-client/create-client.component';
|
import { CreateClientComponent } from './components/groups/clients/create-client/create-client.component';
|
||||||
|
import { DeleteModalComponent } from './components/groups/delete-modal/delete-modal.component';
|
||||||
|
|
||||||
|
|
||||||
@NgModule({ declarations: [
|
@NgModule({ declarations: [
|
||||||
|
@ -60,7 +61,8 @@ import { CreateClientComponent } from './components/groups/clients/create-client
|
||||||
ChangePasswordModalComponent,
|
ChangePasswordModalComponent,
|
||||||
GroupsComponent,
|
GroupsComponent,
|
||||||
CreateOrganizationalUnitComponent,
|
CreateOrganizationalUnitComponent,
|
||||||
CreateClientComponent
|
CreateClientComponent,
|
||||||
|
DeleteModalComponent
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent],
|
bootstrap: [AppComponent],
|
||||||
imports: [BrowserModule,
|
imports: [BrowserModule,
|
||||||
|
|
|
@ -71,5 +71,18 @@ export class DataService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteElement(uuid: string, type: string): Observable<void> {
|
||||||
|
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<void>(url).pipe(
|
||||||
|
catchError(error => {
|
||||||
|
console.error('Error deleting element', error);
|
||||||
|
return throwError(error);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
</span>
|
</span>
|
||||||
<span class="actions">
|
<span class="actions">
|
||||||
<mat-icon class="edit-icon" (click)="onEditClick(unidad.type, unidad.uuid)">edit</mat-icon>
|
<mat-icon class="edit-icon" (click)="onEditClick(unidad.type, unidad.uuid)">edit</mat-icon>
|
||||||
<mat-icon class="delete-icon" (click)="onDeleteClick(unidad.uuid)">delete</mat-icon>
|
<mat-icon class="delete-icon" (click)="onDeleteClick(unidad.uuid, unidad.nombre || unidad.nombre, unidad.type)">delete</mat-icon>
|
||||||
</span>
|
</span>
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
</mat-list>
|
</mat-list>
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
</span>
|
</span>
|
||||||
<span class="actions">
|
<span class="actions">
|
||||||
<mat-icon class="edit-icon" (click)="onEditClick(child.type, child.uuid)">edit</mat-icon>
|
<mat-icon class="edit-icon" (click)="onEditClick(child.type, child.uuid)">edit</mat-icon>
|
||||||
<mat-icon class="delete-icon" (click)="onDeleteClick(child.uuid)">delete</mat-icon>
|
<mat-icon class="delete-icon" (click)="onDeleteClick(child.uuid, child.name || child.nombre, child.type)">delete</mat-icon>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { DataService } from './data.service';
|
||||||
import { UnidadOrganizativa } from './model';
|
import { UnidadOrganizativa } from './model';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { CreateOrganizationalUnitComponent } from './organizational-units/create-organizational-unit/create-organizational-unit.component';
|
import { CreateOrganizationalUnitComponent } from './organizational-units/create-organizational-unit/create-organizational-unit.component';
|
||||||
|
import { DeleteModalComponent } from './delete-modal/delete-modal.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-groups',
|
selector: 'app-groups',
|
||||||
|
@ -40,8 +41,10 @@ export class GroupsComponent implements OnInit {
|
||||||
loadChildrenAndClients(uuid: string): void {
|
loadChildrenAndClients(uuid: string): void {
|
||||||
this.dataService.getChildren(uuid).subscribe(
|
this.dataService.getChildren(uuid).subscribe(
|
||||||
childrenData => {
|
childrenData => {
|
||||||
|
console.log('Children data:', childrenData); // Depuración
|
||||||
this.dataService.getClients(uuid).subscribe(
|
this.dataService.getClients(uuid).subscribe(
|
||||||
clientsData => {
|
clientsData => {
|
||||||
|
console.log('Clients data:', clientsData); // Depuración
|
||||||
const newChildren = [...childrenData, ...clientsData];
|
const newChildren = [...childrenData, ...clientsData];
|
||||||
if (newChildren.length > 0) {
|
if (newChildren.length > 0) {
|
||||||
this.children = newChildren;
|
this.children = newChildren;
|
||||||
|
@ -57,7 +60,6 @@ export class GroupsComponent implements OnInit {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
addOU(): void {
|
addOU(): void {
|
||||||
this.dialog.open(CreateOrganizationalUnitComponent);
|
this.dialog.open(CreateOrganizationalUnitComponent);
|
||||||
}
|
}
|
||||||
|
@ -79,9 +81,22 @@ export class GroupsComponent implements OnInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDeleteClick(uuid: string): void {
|
onDeleteClick(uuid: string, name: string, type: string): void {
|
||||||
console.log('UUID del elemento a eliminar:', uuid);
|
const dialogRef = this.dialog.open(DeleteModalComponent, {
|
||||||
// Aquí puedes agregar lógica adicional para eliminar el elemento si es necesario
|
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 {
|
onEditClick(type: any, uuid: string): void {
|
||||||
|
|
Loading…
Reference in New Issue