[CSTPER-66] when a community or a collection is created or deleted, angular cache is refreshed so that in case of new community or collection it appears immediately in pages where communities and collections lists are displayed, in case of community or collection deletion deleted community or collection does not appear anymore in pages where communities and collections lists are displayed.

This commit is contained in:
Corrado Lombardi
2020-10-22 15:50:44 +02:00
parent 20c7afce06
commit be6a6a2f62
4 changed files with 226 additions and 24 deletions

View File

@@ -10,7 +10,9 @@ import {TranslateService} from '@ngx-translate/core';
import {RestResponse} from '../../../core/cache/response.models';
import {hasValue, isEmpty, isNotEmpty} from '../../empty.util';
import {RequestService} from '../../../core/data/request.service';
import {getRemoteDataPayload, getSucceededRemoteData} from '../../../core/shared/operators';
import {
getSucceededOrNoContentResponse,
} from '../../../core/shared/operators';
import {Community} from '../../../core/shared/community.model';
import {Collection} from '../../../core/shared/collection.model';
@@ -74,16 +76,17 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
}
private refreshCache(dso: TDomain) {
const parentCommunity = this.parentCommunityUrl(dso as any);
if (!hasValue(parentCommunity)) {
const parentCommunityUrl = this.parentCommunityUrl(dso as any);
if (!hasValue(parentCommunityUrl)) {
return;
}
this.dsoDataService.findByHref(parentCommunity).pipe(
getSucceededRemoteData(),
getRemoteDataPayload(),
map((pc: TDomain) => isEmpty(pc) ? 'communities/search/top' : pc.id ),
take(1)
).subscribe((id: string) => this.requestService.removeByHrefSubstring(id));
this.dsoDataService.findByHref(parentCommunityUrl).pipe(
getSucceededOrNoContentResponse(),
take(1),
).subscribe((rd: RemoteData<TDomain>) => {
const href = rd.hasSucceeded && !isEmpty(rd.payload.id) ? rd.payload.id : 'communities/search/top';
this.requestService.removeByHrefSubstring(href)
});
}
private parentCommunityUrl(dso: Collection | Community): string {