diff --git a/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.css b/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.css index b786c8b..80dc392 100644 --- a/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.css +++ b/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.css @@ -6,6 +6,10 @@ h1 { margin-top: 20px; } +.create-ou-container { + position: relative; +} + .form-field { width: 100%; } @@ -20,6 +24,13 @@ h1 { overflow-y: auto; } +.loading-spinner { + display: block; + margin: 0 auto; + align-items: center; + justify-content: center; +} + .mat-dialog-actions { display: flex; justify-content: flex-end; @@ -55,4 +66,4 @@ h1 { align-items: center; grid-column: span 2; margin-bottom: 10px; -} \ No newline at end of file +} diff --git a/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.html b/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.html index ef830c4..dc980dd 100644 --- a/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.html +++ b/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.html @@ -1,11 +1,10 @@ - - -
+

{{ isEditMode ? 'Editar' : 'Crear' }} Unidad Organizativa

-
+
- General -
+ + General + Tipo @@ -42,8 +41,8 @@ - Información del aula -
Información del aula + Localización @@ -71,8 +70,8 @@ - Configuración de Red -
+ Configuración de Red + OgLive @@ -168,8 +167,8 @@ - Información Adicional -
+ Información Adicional + Comentarios diff --git a/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts b/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts index 170f92e..8dd9b72 100644 --- a/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts +++ b/ogWebconsole/src/app/components/groups/shared/organizational-units/manage-organizational-unit/manage-organizational-unit.component.ts @@ -100,63 +100,76 @@ export class ManageOrganizationalUnitComponent implements OnInit { capacity: [null, [Validators.required, Validators.min(0)]], remoteCalendar: [null] }); - - if (this.isEditMode) { - this.loadData(data.uuid); - } } - ngOnInit() { - this.loadParentUnits(); - this.loadHardwareProfiles(); - this.loadCalendars(); - this.loadOgLives(); - this.loadRepositories(); - this.loadMenus() + ngOnInit(): void { + this.loading = true; + const observables = [ + this.loadParentUnits(), + this.loadHardwareProfiles(), + this.loadCalendars(), + this.loadOgLives(), + this.loadRepositories(), + this.loadMenus(), + ]; + + Promise.all(observables).then(() => { + if (this.isEditMode) { + this.loadData(this.data.uuid).then(() => { + this.loading = false; + }); + } else { + this.loading = false; + } + }).catch(error => { + console.error('Error loading data:', error); + this.loading = false; + }); } get filteredTypes(): string[] { return this.generalFormGroup.get('parent')?.value ? this.types.filter(type => type !== 'organizational-unit') : this.types; } - loadParentUnits() { - this.loading = true; - const url = `${this.baseUrl}/organizational-units?page=1&itemsPerPage=1000`; - this.http.get(url).subscribe( - response => { - this.parentUnits = response['hydra:member']; - this.parentUnitsWithPaths = this.parentUnits.map(unit => ({ - id: unit['@id'], - name: unit.name, - path: this.dataService.getOrganizationalUnitPath(unit, this.parentUnits), - repository: unit.networkSettings?.repository?.['@id'], - hardwareProfile: unit.networkSettings?.hardwareProfile?.['@id'], - ogLive: unit.networkSettings?.ogLive?.['@id'], - menu: unit.networkSettings?.menu?.['@id'], - mcastIp: unit.networkSettings?.mcastIp, - mcastSpeed: unit.networkSettings?.mcastSpeed, - mcastPort: unit.networkSettings?.mcastPort, - mcastMode: unit.networkSettings?.mcastMode, - netiface: unit.networkSettings?.netiface, - p2pMode: unit.networkSettings?.p2pMode, - p2pTime: unit.networkSettings?.p2pTime, - dns: unit.networkSettings?.dns, - netmask: unit.networkSettings?.netmask, - router: unit.networkSettings?.router, - ntp: unit.networkSettings?.ntp - })); + loadParentUnits(): Promise { + return new Promise((resolve, reject) => { + const url = `${this.baseUrl}/organizational-units?page=1&itemsPerPage=1000`; + this.http.get(url).subscribe( + response => { + this.parentUnits = response['hydra:member']; + this.parentUnitsWithPaths = this.parentUnits.map(unit => ({ + id: unit['@id'], + name: unit.name, + path: this.dataService.getOrganizationalUnitPath(unit, this.parentUnits), + repository: unit.networkSettings?.repository?.['@id'], + hardwareProfile: unit.networkSettings?.hardwareProfile?.['@id'], + ogLive: unit.networkSettings?.ogLive?.['@id'], + menu: unit.networkSettings?.menu?.['@id'], + mcastIp: unit.networkSettings?.mcastIp, + mcastSpeed: unit.networkSettings?.mcastSpeed, + mcastPort: unit.networkSettings?.mcastPort, + mcastMode: unit.networkSettings?.mcastMode, + netiface: unit.networkSettings?.netiface, + p2pMode: unit.networkSettings?.p2pMode, + p2pTime: unit.networkSettings?.p2pTime, + dns: unit.networkSettings?.dns, + netmask: unit.networkSettings?.netmask, + router: unit.networkSettings?.router, + ntp: unit.networkSettings?.ntp + })); - const initialUnitId = this.generalFormGroup.get('parent')?.value; - if (initialUnitId) { - this.setOrganizationalUnitDefaults(initialUnitId); + const initialUnitId = this.generalFormGroup.get('parent')?.value; + if (initialUnitId) { + this.setOrganizationalUnitDefaults(initialUnitId); + } + resolve(); + }, + error => { + console.error('Error fetching parent units:', error); + reject(error); } - this.loading = false; - }, - error => { - console.error('Error fetching parent units:', error); - this.loading = false; - } - ); + ); + }); } onParentChange(event: any): void { @@ -191,78 +204,87 @@ export class ManageOrganizationalUnitComponent implements OnInit { return this.parentUnitsWithPaths.find(unit => unit.id === parentId)?.name; } - loadHardwareProfiles(): void { - this.loading = true; - this.dataService.getHardwareProfiles().subscribe( - (data: any[]) => { - this.hardwareProfiles = data; - this.loading = false; - }, - (error: any) => { - console.error('Error fetching hardware profiles', error); - this.loading = false; - } - ); + loadHardwareProfiles(): Promise { + return new Promise((resolve, reject) => { + this.dataService.getHardwareProfiles().subscribe( + (data: any[]) => { + this.hardwareProfiles = data; + resolve(); + }, + error => { + console.error('Error fetching hardware profiles:', error); + reject(error); + } + ); + }); } - loadMenus(): void { - this.loading = true; - const url = `${this.baseUrl}/menus?page=1&itemsPerPage=10000`; + loadOgLives(): Promise { + return new Promise((resolve, reject) => { + const url = `${this.baseUrl}/og-lives?page=1&itemsPerPage=30`; - this.http.get(url).subscribe( - response => { - this.menus = response['hydra:member']; - this.loading = false; - }, - error => { - console.error('Error fetching menus:', error); - this.loading = false; - } - ); + this.http.get(url).subscribe( + response => { + this.ogLives = response['hydra:member']; + resolve(); + }, + error => { + console.error('Error fetching ogLives:', error); + reject(error); + } + ); + }); } - loadOgLives() { - this.loading = true; - this.dataService.getOgLives().subscribe( - (data: any[]) => { - this.ogLives = data; - this.loading = false; - }, - error => { - console.error('Error fetching ogLives', error); - this.loading = false; - } - ); + loadMenus(): Promise { + return new Promise((resolve, reject) => { + const url = `${this.baseUrl}/menus?page=1&itemsPerPage=10000`; + + this.http.get(url).subscribe( + response => { + this.menus = response['hydra:member']; + resolve(); + }, + error => { + console.error('Error fetching menus:', error); + reject(error); + } + ); + }); } - loadRepositories() { - this.loading = true; - this.dataService.getRepositories().subscribe( - (data: any[]) => { - this.repositories = data; - this.loading = false; - }, - error => { - console.error('Error fetching repositories', error); - this.loading = false; - } - ); + loadRepositories(): Promise { + return new Promise((resolve, reject) => { + const url = `${this.baseUrl}/image-repositories?page=1&itemsPerPage=10000`; + + this.http.get(url).subscribe( + response => { + this.repositories = response['hydra:member']; + resolve(); + }, + error => { + console.error('Error fetching ogLives:', error); + reject(error); + } + ); + }); } - loadCalendars() { - this.loading = true; - const apiUrl = `${this.baseUrl}/remote-calendars?page=1&itemsPerPage=30`; - this.http.get(apiUrl).subscribe( - response => { - this.calendars = response['hydra:member']; - this.loading = false; - }, - error => { - console.error('Error loading calendars', error); - this.toastService.error('Error loading current calendar'); - this.loading = false; - } - ); + loadCalendars(): Promise { + return new Promise((resolve, reject) => { + const apiUrl = `${this.baseUrl}/remote-calendars?page=1&itemsPerPage=30`; + this.http.get(apiUrl).subscribe( + response => { + this.calendars = response['hydra:member']; + resolve(); + }, + error => { + console.error('Error loading calendars', error); + this.toastService.error('Error loading current calendar'); + reject(error); + } + ); + }); } loadCurrentCalendar(uuid: string): void { @@ -293,57 +315,58 @@ export class ManageOrganizationalUnitComponent implements OnInit { this.networkSettingsFormGroup.value.repository = event.value; } - loadData(uuid: string) { - this.loading = true; - const url = `${this.baseUrl}/organizational-units/${uuid}`; + loadData(uuid: string): Promise { + return new Promise((resolve, reject) => { + const url = `${this.baseUrl}/organizational-units/${uuid}`; - this.http.get(url).subscribe( - data => { - this.generalFormGroup.patchValue({ - name: data.name, - parent: data.parent ? data.parent['@id'] : '', - description: data.description, - type: data.type, - excludeParentChanges: data.excludeParentChanges - }); - this.additionalInfoFormGroup.patchValue({ - comments: data.comments - }); - this.networkSettingsFormGroup.patchValue({ - proxy: data.networkSettings.proxy, - dns: data.networkSettings.dns, - netmask: data.networkSettings.netmask, - router: data.networkSettings.router, - ntp: data.networkSettings.ntp, - netiface: data.networkSettings.netiface, - p2pMode: data.networkSettings.p2pMode, - p2pTime: data.networkSettings.p2pTime, - mcastIp: data.networkSettings.mcastIp, - mcastSpeed: data.networkSettings.mcastSpeed, - mcastPort: data.networkSettings.mcastPort, - mcastMode: data.networkSettings.mcastMode, - menu: data.networkSettings.menu ? data.networkSettings.menu['@id'] : null, - hardwareProfile: data.networkSettings.hardwareProfile ? data.networkSettings.hardwareProfile['@id'] : null, - ogLive: data.networkSettings.ogLive ? data.networkSettings.ogLive['@id'] : null, - repository: data.networkSettings.repository ? data.networkSettings.repository['@id'] : null - }); - this.classroomInfoFormGroup.patchValue({ - location: data.location, - projector: data.projector, - board: data.board, - capacity: data.capacity, - remoteCalendar: data.remoteCalendar ? data.remoteCalendar['@id'] : null - }); - this.loading = false; - }, + this.http.get(url).subscribe( + data => { + this.generalFormGroup.patchValue({ + name: data.name, + parent: data.parent ? data.parent['@id'] : '', + description: data.description, + type: data.type, + excludeParentChanges: data.excludeParentChanges + }); + this.additionalInfoFormGroup.patchValue({ + comments: data.comments + }); + this.networkSettingsFormGroup.patchValue({ + proxy: data.networkSettings?.proxy, + dns: data.networkSettings?.dns, + netmask: data.networkSettings?.netmask, + router: data.networkSettings?.router, + ntp: data.networkSettings?.ntp, + netiface: data.networkSettings?.netiface, + p2pMode: data.networkSettings?.p2pMode, + p2pTime: data.networkSettings?.p2pTime, + mcastIp: data.networkSettings?.mcastIp, + mcastSpeed: data.networkSettings?.mcastSpeed, + mcastPort: data.networkSettings?.mcastPort, + mcastMode: data.networkSettings?.mcastMode, + menu: data.networkSettings?.menu ? data.networkSettings.menu['@id'] : null, + hardwareProfile: data.networkSettings?.hardwareProfile ? data.networkSettings.hardwareProfile['@id'] : null, + ogLive: data.networkSettings?.ogLive ? data.networkSettings.ogLive['@id'] : null, + repository: data.networkSettings?.repository ? data.networkSettings.repository['@id'] : null + }); + this.classroomInfoFormGroup.patchValue({ + location: data.location, + projector: data.projector, + board: data.board, + capacity: data.capacity, + remoteCalendar: data.remoteCalendar ? data.remoteCalendar['@id'] : null + }); + resolve(); + }, - error => { - console.error('Error fetching data for edit:', error); - this.toastService.error('Error fetching data'); - this.loading = false; - this.onNoClick(); - } - ); + error => { + console.error('Error fetching data for edit:', error); + this.toastService.error('Error fetching data'); + reject(error); + this.onNoClick(); + } + ); + }); } onSubmit() {