[DURACOM-152] Field visibility

This commit is contained in:
Alisa Ismailati
2023-06-16 13:27:51 +02:00
parent fda4ef77e4
commit d00ad0cd0e
4 changed files with 37 additions and 13 deletions

View File

@@ -0,0 +1,4 @@
export enum SubmissionFieldScopeType {
WorkspaceItem = 'SUBMISSION',
WorkflowItem = 'WORKFLOW',
}

View File

@@ -1,4 +1,4 @@
export enum SubmissionScopeType {
WorkspaceItem = 'WORKSPACE',
WorkflowItem = 'WORKFLOW'
WorkflowItem = 'WORKFLOW',
}

View File

@@ -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<string> = new InjectionToken<string>('submissionId');
export const CONFIG_DATA: InjectionToken<FormFieldModel> = new InjectionToken<FormFieldModel>('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(fieldScope)
&& isNotEmpty(visibility)
&& visibility.main === VisibilityType.READONLY;
&& ((
submissionScope === SubmissionScopeType.WorkspaceItem
&& visibility.main === VisibilityType.READONLY
)
||
(visibility.other === VisibilityType.READONLY
&& submissionScope === SubmissionScopeType.WorkflowItem
)
);
}
/**

View File

@@ -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[] {