visibility create function scanIfChildsOfCompositeFieldHasVisibleItems
fix style delete buttons fix AutoComplete copnonnent get from Url to external resorsis multiplisity model clone for mulitiplicity
This commit is contained in:
parent
8b45ee5548
commit
52f7c6dc0c
|
@ -60,9 +60,9 @@
|
|||
<mat-expansion-panel *ngFor="let field of form.get('fields')['controls'] let i=index;" #panel>
|
||||
<mat-expansion-panel-header>
|
||||
<mat-panel-title>{{i + 1}}. {{getFieldTile(field, i)}}</mat-panel-title>
|
||||
<div class="btn-group pull-right">
|
||||
<button type="button" class="btn btn-sm" style="margin-left:5px;" (click)="DeleteField(i);">
|
||||
<span class="glyphicon glyphicon-erase"></span>
|
||||
<div class="row">
|
||||
<button mat-icon-button type="button" class="btn btn-sm col-auto" style="margin-right:0.7em;" (click)="DeleteField(i);">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</mat-expansion-panel-header>
|
||||
|
|
|
@ -33,26 +33,25 @@
|
|||
<div class="col-12">
|
||||
<mat-card class="field-card" *ngFor="let fieldControl of form.get('fieldSets')['controls'] let i=index;">
|
||||
<div class="row">
|
||||
<mat-card-title class="col-12">{{i + 1}}. {{getFieldTile(fieldControl, i)}}
|
||||
<button mat-icon-button type="button" class="btn btn-sm" style="margin-left:5px;" (click)="deleteFieldSet(i);">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</mat-card-title>
|
||||
<mat-card-title class="col">{{i + 1}}. {{getFieldTile(fieldControl, i)}}</mat-card-title>
|
||||
<button mat-icon-button type="button" class="btn btn-sm col-auto" style="margin-right:0.7em;" (click)="deleteFieldSet(i);">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
<app-dataset-profile-editor-composite-field-component class="col-12" [form]="fieldControl" [indexPath]="indexPath + 'cf' + i"></app-dataset-profile-editor-composite-field-component>
|
||||
</div>
|
||||
</mat-card>
|
||||
</div>
|
||||
<div class="col-12"><button mat-button class="full-width" (click)="addField()">{{'DATASET-PROFILE-EDITOR.STEPS.FORM.SECTION.ACTIONS.ADD-FIELD'
|
||||
| translate}}</button></div>
|
||||
|
||||
<h4 style="font-weight: bold" class="col-12">{{'DATASET-PROFILE-EDITOR.STEPS.FORM.SECTION.FIELDS.SUB-SECTIONS-TITLE' |
|
||||
translate}}</h4>
|
||||
<div *ngIf="dataModel.sections.length > 0" class="col-12">
|
||||
<mat-expansion-panel *ngFor="let section of dataModel.sections; let i=index;" #panel>
|
||||
<mat-expansion-panel-header>
|
||||
<mat-panel-title>{{i + 1}}. {{form.get('sections').get(''+i).get('title').value}}</mat-panel-title>
|
||||
<div class="row">
|
||||
<span class="col">{{i + 1}}. {{form.get('sections').get(''+i).get('title').value}}</span>
|
||||
<button mat-icon-button type="button" class="col-auto" (click)="DeleteSectionInSection(i);">
|
||||
<!-- <span class="col">{{i + 1}}. {{form.get('sections').get(''+i).get('title').value}}</span> -->
|
||||
<button mat-icon-button type="button" class="btn btn-sm col-auto" style="margin-right:0.7em;" (click)="DeleteSectionInSection(i);">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -289,7 +289,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
|
||||
|
||||
save() {
|
||||
if (!this.isFormValid()) { return; }
|
||||
//if (!this.isFormValid()) { return; }
|
||||
this.formGroup.get('status').setValue('0');
|
||||
this.submit();
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
<div *ngIf="form && this.visibilityRulesService.checkElementVisibility(this.form.get('id').value)" [id]="this.form.get('id').value" [formGroup]="form" class="dynamic-form-composite-field row">
|
||||
<div *ngIf="form && this.visibilityRulesService.checkElementVisibility(this.form.get('id').value)" [id]="this.form.get('id').value"
|
||||
[formGroup]="form" class="dynamic-form-composite-field row">
|
||||
|
||||
<div *ngIf="form.get('fields').length === 1 && this.visibilityRulesService.checkElementVisibility(form.get('fields')['controls'][0].get('id').value)" class="col-12">
|
||||
<div *ngIf="form.get('fields').length === 1 && this.visibilityRulesService.checkElementVisibility(form.get('fields')['controls'][0].get('id').value)"
|
||||
class="col-12">
|
||||
<div class="row">
|
||||
<h5 *ngIf="form.get('title').value" style="font-weight:bold; color: #3a3737;" class="col-12">{{form.get('numbering').value}} {{form.get('title').value}}
|
||||
<h5 *ngIf="form.get('title').value" style="font-weight:bold; color: #3a3737;" class="col-12">{{form.get('numbering').value}}
|
||||
{{form.get('title').value}}
|
||||
<!-- <a *ngIf="this.markForConsiderationService.exists(compositeField)" (click)="markForConsideration()" style="cursor: pointer">
|
||||
Mark For Consideration
|
||||
</a> -->
|
||||
|
@ -16,7 +19,8 @@
|
|||
</div>
|
||||
<div *ngIf="form.get('fields').length > 1" class="col-12">
|
||||
<div class="row">
|
||||
<h5 *ngIf="form.get('title').value" style="font-weight:bold; color: #3a3737;" class="col-12">{{form.get('numbering').value}} {{form.get('title').value}}</h5>
|
||||
<h5 *ngIf="form.get('title').value" style="font-weight:bold; color: #3a3737;" class="col-12">{{form.get('numbering').value}}
|
||||
{{form.get('title').value}}</h5>
|
||||
<h5 *ngIf="form.get('description').value" class="col-12">{{form.get('description').value}}</h5>
|
||||
<h5 *ngIf="form.get('extendedDescription').value" class="col-12">
|
||||
<i>{{form.get('extendedDescription').value}}</i>
|
||||
|
@ -24,12 +28,11 @@
|
|||
<div *ngFor="let fieldFormGroup of form.get('fields')['controls']; let i = index;" class="col-12">
|
||||
<div class="row">
|
||||
<div class="col-12" *ngIf="(fieldFormGroup.get('multiplicity')?.value?.max - 1) > (fieldFormGroup.get('multiplicityItems')?.length)">
|
||||
<a (click)="addMultipleField(i)" style="cursor: pointer">
|
||||
<a (click)="addMultipleField(i+1)" style="cursor: pointer">
|
||||
Add one more field +
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<app-form-field [form]="fieldFormGroup" class="col-12" [datasetProfileId]="datasetProfileId"></app-form-field>
|
||||
<div *ngIf="fieldFormGroup" class="col-12">
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
.dynamic-form-composite-field {
|
||||
|
||||
}
|
|
@ -10,10 +10,8 @@ import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.
|
|||
})
|
||||
export class FormCompositeFieldComponent {
|
||||
|
||||
// @Input() compositeField: DatasetDescriptionCompositeFieldEditorModel;
|
||||
@Input() datasetProfileId: String;
|
||||
@Input() form: FormGroup;
|
||||
//trackByFn = (index, item) => item ? item['id'] : null;
|
||||
|
||||
constructor(
|
||||
public visibilityRulesService: VisibilityRulesService,
|
||||
|
@ -21,11 +19,8 @@ export class FormCompositeFieldComponent {
|
|||
) {
|
||||
}
|
||||
|
||||
// ngOnInit() {
|
||||
// if (this.compositeField) {
|
||||
// this.form = this.visibilityRulesService.getFormGroup(this.compositeField.id);
|
||||
// }
|
||||
// }
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
addMultipleField(fieldIndex: number) {
|
||||
// const field: DatasetDescriptionFieldEditorModel = this.compositeField.fields[fieldIndex].cloneForMultiplicity(fieldIndex, '');
|
||||
|
|
|
@ -61,6 +61,7 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
|
|||
|
||||
autocompleteRequestItem.criteria.fieldID = this.form.get('id').value;
|
||||
autocompleteRequestItem.criteria.profileID = this.datasetProfileId;
|
||||
autocompleteRequestItem.criteria.like = query;
|
||||
return this.datasetExternalAutocompleteService.queryAutocomplete(autocompleteRequestItem);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,19 +9,22 @@
|
|||
<h3 *ngIf="form.get('description').value">{{form.get('description').value}}</h3>
|
||||
</mat-panel-description>
|
||||
</mat-expansion-panel-header>
|
||||
|
||||
<div *ngFor="let compositeFieldFormGroup of form.get('compositeFields')['controls']; let i = index;" class="col-12">
|
||||
<!-- <div *ngIf="isElementVisible(compositeField)" class="row"> -->
|
||||
<div class="row">
|
||||
<div *ngIf="(compositeFieldFormGroup.get('multiplicity').value.max - 1) > (compositeFieldFormGroup.get('multiplicityItems').length)" class="col-12">
|
||||
<!-- *ngIf="this.visibilityRulesService.checkElementVisibility(compositeFieldFormGroup.get('id').value)" -->
|
||||
<div class="row" *ngIf="this.visibilityRulesService.checkElementVisibility(compositeFieldFormGroup.get('id').value) && this.visibilityRulesService.scanIfChildsOfCompositeFieldHasVisibleItems(compositeFieldFormGroup)">
|
||||
|
||||
<div *ngIf="(compositeFieldFormGroup.get('multiplicity').value.max - 1) > (compositeFieldFormGroup.get('multiplicityItems').length)"
|
||||
class="col-12">
|
||||
<button mat-button color="primary" (click)="addMultipleField(i)">
|
||||
Add one more fieldset +
|
||||
</button>
|
||||
</div>
|
||||
<app-form-composite-field class="col-12" [form]="compositeFieldFormGroup" [datasetProfileId]="datasetProfileId"></app-form-composite-field>
|
||||
<div *ngIf="compositeField" class="col-12">
|
||||
<div *ngIf="compositeFieldFormGroup" class="col-12">
|
||||
<div class="row">
|
||||
<app-form-composite-field class="col-12" *ngFor="let multipleCompositeFieldFormGroup of compositeFieldFormGroup.get('multiplicityItems')['controls']; let j = index" [form]="multipleCompositeFieldFormGroup" [datasetProfileId]="datasetProfileId"></app-form-composite-field>
|
||||
<app-form-composite-field class="col-12" *ngFor="let multipleCompositeFieldFormGroup of compositeFieldFormGroup.get('multiplicityItems')['controls']; let j = index"
|
||||
[form]="multipleCompositeFieldFormGroup" [datasetProfileId]="datasetProfileId"></app-form-composite-field>
|
||||
<mat-form-field *ngIf="compositeFieldFormGroup.get('hasCommentField').value" class="col-12" [formGroup]="compositeFieldFormGroup">
|
||||
<input matInput formControlName="commentFieldValue" placeholder="comment">
|
||||
</mat-form-field>
|
||||
|
@ -31,11 +34,13 @@
|
|||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="form.get('sections')" class="col-12">
|
||||
<div *ngFor="let subSectionFormGroup of form.get('sections')['controls']; let j = index;" class="row">
|
||||
<app-form-section class="col-12" [form]="subSectionFormGroup" [path]="path+'.'+(j+1)" [pathName]="pathName+'.sections.'+j" [datasetProfileId]="datasetProfileId"></app-form-section>
|
||||
<app-form-section class="col-12" [form]="subSectionFormGroup" [path]="path+'.'+(j+1)" [pathName]="pathName+'.sections.'+j"
|
||||
[datasetProfileId]="datasetProfileId"></app-form-section>
|
||||
</div>
|
||||
</div>
|
||||
</mat-expansion-panel>
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { AfterViewInit, Component, Input, OnInit } from '@angular/core';
|
||||
import { FormGroup } from '@angular/forms';
|
||||
import { FormGroup, FormArray, AbstractControl } from '@angular/forms';
|
||||
import { FormFocusService } from '../../form-focus/form-focus.service';
|
||||
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
|
||||
import { DatasetDescriptionSectionEditorModel, DatasetDescriptionCompositeFieldEditorModel } from '../../dataset-description-form.model';
|
||||
import { FormCompositeFieldComponent } from '../form-composite-field/form-composite-field.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-form-section',
|
||||
|
@ -10,14 +12,14 @@ import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.
|
|||
})
|
||||
export class FormSectionComponent implements OnInit {
|
||||
|
||||
// @Input() section: DatasetDescriptionSectionEditorModel;
|
||||
//@Input() section: DatasetDescriptionSectionEditorModel;
|
||||
@Input() datasetProfileId: String;
|
||||
@Input() form: FormGroup;
|
||||
@Input() pathName: string;
|
||||
@Input() path: string;
|
||||
//trackByFn = (index, item) => item ? item['id'] : null;
|
||||
constructor(
|
||||
private visibilityRulesService: VisibilityRulesService,
|
||||
public visibilityRulesService: VisibilityRulesService,
|
||||
private formFocusService: FormFocusService
|
||||
) { }
|
||||
|
||||
|
@ -31,11 +33,11 @@ export class FormSectionComponent implements OnInit {
|
|||
// this.visibilityRulesService.triggerVisibilityEvaluation();
|
||||
// }
|
||||
|
||||
// addMultipleField(fieldsetIndex: number) {
|
||||
// const compositeField: DatasetDescriptionCompositeFieldEditorModel = this.section.compositeFields[fieldsetIndex].cloneForMultiplicity(fieldsetIndex);
|
||||
// this.section.compositeFields[fieldsetIndex].multiplicityItems.push(compositeField);
|
||||
// (<FormArray>(this.form.get('compositeFields').get('' + fieldsetIndex).get('multiplicityItems'))).push(compositeField.buildForm());
|
||||
// }
|
||||
addMultipleField(fieldsetIndex: number) {
|
||||
const compositeFieldToBeCloned = (this.form.get('compositeFields').get('' + fieldsetIndex) as FormGroup).getRawValue();
|
||||
const compositeField: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel().cloneForMultiplicity(compositeFieldToBeCloned, fieldsetIndex);
|
||||
(<FormArray>(this.form.get('compositeFields').get('' + fieldsetIndex).get('multiplicityItems'))).push(compositeField.buildForm());
|
||||
}
|
||||
|
||||
// isElementVisible(fieldSet: CompositeField): boolean {
|
||||
// return fieldSet && fieldSet.fields && fieldSet.fields.length > 0
|
||||
|
|
|
@ -173,18 +173,23 @@ export class DatasetDescriptionCompositeFieldEditorModel extends BaseFormModel {
|
|||
return formGroup;
|
||||
}
|
||||
|
||||
cloneForMultiplicity(index: number): DatasetDescriptionCompositeFieldEditorModel {
|
||||
// cloneForMultiplicity(index: number): DatasetDescriptionCompositeFieldEditorModel {
|
||||
// const newItem: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel();
|
||||
// newItem.id = 'multiple_' + this.id + '_' + index;
|
||||
// this.fields.forEach(field => {
|
||||
// newItem.fields.push(field.cloneForMultiplicity(this.fields.indexOf(field), newItem.id + '_'));
|
||||
// });
|
||||
// newItem.ordinal = this.ordinal;
|
||||
// return newItem;
|
||||
// }
|
||||
|
||||
cloneForMultiplicity(item: CompositeField, index: number): DatasetDescriptionCompositeFieldEditorModel {
|
||||
const newItem: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel();
|
||||
newItem.id = 'multiple_' + this.id + '_' + index;
|
||||
this.fields.forEach(field => {
|
||||
newItem.fields.push(field.cloneForMultiplicity(this.fields.indexOf(field), newItem.id + '_'));
|
||||
newItem.id = 'multiple_' + item.id + '_' + index;
|
||||
item.fields.forEach((field, index) => {
|
||||
newItem.fields.push(new DatasetDescriptionFieldEditorModel().cloneForMultiplicity(field, index, newItem.id + '_'));
|
||||
});
|
||||
|
||||
// put on new item only the first (Fields) value and the last (Fields) value
|
||||
// the first is on "fields":[{},{}]
|
||||
// and the New is on "multiplicityItem":[{ fields":[{},{}] },{ fields":[{},{}] }]
|
||||
newItem.ordinal = this.ordinal;
|
||||
|
||||
newItem.ordinal = item.ordinal;
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
|
@ -254,18 +259,33 @@ export class DatasetDescriptionFieldEditorModel extends BaseFormModel {
|
|||
return formGroup;
|
||||
}
|
||||
|
||||
cloneForMultiplicity(index: number, idPath: string): DatasetDescriptionFieldEditorModel {
|
||||
// cloneForMultiplicity(index: number, idPath: string): DatasetDescriptionFieldEditorModel {
|
||||
// const newItem: DatasetDescriptionFieldEditorModel = new DatasetDescriptionFieldEditorModel();
|
||||
|
||||
// newItem.id = idPath ? idPath + index : 'multiple_' + this.id + '_' + index;
|
||||
// newItem.title = this.title;
|
||||
// newItem.description = this.description;
|
||||
// newItem.extendedDescription = this.extendedDescription;
|
||||
// newItem.viewStyle = this.viewStyle;
|
||||
// newItem.defaultVisibility = this.defaultVisibility;
|
||||
// newItem.page = this.page;
|
||||
// newItem.multiplicity = null;
|
||||
// newItem.data = this.data;
|
||||
|
||||
// return newItem;
|
||||
// }
|
||||
cloneForMultiplicity(item: Field, index: number, idPath: string): DatasetDescriptionFieldEditorModel {
|
||||
const newItem: DatasetDescriptionFieldEditorModel = new DatasetDescriptionFieldEditorModel();
|
||||
|
||||
newItem.id = idPath ? idPath + index : 'multiple_' + this.id + '_' + index;
|
||||
newItem.title = this.title;
|
||||
newItem.description = this.description;
|
||||
newItem.extendedDescription = this.extendedDescription;
|
||||
newItem.viewStyle = this.viewStyle;
|
||||
newItem.defaultVisibility = this.defaultVisibility;
|
||||
newItem.page = this.page;
|
||||
newItem.id = idPath ? idPath + index : 'multiple_' + item.id + '_' + index;
|
||||
newItem.title = item.title;
|
||||
newItem.description = item.description;
|
||||
newItem.extendedDescription = item.extendedDescription;
|
||||
newItem.viewStyle = item.viewStyle;
|
||||
newItem.defaultVisibility = item.defaultVisibility;
|
||||
newItem.page = item.page;
|
||||
newItem.multiplicity = null;
|
||||
newItem.data = this.data;
|
||||
newItem.data = item.data;
|
||||
|
||||
return newItem;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
import { ApplicationRef, Injectable, NgZone } from '@angular/core';
|
||||
import { FormArray, FormGroup } from '@angular/forms';
|
||||
import { isNumeric } from 'rxjs/internal/util/isNumeric';
|
||||
import { Rule } from '../../../../core/model/dataset-profile-definition/rule';
|
||||
import { VisibilityRule } from './models/visibility-rule';
|
||||
import { VisibilityRulesContext } from './models/visibility-rules-context';
|
||||
import { isNumeric } from 'rxjs/internal/util/isNumeric';
|
||||
|
||||
@Injectable()
|
||||
export class VisibilityRulesService {
|
||||
|
||||
// public formGroup: FormGroup;
|
||||
|
||||
private visibilityRuleContext: VisibilityRulesContext;
|
||||
// private fieldsPathMemory: any = {};
|
||||
private elementVisibilityMap = new Map<String, boolean>();
|
||||
// private initialModel: DatasetProfileDefinitionModel;
|
||||
// private currentModel: DatasetProfileDefinitionModel;
|
||||
|
||||
constructor(
|
||||
public applicationReference: ApplicationRef,
|
||||
|
@ -21,25 +19,6 @@ export class VisibilityRulesService {
|
|||
|
||||
}
|
||||
|
||||
// public setModel(model: DatasetProfileDefinitionModel) {
|
||||
// this.initialModel = model;
|
||||
// this.currentModel = model;
|
||||
// //this.visibilityRuleContext.rules.forEach(item => this.evaluateVisibility(item))
|
||||
// }
|
||||
|
||||
// public triggerVisibilityEvaluation() {
|
||||
// this.visibilityRuleContext.rules.forEach(item => this.evaluateVisibility(item));
|
||||
// }
|
||||
|
||||
// public getFormGroup(id: string): FormGroup {
|
||||
// const pathKeyArray = this.search('pages', this.initialModel.pages, id).split('.');
|
||||
|
||||
// pathKeyArray.pop();
|
||||
// const pathKey = pathKeyArray.join('.');
|
||||
// if (!this.fieldsPathMemory[id] && pathKey) { this.fieldsPathMemory[id] = pathKey; }
|
||||
// return (<FormGroup>this.formGroup.get(pathKey));
|
||||
// }
|
||||
|
||||
public checkElementVisibility(id: string): boolean {
|
||||
if (this.visibilityRuleContext.rules.filter(item => item.targetControlId === id).length === 0) { return true; }
|
||||
return this.elementVisibilityMap.has(id) ? this.elementVisibilityMap.get(id) : false;
|
||||
|
@ -57,41 +36,14 @@ export class VisibilityRulesService {
|
|||
|
||||
private evaluateVisibility(visibilityRule: VisibilityRule, value: any) {
|
||||
for (let i = 0; i < visibilityRule.sourceVisibilityRules.length; i++) {
|
||||
//const pathKey = this.fieldsPathMemory[visibilityRule.sourceVisibilityRules[i].sourceControlId];
|
||||
// if (this.formGroup.get(pathKey + '.value') && (this.parseValue(this.formGroup.get(pathKey + '.value').value) !== this.parseValue(visibilityRule.sourceVisibilityRules[i].sourceControlValue))) {
|
||||
if (value != null && (this.parseValue(value) !== this.parseValue(visibilityRule.sourceVisibilityRules[i].sourceControlValue))) {
|
||||
// if (this.formGroup.get(pathKey).parent.get('id')) {
|
||||
// if (!this.checkElementVisibility(this.formGroup.get(pathKey).parent.get('id').value)) {
|
||||
// const targetPathKey = this.fieldsPathMemory[visibilityRule.targetControlId];
|
||||
// this.getObject(this.currentModel, 'id', visibilityRule.targetControlId, this.currentModel, true);
|
||||
this.elementVisibilityMap.set(visibilityRule.targetControlId, false);
|
||||
// this.clearValues(targetPathKey);
|
||||
return;
|
||||
}
|
||||
// } else {
|
||||
// const targetPathKey = this.fieldsPathMemory[visibilityRule.targetControlId];
|
||||
// this.getObject(this.currentModel, 'id', visibilityRule.targetControlId, this.currentModel, true);
|
||||
// this.elementVisibilityMap.set(visibilityRule.targetControlId, false);
|
||||
// this.clearValues(targetPathKey);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// const obj = this.getObject(this.initialModel, 'id', visibilityRule.targetControlId, this.initialModel);
|
||||
// const targetObjPathKey = this.fieldsPathMemory[visibilityRule.targetControlId] ? this.fieldsPathMemory[visibilityRule.targetControlId] : this.search('pages', this.initialModel.pages, obj);
|
||||
// this.updateValue(this.currentModel, obj, targetObjPathKey);
|
||||
this.elementVisibilityMap.set(visibilityRule.targetControlId, true);
|
||||
}
|
||||
|
||||
// private clearValues(pathKey) {
|
||||
// if (pathKey && this.formGroup.get(pathKey + '.value')) { this.formGroup.get(pathKey + '.value').patchValue(null); }
|
||||
// if (pathKey && this.formGroup.get(pathKey)['controls'].fields) {
|
||||
// for (let i = 0; i < this.formGroup.get(pathKey)['controls'].fields.length; i++) {
|
||||
// this.clearValues(pathKey + '.fields.' + i);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
parseValue(value: any) {
|
||||
if (typeof value === 'string') {
|
||||
if (isNumeric(value)) { return value; }
|
||||
|
@ -105,49 +57,31 @@ export class VisibilityRulesService {
|
|||
} else { return value; }
|
||||
}
|
||||
|
||||
// updateValue(obj, value, path) {
|
||||
// let i;
|
||||
// path = path.split('.');
|
||||
search(path, obj, target) {
|
||||
for (const k in obj) {
|
||||
if (obj.hasOwnProperty(k)) {
|
||||
if (obj[k] === target) {
|
||||
return path + '.' + k;
|
||||
} else if (typeof obj[k] === 'object') {
|
||||
const result = this.search(path + '.' + k, obj[k], target);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// for (i = 0; i < path.length - 1; i++) {
|
||||
// obj = obj[path[i]];
|
||||
// }
|
||||
|
||||
// for (let propIndex = 0; propIndex < obj.length; propIndex++) {
|
||||
// if (obj[propIndex] && obj[propIndex]['id'] === value['id']) { return; }
|
||||
// }
|
||||
// obj[path[i]] = value;
|
||||
// }
|
||||
|
||||
// search(path, obj, target) {
|
||||
// for (const k in obj) {
|
||||
// if (obj.hasOwnProperty(k)) {
|
||||
// if (obj[k] === target) {
|
||||
// return path + '.' + k;
|
||||
// } else if (typeof obj[k] === 'object') {
|
||||
// const result = this.search(path + '.' + k, obj[k], target);
|
||||
// if (result) {
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// private getObject(obj, key, val, parent, deleteObj = false) {
|
||||
// for (const i in obj) {
|
||||
// if (!obj.hasOwnProperty(i)) { continue; }
|
||||
// if (typeof obj[i] === 'object') {
|
||||
// const returnObj = this.getObject(obj[i], key, val, obj, deleteObj);
|
||||
// if (returnObj) { return returnObj; }
|
||||
// } else if (i === key && obj[key] === val) {
|
||||
// //console.log(obj[key])
|
||||
// if (deleteObj) { parent[parent.indexOf(obj)] = null; }
|
||||
// return obj;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
scanIfChildsOfCompositeFieldHasVisibleItems(compositeFieldParent: FormGroup): boolean {
|
||||
let isVisible = false;
|
||||
(<FormArray>(compositeFieldParent.get('fields'))).controls.forEach(element => {
|
||||
if (this.checkElementVisibility(element.get('id').value)) {
|
||||
isVisible = true;
|
||||
}
|
||||
});
|
||||
return isVisible;
|
||||
}
|
||||
|
||||
private translate(item: any) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue