description templates validation fixes (in progress)

This commit is contained in:
amentis 2024-02-05 17:59:11 +02:00
parent 8bf1e0c4d6
commit fc756a1780
26 changed files with 295 additions and 139 deletions

View File

@ -4,18 +4,23 @@ import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class MultiplicityPersist {
private Integer min = null;
public static final String _min = "min";
private Integer max = null;
public static final String _max = "max";
private String placeholder = null;
@ -59,8 +64,11 @@ public class MultiplicityPersist {
public static final String ValidatorName = "DescriptionTemplate.MultiplicityValidator";
protected MultiplicityValidator(ConventionService conventionService, ErrorThesaurusProperties errors) {
private final MessageSource messageSource;
protected MultiplicityValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
@ -70,7 +78,20 @@ public class MultiplicityPersist {
@Override
protected List<Specification> specifications(MultiplicityPersist item) {
return Lists.newArrayList();
return Arrays.asList(
this.spec()
.iff(() -> !this.isNull(item.getMin()))
.must(() -> item.getMin() >= 0)
.failOn(MultiplicityPersist._min).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{MultiplicityPersist._min}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getMax()))
.must(() -> item.getMax() >= 0)
.failOn(MultiplicityPersist._max).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{MultiplicityPersist._max}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getMax()))
.must(() -> !this.isNull(item.getMin()) && (item.getMax() >= item.getMin()))
.failOn(MultiplicityPersist._max).failWith(messageSource.getMessage("Validation.LowerThanMin", new Object[]{MultiplicityPersist._min}, LocaleContextHolder.getLocale()))
);
}
}

View File

@ -161,7 +161,10 @@ public class ExternalSelectDataPersist extends BaseFieldDataPersist {
protected List<Specification> specifications(ExternalSelectSourcePersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getUrl()))
.must(() -> !this.isEmpty(item.getMethod()))
.failOn(ExternalSelectSourcePersist._method).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectSourcePersist._method}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getUrl()))
.failOn(ExternalSelectSourcePersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectSourcePersist._url}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getHasAuth()) && item.getHasAuth())
@ -314,8 +317,14 @@ public class ExternalSelectDataPersist extends BaseFieldDataPersist {
protected List<Specification> specifications(ExternalSelectAuthDataPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getUrl()))
.failOn(ExternalSelectAuthDataPersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectAuthDataPersist._url}, LocaleContextHolder.getLocale()))
.must(() -> !this.isEmpty(item.getUrl()))
.failOn(ExternalSelectAuthDataPersist._url).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectAuthDataPersist._url}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getMethod()))
.failOn(ExternalSelectAuthDataPersist._method).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectAuthDataPersist._method}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getType()))
.failOn(ExternalSelectAuthDataPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalSelectAuthDataPersist._type}, LocaleContextHolder.getLocale()))
);
}
}

View File

@ -63,8 +63,15 @@ public class UploadDataPersist extends BaseFieldDataPersist {
List<Specification> specifications = getBaseSpecifications(item);
specifications.addAll(Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getTypes()))
.must(() -> !this.isListNullOrEmpty(item.getTypes()))
.failOn(UploadDataPersist._types).failWith(messageSource.getMessage("Validation_Required", new Object[]{UploadDataPersist._types}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getMaxFileSizeInMB()))
.failOn(UploadDataPersist._maxFileSizeInMB).failWith(messageSource.getMessage("Validation_Required", new Object[]{UploadDataPersist._maxFileSizeInMB}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isNull(item.getMaxFileSizeInMB()))
.must(() -> item.getMaxFileSizeInMB() > 0 && item.getMaxFileSizeInMB() <= 10)
.failOn(UploadDataPersist._maxFileSizeInMB).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{UploadDataPersist._maxFileSizeInMB}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getTypes()))
.on(UploadDataPersist._types)

View File

