Skip to content

Commit d00ad0c

Browse files
[DURACOM-152] Field visibility
1 parent fda4ef7 commit d00ad0c

4 files changed

Lines changed: 37 additions & 13 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum SubmissionFieldScopeType {
2+
WorkspaceItem = 'SUBMISSION',
3+
WorkflowItem = 'WORKFLOW',
4+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export enum SubmissionScopeType {
22
WorkspaceItem = 'WORKSPACE',
3-
WorkflowItem = 'WORKFLOW'
3+
WorkflowItem = 'WORKFLOW',
44
}

src/app/shared/form/builder/parsers/field-parser.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { RelationshipOptions } from '../models/relationship-options.model';
2424
import { VocabularyOptions } from '../../../../core/submission/vocabularies/models/vocabulary-options.model';
2525
import { ParserType } from './parser-type';
2626
import { isNgbDateStruct } from '../../../date.util';
27+
import { SubmissionScopeType } from '../../../../core/submission/submission-scope-type';
2728

2829
export const SUBMISSION_ID: InjectionToken<string> = new InjectionToken<string>('submissionId');
2930
export const CONFIG_DATA: InjectionToken<FormFieldModel> = new InjectionToken<FormFieldModel>('configData');
@@ -282,7 +283,7 @@ export abstract class FieldParser {
282283
controlModel.id = (this.fieldId).replace(/\./g, '_');
283284

284285
// Set read only option
285-
controlModel.readOnly = this.parserOptions.readOnly || this.isFieldReadOnly(this.configData.visibility, this.parserOptions.submissionScope);
286+
controlModel.readOnly = this.parserOptions.readOnly || this.isFieldReadOnly(this.configData.visibility, this.configData.scope, this.parserOptions.submissionScope);
286287
controlModel.disabled = controlModel.readOnly;
287288
if (hasValue(this.configData.selectableRelationship)) {
288289
controlModel.relationship = Object.assign(new RelationshipOptions(), this.configData.selectableRelationship);
@@ -322,14 +323,25 @@ export abstract class FieldParser {
322323
}
323324

324325
/**
325-
* Check if a field is read-only with the given scope
326+
* Checks if a field is read-only with the given scope.
327+
* The field is readonly when submissionScope is WORKSPACE and the main visibility is READONLY
328+
* or when submissionScope is WORKFLOW and the other visibility is READONLY
326329
* @param visibility
327330
* @param submissionScope
328331
*/
329-
private isFieldReadOnly(visibility: SectionVisibility, submissionScope: string) {
332+
private isFieldReadOnly(visibility: SectionVisibility, fieldScope: string, submissionScope: string) {
330333
return isNotEmpty(submissionScope)
331-
&& isNotEmpty(visibility)
332-
&& visibility.main === VisibilityType.READONLY;
334+
&& isNotEmpty(fieldScope)
335+
&& isNotEmpty(visibility)
336+
&& ((
337+
submissionScope === SubmissionScopeType.WorkspaceItem
338+
&& visibility.main === VisibilityType.READONLY
339+
)
340+
||
341+
(visibility.other === VisibilityType.READONLY
342+
&& submissionScope === SubmissionScopeType.WorkflowItem
343+
)
344+
);
333345
}
334346

335347
/**

src/app/shared/form/builder/parsers/row-parser.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SubmissionFieldScopeType } from './../../../../core/submission/submission-field-scope-type';
12
import { SectionVisibility } from './../../../../submission/objects/section-visibility.model';
23
import { Injectable, Injector } from '@angular/core';
34

@@ -13,7 +14,7 @@ import { ParserOptions } from './parser-options';
1314
import { ParserType } from './parser-type';
1415
import { setLayout } from './parser.utils';
1516
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from '../ds-dynamic-form-ui/ds-dynamic-form-constants';
16-
import { VisibilityType } from '../../../../submission/sections/visibility-type';
17+
import { SubmissionScopeType } from '../../../../core/submission/submission-scope-type';
1718

1819
export const ROW_ID_PREFIX = 'df-row-group-config-';
1920

@@ -125,18 +126,25 @@ export class RowParser {
125126
}
126127

127128
/**
128-
* Check if the field is hidden or not, based on the visibility and the submission scope
129+
* Check if the field is hidden or not.
130+
* It is hidden when we do have the scope,
131+
* but we do not have the visibility,
132+
* also the field scope should be different from the submissionScope.
129133
* @param visibility The visibility of the field
130134
* @param scope the scope of the field
131135
* @param submissionScope the scope of the submission
132136
* @returns If the field is hidden or not
133137
*/
134138
private isHidden(visibility: SectionVisibility, scope: string, submissionScope: string): boolean {
135-
return isEmpty(visibility)
136-
|| (isNotEmpty(visibility) && visibility.main !== VisibilityType.READONLY)
137-
&& isNotEmpty(submissionScope)
138-
&& (isNotEmpty(scope)
139-
&& scope !== submissionScope);
139+
return isNotEmpty(scope)
140+
&& (
141+
isEmpty(visibility)
142+
&& (
143+
submissionScope === SubmissionScopeType.WorkspaceItem && scope !== SubmissionFieldScopeType.WorkspaceItem
144+
||
145+
submissionScope === SubmissionScopeType.WorkflowItem && scope !== SubmissionFieldScopeType.WorkflowItem
146+
)
147+
);
140148
}
141149

142150
filterScopedFields(fields: FormFieldModel[], submissionScope): FormFieldModel[] {

0 commit comments

Comments
 (0)