dataset admin combobox fix

This commit is contained in:
Diamantis Tziotzios 2019-01-28 17:47:12 +02:00
parent 196435d069
commit fd809ab361
5 changed files with 21 additions and 90 deletions

View File

@ -1,34 +0,0 @@
import { FormGroup } from '@angular/forms';
import { DatasetProfileComboBoxType } from '../../../../../core/common/enum/dataset-profile-combo-box-type';
import { WordListFieldData } from '../../../../../core/model/dataset-profile-definition/field-data/field-data';
import { FieldDataEditorModel } from './field-data-editor-model';
import { FieldDataOptionEditorModel } from './field-data-option-editor-model';
export class WordListFieldDataEditorModel extends FieldDataEditorModel<WordListFieldDataEditorModel> {
public type: DatasetProfileComboBoxType = DatasetProfileComboBoxType.WordList;
public options: Array<FieldDataOptionEditorModel>;
buildForm(): FormGroup {
const formGroup = this.formBuilder.group({
type: [this.type],
label: [this.label]
});
const optionsFormArray = new Array<FormGroup>();
if (this.options) {
this.options.forEach(item => {
const form: FormGroup = item.buildForm();
optionsFormArray.push(form);
});
}
formGroup.addControl('options', this.formBuilder.array(optionsFormArray));
return formGroup;
}
fromModel(item: WordListFieldData): WordListFieldDataEditorModel {
this.type = item.type;
if (item.options) { this.options = item.options.map(x => new FieldDataOptionEditorModel().fromModel(x)); }
this.label = item.label;
return this;
}
}

View File

@ -15,6 +15,5 @@ export class DatasetProfileEditorAutoCompleteFieldComponent implements OnInit {
ngOnInit() {
this.data.type = DatasetProfileComboBoxType.Autocomplete;
if (!this.form.get('data')) { this.form.addControl('data', this.data.buildForm()); }
}
}

View File

@ -4,6 +4,8 @@ import { takeUntil } from 'rxjs/operators';
import { BaseComponent } from '../../../../../../../core/common/base/base.component';
import { DatasetProfileComboBoxType } from '../../../../../../../core/common/enum/dataset-profile-combo-box-type';
import { EnumUtils } from '../../../../../../../core/services/utilities/enum-utils.service';
import { AutoCompleteFieldDataEditorModel } from '../../../../admin/field-data/auto-complete-field-data-editor-model';
import { WordListFieldDataEditorModel } from '../../../../admin/field-data/word-list-field-data-editor-model';
@Component({
selector: 'app-dataset-profile-editor-combo-box-field-component',
@ -20,41 +22,20 @@ export class DatasetProfileEditorComboBoxFieldComponent extends BaseComponent im
) { super(); }
ngOnInit() {
// this.form.get('data').get('type').valueChanges
// .pipe(takeUntil(this._destroyed))
// .subscribe(x => {
// if (x === "autocomplete") {
// //if(!this.form.get('data').get('url')) this.form.addControl('data', new AutoCompleteFieldDataEditorModel().buildForm());
// //delete
// if (this.form.get('data').get('options')) (<FormGroup>this.form.get('data')).removeControl('options');
// //add
// if (!this.form.get('data').get('url')) (<FormGroup>this.form.get('data')).addControl('url', new FormControl(''));
// if (!this.form.get('data').get('optionsRoot')) (<FormGroup>this.form.get('data')).addControl('optionsRoot', new FormControl(''));
// if (!this.form.get('data').get('autoCompleteOptions')) (<FormGroup>this.form.get('data')).addControl('autoCompleteOptions', new FormControl(''));
this.setupListeners();
}
// } else if (x === "wordlist") {
// //this.form.addControl('data', new WordListFieldDataEditorModel().buildForm());
// //delete
// if (this.form.get('data').get('url')) (<FormGroup>this.form.get('data')).removeControl('url');
// if (this.form.get('data').get('optionsRoot')) (<FormGroup>this.form.get('data')).removeControl('optionsRoot');
// if (this.form.get('data').get('autoCompleteOptions')) (<FormGroup>this.form.get('data')).removeControl('autoCompleteOptions');
// //add
// if (!this.form.get('data').get('options')) (<FormGroup>this.form.get('data')).addControl('options', new FormControl);
// }
// });
setupListeners() {
this.form.get('data').get('type').valueChanges
.pipe(takeUntil(this._destroyed))
.subscribe(x => {
if (this.form.get('data')) {
this.form.removeControl('data');
if(x==="autocomplete"){
this.form.addControl('data',new AutoCompleteFieldDataEditorModel().buildForm());
}else if(x==="wordlist"){
this.form.addControl('data',new WordListFieldDataEditorModel().buildForm());
}
if (this.form.get('data')) { this.form.removeControl('data'); }
if (x === DatasetProfileComboBoxType.Autocomplete) {
this.form.addControl('data', new AutoCompleteFieldDataEditorModel().buildForm());
} else if (x === DatasetProfileComboBoxType.WordList) {
this.form.addControl('data', new WordListFieldDataEditorModel().buildForm());
}
})
this.setupListeners();
});
}
}

