blob: a3f2271d355caf673202d4389b89005e30f9031b [file] [log] [blame]
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +03001import { Location } from '@angular/common';
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +03002import { Component, ViewChild, ViewEncapsulation } from '@angular/core';
3import { ActivatedRoute } from '@angular/router';
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +03004import { ToastrService } from 'ngx-toastr';
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +03005import { RestApiService } from '../api/rest-api.service';
6import { GeneralComponent } from '../general/general.component';
7import { RuleEngineApiService } from '../rule-engine/api/rule-engine-api.service';
8import { Store } from '../store/store';
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +03009
10@Component({
11 selector: 'app-main',
12 encapsulation: ViewEncapsulation.None,
13 templateUrl: './main.component.html',
14 styleUrls: ['./main.component.scss']
15})
16export class MainComponent {
17 cdump;
18 nodes = [];
19 @ViewChild(GeneralComponent) generalComponent: GeneralComponent;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030020 // @ViewChildren(RuleFrameComponent) ruleFrameRef:
21 // QueryList<RuleFrameComponent>;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030022
23 constructor(
24 private route: ActivatedRoute,
25 private restApi: RestApiService,
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030026 private _ruleApi: RuleEngineApiService,
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030027 private toastr: ToastrService,
28 public store: Store,
29 private location: Location
30 ) {
31 this.route.snapshot.params.mcid === 'import'
32 ? (this.store.generalflow = 'import')
33 : (this.store.generalflow = 'new');
34 }
35
36 goBack() {
37 this.location.back();
38 }
39
40 createMC(params) {
41 console.log('newVfcmt: %o', params);
42 this.store.loader = true;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030043 this.store.vfiName = params.serviceAttached;
44 this.store.flowType = 'default';
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030045 this.restApi
46 .createNewVFCMT({
47 name: params.name,
48 description: params.description,
49 templateUuid: params.template,
50 vfiName: params.serviceAttached,
51 serviceUuid: this.route.snapshot.params.uuid,
52 contextType: this.route.snapshot.params.contextType,
53 flowType: 'default'
54 })
55 .subscribe(
56 success => {
57 console.log(success);
58 this.store.mcUuid = success.vfcmt.uuid;
59 console.log(this.cleanProperty(success));
60 this.store.cdump = success.cdump;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030061 this.diagramRelationsFromCdump(success);
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030062 this.nodes = this.store.cdump.nodes;
63 this.store.setTabsProperties(this.nodes);
64 this.setDataFromMapToRuleEngine(success.cdump);
65 this.store.loader = false;
66 this.store.isEditMode = true;
67 },
68 error => {
69 this.store.loader = false;
70 console.log(error.notes);
71 this.store.ErrorContent = Object.values(error.requestError);
72 this.store.displayErrorDialog = true;
73 }
74 );
75 }
76
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030077 private diagramRelationsFromCdump(success: any) {
78 this.generalComponent.list = success.cdump.relations.map(item => {
79 return {
80 name1: item.name1,
81 name2: item.name2,
82 p1: item.meta.p1,
83 p2: item.meta.p2
84 };
85 });
86 }
87
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +030088 updateCdump(cdump) {
89 this.store.cdump = cdump;
90 this.nodes = this.store.cdump.nodes;
91 this.store.setTabsProperties(this.nodes);
92 this.setDataFromMapToRuleEngine(cdump);
93 }
94
95 importMC(params) {
96 console.log('importVfcmt: %o', params);
97 this.generalComponent.importCompleted = true;
98 this.store.loader = true;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +030099 this.store.vfiName = params.serviceAttached;
100 this.store.flowType = params.flowType;
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300101 this.restApi
102 .importVFCMT({
103 name: params.name,
104 description: params.description,
105 templateUuid: params.template,
106 vfiName: params.vfni,
107 serviceUuid: this.route.snapshot.params.uuid,
108 contextType: this.route.snapshot.params.contextType,
109 flowType: params.flowType,
110 cloneVFCMT: params.isCloneVFCMT,
111 updateFlowType: params.isUpdateFlowType
112 })
113 .subscribe(
114 success => {
115 console.log(success);
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300116
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300117 this.location.path();
118 // this.location.go();
119 this.store.mcUuid = success.vfcmt.uuid;
120 console.log(this.cleanProperty(success));
121 this.store.cdump = success.cdump;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300122 this.diagramRelationsFromCdump(success);
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300123 this.nodes = this.store.cdump.nodes;
124 this.store.setTabsProperties(this.nodes);
125 this.setDataFromMapToRuleEngine(success.cdump);
126 this.store.generalflow = 'edit';
127 this.store.loader = false;
128 this.store.isEditMode = true;
129 },
130 error => {
131 this.store.loader = false;
132 console.log(error.notes);
133 this.store.ErrorContent = Object.values(error.requestError);
134 this.store.displayErrorDialog = true;
135 }
136 );
137 }
138
139 setDataFromMapToRuleEngine(cdump) {
140 this.store.tabParmasForRule = cdump.nodes
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300141 .filter(x => x.name.toLowerCase().includes('map'))
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300142 .map(y => {
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300143 return { name: y.name, nid: y.nid };
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300144 });
145 }
146
147 cleanProperty(response) {
148 return response.cdump.nodes.map(node => {
149 const t = node.properties.filter(item =>
150 item.hasOwnProperty('assignment')
151 );
152 node.properties = t;
153 return node;
154 });
155 }
156
157 saveCDUMP() {
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300158 this.store.loader = true;
159 this.restApi
160 .saveMonitoringComponent({
161 contextType: this.store.sdcParmas.contextType,
162 serviceUuid: this.store.sdcParmas.uuid,
163 vfiName: this.generalComponent.newVfcmt.vfni,
164 vfcmtUuid: this.store.mcUuid,
165 flowType: this.generalComponent.newVfcmt.flowType,
166 cdump: this.store.cdump
167 })
168 .subscribe(
169 success => {
170 this.store.loader = false;
171 this.store.mcUuid = success.uuid;
172 this.toastr.success('', 'Save succeeded');
173 },
174 error => {
175 this.store.loader = false;
176 console.log(error.notes);
177 this.store.ErrorContent = Object.values(error.requestError);
178 this.store.displayErrorDialog = true;
179 },
180 () => {}
181 );
182 }
183
184 saveAndCreateBlueprint() {
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300185 this.store.loader = true;
186 if (this.store.cdumpIsDirty) {
187 this.restApi
188 .saveMonitoringComponent({
189 contextType: this.store.sdcParmas.contextType,
190 serviceUuid: this.store.sdcParmas.uuid,
191 vfiName: this.generalComponent.newVfcmt.vfni,
192 vfcmtUuid: this.store.mcUuid,
193 cdump: this.store.cdump
194 })
195 .subscribe(
196 success => {
197 this.store.loader = false;
198 this.store.mcUuid = success.uuid;
199 this.submitBlueprint();
200 },
201 error => {
202 this.store.loader = false;
203 console.log(error.notes);
204 this.store.ErrorContent = Object.values(error.requestError);
205 this.store.displayErrorDialog = true;
206 },
207 () => {}
208 );
209 } else {
210 this.submitBlueprint();
211 }
212 }
213
214 submitBlueprint() {
215 this.store.loader = true;
216 this.restApi
217 .submitMonitoringComponent({
218 contextType: this.store.sdcParmas.contextType,
219 serviceUuid: this.store.sdcParmas.uuid,
220 vfiName: this.generalComponent.newVfcmt.vfni,
221 vfcmtUuid: this.store.mcUuid,
222 flowType: this.store.cdump.flowType
223 })
224 .subscribe(
225 success => {
226 this.store.loader = false;
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300227
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300228 this.toastr.success('', 'Save succeeded');
229 },
230 error => {
231 this.store.loader = false;
232 console.log(error.notes);
233 this.store.ErrorContent = Object.values(error.requestError);
234 this.store.displayErrorDialog = true;
235 },
236 () => {}
237 );
238 }
239
240 handleChange(e) {
Stone, Avi (as206k)548c5a22018-06-03 13:12:12 +0300241 this._ruleApi.callUpdateTabIndex(e.index - 1);
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +0300242 this.store.setTabIndex(e.index - 1);
243 }
244}