diff --git a/ogWebconsole/src/app/components/groups/client-view/client-view.component.html b/ogWebconsole/src/app/components/groups/client-view/client-view.component.html index d60e173..7cbdd4d 100644 --- a/ogWebconsole/src/app/components/groups/client-view/client-view.component.html +++ b/ogWebconsole/src/app/components/groups/client-view/client-view.component.html @@ -44,7 +44,7 @@ - + diff --git a/ogWebconsole/src/app/components/groups/groups.component.ts b/ogWebconsole/src/app/components/groups/groups.component.ts index b8be0e8..25646cb 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.ts +++ b/ogWebconsole/src/app/components/groups/groups.component.ts @@ -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; diff --git a/ogWebconsole/src/app/components/groups/organizational-units/create-organizational-unit/create-organizational-unit.component.html b/ogWebconsole/src/app/components/groups/organizational-units/create-organizational-unit/create-organizational-unit.component.html index 55ea6fc..19cce7f 100644 --- a/ogWebconsole/src/app/components/groups/organizational-units/create-organizational-unit/create-organizational-unit.component.html +++ b/ogWebconsole/src/app/components/groups/organizational-units/create-organizational-unit/create-organizational-unit.component.html @@ -49,6 +49,17 @@ Aforo + + + + Calendario Asociado + + + {{ calendar.name }} + + + +
@@ -83,7 +94,7 @@ bootFileName - + Url servidor Proxy @@ -107,9 +118,7 @@ Modo P2P - + {{ option.name }} @@ -133,9 +142,7 @@ Modo Multicast - + {{ option.name }} @@ -147,7 +154,7 @@ Perfil de Hardware - {{ unit.description }} + {{ unit.description }} Formato de URL inválido. diff --git a/ogWebconsole/src/app/components/groups/organizational-units/create-organizational-unit/create-organizational-unit.component.ts b/ogWebconsole/src/app/components/groups/organizational-units/create-organizational-unit/create-organizational-unit.component.ts index 2e7f363..4d55383 100644 --- a/ogWebconsole/src/app/components/groups/organizational-units/create-organizational-unit/create-organizational-unit.component.ts +++ b/ogWebconsole/src/app/components/groups/organizational-units/create-organizational-unit/create-organizational-unit.component.ts @@ -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(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(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(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'); + } } } diff --git a/ogWebconsole/src/app/components/groups/organizational-units/show-organizational-unit/show-organizational-unit.component.html b/ogWebconsole/src/app/components/groups/organizational-units/show-organizational-unit/show-organizational-unit.component.html index 93406cd..8cf3f5e 100644 --- a/ogWebconsole/src/app/components/groups/organizational-units/show-organizational-unit/show-organizational-unit.component.html +++ b/ogWebconsole/src/app/components/groups/organizational-units/show-organizational-unit/show-organizational-unit.component.html @@ -29,15 +29,5 @@ - -
- - - - - - -
-