View File

@ -16,7 +16,6 @@ export class DatasetProfileEditorWordListFieldComponent implements OnInit {
ngOnInit() {
this.data.type = DatasetProfileComboBoxType.WordList;
if (!this.form.get('data')) { this.form.addControl('data', this.data.buildForm()); }
}
addNewRow() {

View File

@ -1,21 +1,18 @@

import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators, FormArray } from '@angular/forms';
import { ValidationType } from '../../../../../../core/common/enum/validation-type';
import { EnumUtils } from '../../../../../../core/services/utilities/enum-utils.service';
import { RuleEditorModel } from '../../../admin/rule-editor-model';
import { DatasetProfileFieldViewStyle } from '../../../../../../core/common/enum/dataset-profile-field-view-style';
import { RadioBoxFieldDataEditorModel } from '../../../admin/field-data/radio-box-field-data-editor-model';
import { DatasetProfileEditorComboBoxFieldComponent } from '../field-type/combo-box/dataset-profile-editor-combo-box-field.component';
import { Component, Input, OnInit } from '@angular/core';
import { FormArray, FormControl, FormGroup } from '@angular/forms';
import { takeUntil } from 'rxjs/operators';
import { BaseComponent } from '../../../../../../core/common/base/base.component';
import { ViewStyleEditorModel } from '../../../admin/view-style-editor-model';
import { TextAreaFieldDataEditorModel } from '../../../admin/field-data/text-area-field-data-editor-model';
import { DatasetProfileFieldViewStyle } from '../../../../../../core/common/enum/dataset-profile-field-view-style';
import { ValidationType } from '../../../../../../core/common/enum/validation-type';
import { EnumUtils } from '../../../../../../core/services/utilities/enum-utils.service';
import { BooleanDecisionFieldDataEditorModel } from '../../../admin/field-data/boolean-decision-field-data-editor-model';
import { CheckBoxFieldDataEditorModel } from '../../../admin/field-data/check-box-field-data-editor-model';
import { FreeTextFieldDataEditorModel } from '../../../admin/field-data/free-text-field-data-editor-model';
import { RadioBoxFieldDataEditorModel } from '../../../admin/field-data/radio-box-field-data-editor-model';
import { TextAreaFieldDataEditorModel } from '../../../admin/field-data/text-area-field-data-editor-model';
import { WordListFieldDataEditorModel } from '../../../admin/field-data/word-list-field-data-editor-model';
import { AutoCompleteFieldDataEditorModel } from '../../../admin/field-data/auto-complete-field-data-editor-model';
import { RuleEditorModel } from '../../../admin/rule-editor-model';
@Component({
selector: 'app-dataset-profile-editor-field-component',
@ -54,29 +51,18 @@ export class DatasetProfileEditorFieldComponent extends BaseComponent implements
case DatasetProfileFieldViewStyle.BooleanDecision:
this.form.addControl('data', new BooleanDecisionFieldDataEditorModel().buildForm());
break;
case DatasetProfileFieldViewStyle.CheckBox:
this.form.addControl('data', new CheckBoxFieldDataEditorModel().buildForm());
break;
case DatasetProfileFieldViewStyle.ComboBox:
//this.form.removeControl('data');
this.form.addControl('data', new FormGroup({}));
(<FormGroup>this.form.get('data')).addControl('type', new FormControl(''));
(<FormGroup>this.form.get('data')).addControl('label', new FormControl(''));
//this.form.get('data').get('type').setValue("autocomplete");
this.form.addControl('data', new WordListFieldDataEditorModel().buildForm());
break;
case DatasetProfileFieldViewStyle.FreeText:
this.form.addControl('data', new FreeTextFieldDataEditorModel().buildForm());
break;
case DatasetProfileFieldViewStyle.RadioBox:
this.form.addControl('data', new RadioBoxFieldDataEditorModel().buildForm());
break;
case DatasetProfileFieldViewStyle.TextArea:
this.form.addControl('data', new TextAreaFieldDataEditorModel().buildForm());
break;