diff --git a/ogWebconsole/src/app/components/groups/data.service.ts b/ogWebconsole/src/app/components/groups/data.service.ts index 5ee1405..b2f9ee8 100644 --- a/ogWebconsole/src/app/components/groups/data.service.ts +++ b/ogWebconsole/src/app/components/groups/data.service.ts @@ -1,35 +1,55 @@ -// data.service.ts import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Observable, throwError } from 'rxjs'; +import { catchError, map } from 'rxjs/operators'; import { UnidadOrganizativa } from './model'; @Injectable({ - providedIn: 'root', + providedIn: 'root' }) export class DataService { - private unidadesOrganizativas: UnidadOrganizativa[] = [ - { - id: 1, - nombre: 'Unidad Organizativa 1', - aulas: [ - { - id: 1, - nombre: 'Aula 1', - clientes: [ - { id: 1, nombre: 'Cliente 1' }, - { id: 2, nombre: 'Cliente 2' }, - ], - }, - { - id: 2, - nombre: 'Aula 2', - clientes: [{ id: 3, nombre: 'Cliente 3' }], - }, - ], - }, - // Otros datos de ejemplo - ]; - getUnidadesOrganizativas(): UnidadOrganizativa[] { - return this.unidadesOrganizativas; + private apiUrl = 'http://127.0.0.1:8080/organizational-units?page=1&itemsPerPage=30'; + + constructor(private http: HttpClient) {} + + getUnidadesOrganizativas(): Observable { + return this.http.get(this.apiUrl).pipe( + map(response => { + if (response['hydra:member'] && Array.isArray(response['hydra:member'])) { + return response['hydra:member'] + .filter((unidad: any) => unidad.type === 'organizational-unit') + .map((unidad: any) => ({ + id: unidad.id, + nombre: unidad.name, + uuid: unidad.uuid, + type: unidad.type, + aulas: [] + })); + } else { + throw new Error('Unexpected response format'); + } + }), + catchError(error => { + console.error('Error fetching unidades organizativas', error); + return throwError(error); + }) + ); + } + + getChildren(uuid: string): Observable { + return this.http.get(this.apiUrl).pipe( + map(response => { + if (response['hydra:member'] && Array.isArray(response['hydra:member'])) { + return response['hydra:member'].filter((element: any) => element.parent === `/organizational-units/${uuid}`); + } else { + throw new Error('Unexpected response format'); + } + }), + catchError(error => { + console.error('Error fetching children', error); + return throwError(error); + }) + ); } } diff --git a/ogWebconsole/src/app/components/groups/groups.component.css b/ogWebconsole/src/app/components/groups/groups.component.css index a70c0c6..8dcc781 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.css +++ b/ogWebconsole/src/app/components/groups/groups.component.css @@ -14,4 +14,12 @@ button { margin-left: 10px; margin-bottom: 20px; -} \ No newline at end of file +} + .clickable-item:hover { + cursor: pointer; + } + + .selected-item { + background-color: #e0e0e0; + } + \ No newline at end of file diff --git a/ogWebconsole/src/app/components/groups/groups.component.html b/ogWebconsole/src/app/components/groups/groups.component.html index 0e41409..d9eaaed 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.html +++ b/ogWebconsole/src/app/components/groups/groups.component.html @@ -1,8 +1,6 @@

Crear

- - - +

Grupos

@@ -10,36 +8,13 @@ Unidad organizativa - - + + {{ unidad.nombre }} - - - - - - Aulas - - - - {{ aula.nombre }} - - - - - - Clientes - - - - {{ cliente.nombre }} - - + + diff --git a/ogWebconsole/src/app/components/groups/groups.component.ts b/ogWebconsole/src/app/components/groups/groups.component.ts index 10218db..fae8627 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.ts +++ b/ogWebconsole/src/app/components/groups/groups.component.ts @@ -1,10 +1,8 @@ -// groups.component.ts import { Component, OnInit } from '@angular/core'; import { DataService } from './data.service'; -import { UnidadOrganizativa, Aula, Cliente } from './model'; -import { CreateOrganizationalUnitComponent } from './organizational-units/create-organizational-unit/create-organizational-unit.component'; +import { UnidadOrganizativa } from './model'; import { MatDialog } from '@angular/material/dialog'; -import { CreateClientComponent } from './clients/create-client/create-client.component'; +import { CreateOrganizationalUnitComponent } from './organizational-units/create-organizational-unit/create-organizational-unit.component'; @Component({ selector: 'app-groups', @@ -14,32 +12,21 @@ import { CreateClientComponent } from './clients/create-client/create-client.com export class GroupsComponent implements OnInit { unidadesOrganizativas: UnidadOrganizativa[] = []; selectedUnidad: UnidadOrganizativa | null = null; - selectedAula: Aula | null = null; - selectedClientes: Cliente[] = []; constructor(private dataService: DataService, public dialog: MatDialog) {} ngOnInit(): void { - this.unidadesOrganizativas = this.dataService.getUnidadesOrganizativas(); + this.dataService.getUnidadesOrganizativas().subscribe( + data => this.unidadesOrganizativas = data, + error => console.error('Error fetching unidades organizativas', error) + ); } onSelectUnidad(unidad: UnidadOrganizativa): void { this.selectedUnidad = unidad; - this.selectedAula = null; - this.selectedClientes = []; } - onSelectAula(aula: Aula): void { - this.selectedAula = aula; - this.selectedClientes = aula.clientes; - } - - - addOU() { - const dialogRef = this.dialog.open(CreateOrganizationalUnitComponent); - } - - addClient() { - const dialogRef = this.dialog.open(CreateClientComponent); + addOU(): void { + this.dialog.open(CreateOrganizationalUnitComponent); } } diff --git a/ogWebconsole/src/app/components/groups/model.ts b/ogWebconsole/src/app/components/groups/model.ts index 7a672a4..2436b80 100644 --- a/ogWebconsole/src/app/components/groups/model.ts +++ b/ogWebconsole/src/app/components/groups/model.ts @@ -1,19 +1,16 @@ -// models.ts +// model.ts export interface Cliente { - id: number; - nombre: string; - } - - export interface Aula { - id: number; - nombre: string; - clientes: Cliente[]; - bloques?: Aula[]; - } - - export interface UnidadOrganizativa { - id: number; - nombre: string; - aulas: Aula[]; - } - \ No newline at end of file + nombre: string; +} + +export interface Aula { + nombre: string; + clientes: Cliente[]; +} + +export interface UnidadOrganizativa { + id: number; + nombre: string; + uuid: string; + aulas: Aula[]; +} 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 ebaf5a7..44f0b27 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 @@ -1,24 +1,30 @@

