75832: Groups registry refactor

This commit is contained in:
Marie Verdonck
2021-01-14 16:20:04 +01:00
parent 17e8881380
commit f1407b7f5b
12 changed files with 106 additions and 64 deletions

View File

@@ -143,7 +143,9 @@ export class GroupFormComponent implements OnInit, OnDestroy {
initialisePage() {
this.subs.push(this.route.params.subscribe((params) => {
if (params.groupId !== 'newGroup') {
this.setActiveGroup(params.groupId);
}
}));
this.canEdit$ = this.groupDataService.getActiveGroup().pipe(
hasValueOperator(),
@@ -225,14 +227,12 @@ export class GroupFormComponent implements OnInit, OnDestroy {
{
value: this.groupDescription.value
}
],
]
},
};
if (group === null) {
console.log('createNewGroup', values);
this.createNewGroup(values);
} else {
console.log('editGroup', group);
this.editGroup(group);
}
}

View File

@@ -24,10 +24,10 @@
</div>
</form>
<ds-pagination *ngIf="(searchResults$ | async)?.payload?.totalElements > 0"
<ds-pagination *ngIf="(ePeopleSearchDtos | async)?.totalElements > 0"
[paginationOptions]="configSearch"
[pageInfoState]="(searchResults$ | async)?.payload"
[collectionSize]="(searchResults$ | async)?.payload?.totalElements"
[pageInfoState]="(ePeopleSearchDtos | async)"
[collectionSize]="(ePeopleSearchDtos | async)?.totalElements"
[hideGear]="true"
[hidePagerWhenSinglePage]="true"
(pageChange)="onPageChangeSearch($event)">
@@ -42,23 +42,23 @@
</tr>
</thead>
<tbody>
<tr *ngFor="let ePerson of (searchResults$ | async)?.payload?.page">
<td>{{ePerson.id}}</td>
<td><a (click)="ePersonDataService.startEditingNewEPerson(ePerson)"
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">{{ePerson.name}}</a></td>
<tr *ngFor="let ePerson of (ePeopleSearchDtos | async)?.page">
<td>{{ePerson.eperson.id}}</td>
<td><a (click)="ePersonDataService.startEditingNewEPerson(ePerson.eperson)"
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">{{ePerson.eperson.name}}</a></td>
<td>
<div class="btn-group edit-field">
<button *ngIf="(isMemberOfGroup(ePerson) | async)"
<button *ngIf="(ePerson.memberOfGroup)"
(click)="deleteMemberFromGroup(ePerson)"
class="btn btn-outline-danger btn-sm"
title="{{messagePrefix + '.table.edit.buttons.remove' | translate: {name: ePerson.name} }}">
title="{{messagePrefix + '.table.edit.buttons.remove' | translate: {name: ePerson.eperson.name} }}">
<i class="fas fa-trash-alt fa-fw"></i>
</button>
<button *ngIf="!(isMemberOfGroup(ePerson) | async)"
<button *ngIf="!(ePerson.memberOfGroup)"
(click)="addMemberToGroup(ePerson)"
class="btn btn-outline-primary btn-sm"
title="{{messagePrefix + '.table.edit.buttons.add' | translate: {name: ePerson.name} }}">
title="{{messagePrefix + '.table.edit.buttons.add' | translate: {name: ePerson.eperson.name} }}">
<i class="fas fa-plus fa-fw"></i>
</button>
</div>
@@ -70,7 +70,7 @@
</ds-pagination>
<div *ngIf="(searchResults$ | async)?.payload?.totalElements == 0 && searchDone"
<div *ngIf="(ePeopleSearchDtos | async)?.totalElements == 0 && searchDone"
class="alert alert-info w-100 mb-2"
role="alert">
{{messagePrefix + '.no-items' | translate}}
@@ -78,10 +78,10 @@
<h4>{{messagePrefix + '.headMembers' | translate}}</h4>
<ds-pagination *ngIf="(members$ | async)?.payload?.totalElements > 0"
<ds-pagination *ngIf="(ePeopleMembersOfGroupDtos | async)?.totalElements > 0"
[paginationOptions]="config"
[pageInfoState]="(members$ | async)?.payload"
[collectionSize]="(members$ | async)?.payload?.totalElements"
[pageInfoState]="(ePeopleMembersOfGroupDtos | async)"
[collectionSize]="(ePeopleMembersOfGroupDtos | async)?.totalElements"
[hideGear]="true"
[hidePagerWhenSinglePage]="true"
(pageChange)="onPageChange($event)">
@@ -96,15 +96,15 @@
</tr>
</thead>
<tbody>
<tr *ngFor="let ePerson of (members$ | async)?.payload?.page">
<td>{{ePerson.id}}</td>
<td><a (click)="ePersonDataService.startEditingNewEPerson(ePerson)"
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">{{ePerson.name}}</a></td>
<tr *ngFor="let ePerson of (ePeopleMembersOfGroupDtos | async)?.page">
<td>{{ePerson.eperson.id}}</td>
<td><a (click)="ePersonDataService.startEditingNewEPerson(ePerson.eperson)"
[routerLink]="[ePersonDataService.getEPeoplePageRouterLink()]">{{ePerson.eperson.name}}</a></td>
<td>
<div class="btn-group edit-field">
<button (click)="deleteMemberFromGroup(ePerson)"
class="btn btn-outline-danger btn-sm"
title="{{messagePrefix + '.table.edit.buttons.remove' | translate: {name: ePerson.name} }}">
title="{{messagePrefix + '.table.edit.buttons.remove' | translate: {name: ePerson.eperson.name} }}">
<i class="fas fa-trash-alt fa-fw"></i>
</button>
</div>
@@ -116,7 +116,7 @@
</ds-pagination>
<div *ngIf="(members$ | async)?.payload?.totalElements == 0" class="alert alert-info w-100 mb-2"
<div *ngIf="(ePeopleMembersOfGroupDtos | async) == undefined || (ePeopleMembersOfGroupDtos | async)?.totalElements == 0" class="alert alert-info w-100 mb-2"
role="alert">
{{messagePrefix + '.no-members-yet' | translate}}
</div>

