description template ui changes

This commit is contained in:
Diamantis Tziotzios 2024-02-08 17:14:25 +02:00
parent 9d4e814d1c
commit 98d6636855
14 changed files with 89 additions and 163 deletions

View File

@ -65,8 +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"
[validationErrorModel]="validationErrorModel" [rootPath]="rootPath + 'fields[' + i + '].'" (delete)="deleteField(i)">
<app-description-template-editor-field-component class="col-12" [form]="field" [showOrdinal]="false" [viewOnly]="viewOnly" [expandView]="hasFocus" [canBeDeleted]="fieldsArray.length !=1"
[validationErrorModel]="validationErrorModel" [validationRootPath]="validationRootPath + '.fields[' + i + '].'" (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

@ -1,4 +1,4 @@
import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
import { AbstractControl, UntypedFormArray, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { MatCheckboxChange } from '@angular/material/checkbox';
import { MatDialog } from '@angular/material/dialog';
@ -39,7 +39,6 @@ import { ValidationErrorModel } from '@common/forms/validation/error-model/valid
export class DescriptionTemplateEditorCompositeFieldComponent extends BaseComponent implements OnInit, OnChanges {
@Input() form: UntypedFormGroup;
@Input() indexPath: string;
@Input() viewOnly: boolean;
@Input() datasetProfileId?: string;
@ -48,7 +47,7 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon
@Input() hasFocus: boolean = false;
@ViewChild("inputs") inputs: TransitionGroupComponent;
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
@Input() validationRootPath: string;
showPreview: boolean = true;
previewDirty: boolean = false;
@ -65,6 +64,7 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon
private myCustomValidators: EditorCustomValidators = new EditorCustomValidators();
isMultiplicityEnabled = false;
constructor(
private dialog: MatDialog,
@ -321,22 +321,22 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon
}
addNewField() {
const field: DescriptionTemplateFieldEditorModel = new DescriptionTemplateFieldEditorModel();
field.id = Guid.create().toString();
// addNewField() {
// const field: DescriptionTemplateFieldEditorModel = new DescriptionTemplateFieldEditorModel();
// field.id = Guid.create().toString();
field.ordinal = (this.form.get('fields') as UntypedFormArray).length;
// field.ordinal = (this.form.get('fields') as UntypedFormArray).length;
const fieldForm = field.buildForm();
// fieldForm.setValidators(this.customFieldValidator());
// const fieldForm = field.buildForm();
// // fieldForm.setValidators(this.customFieldValidator());
// fieldForm.get('viewStyle').get('renderStyle').setValidators(Validators.required);
// // fieldForm.get('viewStyle').get('renderStyle').setValidators(Validators.required);
(<UntypedFormArray>this.form.get('fields')).push(fieldForm);
// (<UntypedFormArray>this.form.get('fields')).push(fieldForm);
this.setTargetField(fieldForm);
fieldForm.updateValueAndValidity();
}
// this.setTargetField(fieldForm);
// fieldForm.updateValueAndValidity();
// }
DeleteField(index) {
@ -573,7 +573,7 @@ export class DescriptionTemplateEditorCompositeFieldComponent extends BaseCompon
}
}
(<UntypedFormArray>this.form.get('fields')).push(new DescriptionTemplateFieldEditorModel(this.validationErrorModel).fromModel(field).buildForm({rootPath: this.rootPath + 'fields[' + this.fieldsArray.length + '].'}));
(<UntypedFormArray>this.form.get('fields')).push(new DescriptionTemplateFieldEditorModel(this.validationErrorModel).fromModel(field).buildForm({rootPath: this.validationRootPath + '.fields[' + this.fieldsArray.length + ']'}));
this.inputs.init();
// fieldForm.get('viewStyle').get('renderStyle').updateValueAndValidity();
// fieldForm.get('data').updateValueAndValidity();

View File

@ -1,3 +1,4 @@
{{validationRootPath}}
<ng-container *ngIf="expandView">
<!-- ACTIONS PER FIELD -->
@ -201,18 +202,18 @@
<ng-container *ngIf="form.get('visibilityRules')?.value.length">
<h4 class="col-12" style="font-weight: bold">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.RULES-TITLE' | translate}}
</h4>
<app-description-template-editor-visibility-rule-component class="col-12" [form]="form.get('visibilityRules')" [validationErrorModel]="validationErrorModel" [rootPath]="rootPath" [fieldTypeForCheck]="form.get('data').get('fieldType').value" [formArrayOptionsForCheck]="this.form.get('data')?.get('options')" [viewOnly]="viewOnly"></app-description-template-editor-visibility-rule-component>
<app-description-template-editor-visibility-rule-component class="col-12" [form]="form.get('visibilityRules')" [validationErrorModel]="validationErrorModel" [rootPath]="validationRootPath" [fieldTypeForCheck]="form.get('data').get('fieldType').value" [formArrayOptionsForCheck]="this.form.get('data')?.get('options')" [viewOnly]="viewOnly"></app-description-template-editor-visibility-rule-component>
<!-- <div class="col-12" *ngIf="!viewOnly">
<button mat-button class="full-width" (click)="addNewRule()" [disabled]="!form.get('data').get('fieldType').value">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.ACTIONS.ADD-RULE' | translate}}</button>
</div> -->
</ng-container>
</div>
<div class="row" [ngSwitch]="form.get('data')?.get('fieldType')?.value " *ngIf="expandView">
<div class="row" [ngSwitch]="form.get('data')?.get('fieldType')?.value" >
<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-external-select-field-component *ngSwitchCase="descriptionTemplateFieldTypeEnum.EXTERNAL_SELECT" class="col-12" [form]="form" [validationErrorModel]= "validationErrorModel" [rootPath]="validationRootPath"></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]="validationRootPath"></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]="validationRootPath"></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]="validationRootPath"></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

@ -35,8 +35,6 @@ import { ValidationErrorModel } from '@common/forms/validation/error-model/valid
export class DescriptionTemplateEditorFieldComponent extends BaseComponent implements OnInit, ErrorStateMatcher {
@Input() viewOnly: boolean;
@Input() form: UntypedFormGroup;
@Input() showOrdinal = true;
@Input() indexPath: string;
validationTypeEnum = ValidationType;
// isFieldMultiplicityEnabled = false;
@ -48,7 +46,7 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple
@Output() delete = new EventEmitter<void>();
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
@Input() validationRootPath: string;
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
@ -96,7 +94,7 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple
addNewRule() {
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 +'].'}));
(<UntypedFormArray>this.form.get('visibilityRules')).push(rule.buildForm({rootPath: this.validationRootPath + 'visibilityRules[' + ruleArray.length +'].'}));
}
get canApplyVisibility(): boolean {
@ -219,7 +217,7 @@ export class DescriptionTemplateEditorFieldComponent extends BaseComponent imple
}
const form = (new DescriptionTemplateFieldEditorModel(this.validationErrorModel)).fromModel(field)
.buildForm({rootPath: this.rootPath});
.buildForm({rootPath: this.validationRootPath});
const fields = this.form.parent as UntypedFormArray;

View File

@ -1,14 +0,0 @@
<mat-card *ngFor="let pageControl of form['controls']; let i=index;" class="page-card">
<mat-card-title class="page-card-title">{{'DATASET-PROFILE-EDITOR.STEPS.PAGES.PAGE-PREFIX' | translate}} {{i + 1}}</mat-card-title>
<div class="row">
<mat-form-field class="col">
<input matInput type="text" placeholder="{{'DATASET-PROFILE-EDITOR.STEPS.PAGES.PAGE-INPUT-TITLE' | translate}}"
[formControl]="pageControl.get('title')" required>
<mat-error *ngIf="pageControl.get('title').hasError('backendError')">{{pageControl.get('title').getError('backendError').message}}</mat-error>
<mat-error *ngIf="pageControl.get('title').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
<button mat-icon-button type="button" class="col-auto" (click)="removePage(i)" [disabled]="viewOnly">
<mat-icon>delete</mat-icon>
</button>
</div>
</mat-card>

View File

@ -1,7 +0,0 @@
.page-card {
margin-bottom: 1em;
.page-card-title {
text-align: center;
}
}

View File

@ -1,17 +0,0 @@
import { Component, Input } from '@angular/core';
import { UntypedFormArray } from '@angular/forms';
@Component({
selector: 'app-dataset-profile-editor-page-component',
templateUrl: './dataset-profile-editor-page.component.html',
styleUrls: ['./dataset-profile-editor-page.component.scss']
})
export class DatasetProfileEditorPageComponent {
@Input() form: UntypedFormArray;
@Input() viewOnly: boolean;
removePage(index) {
(<UntypedFormArray>this.form).removeAt(index);
}
}

View File

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

View File

