From bf3fe8b1ae342f4f53644c732871c5f927ff4a0d Mon Sep 17 00:00:00 2001 From: apuente Date: Mon, 12 Aug 2024 14:14:45 +0200 Subject: [PATCH] Code clean --- .../components/groups/groups.component.html | 87 ++++--------------- .../app/components/groups/groups.component.ts | 47 ++++++---- 2 files changed, 47 insertions(+), 87 deletions(-) diff --git a/ogWebconsole/src/app/components/groups/groups.component.html b/ogWebconsole/src/app/components/groups/groups.component.html index 7cad814..bccfb25 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.html +++ b/ogWebconsole/src/app/components/groups/groups.component.html @@ -179,6 +179,9 @@ Nombre + + + @@ -216,73 +219,7 @@ Windows 10 Education 1803 64 bits Ubuntu 18.04.1 LTS 64 bits Ubuntu 16.04.4 LTS 64 bits - DATA - Windows Boot loader - Windows 7 Professional - OpenGnsys Live - Ubuntu 18.04 LTS 64 bits - Windows 10 Education 1709 64 bits - Windows 7 Enterprise 64 bits - Windows 10 Education 1607 64 bits - Ubuntu 16.04.5 LTS 64 bits - Ubuntu 16.04.2 LTS 64 bits - Windows 10 Education 64 bits - CentOS release 6.3 (Final) 64 bits - Ubuntu 16.04.1 LTS 64 bits - Windows 10 Enterprise 1803 64 bits - Ubuntu 16.04.3 LTS 64 bits - Ubuntu precise (12.04.4 LTS) - GRUB2 Loader - Mac OS X 10.9.5 64 bits - Mac OS X 10.8.3 recovery - Mac OS X 10.13.6 - Windows 10 Education 1703 64 bits - Windows 7 Professional 64 bits - Ubuntu 14.04.4 LTS 64 bits - Windows 10 Education 1511 64 bits - Ubuntu 18.04.2 LTS 64 bits - Windows 10 Education 1809 64 bits - Ubuntu 16.04.6 LTS 64 bits - Ubuntu 14.04.5 LTS 64 bits - Windows 10 Education 1903 64 bits - Windows 10 Enterprise 1903 64 bits - Windows 10 Pro 1903 64 bits - Ubuntu 18.04.3 LTS 64 bits - Windows 10 Education 1909 64 bits - Ubuntu 18.04.3 LTS - Windows 10 Enterprise 1909 64 bits - Ubuntu 18.04.4 LTS 64 bits - Windows Boot loader 64 bits - Windows 10 Education 2004 64 bits - Ubuntu 20.04 LTS 64 bits - Ubuntu 20.04.1 LTS 64 bits - Windows 10 Enterprise LTSC 2019 Evaluation 1809 64 bits - Ubuntu 18.04.5 LTS 64 bits - Windows 10 Education 2009 64 bits - Ubuntu 20.04.2 LTS 64 bits - GRUB2 Loader 64 bits - Windows 10 Education 2009 - Debian GNU/Linux 8 (jessie) 64 bits - Windows 10 Enterprise 2009 64 bits - Windows 10 Pro 2009 64 bits - Windows 10 Pro 1909 64 bits - Windows 10 Home 2009 64 bits - Ubuntu 20.04.3 LTS 64 bits - Ubuntu 20.04.4 LTS 64 bits - Microsoft Windows XP - Ubuntu 22.04 LTS 64 bits - Ubuntu 22.04.1 LTS 64 bits - EducaAndOS 20.04 64 bits - Ubuntu 20.04.5 LTS 64 bits - Windows 10 Pro N 2009 64 bits - Guadalinex Edu 20.04 64 bits - Ubuntu 18.04.6 LTS 64 bits - elementary OS 6 Odin 64 bits - Ubuntu 22.04.2 LTS 64 bits - Ubuntu 22.04.3 LTS 64 bits - Windows 10 Pro for Workstations 2009 64 bits - Ubuntu 23.10 64 bits - Ubuntu 22.04.4 LTS 64 bits + RESTO DE OPCIONES TBI @@ -313,7 +250,7 @@ - + @@ -322,13 +259,19 @@ - - + + {{ result.name }}

{{ result.type }}

-

Unidades internas: {{ result.type !== 'client' ? result.children.length : 0}}

-

Clientes: {{ result.type !== 'client' ? result.clients.length : 0}}

+

+ Unidades internas: {{ result.type !== 'client' ? result.children.length : 0 }} +

+

+ Clientes: {{ result.type !== 'client' ? result.clients.length : 0 }} +

