This commit is contained in:
annampak 2017-12-01 18:33:55 +02:00
commit 9b8d2cbf2e
8 changed files with 125 additions and 6 deletions

View File

@ -0,0 +1,20 @@
import { FormGenerator } from '../interfaces/FormGenerator';
import { Serializable } from '../interfaces/Serializable';
import { FormGroup, FormBuilder } from '@angular/forms'
export class ListingItem implements Serializable<ListingItem>, FormGenerator<FormGroup>{
public label: string;
public value: string;
fromJSONObject(item: any): ListingItem {
this.label = item.label;
this.value = item.value;
return this;
}
buildForm(): FormGroup {
return new FormBuilder().group({
label: [this.label],
value: [this.value]
})
}
}

View File

@ -0,0 +1,21 @@
import { DataField } from './DataField';
import { FormGroup } from '@angular/forms'
export class AutocompleteData extends DataField<AutocompleteData>{
public type:string;
public url:string;
buildForm():FormGroup{
return this.formBuilder.group({
type:[this.type],
url:[this.url]
})
}
fromJSONObject(item:any):AutocompleteData{
this.type = item.type;
this.url = item.url;
return this;
}
}

View File

@ -1,6 +1,15 @@
import { BaseModel } from '../BaseModel';
import { FormGenerator } from '../interfaces/FormGenerator';
import { Serializable } from '../interfaces/Serializable';
import { FormGroup } from '@angular/forms'
export abstract class DataField<T> implements Serializable<T>,FormGenerator<FormGroup>{
export abstract class DataField<T> extends BaseModel implements Serializable<T>,FormGenerator<FormGroup>{
buildForm():FormGroup{
throw new Error("Build Form Is not not correctly overriden");
}
fromJSONObject(item:any):T{
throw new Error("From Json Object is not correctly overriden")
}
}

View File

@ -0,0 +1,26 @@
import { JsonSerializer } from '../../utilities/JsonSerializer';
import { DataField } from './DataField';
import { ListingItem } from '../Commons/ListingItem';
import { FormGroup } from '@angular/forms'
export class RadioBoxData extends DataField<RadioBoxData>{
public options:Array<ListingItem>;
buildForm():FormGroup{
let formGroup = this.formBuilder.group({});
let optionsFormArray = new Array<FormGroup>();
if (this.options) {
this.options.forEach(item => {
let form: FormGroup = item.buildForm();
optionsFormArray.push(form)
})
}
formGroup.addControl('options', this.formBuilder.array(optionsFormArray));
return formGroup;
}
fromJSONObject(item:any):RadioBoxData{
this.options = new JsonSerializer<ListingItem>().fromJSONArray(item.options,ListingItem);
return this;
}
}

View File

@ -0,0 +1,30 @@
import { JsonSerializer } from '../../utilities/JsonSerializer';
import { ListingItem } from '../Commons/ListingItem';
import { DataField } from './DataField';
import { FormGroup } from '@angular/forms'
export class WordListData extends DataField<WordListData>{
public type:string;
public options:Array<ListingItem>;
buildForm():FormGroup{
let formGroup = this.formBuilder.group({
type:[this.type]
});
let optionsFormArray = new Array<FormGroup>();
if (this.options) {
this.options.forEach(item => {
let form: FormGroup = item.buildForm();
optionsFormArray.push(form)
})
}
formGroup.addControl('options', this.formBuilder.array(optionsFormArray));
return formGroup;
}
fromJSONObject(item:any):WordListData{
this.type = item.type;
this.options = new JsonSerializer<ListingItem>().fromJSONArray(item.options,ListingItem);
return this;
}
}

View File

@ -1,3 +1,7 @@
import { RadioBoxData } from './DataField/RadioBoxData';
import { WordListData } from './DataField/WordListData';
import { AutocompleteData } from './DataField/AutocompleteData';
import { DataField } from './DataField/DataField';
import { BaseModel } from './BaseModel';
import { FormGroup } from '@angular/forms';
import { FormGenerator } from './interfaces/FormGenerator';
@ -22,6 +26,7 @@ export class Field extends BaseModel implements Serializable<Field>,FormGenerato
public multiplicity: Multiplicity = new Multiplicity();
public ordinal: number;
public visible: Visibility = new Visibility();
public data:DataField<any>;
fromJSONObject(item:any):Field{
this.id = item.id;
@ -35,6 +40,14 @@ export class Field extends BaseModel implements Serializable<Field>,FormGenerato
this.ordinal = item.ordinal;
this.viewStyle = new JsonSerializer<ViewStyle>().fromJSONObject(item.viewStyle, ViewStyle);
this.visible = new JsonSerializer<Visibility>().fromJSONObject(item.visible, Visibility);
if(item.data) {
if(this.viewStyle.renderStyle === "combobox"){
if(item.data.type === "autocomplete") this.data = new JsonSerializer<AutocompleteData>().fromJSONObject(item.data,AutocompleteData);
if(item.data.type === "wordlist")this.data = new JsonSerializer<WordListData>().fromJSONObject(item.data,WordListData);
}else{
if(this.viewStyle.renderStyle === "radiobox") this.data = new JsonSerializer<RadioBoxData>().fromJSONObject(item.data,RadioBoxData);
}
}
return this;
}
@ -53,7 +66,8 @@ export class Field extends BaseModel implements Serializable<Field>,FormGenerato
formGroup.addControl("multiplicity", this.multiplicity.buildForm());
formGroup.addControl("defaultValue", this.defaultValue.buildForm());
formGroup.addControl("viewStyle", this.viewStyle.buildForm());
//formGroup.addControl("visible", this.visible.buildForm());
formGroup.addControl("visible", this.visible.buildForm());
if(this.data)formGroup.addControl("data", this.data.buildForm());
return formGroup;
}

View File

@ -17,7 +17,6 @@ export class Data extends BaseModel implements Serializable<Data>,FormGenerator<
let formGroup = this.formBuilder.group({
type: [this.type],
url: [this.url]
});
return formGroup;
}

View File

@ -18,7 +18,7 @@ export class RestBase {
/*
*/
protocol: string = "http";
hostname: string = "192.168.32.103";
hostname: string = "localhost";
port: number = 8080;
webappname: string = "dmp-backend";
restpath: string = "rest";