From f6fea087c356bceaa03f4060baa970cceabd1775 Mon Sep 17 00:00:00 2001 From: Raf Ponsaerts Date: Tue, 29 Sep 2020 14:18:15 +0200 Subject: [PATCH] [Task 72956] further development on delete eperson --- .../epeople-registry.component.ts | 30 ++++++++++++------- src/app/core/data/data.service.ts | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) 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 aa237531b8..b8a6474721 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 @@ -20,6 +20,9 @@ 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 { ObjectCacheService } from "../../../core/cache/object-cache.service"; +import { tap } from "rxjs/internal/operators/tap"; +import { filter } from "rxjs/internal/operators/filter"; @Component({ selector: 'ds-epeople-registry', @@ -76,7 +79,8 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy { private formBuilder: FormBuilder, private router: Router, private modalService: NgbModal, - public requestService: RequestService) { + public requestService: RequestService, + public objectCache: ObjectCacheService) { this.currentSearchQuery = ''; this.currentSearchScope = 'metadata'; this.searchForm = this.formBuilder.group(({ @@ -138,15 +142,15 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy { this.currentSearchScope = scope; this.config.currentPage = 1; } - this.epersonService.searchByScope(this.currentSearchScope, this.currentSearchQuery, { + this.subs.push(this.epersonService.searchByScope(this.currentSearchScope, this.currentSearchQuery, { currentPage: this.config.currentPage, elementsPerPage: this.config.pageSize }).subscribe((peopleRD) => { this.ePeople$.next(peopleRD) } - ); + )); - this.ePeople$.pipe( + this.subs.push(this.ePeople$.pipe( getAllSucceededRemoteDataPayload(), switchMap((epeople) => { return combineLatest(...epeople.page.map((eperson) => { @@ -161,7 +165,7 @@ 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))); } /** @@ -232,6 +236,10 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy { * Unsub all subscriptions */ ngOnDestroy(): void { + this.cleanupSubscribes(); + } + + cleanupSubscribes() { this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe()); } @@ -259,11 +267,13 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy { * This method will ensure that the page gets reset and that the cache is cleared */ reset() { - this.ePeopleDto$.pipe(take(1)).subscribe((epersons: PaginatedList) => { - epersons.page.forEach((eperson: EpersonDtoModel) => { - this.requestService.removeByHrefSubstring(eperson.eperson.self); - }) + this.epersonService.getSearchByHref("byMetadata", {}).pipe( + switchMap((href) => this.requestService.removeByHrefSubstring(href)), + filter((isCached) => isCached), + take(1) + ).subscribe(() => { + this.cleanupSubscribes(); + this.initialisePage(); }); - this.initialisePage(); } } diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 0d818f2030..dca6988473 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -89,7 +89,7 @@ export abstract class DataService implements UpdateDa * Return an observable that emits created HREF * @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved */ - protected getSearchByHref(searchMethod: string, options: FindListOptions = {}, ...linksToFollow: Array>): Observable { + public getSearchByHref(searchMethod: string, options: FindListOptions = {}, ...linksToFollow: Array>): Observable { let result$: Observable; const args = [];