From 41e1d0659438e7e9dad5052a53d5e3350b49f5e5 Mon Sep 17 00:00:00 2001 From: lotte Date: Thu, 1 Apr 2021 12:23:26 +0200 Subject: [PATCH] applied feedback for submission upload section --- .../form/submission-form.component.spec.ts | 9 +++++---- .../form/submission-form.component.ts | 17 +++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/app/submission/form/submission-form.component.spec.ts b/src/app/submission/form/submission-form.component.spec.ts index d719472adf..94d1033079 100644 --- a/src/app/submission/form/submission-form.component.spec.ts +++ b/src/app/submission/form/submission-form.component.spec.ts @@ -24,7 +24,7 @@ import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-servic import { createTestComponent } from '../../shared/testing/utils.test'; import { Item } from '../../core/shared/item.model'; import { TestScheduler } from 'rxjs/testing'; - +import { SectionsService } from '../sections/sections.service'; describe('SubmissionFormComponent Component', () => { @@ -55,6 +55,7 @@ describe('SubmissionFormComponent Component', () => { { provide: AuthService, useClass: AuthServiceStub }, { provide: HALEndpointService, useValue: new HALEndpointServiceStub('workspaceitems') }, { provide: SubmissionService, useValue: submissionServiceStub }, + { provide: SectionsService, useValue: { isSectionAvailable: () => observableOf(true) } }, ChangeDetectorRef, SubmissionFormComponent ], @@ -115,7 +116,7 @@ describe('SubmissionFormComponent Component', () => { expect(compAsAny.submissionSections).toBeUndefined(); expect(compAsAny.subs).toEqual([]); expect(submissionServiceStub.startAutoSave).not.toHaveBeenCalled(); - expect(comp.loading).toBeObservable(cold('(a|)', {a: true})); + expect(comp.loading).toBeObservable(cold('(a|)', { a: true })); done(); }); @@ -140,7 +141,7 @@ describe('SubmissionFormComponent Component', () => { }); scheduler.flush(); - expect(comp.submissionSections).toBeObservable(cold('(a|)', {a: sectionsList})); + expect(comp.submissionSections).toBeObservable(cold('(a|)', { a: sectionsList })); expect(submissionServiceStub.dispatchInit).toHaveBeenCalledWith( collectionId, @@ -201,7 +202,7 @@ describe('SubmissionFormComponent Component', () => { submissionDefinition: { name: 'traditional' } - } as any); + } as any); fixture.detectChanges(); }); scheduler.flush(); diff --git a/src/app/submission/form/submission-form.component.ts b/src/app/submission/form/submission-form.component.ts index a2f4443c3a..d5107fb81a 100644 --- a/src/app/submission/form/submission-form.component.ts +++ b/src/app/submission/form/submission-form.component.ts @@ -16,7 +16,7 @@ import { SectionDataObject } from '../sections/models/section-data.model'; import { SubmissionService } from '../submission.service'; import { Item } from '../../core/shared/item.model'; import { SectionsType } from '../sections/sections-type'; -import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject'; +import { SectionsService } from '../sections/sections.service'; /** * This component represents the submission form. @@ -74,7 +74,7 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy { /** * Emits true when the submission config has bitstream uploading enabled in submission */ - public uploadEnabled$ = new BehaviorSubject(false); + public uploadEnabled$: Observable; /** * Observable of the list of submission's sections @@ -107,12 +107,14 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy { * @param {ChangeDetectorRef} changeDetectorRef * @param {HALEndpointService} halService * @param {SubmissionService} submissionService + * @param {SectionsService} sectionsService */ constructor( private authService: AuthService, private changeDetectorRef: ChangeDetectorRef, private halService: HALEndpointService, - private submissionService: SubmissionService) { + private submissionService: SubmissionService, + private sectionsService: SectionsService) { this.isActive = true; } @@ -135,12 +137,11 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy { } else { return observableOf([]); } - }), - tap((sectionList) => { - this.uploadEnabled$.next(isNotEmpty(sectionList) && sectionList.some(config => config.sectionType === SectionsType.Upload)); - }) - ); + })); + debugger; + this.uploadEnabled$ = this.sectionsService.isSectionAvailable(this.submissionId, SectionsType.Upload); + this.uploadEnabled$.subscribe((t) => {console.log('this.uploadEnabled$', t)}); // check if is submission loading this.loading = this.submissionService.getSubmissionObject(this.submissionId).pipe( filter(() => this.isActive),