refs #2939. Propagate network settings
testing/ogGui-multibranch/pipeline/head There was a failure building this commit
Details
testing/ogGui-multibranch/pipeline/head There was a failure building this commit
Details
parent
b2b3dc47af
commit
2012e87fb9
|
|
@ -406,7 +406,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
|||
const selectedClientsBeforeEdit = this.selection.selected.map(client => client.uuid);
|
||||
this.fetchClientsForNode(node, selectedClientsBeforeEdit);
|
||||
|
||||
if (node.type === NodeType.Classroom || node.type === NodeType.ClassroomsGroup) {
|
||||
if (node.type === NodeType.Classroom || node.type === NodeType.ClientsGroup) {
|
||||
this.getStatusForAllClientsInNode(node);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Component, EventEmitter, Inject, OnInit, Output } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
|
||||
import { DataService } from "../../../services/data.service";
|
||||
import { ToastrService } from "ngx-toastr";
|
||||
import { ConfigService } from '@services/config.service';
|
||||
import { DeleteModalComponent } from '../../../../../shared/delete_modal/delete-modal/delete-modal.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-manage-organizational-unit',
|
||||
|
|
@ -59,6 +60,7 @@ export class ManageOrganizationalUnitComponent implements OnInit {
|
|||
private dataService: DataService,
|
||||
private configService: ConfigService,
|
||||
private toastService: ToastrService,
|
||||
private dialog: MatDialog,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any
|
||||
) {
|
||||
this.isEditMode = !!data?.uuid;
|
||||
|
|
@ -270,71 +272,113 @@ export class ManageOrganizationalUnitComponent implements OnInit {
|
|||
|
||||
onSubmit() {
|
||||
if (this.generalFormGroup.valid && this.additionalInfoFormGroup.valid && this.networkSettingsFormGroup.valid) {
|
||||
const parentValue = this.generalFormGroup.value.parent;
|
||||
|
||||
// Preparar networkSettings con lógica condicional para p2pTime
|
||||
const networkSettings = { ...this.networkSettingsFormGroup.value };
|
||||
if (networkSettings.p2pMode !== 'seeder') {
|
||||
networkSettings.p2pTime = null;
|
||||
}
|
||||
|
||||
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: networkSettings,
|
||||
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' });
|
||||
const confirmRef = this.dialog.open(DeleteModalComponent, {
|
||||
width: '400px',
|
||||
data: {
|
||||
title: 'Propagar parámetros',
|
||||
message: '¿Desea propagar los parámetros de red (ogLive, repositorio, menú, plantilla PXE, perfil hardware) a todos los clientes de esta unidad organizativa?',
|
||||
confirmText: 'Sí, propagar',
|
||||
cancelText: 'No, solo guardar',
|
||||
}
|
||||
});
|
||||
|
||||
this.http.put<any>(putUrl, formData, { headers }).subscribe(
|
||||
response => {
|
||||
confirmRef.afterClosed().subscribe((propagate: boolean) => {
|
||||
this.submitForm(propagate === true);
|
||||
});
|
||||
} else {
|
||||
this.submitForm(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private submitForm(propagate: boolean) {
|
||||
const parentValue = this.generalFormGroup.value.parent;
|
||||
|
||||
const networkSettings = { ...this.networkSettingsFormGroup.value };
|
||||
if (networkSettings.p2pMode !== 'seeder') {
|
||||
networkSettings.p2pTime = null;
|
||||
}
|
||||
|
||||
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: networkSettings,
|
||||
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<any>(putUrl, formData, { headers }).subscribe(
|
||||
response => {
|
||||
if (propagate) {
|
||||
this.propagateNetworkSettings();
|
||||
} else {
|
||||
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' });
|
||||
},
|
||||
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<any>(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);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
this.http.post<any>(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);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private propagateNetworkSettings() {
|
||||
const propagateUrl = `${this.baseUrl}/organizational-units/${this.data.uuid}/propagate-network-settings`;
|
||||
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
|
||||
|
||||
this.http.post<any>(propagateUrl, {}, { headers }).subscribe(
|
||||
() => {
|
||||
this.unitAdded.emit();
|
||||
this.dialogRef.close({ success: true });
|
||||
this.toastService.success('Editado y parámetros propagados exitosamente', 'Éxito');
|
||||
},
|
||||
error => {
|
||||
console.error('Error al propagar parámetros:', error);
|
||||
this.unitAdded.emit();
|
||||
this.dialogRef.close({ success: true });
|
||||
this.toastService.warning('Guardado, pero hubo un error al propagar los parámetros', 'Aviso');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getSelectedParentName(): string | undefined {
|
||||
const parentId = this.generalFormGroup.get('parent')?.value;
|
||||
return this.parentUnitsWithPaths.find(unit => unit.id === parentId)?.name;
|
||||
|
|
|
|||
Loading…
Reference in New Issue