mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 04:23:04 +00:00
[DURACOM-152] Fixed read-only visibility for submission form fields
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { SectionVisibility } from './../../../../submission/objects/section-visibility.model';
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
|
||||
import { DYNAMIC_FORM_CONTROL_TYPE_ARRAY, DynamicFormGroupModelConfig } from '@ng-dynamic-forms/core';
|
||||
import uniqueId from 'lodash/uniqueId';
|
||||
|
||||
import { isEmpty } from '../../../empty.util';
|
||||
import { isEmpty, isNotEmpty } from '../../../empty.util';
|
||||
import { DynamicRowGroupModel } from '../ds-dynamic-form-ui/models/ds-dynamic-row-group-model';
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
import { CONFIG_DATA, FieldParser, INIT_FORM_VALUES, PARSER_OPTIONS, SUBMISSION_ID } from './field-parser';
|
||||
@@ -12,6 +13,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';
|
||||
|
||||
export const ROW_ID_PREFIX = 'df-row-group-config-';
|
||||
|
||||
@@ -118,15 +120,30 @@ export class RowParser {
|
||||
return parsedResult;
|
||||
}
|
||||
|
||||
checksFieldScope(fieldScope, submissionScope) {
|
||||
return (isEmpty(fieldScope) || isEmpty(submissionScope) || fieldScope === submissionScope);
|
||||
checksFieldScope(fieldScope, submissionScope, visibility: SectionVisibility) {
|
||||
return (isEmpty(fieldScope) || !this.isHidden(visibility, fieldScope, submissionScope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the field is hidden or not, based on the visibility and the submission scope
|
||||
* @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);
|
||||
}
|
||||
|
||||
filterScopedFields(fields: FormFieldModel[], submissionScope): FormFieldModel[] {
|
||||
const filteredFields: FormFieldModel[] = [];
|
||||
fields.forEach((field: FormFieldModel) => {
|
||||
// Whether field scope doesn't match the submission scope, skip it
|
||||
if (this.checksFieldScope(field.scope, submissionScope)) {
|
||||
if (this.checksFieldScope(field.scope, submissionScope, field.visibility)) {
|
||||
filteredFields.push(field);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user