Skip to content

Commit 681ee6f

Browse files
[DURACOM-145] Handled collection step
on a submission form
1 parent c233927 commit 681ee6f

8 files changed

Lines changed: 91 additions & 3 deletions

src/app/submission/form/collection/submission-form-collection.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class="btn btn-outline-primary"
2626
(blur)="onClose()"
2727
(click)="onClose()"
28-
[disabled]="(processingChange$ | async) || collectionModifiable == false"
28+
[disabled]="(processingChange$ | async) || collectionModifiable == false || isReadonly"
2929
ngbDropdownToggle>
3030
<span *ngIf="(processingChange$ | async)"><i class='fas fa-circle-notch fa-spin'></i></span>
3131
<span *ngIf="!(processingChange$ | async)">{{ selectedCollectionName$ | async }}</span>

src/app/submission/form/collection/submission-form-collection.component.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ describe('SubmissionFormCollectionComponent Component', () => {
249249
expect(dropDown).toBeFalsy();
250250
});
251251

252+
it('the dropdown button should be disabled when isReadonly is true', () => {
253+
comp.isReadonly = true;
254+
fixture.detectChanges();
255+
expect(dropdowBtn.nativeNode.attributes.disabled).toBeDefined();
256+
});
257+
252258
it('should be simulated when the drop-down menu is closed', () => {
253259
spyOn(comp, 'onClose');
254260
comp.onClose();

src/app/submission/form/collection/submission-form-collection.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
6464
*/
6565
@Input() submissionId;
6666

67+
/**
68+
* Flag to indicate if the submission dropdown is read only
69+
*/
70+
@Input() isReadonly = false;
71+
6772
/**
6873
* An event fired when a different collection is selected.
6974
* Event's payload equals to new SubmissionObject.

src/app/submission/form/submission-form.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
</div>
99

1010
<div class="submission-form-header-item mb-3 mb-sm-0 flex-sm-grow-1 flex-md-grow-0">
11+
<ng-container *ngIf="!isSectionHidden">
1112
<ds-submission-form-collection [currentCollectionId]="collectionId"
1213
[currentDefinition]="definitionId"
1314
[submissionId]="submissionId"
1415
[collectionModifiable]="collectionModifiable"
16+
[isReadonly]="isSectionReadonly"
1517
(collectionChange)="onCollectionChange($event)">
1618
</ds-submission-form-collection>
19+
</ng-container>
1720
</div>
1821
<div class="submission-form-header-item text-right">
1922
<ds-submission-form-section-add [collectionId]="collectionId"

src/app/submission/form/submission-form.component.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { createTestComponent } from '../../shared/testing/utils.test';
2525
import { Item } from '../../core/shared/item.model';
2626
import { TestScheduler } from 'rxjs/testing';
2727
import { SectionsService } from '../sections/sections.service';
28+
import { VisibilityType } from '../sections/visibility-type';
2829

2930
describe('SubmissionFormComponent Component', () => {
3031

@@ -156,6 +157,32 @@ describe('SubmissionFormComponent Component', () => {
156157
done();
157158
});
158159

160+
it('should return the visibility object of the collection section', () => {
161+
comp.submissionDefinition = submissionDefinition;
162+
fixture.detectChanges();
163+
const result = compAsAny.getCollectionVisibility();
164+
expect(result).toEqual({
165+
main: VisibilityType.HIDDEN,
166+
other: VisibilityType.HIDDEN,
167+
});
168+
});
169+
170+
it('should return true if collection section visibility is hidden', () => {
171+
comp.submissionDefinition = submissionDefinition;
172+
fixture.detectChanges();
173+
expect(comp.isSectionHidden).toBe(true);
174+
});
175+
176+
it('should return false for isSectionReadonly when collection section visibility is not READONLY', () => {
177+
const visibility = {
178+
main: VisibilityType.READONLY,
179+
other: VisibilityType.READONLY,
180+
};
181+
comp.submissionDefinition = Object.assign({}, submissionDefinition, { visibility: visibility });
182+
fixture.detectChanges();
183+
expect(comp.isSectionReadonly).toBe(false);
184+
});
185+
159186
it('should update properly on collection change', (done) => {
160187
comp.collectionId = collectionId;
161188
comp.submissionId = submissionId;

src/app/submission/form/submission-form.component.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
99
import { SubmissionObject } from '../../core/submission/models/submission-object.model';
1010
import { WorkspaceitemSectionsObject } from '../../core/submission/models/workspaceitem-sections.model';
1111

12-
import { hasValue, isNotEmpty } from '../../shared/empty.util';
12+
import { hasValue, isNotEmpty, isNotUndefined } from '../../shared/empty.util';
1313
import { UploaderOptions } from '../../shared/upload/uploader/uploader-options.model';
1414
import { SubmissionObjectEntry } from '../objects/submission-objects.reducer';
1515
import { SectionDataObject } from '../sections/models/section-data.model';
@@ -18,6 +18,10 @@ import { Item } from '../../core/shared/item.model';
1818
import { SectionsType } from '../sections/sections-type';
1919
import { SectionsService } from '../sections/sections.service';
2020
import { SubmissionError } from '../objects/submission-error.model';
21+
import { SubmissionSectionVisibility } from './../../core/config/models/config-submission-section.model';
22+
import { SubmissionSectionModel } from './../../core/config/models/config-submission-section.model';
23+
import { VisibilityType } from '../sections/visibility-type';
24+
import isEqual from 'lodash/isEqual';
2125

2226
/**
2327
* This component represents the submission form.
@@ -188,6 +192,42 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
188192
}
189193
}
190194

195+
/**
196+
* Returns the visibility object of the collection section
197+
*/
198+
private getCollectionVisibility(): SubmissionSectionVisibility {
199+
const submissionSectionModel: SubmissionSectionModel =
200+
this.submissionDefinition.sections.page.find(
201+
(section) => isEqual(section.sectionType, SectionsType.Collection)
202+
);
203+
204+
return isNotUndefined(submissionSectionModel.visibility) ? submissionSectionModel.visibility : null;
205+
}
206+
207+
/**
208+
* Getter to see if the collection section visibility is hidden
209+
*/
210+
get isSectionHidden(): boolean {
211+
const visibility = this.getCollectionVisibility();
212+
return (
213+
hasValue(visibility) &&
214+
isEqual(visibility.main, VisibilityType.HIDDEN) &&
215+
isEqual(visibility.other, VisibilityType.HIDDEN)
216+
);
217+
}
218+
219+
/**
220+
* Getter to see if the collection section visibility is readonly
221+
*/
222+
get isSectionReadonly(): boolean {
223+
const visibility = this.getCollectionVisibility();
224+
return (
225+
hasValue(visibility) &&
226+
isEqual(visibility.main, VisibilityType.READONLY) &&
227+
isEqual(visibility.other, VisibilityType.READONLY)
228+
);
229+
}
230+
191231
/**
192232
* Unsubscribe from all subscriptions, destroy instance variables
193233
* and reset submission state
@@ -239,6 +279,8 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
239279
protected getSectionsList(): Observable<any> {
240280
return this.submissionService.getSubmissionSections(this.submissionId).pipe(
241281
filter((sections: SectionDataObject[]) => isNotEmpty(sections)),
242-
map((sections: SectionDataObject[]) => sections));
282+
map((sections: SectionDataObject[]) =>
283+
sections.filter((section: SectionDataObject) => !isEqual(section.sectionType,SectionsType.Collection))),
284+
);
243285
}
244286
}

src/app/submission/sections/sections-type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export enum SectionsType {
88
AccessesCondition = 'accessCondition',
99
SherpaPolicies = 'sherpaPolicy',
1010
Identifiers = 'identifiers',
11+
Collection = 'collection',
1112
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum VisibilityType {
2+
HIDDEN = 'HIDDEN',
3+
READONLY = 'READONLY',
4+
}

0 commit comments

Comments
 (0)