[Task 72956] further development on delete eperson

This commit is contained in:
Raf Ponsaerts
2020-09-29 14:18:15 +02:00
parent 456551fd94
commit f6fea087c3
2 changed files with 21 additions and 11 deletions

View File

@@ -20,6 +20,9 @@ import { RestResponse } from '../../../core/cache/response.models';
import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component'; import { ConfirmationModalComponent } from '../../../shared/confirmation-modal/confirmation-modal.component';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { RequestService } from '../../../core/data/request.service'; 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({ @Component({
selector: 'ds-epeople-registry', selector: 'ds-epeople-registry',
@@ -76,7 +79,8 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router, private router: Router,
private modalService: NgbModal, private modalService: NgbModal,
public requestService: RequestService) { public requestService: RequestService,
public objectCache: ObjectCacheService) {
this.currentSearchQuery = ''; this.currentSearchQuery = '';
this.currentSearchScope = 'metadata'; this.currentSearchScope = 'metadata';
this.searchForm = this.formBuilder.group(({ this.searchForm = this.formBuilder.group(({
@@ -138,15 +142,15 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
this.currentSearchScope = scope; this.currentSearchScope = scope;
this.config.currentPage = 1; 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, currentPage: this.config.currentPage,
elementsPerPage: this.config.pageSize elementsPerPage: this.config.pageSize
}).subscribe((peopleRD) => { }).subscribe((peopleRD) => {
this.ePeople$.next(peopleRD) this.ePeople$.next(peopleRD)
} }
); ));
this.ePeople$.pipe( this.subs.push(this.ePeople$.pipe(
getAllSucceededRemoteDataPayload(), getAllSucceededRemoteDataPayload(),
switchMap((epeople) => { switchMap((epeople) => {
return combineLatest(...epeople.page.map((eperson) => { return combineLatest(...epeople.page.map((eperson) => {
@@ -161,7 +165,7 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
})).pipe(map((dtos: EpersonDtoModel[]) => { })).pipe(map((dtos: EpersonDtoModel[]) => {
return new PaginatedList(epeople.pageInfo, dtos); 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 * Unsub all subscriptions
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.cleanupSubscribes();
}
cleanupSubscribes() {
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe()); 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 * This method will ensure that the page gets reset and that the cache is cleared
*/ */
reset() { reset() {
this.ePeopleDto$.pipe(take(1)).subscribe((epersons: PaginatedList<EpersonDtoModel>) => { this.epersonService.getSearchByHref("byMetadata", {}).pipe(
epersons.page.forEach((eperson: EpersonDtoModel) => { switchMap((href) => this.requestService.removeByHrefSubstring(href)),
this.requestService.removeByHrefSubstring(eperson.eperson.self); filter((isCached) => isCached),
}) take(1)
).subscribe(() => {
this.cleanupSubscribes();
this.initialisePage();
}); });
this.initialisePage();
} }
} }

View File

@@ -89,7 +89,7 @@ export abstract class DataService<T extends CacheableObject> implements UpdateDa
* Return an observable that emits created HREF * Return an observable that emits created HREF
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved * @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
*/ */
protected getSearchByHref(searchMethod: string, options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<string> { public getSearchByHref(searchMethod: string, options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<string> {
let result$: Observable<string>; let result$: Observable<string>;
const args = []; const args = [];