mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
cache cleared with parent community reference once a collection or a community is created or deleted
This commit is contained in:
@@ -2,18 +2,24 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { take } from 'rxjs/operators';
|
||||
import {flatMap, map, take} from 'rxjs/operators';
|
||||
import { ComColDataService } from '../../../core/data/comcol-data.service';
|
||||
import { CommunityDataService } from '../../../core/data/community-data.service';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { RouteService } from '../../../core/services/route.service';
|
||||
import { Community } from '../../../core/shared/community.model';
|
||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||
import { getSucceededRemoteData } from '../../../core/shared/operators';
|
||||
import {
|
||||
getFirstSucceededRemoteDataPayload,
|
||||
getRemoteDataPayload,
|
||||
getSucceededRemoteData
|
||||
} from '../../../core/shared/operators';
|
||||
import { ResourceType } from '../../../core/shared/resource-type';
|
||||
import { hasValue, isNotEmpty, isNotUndefined } from '../../empty.util';
|
||||
import {hasValue, isEmpty, isNotEmpty, isNotUndefined} from '../../empty.util';
|
||||
import { NotificationsService } from '../../notifications/notifications.service';
|
||||
import { RequestParam } from '../../../core/cache/models/request-param.model';
|
||||
import {RequestService} from '../../../core/data/request.service';
|
||||
import {Collection} from '../../../core/shared/collection.model';
|
||||
|
||||
/**
|
||||
* Component representing the create page for communities and collections
|
||||
@@ -54,7 +60,8 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
|
||||
protected routeService: RouteService,
|
||||
protected router: Router,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected translate: TranslateService
|
||||
protected translate: TranslateService,
|
||||
protected requestService: RequestService
|
||||
) {
|
||||
|
||||
}
|
||||
@@ -76,25 +83,29 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
|
||||
const dso = event.dso;
|
||||
const uploader = event.uploader;
|
||||
|
||||
this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => {
|
||||
this.parentUUID$.pipe(
|
||||
take(1),
|
||||
flatMap((uuid: string) => {
|
||||
const params = uuid ? [new RequestParam('parent', uuid)] : [];
|
||||
this.dsoDataService.create(dso, ...params)
|
||||
.pipe(getSucceededRemoteData())
|
||||
.subscribe((dsoRD: RemoteData<TDomain>) => {
|
||||
if (isNotUndefined(dsoRD)) {
|
||||
this.newUUID = dsoRD.payload.uuid;
|
||||
if (uploader.queue.length > 0) {
|
||||
this.dsoDataService.getLogoEndpoint(this.newUUID).pipe(take(1)).subscribe((href: string) => {
|
||||
uploader.options.url = href;
|
||||
uploader.uploadAll();
|
||||
});
|
||||
} else {
|
||||
this.navigateToNewPage();
|
||||
}
|
||||
this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success'));
|
||||
return this.dsoDataService.create(dso, ...params)
|
||||
.pipe(getFirstSucceededRemoteDataPayload()
|
||||
)
|
||||
}))
|
||||
.subscribe((dsoRD: TDomain) => {
|
||||
if (isNotUndefined(dsoRD)) {
|
||||
this.newUUID = dsoRD.uuid;
|
||||
if (uploader.queue.length > 0) {
|
||||
this.dsoDataService.getLogoEndpoint(this.newUUID).pipe(take(1)).subscribe((href: string) => {
|
||||
uploader.options.url = href;
|
||||
uploader.uploadAll();
|
||||
});
|
||||
} else {
|
||||
this.navigateToNewPage();
|
||||
}
|
||||
});
|
||||
});
|
||||
this.refreshCache(dsoRD);
|
||||
}
|
||||
this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,4 +117,21 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
|
||||
}
|
||||
}
|
||||
|
||||
private refreshCache(dso: TDomain) {
|
||||
const parentCommunityUrl = this.parentCommunityUrl(dso as any);
|
||||
if (!hasValue(parentCommunityUrl)) {
|
||||
return;
|
||||
}
|
||||
this.dsoDataService.findByHref(parentCommunityUrl).pipe(
|
||||
getSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
map((pc: TDomain) => isEmpty(pc) ? 'communities/search/top' : pc.id),
|
||||
take(1)
|
||||
).subscribe((href: string) => this.requestService.removeByHrefSubstring(href));
|
||||
}
|
||||
|
||||
private parentCommunityUrl(dso: Collection | Community) {
|
||||
const parentCommunity = dso._links.parentCommunity;
|
||||
return isNotEmpty(parentCommunity) ? parentCommunity.href : null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user