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 6f90c11..9acb0a0 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 @@ -15,30 +15,48 @@ {{ 'labelRole' | translate }} - - {{ group.name }} - + @for (group of userGroups; track group['@id']) { + + {{ group.name }} + + } {{ 'labelOrganizationalUnit' | translate }} - - {{ unit.name }} - + @for (unit of organizationalUnits; track unit['@id']) { + + {{ unit.name }} + + } {{ 'cardView' | translate }} - - {{ option.name }} - + @for (option of views; track option.value) { + + {{ option.name }} + + } + + {{ 'userLanguage' | translate }} + + @for (lang of availableLanguages; track lang.code) { + + {{ lang.label }} + + } + + {{ 'userLanguageHint' | translate }} + + {{ 'clientsPerPage' | 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 308da61..bceaa5b 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 @@ -36,6 +36,8 @@ export class AddUserModalComponent implements OnInit { { value: 'list', name: 'Listado' }, ]; + readonly availableLanguages: { code: string; label: string }[]; + constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, @@ -46,12 +48,15 @@ export class AddUserModalComponent implements OnInit { private configService: ConfigService ) { this.baseUrl = this.configService.apiUrl; + const langs = this.configService.languages; + this.availableLanguages = Object.keys(langs).map(code => ({ code, label: langs[code] })); this.userForm = this.fb.group({ username: ['', Validators.required], password: ['', Validators.required], role: ['', Validators.required], groupsView: ['card', Validators.required], clientsPerPage: [null, [Validators.min(1)]], + language: ['es'], organizationalUnits: [[]] }); @@ -87,7 +92,8 @@ export class AddUserModalComponent implements OnInit { role: response.userGroups.length > 0 ? response.userGroups[0]['@id'] : null, organizationalUnits: organizationalUnitIds, groupsView: response.groupsView, - clientsPerPage: response.clientsPerPage ?? null + clientsPerPage: response.clientsPerPage ?? null, + language: response.language ?? 'es' }); this.userId = response['@id']; @@ -114,7 +120,8 @@ export class AddUserModalComponent implements OnInit { enabled: true, userGroups: [this.userForm.value.role], groupsView: this.userForm.value.groupsView, - clientsPerPage: this.userForm.value.clientsPerPage || null + clientsPerPage: this.userForm.value.clientsPerPage || null, + language: this.userForm.value.language || null }; if (!this.userId && this.userForm.value.password) { diff --git a/ogWebconsole/src/app/layout/header/header.component.ts b/ogWebconsole/src/app/layout/header/header.component.ts index 4196b4f..4ef3bd3 100644 --- a/ogWebconsole/src/app/layout/header/header.component.ts +++ b/ogWebconsole/src/app/layout/header/header.component.ts @@ -34,7 +34,14 @@ export class HeaderComponent implements OnInit { ngOnInit(): void { this.breakpointObserver.observe(['(max-width: 576px)']).subscribe((result) => { this.isSmallScreen = result.matches; - }) + }); + + // Aplicar idioma guardado: el del JWT (servidor) tiene prioridad sobre localStorage + const jwtLang = this.auth.language; + const localLang = localStorage.getItem('language'); + const langToApply = jwtLang || localLang || 'es'; + this.translate.use(langToApply); + localStorage.setItem('language', langToApply); } get availableLanguages() { diff --git a/ogWebconsole/src/app/services/auth.service.ts b/ogWebconsole/src/app/services/auth.service.ts index 3c18231..c88d1b0 100644 --- a/ogWebconsole/src/app/services/auth.service.ts +++ b/ogWebconsole/src/app/services/auth.service.ts @@ -18,6 +18,7 @@ interface JwtPayload { uuid: string; groupsView: string; clientsPerPage: number | null; + language: string | null; } @Injectable({ providedIn: 'root' }) @@ -103,6 +104,11 @@ export class AuthService { return this.tokenPayload?.clientsPerPage ?? null; } + /** Idioma preferido del usuario */ + get language(): string | null { + return this.tokenPayload?.language ?? null; + } + /** * Devuelve el rol principal del usuario según prioridad. */ diff --git a/ogWebconsole/src/locale/cat.json b/ogWebconsole/src/locale/cat.json index 973cc78..76153a0 100644 --- a/ogWebconsole/src/locale/cat.json +++ b/ogWebconsole/src/locale/cat.json @@ -238,6 +238,8 @@ "clientSelectStepText": "Selecciona un client per veure les traces associades.", "clientsPerPage": "Clients per pàgina", "clientsPerPageHint": "Nombre de clients mostrats per pàgina al llistat", + "userLanguage": "Idioma preferit", + "userLanguageHint": "Idioma de la interfície per a aquest usuari", "clientSuccessfullyRemovedFromThe": "Client eliminat de la xarxa correctament", "clientsViewStepText": "Visualització dels clients de la unitat organitzativa seleccionada", "clientUpdatedSuccessfully": "Client actualitzat correctament", diff --git a/ogWebconsole/src/locale/en.json b/ogWebconsole/src/locale/en.json index 8afc28a..c87fbce 100644 --- a/ogWebconsole/src/locale/en.json +++ b/ogWebconsole/src/locale/en.json @@ -238,6 +238,8 @@ "clientSelectStepText": "Select a client to see the associated traces.", "clientsPerPage": "Clients per page", "clientsPerPageHint": "Number of clients shown per page in the list", + "userLanguage": "Preferred language", + "userLanguageHint": "Interface language for this user", "clientSuccessfullyRemovedFromThe": "Client successfully removed from the network", "clientsViewStepText": "Display of the selected organizational unit's clients", "clientUpdatedSuccessfully": "Client updated successfully", diff --git a/ogWebconsole/src/locale/es.json b/ogWebconsole/src/locale/es.json index a476d54..61dd482 100644 --- a/ogWebconsole/src/locale/es.json +++ b/ogWebconsole/src/locale/es.json @@ -238,6 +238,8 @@ "clientSelectStepText": "Selecciona un cliente para ver las trazas asociadas.", "clientsPerPage": "Clientes por página", "clientsPerPageHint": "Número de clientes mostrados por página en el listado", + "userLanguage": "Idioma preferido", + "userLanguageHint": "Idioma de la interfaz para este usuario", "clientSuccessfullyRemovedFromThe": "Cliente eliminado de la red con éxito", "clientsViewStepText": "Visualización de los clientes de la unidad organizativa seleccionada", "clientUpdatedSuccessfully": "Cliente actualizado con éxito",