X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=it%2Fotf.git;a=blobdiff_plain;f=otf-frontend%2Fclient%2Fsrc%2Fapp%2Fshared%2Fmodules%2Fform-generator%2Fform-generator.component.ts;fp=otf-frontend%2Fclient%2Fsrc%2Fapp%2Fshared%2Fmodules%2Fform-generator%2Fform-generator.component.ts;h=6f205db0e6259e58bf2a3ca010e558c03f94bbcd;hp=0000000000000000000000000000000000000000;hb=14f6f95c84a4a1fa8774190db4a03fd0214ec55f;hpb=f49bd1efeaaddd4891c1f329b18d8cfb28b3e75b
diff --git a/otf-frontend/client/src/app/shared/modules/form-generator/form-generator.component.ts b/otf-frontend/client/src/app/shared/modules/form-generator/form-generator.component.ts
new file mode 100644
index 0000000..6f205db
--- /dev/null
+++ b/otf-frontend/client/src/app/shared/modules/form-generator/form-generator.component.ts
@@ -0,0 +1,381 @@
+/* Copyright (c) 2019 AT&T Intellectual Property. #
+# #
+# Licensed under the Apache License, Version 2.0 (the "License"); #
+# you may not use this file except in compliance with the License. #
+# You may obtain a copy of the License at #
+# #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+# #
+# Unless required by applicable law or agreed to in writing, software #
+# distributed under the License is distributed on an "AS IS" BASIS, #
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
+# See the License for the specific language governing permissions and #
+# limitations under the License. #
+##############################################################################*/
+
+
+import { Component, OnInit, Input, Output, EventEmitter, ViewChild, NgModuleRef, Injector, Compiler, NgModule, ViewContainerRef } from '@angular/core';
+import { FormGroup, FormControl, ReactiveFormsModule } from '@angular/forms';
+import { MatSnackBar } from '@angular/material';
+import { AlertSnackbarComponent } from '../alert-snackbar/alert-snackbar.component';
+
+
+@Component({
+ selector: 'app-form-generator',
+ templateUrl: './form-generator.component.html',
+ styleUrls: ['./form-generator.component.scss']
+})
+export class FormGeneratorComponent implements OnInit {
+
+ public test = {
+ text1: "Hello please enter text1",
+ text2: "Hello please enter text2",
+ one: {
+ text1: "lol"
+ },
+ siteSpecific: {
+ port: "1234",
+ host: "google.com"
+ },
+ list: ["Enter", "some", "values"],
+ list2: [{"test": "hello"}, {"test2": "hello2"}]
+ }
+ public isSaved = false;
+ public arrayCheck;
+ @Input() public JSONData : any;
+ @Input() public taskId: any;
+ @ViewChild('test', { read: ViewContainerRef }) public containerDiv;
+ @Output() public childEvent = new EventEmitter();
+
+ form = new FormGroup({
+ });
+
+ //public textAreaTemplate = ""
+ const tmpCmp = Component({template: textAreaTemplate})(class {
+ });
+ const tmpModule = NgModule({imports:[ReactiveFormsModule], declarations: [tmpCmp]})(class {
+ });
+
+ //this.containerDiv.element.nativeElement.appendChild(document.createElement("label")).innerHTML = key.trim();
+
+ this.compiler.compileModuleAndAllComponentsAsync(tmpModule)
+ .then((factories) => {
+ const f = factories.componentFactories[0];
+ const cmpRef = this.containerDiv.createComponent(f);
+ cmpRef.instance.form = this.form;
+ })
+ }
+ else{
+ const textAreaTemplate = '
' + key.trim() + '
';// + path + "'> "+ data[key] + ""
+ const tmpCmp = Component({template: textAreaTemplate})(class {
+ });
+ const tmpModule = NgModule({imports:[ReactiveFormsModule], declarations: [tmpCmp]})(class {
+ });
+
+ //this.containerDiv.element.nativeElement.appendChild(document.createElement("label")).innerHTML = key.trim();
+
+ this.compiler.compileModuleAndAllComponentsAsync(tmpModule)
+ .then((factories) => {
+ const f = factories.componentFactories[0];
+ const cmpRef = this.containerDiv.createComponent(f);
+ cmpRef.instance.form = this.form;
+ })
+ }
+ // const textAreaTemplate = '
';// + path + "'> "+ data[key] + ""
+ // const tmpCmp = Component({template: textAreaTemplate})(class {
+ // });
+ // const tmpModule = NgModule({imports:[ReactiveFormsModule] ,declarations: [tmpCmp]})(class {
+ // });
+
+ // //this.containerDiv.element.nativeElement.appendChild(document.createElement("label")).innerHTML = key.trim();
+
+ // this.compiler.compileModuleAndAllComponentsAsync(tmpModule)
+ // .then((factories) => {
+ // const f = factories.componentFactories[0];
+ // const cmpRef = this.containerDiv.createComponent(f);
+ // cmpRef.instance.form = this.form;
+ // })
+
+ }
+ else if(typeof data[key] === 'boolean'){
+ let str = '';
+ let str2 = 'h5';
+ let bold = ' style="font-weight:bold"'
+ if(level > 1){
+ str2 = 'label';
+ bold = '';
+ }
+ if(data[key]){
+ str = '';
+ }else{
+ str = '';
+ }
+ this.form.addControl(keyPath + key.trim(), new FormControl(data[key]));
+ const textAreaTemplate = ' <' + str2 + bold + ' class="mr-2">' + key.trim() + '' + str2 + '>
';// + path + "'> "+ data[key] + ""
+ const tmpCmp = Component({template: textAreaTemplate})(class {
+ });
+ const tmpModule = NgModule({imports:[ReactiveFormsModule], declarations: [tmpCmp]})(class {
+ });
+
+ //this.containerDiv.element.nativeElement.appendChild(document.createElement("label")).innerHTML = key.trim();
+
+ this.compiler.compileModuleAndAllComponentsAsync(tmpModule)
+ .then((factories) => {
+ const f = factories.componentFactories[0];
+ const cmpRef = this.containerDiv.createComponent(f);
+ cmpRef.instance.form = this.form;
+ })
+ }
+ else if(typeof data[key] === typeof 23){
+ let str = 'h5';
+ let bold = ' style="font-weight:bold"';
+ if(level > 1){
+ str = 'label';
+ bold = '';
+ }
+ this.form.addControl(keyPath + key.trim(), new FormControl(data[key]));
+ const textInputTemplate = ' <' + str + bold + ' class="mr-2">' + key.trim() + '' + str + '>
';
+ const tmpCmp = Component({template: textInputTemplate})(class {
+ });
+ const tmpModule = NgModule({imports:[ReactiveFormsModule], declarations: [tmpCmp]})(class {
+ });
+
+ //this.containerDiv.element.nativeElement.appendChild(document.createElement("label")).innerHTML = key.trim();
+
+ this.compiler.compileModuleAndAllComponentsAsync(tmpModule)
+ .then((factories) => {
+ const f = factories.componentFactories[0];
+ const cmpRef = this.containerDiv.createComponent(f);
+ cmpRef.instance.form = this.form;
+ })
+ }
+ else{
+ const textAreaTemplate = ' ' + key.trim() + ': Type Not Supported
';// + path + "'> "+ data[key] + ""
+ const tmpCmp = Component({template: textAreaTemplate})(class {
+ });
+ const tmpModule = NgModule({imports:[ReactiveFormsModule], declarations: [tmpCmp]})(class {
+ });
+
+ //this.containerDiv.element.nativeElement.appendChild(document.createElement("label")).innerHTML = key.trim();
+
+ this.compiler.compileModuleAndAllComponentsAsync(tmpModule)
+ .then((factories) => {
+ const f = factories.componentFactories[0];
+ const cmpRef = this.containerDiv.createComponent(f);
+ cmpRef.instance.form = this.form;
+ })
+ }
+
+ }
+ }
+}