From 5615390ce5d2781c404fef8c0686670fcc4b497e Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Wed, 30 Sep 2020 14:46:03 +0200 Subject: [PATCH] [Task 72956] fixed EPerson deletion issues with page not refreshing --- .../epeople-registry.component.html | 8 ++--- .../epeople-registry.component.ts | 36 +++++++++---------- src/app/core/eperson/eperson-data.service.ts | 30 ---------------- 3 files changed, 21 insertions(+), 53 deletions(-) diff --git a/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.html b/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.html index d708940c99..5cb8e77a3e 100644 --- a/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.html +++ b/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.html @@ -4,7 +4,7 @@ -
@@ -42,8 +42,8 @@ @@ -85,7 +85,7 @@ - diff --git a/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts b/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts index beaa2b4846..d385d83348 100644 --- a/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts +++ b/src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts @@ -2,7 +2,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder } from '@angular/forms'; import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; -import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; +import { BehaviorSubject, combineLatest, Observable, of as observableOf } from 'rxjs'; import { Subscription } from 'rxjs/internal/Subscription'; import { map, switchMap, take } from 'rxjs/operators'; import { PaginatedList } from '../../../core/data/paginated-list'; @@ -20,7 +20,8 @@ import { RestResponse } from '../../../core/cache/response.models'; import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { RequestService } from '../../../core/data/request.service'; -import { filter } from "rxjs/internal/operators/filter"; +import { filter } from 'rxjs/internal/operators/filter'; +import { PageInfo } from '../../../core/shared/page-info.model'; @Component({ selector: 'ds-epeople-registry', @@ -44,6 +45,11 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy { */ ePeopleDto$: BehaviorSubject> = new BehaviorSubject>({} as any); + /** + * An observable for the pageInfo, needed to pass to the pagination component + */ + pageInfoState$: BehaviorSubject = new BehaviorSubject(undefined); + /** * Pagination config used to display the list of epeople */ @@ -108,18 +114,10 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy { * @param event */ onPageChange(event) { - this.config.currentPage = event; - this.search({ scope: this.currentSearchScope, query: this.currentSearchQuery }) - } - - /** - * Force-update the list of EPeople by first clearing the cache related to EPeople, then performing - * a new REST call - */ - public forceUpdateEPeople() { - this.epersonService.clearEPersonRequests(); - this.isEPersonFormShown = false; - this.search({ query: '', scope: 'metadata' }) + if (this.config.currentPage !== event) { + this.config.currentPage = event; + this.search({ scope: this.currentSearchScope, query: this.currentSearchQuery }) + } } /** @@ -162,7 +160,10 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy { })).pipe(map((dtos: EpersonDtoModel[]) => { return new PaginatedList(epeople.pageInfo, dtos); })) - })).subscribe((value) => this.ePeopleDto$.next(value))); + })).subscribe((value) => { + this.ePeopleDto$.next(value); + this.pageInfoState$.next(value.pageInfo); + })); } /** @@ -217,12 +218,9 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy { if (restResponse.isSuccessful) { this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', { name: ePerson.name })); this.reset(); - this.forceUpdateEPeople(); } else { this.notificationsService.error('Error occured when trying to delete EPerson with id: ' + ePerson.id + ' with code: ' + restResponse.statusCode + ' and message: ' + restResponse.statusText); } - this.epersonService.cancelEditEPerson(); - this.isEPersonFormShown = false; }) }} }); @@ -264,7 +262,7 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy { * This method will ensure that the page gets reset and that the cache is cleared */ reset() { - this.epersonService.getSearchByHref("byMetadata", {}).pipe( + this.epersonService.getBrowseEndpoint().pipe( switchMap((href) => this.requestService.removeByHrefSubstring(href)), filter((isCached) => isCached), take(1) diff --git a/src/app/core/eperson/eperson-data.service.ts b/src/app/core/eperson/eperson-data.service.ts index abe9777e7f..a32bd87636 100644 --- a/src/app/core/eperson/eperson-data.service.ts +++ b/src/app/core/eperson/eperson-data.service.ts @@ -299,34 +299,4 @@ export class EPersonDataService extends DataService { map((request: RequestEntry) => request.response) ); } - - /** - * Make a new FindListRequest with given search method - * - * @param searchMethod The search method for the object - * @param options The [[FindListOptions]] object - * @param linksToFollow The array of [[FollowLinkConfig]] - * @return {Observable>} - * Return an observable that emits response from the server - */ - searchBy(searchMethod: string, options: FindListOptions = {}, ...linksToFollow: Array>): Observable>> { - const hrefObs = this.getSearchByHref(searchMethod, options, ...linksToFollow); - - return hrefObs.pipe( - find((href: string) => hasValue(href)), - tap((href: string) => { - this.requestService.removeByHrefSubstring(href); - const request = new FindListRequest(this.requestService.generateRequestId(), href, options); - - this.requestService.configure(request); - } - ), - switchMap((href) => this.requestService.getByHref(href)), - skipWhile((requestEntry) => hasValue(requestEntry) && requestEntry.completed), - switchMap((href) => - this.rdbService.buildList(hrefObs, ...linksToFollow) as Observable>> - ) - ); - } - }