diff --git a/ogWebconsole/src/app/components/groups/groups.component.ts b/ogWebconsole/src/app/components/groups/groups.component.ts index a47fde3..da86861 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.ts +++ b/ogWebconsole/src/app/components/groups/groups.component.ts @@ -13,10 +13,8 @@ import {ToastrService} from "ngx-toastr"; import {TreeViewComponent} from "./tree-view/tree-view.component"; import {MatBottomSheet} from "@angular/material/bottom-sheet"; import {LegendComponent} from "./legend/legend.component"; -import { ClassroomViewComponent } from './classroom-view/classroom-view.component'; import { ClassroomViewDialogComponent } from './classroom-view/classroom-view-modal'; import {HttpClient} from "@angular/common/http"; -import {Observable} from "rxjs"; import {PageEvent} from "@angular/material/paginator"; import { SaveFiltersDialogComponent } from './save-filters-dialog/save-filters-dialog.component'; import { AcctionsModalComponent } from './acctions-modal/acctions-modal.component'; @@ -29,11 +27,11 @@ import { AcctionsModalComponent } from './acctions-modal/acctions-modal.componen export class GroupsComponent implements OnInit { organizationalUnits: UnidadOrganizativa[] = []; selectedUnidad: UnidadOrganizativa | null = null; - selectedDetail: any | null = null; // Nueva variable para el detalle del elemento seleccionado + selectedDetail: any | null = null; children: any[] = []; breadcrumb: string[] = []; - clientsData: any[] = []; // Nueva variable para almacenar los datos de clients - breadcrumbData: any[] = []; // Almacenar datos de breadcrumb para navegar + clientsData: any[] = []; + breadcrumbData: any[] = []; loading:boolean = false; loadingChildren:boolean = false; searchTerm: string = ''; @@ -53,6 +51,8 @@ export class GroupsComponent implements OnInit { page: number = 1; pageSizeOptions: number[] = [5, 10, 25, 100]; selectedElements: string[] = []; + isAllSelected: boolean = false; + constructor( private dataService: DataService, @@ -83,11 +83,11 @@ export class GroupsComponent implements OnInit { this.dataService.getOrganizationalUnits(this.searchTerm).subscribe( data => { this.organizationalUnits = data; - this.loading = false; // Desactivar el spinner después de obtener los datos + this.loading = false; }, error => { console.error('Error fetching unidades organizativas', error); - this.loading = false; // Desactivar el spinner en caso de error + this.loading = false; } ); } @@ -95,14 +95,14 @@ export class GroupsComponent implements OnInit { onSelectUnidad(unidad: UnidadOrganizativa): void { this.selectedUnidad = unidad; - this.selectedDetail = unidad; // Mostrar detalles de la unidad seleccionada + this.selectedDetail = unidad; this.breadcrumb = [unidad.name]; this.breadcrumbData = [unidad]; this.loadChildrenAndClients(unidad.id); } onSelectChild(child: any): void { - this.selectedDetail = child; // Mostrar detalles del niño seleccionado + this.selectedDetail = child; if (child.type !== 'client' && child.uuid && child.id) { this.breadcrumb.push(child.name || child.name); this.breadcrumbData.push(child); @@ -128,27 +128,27 @@ export class GroupsComponent implements OnInit { console.log('Children data:', childrenData); this.dataService.getClients(id).subscribe( clientsData => { - this.clientsData = clientsData; // Almacenar clientsData para pasarlo al componente hijo + this.clientsData = clientsData; const newChildren = [...childrenData, ...clientsData]; if (newChildren.length > 0) { this.children = newChildren; } else { - this.children = []; // Limpiar card2 cuando no hay elementos + this.children = []; } this.loadingChildren = false }, error => { console.error('Error fetching clients', error); - this.clientsData = []; // Limpiar clientsData en caso de error - this.children = []; // Limpiar card2 en caso de error + this.clientsData = []; + this.children = []; this.loadingChildren = false } ); }, error => { console.error('Error fetching children', error); - this.children = []; // Limpiar card2 en caso de error + this.children = []; this.loadingChildren = false } ); @@ -173,7 +173,6 @@ export class GroupsComponent implements OnInit { const dialogRef = this.dialog.open(CreateClientComponent, { data: { organizationalUnit }, width: '700px'}); - // Subscribirse al evento unitAdded del componente de creación después de cerrar el diálogo dialogRef.afterClosed().subscribe(() => { this.dataService.getOrganizationalUnits().subscribe( data => { @@ -380,6 +379,7 @@ export class GroupsComponent implements OnInit { } + onCheckboxChange(event: any, name: string) { if (event.checked) { this.selectedElements.push(name); @@ -389,9 +389,26 @@ export class GroupsComponent implements OnInit { this.selectedElements.splice(index, 1); } } + + this.isAllSelected = this.selectedElements.length === this.filteredResults.length; console.log(this.selectedElements); } + toggleSelectAll() { + this.isAllSelected = !this.isAllSelected; + + if (this.isAllSelected) { + this.selectedElements = this.filteredResults.map(result => result.name); + } else { + this.selectedElements = []; + } + console.log(this.selectedElements); + } + + isSelected(name: string): boolean { + return this.selectedElements.includes(name); + } + sendActions() { const dialogRef = this.dialog.open(AcctionsModalComponent, { data: { selectedElements: this.selectedElements }, width: '700px'});