Añadir Unidad Organizativa

- +
General + + Tipo + + {{ type }} + + Nombre Padre - + Descripción
- +
@@ -31,13 +37,9 @@ Comentarios - - Tipo - -
- +
@@ -101,7 +103,7 @@ Validación
- +
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 d5c41af..3e4ef34 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 @@ -9,10 +9,10 @@ import { MatDialogRef } from '@angular/material/dialog'; }) export class CreateOrganizationalUnitComponent implements OnInit { isLinear = true; - networkForm: FormGroup; generalFormGroup: FormGroup; additionalInfoFormGroup: FormGroup; networkSettingsFormGroup: FormGroup; + types: string[] = ['organizational-unit', 'classrooms-group', 'classroom', 'clients-group']; constructor( private _formBuilder: FormBuilder, @@ -20,12 +20,12 @@ export class CreateOrganizationalUnitComponent implements OnInit { ) { this.generalFormGroup = this._formBuilder.group({ name: ['', Validators.required], - parent: ['', [Validators.required, Validators.pattern('https?://.+')]], - description: [''] + parent: ['', Validators.required], + description: [''], + type: ['', Validators.required] }); this.additionalInfoFormGroup = this._formBuilder.group({ comments: [''], - type: ['', Validators.required] }); this.networkSettingsFormGroup = this._formBuilder.group({ proxy: [''], @@ -43,26 +43,23 @@ export class CreateOrganizationalUnitComponent implements OnInit { hardwareProfile: ['', Validators.pattern('https?://.+')], validation: [false] }); - - this.networkForm = this._formBuilder.group({ - general: this.generalFormGroup, - additionalInfo: this.additionalInfoFormGroup, - networkSettings: this.networkSettingsFormGroup - }); } ngOnInit() {} onSubmit() { - if (this.networkForm.valid) { - const formData = this.networkForm.value; + if (this.generalFormGroup.valid && this.additionalInfoFormGroup.valid && this.networkSettingsFormGroup.valid) { + const formData = { + ...this.generalFormGroup.value, + ...this.additionalInfoFormGroup.value, + ...this.networkSettingsFormGroup.value, + }; console.log('Form Data:', formData); - // handle form submission logic - this.dialogRef.close(formData); // Cierra el modal y pasa los datos del formulario + this.dialogRef.close(formData); } } onNoClick(): void { - this.dialogRef.close(); // Cierra el modal sin pasar datos + this.dialogRef.close(); } } diff --git a/ogWebconsole/src/app/components/layout/sidebar/sidebar.component.css b/ogWebconsole/src/app/components/layout/sidebar/sidebar.component.css index 081d0e5..d68e53c 100644 --- a/ogWebconsole/src/app/components/layout/sidebar/sidebar.component.css +++ b/ogWebconsole/src/app/components/layout/sidebar/sidebar.component.css @@ -7,6 +7,7 @@ background-color: rgb(245, 245, 245); transition: left 0.3s ease-in-out; box-shadow: 10px 0 10px -5px rgba(0, 0, 0, 0.5); + z-index: 99999999999; } .sidebar.visible { diff --git a/ogWebconsole/src/app/components/layout/sidebar/sidebar.component.ts b/ogWebconsole/src/app/components/layout/sidebar/sidebar.component.ts index 89f5112..ad83d71 100644 --- a/ogWebconsole/src/app/components/layout/sidebar/sidebar.component.ts +++ b/ogWebconsole/src/app/components/layout/sidebar/sidebar.component.ts @@ -21,7 +21,6 @@ export class SidebarComponent { if (token) { try { this.decodedToken = jwtDecode(token); - console.log('Decoded token:', this.decodedToken); this.isSuperAdmin = this.decodedToken.roles.includes('ROLE_SUPER_ADMIN'); this.username = this.decodedToken.username; } catch (error) {