mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #1017 from atmire/w2p-75832_Issue-962_fix-unnecessary-calls-creating-deleting-groups
Fix unnecessary calls when creating/deleting groups
This commit is contained in:
@@ -143,7 +143,9 @@ export class GroupFormComponent implements OnInit, OnDestroy {
|
||||
|
||||
initialisePage() {
|
||||
this.subs.push(this.route.params.subscribe((params) => {
|
||||
this.setActiveGroup(params.groupId);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -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>
|
||||
|
@@ -2,9 +2,15 @@ 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 { map, mergeMap, take } from 'rxjs/operators';
|
||||
import { PaginatedList } from '../../../../../core/data/paginated-list.model';
|
||||
import {
|
||||
Observable,
|
||||
of as observableOf,
|
||||
Subscription,
|
||||
BehaviorSubject,
|
||||
combineLatest as observableCombineLatest, ObservedValueOf,
|
||||
} from 'rxjs';
|
||||
import { map, mergeMap, switchMap, take } from 'rxjs/operators';
|
||||
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';
|
||||
@@ -13,18 +19,19 @@ import { Group } from '../../../../../core/eperson/models/group.model';
|
||||
import {
|
||||
getRemoteDataPayload,
|
||||
getFirstSucceededRemoteData,
|
||||
getFirstCompletedRemoteData
|
||||
getFirstCompletedRemoteData, getAllCompletedRemoteData
|
||||
} 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
|
||||
*/
|
||||
enum SubKey {
|
||||
Members,
|
||||
ActiveGroup,
|
||||
SearchResults,
|
||||
MembersDTO,
|
||||
SearchResultsDTO,
|
||||
}
|
||||
|
||||
@Component({
|
||||
@@ -42,11 +49,11 @@ 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
|
||||
@@ -130,16 +137,60 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
||||
* @private
|
||||
*/
|
||||
private retrieveMembers(page: number) {
|
||||
this.unsubFrom(SubKey.Members);
|
||||
this.subs.set(
|
||||
SubKey.Members,
|
||||
this.ePersonDataService.findAllByHref(this.groupBeingEdited._links.epersons.href, {
|
||||
currentPage: page,
|
||||
elementsPerPage: this.config.pageSize
|
||||
}
|
||||
).subscribe((rd: RemoteData<PaginatedList<EPerson>>) => {
|
||||
this.members$.next(rd);
|
||||
}));
|
||||
this.unsubFrom(SubKey.MembersDTO);
|
||||
this.subs.set(SubKey.MembersDTO, this.ePersonDataService.findAllByHref(this.groupBeingEdited._links.epersons.href, {
|
||||
currentPage: page,
|
||||
elementsPerPage: this.config.pageSize
|
||||
}).pipe(
|
||||
getAllCompletedRemoteData(),
|
||||
map((rd: RemoteData<any>) => {
|
||||
if (rd.hasFailed) {
|
||||
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure', {cause: rd.errorMessage}));
|
||||
} else {
|
||||
return rd;
|
||||
}
|
||||
}),
|
||||
switchMap((epersonListRD: RemoteData<PaginatedList<EPerson>>) => {
|
||||
const dtos$ = observableCombineLatest(...epersonListRD.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$;
|
||||
}));
|
||||
return dtos$.pipe(map((dtos: EpersonDtoModel[]) => {
|
||||
return buildPaginatedList(epersonListRD.payload.pageInfo, dtos);
|
||||
}));
|
||||
}))
|
||||
.subscribe((paginatedListOfDTOs: PaginatedList<EpersonDtoModel>) => {
|
||||
this.ePeopleMembersOfGroupDtos.next(paginatedListOfDTOs);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the given ePerson is a member of the group currently being edited
|
||||
* @param possibleMember EPerson that is a possible member (being tested) of the group currently being edited
|
||||
*/
|
||||
isMemberOfGroup(possibleMember: EPerson): Observable<boolean> {
|
||||
return this.groupDataService.getActiveGroup().pipe(take(1),
|
||||
mergeMap((group: Group) => {
|
||||
if (group != null) {
|
||||
return this.ePersonDataService.findAllByHref(group._links.epersons.href, {
|
||||
currentPage: 1,
|
||||
elementsPerPage: 9999
|
||||
}, false)
|
||||
.pipe(
|
||||
getFirstSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
map((listEPeopleInGroup: PaginatedList<EPerson>) => listEPeopleInGroup.page.filter((ePersonInList: EPerson) => ePersonInList.id === possibleMember.id)),
|
||||
map((epeople: EPerson[]) => epeople.length > 0));
|
||||
} else {
|
||||
return observableOf(false);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,11 +211,12 @@ 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);
|
||||
this.search({ scope: this.currentSearchScope, query: this.currentSearchQuery });
|
||||
} else {
|
||||
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure.noActiveGroup'));
|
||||
}
|
||||
@@ -175,40 +227,18 @@ 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'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the given ePerson is a member of the group currently being edited
|
||||
* @param possibleMember EPerson that is a possible member (being tested) of the group currently being edited
|
||||
*/
|
||||
isMemberOfGroup(possibleMember: EPerson): Observable<boolean> {
|
||||
return this.groupDataService.getActiveGroup().pipe(take(1),
|
||||
mergeMap((group: Group) => {
|
||||
if (group != null) {
|
||||
return this.ePersonDataService.findAllByHref(group._links.epersons.href, {
|
||||
currentPage: 1,
|
||||
elementsPerPage: 9999
|
||||
})
|
||||
.pipe(
|
||||
getFirstSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
map((listEPeopleInGroup: PaginatedList<EPerson>) => listEPeopleInGroup.page.filter((ePersonInList: EPerson) => ePersonInList.id === possibleMember.id)),
|
||||
map((epeople: EPerson[]) => epeople.length > 0));
|
||||
} else {
|
||||
return observableOf(false);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Search in the EPeople by name, email or metadata
|
||||
* @param data Contains scope and query param
|
||||
@@ -228,13 +258,38 @@ export class MembersListComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
this.searchDone = true;
|
||||
|
||||
this.unsubFrom(SubKey.SearchResults);
|
||||
this.subs.set(SubKey.SearchResults, this.ePersonDataService.searchByScope(this.currentSearchScope, this.currentSearchQuery, {
|
||||
currentPage: this.configSearch.currentPage,
|
||||
elementsPerPage: this.configSearch.pageSize
|
||||
}).subscribe((rd: RemoteData<PaginatedList<EPerson>>) => {
|
||||
this.searchResults$.next(rd);
|
||||
}));
|
||||
this.unsubFrom(SubKey.SearchResultsDTO);
|
||||
this.subs.set(SubKey.SearchResultsDTO,
|
||||
this.ePersonDataService.searchByScope(this.currentSearchScope, this.currentSearchQuery, {
|
||||
currentPage: this.configSearch.currentPage,
|
||||
elementsPerPage: this.configSearch.pageSize
|
||||
}, false).pipe(
|
||||
getAllCompletedRemoteData(),
|
||||
map((rd: RemoteData<any>) => {
|
||||
if (rd.hasFailed) {
|
||||
this.notificationsService.error(this.translateService.get(this.messagePrefix + '.notification.failure', {cause: rd.errorMessage}));
|
||||
} else {
|
||||
return rd;
|
||||
}
|
||||
}),
|
||||
switchMap((epersonListRD: RemoteData<PaginatedList<EPerson>>) => {
|
||||
const dtos$ = observableCombineLatest(...epersonListRD.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$;
|
||||
}));
|
||||
return dtos$.pipe(map((dtos: EpersonDtoModel[]) => {
|
||||
return buildPaginatedList(epersonListRD.payload.pageInfo, dtos);
|
||||
}));
|
||||
}))
|
||||
.subscribe((paginatedListOfDTOs: PaginatedList<EpersonDtoModel>) => {
|
||||
this.ePeopleSearchDtos.next(paginatedListOfDTOs);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -130,7 +130,7 @@ export class SubgroupsListComponent implements OnInit, OnDestroy {
|
||||
SubKey.Members,
|
||||
this.groupDataService.findAllByHref(this.groupBeingEdited._links.subgroups.href, {
|
||||
currentPage: page,
|
||||
elementsPerPage: this.config.pageSize
|
||||
elementsPerPage: this.config.pageSize
|
||||
}
|
||||
).subscribe((rd: RemoteData<PaginatedList<Group>>) => {
|
||||
this.subGroups$.next(rd);
|
||||
|
@@ -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"> {{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>
|
||||
|
@@ -26,7 +26,7 @@ import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||
import {
|
||||
getAllSucceededRemoteDataPayload,
|
||||
getFirstCompletedRemoteData,
|
||||
getAllSucceededRemoteData
|
||||
getFirstSucceededRemoteData
|
||||
} from '../../../core/shared/operators';
|
||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||
import { hasValue } from '../../../shared/empty.util';
|
||||
@@ -55,15 +55,12 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
||||
currentPage: 1
|
||||
});
|
||||
|
||||
/**
|
||||
* A list of all the current Groups within the repository or the result of the search
|
||||
*/
|
||||
groups$: BehaviorSubject<RemoteData<PaginatedList<Group>>> = new BehaviorSubject<RemoteData<PaginatedList<Group>>>({} as any);
|
||||
/**
|
||||
* A BehaviorSubject with the list of GroupDtoModel objects made from the Groups in the repository or
|
||||
* as the result of the search
|
||||
*/
|
||||
groupsDto$: BehaviorSubject<PaginatedList<GroupDtoModel>> = new BehaviorSubject<PaginatedList<GroupDtoModel>>({} as any);
|
||||
deletedGroupsIds: string[] = [];
|
||||
|
||||
/**
|
||||
* An observable for the pageInfo, needed to pass to the pagination component
|
||||
@@ -104,30 +101,6 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit() {
|
||||
this.search({ query: this.currentSearchQuery });
|
||||
|
||||
this.subs.push(this.groups$.pipe(
|
||||
getAllSucceededRemoteDataPayload(),
|
||||
switchMap((groups: PaginatedList<Group>) => {
|
||||
return observableCombineLatest(groups.page.map((group: Group) => {
|
||||
return observableCombineLatest([
|
||||
this.authorizationService.isAuthorized(FeatureID.CanDelete, hasValue(group) ? group.self : undefined),
|
||||
this.hasLinkedDSO(group)
|
||||
]).pipe(
|
||||
map(([isAuthorized, hasLinkedDSO]: boolean[]) => {
|
||||
const groupDtoModel: GroupDtoModel = new GroupDtoModel();
|
||||
groupDtoModel.ableToDelete = isAuthorized && !hasLinkedDSO;
|
||||
groupDtoModel.group = group;
|
||||
return groupDtoModel;
|
||||
}
|
||||
)
|
||||
);
|
||||
})).pipe(map((dtos: GroupDtoModel[]) => {
|
||||
return buildPaginatedList(groups.pageInfo, dtos);
|
||||
}));
|
||||
})).subscribe((value: PaginatedList<GroupDtoModel>) => {
|
||||
this.groupsDto$.next(value);
|
||||
this.pageInfoState$.next(value.pageInfo);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,14 +127,42 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
||||
this.searchSub.unsubscribe();
|
||||
this.subs = this.subs.filter((sub: Subscription) => sub !== this.searchSub);
|
||||
}
|
||||
|
||||
this.searchSub = this.groupService.searchGroups(this.currentSearchQuery.trim(), {
|
||||
currentPage: this.config.currentPage,
|
||||
elementsPerPage: this.config.pageSize
|
||||
}).pipe(
|
||||
getAllSucceededRemoteData()
|
||||
).subscribe((groupsRD: RemoteData<PaginatedList<Group>>) => {
|
||||
this.groups$.next(groupsRD);
|
||||
this.pageInfoState$.next(groupsRD.payload.pageInfo);
|
||||
getAllSucceededRemoteDataPayload(),
|
||||
switchMap((groups: PaginatedList<Group>) => {
|
||||
if (groups.page.length === 0) {
|
||||
return observableOf(buildPaginatedList(groups.pageInfo, []));
|
||||
}
|
||||
return observableCombineLatest(groups.page.map((group: Group) => {
|
||||
if (!this.deletedGroupsIds.includes(group.id)) {
|
||||
return observableCombineLatest([
|
||||
this.authorizationService.isAuthorized(FeatureID.CanDelete, hasValue(group) ? group.self : undefined),
|
||||
this.hasLinkedDSO(group),
|
||||
this.getSubgroups(group),
|
||||
this.getMembers(group)
|
||||
]).pipe(
|
||||
map(([isAuthorized, hasLinkedDSO, subgroups, members]:
|
||||
[boolean, boolean, RemoteData<PaginatedList<Group>>, RemoteData<PaginatedList<EPerson>>]) => {
|
||||
const groupDtoModel: GroupDtoModel = new GroupDtoModel();
|
||||
groupDtoModel.ableToDelete = isAuthorized && !hasLinkedDSO;
|
||||
groupDtoModel.group = group;
|
||||
groupDtoModel.subgroups = subgroups.payload;
|
||||
groupDtoModel.epersons = members.payload;
|
||||
return groupDtoModel;
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
})).pipe(map((dtos: GroupDtoModel[]) => {
|
||||
return buildPaginatedList(groups.pageInfo, dtos);
|
||||
}));
|
||||
})).subscribe((value: PaginatedList<GroupDtoModel>) => {
|
||||
this.groupsDto$.next(value);
|
||||
this.pageInfoState$.next(value.pageInfo);
|
||||
});
|
||||
this.subs.push(this.searchSub);
|
||||
}
|
||||
@@ -169,16 +170,17 @@ 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.deletedGroupsIds = [...this.deletedGroupsIds, group.group.id];
|
||||
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 }));
|
||||
}
|
||||
});
|
||||
@@ -201,7 +203,7 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
||||
* @param group
|
||||
*/
|
||||
getMembers(group: Group): Observable<RemoteData<PaginatedList<EPerson>>> {
|
||||
return this.ePersonDataService.findAllByHref(group._links.epersons.href);
|
||||
return this.ePersonDataService.findAllByHref(group._links.epersons.href).pipe(getFirstSucceededRemoteData());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +211,7 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
||||
* @param group
|
||||
*/
|
||||
getSubgroups(group: Group): Observable<RemoteData<PaginatedList<Group>>> {
|
||||
return this.groupService.findAllByHref(group._links.subgroups.href);
|
||||
return this.groupService.findAllByHref(group._links.subgroups.href).pipe(getFirstSucceededRemoteData());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,6 +220,7 @@ export class GroupsRegistryComponent implements OnInit, OnDestroy {
|
||||
*/
|
||||
hasLinkedDSO(group: Group): Observable<boolean> {
|
||||
return this.dSpaceObjectDataService.findByHref(group._links.object.href).pipe(
|
||||
getFirstSucceededRemoteData(),
|
||||
map((rd: RemoteData<DSpaceObject>) => hasValue(rd) && hasValue(rd.payload)),
|
||||
catchError(() => observableOf(false)),
|
||||
);
|
||||
@@ -233,15 +236,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
|
||||
*/
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
||||
}
|
||||
|
@@ -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>;
|
||||
|
||||
}
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -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
|
||||
|
@@ -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}}\"",
|
||||
@@ -404,6 +402,8 @@
|
||||
|
||||
"admin.access-control.groups.form.members-list.no-items": "No EPeople found in that search",
|
||||
|
||||
"admin.access-control.groups.form.subgroups-list.notification.failure": "Something went wrong: \"{{cause}}\"",
|
||||
|
||||
"admin.access-control.groups.form.subgroups-list.head": "Groups",
|
||||
|
||||
"admin.access-control.groups.form.subgroups-list.search.head": "Add Subgroup",
|
||||
|
Reference in New Issue
Block a user