From a45273048d882842728a61f59cea95aa3f09afd8 Mon Sep 17 00:00:00 2001 From: Ben Bosman Date: Fri, 31 Jan 2020 09:47:40 +0100 Subject: [PATCH] verify whether file uploads are mandatory => observe changes to both filelist and required status --- resources/i18n/en.json5 | 2 ++ .../sections/upload/section-upload.component.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/resources/i18n/en.json5 b/resources/i18n/en.json5 index 478f183da4..42eee31e7c 100644 --- a/resources/i18n/en.json5 +++ b/resources/i18n/en.json5 @@ -532,6 +532,8 @@ "error.validation.pattern": "This input is restricted by the current pattern: {{ pattern }}.", + "error.validation.filerequired": "The file upload is mandatory", + "footer.copyright": "copyright © 2002-{{ year }}", diff --git a/src/app/submission/sections/upload/section-upload.component.ts b/src/app/submission/sections/upload/section-upload.component.ts index b4c2a9b30b..6c2506b773 100644 --- a/src/app/submission/sections/upload/section-upload.component.ts +++ b/src/app/submission/sections/upload/section-upload.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectorRef, Component, Inject } from '@angular/core'; -import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs'; +import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription} from 'rxjs'; import { distinctUntilChanged, filter, find, flatMap, map, reduce, take, tap } from 'rxjs/operators'; import { SectionModelComponent } from '../models/section.model'; @@ -108,7 +108,7 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent { * Is the upload required * @type {boolean} */ - public required: boolean; + public required$ = new BehaviorSubject(true); /** * Array to track all subscriptions and unsubscribe them onDestroy @@ -178,7 +178,7 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent { }), flatMap(() => config$), flatMap((config: SubmissionUploadsModel) => { - this.required = config.required; + this.required$.next(config.required); this.availableAccessConditionOptions = isNotEmpty(config.accessConditionOptions) ? config.accessConditionOptions : []; this.collectionPolicyType = this.availableAccessConditionOptions.length > 0 @@ -282,9 +282,11 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent { protected getSectionStatus(): Observable { // if not mandatory, always true // if mandatory, at least one file is required - return this.bitstreamService.getUploadedFileList(this.submissionId, this.sectionData.id).pipe( - map((fileList: any[]) => - (!this.required || (isNotUndefined(fileList) && fileList.length > 0)))); + return observableCombineLatest(this.required$, + this.bitstreamService.getUploadedFileList(this.submissionId, this.sectionData.id), + (required,fileList: any[]) => { + return (!required || (isNotUndefined(fileList) && fileList.length > 0)); + }); } /**