@ -29,7 +29,7 @@ export class DescriptionTemplateEditorSectionFieldSetComponent implements OnInit
@Output() addNewFieldSet = new EventEmitter<UntypedFormGroup>();
@Output() cloneFieldSet = new EventEmitter<UntypedFormGroup>();
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
@Input() validationRootPath: string;
idprefix = "id";
@ -125,7 +125,6 @@ export class DescriptionTemplateEditorSectionFieldSetComponent implements OnInit
// return parent;
// }
private initialize() {
if (this.tocentry.type === ToCEntryType.Section) {
this.form = this.tocentry.form;

View File

@ -1,8 +1,6 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { UntypedFormArray, UntypedFormGroup } from '@angular/forms';
import { Component, Input, OnInit } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { BaseComponent } from '@common/base/base.component';
import { Guid } from '@common/types/guid';
import { DescriptionTemplateFieldEditorModel, DescriptionTemplateFieldSetEditorModel, DescriptionTemplateSectionEditorModel } from '../../description-template-editor.model';
@Component({
selector: 'app-description-template-editor-section-component',
@ -13,63 +11,10 @@ import { DescriptionTemplateFieldEditorModel, DescriptionTemplateFieldSetEditorM
export class DescriptionTemplateEditorSectionComponent extends BaseComponent implements OnInit {
@Input() form: UntypedFormGroup;
@Input() indexPath: string;
@Input() viewOnly: boolean;
@Output() fieldsetAdded = new EventEmitter<String>(); //returns the id of the fieldset added
constructor() { super(); }
ngOnInit() {
}
addField() {
const fieldSet: DescriptionTemplateFieldSetEditorModel = new DescriptionTemplateFieldSetEditorModel();
fieldSet.ordinal = (this.form.get('fieldSets') as UntypedFormArray).length;
const field: DescriptionTemplateFieldEditorModel = new DescriptionTemplateFieldEditorModel();
field.id = Guid.create().toString();
field.ordinal = 0;//first field in fields
fieldSet.fields.push(field);
fieldSet.id = Guid.create().toString();
const fieldsetsArray = this.form.get('fieldSets') as UntypedFormArray;
fieldsetsArray.push(fieldSet.buildForm());
const fieldSetForm = fieldsetsArray.at(fieldsetsArray.length - 1);
//emit id inserted
if (fieldSetForm) {
const id: string = fieldSetForm.get('id').value;
this.fieldsetAdded.emit(id);
}
}
addSectioninSection() {
const section: DescriptionTemplateSectionEditorModel = new DescriptionTemplateSectionEditorModel();
//this.dataModel.sections.push(section);
(<UntypedFormArray>this.form.get('sections')).push(section.buildForm());
}
DeleteSectionInSection(index) {
//this.dataModel.sections.splice(index, 1);
(<UntypedFormArray>this.form.get('sections')).removeAt(index);
}
deleteFieldSet(index) {
//this.dataModel.fieldSets.splice(index, 1);
(<UntypedFormArray>this.form.get('fieldSets')).removeAt(index);
}
keepPageSelectionValid(pagesJson: Array<any>) {
const selectedPage = this.form.get('page').value as String;
// const pages: Array<PageEditorModel> = JsonSerializer.fromJSONArray(pagesJson, Page);
if (pagesJson.find(elem => elem.id === selectedPage) === undefined) {
this.form.get('page').reset();
}
}
getFieldTile(formGroup: UntypedFormGroup, index: number) {
if (formGroup.get('title') && formGroup.get('title').value && formGroup.get('title').value.length > 0) { return formGroup.get('title').value; }
return "Field " + (index + 1);
}
}

View File

@ -178,7 +178,15 @@
<div class="row sticky-top table-container" style="top : 7em;">
<description-template-table-of-contents class="toc-pane-container col" style="margin-bottom: 2em;" [links]="toCEntries" (itemClick)="displayItem($event)" (createEntry)="addNewEntry($event)" (removeEntry)="onRemoveEntry($event)" [itemSelected]="selectedTocEntry" [viewOnly]="formGroup.disabled" (dataNeedsRefresh)="onDataNeedsRefresh($event)" [colorizeInvalid]="colorizeInvalid">
<description-template-table-of-contents class="toc-pane-container col" style="margin-bottom: 2em;"
[links]="toCEntries"
(itemClick)="displayItem($event)"
(createEntry)="addNewEntry($event)"
(removeEntry)="onRemoveEntry($event)"
[itemSelected]="selectedTocEntry"
[viewOnly]="formGroup.disabled"
(dataNeedsRefresh)="onDataNeedsRefresh($event)"
[colorizeInvalid]="colorizeInvalid">
</description-template-table-of-contents>
</div>
</div>
@ -213,8 +221,14 @@
</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" [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
[tocentry]="selectedTocEntry"
[viewOnly]="viewOnly"
[datasetProfileId]="datasetProfileId"
[validationErrorModel]="editorModel.validationErrorModel"
[validationRootPath]="selectedTocEntry.validationRootPath"
(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>

View File

@ -441,7 +441,8 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
form: pageElement,
numbering: (i + 1).toString(),
subEntriesType: ToCEntryType.Section,
subEntries: []
subEntries: [],
validationRootPath: 'definition.pages[' + i + ']'
} as ToCEntry;
const subEntries = [];
@ -452,10 +453,11 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
label: sectionElement.get('title').value,
type: ToCEntryType.Section,
form: sectionElement,
numbering: page.numbering + '.' + (subEntries.length + 1)
numbering: page.numbering + '.' + (subEntries.length + 1),
validationRootPath: page.validationRootPath + '.sections[' + i + ']'
} as ToCEntry;
const sectionItems = this.populateSections(sectionElement.get('sections') as UntypedFormArray, item.numbering);
const fieldSetItems = this.populateFieldSets(sectionElement.get('fieldSets') as UntypedFormArray, item.numbering);
const sectionItems = this.populateSections(sectionElement.get('sections') as UntypedFormArray, item.numbering, item.validationRootPath);
const fieldSetItems = this.populateFieldSets(sectionElement.get('fieldSets') as UntypedFormArray, item.numbering, item.validationRootPath);
if (sectionItems != null) {
item.subEntries = sectionItems;
@ -483,7 +485,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
return result;
}
private populateSections(sections: UntypedFormArray, existingNumbering: string): ToCEntry[] {
private populateSections(sections: UntypedFormArray, existingNumbering: string, validationRootPath: string): ToCEntry[] {
if (sections == null || sections.controls == null || sections.controls.length == 0) { return null; }
const result: ToCEntry[] = [];
@ -494,10 +496,11 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
label: sectionElement.get('title').value,
type: ToCEntryType.Section,
form: sectionElement,
numbering: existingNumbering + '.' + (i + 1)
numbering: existingNumbering + '.' + (i + 1),
validationRootPath: validationRootPath + '.sections[' + i + ']'
} as ToCEntry;
const sectionItems = this.populateSections(sectionElement.get('sections') as UntypedFormArray, item.numbering);
const fieldSetItems = this.populateFieldSets(sectionElement.get('fieldSets') as UntypedFormArray, item.numbering);
const sectionItems = this.populateSections(sectionElement.get('sections') as UntypedFormArray, item.numbering, item.validationRootPath);
const fieldSetItems = this.populateFieldSets(sectionElement.get('fieldSets') as UntypedFormArray, item.numbering, item.validationRootPath);
if (sectionItems != null) {
item.subEntries = sectionItems;
item.subEntriesType = ToCEntryType.Section;
@ -516,7 +519,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
return result;
}
private populateFieldSets(fieldSets: UntypedFormArray, existingNumbering: string): ToCEntry[] {
private populateFieldSets(fieldSets: UntypedFormArray, existingNumbering: string, validationRootPath: string): ToCEntry[] {
if (fieldSets == null || fieldSets.controls == null || fieldSets.controls.length == 0) { return null; }
const result: ToCEntry[] = [];
@ -528,7 +531,8 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
type: ToCEntryType.FieldSet,
//subEntries: this.populateSections((fieldSetElement.get('fieldSets') as FormArray), existingNumbering + '.' + i),
form: fieldSetElement,
numbering: existingNumbering + '.' + (i + 1)
numbering: existingNumbering + '.' + (i + 1),
validationRootPath: validationRootPath
} as ToCEntry)
});
@ -582,6 +586,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
page.id = Guid.create().toString();
if (isNaN(pages.length)) { page.ordinal = 0; } else { page.ordinal = pages.length; }
const pageForm = page.buildForm({ rootPath: 'definition.pages[' + pages.length + '].' });
console.log('definition.pages[' + pages.length + '].');
// this.dataModel.pages.push(page);
pages.push(pageForm);
@ -618,9 +623,9 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
}
//store rootPath for next levels/components
this.rootPath = 'definition.pages['+ pageIndex +'].sections[' + sectionsArray.length + '].';
this.rootPath = 'definition.pages[' + pageIndex + '].sections[' + sectionsArray.length + '].';
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages['+ pageIndex +'].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
@ -628,15 +633,15 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
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){
if (sectionIndexes && sectionIndexes.length > 0) {
pageIndex = j;
break;
}
}
let parentSectionRootPath = '';
if(sectionIndexes.length > 0){
if (sectionIndexes.length > 0) {
sectionIndexes.forEach(index => {
parentSectionRootPath = parentSectionRootPath + 'sections[' + index +'].'
parentSectionRootPath = parentSectionRootPath + 'sections[' + index + '].'
});
sectionsArray = parent.form.get('sections') as UntypedFormArray;
@ -650,9 +655,9 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
}
//store rootPath for next levels/components
this.rootPath = 'definition.pages['+ pageIndex +'].'+ parentSectionRootPath;
this.rootPath = 'definition.pages[' + pageIndex + '].' + parentSectionRootPath;
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages['+ pageIndex +'].' + parentSectionRootPath + 'sections[' + sectionsArray.length + '].' }));
sectionsArray.push(section.buildForm({ rootPath: 'definition.pages[' + pageIndex + '].' + parentSectionRootPath + 'sections[' + sectionsArray.length + '].' }));
// (child.form.parent as FormArray).push(section.buildForm());
}
@ -676,15 +681,15 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
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){
if (sectionIndexes && sectionIndexes.length > 0) {
pageIndex = j;
break;
}
}
let parentSectionRootPath = '';
if(sectionIndexes.length > 0){
if (sectionIndexes.length > 0) {
sectionIndexes.forEach(index => {
parentSectionRootPath = parentSectionRootPath + 'sections[' + index +'].'
parentSectionRootPath = parentSectionRootPath + 'sections[' + index + '].'
});
}
if (sectionIndexes.length > 0) {
@ -694,7 +699,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
field.ordinal = 0;//first filed in the fields list
const fieldSetsArray = parent.form.get('fieldSets') as UntypedFormArray
const fieldForm = field.buildForm({ rootPath: this.rootPath+ 'fields[' + 0 + '].'});
const fieldForm = field.buildForm({ rootPath: this.rootPath + 'fields[' + 0 + '].' });
//give fieldset id and ordinal
const fieldSet: DescriptionTemplateFieldSetEditorModel = new DescriptionTemplateFieldSetEditorModel(this.editorModel.validationErrorModel);
@ -707,7 +712,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
} catch {
fieldSet.ordinal = fieldSetsArray.length;
}
const fieldsetForm = fieldSet.buildForm({ rootPath: 'definition.pages['+ pageIndex +'].' + parentSectionRootPath + '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);
@ -726,18 +731,18 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
this.formGroup.updateValueAndValidity();
}
private findSectionIndex(sectionFormArray: UntypedFormArray, parentId: string) : number[]{
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){
} else if (parentSections && parentSections.length > 0) {
const indexes: number[] = this.findSectionIndex(parentSections, parentId);
if (indexes && indexes.length > 0) {
indexes.unshift(i);
return indexes;
}
@ -747,20 +752,20 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
return null;
}
private getUpdatedSectionFormArray(sectionFormArray: UntypedFormArray, tceId: string) : UntypedFormArray{
private getUpdatedSectionFormArray(sectionFormArray: UntypedFormArray, tceId: string): UntypedFormArray {
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 == tceId) {
sectionFormArray.removeAt(i);
return sectionFormArray;
// sectionFormArray.at(i).get('ordinal').patchValue(i);
} else if (parentSections && parentSections.length > 0){
} else if (parentSections && parentSections.length > 0) {
const currentSectionFormArray = this.getUpdatedSectionFormArray(parentSections, tceId);
if (currentSectionFormArray != null || currentSectionFormArray != undefined){
if (currentSectionFormArray != null || currentSectionFormArray != undefined) {
return currentSectionFormArray;
}
}
@ -904,7 +909,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
const parentSections = pages.at(j).get('sections') as UntypedFormArray;
const sectionFormArray = this.getUpdatedSectionFormArray(parentSections, tce.id);
if (sectionFormArray){
if (sectionFormArray) {
//update ordinal
for (let i = 0; i < sectionFormArray.length; i++) {
sectionFormArray.at(i).get('ordinal').patchValue(i);

View File

@ -8,6 +8,8 @@ export interface ToCEntry {
type: ToCEntryType;
form: AbstractControl;
numbering: string;
validationRootPath: string;
}

View File

@ -292,8 +292,8 @@ export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements Des
}
const formGroup = this.formBuilder.group({});
formGroup.addControl('comment', new FormControl({ value: 'this.comment', disabled: disabled }, context.getValidation('comment').validators));
formGroup.addControl('ordinal', new FormControl({ value: 5, disabled: disabled }, context.getValidation('ordinal').validators));
formGroup.addControl('comment', new FormControl({ value: this.comment, disabled: disabled }, context.getValidation('comment').validators));
formGroup.addControl('ordinal', new FormControl({ value: this.ordinal, disabled: disabled }, context.getValidation('ordinal').validators));
const fieldsFormGroup = this.formBuilder.group({});