Merge "Import Ace editor in Test module"
[ccsdk/cds.git] / cds-ui / client / src / app / feature-modules / blueprint / test-template / test-template.component.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
5 ===================================================================
6
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
11
12     http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END============================================
20 */
21
22 import { Component, OnInit, ViewChild } from '@angular/core';
23 import { FlatTreeControl } from '@angular/cdk/tree';
24 import { MatTreeFlatDataSource, MatTreeFlattener } from '@angular/material/tree';
25 import { Observable, Subscription } from 'rxjs';
26 import { Store } from '@ngrx/store';
27
28 import { IAppState } from '../../../common/core/store/state/app.state';
29 import { IBlueprintState } from 'src/app/common/core/store/models/blueprintState.model';
30 import { IBlueprint } from 'src/app/common/core/store/models/blueprint.model';
31 import { IMetaData } from '../../../common/core/store/models/metadata.model';
32 import { LoadBlueprintSuccess } from 'src/app/common/core/store/actions/blueprint.action';
33
34 import "ace-builds/webpack-resolver";
35 import 'brace';
36 import 'brace/ext/language_tools';
37 import 'ace-builds/src-min-noconflict/snippets/html';
38
39 interface FoodNode {
40   name: string;
41   children?: FoodNode[];
42 }
43
44 const TREE_DATA: FoodNode[] = [
45   {
46     name: 'Definitions',
47     children: [
48       { name: 'activation-blueprint.json' },
49       { name: 'artifacts_types.json' },
50       { name: 'data_types.json' },
51     ]
52   },
53   {
54     name: 'Scripts',
55     children: [
56       {
57         name: 'kotlin',
58         children: [
59           { name: 'ScriptComponent.cba.kts' },
60           { name: 'ResourceAssignmentProcessor.cba.kts' },
61         ]
62       }
63     ]
64   },
65   {
66     name: 'Templates',
67     children: [
68       {
69         name: 'baseconfig-template'
70       }
71     ]
72   },
73   {
74     name: 'TOSCA-Metada',
75     children: [
76       {
77         name: 'TOSCA.meta'
78       }
79     ]
80   },
81 ];
82
83 /** Flat node with expandable and level information */
84 interface ExampleFlatNode {
85   expandable: boolean;
86   name: string;
87   level: number;
88 }
89
90
91
92
93
94 @Component({
95   selector: 'app-test-template',
96   templateUrl: './test-template.component.html',
97   styleUrls: ['./test-template.component.scss']
98 })
99 export class TestTemplateComponent implements OnInit {
100   private blueprintpState: Subscription;
101   private request;
102   private workflows = [];
103   @ViewChild('editor') editor;
104   options: any = { fontSize: "100%", printMargin: false, tabSize: 2 };
105   private transformer = (node: FoodNode, level: number) => {
106     return {
107       expandable: !!node.children && node.children.length > 0,
108       name: node.name,
109       level: level,
110     };
111   }
112
113   treeControl = new FlatTreeControl<ExampleFlatNode>(
114     node => node.level, node => node.expandable);
115
116   treeFlattener = new MatTreeFlattener(
117     this.transformer, node => node.level, node => node.expandable, node => node.children);
118
119   dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
120
121   constructor(private store: Store<IAppState>) {
122     this.blueprintpState = this.store.select('blueprint')
123       .subscribe((data: any) => {
124         console.log(data);
125         if (data.blueprint.topology_template && data.blueprint.topology_template.workflows) {
126           this.buildWorkflowData(data.blueprint.topology_template.workflows);
127           // this.request = JSON.stringify(data.blueprint.topology_template.workflows[0], undefined, 4);
128         }
129       });
130     this.dataSource.data = TREE_DATA;
131
132   }
133
134   hasChild = (_: number, node: ExampleFlatNode) => node.expandable;
135
136   ngOnInit() {
137   }
138
139   fileClicked(file) {
140     console.log('selected file:' + file);
141   }
142
143   buildWorkflowData(data) {
144     this.workflows = [];
145     for (var property1 in data) {
146       data[property1].name = property1;
147       this.workflows.push(data[property1])
148     }
149     this.request = this.workflows[0];
150   }
151
152   createRequest(workflow) {
153     this.request = JSON.stringify(workflow, undefined, 4);
154
155   }
156
157 }