verify whether file uploads are mandatory => observe changes to both filelist and required status

This commit is contained in:
Ben Bosman
2020-01-31 09:47:40 +01:00
parent 17989667aa
commit a45273048d
2 changed files with 10 additions and 6 deletions

View File

@@ -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 }}",

View File

@@ -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<boolean>(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<boolean> {
// 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));
});
}
/**