From d00ad0cd0e33e8eb3590768e56e64f1e24e694ba Mon Sep 17 00:00:00 2001 From: Alisa Ismailati Date: Fri, 16 Jun 2023 13:27:51 +0200 Subject: [PATCH] [DURACOM-152] Field visibility --- .../submission/submission-field-scope-type.ts | 4 ++++ .../core/submission/submission-scope-type.ts | 2 +- .../form/builder/parsers/field-parser.ts | 22 ++++++++++++++----- .../shared/form/builder/parsers/row-parser.ts | 22 +++++++++++++------ 4 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 src/app/core/submission/submission-field-scope-type.ts diff --git a/src/app/core/submission/submission-field-scope-type.ts b/src/app/core/submission/submission-field-scope-type.ts new file mode 100644 index 0000000000..4a9292ec3d --- /dev/null +++ b/src/app/core/submission/submission-field-scope-type.ts @@ -0,0 +1,4 @@ +export enum SubmissionFieldScopeType { + WorkspaceItem = 'SUBMISSION', + WorkflowItem = 'WORKFLOW', +} diff --git a/src/app/core/submission/submission-scope-type.ts b/src/app/core/submission/submission-scope-type.ts index 6ed32d3b4e..f319e5c473 100644 --- a/src/app/core/submission/submission-scope-type.ts +++ b/src/app/core/submission/submission-scope-type.ts @@ -1,4 +1,4 @@ export enum SubmissionScopeType { WorkspaceItem = 'WORKSPACE', - WorkflowItem = 'WORKFLOW' + WorkflowItem = 'WORKFLOW', } diff --git a/src/app/shared/form/builder/parsers/field-parser.ts b/src/app/shared/form/builder/parsers/field-parser.ts index e118ca7add..7ea55d4454 100644 --- a/src/app/shared/form/builder/parsers/field-parser.ts +++ b/src/app/shared/form/builder/parsers/field-parser.ts @@ -24,6 +24,7 @@ import { RelationshipOptions } from '../models/relationship-options.model'; import { VocabularyOptions } from '../../../../core/submission/vocabularies/models/vocabulary-options.model'; import { ParserType } from './parser-type'; import { isNgbDateStruct } from '../../../date.util'; +import { SubmissionScopeType } from '../../../../core/submission/submission-scope-type'; export const SUBMISSION_ID: InjectionToken = new InjectionToken('submissionId'); export const CONFIG_DATA: InjectionToken = new InjectionToken('configData'); @@ -282,7 +283,7 @@ export abstract class FieldParser { controlModel.id = (this.fieldId).replace(/\./g, '_'); // Set read only option - controlModel.readOnly = this.parserOptions.readOnly || this.isFieldReadOnly(this.configData.visibility, this.parserOptions.submissionScope); + controlModel.readOnly = this.parserOptions.readOnly || this.isFieldReadOnly(this.configData.visibility, this.configData.scope, this.parserOptions.submissionScope); controlModel.disabled = controlModel.readOnly; if (hasValue(this.configData.selectableRelationship)) { controlModel.relationship = Object.assign(new RelationshipOptions(), this.configData.selectableRelationship); @@ -322,14 +323,25 @@ export abstract class FieldParser { } /** - * Check if a field is read-only with the given scope + * Checks if a field is read-only with the given scope. + * The field is readonly when submissionScope is WORKSPACE and the main visibility is READONLY + * or when submissionScope is WORKFLOW and the other visibility is READONLY * @param visibility * @param submissionScope */ - private isFieldReadOnly(visibility: SectionVisibility, submissionScope: string) { + private isFieldReadOnly(visibility: SectionVisibility, fieldScope: string, submissionScope: string) { return isNotEmpty(submissionScope) - && isNotEmpty(visibility) - && visibility.main === VisibilityType.READONLY; + && isNotEmpty(fieldScope) + && isNotEmpty(visibility) + && (( + submissionScope === SubmissionScopeType.WorkspaceItem + && visibility.main === VisibilityType.READONLY + ) + || + (visibility.other === VisibilityType.READONLY + && submissionScope === SubmissionScopeType.WorkflowItem + ) + ); } /** diff --git a/src/app/shared/form/builder/parsers/row-parser.ts b/src/app/shared/form/builder/parsers/row-parser.ts index 6602e53714..3f5b4a04c6 100644 --- a/src/app/shared/form/builder/parsers/row-parser.ts +++ b/src/app/shared/form/builder/parsers/row-parser.ts @@ -1,3 +1,4 @@ +import { SubmissionFieldScopeType } from './../../../../core/submission/submission-field-scope-type'; import { SectionVisibility } from './../../../../submission/objects/section-visibility.model'; import { Injectable, Injector } from '@angular/core'; @@ -13,7 +14,7 @@ import { ParserOptions } from './parser-options'; import { ParserType } from './parser-type'; import { setLayout } from './parser.utils'; import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from '../ds-dynamic-form-ui/ds-dynamic-form-constants'; -import { VisibilityType } from '../../../../submission/sections/visibility-type'; +import { SubmissionScopeType } from '../../../../core/submission/submission-scope-type'; export const ROW_ID_PREFIX = 'df-row-group-config-'; @@ -125,18 +126,25 @@ export class RowParser { } /** - * Check if the field is hidden or not, based on the visibility and the submission scope + * Check if the field is hidden or not. + * It is hidden when we do have the scope, + * but we do not have the visibility, + * also the field scope should be different from the submissionScope. * @param visibility The visibility of the field * @param scope the scope of the field * @param submissionScope the scope of the submission * @returns If the field is hidden or not */ private isHidden(visibility: SectionVisibility, scope: string, submissionScope: string): boolean { - return isEmpty(visibility) - || (isNotEmpty(visibility) && visibility.main !== VisibilityType.READONLY) - && isNotEmpty(submissionScope) - && (isNotEmpty(scope) - && scope !== submissionScope); + return isNotEmpty(scope) + && ( + isEmpty(visibility) + && ( + submissionScope === SubmissionScopeType.WorkspaceItem && scope !== SubmissionFieldScopeType.WorkspaceItem + || + submissionScope === SubmissionScopeType.WorkflowItem && scope !== SubmissionFieldScopeType.WorkflowItem + ) + ); } filterScopedFields(fields: FormFieldModel[], submissionScope): FormFieldModel[] {