Create UO playload fix

pull/4/head
Alvaro Puente Mella 2024-07-05 12:41:31 +02:00
parent 1a9a455c1e
commit 27063fc1fb
2 changed files with 28 additions and 32 deletions

View File

@ -96,10 +96,7 @@ constructor(private dataService: DataService, public dialog: MatDialog) {}
addOU(): void {
const dialogRef = this.dialog.open(CreateOrganizationalUnitComponent);
// Subscribirse al evento unitAdded del componente de creación después de cerrar el diálogo
dialogRef.afterClosed().subscribe(() => {
// Aquí puedes actualizar las cards o hacer cualquier otra acción necesaria después de añadir una unidad organizativa
this.dataService.getUnidadesOrganizativas().subscribe(
data => this.unidadesOrganizativas = data,
error => console.error('Error fetching unidades organizativas', error)
@ -112,7 +109,6 @@ constructor(private dataService: DataService, public dialog: MatDialog) {}
// Subscribirse al evento unitAdded del componente de creación después de cerrar el diálogo
dialogRef.afterClosed().subscribe(() => {
// Aquí puedes actualizar las cards o hacer cualquier otra acción necesaria después de añadir una unidad organizativa
this.dataService.getUnidadesOrganizativas().subscribe(
data => this.unidadesOrganizativas = data,
error => console.error('Error fetching unidades organizativas', error)

View File

@ -75,42 +75,42 @@ export class CreateOrganizationalUnitComponent implements OnInit {
);
}
private cleanFormValues(formGroup: FormGroup): any {
const cleanedValues: any = {};
Object.keys(formGroup.controls).forEach(key => {
const value = formGroup.get(key)?.value;
if (value !== '' && value !== 0) {
cleanedValues[key] = value;
}
});
return cleanedValues;
}
onSubmit() {
if (this.generalFormGroup.valid && this.additionalInfoFormGroup.valid && this.networkSettingsFormGroup.valid && (this.generalFormGroup.value.type !== 'classroom' || this.classroomInfoFormGroup.valid)) {
const parentValue = this.generalFormGroup.value.parent;
const generalFormValues = this.cleanFormValues(this.generalFormGroup);
const additionalInfoFormValues = this.cleanFormValues(this.additionalInfoFormGroup);
const networkSettingsFormValues = this.cleanFormValues(this.networkSettingsFormGroup);
const classroomInfoFormValues = this.cleanFormValues(this.classroomInfoFormGroup);
const formData: any = {
name: this.generalFormGroup.value.name,
parent: parentValue || null,
description: this.generalFormGroup.value.description,
comments: this.additionalInfoFormGroup.value.comments,
type: this.generalFormGroup.value.type,
networkSettings: {
proxy: this.networkSettingsFormGroup.value.proxy,
dns: this.networkSettingsFormGroup.value.dns,
netmask: this.networkSettingsFormGroup.value.netmask,
router: this.networkSettingsFormGroup.value.router,
ntp: this.networkSettingsFormGroup.value.ntp,
p2pMode: this.networkSettingsFormGroup.value.p2pMode,
p2pTime: this.networkSettingsFormGroup.value.p2pTime,
mcastIp: this.networkSettingsFormGroup.value.mcastIp,
mcastSpeed: this.networkSettingsFormGroup.value.mcastSpeed,
mcastPort: this.networkSettingsFormGroup.value.mcastPort,
mcastMode: this.networkSettingsFormGroup.value.mcastMode,
menu: this.networkSettingsFormGroup.value.menu,
hardwareProfile: this.networkSettingsFormGroup.value.hardwareProfile,
validation: this.networkSettingsFormGroup.value.validation
}
...generalFormValues,
comments: additionalInfoFormValues.comments,
networkSettings: { ...networkSettingsFormValues }
};
if (this.generalFormGroup.value.type === 'classroom') {
formData.location = this.classroomInfoFormGroup.value.location;
formData.projector = this.classroomInfoFormGroup.value.projector;
formData.board = this.classroomInfoFormGroup.value.board;
formData.capacity = this.classroomInfoFormGroup.value.capacity;
formData.photo = this.classroomInfoFormGroup.value.photo;
formData.location = classroomInfoFormValues.location;
formData.projector = classroomInfoFormValues.projector;
formData.board = classroomInfoFormValues.board;
if (classroomInfoFormValues.capacity !== undefined) {
formData.capacity = classroomInfoFormValues.capacity;
}
if (classroomInfoFormValues.photo !== undefined) {
formData.photo = classroomInfoFormValues.photo;
}
}
console.log('POST data:', formData);
const postUrl = 'http://127.0.0.1:8080/organizational-units';
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });