diff --git a/src/app/submission/form/collection/submission-form-collection.component.html b/src/app/submission/form/collection/submission-form-collection.component.html index c1227eeccc..a78d737640 100644 --- a/src/app/submission/form/collection/submission-form-collection.component.html +++ b/src/app/submission/form/collection/submission-form-collection.component.html @@ -25,7 +25,7 @@ class="btn btn-outline-primary" (blur)="onClose()" (click)="onClose()" - [disabled]="(processingChange$ | async) || collectionModifiable == false" + [disabled]="(processingChange$ | async) || collectionModifiable == false || isReadonly" ngbDropdownToggle> {{ selectedCollectionName$ | async }} diff --git a/src/app/submission/form/collection/submission-form-collection.component.spec.ts b/src/app/submission/form/collection/submission-form-collection.component.spec.ts index 5b9946e1a4..a277e50286 100644 --- a/src/app/submission/form/collection/submission-form-collection.component.spec.ts +++ b/src/app/submission/form/collection/submission-form-collection.component.spec.ts @@ -249,6 +249,12 @@ describe('SubmissionFormCollectionComponent Component', () => { expect(dropDown).toBeFalsy(); }); + it('the dropdown button should be disabled when isReadonly is true', () => { + comp.isReadonly = true; + fixture.detectChanges(); + expect(dropdowBtn.nativeNode.attributes.disabled).toBeDefined(); + }); + it('should be simulated when the drop-down menu is closed', () => { spyOn(comp, 'onClose'); comp.onClose(); diff --git a/src/app/submission/form/collection/submission-form-collection.component.ts b/src/app/submission/form/collection/submission-form-collection.component.ts index 4eac4c506a..70a4cebf45 100644 --- a/src/app/submission/form/collection/submission-form-collection.component.ts +++ b/src/app/submission/form/collection/submission-form-collection.component.ts @@ -64,6 +64,11 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit { */ @Input() submissionId; + /** + * Flag to indicate if the submission dropdown is read only + */ + @Input() isReadonly = false; + /** * An event fired when a different collection is selected. * Event's payload equals to new SubmissionObject. diff --git a/src/app/submission/form/submission-form.component.html b/src/app/submission/form/submission-form.component.html index f75af08f8e..4a916cfe23 100644 --- a/src/app/submission/form/submission-form.component.html +++ b/src/app/submission/form/submission-form.component.html @@ -8,12 +8,15 @@
+ +
{ @@ -156,6 +157,32 @@ describe('SubmissionFormComponent Component', () => { done(); }); + it('should return the visibility object of the collection section', () => { + comp.submissionDefinition = submissionDefinition; + fixture.detectChanges(); + const result = compAsAny.getCollectionVisibility(); + expect(result).toEqual({ + main: VisibilityType.HIDDEN, + other: VisibilityType.HIDDEN, + }); + }); + + it('should return true if collection section visibility is hidden', () => { + comp.submissionDefinition = submissionDefinition; + fixture.detectChanges(); + expect(comp.isSectionHidden).toBe(true); + }); + + it('should return false for isSectionReadonly when collection section visibility is not READONLY', () => { + const visibility = { + main: VisibilityType.READONLY, + other: VisibilityType.READONLY, + }; + comp.submissionDefinition = Object.assign({}, submissionDefinition, { visibility: visibility }); + fixture.detectChanges(); + expect(comp.isSectionReadonly).toBe(false); + }); + it('should update properly on collection change', (done) => { comp.collectionId = collectionId; comp.submissionId = submissionId; diff --git a/src/app/submission/form/submission-form.component.ts b/src/app/submission/form/submission-form.component.ts index 0e17e128bc..216aefcfc3 100644 --- a/src/app/submission/form/submission-form.component.ts +++ b/src/app/submission/form/submission-form.component.ts @@ -9,7 +9,7 @@ import { HALEndpointService } from '../../core/shared/hal-endpoint.service'; import { SubmissionObject } from '../../core/submission/models/submission-object.model'; import { WorkspaceitemSectionsObject } from '../../core/submission/models/workspaceitem-sections.model'; -import { hasValue, isNotEmpty } from '../../shared/empty.util'; +import { hasValue, isNotEmpty, isNotUndefined } from '../../shared/empty.util'; import { UploaderOptions } from '../../shared/upload/uploader/uploader-options.model'; import { SubmissionObjectEntry } from '../objects/submission-objects.reducer'; import { SectionDataObject } from '../sections/models/section-data.model'; @@ -18,6 +18,10 @@ import { Item } from '../../core/shared/item.model'; import { SectionsType } from '../sections/sections-type'; import { SectionsService } from '../sections/sections.service'; import { SubmissionError } from '../objects/submission-error.model'; +import { SubmissionSectionVisibility } from './../../core/config/models/config-submission-section.model'; +import { SubmissionSectionModel } from './../../core/config/models/config-submission-section.model'; +import { VisibilityType } from '../sections/visibility-type'; +import isEqual from 'lodash/isEqual'; /** * This component represents the submission form. @@ -188,6 +192,42 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy { } } + /** + * Returns the visibility object of the collection section + */ + private getCollectionVisibility(): SubmissionSectionVisibility { + const submissionSectionModel: SubmissionSectionModel = + this.submissionDefinition.sections.page.find( + (section) => isEqual(section.sectionType, SectionsType.Collection) + ); + + return isNotUndefined(submissionSectionModel.visibility) ? submissionSectionModel.visibility : null; + } + + /** + * Getter to see if the collection section visibility is hidden + */ + get isSectionHidden(): boolean { + const visibility = this.getCollectionVisibility(); + return ( + hasValue(visibility) && + isEqual(visibility.main, VisibilityType.HIDDEN) && + isEqual(visibility.other, VisibilityType.HIDDEN) + ); + } + + /** + * Getter to see if the collection section visibility is readonly + */ + get isSectionReadonly(): boolean { + const visibility = this.getCollectionVisibility(); + return ( + hasValue(visibility) && + isEqual(visibility.main, VisibilityType.READONLY) && + isEqual(visibility.other, VisibilityType.READONLY) + ); + } + /** * Unsubscribe from all subscriptions, destroy instance variables * and reset submission state @@ -239,6 +279,8 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy { protected getSectionsList(): Observable { return this.submissionService.getSubmissionSections(this.submissionId).pipe( filter((sections: SectionDataObject[]) => isNotEmpty(sections)), - map((sections: SectionDataObject[]) => sections)); + map((sections: SectionDataObject[]) => + sections.filter((section: SectionDataObject) => !isEqual(section.sectionType,SectionsType.Collection))), + ); } } diff --git a/src/app/submission/sections/sections-type.ts b/src/app/submission/sections/sections-type.ts index 6fb7380822..6bca8a7252 100644 --- a/src/app/submission/sections/sections-type.ts +++ b/src/app/submission/sections/sections-type.ts @@ -8,4 +8,5 @@ export enum SectionsType { AccessesCondition = 'accessCondition', SherpaPolicies = 'sherpaPolicy', Identifiers = 'identifiers', + Collection = 'collection', } diff --git a/src/app/submission/sections/visibility-type.ts b/src/app/submission/sections/visibility-type.ts new file mode 100644 index 0000000000..b2e167285c --- /dev/null +++ b/src/app/submission/sections/visibility-type.ts @@ -0,0 +1,4 @@ +export enum VisibilityType { + HIDDEN = 'HIDDEN', + READONLY = 'READONLY', +}