From 99cf9f7c0a24e54215e821b51082aa8133e9d511 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Mon, 15 Mar 2021 18:01:50 -0400 Subject: [PATCH] =?UTF-8?q?Normalisation=20de=20la=20liste=20des=20employ?= =?UTF-8?q?=C3=A9s=20et=20des=20groupes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accounts/services/account.service.ts | 5 +- .../employees/pages/list/list.component.html | 77 +++---------------- .../employees/pages/list/list.component.ts | 27 ++++--- .../groups/pages/list/list.component.html | 77 +++---------------- .../groups/pages/list/list.component.ts | 41 ++++------ .../entity-list/entity-list.component.html | 30 ++++++-- .../entity-list/entity-list.component.ts | 54 ++++++++++--- 7 files changed, 129 insertions(+), 182 deletions(-) diff --git a/src/app/modules/accounts/services/account.service.ts b/src/app/modules/accounts/services/account.service.ts index fda72d8..962df6d 100644 --- a/src/app/modules/accounts/services/account.service.ts +++ b/src/app/modules/accounts/services/account.service.ts @@ -64,7 +64,10 @@ export class AccountService implements OnDestroy { this.setLoggedInEmployeeFromApi() success() }, - error: err => this.errorService.handleError(err) + error: err => { + this.errorService.handleError(err) + globalLoadingWheel.hide() + } }) } diff --git a/src/app/modules/employees/pages/list/list.component.html b/src/app/modules/employees/pages/list/list.component.html index 15f11bb..e52139f 100644 --- a/src/app/modules/employees/pages/list/list.component.html +++ b/src/app/modules/employees/pages/list/list.component.html @@ -1,66 +1,13 @@ -
- -
+ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Numéro d'employé{{employee.id}}Nom{{employee.firstName}} {{employee.lastName}}Groupe - {{employee.group.name}} - Aucun - Dernière connexion - {{getDate(employee.lastLoginTime).toLocaleString()}} - Jamais - Permissions - {{employee.permissions.length}} - 0 - - - - - -
- -
-
+ + + diff --git a/src/app/modules/employees/pages/list/list.component.ts b/src/app/modules/employees/pages/list/list.component.ts index 6805ea6..05e7b98 100644 --- a/src/app/modules/employees/pages/list/list.component.ts +++ b/src/app/modules/employees/pages/list/list.component.ts @@ -23,9 +23,22 @@ import {ErrorService} from '../../../shared/service/error.service' }) export class ListComponent extends ErrorHandlingComponent { employees$: Observable - columns = ['id', 'name', 'group', 'permissionCount', 'lastLogin', 'editButton', 'editPasswordButton'] - - expandedElement: Employee | null + columns = [ + {def: 'id', title: 'Numéro d\'employé', valueFn: e => e.id}, + {def: 'name', title: 'Nom', valueFn: e => `${e.firstName} ${e.lastName}`}, + {def: 'group', title: 'Groupe', valueFn: e => e.group ? e.group.name : 'Aucun'}, + {def: 'permissionCount', title: 'Nombre de permissions', valueFn: e => e.permissions.length}, + {def: 'lastLogin', title: 'Dernière connexion', valueFn: e => e.lastLoginTime ? this.getDate(e.lastLoginTime).toLocaleString() : 'Jamais'} + ] + buttons = [{ + text: 'Modifier', + linkFn: employee => `/employee/edit/${employee.id}`, + permission: EmployeePermission.EDIT_EMPLOYEE + }, { + text: 'Modifier mot de passe', + linkFn: employee => `/employee/password/edit/${employee.id}`, + permission: EmployeePermission.EDIT_EMPLOYEE_PASSWORD + }] constructor( private employeeService: EmployeeService, @@ -44,12 +57,4 @@ export class ListComponent extends ErrorHandlingComponent { getDate(dateString: string) { return new Date(dateString) } - - get canEditEmployee(): boolean { - return this.accountService.hasPermission(EmployeePermission.EDIT_EMPLOYEE) - } - - get canEditEmployeePassword(): boolean { - return this.accountService.hasPermission(EmployeePermission.EDIT_EMPLOYEE_PASSWORD) - } } diff --git a/src/app/modules/groups/pages/list/list.component.html b/src/app/modules/groups/pages/list/list.component.html index be59f51..4d17df7 100644 --- a/src/app/modules/groups/pages/list/list.component.html +++ b/src/app/modules/groups/pages/list/list.component.html @@ -1,66 +1,13 @@ -
- -
+ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Nom{{group.name}}Nombre de permissions{{group.permissions.length}}Nombre d'utilisateurs{{group.employeeCount}} - - - - -
- -
-
+ + + diff --git a/src/app/modules/groups/pages/list/list.component.ts b/src/app/modules/groups/pages/list/list.component.ts index 4844dbf..dc2e7a2 100644 --- a/src/app/modules/groups/pages/list/list.component.ts +++ b/src/app/modules/groups/pages/list/list.component.ts @@ -2,31 +2,35 @@ import {Component} from '@angular/core' import {GroupService} from '../../services/group.service' import {EmployeeGroup, EmployeePermission} from '../../../shared/model/employee' import {map} from 'rxjs/operators' -import {animate, state, style, transition, trigger} from '@angular/animations' import {AccountService} from '../../../accounts/services/account.service' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' import {ActivatedRoute, Router} from '@angular/router' import {ErrorModel, ErrorService} from '../../../shared/service/error.service' import {AlertService} from '../../../shared/service/alert.service' -import {globalLoadingWheel} from '../../../shared/components/loading-wheel/loading-wheel.component' @Component({ selector: 'cre-groups', templateUrl: './list.component.html', - styleUrls: ['./list.component.sass'], - animations: [ - trigger('detailExpand', [ - state('collapsed', style({height: '0px', minHeight: '0'})), - state('expanded', style({height: '*'})), - transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')) - ]) - ] + styleUrls: ['./list.component.sass'] }) export class ListComponent extends ErrorHandlingComponent { groups$ = this.groupService.all.pipe(map(groups => groups.filter(g => g.id >= 0))) defaultGroup: EmployeeGroup = null - columns = ['name', 'permissionCount', 'employeeCount', 'defaultGroup', 'editGroup'] - expandedElement: EmployeeGroup | null + columns = [ + {def: 'name', title: 'Nom', valueFn: g => g.name}, + {def: 'permissionCount', title: 'Nombre de permissions', valueFn: g => g.permissions.length}, + {def: 'employeeCount', title: 'Nombre d\'utilisateurs', valueFn: g => g.employeeCount} + ] + buttons = [{ + text: 'Définir par défaut', + clickFn: group => this.setDefaultGroup(group), + permission: EmployeePermission.SET_BROWSER_DEFAULT_GROUP, + disabledFn: group => this.isDefaultGroup(group) + }, { + text: 'Modifier', + linkFn: group => `/group/edit/${group.id}`, + permission: EmployeePermission.EDIT_EMPLOYEE_GROUP + }] handledErrorModels: ErrorModel[] = [{ filter: error => error.status === 404, @@ -48,6 +52,7 @@ export class ListComponent extends ErrorHandlingComponent { this.subscribe( this.groupService.defaultGroup, group => this.defaultGroup = group, + true ) } @@ -62,16 +67,4 @@ export class ListComponent extends ErrorHandlingComponent { isDefaultGroup(group: EmployeeGroup): boolean { return this.defaultGroup && this.defaultGroup.id == group.id } - - get canViewEmployee(): boolean { - return this.accountService.hasPermission(EmployeePermission.VIEW_EMPLOYEE) - } - - get canEditGroup(): boolean { - return this.accountService.hasPermission(EmployeePermission.EDIT_EMPLOYEE_GROUP) - } - - get canSetBrowserDefaultGroup(): boolean { - return this.accountService.hasPermission(EmployeePermission.SET_BROWSER_DEFAULT_GROUP) - } } diff --git a/src/app/modules/shared/components/entity-list/entity-list.component.html b/src/app/modules/shared/components/entity-list/entity-list.component.html index d5acfd2..f444d14 100644 --- a/src/app/modules/shared/components/entity-list/entity-list.component.html +++ b/src/app/modules/shared/components/entity-list/entity-list.component.html @@ -2,7 +2,7 @@ - +
@@ -20,20 +20,40 @@ - + + + + - + + + + +
{{column.title}} + +
+ +
+
diff --git a/src/app/modules/shared/components/entity-list/entity-list.component.ts b/src/app/modules/shared/components/entity-list/entity-list.component.ts index 2f3d7a8..d5ddb0f 100644 --- a/src/app/modules/shared/components/entity-list/entity-list.component.ts +++ b/src/app/modules/shared/components/entity-list/entity-list.component.ts @@ -2,11 +2,19 @@ import {Component, Input} from '@angular/core' import {Observable} from 'rxjs' import {AccountService} from '../../../accounts/services/account.service' import {EmployeePermission} from '../../model/employee' +import {animate, state, style, transition, trigger} from '@angular/animations' @Component({ selector: 'cre-entity-list', templateUrl: './entity-list.component.html', - styleUrls: ['./entity-list.component.sass'] + styleUrls: ['./entity-list.component.sass'], + animations: [ + trigger('detailExpand', [ + state('collapsed', style({height: '0px', minHeight: '0'})), + state('expanded', style({height: '*'})), + transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')) + ]) + ] }) export class EntityListComponent { @Input() entities$: Observable @@ -15,8 +23,11 @@ export class EntityListComponent { @Input() buttons?: TableButton[] @Input() addLink: string @Input() addPermission: EmployeePermission + @Input() expandable = false + @Input() rowDetailsTemplate hoveredEntity: T | null + expandedEntity: T | null constructor( private accountService: AccountService @@ -31,23 +42,43 @@ export class EntityListComponent { return this.accountService.hasPermission(permission) } - openExternalLink(button: TableButton, entity: T) { - let externalLink = null + getRouterLink(button: TableButton, entity: T): string { // @ts-ignore - if (button.link && button.link.externalLink) { + if (button.link && !button.link.externalLink) { // @ts-ignore - externalLink = button.link.externalLink - } else { - const linkFnResult = button.linkFn(entity) + return button.link + } else if (button.linkFn) { + const fnResult = button.linkFn(entity) // @ts-ignore - if (linkFnResult && linkFnResult.externalLink) { + if (!fnResult.externalLink) { // @ts-ignore - externalLink = linkFnResult.externalLink + return fnResult } } + return undefined + } - if (externalLink) { - window.open(externalLink, '_blank') + clickButton(button: TableButton, entity: T) { + if (button.link || button.linkFn) { + let externalLink = null + // @ts-ignore + if (button.link && button.link.externalLink) { + // @ts-ignore + externalLink = button.link.externalLink + } else { + const linkFnResult = button.linkFn(entity) + // @ts-ignore + if (linkFnResult && linkFnResult.externalLink) { + // @ts-ignore + externalLink = linkFnResult.externalLink + } + } + + if (externalLink) { + window.open(externalLink, '_blank') + } + } else if (button.clickFn) { + button.clickFn(entity) } } @@ -87,6 +118,7 @@ export class TableButton { public text: string, public link: string | { externalLink: string } | null, public linkFn: (T) => string | { externalLink: string } | null, + public clickFn: (T) => void, public permission: EmployeePermission | null, public disabledFn: (T) => boolean | null ) {