ui data field
This commit is contained in:
parent
0a83a274d8
commit
83a92b1770
|
@ -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]
|
||||
})
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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")
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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,8 +66,9 @@ 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;
|
||||
}
|
||||
}
|
|
@ -16,8 +16,7 @@ export class Data extends BaseModel implements Serializable<Data>,FormGenerator<
|
|||
buildForm():FormGroup{
|
||||
let formGroup = this.formBuilder.group({
|
||||
type: [this.type],
|
||||
url: [this.url]
|
||||
|
||||
url: [this.url]
|
||||
});
|
||||
return formGroup;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ export class RestBase {
|
|||
/*
|
||||
*/
|
||||
protocol: string = "http";
|
||||
hostname: string = "dionysus.di.uoa.gr";
|
||||
hostname: string = "localhost";
|
||||
port: number = 8080;
|
||||
webappname: string = "dmp-backend";
|
||||
restpath: string = "rest";
|
||||
|
|
Loading…
Reference in New Issue