mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 13:33:03 +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 { Router } from '@angular/router';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { Observable } from 'rxjs';
|
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 { ComColDataService } from '../../../core/data/comcol-data.service';
|
||||||
import { CommunityDataService } from '../../../core/data/community-data.service';
|
import { CommunityDataService } from '../../../core/data/community-data.service';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
import { RouteService } from '../../../core/services/route.service';
|
import { RouteService } from '../../../core/services/route.service';
|
||||||
import { Community } from '../../../core/shared/community.model';
|
import { Community } from '../../../core/shared/community.model';
|
||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.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 { 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 { NotificationsService } from '../../notifications/notifications.service';
|
||||||
import { RequestParam } from '../../../core/cache/models/request-param.model';
|
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
|
* Component representing the create page for communities and collections
|
||||||
@@ -54,7 +60,8 @@ export class CreateComColPageComponent<TDomain extends DSpaceObject> implements
|
|||||||
protected routeService: RouteService,
|
protected routeService: RouteService,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected notificationsService: NotificationsService,
|
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 dso = event.dso;
|
||||||
const uploader = event.uploader;
|
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)] : [];
|
const params = uuid ? [new RequestParam('parent', uuid)] : [];
|
||||||
this.dsoDataService.create(dso, ...params)
|
return this.dsoDataService.create(dso, ...params)
|
||||||
.pipe(getSucceededRemoteData())
|
.pipe(getFirstSucceededRemoteDataPayload()
|
||||||
.subscribe((dsoRD: RemoteData<TDomain>) => {
|
)
|
||||||
if (isNotUndefined(dsoRD)) {
|
}))
|
||||||
this.newUUID = dsoRD.payload.uuid;
|
.subscribe((dsoRD: TDomain) => {
|
||||||
if (uploader.queue.length > 0) {
|
if (isNotUndefined(dsoRD)) {
|
||||||
this.dsoDataService.getLogoEndpoint(this.newUUID).pipe(take(1)).subscribe((href: string) => {
|
this.newUUID = dsoRD.uuid;
|
||||||
uploader.options.url = href;
|
if (uploader.queue.length > 0) {
|
||||||
uploader.uploadAll();
|
this.dsoDataService.getLogoEndpoint(this.newUUID).pipe(take(1)).subscribe((href: string) => {
|
||||||
});
|
uploader.options.url = href;
|
||||||
} else {
|
uploader.uploadAll();
|
||||||
this.navigateToNewPage();
|
});
|
||||||
}
|
} else {
|
||||||
this.notificationsService.success(null, this.translate.get(this.type.value + '.create.notifications.success'));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,18 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import { Observable } from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import {RemoteData} from '../../../core/data/remote-data';
|
||||||
import { first, map } from 'rxjs/operators';
|
import {first, map, take} from 'rxjs/operators';
|
||||||
import { DataService } from '../../../core/data/data.service';
|
import {DataService} from '../../../core/data/data.service';
|
||||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
import {DSpaceObject} from '../../../core/shared/dspace-object.model';
|
||||||
import { NotificationsService } from '../../notifications/notifications.service';
|
import {NotificationsService} from '../../notifications/notifications.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import {TranslateService} from '@ngx-translate/core';
|
||||||
import { RestResponse } from '../../../core/cache/response.models';
|
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
|
* Component representing the delete page for communities and collections
|
||||||
@@ -31,7 +36,8 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
|
|||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected notifications: NotificationsService,
|
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) {
|
if (response.isSuccessful) {
|
||||||
const successMessage = this.translate.instant((dso as any).type + '.delete.notification.success');
|
const successMessage = this.translate.instant((dso as any).type + '.delete.notification.success');
|
||||||
this.notifications.success(successMessage)
|
this.notifications.success(successMessage)
|
||||||
|
this.refreshCache(dso);
|
||||||
} else {
|
} else {
|
||||||
const errorMessage = this.translate.instant((dso as any).type + '.delete.notification.fail');
|
const errorMessage = this.translate.instant((dso as any).type + '.delete.notification.fail');
|
||||||
this.notifications.error(errorMessage)
|
this.notifications.error(errorMessage)
|
||||||
@@ -65,4 +72,22 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
|
|||||||
onCancel(dso: TDomain) {
|
onCancel(dso: TDomain) {
|
||||||
this.router.navigate([this.frontendURL + '/' + dso.uuid + '/edit']);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user