From 639f55edb3d21375f8658b63cde71f79e37d9b41 Mon Sep 17 00:00:00 2001 From: Lucas Lara Date: Wed, 14 May 2025 10:07:19 +0200 Subject: [PATCH 1/3] refactor: update command filter to use name instead of id and remove date range handling --- .../client-task-logs.component.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/ogWebconsole/src/app/components/task-logs/client-task-logs/client-task-logs.component.ts b/ogWebconsole/src/app/components/task-logs/client-task-logs/client-task-logs.component.ts index 2db9e1b..897622d 100644 --- a/ogWebconsole/src/app/components/task-logs/client-task-logs/client-task-logs.component.ts +++ b/ogWebconsole/src/app/components/task-logs/client-task-logs/client-task-logs.component.ts @@ -35,7 +35,6 @@ export class ClientTaskLogsComponent implements OnInit { mode: ProgressBarMode = 'buffer'; progress = 0; bufferValue = 0; - dateRange = new FormControl(); filteredCommands2 = Object.keys(COMMAND_TYPES).map(key => ({ name: key, @@ -135,7 +134,9 @@ export class ClientTaskLogsComponent implements OnInit { } onOptionCommandSelected(selectedCommand: any): void { - this.filters['command'] = selectedCommand.id; + this.filters['command'] = selectedCommand.name; + console.log('Comando seleccionado:', selectedCommand); + console.log('Valor que se usará para el filtro:', selectedCommand.name); this.loadTraces(); } @@ -191,22 +192,13 @@ export class ClientTaskLogsComponent implements OnInit { .set('itemsPerPage', this.itemsPerPage.toString()); if (this.filters['command']) { - params = params.set('command.id', this.filters['command']); + params = params.set('command.name', this.filters['command']); } if (this.filters['status']) { params = params.set('status', this.filters['status']); } - const range = this.dateRange?.value; - if (range?.start && range?.end) { - const fromDate = this.datePipe.transform(range.start, 'yyyy-MM-dd'); - const toDate = this.datePipe.transform(range.end, 'yyyy-MM-dd'); - - params = params.set('executedAt[after]', fromDate!); - params = params.set('executedAt[before]', toDate!); - } - const url = `${this.baseUrl}/traces`; this.http.get(url, { params }).subscribe( @@ -240,7 +232,6 @@ export class ClientTaskLogsComponent implements OnInit { this.loading = true; clientSearchCommandInput.value = null; clientSearchStatusInput.value = null; - this.dateRange.reset(); this.filters = {}; this.loadTraces(); } From 4ff21afb5782251a3a946ec79c781b89116b11a2 Mon Sep 17 00:00:00 2001 From: Lucas Lara Date: Fri, 16 May 2025 12:59:03 +0200 Subject: [PATCH 2/3] refactor: conditionally update network settings based on excludeParentChanges flag --- .../manage-organizational-unit.component.ts | 59 +++++++++++-------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts b/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts index 1ae3a86..649b584 100644 --- a/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts +++ b/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts @@ -182,7 +182,8 @@ export class ManageOrganizationalUnitComponent implements OnInit { setOrganizationalUnitDefaults(unitId: string): void { const selectedUnit: any = this.parentUnitsWithPaths.find(unit => unit.id === unitId); - if (selectedUnit) { + const exclude = this.generalFormGroup.get('excludeParentChanges')?.value; + if (selectedUnit && !exclude) { this.networkSettingsFormGroup.patchValue({ repository: selectedUnit.repository || null, hardwareProfile: selectedUnit.hardwareProfile || null, @@ -229,14 +230,14 @@ export class ManageOrganizationalUnitComponent implements OnInit { const url = `${this.baseUrl}/pxe-templates?page=1&itemsPerPage=10000`; this.http.get(url).subscribe( - response => { + response => { this.pxeTemplates = response['hydra:member']; resolve(); - }, - error => { + }, + error => { console.error('Error fetching pxe templates:', error); reject(error); - } + } ); }); } @@ -331,35 +332,42 @@ export class ManageOrganizationalUnitComponent implements OnInit { this.http.get(url).subscribe( data => { + const exclude = data.excludeParentChanges; + this.generalFormGroup.patchValue({ name: data.name, parent: data.parent ? data.parent['@id'] : '', description: data.description, type: data.type, - excludeParentChanges: data.excludeParentChanges + excludeParentChanges: exclude }); + this.additionalInfoFormGroup.patchValue({ comments: data.comments }); - this.networkSettingsFormGroup.patchValue({ - proxy: data.networkSettings?.proxy, - dns: data.networkSettings?.dns, - netmask: data.networkSettings?.netmask, - router: data.networkSettings?.router, - ntp: data.networkSettings?.ntp, - netiface: data.networkSettings?.netiface, - p2pMode: data.networkSettings?.p2pMode, - p2pTime: data.networkSettings?.p2pTime, - mcastIp: data.networkSettings?.mcastIp, - mcastSpeed: data.networkSettings?.mcastSpeed, - mcastPort: data.networkSettings?.mcastPort, - mcastMode: data.networkSettings?.mcastMode, - menu: data.networkSettings?.menu ? data.networkSettings.menu['@id'] : null, - hardwareProfile: data.networkSettings?.hardwareProfile ? data.networkSettings.hardwareProfile['@id'] : null, - ogLive: data.networkSettings?.ogLive ? data.networkSettings.ogLive['@id'] : null, - repository: data.networkSettings?.repository ? data.networkSettings.repository['@id'] : null, - pxeTemplate: data.networkSettings?.pxeTemplate ? data.networkSettings.pxeTemplate['@id'] : null - }); + + if (!exclude) { + this.networkSettingsFormGroup.patchValue({ + proxy: data.networkSettings?.proxy, + dns: data.networkSettings?.dns, + netmask: data.networkSettings?.netmask, + router: data.networkSettings?.router, + ntp: data.networkSettings?.ntp, + netiface: data.networkSettings?.netiface, + p2pMode: data.networkSettings?.p2pMode, + p2pTime: data.networkSettings?.p2pTime, + mcastIp: data.networkSettings?.mcastIp, + mcastSpeed: data.networkSettings?.mcastSpeed, + mcastPort: data.networkSettings?.mcastPort, + mcastMode: data.networkSettings?.mcastMode, + menu: data.networkSettings?.menu ? data.networkSettings.menu['@id'] : null, + hardwareProfile: data.networkSettings?.hardwareProfile ? data.networkSettings.hardwareProfile['@id'] : null, + ogLive: data.networkSettings?.ogLive ? data.networkSettings.ogLive['@id'] : null, + repository: data.networkSettings?.repository ? data.networkSettings.repository['@id'] : null, + pxeTemplate: data.networkSettings?.pxeTemplate ? data.networkSettings.pxeTemplate['@id'] : null + }); + } + this.classroomInfoFormGroup.patchValue({ location: data.location, projector: data.projector, @@ -367,6 +375,7 @@ export class ManageOrganizationalUnitComponent implements OnInit { capacity: data.capacity, remoteCalendar: data.remoteCalendar ? data.remoteCalendar['@id'] : null }); + resolve(); }, From b0d255a7d1e2b737ca286930c9e48bd83dfbf792 Mon Sep 17 00:00:00 2001 From: Lucas Lara Date: Fri, 16 May 2025 13:46:15 +0200 Subject: [PATCH 3/3] refactor: prevent default setting of organizational unit when not in edit mode and streamline data loading logic --- .../manage-organizational-unit.component.ts | 248 +++++++++--------- 1 file changed, 124 insertions(+), 124 deletions(-) diff --git a/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts b/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts index 649b584..792db32 100644 --- a/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts +++ b/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts @@ -177,7 +177,9 @@ export class ManageOrganizationalUnitComponent implements OnInit { } onParentChange(event: any): void { - this.setOrganizationalUnitDefaults(event.value); + if (!this.isEditMode) { + this.setOrganizationalUnitDefaults(event.value); + } } setOrganizationalUnitDefaults(unitId: string): void { @@ -205,6 +207,127 @@ export class ManageOrganizationalUnitComponent implements OnInit { } } + loadData(uuid: string): Promise { + return new Promise((resolve, reject) => { + const url = `${this.baseUrl}/organizational-units/${uuid}`; + + this.http.get(url).subscribe( + data => { + const exclude = data.excludeParentChanges; + + this.generalFormGroup.patchValue({ + name: data.name, + parent: data.parent ? data.parent['@id'] : '', + description: data.description, + type: data.type, + excludeParentChanges: exclude + }); + + this.additionalInfoFormGroup.patchValue({ + comments: data.comments + }); + + this.networkSettingsFormGroup.patchValue({ + proxy: data.networkSettings?.proxy, + dns: data.networkSettings?.dns, + netmask: data.networkSettings?.netmask, + router: data.networkSettings?.router, + ntp: data.networkSettings?.ntp, + netiface: data.networkSettings?.netiface, + p2pMode: data.networkSettings?.p2pMode, + p2pTime: data.networkSettings?.p2pTime, + mcastIp: data.networkSettings?.mcastIp, + mcastSpeed: data.networkSettings?.mcastSpeed, + mcastPort: data.networkSettings?.mcastPort, + mcastMode: data.networkSettings?.mcastMode, + menu: data.networkSettings?.menu ? data.networkSettings.menu['@id'] : null, + hardwareProfile: data.networkSettings?.hardwareProfile ? data.networkSettings.hardwareProfile['@id'] : null, + ogLive: data.networkSettings?.ogLive ? data.networkSettings.ogLive['@id'] : null, + repository: data.networkSettings?.repository ? data.networkSettings.repository['@id'] : null, + pxeTemplate: data.networkSettings?.pxeTemplate ? data.networkSettings.pxeTemplate['@id'] : null + }); + + this.classroomInfoFormGroup.patchValue({ + location: data.location, + projector: data.projector, + board: data.board, + capacity: data.capacity, + remoteCalendar: data.remoteCalendar ? data.remoteCalendar['@id'] : null + }); + + resolve(); + }, + + error => { + console.error('Error fetching data for edit:', error); + this.toastService.error('Error fetching data'); + reject(error); + this.onNoClick(); + } + ); + }); + } + + onSubmit() { + if (this.generalFormGroup.valid && this.additionalInfoFormGroup.valid && this.networkSettingsFormGroup.valid) { + const parentValue = this.generalFormGroup.value.parent; + const formData = { + name: this.generalFormGroup.value.name, + excludeParentChanges: this.generalFormGroup.value.excludeParentChanges, + parent: parentValue || null, + description: this.generalFormGroup.value.description, + comments: this.additionalInfoFormGroup.value.comments, + remoteCalendar: this.generalFormGroup.value.remoteCalendar, + type: this.generalFormGroup.value.type, + networkSettings: this.networkSettingsFormGroup.value, + location: this.classroomInfoFormGroup.value.location, + projector: this.classroomInfoFormGroup.value.projector, + board: this.classroomInfoFormGroup.value.board, + capacity: this.classroomInfoFormGroup.value.capacity, + }; + + if (this.isEditMode) { + const putUrl = `${this.baseUrl}/organizational-units/${this.data.uuid}`; + const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); + + this.http.put(putUrl, formData, { headers }).subscribe( + response => { + this.unitAdded.emit(); + this.dialogRef.close({ success: true }); + this.toastService.success('Editado exitosamente', 'Éxito'); + }, + error => { + console.error('Error al realizar PUT:', error); + const errorMessages = error.error['hydra:description'].split('\n'); + errorMessages.forEach((message: string) => { + const cleanedMessage = message.replace(/networkSettings\.(\w+):/, 'Error $1:'); + this.toastService.error(cleanedMessage); + }); + } + ); + } else { + const postUrl = `${this.baseUrl}/organizational-units`; + const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); + + this.http.post(postUrl, formData, { headers }).subscribe( + response => { + this.unitAdded.emit(response); + this.dialogRef.close({ success: true }); + this.toastService.success('Creado exitosamente', 'Éxito'); + }, + error => { + console.error('Error al realizar POST:', error); + const errorMessages = error.error['hydra:description'].split('\n'); + errorMessages.forEach((message: string) => { + const cleanedMessage = message.replace(/networkSettings\.(\w+):/, 'Error $1:'); + this.toastService.error(cleanedMessage); + }); + } + ); + } + } + } + getSelectedParentName(): string | undefined { const parentId = this.generalFormGroup.get('parent')?.value; return this.parentUnitsWithPaths.find(unit => unit.id === parentId)?.name; @@ -326,129 +449,6 @@ export class ManageOrganizationalUnitComponent implements OnInit { this.networkSettingsFormGroup.value.pxeTemplate = event.value; } - loadData(uuid: string): Promise { - return new Promise((resolve, reject) => { - const url = `${this.baseUrl}/organizational-units/${uuid}`; - - this.http.get(url).subscribe( - data => { - const exclude = data.excludeParentChanges; - - this.generalFormGroup.patchValue({ - name: data.name, - parent: data.parent ? data.parent['@id'] : '', - description: data.description, - type: data.type, - excludeParentChanges: exclude - }); - - this.additionalInfoFormGroup.patchValue({ - comments: data.comments - }); - - if (!exclude) { - this.networkSettingsFormGroup.patchValue({ - proxy: data.networkSettings?.proxy, - dns: data.networkSettings?.dns, - netmask: data.networkSettings?.netmask, - router: data.networkSettings?.router, - ntp: data.networkSettings?.ntp, - netiface: data.networkSettings?.netiface, - p2pMode: data.networkSettings?.p2pMode, - p2pTime: data.networkSettings?.p2pTime, - mcastIp: data.networkSettings?.mcastIp, - mcastSpeed: data.networkSettings?.mcastSpeed, - mcastPort: data.networkSettings?.mcastPort, - mcastMode: data.networkSettings?.mcastMode, - menu: data.networkSettings?.menu ? data.networkSettings.menu['@id'] : null, - hardwareProfile: data.networkSettings?.hardwareProfile ? data.networkSettings.hardwareProfile['@id'] : null, - ogLive: data.networkSettings?.ogLive ? data.networkSettings.ogLive['@id'] : null, - repository: data.networkSettings?.repository ? data.networkSettings.repository['@id'] : null, - pxeTemplate: data.networkSettings?.pxeTemplate ? data.networkSettings.pxeTemplate['@id'] : null - }); - } - - this.classroomInfoFormGroup.patchValue({ - location: data.location, - projector: data.projector, - board: data.board, - capacity: data.capacity, - remoteCalendar: data.remoteCalendar ? data.remoteCalendar['@id'] : null - }); - - resolve(); - }, - - error => { - console.error('Error fetching data for edit:', error); - this.toastService.error('Error fetching data'); - reject(error); - this.onNoClick(); - } - ); - }); - } - - onSubmit() { - if (this.generalFormGroup.valid && this.additionalInfoFormGroup.valid && this.networkSettingsFormGroup.valid) { - const parentValue = this.generalFormGroup.value.parent; - const formData = { - name: this.generalFormGroup.value.name, - excludeParentChanges: this.generalFormGroup.value.excludeParentChanges, - parent: parentValue || null, - description: this.generalFormGroup.value.description, - comments: this.additionalInfoFormGroup.value.comments, - remoteCalendar: this.generalFormGroup.value.remoteCalendar, - type: this.generalFormGroup.value.type, - networkSettings: this.networkSettingsFormGroup.value, - location: this.classroomInfoFormGroup.value.location, - projector: this.classroomInfoFormGroup.value.projector, - board: this.classroomInfoFormGroup.value.board, - capacity: this.classroomInfoFormGroup.value.capacity, - }; - - if (this.isEditMode) { - const putUrl = `${this.baseUrl}/organizational-units/${this.data.uuid}`; - const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); - - this.http.put(putUrl, formData, { headers }).subscribe( - response => { - this.unitAdded.emit(); - this.dialogRef.close({ success: true }); - this.toastService.success('Editado exitosamente', 'Éxito'); - }, - error => { - console.error('Error al realizar PUT:', error); - const errorMessages = error.error['hydra:description'].split('\n'); - errorMessages.forEach((message: string) => { - const cleanedMessage = message.replace(/networkSettings\.(\w+):/, 'Error $1:'); - this.toastService.error(cleanedMessage); - }); - } - ); - } else { - const postUrl = `${this.baseUrl}/organizational-units`; - const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); - - this.http.post(postUrl, formData, { headers }).subscribe( - response => { - this.unitAdded.emit(response); - this.dialogRef.close({ success: true }); - this.toastService.success('Creado exitosamente', 'Éxito'); - }, - error => { - console.error('Error al realizar POST:', error); - const errorMessages = error.error['hydra:description'].split('\n'); - errorMessages.forEach((message: string) => { - const cleanedMessage = message.replace(/networkSettings\.(\w+):/, 'Error $1:'); - this.toastService.error(cleanedMessage); - }); - } - ); - } - } - } - onNoClick(): void { this.dialogRef.close({ success: false }); }