[Task 72956] fixed EPerson deletion issues with page not refreshing

This commit is contained in:
Raf Ponsaerts
2020-09-30 14:46:03 +02:00
parent e12559544b
commit 5615390ce5
3 changed files with 21 additions and 53 deletions

View File

@@ -4,7 +4,7 @@
<h2 id="header" class="border-bottom pb-2">{{labelPrefix + 'head' | translate}}</h2> <h2 id="header" class="border-bottom pb-2">{{labelPrefix + 'head' | translate}}</h2>
<ds-eperson-form *ngIf="isEPersonFormShown" (submitForm)="forceUpdateEPeople()" <ds-eperson-form *ngIf="isEPersonFormShown" (submitForm)="reset()"
(cancelForm)="isEPersonFormShown = false"></ds-eperson-form> (cancelForm)="isEPersonFormShown = false"></ds-eperson-form>
<div *ngIf="!isEPersonFormShown"> <div *ngIf="!isEPersonFormShown">
@@ -42,8 +42,8 @@
<ds-pagination <ds-pagination
*ngIf="(ePeopleDto$ | async)?.totalElements > 0" *ngIf="(ePeopleDto$ | async)?.totalElements > 0"
[paginationOptions]="config" [paginationOptions]="config"
[pageInfoState]="(ePeopleDto$ | async)?.pageInfo" [pageInfoState]="pageInfoState$"
[collectionSize]="(ePeopleDto$ | async)?.totalElements" [collectionSize]="(pageInfoState$ | async)?.totalElements"
[hideGear]="true" [hideGear]="true"
[hidePagerWhenSinglePage]="true" [hidePagerWhenSinglePage]="true"
(pageChange)="onPageChange($event)"> (pageChange)="onPageChange($event)">
@@ -85,7 +85,7 @@
</ds-pagination> </ds-pagination>
<div *ngIf="(ePeopleDto$ | async)?.totalElements == 0" class="alert alert-info w-100 mb-2" role="alert"> <div *ngIf="(pageInfoState$ | async)?.totalElements == 0" class="alert alert-info w-100 mb-2" role="alert">
{{labelPrefix + 'no-items' | translate}} {{labelPrefix + 'no-items' | translate}}
</div> </div>
</div> </div>

View File

@@ -2,7 +2,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder } from '@angular/forms'; import { FormBuilder } from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core'; 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 { Subscription } from 'rxjs/internal/Subscription';
import { map, switchMap, take } from 'rxjs/operators'; import { map, switchMap, take } from 'rxjs/operators';
import { PaginatedList } from '../../../core/data/paginated-list'; 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 { 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 { filter } from "rxjs/internal/operators/filter"; import { filter } from 'rxjs/internal/operators/filter';
import { PageInfo } from '../../../core/shared/page-info.model';
@Component({ @Component({
selector: 'ds-epeople-registry', selector: 'ds-epeople-registry',
@@ -44,6 +45,11 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
*/ */
ePeopleDto$: BehaviorSubject<PaginatedList<EpersonDtoModel>> = new BehaviorSubject<PaginatedList<EpersonDtoModel>>({} as any); ePeopleDto$: BehaviorSubject<PaginatedList<EpersonDtoModel>> = new BehaviorSubject<PaginatedList<EpersonDtoModel>>({} as any);
/**
* An observable for the pageInfo, needed to pass to the pagination component
*/
pageInfoState$: BehaviorSubject<PageInfo> = new BehaviorSubject<PageInfo>(undefined);
/** /**
* Pagination config used to display the list of epeople * Pagination config used to display the list of epeople
*/ */
@@ -108,18 +114,10 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
* @param event * @param event
*/ */
onPageChange(event) { onPageChange(event) {
if (this.config.currentPage !== event) {
this.config.currentPage = event; this.config.currentPage = event;
this.search({ scope: this.currentSearchScope, query: this.currentSearchQuery }) 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' })
} }
/** /**
@@ -162,7 +160,10 @@ 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);
this.pageInfoState$.next(value.pageInfo);
}));
} }
/** /**
@@ -217,12 +218,9 @@ export class EPeopleRegistryComponent implements OnInit, OnDestroy {
if (restResponse.isSuccessful) { if (restResponse.isSuccessful) {
this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', { name: ePerson.name })); this.notificationsService.success(this.translateService.get(this.labelPrefix + 'notification.deleted.success', { name: ePerson.name }));
this.reset(); this.reset();
this.forceUpdateEPeople();
} else { } else {
this.notificationsService.error('Error occured when trying to delete EPerson with id: ' + ePerson.id + ' with code: ' + restResponse.statusCode + ' and message: ' + restResponse.statusText); 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 * This method will ensure that the page gets reset and that the cache is cleared
*/ */
reset() { reset() {
this.epersonService.getSearchByHref("byMetadata", {}).pipe( this.epersonService.getBrowseEndpoint().pipe(
switchMap((href) => this.requestService.removeByHrefSubstring(href)), switchMap((href) => this.requestService.removeByHrefSubstring(href)),
filter((isCached) => isCached), filter((isCached) => isCached),
take(1) take(1)

View File

@@ -299,34 +299,4 @@ export class EPersonDataService extends DataService<EPerson> {
map((request: RequestEntry) => request.response) 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<RemoteData<PaginatedList<EPerson>>}
* Return an observable that emits response from the server
*/
searchBy(searchMethod: string, options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<EPerson>>): Observable<RemoteData<PaginatedList<EPerson>>> {
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<EPerson>(hrefObs, ...linksToFollow) as Observable<RemoteData<PaginatedList<EPerson>>>
)
);
}
} }