@ -34,12 +34,12 @@
<div class="row">
<mat-form-field *ngIf="isMultiplicityEnabled" class="col pl-0 underline-line-field">
<input matInput placeholder="{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.MULTIPLICITY-MIN' | translate}}" type="number" [formControl]="form.get('multiplicity').get('min')" required>
<input matInput placeholder="{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.MULTIPLICITY-MIN' | translate}}" type="number" [formControl]="form.get('multiplicity').get('min')">
<mat-error *ngIf="form.get('multiplicity').get('min').hasError('backendError')">{{form.get('multiplicity').get('min').getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.get('multiplicity').get('min').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<mat-form-field *ngIf="isMultiplicityEnabled" class="col pr-0 underline-line-field">
<input matInput placeholder="{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.MULTIPLICITY-MAX' | translate}}" type="number" [formControl]="this.form.get('multiplicity').get('max')" required>
<input matInput placeholder="{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.MULTIPLICITY-MAX' | translate}}" type="number" [formControl]="this.form.get('multiplicity').get('max')">
<mat-error *ngIf="form.get('multiplicity').get('max').hasError('backendError')">{{form.get('multiplicity').get('max').getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.get('multiplicity').get('max').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -65,7 +65,8 @@
<!-- FIELDS -->
<div #inputs transition-group class="col-12" *ngIf="hasFocus" [@fade-in]>
<div *ngFor="let field of fieldsArray.controls; let i=index;" class="row bg-white field-input mt-3" (click)="setTargetField(field)" transition-group-item>
<app-description-template-editor-field-component class="col-12" [form]="field" [showOrdinal]="false" [indexPath]="indexPath + 'f' + i" [viewOnly]="viewOnly" [expandView]="hasFocus" [canBeDeleted]="fieldsArray.length !=1" (delete)="deleteField(i)">
<app-description-template-editor-field-component class="col-12" [form]="field" [showOrdinal]="false" [indexPath]="indexPath + 'f' + i" [viewOnly]="viewOnly" [expandView]="hasFocus" [canBeDeleted]="fieldsArray.length !=1"
[validationErrorModel]="validationErrorModel" [rootPath]="rootPath" (delete)="deleteField(i)">
<div class="arrows mt-2">
<ul class="list-unstyled list-inline d-flex align-items-center">
<li *ngIf="canGoUp(i)" class="text-muted">

View File

@ -28,6 +28,7 @@ import { debounceTime, delay, map, takeUntil, tap } from 'rxjs/operators';
import { GENERAL_ANIMATIONS } from '../../animations/animations';
import { EditorCustomValidators } from '../../custom-validators/editor-custom-validators';
import { DescriptionTemplateFieldEditorModel, DescriptionTemplateRuleEditorModel, DescriptionTemplateSectionEditorModel } from '../../description-template-editor.model';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-composite-field-component',
@ -46,6 +47,8 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon
@Input() numbering: string;
@Input() hasFocus: boolean = false;
@ViewChild("inputs") inputs: TransitionGroupComponent;
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
showPreview: boolean = true;
previewDirty: boolean = false;

View File

@ -12,6 +12,7 @@
|
translate}}</mat-option>
</mat-select>
<mat-error *ngIf="form.hasError('backendError')">{{form.getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -22,6 +23,7 @@
<mat-option [value]="'true'">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.CHECK-BOX.CHECKED' | translate}}</mat-option>
<mat-option [value]="'false'">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.CHECK-BOX.UNCHECKED' | translate}}</mat-option>
</mat-select>
<mat-error *ngIf="form.hasError('backendError')">{{form.getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -32,6 +34,7 @@
<mat-option [value]="null">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.NONE' | translate }}</mat-option>
<mat-option *ngFor="let opt of formArrayOptions['controls']" [value]="opt.get('value').value">{{opt.get('label').value}}</mat-option>
</mat-select>
<mat-error *ngIf="form.hasError('backendError')">{{form.getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -39,6 +42,7 @@
<mat-form-field class="col-md-12" *ngIf="fieldType === descriptionTemplateFieldTypeEnum.FREE_TEXT">
<mat-label>{{placeHolder}}</mat-label>
<input matInput type="text" [placeholder]="placeHolder" [formControl]="form">
<mat-error *ngIf="form.hasError('backendError')">{{form.getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -49,6 +53,7 @@
<mat-option [value]="null">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.NONE' | translate}}</mat-option>
<mat-option *ngFor="let opt of formArrayOptions['controls']" [value]="opt.get('value').value">{{opt.get('label').value}}</mat-option>
</mat-select>
<mat-error *ngIf="form.hasError('backendError')">{{form.getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -56,6 +61,7 @@
<mat-form-field class="col-md-12" *ngIf="fieldType === descriptionTemplateFieldTypeEnum.TEXT_AREA">
<mat-label>{{placeHolder}}</mat-label>
<input matInput type="text" [placeholder]="placeHolder" [formControl]="form">
<mat-error *ngIf="form.hasError('backendError')">{{form.getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -63,6 +69,7 @@
<mat-form-field class="col-md-12" *ngIf="fieldType === descriptionTemplateFieldTypeEnum.RICH_TEXT_AREA">
<mat-label>{{placeHolder}}</mat-label>
<input matInput type="text" [placeholder]="placeHolder" [formControl]="form">
<mat-error *ngIf="form.hasError('backendError')">{{form.getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -73,6 +80,7 @@
<input matInput [placeholder]="placeHolder" class="table-input" [matDatepicker]="date" [formControl]="form">
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
<mat-datepicker #date></mat-datepicker>
<mat-error *ngIf="form.hasError('backendError')">{{form.getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
</mat-error>
</mat-form-field>

View File

@ -77,7 +77,7 @@
<mat-form-field class="col-md-6">
<mat-label>{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.FIELD-AUTOCOMPLETE-URL' | translate}}</mat-label>
<input matInput [formControl]="singleForm.get('auth').get('url')">
<mat-error *ngIf="singleForm.get('auth').get('method').hasError('backendError')">{{singleForm.get('auth').get('method').getError('backendError').message}}</mat-error>
<mat-error *ngIf="singleForm.get('auth').get('url').hasError('backendError')">{{singleForm.get('auth').get('url').getError('backendError').message}}</mat-error>
<mat-error *ngIf="singleForm.get('auth').get('url').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<mat-form-field class="col-md-6">

View File

@ -4,6 +4,7 @@ import { DescriptionTemplateExternalSelectSourceEditorModel } from '../../../des
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { DescriptionTemplateExternalSelectHttpMethodType } from '@app/core/common/enum/description-template-external-select-http-method-type';
import { DescriptionTemplateExternalSelectAuthType } from '@app/core/common/enum/description-template-external-select-auth-type';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-external-select-field-component',
@ -13,6 +14,9 @@ import { DescriptionTemplateExternalSelectAuthType } from '@app/core/common/enum
export class DescriptionTemplateEditorExternalSelectFieldComponent implements OnInit {
@Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
methodTypeValues = this.enumUtils.getEnumValues<DescriptionTemplateExternalSelectHttpMethodType>(DescriptionTemplateExternalSelectHttpMethodType);
authTypeValues = this.enumUtils.getEnumValues<DescriptionTemplateExternalSelectAuthType>(DescriptionTemplateExternalSelectAuthType);
@ -24,7 +28,9 @@ export class DescriptionTemplateEditorExternalSelectFieldComponent implements On
}
addSource() {
(<UntypedFormArray>this.form.get('data').get('sources')).push(new DescriptionTemplateExternalSelectSourceEditorModel().buildForm());
const externalDataset = new DescriptionTemplateExternalSelectSourceEditorModel(this.validationErrorModel);
const externalSelectArray = this.form.get('data').get('sources') as UntypedFormArray;
externalSelectArray.push(externalDataset.buildForm({rootPath: this.rootPath + 'data.sources[' + externalSelectArray.length + '].'}));
}
removeSource(index: number) {

View File

@ -18,13 +18,13 @@
<div *ngFor="let option of form.get('data').get('options')['controls'] index as i" class="row">
<mat-form-field class="col">
<mat-label>{{'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.FIELDS.FIELD-RADIO-BOX-LABEL' | translate}}</mat-label>
<input matInput type="string" [formControl]="this.form.get('data').get('options').get(''+i).get('label')">
<mat-error *ngIf="form.get('data').get('options').get(''+i).get('label').hasError('backendError')">{{form.get('data').get('options').get(''+i).get('label').getError('backendError').message}}</mat-error>
<input matInput type="string" [formControl]="option.get('label')">
<mat-error *ngIf="option.get('label').hasError('backendError')">{{option.get('label').getError('backendError').message}}</mat-error>
</mat-form-field>
<mat-form-field class="col">
<mat-label>{{'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.FIELDS.FIELD-RADIO-BOX-VALUE' | translate}}</mat-label>
<input matInput type="string" [formControl]="this.form.get('data').get('options').get(''+i).get('value')">
<mat-error *ngIf="form.get('data').get('options').get(''+i).get('value').hasError('backendError')">{{form.get('data').get('options').get(''+i).get('value').getError('backendError').message}}</mat-error>
<input matInput type="string" [formControl]="option.get('value')">
<mat-error *ngIf="option.get('value').hasError('backendError')">{{option.get('value').getError('backendError').message}}</mat-error>
</mat-form-field>
<button mat-icon-button class="col-auto" (click)="deleteRow(i)" type="button"
[disabled]="this.form.disabled">

View File

@ -1,6 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { DescriptionTemplateRadioBoxOptionEditorModel } from '../../../description-template-editor.model';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-radio-box-field-component',
@ -10,14 +11,18 @@ import { DescriptionTemplateRadioBoxOptionEditorModel } from '../../../descripti
export class DescriptionTemplateEditorRadioBoxFieldComponent implements OnInit {
@Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
ngOnInit() {
}
addNewRow() {
const radioListOptions: DescriptionTemplateRadioBoxOptionEditorModel = new DescriptionTemplateRadioBoxOptionEditorModel();
if (!this.form.get('data').get('options')) { (<UntypedFormGroup>this.form.get('data')).addControl('options', new UntypedFormBuilder().array([])); }
(<UntypedFormArray>this.form.get('data').get('options')).push(radioListOptions.buildForm());
const radioListOptions: DescriptionTemplateRadioBoxOptionEditorModel = new DescriptionTemplateRadioBoxOptionEditorModel(this.validationErrorModel);
const selectOptionsArray = this.form.get('data').get('options') as UntypedFormArray;
if (!selectOptionsArray) { (<UntypedFormGroup>this.form.get('data')).addControl('options', new UntypedFormBuilder().array([])); }
selectOptionsArray.push(radioListOptions.buildForm({rootPath: this.rootPath + 'data.options[' + selectOptionsArray.length + '].'}));
}
deleteRow(intex: number) {

View File

@ -1,6 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { UntypedFormArray, UntypedFormGroup } from '@angular/forms';
import { DescriptionTemplateSelectOptionEditorModel } from '../../../description-template-editor.model';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-select-field-component',
@ -10,13 +11,16 @@ import { DescriptionTemplateSelectOptionEditorModel } from '../../../description
export class DescriptionTemplateEditorSelectFieldComponent implements OnInit {
@Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
ngOnInit() {
}
addNewRow() {
const selectOptions: DescriptionTemplateSelectOptionEditorModel = new DescriptionTemplateSelectOptionEditorModel();
(<UntypedFormArray>this.form.get('data').get('options')).push(selectOptions.buildForm());
const selectOptions: DescriptionTemplateSelectOptionEditorModel = new DescriptionTemplateSelectOptionEditorModel(this.validationErrorModel);
const selectOptionsArray = this.form.get('data').get('options') as UntypedFormArray;
selectOptionsArray.push(selectOptions.buildForm({rootPath: this.rootPath + 'data.options[' + selectOptionsArray.length + '].'}));
}
deleteRow(intex: number) {

View File

@ -29,6 +29,8 @@
{{type.label}}
</mat-option>
</mat-select>
<mat-error *ngIf="form.get('data').get('types').dirty && form.get('data').get('types').hasError('required')">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.TYPES-REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="form.get('data').get('types').hasError('backendError')">{{form.get('data').get('types').getError('backendError').message}}</mat-error>
</mat-form-field>
<div class="col-12">
@ -37,13 +39,13 @@
<div *ngIf="isCustomType(type.value.value)" class="row">
<mat-form-field class="col">
<mat-label>{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.FIELD-UPLOAD-LABEL' | translate}}</mat-label>
<input matInput type="string" [formControl]="this.form.get('data').get('types').get(''+i).get('label')">
<mat-error *ngIf="form.get('data').get('types').get(''+i).get('label').hasError('backendError')">{{form.get('data').get('types').get(''+i).get('label').getError('backendError').message}}</mat-error>
<input matInput type="string" [formControl]="type.get('label')">
<mat-error *ngIf="type.get('label').hasError('backendError')">{{type.get('label').getError('backendError').message}}</mat-error>
</mat-form-field>
<mat-form-field class="col">
<mat-label>{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.FIELD-UPLOAD-VALUE' | translate}}</mat-label>
<input matInput type="string" [formControl]="this.form.get('data').get('types').get(''+i).get('value')">
<mat-error *ngIf="form.get('data').get('types').get(''+i).get('value').hasError('backendError')">{{form.get('data').get('types').get(''+i).get('value').getError('backendError').message}}</mat-error>
<input matInput type="string" [formControl]="type.get('value')">
<mat-error *ngIf="type.get('value').hasError('backendError')">{{type.get('value').getError('backendError').message}}</mat-error>
</mat-form-field>
<button mat-icon-button class="col-auto" (click)="deleteRow(i)" type="button" [disabled]="form.get('data').get('types').disabled">
<mat-icon>delete</mat-icon>

View File

@ -3,6 +3,7 @@ import { UntypedFormArray, UntypedFormBuilder, UntypedFormControl, UntypedFormGr
import { DescriptionTemplateUploadOption } from '@app/core/model/description-template/description-template';
import { ConfigurationService } from "@app/core/services/configuration/configuration.service";
import { DescriptionTemplateUploadOptionEditorModel } from '../../../description-template-editor.model';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-upload-field-component',
@ -45,6 +46,8 @@ export class DescriptionTemplateEditorUploadFieldComponent implements OnInit {
public typesFormControl = new UntypedFormControl();
@Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
constructor(private configurationService: ConfigurationService) { }
@ -79,12 +82,13 @@ export class DescriptionTemplateEditorUploadFieldComponent implements OnInit {
}
addNewRow(type: DescriptionTemplateUploadOption = null) {
const typeListOptions: DescriptionTemplateUploadOptionEditorModel = new DescriptionTemplateUploadOptionEditorModel();
const typesArray = this.form.get('data').get('types') as UntypedFormArray;
const typeListOptions: DescriptionTemplateUploadOptionEditorModel = new DescriptionTemplateUploadOptionEditorModel(this.validationErrorModel);
if (type != null) {
typeListOptions.fromModel(type);
}
(<UntypedFormGroup>this.form.get('data')).addControl('types', new UntypedFormBuilder().array([]));
(<UntypedFormArray>this.form.get('data').get('types')).push(typeListOptions.buildForm());
typesArray.push(typeListOptions.buildForm({rootPath: this.rootPath + 'data.types[' + typesArray.length + '].'}));
}
deleteRow(index: number) {

View File

@ -184,7 +184,8 @@
</mat-checkbox>
<!-- Default Value -->
<app-description-template-editor-default-value-component *ngIf="form.get('data')?.get('fieldType')?.value" class="col-6" [fieldType]="form.get('data').get('fieldType').value" [form]="this.form.get('defaultValue')" [formArrayOptions]="form.get('data')?.get('options')" [comboBoxType]="this.form.get('data')?.get('type')?.value" [internalDmpEntitiesType]="this.form.get('data')?.get('type')?.value" placeHolder="{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.DEFAULT-VALUE' | translate}}">
<app-description-template-editor-default-value-component *ngIf="form.get('data')?.get('fieldType')?.value" class="col-6" [fieldType]="form.get('data').get('fieldType').value" [form]="this.form.get('defaultValue')" [formArrayOptions]="form.get('data')?.get('options')" [comboBoxType]="this.form.get('data')?.get('type')?.value" [internalDmpEntitiesType]="this.form.get('data')?.get('type')?.value"
[validationErrorModel]= "validationErrorModel" placeHolder="{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.DEFAULT-VALUE' | translate}}">
</app-description-template-editor-default-value-component>
<div class="col-12"></div>
<div class="col-auto mb-4 mt-2">
@ -207,10 +208,10 @@
</div>
<div class="row" [ngSwitch]="form.get('data')?.get('fieldType')?.value " *ngIf="expandView">
<app-description-template-editor-external-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.EXTERNAL_SELECT" class="col-12" [form]="form"></app-description-template-editor-external-select-field-component>
<app-description-template-editor-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.SELECT" class="col-12" [form]="form"></app-description-template-editor-select-field-component>
<app-description-template-editor-radio-box-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.RADIO_BOX" class="col-12" [form]="form"></app-description-template-editor-radio-box-field-component>
<app-description-template-editor-upload-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.UPLOAD" class="col-12" [form]="form"></app-description-template-editor-upload-field-component>
<app-description-template-editor-external-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.EXTERNAL_SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="rootPath"></app-description-template-editor-external-select-field-component>
<app-description-template-editor-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="rootPath"></app-description-template-editor-select-field-component>
<app-description-template-editor-radio-box-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.RADIO_BOX" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="rootPath"></app-description-template-editor-radio-box-field-component>
<app-description-template-editor-upload-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.UPLOAD" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="rootPath"></app-description-template-editor-upload-field-component>
<app-description-template-editor-label-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.BOOLEAN_DECISION" class="col-12" [form]="form"></app-description-template-editor-label-field-component>
<app-description-template-editor-label-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.CHECK_BOX" class="col-12" [form]="form"></app-description-template-editor-label-field-component>

View File

@ -25,6 +25,7 @@ import { BaseComponent } from '@common/base/base.component';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { DescriptionTemplateFieldEditorModel, DescriptionTemplateRuleEditorModel } from '../../description-template-editor.model';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-field-component',
@ -46,6 +47,8 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple
@Input() canBeDeleted: boolean = true;
@Output() delete = new EventEmitter<void>();
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
@ -91,8 +94,9 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple
}
addNewRule() {
const rule: DescriptionTemplateRuleEditorModel = new DescriptionTemplateRuleEditorModel();
(<UntypedFormArray>this.form.get('visibilityRules')).push(rule.buildForm());
const rule: DescriptionTemplateRuleEditorModel = new DescriptionTemplateRuleEditorModel(this.validationErrorModel);
const ruleArray = this.form.get('visibilityRules') as UntypedFormArray;
(<UntypedFormArray>this.form.get('visibilityRules')).push(rule.buildForm({rootPath: this.rootPath + 'visibilityRules[' + ruleArray.length +'].'}));
}
get canApplyVisibility(): boolean {
@ -214,7 +218,8 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple
}
}
const form = (new DescriptionTemplateFieldEditorModel).fromModel(field).buildForm();
const form = (new DescriptionTemplateFieldEditorModel(this.validationErrorModel)).fromModel(field)
.buildForm({rootPath: this.rootPath});
const fields = this.form.parent as UntypedFormArray;

View File

@ -63,7 +63,9 @@
<app-description-template-editor-composite-field-component [form]="fieldset"
[viewOnly]="viewOnly" [numbering]="numbering + '.'+ (i+1)"
[hasFocus]="fieldset.get('id').value === selectedFieldSetId"
[datasetProfileId]="datasetProfileId">
[datasetProfileId]="datasetProfileId"
[validationErrorModel]="validationErrorModel"
[rootPath]="rootPath">
</app-description-template-editor-composite-field-component>
</mat-card-content>
</mat-card>

View File

@ -8,6 +8,7 @@ import { debounceTime } from 'rxjs/operators';
import { GENERAL_ANIMATIONS } from '../../animations/animations';
import { DescriptionTemplateFieldEditorModel, DescriptionTemplateFieldSetEditorModel } from '../../description-template-editor.model';
import { ToCEntry, ToCEntryType } from '../../table-of-contents/description-template-table-of-contents-entry';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-section-fieldset-component',
@ -27,6 +28,8 @@ export class DescriptionTemplateEditorSectionFieldSetComponent implements OnInit
@Output() removeFieldSet = new EventEmitter<string>();
@Output() addNewFieldSet = new EventEmitter<UntypedFormGroup>();
@Output() cloneFieldSet = new EventEmitter<UntypedFormGroup>();
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
idprefix = "id";

View File

@ -5,7 +5,7 @@
<mat-form-field class="col-12">
<input matInput type="text" [placeholder]="('DESCRIPTION-TEMPLATE-EDITOR.STEPS.GENERAL-INFO.UNTITLED' | translate)+ ' '+ ('DESCRIPTION-TEMPLATE-EDITOR.STEPS.SECTION-INFO.SECTION' | translate)"formControlName="title">
<mat-error *ngIf="form.get('title').hasError('backendError')">{{form.get('title').getError('backendError').message}}</mat-error>
<mat-error >{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="form.get('title').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<div class="heading col-12">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.SECTION-INFO.SECTION-DESCRIPTION' | translate}} </div>
<div class="hint col-12">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.SECTION-INFO.SECTION-DESCRIPTION-HINT' | translate}}</div>

View File

@ -30,7 +30,8 @@
</mat-select>
<mat-error>{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="ruleFormGroup.get('target').hasError('backendError')">{{ruleFormGroup.get('target').getError('backendError').message}}</mat-error>
<mat-error *ngIf="ruleFormGroup.get('target').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<div class="col-auto align-self-center"><button mat-icon-button type="button" (click)="deleteRule(i);" [disabled]="viewOnly">

View File

@ -1,9 +1,11 @@
import { Component, Input, OnInit } from '@angular/core';
import { AbstractControl, UntypedFormArray, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { AbstractControl, FormArray, 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';
import { ToCEntryType } from '../../table-of-contents/description-template-table-of-contents-entry';
import { DescriptionTemplateRuleEditorModel } from '../../description-template-editor.model';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-visibility-rule-component',
@ -19,6 +21,7 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
@Input() fieldTypeForCheck: DescriptionTemplateFieldType;
@Input() formArrayOptionsForCheck: UntypedFormArray;
@Input() viewOnly: boolean;
@Input() validationErrorModel: ValidationErrorModel;
options: OptionItem[];
@ -41,6 +44,7 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
deleteRule(index) {
this.form.removeAt(index);
// TODO akis reply validators fix
this.form.markAsDirty();//deactivate guard
}

View File

@ -200,7 +200,8 @@
<div class="hint">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.PAGE-INFO.PAGE-NAME-HINT' | translate}}</div>
<mat-form-field>
<input type="text" matInput formControlName="title" [placeholder]="('DESCRIPTION-TEMPLATE-EDITOR.STEPS.GENERAL-INFO.UNTITLED' | translate) +' '+ ('DESCRIPTION-TEMPLATE-EDITOR.STEPS.PAGE-INFO.PAGE' |translate)">
<mat-error>{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="selectedTocEntry.form.get('title').hasError('backendError')">{{selectedTocEntry.form.get('title').getError('backendError').message}}</mat-error>
<mat-error *ngIf="selectedTocEntry.form.get('title').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
@ -212,7 +213,8 @@
</div>
<div class="col-12" *ngIf="(selectedTocEntry.type === tocEntryEnumValues.Section) || (selectedTocEntry.type === tocEntryEnumValues.FieldSet)">
<app-description-template-editor-section-fieldset-component [tocentry]="selectedTocEntry" [viewOnly]="viewOnly" [datasetProfileId]="datasetProfileId" (addNewFieldSet)="addNewEntry({childType: tocEntryEnumValues.FieldSet,parent: {formGroup: $event}})" (removeFieldSet)="onRemoveEntry(_findTocEntryById($event, toCEntries))" (cloneFieldSet)="cloneFieldSet($event)" (selectedEntryId)="displayItem(_findTocEntryById($event, toCEntries))" (dataNeedsRefresh)="onDataNeedsRefresh()">
<app-description-template-editor-section-fieldset-component [tocentry]="selectedTocEntry" [viewOnly]="viewOnly" [datasetProfileId]="datasetProfileId" [validationErrorModel]="editorModel.validationErrorModel" [rootPath]="rootPath"
(addNewFieldSet)="addNewEntry({childType: tocEntryEnumValues.FieldSet,parent: {formGroup: $event}})" (removeFieldSet)="onRemoveEntry(_findTocEntryById($event, toCEntries))" (cloneFieldSet)="cloneFieldSet($event)" (selectedEntryId)="displayItem(_findTocEntryById($event, toCEntries))" (dataNeedsRefresh)="onDataNeedsRefresh()">
</app-description-template-editor-section-fieldset-component>
</div>
@ -225,6 +227,8 @@
<div class="row w-100 justify-content-center">
<div class="col-auto">
{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.PAGE-INFO.ACTIONS.NOTHING-HERE-HINT'| translate}}
<p *ngIf="formGroup.get('definition').get('pages').dirty && formGroup.get('definition').get('pages').hasError('required')">{{'DMP-BLUEPRINT-EDITOR.FIELDS-REQUIRED' | translate}}</p>
<p *ngIf="formGroup.get('definition').get('pages').hasError('backendError')">{{formGroup.get('definition').get('pages').getError('backendError').message}}</p>
</div>
</div>
<div class="row justify-content-center">

View File

@ -70,6 +70,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
usersMap: Map<Guid, User> = new Map<Guid, User>();
userFormControl = new FormControl();
rootPath: string = null;
// selectedSystemFields: Array<DescriptionTemplateSystemFieldType> = [];
@ -571,18 +572,19 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
addNewEntry(tce: NewEntryType) {
const parent = tce.parent;
const pages = this.formGroup.get('definition').get('pages') as FormArray;
let pageIndex = -1;
// define entry type
switch (tce.childType) {
case ToCEntryType.Page:
const pagesArray = (this.formGroup.get('definition').get('pages') as UntypedFormArray);
const page: DescriptionTemplatePageEditorModel = new DescriptionTemplatePageEditorModel(this.editorModel.validationErrorModel);
page.id = Guid.create().toString();
if (isNaN(pagesArray.length)) { page.ordinal = 0; } else { page.ordinal = pagesArray.length; }
const pageForm = page.buildForm({ rootPath: 'definition.pages[' + pagesArray.length + '].' });
if (isNaN(pages.length)) { page.ordinal = 0; } else { page.ordinal = pages.length; }
const pageForm = page.buildForm({ rootPath: 'definition.pages[' + pages.length + '].' });
// this.dataModel.pages.push(page);
pagesArray.push(pageForm);
pages.push(pageForm);
// this.form.updateValueAndValidity();
this.refreshToCEntries();
this.selectedTocEntry = this._findTocEntryById(pageForm.get('id').value, this.toCEntries);
@ -595,7 +597,16 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
let sectionsArray: UntypedFormArray;
if (parent.type === ToCEntryType.Page) {//FIRST LEVEL SECTION
sectionsArray = (this.formGroup.get('definition').get('pages') as FormArray).controls.find(x => x.get('id')?.value === parent.id).get('sections') as UntypedFormArray;
for (let i = 0; i < pages?.length; i++) {
let page = pages.at(i);
let pageId = page.get('id').value;
if (pageId == parent.id) {
pageIndex = i;
break;
}
}
sectionsArray = pages.controls.find(x => x.get('id')?.value === parent.id).get('sections') as UntypedFormArray;
try {
const max = sectionsArray.controls.map(control => control.get('ordinal').value)
.reduce((a, b) => Math.max(a, b));
@ -605,10 +616,26 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
section.ordinal = sectionsArray.length;
}
sectionsArray.push(section.buildForm({ rootPath: 'definition.sections[' + sectionsArray.length + '].' }));
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages['+ pageIndex +'].sections[' + sectionsArray.length + '].' }));
// this.form.updateValueAndValidity();
} else if (parent.type == ToCEntryType.Section) { //SUBSECTION OF SECTION
let sectionIndexes: number[] = [];
for (let j = 0; j < pages.length; j++) {
const parentSections = pages.at(j).get('sections') as UntypedFormArray;
sectionIndexes = this.findSectionIndex(parentSections, parent.id);
if (sectionIndexes && sectionIndexes.length > 0){
pageIndex = j;
break;
}
}
let parentSectionRootPath = '';
if(sectionIndexes.length > 0){
sectionIndexes.forEach(index => {
parentSectionRootPath = parentSectionRootPath + 'sections[' + index +'].'
});
}
sectionsArray = parent.form.get('sections') as UntypedFormArray;
//adding page parent MAYBE NOT NEEDED
@ -619,7 +646,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
section.ordinal = sectionsArray.length;
}
sectionsArray.push(section.buildForm({ rootPath: 'definition.sections[' + sectionsArray.length + '].' }));
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages['+ pageIndex +'].' + parentSectionRootPath + 'sections[' + sectionsArray.length + '].' }));
// (child.form.parent as FormArray).push(section.buildForm());
} else {
@ -638,36 +665,31 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
break;
case ToCEntryType.FieldSet:
let sectionIndex = -1;
const pages = (this.formGroup.get('definition').get('pages') as UntypedFormArray);
let sectionIndexes: number[] = [];
for (let j = 0; j < pages.length; j++) {
const sections = (this.formGroup.get('definition').get('pages') as UntypedFormArray).at(j).get('sections') as UntypedFormArray;
for (let i = 0; i < sections?.length; i++) {
let section = sections.at(i);
let sectionId = section.get('id').value;
if (sectionId == parent.id) {
sectionIndex = i;
const parentSections = pages.at(j).get('sections') as UntypedFormArray;
sectionIndexes = this.findSectionIndex(parentSections, parent.id);
if (sectionIndexes && sectionIndexes.length > 0){
pageIndex = j;
break;
}
}
let parentSectionRootPath = '';
if(sectionIndexes.length > 0){
sectionIndexes.forEach(index => {
parentSectionRootPath = parentSectionRootPath + 'sections[' + index +'].'
});
}
if (sectionIndex > -1) {
if (sectionIndexes.length > 0) {
//create one field form fieldset
const field: DescriptionTemplateFieldEditorModel = new DescriptionTemplateFieldEditorModel(this.editorModel.validationErrorModel);
field.id = Guid.create().toString();
field.ordinal = 0;//first filed in the fields list
// const fieldForm = field.buildForm();
// fieldForm.setValidators(this.customFieldValidator());
// fieldForm.get('viewStyle').get('renderStyle').setValidators(Validators.required);
// fieldSet.fields.push(field);
// field.ordinal = fieldSet.fields.length-1;
const fieldSetsArray = parent.form.get('fieldSets') as UntypedFormArray
const fieldForm = field.buildForm({ rootPath: 'definition.sections[' + sectionIndex + '].fieldSets[' + fieldSetsArray.length + '].fields[' + 0 + '].' });
//store rootPath for next levels/components
this.rootPath = 'definition.pages['+ pageIndex +'].'+ parentSectionRootPath+ 'fieldSets[' + fieldSetsArray.length + '].fields[' + 0 + '].';
const fieldForm = field.buildForm({ rootPath: this.rootPath});
//give fieldset id and ordinal
const fieldSet: DescriptionTemplateFieldSetEditorModel = new DescriptionTemplateFieldSetEditorModel(this.editorModel.validationErrorModel);
@ -680,7 +702,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
} catch {
fieldSet.ordinal = fieldSetsArray.length;
}
const fieldsetForm = fieldSet.buildForm({ rootPath: 'definition.sections[' + sectionIndex + '].fieldSets[' + fieldSetsArray.length + '].' });
const fieldsetForm = fieldSet.buildForm({ rootPath: 'definition.pages['+ pageIndex +'].' + parentSectionRootPath + 'fieldSets[' + fieldSetsArray.length + '].' });
(fieldsetForm.get('fields') as UntypedFormArray).push(fieldForm);
fieldSetsArray.push(fieldsetForm);
@ -699,6 +721,26 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
this.formGroup.updateValueAndValidity();
}
private findSectionIndex(sectionFormArray: UntypedFormArray, parentId: string) : number[]{
for (let i = 0; i < sectionFormArray?.length; i++) {
let sectionFormGroup = sectionFormArray.at(i);
let sectionId = sectionFormGroup.get('id').value;
const parentSections = sectionFormGroup.get('sections') as UntypedFormArray;
if (sectionId == parentId) {
return [i];
} else if (parentSections && parentSections.length > 0){
const indexes: number[]= this.findSectionIndex(parentSections, parentId);
if (indexes && indexes.length > 0){
indexes.unshift(i);
return indexes;
}
}
}
return null;
}
onRemoveEntry(tce: ToCEntry) {
@ -719,12 +761,12 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
}
private _deleteEntry(tce: ToCEntry) {
const pages = this.formGroup.get('definition').get('pages') as UntypedFormArray;
let pageIndex = -1;
//define entry type
switch (tce.type) {
case ToCEntryType.Page:
const pages = this.formGroup.get('definition').get('pages') as UntypedFormArray;
let pageIndex = -1;
//get the index
for (let i = 0; i < pages.length; i++) {
let page = pages.at(i) as UntypedFormGroup;
@ -739,23 +781,6 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
//remove page
this._updateSelectedItem(tce);
pages.removeAt(pageIndex);
//clean up sections of removed page
const sections = (this.formGroup.get('definition').get('sections') as UntypedFormArray);
const sectionsIndexToBeRemoved = [];
sections.controls.forEach((section, idx) => {
if (section.get('page').value === tce.id) {
sectionsIndexToBeRemoved.push(idx);
}
});
if (sectionsIndexToBeRemoved.length) {
sectionsIndexToBeRemoved.reverse().forEach(index => {
sections.removeAt(index);
});
}
//update page ordinals
for (let i = 0; i < pages.length; i++) {
@ -772,30 +797,29 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
case ToCEntryType.Section:
//FIRST LEVEL SECTION CASE
let index = -1;
const sections = (this.formGroup.get('definition').get('sections') as UntypedFormArray);
for (let i = 0; i < sections.length; i++) {
let sectionIndex = -1;
for (let j = 0; j < pages.length; j++) {
const sections = pages.at(j).get('sections') as UntypedFormArray;
for (let i = 0; i < sections?.length; i++) {
let section = sections.at(i);
let sectionId = section.get('id').value;
if (sectionId == tce.id) {
index = i;
sectionIndex = i;
pageIndex = j;
break;
}
}
}
if (index >= 0) { //section found
if (sectionIndex >= 0) { //section found
const sections = (this.formGroup.get('definition').get('sections') as UntypedFormArray);
const sections = pages.at(pageIndex).get('sections') as UntypedFormArray;
//remove section
this._updateSelectedItem(tce);
sections.removeAt(index);
sections.removeAt(sectionIndex);
//update ordinal
for (let i = 0; i < sections.length; i++) {
@ -804,19 +828,42 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
} else {//NOT FOUND IN FIRST LEVEL CASE
//LOOK FOR SUBSECTION CASE
let parentFormArray = tce.form.parent as UntypedFormArray;
let parentSectionIndex = -1;
let sectionIndex = -1;
for (let j = 0; j < pages.length; j++) {
const parentSections = pages.at(j).get('sections') as UntypedFormArray;
for (let i = 0; i < parentFormArray.length; i++) {
let section = parentFormArray.at(i);
for (let i = 0; i < parentSections?.length; i++) {
const sections = (pages.at(j).get('sections') as UntypedFormArray).at(i).get('sections') as UntypedFormArray;
if (section.get('id').value == tce.id) {
index = i;
for (let k = 0; i < sections?.length; i++) {
let section = sections.at(i);
let sectionId = section.get('id').value;
if (sectionId == tce.id) {
sectionIndex = k;
parentSectionIndex = i;
pageIndex = j;
break;
}
}
if (index >= 0) {
}
}
// let parentFormArray = tce.form.parent as UntypedFormArray;
// for (let i = 0; i < parentFormArray.length; i++) {
// let section = parentFormArray.at(i);
// if (section.get('id').value == tce.id) {
// index = i;
// break;
// }
// }
if (sectionIndex >= 0) {
this._updateSelectedItem(tce);
parentFormArray.removeAt(index);
const parentFormArray = (pages.at(pageIndex).get('sections') as UntypedFormArray).at(parentSectionIndex).get('sections') as UntypedFormArray;
parentFormArray.removeAt(sectionIndex);
//update odrinal
@ -877,14 +924,30 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
this.selectedTocEntry = null;
} else {
const pages = this.formGroup.get('definition').get('pages') as UntypedFormArray;
//if first level section
const firstLevelSections = (this.formGroup.get('definition').get('sections') as UntypedFormArray);
// const firstLevelSections = (this.formGroup.get('definition').get('sections') as UntypedFormArray);
// let isFirstLevel: boolean = false;
// firstLevelSections.controls.forEach(section => {
// if (section.get('id').value === tce.id) {
// isFirstLevel = true;
// }
// });
let isFirstLevel: boolean = false;
firstLevelSections.controls.forEach(section => {
if (section.get('id').value === tce.id) {
for (let j = 0; j < pages.length; j++) {
const sections = pages.at(j).get('sections') as UntypedFormArray;
for (let i = 0; i < sections?.length; i++) {
let section = sections.at(i);
let sectionId = section.get('id').value;
if (sectionId == tce.id) {
isFirstLevel = true;
break;
}
});
}
}
let parentId = null;
if (isFirstLevel) {

View File

@ -18,7 +18,7 @@ export class DescriptionTemplateEditorModel extends BaseEditorModel implements D
language: string;
type: Guid;
status: DescriptionTemplateStatus = DescriptionTemplateStatus.Draft;
definition: DescriptionTemplateDefinitionEditorModel = new DescriptionTemplateDefinitionEditorModel();
definition: DescriptionTemplateDefinitionEditorModel = new DescriptionTemplateDefinitionEditorModel(this.validationErrorModel);
users: UserDescriptionTemplateEditorModel[] = [];
permissions: string[];
@ -229,8 +229,8 @@ export class DescriptionTemplateDefinitionEditorModel implements DescriptionTemp
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}pages[${index}].`
}), context.getValidation('pages')
)
})
), context.getValidation('pages').validators
),
});
}
@ -311,8 +311,8 @@ export class DescriptionTemplatePageEditorModel implements DescriptionTemplatePa
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}sections[${index}].`
}), context.getValidation('sections')
)
})
), context.getValidation('sections').validators
),
});
}
@ -428,8 +428,8 @@ export class DescriptionTemplateSectionEditorModel implements DescriptionTemplat
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}sections[${index}].`
}), context.getValidation('sections')
)
})
), context.getValidation('sections').validators
),
fieldSets: this.formBuilder.array(
(this.fieldSets ?? []).map(
@ -437,8 +437,8 @@ export class DescriptionTemplateSectionEditorModel implements DescriptionTemplat
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}fieldSets[${index}].`
}), context.getValidation('fieldSets')
)
})
), context.getValidation('fieldSets').validators
)
});
}
@ -509,7 +509,7 @@ export class DescriptionTemplateFieldSetEditorModel implements DescriptionTempla
description: string;
extendedDescription: string;
additionalInformation: string;
multiplicity: DescriptionTemplateMultiplicityEditorModel = new DescriptionTemplateMultiplicityEditorModel();
multiplicity: DescriptionTemplateMultiplicityEditorModel = new DescriptionTemplateMultiplicityEditorModel(this.validationErrorModel);
hasCommentField: boolean = false;
fields: DescriptionTemplateFieldEditorModel[] = [];
@ -567,8 +567,8 @@ export class DescriptionTemplateFieldSetEditorModel implements DescriptionTempla
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}fields[${index}].`
}), context.getValidation('fields')
)
})
), context.getValidation('fields').validators
)
});
}
@ -722,7 +722,7 @@ export class DescriptionTemplateFieldEditorModel implements DescriptionTemplateF
visibilityRules: DescriptionTemplateRuleEditorModel[] = [];
validations: DescriptionTemplateFieldValidationType[] = [];
includeInExport: boolean = false;
data: DescriptionTemplateLabelDataEditorModel = new DescriptionTemplateLabelDataEditorModel();
data: DescriptionTemplateLabelDataEditorModel = new DescriptionTemplateLabelDataEditorModel(this.validationErrorModel);
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
@ -1242,9 +1242,9 @@ export class DescriptionTemplateExternalSelectSourceEditorModel implements Descr
url: string;
method: string;
optionsRoot: string;
sourceBinding: DescriptionTemplateExternalSelectSourceBindingEditorModel = new DescriptionTemplateExternalSelectSourceBindingEditorModel();
sourceBinding: DescriptionTemplateExternalSelectSourceBindingEditorModel = new DescriptionTemplateExternalSelectSourceBindingEditorModel(this.validationErrorModel);
hasAuth: boolean;
auth: DescriptionTemplateExternalSelectAuthDataEditorModel = new DescriptionTemplateExternalSelectAuthDataEditorModel();
auth: DescriptionTemplateExternalSelectAuthDataEditorModel = new DescriptionTemplateExternalSelectAuthDataEditorModel(this.validationErrorModel);
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
constructor(
@ -1849,8 +1849,9 @@ export class DescriptionTemplateUploadDataEditorModel extends DescriptionTemplat
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}types[${index}].`
}), context.getValidation('types')
)));
})
), context.getValidation('types').validators
));
return formGroup;
}

View File

@ -139,7 +139,7 @@
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
<input matInput type="text" name="value" [formControl]="field.get('value')" required>
<input matInput type="text" name="value" [formControl]="field.get('value')">
<mat-error *ngIf="field.get('value').hasError('backendError')">{{field.get('value').getError('backendError').message}}</mat-error>
<mat-error *ngIf="field.get('value').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>

View File

@ -220,7 +220,7 @@ export class FieldEditorModel implements FieldPersist {
baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}code`)] });
baseValidationArray.push({ key: 'dataType', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}dataType`)] });
baseValidationArray.push({ key: 'value', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}value`)] });
baseValidationArray.push({ key: 'value', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}value`)] });
baseContext.validation = baseValidationArray;
return baseContext;

View File

@ -574,7 +574,9 @@
"PRODUCED": "Produced dataset",
"REUSED": "Reused dataset",
"OTHER": "Other"
}
},
"FIELD-LABEL": "Label",
"FIELD-MULTIPLE-SELECT": "Multiple Select"
},
"ERROR-MESSAGES": {
"FIELD-OTHER-SOURCES-REQUIRED": "At least one source must be provided.",