65240: ComCol logo delete on bitstreams endpoint + caching issue fixes when editing logos

This commit is contained in:
Kristof De Langhe
2019-10-17 17:59:18 +02:00
parent bfb2ef021a
commit c7bb6ab17c
5 changed files with 85 additions and 33 deletions

View File

@@ -1,20 +1,30 @@
<div class="container-fluid">
<label>{{type.value + '.edit.logo.label' | translate}}</label>
<ng-container *ngVar="(dso?.logo | async)?.payload as logo">
<ds-comcol-page-logo [logo]="logo"></ds-comcol-page-logo>
<div *ngIf="logo" class="btn-group btn-group-sm float-right" role="group">
<button type="button" class="btn btn-danger" (click)="deleteLogo()">
<i class="fas fa-trash" aria-hidden="true"></i>
</button>
<div class="row">
<div class="col-12 d-inline-block">
<label>{{type.value + '.edit.logo.label' | translate}}</label>
</div>
</ng-container>
<ds-uploader *ngIf="initializedUploaderOptions | async"
[dropMsg]="type.value + '.edit.logo.upload'"
[dropOverDocumentMsg]="type.value + '.edit.logo.upload'"
[enableDragOverDocument]="true"
[uploadFilesOptions]="uploadFilesOptions"
(onCompleteItem)="onCompleteItem()"
(onUploadError)="onUploadError()"></ds-uploader>
<ng-container *ngVar="(dso?.logo | async)?.payload as logo">
<div class="col-8 d-inline-block">
<ds-comcol-page-logo [logo]="logo"></ds-comcol-page-logo>
</div>
<div class="col-4 d-inline-block">
<div *ngIf="logo" class="btn-group btn-group-sm float-right" role="group">
<button type="button" class="btn btn-danger" (click)="deleteLogo()">
<i class="fas fa-trash" aria-hidden="true"></i>
</button>
</div>
</div>
<div *ngIf="!logo" class="col-12 d-inline-block">
<ds-uploader *ngIf="initializedUploaderOptions | async"
[dropMsg]="type.value + '.edit.logo.upload'"
[dropOverDocumentMsg]="type.value + '.edit.logo.upload'"
[enableDragOverDocument]="true"
[uploadFilesOptions]="uploadFilesOptions"
(onCompleteItem)="onCompleteItem()"
(onUploadError)="onUploadError()"></ds-uploader>
</div>
</ng-container>
</div>
</div>
<ds-form *ngIf="formModel"
[formId]="'comcol-form-id'"

View File

@@ -23,6 +23,9 @@ import { RemoteData } from '../../../core/data/remote-data';
import { Bitstream } from '../../../core/shared/bitstream.model';
import { combineLatest as observableCombineLatest } from 'rxjs';
import { RestRequestMethod } from '../../../core/data/rest-request-method';
import { RequestService } from '../../../core/data/request.service';
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
import { take } from 'rxjs/operators';
/**
* A form for creating and editing Communities or Collections
@@ -74,7 +77,6 @@ export class ComColFormComponent<T extends DSpaceObject> implements OnInit, OnDe
* @type {UploaderOptions}
*/
uploadFilesOptions: UploaderOptions = Object.assign(new UploaderOptions(), {
disableMultipart: true,
autoUpload: false
});
@@ -112,7 +114,9 @@ export class ComColFormComponent<T extends DSpaceObject> 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<T extends DSpaceObject> 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<T extends DSpaceObject> 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();
}