refs #1563. New field groupsView in user
	
		
			
	
		
	
	
		
			
				
	
				testing/ogGui-multibranch/pipeline/head There was a failure building this commit
				
					Details
				
			
		
	
				
					
				
			
				
	
				testing/ogGui-multibranch/pipeline/head There was a failure building this commit
				
					Details
				
			
		
	
							parent
							
								
									4ef99a7c98
								
							
						
					
					
						commit
						20452c83eb
					
				|  | @ -1,3 +1,5 @@ | |||
| <app-loading [isLoading]="loading"></app-loading> | ||||
| 
 | ||||
| <h1 mat-dialog-title>{{ 'dialogTitleAddUser' | translate }}</h1> | ||||
| <mat-dialog-content class="form-container"> | ||||
|   <form [formGroup]="userForm" class="user-form"> | ||||
|  |  | |||
|  | @ -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 | ||||
|           } | ||||
|         ); | ||||
|       } | ||||
|  |  | |||
|  | @ -26,7 +26,16 @@ | |||
|   <table mat-table [dataSource]="dataSource" class="mat-elevation-z8"> | ||||
|     <ng-container *ngFor="let column of columns" [matColumnDef]="column.columnDef"> | ||||
|       <th mat-header-cell *matHeaderCellDef> {{ column.header }} </th> | ||||
|       <td mat-cell *matCellDef="let user"> {{ column.cell(user) }} </td> | ||||
|       <td mat-cell *matCellDef="let user"> | ||||
|         <ng-container *ngIf="column.columnDef === 'groupsView'"> | ||||
|           <mat-chip> | ||||
|             {{ user[column.columnDef] === 'card' ? 'Vista tarjetas' : 'Listado' }} | ||||
|           </mat-chip> | ||||
|         </ng-container> | ||||
|         <ng-container *ngIf="column.columnDef !== 'groupsView'" > | ||||
|           {{ column.cell(user) }} | ||||
|           </ng-container> | ||||
|         </td> | ||||
|     </ng-container> | ||||
| 
 | ||||
|     <ng-container matColumnDef="actions"> | ||||
|  | @ -49,4 +58,4 @@ | |||
|   <mat-paginator [length]="length" [pageSize]="itemsPerPage" [pageIndex]="page" [pageSizeOptions]="pageSizeOptions" | ||||
|     (page)="onPageChange($event)"> | ||||
|   </mat-paginator> | ||||
| </div> | ||||
| </div> | ||||
|  |  | |||
|  | @ -54,7 +54,7 @@ export class GroupsComponent implements OnInit, OnDestroy { | |||
|   selectedClients = new MatTableDataSource<Client>([]); | ||||
|   selection = new SelectionModel<any>(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'; | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue