cache cleared with parent community reference once a collection or a community is created or deleted

This commit is contained in:
Corrado Lombardi
2020-09-24 13:03:29 +02:00
parent d9c177b100
commit 367470a912
2 changed files with 85 additions and 32 deletions

View File

@@ -1,13 +1,18 @@
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import { RemoteData } from '../../../core/data/remote-data';
import { first, map } from 'rxjs/operators';
import { DataService } from '../../../core/data/data.service';
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
import { NotificationsService } from '../../notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
import { RestResponse } from '../../../core/cache/response.models';
import {Component, OnInit} from '@angular/core';
import {Observable} from 'rxjs';
import {ActivatedRoute, Router} from '@angular/router';
import {RemoteData} from '../../../core/data/remote-data';
import {first, map, take} from 'rxjs/operators';
import {DataService} from '../../../core/data/data.service';
import {DSpaceObject} from '../../../core/shared/dspace-object.model';
import {NotificationsService} from '../../notifications/notifications.service';
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 {Community} from '../../../core/shared/community.model';
import {Collection} from '../../../core/shared/collection.model';
/**
* Component representing the delete page for communities and collections
@@ -31,7 +36,8 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
protected router: Router,
protected route: ActivatedRoute,
protected notifications: NotificationsService,
protected translate: TranslateService
protected translate: TranslateService,
protected requestService: RequestService
) {
}
@@ -50,6 +56,7 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
if (response.isSuccessful) {
const successMessage = this.translate.instant((dso as any).type + '.delete.notification.success');
this.notifications.success(successMessage)
this.refreshCache(dso);
} else {
const errorMessage = this.translate.instant((dso as any).type + '.delete.notification.fail');
this.notifications.error(errorMessage)
@@ -65,4 +72,22 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
onCancel(dso: TDomain) {
this.router.navigate([this.frontendURL + '/' + dso.uuid + '/edit']);
}
private refreshCache(dso: TDomain) {
const parentCommunity = this.parentCommunityUrl(dso as any);
if (!hasValue(parentCommunity)) {
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));
}
private parentCommunityUrl(dso: Collection | Community): string {
const parentCommunity = dso._links.parentCommunity;
return isNotEmpty(parentCommunity) ? parentCommunity.href : null;
}
}