Code improvements

Move shared properties down to FormWidgetModel level, reduce repetitive
parsing code.
This commit is contained in:
Denys Vuika
2016-10-27 10:37:14 +01:00
committed by Vito Albano
parent 7b23f939ea
commit 3fb0da0e0b
7 changed files with 35 additions and 68 deletions
@@ -107,7 +107,12 @@ describe('ContainerModel', () => {
});
expect(container.isCollapsible()).toBeFalsy();
container.type = FormFieldTypes.GROUP;
container = new ContainerModel(new FormModel(), {
type: FormFieldTypes.GROUP,
params: {
allowCollapse: true
}
});
expect(container.isCollapsible()).toBeTruthy();
});
@@ -23,14 +23,8 @@ import { FormModel } from './form.model';
import { FormFieldModel } from './form-field.model';
import { WidgetVisibilityModel } from '../../../models/widget-visibility.model';
// TODO: inherit FormFieldModel
export class ContainerModel extends FormWidgetModel {
fieldType: string;
id: string;
name: string;
type: string;
tab: string;
numberOfColumns: number = 1;
params: FormFieldMetadata = {};
isVisible: boolean = true;
@@ -67,11 +61,6 @@ export class ContainerModel extends FormWidgetModel {
super(form, json);
if (json) {
this.fieldType = json.fieldType;
this.id = json.id;
this.name = json.name;
this.type = json.type;
this.tab = json.tab;
this.numberOfColumns = <number> json.numberOfColumns;
this.params = <FormFieldMetadata> json.params || {};
this.visibilityCondition = <WidgetVisibilityModel> json.visibilityCondition;
@@ -18,6 +18,7 @@
export class FormFieldTypes {
static CONTAINER: string = 'container';
static GROUP: string = 'group';
static DYNAMIC_TABLE: string = 'dynamic-table';
static TEXT: string = 'text';
static MULTILINE_TEXT: string = 'multi-line-text';
static DROPDOWN: string = 'dropdown';
@@ -23,25 +23,12 @@ export class FormOutcomeModel extends FormWidgetModel {
static SAVE_ACTION: string = 'Save'; // Activiti 'Save' action name
static COMPLETE_ACTION: string = 'Complete'; // Activiti 'Complete' action name
private _id: string;
private _name: string;
isSystem: boolean = false;
get id() {
return this._id;
}
get name() {
return this._name;
}
constructor(form: FormModel, json?: any) {
super(form, json);
if (json) {
this._id = json.id;
this._name = json.name;
this.isSystem = json.isSystem ? true : false;
}
}
@@ -19,20 +19,26 @@ import { FormModel } from './form.model';
export class FormWidgetModel {
private _form: FormModel;
private _json: any;
readonly fieldType: string;
readonly id: string;
readonly name: string;
readonly type: string;
readonly tab: string;
get form(): FormModel {
return this._form;
}
get json(): any {
return this._json;
}
readonly form: FormModel;
readonly json: any;
constructor(form: FormModel, json: any) {
this._form = form;
this._json = json;
this.form = form;
this.json = json;
if (json) {
this.fieldType = json.fieldType;
this.id = json.id;
this.name = json.name;
this.type = json.type;
this.tab = json.tab;
}
}
}
@@ -28,28 +28,13 @@ export class FormModel {
static SAVE_OUTCOME: string = '$save';
static COMPLETE_OUTCOME: string = '$complete';
private _id: string;
private _name: string;
private _taskId: string;
private _taskName: string = FormModel.UNSET_TASK_NAME;
readonly id: string;
readonly name: string;
readonly taskId: string;
readonly taskName: string = FormModel.UNSET_TASK_NAME;
private _isValid: boolean = true;
get id(): string {
return this._id;
}
get name(): string {
return this._name;
}
get taskId(): string {
return this._taskId;
}
get taskName(): string {
return this._taskName;
}
get isValid(): boolean {
return this._isValid;
}
@@ -61,11 +46,7 @@ export class FormModel {
values: FormValues = {};
private _json: any;
get json() {
return this._json;
}
readonly json: any;
hasTabs(): boolean {
return this.tabs && this.tabs.length > 0;
@@ -82,12 +63,12 @@ export class FormModel {
constructor(json?: any, data?: FormValues, readOnly: boolean = false) {
this.readOnly = readOnly;
if (json) {
this._json = json;
this.json = json;
this._id = json.id;
this._name = json.name;
this._taskId = json.taskId;
this._taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME;
this.id = json.id;
this.name = json.name;
this.taskId = json.taskId;
this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME;
let tabCache: FormWidgetModelCache<TabModel> = {};
@@ -22,7 +22,6 @@ import { WidgetVisibilityModel } from '../../../models/widget-visibility.model';
export class TabModel extends FormWidgetModel {
id: string;
title: string;
isVisible: boolean = true;
visibilityCondition: WidgetVisibilityModel;
@@ -37,7 +36,6 @@ export class TabModel extends FormWidgetModel {
super(form, json);
if (json) {
this.id = json.id;
this.title = json.title;
this.visibilityCondition = <WidgetVisibilityModel> json.visibilityCondition;
}