diff --git a/src/app/+collection-page/collection-form/collection-form.component.ts b/src/app/+collection-page/collection-form/collection-form.component.ts index a1d6a08290..76ba549f14 100644 --- a/src/app/+collection-page/collection-form/collection-form.component.ts +++ b/src/app/+collection-page/collection-form/collection-form.component.ts @@ -8,6 +8,8 @@ import { TranslateService } from '@ngx-translate/core'; import { NotificationsService } from '../../shared/notifications/notifications.service'; import { CommunityDataService } from '../../core/data/community-data.service'; import { AuthService } from '../../core/auth/auth.service'; +import { RequestService } from '../../core/data/request.service'; +import { ObjectCacheService } from '../../core/cache/object-cache.service'; /** * Form used for creating and editing collections @@ -75,7 +77,9 @@ export class CollectionFormComponent extends ComColFormComponent { protected translate: TranslateService, protected notificationsService: NotificationsService, protected authService: AuthService, - protected dsoService: CommunityDataService) { - super(location, formService, translate, notificationsService, authService); + protected dsoService: CommunityDataService, + protected requestService: RequestService, + protected objectCache: ObjectCacheService) { + super(location, formService, translate, notificationsService, authService, requestService, objectCache); } } diff --git a/src/app/+community-page/community-form/community-form.component.ts b/src/app/+community-page/community-form/community-form.component.ts index 8e4f98c14e..1f081bd81b 100644 --- a/src/app/+community-page/community-form/community-form.component.ts +++ b/src/app/+community-page/community-form/community-form.component.ts @@ -9,6 +9,8 @@ import { TranslateService } from '@ngx-translate/core'; import { NotificationsService } from '../../shared/notifications/notifications.service'; import { CommunityDataService } from '../../core/data/community-data.service'; import { AuthService } from '../../core/auth/auth.service'; +import { RequestService } from '../../core/data/request.service'; +import { ObjectCacheService } from '../../core/cache/object-cache.service'; /** * Form used for creating and editing communities @@ -68,7 +70,9 @@ export class CommunityFormComponent extends ComColFormComponent { protected translate: TranslateService, protected notificationsService: NotificationsService, protected authService: AuthService, - protected dsoService: CommunityDataService) { - super(location, formService, translate, notificationsService, authService); + protected dsoService: CommunityDataService, + protected requestService: RequestService, + protected objectCache: ObjectCacheService) { + super(location, formService, translate, notificationsService, authService, requestService, objectCache); } } diff --git a/src/app/core/data/comcol-data.service.ts b/src/app/core/data/comcol-data.service.ts index ba17d04d76..60bd837163 100644 --- a/src/app/core/data/comcol-data.service.ts +++ b/src/app/core/data/comcol-data.service.ts @@ -1,6 +1,6 @@ import { distinctUntilChanged, filter, map, mergeMap, share, switchMap, take, tap } from 'rxjs/operators'; -import { merge as observableMerge, Observable, throwError as observableThrowError } from 'rxjs'; -import { isEmpty, isNotEmpty } from '../../shared/empty.util'; +import { merge as observableMerge, Observable, throwError as observableThrowError, combineLatest as observableCombineLatest } from 'rxjs'; +import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util'; import { NormalizedCommunity } from '../cache/models/normalized-community.model'; import { ObjectCacheService } from '../cache/object-cache.service'; import { CommunityDataService } from './community-data.service'; @@ -8,15 +8,27 @@ import { CommunityDataService } from './community-data.service'; import { DataService } from './data.service'; import { DeleteRequest, FindAllOptions, FindByIDRequest, RestRequest } from './request.models'; import { HALEndpointService } from '../shared/hal-endpoint.service'; -import { configureRequest, getResponseFromEntry } from '../shared/operators'; +import { + configureRequest, + getRemoteDataPayload, + getResponseFromEntry, + getSucceededRemoteData +} from '../shared/operators'; import { CacheableObject } from '../cache/object-cache.reducer'; import { RestResponse } from '../cache/response.models'; +import { Bitstream } from '../shared/bitstream.model'; +import { DSpaceObject } from '../shared/dspace-object.model'; export abstract class ComColDataService extends DataService { protected abstract cds: CommunityDataService; protected abstract objectCache: ObjectCacheService; protected abstract halService: HALEndpointService; + /** + * Linkpath of endpoint to delete the logo + */ + protected logoDeleteLinkpath = 'bitstreams'; + /** * Get the scoped endpoint URL by fetching the object with * the given scopeID and returning its HAL link with this @@ -71,14 +83,21 @@ export abstract class ComColDataService extends DataS /** * Delete the logo from the community or collection - * @param id The community or collection's ID + * @param dso The object to delete the logo from */ - public deleteLogo(id: string): Observable { - return this.getLogoEndpoint(id).pipe( - map((href: string) => new DeleteRequest(this.requestService.generateRequestId(), href)), - configureRequest(this.requestService), - switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)), - getResponseFromEntry() - ); + public deleteLogo(dso: DSpaceObject): Observable { + const logo$ = (dso as any).logo; + if (hasValue(logo$)) { + return observableCombineLatest( + logo$.pipe(getSucceededRemoteData(), getRemoteDataPayload(), take(1)), + this.halService.getEndpoint(this.logoDeleteLinkpath) + ).pipe( + map(([logo, href]: [Bitstream, string]) => `${href}/${logo.id}`), + map((href: string) => new DeleteRequest(this.requestService.generateRequestId(), href)), + configureRequest(this.requestService), + switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)), + getResponseFromEntry() + ); + } } } diff --git a/src/app/shared/comcol-forms/comcol-form/comcol-form.component.html b/src/app/shared/comcol-forms/comcol-form/comcol-form.component.html index b65e6e8f80..fafe796107 100644 --- a/src/app/shared/comcol-forms/comcol-form/comcol-form.component.html +++ b/src/app/shared/comcol-forms/comcol-form/comcol-form.component.html @@ -1,20 +1,30 @@
- - - -
- +
+
+
- - + +
+ +
+
+
+ +
+
+
+ +
+
+
implements OnInit, OnDe * @type {UploaderOptions} */ uploadFilesOptions: UploaderOptions = Object.assign(new UploaderOptions(), { - disableMultipart: true, autoUpload: false }); @@ -112,7 +114,9 @@ export class ComColFormComponent implements OnInit, OnDe protected formService: DynamicFormService, protected translate: TranslateService, protected notificationsService: NotificationsService, - protected authService: AuthService) { + protected authService: AuthService, + protected requestService: RequestService, + protected objectCache: ObjectCacheService) { } ngOnInit(): void { @@ -204,7 +208,7 @@ export class ComColFormComponent implements OnInit, OnDe */ deleteLogo() { if (hasValue(this.dso.id)) { - this.dsoService.deleteLogo(this.dso.id).subscribe((response: RestResponse) => { + this.dsoService.deleteLogo(this.dso).subscribe((response: RestResponse) => { if (response.isSuccessful) { this.notificationsService.success( this.translate.get(this.type.value + '.edit.logo.notifications.delete.success.title'), @@ -217,14 +221,25 @@ export class ComColFormComponent implements OnInit, OnDe errorResponse.errorMessage ); } + this.refreshCache(); }); } } + /** + * Refresh the object's cache to ensure the latest version + */ + private refreshCache() { + (this.dso as any).logo = undefined; + this.requestService.removeByHrefSubstring(this.dso.self); + this.objectCache.remove(this.dso.self); + } + /** * The request was successful, display a success notification */ public onCompleteItem() { + this.refreshCache(); this.notificationsService.success(null, this.translate.get(this.type.value + '.edit.logo.notifications.add.success')); this.finishUpload.emit(); }