|
@@ -9,7 +9,7 @@ import { ValidatorFn, AsyncValidatorFn } from '@angular/forms';
|
|
|
import { ValueTransformer } from './../interfaces';
|
|
|
import { standardModifiers, standardTransformer } from './../utils';
|
|
|
|
|
|
-interface SimpleFieldMetaData {
|
|
|
+interface ISimpleFieldMetaData {
|
|
|
name: string; // The FormControl name
|
|
|
source?: string; // Location in API-returned model - defaults to name
|
|
|
type?: string; // The component type e.g. BasicInput, Checkbutton, Timepicker, etc
|
|
@@ -21,35 +21,35 @@ interface SimpleFieldMetaData {
|
|
|
id?: string; // CSS id to apply
|
|
|
before?: string; // Ordering instruction - move before <name of another key in group>
|
|
|
after?: string; // Ordering instruction - move after <name of another key in group>
|
|
|
- isDisabled?: boolean; // Whether field is initially disabled
|
|
|
+ disabled?: boolean; // Whether field is initially disabled
|
|
|
validators?: ValidatorFn[]; // Array of validator functions - following Angular FormControl API
|
|
|
asyncValidators?: AsyncValidatorFn[]; // Array of async validator functions - following Angular FormControl API
|
|
|
valFailureMsgs?: StringMap; // Validation failure messages - display appropriate message if validation fails
|
|
|
onChange?: (val) => {}; // Function to call when field's value changes
|
|
|
}
|
|
|
|
|
|
-interface Option {
|
|
|
+interface IOption {
|
|
|
label: string;
|
|
|
value: string | number | boolean;
|
|
|
}
|
|
|
|
|
|
-interface OptionsFieldMetaData extends SimpleFieldMetaData {
|
|
|
+interface IOptionsFieldMetaData extends ISimpleFieldMetaData {
|
|
|
options; // Array of Options - for select, radio-button-group and other 'multiple-choice' types
|
|
|
horizontal?: boolean; // Whether to arrang radio buttons or checkboxes horizontally (default false)
|
|
|
}
|
|
|
|
|
|
// For components that include links to other pages
|
|
|
-interface Link {
|
|
|
+interface ILink {
|
|
|
label: string;
|
|
|
route: any[] | string;
|
|
|
}
|
|
|
|
|
|
-interface DropdownModifiedInputFieldMetaData extends SimpleFieldMetaData {
|
|
|
+interface IDropdownModifiedInputFieldMetaData extends ISimpleFieldMetaData {
|
|
|
modifiers: string[];
|
|
|
transform: ValueTransformer;
|
|
|
}
|
|
|
|
|
|
-interface TimePickerFieldMetaData extends SimpleFieldMetaData {
|
|
|
+interface ITimePickerFieldMetaData extends ISimpleFieldMetaData {
|
|
|
value: Date | string;
|
|
|
format: string;
|
|
|
steps: StringMap;
|
|
@@ -78,12 +78,12 @@ abstract class SimpleField {
|
|
|
placeholder = '';
|
|
|
class?: string | string[];
|
|
|
id?: string;
|
|
|
- isDisabled = false;
|
|
|
+ disabled = false;
|
|
|
validators: ValidatorFn[] = [];
|
|
|
asyncValidators: AsyncValidatorFn[] = [];
|
|
|
valFailureMsgs: StringMap = {};
|
|
|
|
|
|
- constructor(meta: SimpleFieldMetaData) {
|
|
|
+ constructor(meta: ISimpleFieldMetaData) {
|
|
|
if (meta.type === 'Multiline') {
|
|
|
console.log(meta);
|
|
|
}
|
|
@@ -100,9 +100,11 @@ abstract class SimpleField {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class Option {
|
|
|
+class Option implements IOption {
|
|
|
// Can take a simple string value, a value-label pair [value, label],
|
|
|
// or an Option of the form { label: string, value: string }
|
|
|
+ label: string;
|
|
|
+ value: string | number | boolean;
|
|
|
constructor(opt: string | string[] | Option) {
|
|
|
if (typeof opt === 'object') {
|
|
|
if (Array.isArray(opt)) {
|
|
@@ -121,7 +123,7 @@ class Option {
|
|
|
|
|
|
abstract class OptionsField extends SimpleField {
|
|
|
options: Option[] = [];
|
|
|
- constructor(meta: OptionsFieldMetaData) {
|
|
|
+ constructor(meta: IOptionsFieldMetaData) {
|
|
|
super(meta);
|
|
|
if (Array.isArray(meta.options)) {
|
|
|
this.options = meta.options.reduce((acc, opt) => { acc.push(new Option(opt)); return acc; }, []);
|
|
@@ -139,7 +141,7 @@ abstract class OptionsField extends SimpleField {
|
|
|
|
|
|
class TextField extends SimpleField {
|
|
|
type = 'Text';
|
|
|
- link?: Link;
|
|
|
+ link?: ILink;
|
|
|
}
|
|
|
|
|
|
class TextareaField extends SimpleField {
|
|
@@ -152,7 +154,7 @@ class PasswordField extends SimpleField {
|
|
|
|
|
|
class SelectField extends OptionsField {
|
|
|
type = 'Select';
|
|
|
- link?: Link;
|
|
|
+ link?: ILink;
|
|
|
}
|
|
|
|
|
|
class RadioField extends OptionsField {
|
|
@@ -178,7 +180,7 @@ class DropdownModifiedInputField extends SimpleField {
|
|
|
type = 'DropdownModifiedInput';
|
|
|
modifiers: string[] = standardModifiers;
|
|
|
transform: ValueTransformer = standardTransformer;
|
|
|
- constructor(meta: DropdownModifiedInputFieldMetaData) {
|
|
|
+ constructor(meta: IDropdownModifiedInputFieldMetaData) {
|
|
|
super(meta);
|
|
|
}
|
|
|
}
|
|
@@ -214,7 +216,7 @@ class CheckbuttonGroup {
|
|
|
} else {
|
|
|
const groupMembers = groupmeta.meta;
|
|
|
this.meta = Object.entries(groupMembers)
|
|
|
- .map( ([key, cb]) => [key, new CheckbuttonField(cb as SimpleFieldMetaData)] )
|
|
|
+ .map( ([key, cb]) => [key, new CheckbuttonField(cb as ISimpleFieldMetaData)] )
|
|
|
.reduce((res, [key, cbf]) => { res[key as string] = cbf; return res; }, {});
|
|
|
}
|
|
|
}
|
|
@@ -257,7 +259,6 @@ class Container {
|
|
|
template?: TemplateRef<any>;
|
|
|
meta: StringMap; // TODO: Tighten up on type with union type
|
|
|
constructor(containerMeta: StringMap) {
|
|
|
- console.log(containerMeta);
|
|
|
Object.assign(this, containerMeta);
|
|
|
if (typeof this.label === 'undefined') {
|
|
|
this.label = unCamelCase(this.name);
|
|
@@ -268,14 +269,14 @@ class Container {
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
// Button Group
|
|
|
|
|
|
-interface ButtonInterface {
|
|
|
+interface IButtonInterface {
|
|
|
label: string;
|
|
|
fnId: string;
|
|
|
class?: string;
|
|
|
icon?: string;
|
|
|
}
|
|
|
|
|
|
-class Button implements ButtonInterface {
|
|
|
+class Button implements IButtonInterface {
|
|
|
label;
|
|
|
fnId;
|
|
|
class = 'btn-primary';
|
|
@@ -310,6 +311,18 @@ class Heading {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// ---------------------------------------------------------------------------------------------------------------------
|
|
|
+// Display
|
|
|
+
|
|
|
+class DisplayField {
|
|
|
+ value: string;
|
|
|
+ link?: ILink;
|
|
|
+ readonly noFormControls = true; // Indicates this has no FormControls associated with it
|
|
|
+ constructor(meta) {
|
|
|
+ Object.assign(this, meta);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
@@ -321,6 +334,5 @@ export {
|
|
|
CheckbuttonField, DropdownModifiedInputField, MultilineField,
|
|
|
CheckbuttonGroup,
|
|
|
TimepickerField, DatepickerField,
|
|
|
- Container, ButtonGroup, Heading
|
|
|
+ Container, ButtonGroup, Heading, DisplayField
|
|
|
};
|
|
|
-
|