diff --git a/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.ts b/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.ts index 26ed4110b3..342e3f44e3 100644 --- a/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.ts +++ b/src/app/+my-dspace-page/my-dspace-new-submission/my-dspace-new-submission.component.ts @@ -30,13 +30,7 @@ export class MyDSpaceNewSubmissionComponent implements OnDestroy, OnInit { /** * The UploaderOptions object */ - public uploadFilesOptions: UploaderOptions = { - url: '', - authToken: null, - disableMultipart: false, - itemAlias: null, - autoUpload: true - }; + public uploadFilesOptions: UploaderOptions = new UploaderOptions(); /** * Subscription to unsubscribe from diff --git a/src/app/shared/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol-forms/comcol-form/comcol-form.component.ts index 06c507b3ea..6e8b04e589 100644 --- a/src/app/shared/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol-forms/comcol-form/comcol-form.component.ts @@ -1,16 +1,13 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'; import { Location } from '@angular/common'; -import { - DynamicFormService, - DynamicInputModel -} from '@ng-dynamic-forms/core'; +import { DynamicFormService, DynamicInputModel } from '@ng-dynamic-forms/core'; import { FormGroup } from '@angular/forms'; import { DynamicFormControlModel } from '@ng-dynamic-forms/core/src/model/dynamic-form-control.model'; import { TranslateService } from '@ngx-translate/core'; import { DSpaceObject } from '../../../core/shared/dspace-object.model'; import { MetadataMap, MetadataValue } from '../../../core/shared/metadata.models'; import { ResourceType } from '../../../core/shared/resource-type'; -import { hasValue, isNotEmpty, isUndefined } from '../../empty.util'; +import { hasValue, isNotEmpty } from '../../empty.util'; import { UploaderOptions } from '../../uploader/uploader-options.model'; import { NotificationsService } from '../../notifications/notifications.service'; import { ComColDataService } from '../../../core/data/comcol-data.service'; @@ -22,6 +19,10 @@ import { UploaderComponent } from '../../uploader/uploader.component'; import { FileUploader } from 'ng2-file-upload'; import { ErrorResponse, RestResponse } from '../../../core/cache/response.models'; import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject'; +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'; /** * A form for creating and editing Communities or Collections @@ -72,13 +73,10 @@ export class ComColFormComponent implements OnInit, OnDe * The uploader configuration options * @type {UploaderOptions} */ - uploadFilesOptions: UploaderOptions = { - url: '', - authToken: null, + uploadFilesOptions: UploaderOptions = Object.assign(new UploaderOptions(), { disableMultipart: true, - itemAlias: null, autoUpload: false - }; + }); /** * Emits DSO and Uploader when the form is submitted @@ -133,9 +131,16 @@ export class ComColFormComponent implements OnInit, OnDe if (hasValue(this.dso.id)) { this.subs.push( - this.dsoService.getLogoEndpoint(this.dso.id).subscribe((href: string) => { + observableCombineLatest( + this.dsoService.getLogoEndpoint(this.dso.id), + (this.dso as any).logo + ).subscribe(([href, logoRD]: [string, RemoteData]) => { this.uploadFilesOptions.url = href; this.uploadFilesOptions.authToken = this.authService.buildAuthHeader(); + // If the object already contains a logo, send out a PUT request instead of POST for setting a new logo + if (hasValue(logoRD.payload)) { + this.uploadFilesOptions.method = RestRequestMethod.PUT; + } this.initializedUploaderOptions.next(true); }) ); @@ -232,6 +237,9 @@ export class ComColFormComponent implements OnInit, OnDe this.finishUpload.emit(); } + /** + * Cancel the form and return to the previous page + */ onCancel() { this.location.back(); } diff --git a/src/app/shared/uploader/uploader-options.model.ts b/src/app/shared/uploader/uploader-options.model.ts index fa77a36d11..f195b0930e 100644 --- a/src/app/shared/uploader/uploader-options.model.ts +++ b/src/app/shared/uploader/uploader-options.model.ts @@ -1,3 +1,4 @@ +import { RestRequestMethod } from '../../core/data/rest-request-method'; export class UploaderOptions { /** @@ -9,7 +10,15 @@ export class UploaderOptions { disableMultipart = false; - itemAlias: string; + itemAlias: string = null; + /** + * Automatically send out an upload request when adding files + */ autoUpload = true; + + /** + * The request method to use for the file upload request + */ + method: RestRequestMethod = RestRequestMethod.POST; } diff --git a/src/app/shared/uploader/uploader.component.ts b/src/app/shared/uploader/uploader.component.ts index 794b5cb4b3..935d196d08 100644 --- a/src/app/shared/uploader/uploader.component.ts +++ b/src/app/shared/uploader/uploader.component.ts @@ -95,7 +95,8 @@ export class UploaderComponent { disableMultipart: this.uploadFilesOptions.disableMultipart, itemAlias: this.uploadFilesOptions.itemAlias, removeAfterUpload: true, - autoUpload: this.uploadFilesOptions.autoUpload + autoUpload: this.uploadFilesOptions.autoUpload, + method: this.uploadFilesOptions.method }); if (isUndefined(this.enableDragOverDocument)) { diff --git a/src/app/submission/form/submission-form.component.ts b/src/app/submission/form/submission-form.component.ts index 7ed7bec04b..a11ad43db3 100644 --- a/src/app/submission/form/submission-form.component.ts +++ b/src/app/submission/form/submission-form.component.ts @@ -77,13 +77,7 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy { * The uploader configuration options * @type {UploaderOptions} */ - public uploadFilesOptions: UploaderOptions = { - url: '', - authToken: null, - disableMultipart: false, - itemAlias: null, - autoUpload: true - }; + public uploadFilesOptions: UploaderOptions = new UploaderOptions(); /** * A boolean representing if component is active