View File

@@ -2,9 +2,9 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Observable, of as observableOf, Subscription, BehaviorSubject } from 'rxjs';
import { Observable, of as observableOf, Subscription, BehaviorSubject, ObservedValueOf, combineLatest as observableCombineLatest} from 'rxjs';
import { map, mergeMap, take } from 'rxjs/operators';
import { PaginatedList } from '../../../../../core/data/paginated-list.model';
import {buildPaginatedList, PaginatedList} from '../../../../../core/data/paginated-list.model';
import { RemoteData } from '../../../../../core/data/remote-data';
import { EPersonDataService } from '../../../../../core/eperson/eperson-data.service';
import { GroupDataService } from '../../../../../core/eperson/group-data.service';
@@ -17,6 +17,7 @@ import {
} from '../../../../../core/shared/operators';
import { NotificationsService } from '../../../../../shared/notifications/notifications.service';
import { PaginationComponentOptions } from '../../../../../shared/pagination/pagination-component-options.model';
import {EpersonDtoModel} from '../../../../../core/eperson/models/eperson-dto.model';
/**
* Keys to keep track of specific subscriptions
@@ -25,6 +26,8 @@ enum SubKey {
Members,
ActiveGroup,
SearchResults,
MembersDTO,
SearchResultsDTO,
}
@Component({
@@ -43,10 +46,12 @@ export class MembersListComponent implements OnInit, OnDestroy {
* EPeople being displayed in search result, initially all members, after search result of search
*/
searchResults$: BehaviorSubject<RemoteData<PaginatedList<EPerson>>> = new BehaviorSubject(undefined);
ePeopleSearchDtos: BehaviorSubject<PaginatedList<EpersonDtoModel>> = new BehaviorSubject<PaginatedList<EpersonDtoModel>>(undefined);
/**
* List of EPeople members of currently active group being edited
*/
members$: BehaviorSubject<RemoteData<PaginatedList<EPerson>>> = new BehaviorSubject(undefined);
ePeopleMembersOfGroupDtos: BehaviorSubject<PaginatedList<EpersonDtoModel>> = new BehaviorSubject<PaginatedList<EpersonDtoModel>>(undefined);
/**
* Pagination config used to display the list of EPeople that are result of EPeople search
@@ -139,6 +144,9 @@ export class MembersListComponent implements OnInit, OnDestroy {
}
).subscribe((rd: RemoteData<PaginatedList<EPerson>>) => {
this.members$.next(rd);
if (rd.payload !== undefined) {
this.setEpersonDTOsFromResult(rd, this.ePeopleMembersOfGroupDtos, SubKey.MembersDTO);
}
}));
}
@@ -160,11 +168,11 @@ export class MembersListComponent implements OnInit, OnDestroy {
* Deletes a given EPerson from the members list of the group currently being edited
* @param ePerson EPerson we want to delete as member from group that is currently being edited
*/
deleteMemberFromGroup(ePerson: EPerson) {
deleteMemberFromGroup(ePerson: EpersonDtoModel) {
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
if (activeGroup != null) {
const response = this.groupDataService.deleteMemberFromGroup(activeGroup, ePerson);
this.showNotifications('deleteMember', response, ePerson.name, activeGroup);
const response = this.groupDataService.deleteMemberFromGroup(activeGroup, ePerson.eperson);
this.showNotifications('deleteMember', response, ePerson.eperson.name, activeGroup);
} else {
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
}
@@ -175,11 +183,12 @@ export class MembersListComponent implements OnInit, OnDestroy {
* Adds a given EPerson to the members list of the group currently being edited
* @param ePerson EPerson we want to add as member to group that is currently being edited
*/
addMemberToGroup(ePerson: EPerson) {
addMemberToGroup(ePerson: EpersonDtoModel) {
ePerson.memberOfGroup = true;
this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => {
if (activeGroup != null) {
const response = this.groupDataService.addMemberToGroup(activeGroup, ePerson);
this.showNotifications('addMember', response, ePerson.name, activeGroup);
const response = this.groupDataService.addMemberToGroup(activeGroup, ePerson.eperson);
this.showNotifications('addMember', response, ePerson.eperson.name, activeGroup);
} else {
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
}
@@ -234,9 +243,30 @@ export class MembersListComponent implements OnInit, OnDestroy {
elementsPerPage: this.configSearch.pageSize
}).subscribe((rd: RemoteData<PaginatedList<EPerson>>) => {
this.searchResults$.next(rd);
if (rd.payload !== undefined) {
this.setEpersonDTOsFromResult(rd, this.ePeopleSearchDtos, SubKey.SearchResultsDTO);
}
}));
}
private setEpersonDTOsFromResult(rd: RemoteData<PaginatedList<EPerson>>, addTo: BehaviorSubject<PaginatedList<EpersonDtoModel>>, subkey) {
this.unsubFrom(subkey);
const dtos$ = observableCombineLatest(...rd.payload.page.map((member: EPerson) => {
const dto$: Observable<EpersonDtoModel> = observableCombineLatest(
this.isMemberOfGroup(member), (isMember: ObservedValueOf<Observable<boolean>>) => {
const epersonDtoModel: EpersonDtoModel = new EpersonDtoModel();
epersonDtoModel.eperson = member;
epersonDtoModel.memberOfGroup = isMember;
return epersonDtoModel;
});
return dto$;
}));
this.subs.set(subkey,dtos$.pipe(map((dtos: EpersonDtoModel[]) => {
const paginatedListOfDTOs = buildPaginatedList(rd.payload.pageInfo, dtos);
addTo.next(paginatedListOfDTOs);
})).subscribe());
}
/**
* unsub all subscriptions
*/

View File

@@ -8,7 +8,7 @@
<button class="mr-auto btn btn-success"
[routerLink]="['newGroup']">
<i class="fas fa-plus"></i>
<span class="d-none d-sm-inline">&nbsp;{{messagePrefix + 'button.add' | translate}}</span>
<span class="d-none d-sm-inline">{{messagePrefix + 'button.add' | translate}}</span>
</button>
</div>
@@ -45,7 +45,6 @@
<th scope="col">{{messagePrefix + 'table.id' | translate}}</th>
<th scope="col">{{messagePrefix + 'table.name' | translate}}</th>
<th scope="col">{{messagePrefix + 'table.members' | translate}}</th>
<!-- <th scope="col">{{messagePrefix + 'table.comcol' | translate}}</th>-->
<th>{{messagePrefix + 'table.edit' | translate}}</th>
</tr>
</thead>
@@ -53,8 +52,7 @@
<tr *ngFor="let groupDto of (groupsDto$ | async)?.page">
<td>{{groupDto.group.id}}</td>
<td>{{groupDto.group.name}}</td>
<td>{{(getMembers(groupDto.group) | async)?.payload?.totalElements + (getSubgroups(groupDto.group) | async)?.payload?.totalElements}}</td>
<!-- <td>{{getOptionalComColFromName(group.name)}}</td>-->
<td>{{groupDto.epersons?.totalElements + groupDto.subgroups?.totalElements}}</td>
<td>
<div class="btn-group edit-field">
<button [routerLink]="groupService.getGroupEditPageRouterLink(groupDto.group)"
@@ -63,7 +61,7 @@
<i class="fas fa-edit fa-fw"></i>
</button>
<button *ngIf="!groupDto.group?.permanent && groupDto.ableToDelete"
(click)="deleteGroup(groupDto.group)" class="btn btn-outline-danger btn-sm"
(click)="deleteGroup(groupDto)" class="btn btn-outline-danger btn-sm"
title="{{messagePrefix + 'table.edit.buttons.remove' | translate: {name: groupDto.group.name} }}">
<i class="fas fa-trash-alt fa-fw"></i>
</button>

View File

@@ -169,16 +169,16 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
/**
* Delete Group
*/
deleteGroup(group: Group) {
if (hasValue(group.id)) {
this.groupService.delete(group.id).pipe(getFirstCompletedRemoteData())
deleteGroup(group: GroupDtoModel) {
if (hasValue(group.group.id)) {
this.groupService.delete(group.group.id).pipe(getFirstCompletedRemoteData())
.subscribe((rd: RemoteData<NoContent>) => {
if (rd.hasSucceeded) {
this.notificationsService.success(this.translateService.get(this.messagePrefix + 'notification.deleted.success', { name: group.name }));
this.notificationsService.success(this.translateService.get(this.messagePrefix + 'notification.deleted.success', { name: group.group.name }));
this.reset();
} else {
this.notificationsService.error(
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.title', { name: group.name }),
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.title', { name: group.group.name }),
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.content', { cause: rd.errorMessage }));
}
});
@@ -194,7 +194,7 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
).subscribe((href: string) => {
this.requestService.setStaleByHrefSubstring(href);
});
}
}
/**
* Get the members (epersons embedded value of a group)
@@ -233,15 +233,6 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
this.search({ query: '' });
}
/**
* Extract optional UUID from a group name => To be resolved to community or collection with link
* (Or will be resolved in backend and added to group object, tbd) //TODO
* @param groupName
*/
getOptionalComColFromName(groupName: string): string {
return this.groupService.getUUIDFromString(groupName);
}
/**
* Unsub all subscriptions
*/

View File

@@ -63,10 +63,10 @@ export class EPersonDataService extends DataService<EPerson> {
* @param query Query of search
* @param options Options of search request
*/
public searchByScope(scope: string, query: string, options: FindListOptions = {}): Observable<RemoteData<PaginatedList<EPerson>>> {
public searchByScope(scope: string, query: string, options: FindListOptions = {}, useCachedVersionIfAvailable?: boolean): Observable<RemoteData<PaginatedList<EPerson>>> {
switch (scope) {
case 'metadata':
return this.getEpeopleByMetadata(query.trim(), options);
return this.getEpeopleByMetadata(query.trim(), options, useCachedVersionIfAvailable);
case 'email':
return this.getEPersonByEmail(query.trim()).pipe(
map((rd: RemoteData<EPerson | NoContent>) => {
@@ -100,7 +100,7 @@ export class EPersonDataService extends DataService<EPerson> {
})
);
default:
return this.getEpeopleByMetadata(query.trim(), options);
return this.getEpeopleByMetadata(query.trim(), options, useCachedVersionIfAvailable);
}
}

View File

@@ -13,5 +13,9 @@ export class EpersonDtoModel {
* Whether or not the linked EPerson is able to be deleted
*/
public ableToDelete: boolean;
/**
* Whether or not this EPerson is member of group on page it is being used on
*/
public memberOfGroup: boolean;
}

View File

@@ -1,7 +1,9 @@
import { PaginatedList } from '../../data/paginated-list.model';
import { EPerson } from './eperson.model';
import { Group } from './group.model';
/**
* This class serves as a Data Transfer Model that contains the Group and whether or not it's able to be deleted
* This class serves as a Data Transfer Model that contains the Group, whether or not it's able to be deleted and its members
*/
export class GroupDtoModel {
@@ -9,9 +11,20 @@ export class GroupDtoModel {
* The Group linked to this object
*/
public group: Group;
/**
* Whether or not the linked Group is able to be deleted
*/
public ableToDelete: boolean;
/**
* List of subgroups of this group
*/
public subgroups: PaginatedList<Group>;
/**
* List of members of this group
*/
public epersons: PaginatedList<EPerson>;
}

View File

@@ -1,4 +1,4 @@
import { autoserialize, deserialize, inheritSerialization } from 'cerialize';
import { autoserialize, autoserializeAs, deserialize, inheritSerialization } from 'cerialize';
import { Observable } from 'rxjs';
import { link, typedObject } from '../../cache/builders/build-decorators';
import { PaginatedList } from '../../data/paginated-list.model';
@@ -10,12 +10,20 @@ import { HALLink } from '../../shared/hal-link.model';
import { EPerson } from './eperson.model';
import { EPERSON } from './eperson.resource-type';
import { GROUP } from './group.resource-type';
import { excludeFromEquals } from '../../utilities/equals.decorators';
@typedObject
@inheritSerialization(DSpaceObject)
export class Group extends DSpaceObject {
static type = GROUP;
/**
* A string representing the unique name of this Group
*/
@excludeFromEquals
@autoserializeAs('name')
protected _name: string;
/**
* A string representing the unique handle of this Group
*/

View File

@@ -29,7 +29,7 @@ export class DSpaceObject extends ListableObject implements CacheableObject {
@excludeFromEquals
@deserializeAs('name')
private _name: string;
protected _name: string;
/**
* The human-readable identifier of this DSpaceObject

View File

@@ -308,8 +308,6 @@
"admin.access-control.groups.table.members": "Members",
"admin.access-control.groups.table.comcol": "Community / Collection",
"admin.access-control.groups.table.edit": "Edit",
"admin.access-control.groups.table.edit.buttons.edit": "Edit \"{{name}}\"",