From 8d5b399dba0544b13368e2793571d897069a8026 Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Thu, 1 Feb 2024 16:57:40 +0200 Subject: [PATCH] ui changes for description template editor --- .../FieldSetBuilder.java | 2 + .../MultiplicityBuilder.java | 57 +++++++++++++++++++ .../fielddata/UploadDataBuilder.java | 2 + .../Multiplicity.java | 2 +- .../DescriptionTemplateServiceImpl.java | 3 +- ...late-editor-composite-field.component.html | 53 +++++++++-------- ...ption-template-editor-field.component.html | 2 +- ...late-editor-visibility-rule.component.html | 2 +- ...mplate-editor-visibility-rule.component.ts | 46 ++++++++------- .../description-template-editor.resolver.ts | 5 +- 10 files changed, 124 insertions(+), 50 deletions(-) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/MultiplicityBuilder.java diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/FieldSetBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/FieldSetBuilder.java index 3a873e184..37da9ea27 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/FieldSetBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/FieldSetBuilder.java @@ -44,6 +44,7 @@ public class FieldSetBuilder extends BaseBuilder(); FieldSet fieldsFields = fields.extractPrefixed(this.asPrefix(eu.eudat.model.descriptiontemplatedefinition.FieldSet._fields)); + FieldSet multiplicityFields = fields.extractPrefixed(this.asPrefix(eu.eudat.model.descriptiontemplatedefinition.FieldSet._multiplicity)); List models = new ArrayList<>(); for (FieldSetEntity d : data) { @@ -56,6 +57,7 @@ public class FieldSetBuilder extends BaseBuilder { + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public MultiplicityBuilder( + ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(MultiplicityBuilder.class))); + } + + public MultiplicityBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + + List models = new ArrayList<>(); + for (MultiplicityEntity d : data) { + Multiplicity m = new Multiplicity(); + if (fields.hasField(this.asIndexer(Multiplicity._min))) m.setMin(d.getMin()); + if (fields.hasField(this.asIndexer(Multiplicity._max))) m.setMax(d.getMax()); + if (fields.hasField(this.asIndexer(Multiplicity._placeholder))) m.setPlaceholder(d.getPlaceholder()); + if (fields.hasField(this.asIndexer(Multiplicity._tableView))) m.setTableView(d.getTableView()); + + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/fielddata/UploadDataBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/fielddata/UploadDataBuilder.java index 101d5ebce..49077e70f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/fielddata/UploadDataBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/fielddata/UploadDataBuilder.java @@ -35,6 +35,8 @@ public class UploadDataBuilder extends BaseFieldDataBuilder()); diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.html index a0ee1d587..f8ce001f1 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/composite-field/description-template-editor-composite-field.component.html @@ -8,7 +8,7 @@ - {{form.get('title').getError('backendError').message}} + {{form.get('title').getError('backendError').message}} @@ -17,43 +17,43 @@
{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.DESCRIPTION' | translate}}
- {{form.get('description').getError('backendError').message}} + {{form.get('description').getError('backendError').message}}
{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.EXTENDED-DESCRIPTION' | translate}}
- {{form.get('extendedDescription').getError('backendError').message}} + {{form.get('extendedDescription').getError('backendError').message}}
- {{form.get('additionalInformation').getError('backendError').message}} + {{form.get('additionalInformation').getError('backendError').message}}
- {{form.get('multiplicity').get('min').getError('backendError').message}} + {{form.get('multiplicity').get('min').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} - {{form.get('multiplicity').get('max').getError('backendError').message}} + {{form.get('multiplicity').get('max').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}}
- - {{form.get('multiplicity').get('multiplicity').getError('backendError').message}} + + {{form.get('placeholder').get('multiplicity').getError('backendError').message}}
{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.MULTIPLICITY-TABLEVIEW' | translate}} - {{form.get('multiplicity').get('tableView').getError('backendError').message}} + {{form.get('multiplicity').get('tableView').getError('backendError').message}}
@@ -98,8 +98,8 @@
- - +
@@ -245,36 +245,39 @@ Argos Entities - - + + - - - - - - -
  • {{'DESCRIPTION-TEMPLATE-EDITOR.ACTIONS.FIELDSET.COMMENT-FIELD' | translate}} - {{form.get('hasCommentField').getError('backendError').message}} + {{form.get('hasCommentField').getError('backendError').message}}
  • diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html index b264e5199..ddd1d2329 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field/description-template-editor-field.component.html @@ -199,7 +199,7 @@

    {{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.RULES-TITLE' | translate}}

    - + diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html index 76bc691e7..36b0a7596 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html @@ -1,7 +1,7 @@
    {{i + 1}} - + diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts index e96f23396..3d56a5180 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts @@ -1,5 +1,5 @@ import { Component, Input, OnInit } from '@angular/core'; -import { UntypedFormArray, UntypedFormControl, UntypedFormGroup } from '@angular/forms'; +import { AbstractControl, UntypedFormArray, UntypedFormControl, UntypedFormGroup } from '@angular/forms'; import { DescriptionTemplateFieldType } from '@app/core/common/enum/description-template-field-type'; import { DescriptionTemplateRule } from '@app/core/model/description-template/description-template'; import { TranslateService } from '@ngx-translate/core'; @@ -17,7 +17,6 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { @Input() form: UntypedFormArray; @Input() fieldTypeForCheck: DescriptionTemplateFieldType; - @Input() formControlForCheck: UntypedFormControl; @Input() formArrayOptionsForCheck: UntypedFormArray; @Input() viewOnly: boolean; @@ -30,6 +29,8 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { parentIds: string[] = []; hiddenBy: string[] = []; + rootForm: AbstractControl = null; + constructor(private language: TranslateService) { } @@ -44,6 +45,7 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { } ngOnInit(): void { + this.rootForm = this.findRootForm(); this._computeOptions(); } @@ -87,7 +89,7 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { private _buildHiddenBy(fo: OptionItem) { try { this.fieldOptions.forEach(foption => { - const rules = (foption.form.get('visible').get('rules') as UntypedFormArray).controls.map(c => (c as UntypedFormGroup).getRawValue()) as DescriptionTemplateRule[] + const rules = (foption.form.get('visibilityRules') as UntypedFormArray).controls.map(c => (c as UntypedFormGroup).getRawValue()) as DescriptionTemplateRule[] const targets = rules.map(rule => rule.target); targets.forEach(target => { if (fo.parentsIds.includes(target) && !fo.hiddenBy.includes(foption.id)) { @@ -103,27 +105,33 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { + findRootForm() { + let currentForm: AbstractControl = this.form; + while (currentForm.parent != null){ + currentForm = currentForm.parent; + } + return currentForm; + } getOptions(): OptionItem[] { - const rootForm = this.form.root; - if (rootForm) { - // const parentSections = rootForm.get('sections') as FormArray; + + if (this.rootForm) { const result: OptionItem[] = []; - const sections = rootForm.get('sections') as UntypedFormArray; + (this.rootForm.get('definition').get('pages') as UntypedFormArray).controls.forEach(pageForm => { - if (sections) { - sections.controls.forEach(section => { - const subResult = this.buildOptions(section as UntypedFormGroup, ToCEntryType.Section, []); - result.push(...subResult); - }); - } + const sections = pageForm.get('sections') as UntypedFormArray; + if (sections) { + sections.controls.forEach(section => { + const subResult = this.buildOptions(section as UntypedFormGroup, ToCEntryType.Section, []); + result.push(...subResult); + }); + } + }); - //return options return result; - } //nothing found return []; @@ -169,9 +177,9 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { } computeParentIds(): string[] { - if (!this.formControlForCheck.get('id')) return []; + if (!this.rootForm.get('id')) return []; - const current = this.options.find(opt => opt.id === this.formControlForCheck.get('id').value); + const current = this.options.find(opt => opt.id === this.rootForm.get('id').value); if (current) { return current.parentsIds; } @@ -179,9 +187,9 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { } computeHiddenBy(): string[] { - if (!this.formControlForCheck.get('id')) return []; + if (!this.rootForm.get('id')) return []; - const current = this.options.find(opt => opt.id === this.formControlForCheck.get('id').value); + const current = this.options.find(opt => opt.id === this.rootForm.get('id').value); if (current) { return current.hiddenBy; } diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.resolver.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.resolver.ts index 8fb221974..16711c2ae 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.resolver.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.resolver.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; import { DescriptionTemplateType } from '@app/core/model/description-template-type/description-template-type'; -import { DescriptionTemplate, DescriptionTemplateExternalSelectData, DescriptionTemplateBaseFieldData, DescriptionTemplateSelectOption, DescriptionTemplateDefinition, DescriptionTemplateField, DescriptionTemplateFieldSet, DescriptionTemplateMultiplicity, DescriptionTemplatePage, DescriptionTemplateRule, DescriptionTemplateSection, DescriptionTemplateSelectData, DescriptionTemplateExternalDatasetData, DescriptionTemplateExternalSelectSource, DescriptionTemplateExternalSelectAuthData, DescriptionTemplateExternalSelectSourceBinding } from '@app/core/model/description-template/description-template'; +import { DescriptionTemplate, DescriptionTemplateExternalSelectData, DescriptionTemplateBaseFieldData, DescriptionTemplateSelectOption, DescriptionTemplateDefinition, DescriptionTemplateField, DescriptionTemplateFieldSet, DescriptionTemplateMultiplicity, DescriptionTemplatePage, DescriptionTemplateRule, DescriptionTemplateSection, DescriptionTemplateSelectData, DescriptionTemplateExternalDatasetData, DescriptionTemplateExternalSelectSource, DescriptionTemplateExternalSelectAuthData, DescriptionTemplateExternalSelectSourceBinding, DescriptionTemplateUploadData, DescriptionTemplateUploadOption } from '@app/core/model/description-template/description-template'; import { DescriptionTemplateService } from '@app/core/services/description-template/description-template.service'; import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; import { BaseEditorResolver } from '@common/base/base-editor.resolver'; @@ -85,6 +85,9 @@ export class DescriptionTemplateEditorResolver extends BaseEditorResolver { [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.sources), nameof(x => x.auth), nameof(x => x.body)].join('.'), [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.sources), nameof(x => x.auth), nameof(x => x.path)].join('.'), [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.sources), nameof(x => x.auth), nameof(x => x.type)].join('.'), + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.maxFileSizeInMB)].join('.'), + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.types), nameof(x => x.label)].join('.'), + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.types), nameof(x => x.value)].join('.'),