Create UO playload fix
parent
1a9a455c1e
commit
27063fc1fb
|
@ -96,10 +96,7 @@ constructor(private dataService: DataService, public dialog: MatDialog) {}
|
||||||
|
|
||||||
addOU(): void {
|
addOU(): void {
|
||||||
const dialogRef = this.dialog.open(CreateOrganizationalUnitComponent);
|
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(() => {
|
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(
|
this.dataService.getUnidadesOrganizativas().subscribe(
|
||||||
data => this.unidadesOrganizativas = data,
|
data => this.unidadesOrganizativas = data,
|
||||||
error => console.error('Error fetching unidades organizativas', error)
|
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
|
// Subscribirse al evento unitAdded del componente de creación después de cerrar el diálogo
|
||||||
dialogRef.afterClosed().subscribe(() => {
|
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(
|
this.dataService.getUnidadesOrganizativas().subscribe(
|
||||||
data => this.unidadesOrganizativas = data,
|
data => this.unidadesOrganizativas = data,
|
||||||
error => console.error('Error fetching unidades organizativas', error)
|
error => console.error('Error fetching unidades organizativas', error)
|
||||||
|
|
|
@ -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() {
|
onSubmit() {
|
||||||
if (this.generalFormGroup.valid && this.additionalInfoFormGroup.valid && this.networkSettingsFormGroup.valid && (this.generalFormGroup.value.type !== 'classroom' || this.classroomInfoFormGroup.valid)) {
|
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 = {
|
const formData: any = {
|
||||||
name: this.generalFormGroup.value.name,
|
...generalFormValues,
|
||||||
parent: parentValue || null,
|
comments: additionalInfoFormValues.comments,
|
||||||
description: this.generalFormGroup.value.description,
|
networkSettings: { ...networkSettingsFormValues }
|
||||||
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
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.generalFormGroup.value.type === 'classroom') {
|
if (this.generalFormGroup.value.type === 'classroom') {
|
||||||
formData.location = this.classroomInfoFormGroup.value.location;
|
formData.location = classroomInfoFormValues.location;
|
||||||
formData.projector = this.classroomInfoFormGroup.value.projector;
|
formData.projector = classroomInfoFormValues.projector;
|
||||||
formData.board = this.classroomInfoFormGroup.value.board;
|
formData.board = classroomInfoFormValues.board;
|
||||||
formData.capacity = this.classroomInfoFormGroup.value.capacity;
|
if (classroomInfoFormValues.capacity !== undefined) {
|
||||||
formData.photo = this.classroomInfoFormGroup.value.photo;
|
formData.capacity = classroomInfoFormValues.capacity;
|
||||||
|
}
|
||||||
|
if (classroomInfoFormValues.photo !== undefined) {
|
||||||
|
formData.photo = classroomInfoFormValues.photo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('POST data:', formData);
|
console.log('POST data:', formData);
|
||||||
const postUrl = 'http://127.0.0.1:8080/organizational-units';
|
const postUrl = 'http://127.0.0.1:8080/organizational-units';
|
||||||
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
|
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
|
||||||
|
|
Loading…
Reference in New Issue