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> <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table> </table>
</mat-tab> </mat-tab>
<mat-tab label="Acciones"> <!-- <mat-tab label="Acciones">
<div class="button-column"> <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="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> <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-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> <button mat-flat-button class="button-action button-otros-3" i18n="@@other-actions-3">Otras acciones 3</button>
</div> </div>
</mat-tab> </mat-tab> -->
<mat-tab label="Particiones"> <mat-tab label="Particiones">
</mat-tab> </mat-tab>
</mat-tab-group> </mat-tab-group>

View File

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

View File

@ -49,6 +49,17 @@
<mat-label i18n="@@capacityLabel">Aforo</mat-label> <mat-label i18n="@@capacityLabel">Aforo</mat-label>
<input matInput formControlName="capacity" type="number"> <input matInput formControlName="capacity" type="number">
</mat-form-field> </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> <div>
<button mat-button matStepperPrevious i18n="@@backButton">Atrás</button> <button mat-button matStepperPrevious i18n="@@backButton">Atrás</button>
<button mat-button matStepperNext i18n="@@nextButton">Siguiente</button> <button mat-button matStepperNext i18n="@@nextButton">Siguiente</button>
@ -107,9 +118,7 @@
<mat-form-field class="form-field"> <mat-form-field class="form-field">
<mat-label i18n="@@p2pModeLabel">Modo P2P</mat-label> <mat-label i18n="@@p2pModeLabel">Modo P2P</mat-label>
<mat-select formControlName="p2pMode"> <mat-select formControlName="p2pMode">
<mat-option <mat-option *ngFor="let option of p2pModeOptions" [value]="option.value">
*ngFor="let option of p2pModeOptions"
[value]="option.value">
{{ option.name }} {{ option.name }}
</mat-option> </mat-option>
</mat-select> </mat-select>
@ -133,9 +142,7 @@
<mat-form-field class="form-field"> <mat-form-field class="form-field">
<mat-label i18n="@@mcastModeLabel">Modo Multicast</mat-label> <mat-label i18n="@@mcastModeLabel">Modo Multicast</mat-label>
<mat-select formControlName="mcastMode"> <mat-select formControlName="mcastMode">
<mat-option <mat-option *ngFor="let option of multicastModeOptions" [value]="option.value">
*ngFor="let option of multicastModeOptions"
[value]="option.value">
{{ option.name }} {{ option.name }}
</mat-option> </mat-option>
</mat-select> </mat-select>
@ -147,7 +154,7 @@
<mat-form-field class="form-field"> <mat-form-field class="form-field">
<mat-label i18n="@@hardwareProfileLabel">Perfil de Hardware</mat-label> <mat-label i18n="@@hardwareProfileLabel">Perfil de Hardware</mat-label>
<mat-select formControlName="hardwareProfile"> <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-select>
<mat-error i18n="@@urlFormatError">Formato de URL inválido.</mat-error> <mat-error i18n="@@urlFormatError">Formato de URL inválido.</mat-error>
</mat-form-field> </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 { 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 { HttpClient, HttpHeaders } from '@angular/common/http';
import {ToastrService} from "ngx-toastr"; import { ToastrService } from 'ngx-toastr';
import {DataService} from "../../data.service"; import { DataService } from '../../data.service';
@Component({ @Component({
selector: 'app-create-organizational-unit', selector: 'app-create-organizational-unit',
@ -24,17 +24,21 @@ export class CreateOrganizationalUnitComponent implements OnInit {
'classroom': 'Aula', 'classroom': 'Aula',
'clients-group': 'Grupo de clientes' '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[] = []; parentUnits: any[] = [];
hardwareProfiles: any[] = []; hardwareProfiles: any[] = [];
protected p2pModeOptions = [ calendars: any[] = [];
{"name": 'Leecher', "value": "p2p-mode-leecher"}, selectedCalendarUuid: string | null = null;
{"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"},
];
@Output() unitAdded = new EventEmitter(); @Output() unitAdded = new EventEmitter();
constructor( constructor(
@ -70,7 +74,8 @@ export class CreateOrganizationalUnitComponent implements OnInit {
mcastMode: [''], mcastMode: [''],
menu: [''], menu: [''],
hardwareProfile: [''], hardwareProfile: [''],
validation: [false] validation: [false],
remoteCalendar: ['']
}); });
this.classroomInfoFormGroup = this._formBuilder.group({ this.classroomInfoFormGroup = this._formBuilder.group({
location: [''], location: [''],
@ -83,28 +88,31 @@ export class CreateOrganizationalUnitComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.loadParentUnits(); this.loadParentUnits();
this.loadHardwareProfiles(); this.loadHardwareProfiles();
this.loadCalendars();
} }
loadParentUnits() { loadParentUnits() {
const url = `${this.baseUrl}/organizational-units?page=1&itemsPerPage=1000`; const url = `${this.baseUrl}/organizational-units?page=1&itemsPerPage=1000`;
this.http.get<any>(url).subscribe( this.http.get<any>(url).subscribe(
response => { response => this.parentUnits = response['hydra:member'],
this.parentUnits = response['hydra:member']; error => console.error('Error fetching parent units:', error)
},
error => {
console.error('Error fetching parent units:', error);
}
); );
} }
loadHardwareProfiles(): void { loadHardwareProfiles(): void {
this.dataService.getHardwareProfiles().subscribe( this.dataService.getHardwareProfiles().subscribe(
(data: any[]) => { (data: any[]) => this.hardwareProfiles = data,
this.hardwareProfiles = data; error => console.error('Error fetching hardware profiles', error)
}, );
(error: any) => { }
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() { onSubmit() {
if (this.generalFormGroup.valid && this.additionalInfoFormGroup.valid && this.networkSettingsFormGroup.valid && (this.generalFormGroup.value.type !== 'classroom' || this.classroomInfoFormGroup.valid)) { if (this.isFormValid()) {
const generalFormValues = this.cleanFormValues(this.generalFormGroup); const formData: any = this.buildPayload();
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);
const postUrl = `${this.baseUrl}/organizational-units`; const postUrl = `${this.baseUrl}/organizational-units`;
const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
this.http.post<any>(postUrl, formData, { headers }).subscribe( this.http.post<any>(postUrl, formData, { headers }).subscribe(
response => { response => {
console.log('POST successful:', response);
this.unitAdded.emit(); this.unitAdded.emit();
this.dialogRef.close(); this.dialogRef.close();
this.openSnackBar(false, 'Cliente creado exitosamente'); 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 { onNoClick(): void {
this.dialogRef.close(); this.dialogRef.close();
} }
openSnackBar(isError: boolean, message: string) { openSnackBar(isError: boolean, message: string) {
if (isError) { if (isError) {
this.toastService.error(' Error al crear el cliente: ' + message, 'Error'); this.toastService.error('Error al crear el cliente: ' + message, 'Error');
} else } else {
this.toastService.success('Cliente creado exitosamente', 'Éxito'); this.toastService.success('Cliente creado exitosamente', 'Éxito');
}
} }
} }

View File

@ -29,15 +29,5 @@
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table> </table>
</mat-tab> </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> </mat-tab-group>
</div> </div>