diff --git a/ogWebconsole/src/app/components/admin/users/users/add-user-modal/add-user-modal.component.html b/ogWebconsole/src/app/components/admin/users/users/add-user-modal/add-user-modal.component.html index b7b0ef9..b074aa4 100644 --- a/ogWebconsole/src/app/components/admin/users/users/add-user-modal/add-user-modal.component.html +++ b/ogWebconsole/src/app/components/admin/users/users/add-user-modal/add-user-modal.component.html @@ -1,3 +1,5 @@ + +

{{ 'dialogTitleAddUser' | translate }}

diff --git a/ogWebconsole/src/app/components/admin/users/users/add-user-modal/add-user-modal.component.ts b/ogWebconsole/src/app/components/admin/users/users/add-user-modal/add-user-modal.component.ts index 86e49ee..5c742c6 100644 --- a/ogWebconsole/src/app/components/admin/users/users/add-user-modal/add-user-modal.component.ts +++ b/ogWebconsole/src/app/components/admin/users/users/add-user-modal/add-user-modal.component.ts @@ -23,6 +23,7 @@ export class AddUserModalComponent implements OnInit { userGroups: UserGroup[] = []; organizationalUnits: any[] = []; userId: string | null = null; + loading: boolean = false; protected views = [ {value: 'card', name: 'Tarjetas'}, @@ -50,18 +51,22 @@ export class AddUserModalComponent implements OnInit { this.dataService.getUserGroups().subscribe((data) => { this.userGroups = data['hydra:member']; }); + this.dataService.getOrganizationalUnits().subscribe((data) => { this.organizationalUnits = data['hydra:member'].filter((item: any) => item.type === 'organizational-unit'); }); + if (this.data) { - this.load() + this.load(); + } else { + this.userForm.get('password')?.setValidators([Validators.required]); } } load(): void { + this.loading = true; this.dataService.getUser(this.data).subscribe({ next: (response) => { - const organizationalUnitIds = response.allowedOrganizationalUnits.map((unit: any) => unit['@id']); this.userForm.patchValue({ @@ -72,9 +77,13 @@ export class AddUserModalComponent implements OnInit { }); this.userId = response['@id']; + this.userForm.get('password')?.clearValidators(); + this.userForm.get('password')?.updateValueAndValidity(); + this.loading = false; }, error: (err) => { - console.error('Error fetching remote calendar:', err); + this.loading = false; + console.error('Error fetching user:', err); } }); } @@ -93,16 +102,19 @@ export class AddUserModalComponent implements OnInit { userGroups: [this.userForm.value.role ], groupsView: this.userForm.value.groupsView }; + this.loading = true; if (this.userId) { this.http.put(`${this.baseUrl}${this.userId}`, payload).subscribe( (response) => { this.toastService.success('Usuario editado correctamente'); this.dialogRef.close(); + this.loading = false }, (error) => { this.toastService.error(error['error']['hydra:description']); - console.error('Error al editar el rol', error); + this.loading = false + } ); } else { @@ -110,10 +122,11 @@ export class AddUserModalComponent implements OnInit { (response) => { this.toastService.success('Usuario añadido correctamente'); this.dialogRef.close(); + this.loading = false }, (error) => { this.toastService.error(error['error']['hydra:description']); - console.error('Error al añadir añadido', error); + this.loading = false } ); } diff --git a/ogWebconsole/src/app/components/admin/users/users/users.component.html b/ogWebconsole/src/app/components/admin/users/users/users.component.html index a1cd0ac..efa6f75 100644 --- a/ogWebconsole/src/app/components/admin/users/users/users.component.html +++ b/ogWebconsole/src/app/components/admin/users/users/users.component.html @@ -26,7 +26,16 @@ - + @@ -49,4 +58,4 @@ - \ No newline at end of file + diff --git a/ogWebconsole/src/app/components/groups/groups.component.ts b/ogWebconsole/src/app/components/groups/groups.component.ts index 4970660..ff484ad 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.ts +++ b/ogWebconsole/src/app/components/groups/groups.component.ts @@ -54,7 +54,7 @@ export class GroupsComponent implements OnInit, OnDestroy { selectedClients = new MatTableDataSource([]); selection = new SelectionModel(true, []); cols = 4; - currentView: 'card' | 'list' = 'list'; + currentView: string = 'list'; savedFilterNames: [string, string][] = []; selectedTreeFilter = ''; syncStatus = false; @@ -107,6 +107,7 @@ export class GroupsComponent implements OnInit, OnDestroy { ); this.treeDataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener); + this.currentView = localStorage.getItem('groupsView') || 'list'; } diff --git a/ogWebconsole/src/app/components/login/login.component.ts b/ogWebconsole/src/app/components/login/login.component.ts index d2347a4..ff328ab 100644 --- a/ogWebconsole/src/app/components/login/login.component.ts +++ b/ogWebconsole/src/app/components/login/login.component.ts @@ -3,6 +3,7 @@ import {Component, signal} from '@angular/core'; import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import {ToastrService} from "ngx-toastr"; +import {jwtDecode} from "jwt-decode"; @Component({ selector: 'app-login', @@ -16,6 +17,7 @@ export class LoginComponent { }; errorMessage: string = ''; isLoading: boolean = false; + decodedToken: any; baseUrl: string = import.meta.env.NG_APP_BASE_API_URL; @@ -23,7 +25,7 @@ export class LoginComponent { private http: HttpClient, private router: Router, private toastService: ToastrService, - private translateService: TranslateService + private translateService: TranslateService ) { const savedLanguage = localStorage.getItem('language') || 'es'; this.translateService.use(savedLanguage); @@ -56,7 +58,11 @@ export class LoginComponent { localStorage.setItem('loginToken', res.token); localStorage.setItem('refreshToken', res.refreshToken); localStorage.setItem('username', this.loginObj.username); - this.openSnackBar(false, 'Bienvenido ' + this.loginObj.username); + + this.decodedToken = jwtDecode(res.token); + localStorage.setItem('groupsView', this.decodedToken.groupsView); + + this.openSnackBar(false, 'Bienvenido ' + this.loginObj.username); this.router.navigateByUrl('/groups'); } this.isLoading = false;
{{ column.header }} {{ column.cell(user) }} + + + {{ user[column.columnDef] === 'card' ? 'Vista tarjetas' : 'Listado' }} + + + + {{ column.cell(user) }} + +