34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { FormGroup } from '@angular/forms';
|
|
import { Component, Input, OnInit } from '@angular/core';
|
|
import { WordListData } from '../../../models/DataField/WordListData';
|
|
import { FormArray } from '@angular/forms';
|
|
import { ListingItem } from '../../../models/Common/ListingItem';
|
|
import { JsonSerializer } from '../../../utilities/JsonSerializer';
|
|
import { Field } from '../../../models/datasetProfileAdmin/Field';
|
|
|
|
@Component({
|
|
selector: 'wordlist-component',
|
|
templateUrl: './wordlist-component.html'
|
|
})
|
|
export class WordlistComponent implements OnInit {
|
|
@Input() dataModel: Field;
|
|
@Input() form: FormGroup;
|
|
private data: WordListData = new WordListData();
|
|
private options = new Array<ListingItem>();
|
|
|
|
ngOnInit() {
|
|
this.data.type = "wordlist";
|
|
// if (this.form.get("data")) this.form.removeControl("data");
|
|
this.form.addControl("data", this.data.buildForm());
|
|
if (!this.dataModel.data)
|
|
this.addNewRow();
|
|
}
|
|
|
|
addNewRow() {
|
|
let wordListOptions: ListingItem = new ListingItem();
|
|
(<FormArray>this.form.get("data").get("options")).push(wordListOptions.buildForm());
|
|
this.data.options = [];
|
|
this.data.options.push(wordListOptions);
|
|
this.dataModel.data = JsonSerializer.fromJSONObject(this.data, WordListData);
|
|
}
|
|
} |