From b9401b46b120556a8cea7f88ed0d6c17df1623c4 Mon Sep 17 00:00:00 2001 From: Marie Verdonck Date: Thu, 5 Mar 2020 17:19:15 +0100 Subject: [PATCH] 69111: Added list of groups that EPerson is member of in Edit EPerson form, linking to edit group page --- resources/i18n/en.json5 | 10 ++++ .../eperson-form/eperson-form.component.html | 40 ++++++++++++++++ .../eperson-form/eperson-form.component.ts | 47 ++++++++++++++++++- .../group-form/group-form.component.html | 2 +- .../group-form/group-form.component.ts | 2 +- src/app/core/eperson/group-data.service.ts | 8 ++++ 6 files changed, 105 insertions(+), 4 deletions(-) diff --git a/resources/i18n/en.json5 b/resources/i18n/en.json5 index 975e8ec4e6..72a9530b54 100644 --- a/resources/i18n/en.json5 +++ b/resources/i18n/en.json5 @@ -226,6 +226,16 @@ "admin.access-control.epeople.form.notification.edited.failure": "Failed to edit EPerson \"{{name}}\"", + "admin.access-control.epeople.form.groupsEPersonIsMemberOf": "Member of these groups:", + + "admin.access-control.epeople.form.table.id": "ID", + + "admin.access-control.epeople.form.table.name": "Name", + + "admin.access-control.epeople.form.memberOfNoGroups": "This EPerson is not a member of any groups", + + "admin.access-control.epeople.form.goToGroups": "Add to groups", + "admin.access-control.epeople.notification.deleted.failure": "Failed to delete EPerson: \"{{name}}\"", "admin.access-control.epeople.notification.deleted.success": "Successfully deleted EPerson: \"{{name}}\"", diff --git a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.html b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.html index 6d44dd7fa1..5ab10c94a3 100644 --- a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.html +++ b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.html @@ -15,3 +15,43 @@ (cancel)="onCancel()" (submitForm)="onSubmit()"> + +
+
{{messagePrefix + '.groupsEPersonIsMemberOf' | translate}}
+ + + +
+ + + + + + + + + + + + + +
{{messagePrefix + '.table.id' | translate}}{{messagePrefix + '.table.name' | translate}}
{{group.id}}{{group.name}}
+
+ +
+ + +
diff --git a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts index c6cae75ab0..d06bafb3a8 100644 --- a/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts +++ b/src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.ts @@ -7,17 +7,21 @@ import { DynamicInputModel } from '@ng-dynamic-forms/core'; import { TranslateService } from '@ngx-translate/core'; -import { combineLatest } from 'rxjs/internal/observable/combineLatest'; -import { Subscription } from 'rxjs/internal/Subscription'; +import { Subscription, combineLatest } from 'rxjs'; +import { Observable } from 'rxjs/internal/Observable'; import { take } from 'rxjs/operators'; import { RestResponse } from '../../../../core/cache/response.models'; import { PaginatedList } from '../../../../core/data/paginated-list'; +import { RemoteData } from '../../../../core/data/remote-data'; import { EPersonDataService } from '../../../../core/eperson/eperson-data.service'; +import { GroupDataService } from '../../../../core/eperson/group-data.service'; import { EPerson } from '../../../../core/eperson/models/eperson.model'; +import { Group } from '../../../../core/eperson/models/group.model'; import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../core/shared/operators'; import { hasValue } from '../../../../shared/empty.util'; import { FormBuilderService } from '../../../../shared/form/builder/form-builder.service'; import { NotificationsService } from '../../../../shared/notifications/notifications.service'; +import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model'; @Component({ selector: 'ds-eperson-form', @@ -106,12 +110,27 @@ export class EPersonFormComponent implements OnInit, OnDestroy { */ subs: Subscription[] = []; + /** + * A list of all the groups this EPerson is a member of + */ + groups: Observable>>; + + /** + * Pagination config used to display the list of groups + */ + config: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), { + id: 'groups-ePersonMemberOf-list-pagination', + pageSize: 5, + currentPage: 1 + }); + /** * Try to retrieve initial active eperson, to fill in checkboxes at component creation */ epersonInitial: EPerson; constructor(public epersonService: EPersonDataService, + public groupsDataService: GroupDataService, private formBuilderService: FormBuilderService, private translateService: TranslateService, private notificationsService: NotificationsService,) { @@ -181,6 +200,10 @@ export class EPersonFormComponent implements OnInit, OnDestroy { ]; this.formGroup = this.formBuilderService.createFormGroup(this.formModel); this.subs.push(this.epersonService.getActiveEPerson().subscribe((eperson: EPerson) => { + this.groups = this.groupsDataService.findAllByHref(eperson._links.groups.href, { + currentPage: 1, + elementsPerPage: this.config.pageSize + }); this.formGroup.patchValue({ firstName: eperson != null ? eperson.firstMetadataValue('eperson.firstname') : '', lastName: eperson != null ? eperson.firstMetadataValue('eperson.lastname') : '', @@ -333,6 +356,26 @@ export class EPersonFormComponent implements OnInit, OnDestroy { }); } + /** + * Event triggered when the user changes page + * @param event + */ + onPageChange(event) { + this.updateGroups({ + currentPage: event, + elementsPerPage: this.config.pageSize + }); + } + + /** + * Update the list of groups by fetching it from the rest api or cache + */ + private updateGroups(options) { + this.subs.push(this.epersonService.getActiveEPerson().subscribe((eperson: EPerson) => { + this.groups = this.groupsDataService.findAllByHref(eperson._links.groups.href, options); + })); + } + /** * Cancel the current edit when component is destroyed & unsub all subscriptions */ diff --git a/src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.html b/src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.html index 47c61cb024..0cf0c6dd0b 100644 --- a/src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.html +++ b/src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.html @@ -24,7 +24,7 @@
- +
diff --git a/src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.ts b/src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.ts index eb75a1d024..415a0bb12e 100644 --- a/src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.ts +++ b/src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.ts @@ -134,7 +134,7 @@ export class GroupFormComponent implements OnInit, OnDestroy { onCancel() { this.groupDataService.cancelEditGroup(); this.cancelForm.emit(); - this.router.navigate(['/admin/access-control/groups']); + this.router.navigate([this.groupDataService.getGroupRegistryRouterLink()]); } /** diff --git a/src/app/core/eperson/group-data.service.ts b/src/app/core/eperson/group-data.service.ts index dc331d0b2c..17c9829483 100644 --- a/src/app/core/eperson/group-data.service.ts +++ b/src/app/core/eperson/group-data.service.ts @@ -255,4 +255,12 @@ export class GroupDataService extends DataService { }); } + public getGroupRegistryRouterLink(): string { + return '/admin/access-control/groups'; + } + + public getGroupEditPageRouterLink(groupId: string): string { + return '/admin/access-control/groups/' + groupId; + } + }