From ffc72df88fa49d95fc577a046e47d934aa60d51f Mon Sep 17 00:00:00 2001 From: apuente Date: Wed, 2 Oct 2024 10:12:04 +0200 Subject: [PATCH] refs #798 Added .env fix --- .../add-role-modal.component.ts | 3 +- .../create-command-group.component.ts | 6 ++-- .../create-task/create-task.component.ts | 6 ++-- .../command-detail.component.ts | 2 +- .../acctions-modal.component.ts | 2 +- .../edit-organizational-unit.component.html | 8 ++--- .../edit-organizational-unit.component.ts | 34 +++++++++++++++---- 7 files changed, 41 insertions(+), 20 deletions(-) diff --git a/ogWebconsole/src/app/components/admin/roles/roles/add-role-modal/add-role-modal.component.ts b/ogWebconsole/src/app/components/admin/roles/roles/add-role-modal/add-role-modal.component.ts index b38a0d8..6f928e8 100644 --- a/ogWebconsole/src/app/components/admin/roles/roles/add-role-modal/add-role-modal.component.ts +++ b/ogWebconsole/src/app/components/admin/roles/roles/add-role-modal/add-role-modal.component.ts @@ -9,6 +9,7 @@ import { FormBuilder, FormGroup } from '@angular/forms'; styleUrls: ['./add-role-modal.component.css'] }) export class AddRoleModalComponent { + baseUrl: string = import.meta.env.NG_APP_BASE_API_URL; roleForm: FormGroup; constructor( @@ -49,7 +50,7 @@ export class AddRoleModalComponent { enabled: true }; - this.http.post('http://127.0.0.1:8001/user-groups', payload).subscribe( + this.http.post(`${this.baseUrl}/user-groups`, payload).subscribe( (response) => { this.dialogRef.close(); }, diff --git a/ogWebconsole/src/app/components/commands/commands-groups/create-command-group/create-command-group.component.ts b/ogWebconsole/src/app/components/commands/commands-groups/create-command-group/create-command-group.component.ts index 2a4a93f..1a8d172 100644 --- a/ogWebconsole/src/app/components/commands/commands-groups/create-command-group/create-command-group.component.ts +++ b/ogWebconsole/src/app/components/commands/commands-groups/create-command-group/create-command-group.component.ts @@ -15,7 +15,7 @@ export class CreateCommandGroupComponent implements OnInit { groupName: string = ''; enabled: boolean = true; editing: boolean = false; - private apiUrl = 'http://127.0.0.1:8001/commands'; + private apiUrl = `${this.baseUrl}/commands`; constructor( private http: HttpClient, @@ -70,7 +70,7 @@ export class CreateCommandGroupComponent implements OnInit { if (this.editing) { const groupId = this.data.group.uuid; - this.http.patch(`http://127.0.0.1:8001/command-groups/${groupId}`, payload).subscribe({ + this.http.patch(`${this.baseUrl}/command-groups/${groupId}`, payload).subscribe({ next: () => { this.toastService.success('Grupo de comandos actualizado con éxito'); this.dialogRef.close(); @@ -80,7 +80,7 @@ export class CreateCommandGroupComponent implements OnInit { } }); } else { - this.http.post('http://127.0.0.1:8001/command-groups', payload).subscribe({ + this.http.post(`${this.baseUrl}/command-groups`, payload).subscribe({ next: () => { this.toastService.success('Grupo de comandos creado con éxito'); this.dialogRef.close(); diff --git a/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.ts b/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.ts index 586127d..d0b9a71 100644 --- a/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.ts +++ b/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.ts @@ -73,7 +73,7 @@ export class CreateTaskComponent implements OnInit { } loadOrganizationalUnits(): void { - this.http.get('http://127.0.0.1:8001/organizational-units?page=1&itemsPerPage=30').subscribe( + this.http.get(`${this.baseUrl}/organizational-units?page=1&itemsPerPage=30`).subscribe( (data) => { this.availableOrganizationalUnits = data['hydra:member'].filter((unit: any) => unit['type'] === 'organizational-unit'); }, @@ -139,16 +139,14 @@ export class CreateTaskComponent implements OnInit { const dateTime = this.combineDateAndTime(formData.date, formData.time); const selectedCommands = formData.extraCommands && formData.extraCommands.length > 0 ? formData.extraCommands.map((id: any) => `/commands/${id}`) - : null; // No asignamos nada si no hay comandos seleccionados + : null; - // Creamos el objeto payload const payload: any = { commandGroups: formData.commandGroup ? [`/command-groups/${formData.commandGroup}`] : null, dateTime: dateTime, notes: formData.notes || '' }; - // Solo agregamos commands al payload si hay comandos seleccionados if (selectedCommands) { payload.commands = selectedCommands; } diff --git a/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.ts b/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.ts index 59b41c3..0e9690e 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.ts +++ b/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.ts @@ -35,7 +35,7 @@ export class CommandDetailComponent implements OnInit { scheduleTime: [''] }); - this.http.get('http://127.0.0.1:8001/clients?page=1&itemsPerPage=30').subscribe(response => { + this.http.get(`${this.baseUrl}/clients?page=1&itemsPerPage=30`).subscribe(response => { this.clients = response['hydra:member']; }); diff --git a/ogWebconsole/src/app/components/groups/shared/acctions-modal/acctions-modal.component.ts b/ogWebconsole/src/app/components/groups/shared/acctions-modal/acctions-modal.component.ts index e94012e..0c865bb 100644 --- a/ogWebconsole/src/app/components/groups/shared/acctions-modal/acctions-modal.component.ts +++ b/ogWebconsole/src/app/components/groups/shared/acctions-modal/acctions-modal.component.ts @@ -15,7 +15,7 @@ export class AcctionsModalComponent { selectedElements: any; commands: any[] = []; displayedColumns: string[] = ['name', 'createdBy', 'createdAt']; - private apiUrl = 'http://127.0.0.1:8001/commands?page=1&itemsPerPage=30'; + private apiUrl = `${this.baseUrl}/commands?page=1&itemsPerPage=40`; ngOnInit(): void { this.loadCommands(); diff --git a/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.html b/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.html index fdadaa5..19f2205 100644 --- a/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.html +++ b/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.html @@ -47,14 +47,14 @@ - +
diff --git a/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.ts b/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.ts index 9188b59..5457e3e 100644 --- a/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.ts +++ b/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.ts @@ -32,6 +32,7 @@ export class EditOrganizationalUnitComponent implements OnInit { {"name": 'Full duplex', "value": "full-duplex"}, ]; @Output() unitAdded = new EventEmitter(); // Event emitter to notify parent component about unit addition + calendars: any; constructor( private _formBuilder: FormBuilder, @@ -75,7 +76,8 @@ export class EditOrganizationalUnitComponent implements OnInit { location: [''], projector: [false], board: [false], - capacity: [0, Validators.min(0)] + capacity: [0, Validators.min(0)], + calendarSelect: [null] }); if (this.isEditMode) { @@ -84,8 +86,9 @@ export class EditOrganizationalUnitComponent implements OnInit { } ngOnInit() { - this.loadParentUnits(); // Load parent units when component initializes + this.loadParentUnits(); this.loadHardwareProfiles(); + this.loadCalendars(); } loadParentUnits() { @@ -112,11 +115,29 @@ export class EditOrganizationalUnitComponent implements OnInit { ); } + 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'); + } + ); + } + + onCalendarChange(event: any) { + const selectedCalendarId = event.value; + console.log('Selected calendar ID:', selectedCalendarId); + // Aquí puedes agregar la lógica adicional para manejar el cambio de calendario si es necesario + } + loadData(uuid: string) { const url = `${this.baseUrl}/organizational-units/${uuid}`; this.http.get(url).subscribe( data => { + console.log('Data fetched for edit:', data); this.generalFormGroup.patchValue({ name: data.name, parent: data.parent ? data.parent['@id'] : '', @@ -143,10 +164,11 @@ export class EditOrganizationalUnitComponent implements OnInit { validation: data.networkSettings.validation }); this.classroomInfoFormGroup.patchValue({ - location: data.classroomInfo.location, - projector: data.classroomInfo.projector, - board: data.classroomInfo.board, - capacity: data.classroomInfo.capacity + location: data.location, + projector: data.projector, + board: data.board, + capacity: data.capacity, + calendarSelect: data.remoteCalendar['@id'] }); }, error => {