refs #732 Added organizational unit calendar reference

oggui/calendar
Alvaro Puente Mella 2024-09-30 16:37:03 +02:00
parent 390f454ac2
commit a7da86c804
5 changed files with 84 additions and 64 deletions

View File

@ -44,7 +44,7 @@
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</mat-tab>
<mat-tab label="Acciones">
<!-- <mat-tab label="Acciones">
<div class="button-column">
<button mat-flat-button color="primary" class="button-action button-encender" i18n="@@power-on-button">Encender</button>
<button mat-flat-button color="accent" class="button-action button-apagar" i18n="@@power-off-button">Apagar</button>
@ -53,7 +53,7 @@
<button mat-flat-button class="button-action button-otros-2" i18n="@@other-actions-2">Otras acciones 2</button>
<button mat-flat-button class="button-action button-otros-3" i18n="@@other-actions-3">Otras acciones 3</button>
</div>
</mat-tab>
</mat-tab> -->
<mat-tab label="Particiones">
</mat-tab>
</mat-tab-group>

View File

@ -124,7 +124,6 @@ export class GroupsComponent implements OnInit {
this.loadingChildren = true
this.dataService.getChildren(id).subscribe(
childrenData => {
console.log('Children data:', childrenData);
this.dataService.getClients(id).subscribe(
clientsData => {
this.clientsData = clientsData;

View File

@ -49,6 +49,17 @@
<mat-label i18n="@@capacityLabel">Aforo</mat-label>
<input matInput formControlName="capacity" type="number">
</mat-form-field>
<!-- Campo nuevo para seleccionar el calendario asociado -->
<mat-form-field appearance="fill">
<mat-label>Calendario Asociado</mat-label>
<mat-select (selectionChange)="onCalendarChange($event)">
<mat-option *ngFor="let calendar of calendars" [value]="calendar.uuid">
{{ calendar.name }}
</mat-option>
</mat-select>
</mat-form-field>
<div>
<button mat-button matStepperPrevious i18n="@@backButton">Atrás</button>
<button mat-button matStepperNext i18n="@@nextButton">Siguiente</button>
@ -107,9 +118,7 @@
<mat-form-field class="form-field">
<mat-label i18n="@@p2pModeLabel">Modo P2P</mat-label>
<mat-select formControlName="p2pMode">
<mat-option
*ngFor="let option of p2pModeOptions"
[value]="option.value">
<mat-option *ngFor="let option of p2pModeOptions" [value]="option.value">
{{ option.name }}
</mat-option>
</mat-select>
@ -133,9 +142,7 @@
<mat-form-field class="form-field">
<mat-label i18n="@@mcastModeLabel">Modo Multicast</mat-label>
<mat-select formControlName="mcastMode">
<mat-option
*ngFor="let option of multicastModeOptions"
[value]="option.value">
<mat-option *ngFor="let option of multicastModeOptions" [value]="option.value">
{{ option.name }}
</mat-option>
</mat-select>
@ -147,7 +154,7 @@
<mat-form-field class="form-field">
<mat-label i18n="@@hardwareProfileLabel">Perfil de Hardware</mat-label>
<mat-select formControlName="hardwareProfile">
<mat-option *ngFor="let unit of hardwareProfiles" [value]="unit['@id']">{{ unit.description }} </mat-option>
<mat-option *ngFor="let unit of hardwareProfiles" [value]="unit['@id']">{{ unit.description }}</mat-option>
</mat-select>
<mat-error i18n="@@urlFormatError">Formato de URL inválido.</mat-error>
</mat-form-field>

View File

@ -1,9 +1,9 @@
import {Component, OnInit, Output, EventEmitter, Inject} from '@angular/core';
import { Component, OnInit, Output, EventEmitter, Inject } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {ToastrService} from "ngx-toastr";
import {DataService} from "../../data.service";
import { ToastrService } from 'ngx-toastr';
import { DataService } from '../../data.service';
@Component({
selector: 'app-create-organizational-unit',
@ -24,17 +24,21 @@ export class CreateOrganizationalUnitComponent implements OnInit {
'classroom': 'Aula',
'clients-group': 'Grupo de clientes'
};
protected p2pModeOptions = [
{ name: 'Leecher', value: 'p2p-mode-leecher' },
{ name: 'Peer', value: 'p2p-mode-peer' },
{ name: 'Seeder', value: 'p2p-mode-seeder' },
];
multicastModeOptions: { name: string, value: string }[] = [
{ name: 'Modo 1', value: 'mode1' },
{ name: 'Modo 2', value: 'mode2' },
{ name: 'Modo 3', value: 'mode3' },
];
parentUnits: any[] = [];
hardwareProfiles: any[] = [];
protected p2pModeOptions = [
{"name": 'Leecher', "value": "p2p-mode-leecher"},
{"name": 'Peer', "value": "p2p-mode-peer"},
{"name": 'Seeder', "value": "p2p-mode-seeder"},
];
protected multicastModeOptions = [
{"name": 'Half duplex', "value": "half-duplex"},
{"name": 'Full duplex', "value": "full-duplex"},
];
calendars: any[] = [];
selectedCalendarUuid: string | null = null;
@Output() unitAdded = new EventEmitter();
constructor(
@ -70,7 +74,8 @@ export class CreateOrganizationalUnitComponent implements OnInit {
mcastMode: [''],
menu: [''],
hardwareProfile: [''],
validation: [false]
validation: [false],
remoteCalendar: ['']
});
this.classroomInfoFormGroup = this._formBuilder.group({
location: [''],
@ -83,28 +88,31 @@ export class CreateOrganizationalUnitComponent implements OnInit {
ngOnInit() {
this.loadParentUnits();
this.loadHardwareProfiles();
this.loadCalendars();
}
loadParentUnits() {
const url = `${this.baseUrl}/organizational-units?page=1&itemsPerPage=1000`;
this.http.get<any>(url).subscribe(
response => {
this.parentUnits = response['hydra:member'];
},
error => {
console.error('Error fetching parent units:', error);
}
response => this.parentUnits = response['hydra:member'],
error => console.error('Error fetching parent units:', error)
);
}
loadHardwareProfiles(): void {
this.dataService.getHardwareProfiles().subscribe(
(data: any[]) => {
this.hardwareProfiles = data;
},
(error: any) => {
console.error('Error fetching hardware profiles', error);
(data: any[]) => this.hardwareProfiles = data,
error => console.error('Error fetching hardware profiles', error)
);
}
loadCalendars() {
const apiUrl = `${this.baseUrl}/remote-calendars?page=1&itemsPerPage=30`;
this.http.get<any>(apiUrl).subscribe(
response => this.calendars = response['hydra:member'],
error => {
console.error('Error loading calendars', error);
this.openSnackBar(true, 'Error loading calendars');
}
);
}
@ -121,26 +129,13 @@ export class CreateOrganizationalUnitComponent implements OnInit {
}
onSubmit() {
if (this.generalFormGroup.valid && this.additionalInfoFormGroup.valid && this.networkSettingsFormGroup.valid && (this.generalFormGroup.value.type !== 'classroom' || this.classroomInfoFormGroup.valid)) {
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 = {
...generalFormValues,
...classroomInfoFormValues,
comments: additionalInfoFormValues.comments,
networkSettings: { ...networkSettingsFormValues }
};
console.log('POST data:', formData);
if (this.isFormValid()) {
const formData: any = this.buildPayload();
const postUrl = `${this.baseUrl}/organizational-units`;
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
this.http.post<any>(postUrl, formData, { headers }).subscribe(
response => {
console.log('POST successful:', response);
this.unitAdded.emit();
this.dialogRef.close();
this.openSnackBar(false, 'Cliente creado exitosamente');
@ -153,14 +148,43 @@ export class CreateOrganizationalUnitComponent implements OnInit {
}
}
private isFormValid(): boolean {
return this.generalFormGroup.valid &&
this.additionalInfoFormGroup.valid &&
this.networkSettingsFormGroup.valid &&
(this.generalFormGroup.value.type !== 'classroom' || this.classroomInfoFormGroup.valid);
}
private buildPayload(): any {
const generalFormValues = this.cleanFormValues(this.generalFormGroup);
const additionalInfoFormValues = this.cleanFormValues(this.additionalInfoFormGroup);
const networkSettingsFormValues = this.cleanFormValues(this.networkSettingsFormGroup);
const classroomInfoFormValues = this.cleanFormValues(this.classroomInfoFormGroup);
return {
...generalFormValues,
...classroomInfoFormValues,
comments: additionalInfoFormValues.comments,
networkSettings: { ...networkSettingsFormValues },
remoteCalendar: this.selectedCalendarUuid ? `/remote-calendars/${this.selectedCalendarUuid}` : null,
menu: networkSettingsFormValues.menu || null,
hardwareProfile: networkSettingsFormValues.hardwareProfile || null,
};
}
onCalendarChange(event: any) {
this.selectedCalendarUuid = event.value;
}
onNoClick(): void {
this.dialogRef.close();
}
openSnackBar(isError: boolean, message: string) {
if (isError) {
this.toastService.error(' Error al crear el cliente: ' + message, 'Error');
} else
this.toastService.error('Error al crear el cliente: ' + message, 'Error');
} else {
this.toastService.success('Cliente creado exitosamente', 'Éxito');
}
}
}

View File

@ -29,15 +29,5 @@
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</mat-tab>
<mat-tab disabled label="Acciones" i18n-label="@@actionsTab">
<div class="button-column">
<button mat-flat-button color="primary" class="button-encender" i18n>Encender</button>
<button mat-flat-button color="accent" class="button-apagar" i18n>Apagar</button>
<button mat-flat-button color="warn" class="button-resetear" i18n>Resetear</button>
<button mat-flat-button class="button-otros-1" i18n>Otras acciones 1</button>
<button mat-flat-button class="button-otros-2" i18n>Otras acciones 2</button>
<button mat-flat-button class="button-otros-3" i18n>Otras acciones 3</button>
</div>
</mat-tab>
</mat-tab-group>
</div>