|
@@ -1,10 +1,108 @@
|
|
|
-import { Component } from '@angular/core';
|
|
|
+import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core';
|
|
|
+import { FormBuilder, FormGroup, FormArray, FormControl, Validators } from '@angular/forms';
|
|
|
|
|
|
+import { ValueTransformer } from './dynaform/components/fields//dropdown-modified-input/dropdown-modified-input.component';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import * as fmd from './dynaform/models/index';
|
|
|
+
|
|
|
+
|
|
|
+import { reduce } from 'lodash/fp';
|
|
|
+const reducerIteree = (res, field) => Object.assign(res, { [field.name]: field.value || '' });
|
|
|
+const _extractFormGroupData = reduce(reducerIteree, {});
|
|
|
+const extractFormGroupData = nonNestedFormMetaLevel => _extractFormGroupData(nonNestedFormMetaLevel);
|
|
|
+
|
|
|
+const fieldOne = new fmd.BasicField({
|
|
|
+ name: 'fieldOne',
|
|
|
+ type: 'Checkbutton',
|
|
|
+ value: '123',
|
|
|
+ label: 'Field One'
|
|
|
+});
|
|
|
+
|
|
|
+const fieldTwo = new fmd.BasicField({
|
|
|
+ name: 'fieldTwo',
|
|
|
+ type: 'Checkbutton',
|
|
|
+ value: '456',
|
|
|
+});
|
|
|
+
|
|
|
+const fieldThree = new fmd.BasicField({
|
|
|
+ name: 'fieldThree',
|
|
|
+ value: 'C'
|
|
|
+});
|
|
|
+
|
|
|
+let formMetaDataObj= {
|
|
|
+ fieldOne,
|
|
|
+ fieldTwo,
|
|
|
+ fieldThree
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
@Component({
|
|
|
selector: 'app-root',
|
|
|
templateUrl: './app.component.html',
|
|
|
styleUrls: ['./app.component.scss']
|
|
|
})
|
|
|
-export class AppComponent {
|
|
|
- title = 'app';
|
|
|
+export class AppComponent implements OnInit {
|
|
|
+
|
|
|
+ form: FormGroup;
|
|
|
+
|
|
|
+ modifiers = ['Starts With', 'Contains', 'Matches'];
|
|
|
+ transformerFunctions: ValueTransformer = {
|
|
|
+ inputFn: val => {
|
|
|
+ let modifier = 'Starts With';
|
|
|
+ if (/^%.*?%$/.test(val)) {
|
|
|
+ modifier = 'Contains'
|
|
|
+ } else if (/^[^%].*?[^%]$/.test(val)) {
|
|
|
+ modifier = 'Matches'
|
|
|
+ } else if (/^%.*/.test(val)) {
|
|
|
+ modifier = 'Starts With';
|
|
|
+ }
|
|
|
+ const transformedVal = val.replace(/%/g, '').trim();
|
|
|
+ return { modifier: modifier, value: transformedVal };
|
|
|
+ },
|
|
|
+ outputFn: (mod, val) => {
|
|
|
+ let transformedValue;
|
|
|
+ switch(mod) {
|
|
|
+ case 'Starts With':
|
|
|
+ transformedValue = `%${val}`;
|
|
|
+ break;
|
|
|
+ case 'Contains':
|
|
|
+ transformedValue = `%${val}%`;
|
|
|
+ break;
|
|
|
+ case 'Matches':
|
|
|
+ default:
|
|
|
+ transformedValue = val;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return transformedValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ labels = ['Feature One', 'Allowed', 'Protected'];
|
|
|
+
|
|
|
+ formMetaDataObj = formMetaDataObj;
|
|
|
+
|
|
|
+ @ViewChild('testTemplate', { read: TemplateRef })
|
|
|
+ private tref: TemplateRef<any>;
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ protected fb: FormBuilder
|
|
|
+ ) {
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ this.form = this.fb.group({
|
|
|
+ testVal: '%lovely%',
|
|
|
+ testCheckbutton: true,
|
|
|
+ testCheckbuttonGroup: this.fb.group({
|
|
|
+ feature1: true,
|
|
|
+ feature1Allowed: true,
|
|
|
+ feature1Password: false
|
|
|
+ }),
|
|
|
+ dynaformtest: this.fb.group(extractFormGroupData(formMetaDataObj))
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
+
|