Skip to content
Snippets Groups Projects

feat(admin user): [AOU-429] add toggle in user list to show only user with validation right

5 files
+ 68
2
Compare changes
  • Side-by-side
  • Inline
Files
5
import {adminUserActionNameSpace} from "@admin/user/stores/admin-user.action";
import {
AdminUserAction,
adminUserActionNameSpace,
} from "@admin/user/stores/admin-user.action";
import {
AdminUserState,
AdminUserStateModel,
@@ -25,7 +28,13 @@ import {DataTableComponentHelper} from "@shared/helpers/data-table-component.hel
import {
AbstractListRoutable,
DataTableFieldTypeEnum,
MappingObjectUtil,
MemoizedUtil,
ObjectUtil,
OrderEnum,
Override,
QueryParameters,
QueryParametersUtil,
RouterExtensionService,
} from "solidify-frontend";
@@ -40,7 +49,10 @@ export class AdminUserListRoutable extends AbstractListRoutable<User, AdminUserS
readonly KEY_BACK_BUTTON: string | undefined = LabelTranslateEnum.backToAdmin;
readonly KEY_PARAM_NAME: keyof User & string = "externalUid";
private readonly KEY_HAVE_VALIDATION_RIGHT: string = "haveValidationRight";
adminUserState: typeof AdminUserState = AdminUserState;
protected onlyUserWithValidationRight: boolean = false;
constructor(protected readonly _store: Store,
protected readonly _changeDetector: ChangeDetectorRef,
@@ -49,7 +61,31 @@ export class AdminUserListRoutable extends AbstractListRoutable<User, AdminUserS
protected readonly _actions$: Actions,
protected readonly _dialog: MatDialog,
protected readonly _injector: Injector) {
super(_store, _changeDetector, _route, _routerExt, _actions$, _dialog, StateEnum.admin_user, adminUserActionNameSpace, _injector, {}, StateEnum.admin);
super(_store, _changeDetector, _route, _routerExt, _actions$, _dialog, StateEnum.admin_user, adminUserActionNameSpace, _injector, {
listExtraButtons: [
{
color: "primary",
icon: null,
labelToTranslate: (current) => LabelTranslateEnum.showOnlyUserWithValidationRight,
callback: (model, buttonElementRef, checked) => this.showOnlyUserWithValidationRight(checked),
order: 40,
isToggleButton: true,
isToggleChecked: false,
},
],
}, StateEnum.admin);
}
@Override()
onQueryParametersEvent(queryParameters: QueryParameters): void {
if (this.onlyUserWithValidationRight) {
this.updateQueryParameterWithOnlyValidationRight(queryParameters, true);
this._store.dispatch(new AdminUserAction.ChangeQueryParameters(queryParameters, true));
} else {
this.updateQueryParameterWithOnlyValidationRight(queryParameters, false);
this._store.dispatch(new AdminUserAction.ChangeQueryParameters(queryParameters, true));
}
this._changeDetector.detectChanges(); // Allow to display spinner the first time
}
ngOnInit(): void {
@@ -58,6 +94,32 @@ export class AdminUserListRoutable extends AbstractListRoutable<User, AdminUserS
this.listNewId = [currentUser.resId];
}
showOnlyUserWithValidationRight(onlyWithValidationRight: boolean): void {
let queryParameter = MemoizedUtil.queryParametersSnapshot(this._store, AdminUserState);
queryParameter = QueryParametersUtil.clone(queryParameter);
if (onlyWithValidationRight) {
this.updateQueryParameterWithOnlyValidationRight(queryParameter, true);
this.onlyUserWithValidationRight = true;
} else {
this.updateQueryParameterWithOnlyValidationRight(queryParameter, false);
this.onlyUserWithValidationRight = false;
}
this._store.dispatch(new AdminUserAction.ChangeQueryParameters(queryParameter, true));
this._changeDetector.detectChanges();
}
private updateQueryParameterWithOnlyValidationRight(queryParameters: QueryParameters, haveValidationRight: boolean): QueryParameters | undefined {
queryParameters = ObjectUtil.clone(queryParameters);
queryParameters.search = ObjectUtil.clone(queryParameters.search);
if (haveValidationRight) {
MappingObjectUtil.set(queryParameters.search.searchItems, this.KEY_HAVE_VALIDATION_RIGHT, "true");
} else {
MappingObjectUtil.delete(queryParameters.search.searchItems, this.KEY_HAVE_VALIDATION_RIGHT);
}
return queryParameters;
}
conditionDisplayEditButton(model: User | undefined): boolean {
return true;
}
Loading