summaryrefslogtreecommitdiffstats
path: root/public/src/app/main/main.component.ts
blob: a3f2271d355caf673202d4389b89005e30f9031b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import { Location } from '@angular/common';
import { Component, ViewChild, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ToastrService } from 'ngx-toastr';
import { RestApiService } from '../api/rest-api.service';
import { GeneralComponent } from '../general/general.component';
import { RuleEngineApiService } from '../rule-engine/api/rule-engine-api.service';
import { Store } from '../store/store';

@Component({
  selector: 'app-main',
  encapsulation: ViewEncapsulation.None,
  templateUrl: './main.component.html',
  styleUrls: ['./main.component.scss']
})
export class MainComponent {
  cdump;
  nodes = [];
  @ViewChild(GeneralComponent) generalComponent: GeneralComponent;
  // @ViewChildren(RuleFrameComponent) ruleFrameRef:
  // QueryList<RuleFrameComponent>;

  constructor(
    private route: ActivatedRoute,
    private restApi: RestApiService,
    private _ruleApi: RuleEngineApiService,
    private toastr: ToastrService,
    public store: Store,
    private location: Location
  ) {
    this.route.snapshot.params.mcid === 'import'
      ? (this.store.generalflow = 'import')
      : (this.store.generalflow = 'new');
  }

  goBack() {
    this.location.back();
  }

  createMC(params) {
    console.log('newVfcmt: %o', params);
    this.store.loader = true;
    this.store.vfiName = params.serviceAttached;
    this.store.flowType = 'default';
    this.restApi
      .createNewVFCMT({
        name: params.name,
        description: params.description,
        templateUuid: params.template,
        vfiName: params.serviceAttached,
        serviceUuid: this.route.snapshot.params.uuid,
        contextType: this.route.snapshot.params.contextType,
        flowType: 'default'
      })
      .subscribe(
        success => {
          console.log(success);
          this.store.mcUuid = success.vfcmt.uuid;
          console.log(this.cleanProperty(success));
          this.store.cdump = success.cdump;
          this.diagramRelationsFromCdump(success);
          this.nodes = this.store.cdump.nodes;
          this.store.setTabsProperties(this.nodes);
          this.setDataFromMapToRuleEngine(success.cdump);
          this.store.loader = false;
          this.store.isEditMode = true;
        },
        error => {
          this.store.loader = false;
          console.log(error.notes);
          this.store.ErrorContent = Object.values(error.requestError);
          this.store.displayErrorDialog = true;
        }
      );
  }

  private diagramRelationsFromCdump(success: any) {
    this.generalComponent.list = success.cdump.relations.map(item => {
      return {
        name1: item.name1,
        name2: item.name2,
        p1: item.meta.p1,
        p2: item.meta.p2
      };
    });
  }

  updateCdump(cdump) {
    this.store.cdump = cdump;
    this.nodes = this.store.cdump.nodes;
    this.store.setTabsProperties(this.nodes);
    this.setDataFromMapToRuleEngine(cdump);
  }

  importMC(params) {
    console.log('importVfcmt: %o', params);
    this.generalComponent.importCompleted = true;
    this.store.loader = true;
    this.store.vfiName = params.serviceAttached;
    this.store.flowType = params.flowType;
    this.restApi
      .importVFCMT({
        name: params.name,
        description: params.description,
        templateUuid: params.template,
        vfiName: params.vfni,
        serviceUuid: this.route.snapshot.params.uuid,
        contextType: this.route.snapshot.params.contextType,
        flowType: params.flowType,
        cloneVFCMT: params.isCloneVFCMT,
        updateFlowType: params.isUpdateFlowType
      })
      .subscribe(
        success => {
          console.log(success);

          this.location.path();
          // this.location.go();
          this.store.mcUuid = success.vfcmt.uuid;
          console.log(this.cleanProperty(success));
          this.store.cdump = success.cdump;
          this.diagramRelationsFromCdump(success);
          this.nodes = this.store.cdump.nodes;
          this.store.setTabsProperties(this.nodes);
          this.setDataFromMapToRuleEngine(success.cdump);
          this.store.generalflow = 'edit';
          this.store.loader = false;
          this.store.isEditMode = true;
        },
        error => {
          this.store.loader = false;
          console.log(error.notes);
          this.store.ErrorContent = Object.values(error.requestError);
          this.store.displayErrorDialog = true;
        }
      );
  }

  setDataFromMapToRuleEngine(cdump) {
    this.store.tabParmasForRule = cdump.nodes
      .filter(x => x.name.toLowerCase().includes('map'))
      .map(y => {
        return { name: y.name, nid: y.nid };
      });
  }

  cleanProperty(response) {
    return response.cdump.nodes.map(node => {
      const t = node.properties.filter(item =>
        item.hasOwnProperty('assignment')
      );
      node.properties = t;
      return node;
    });
  }

  saveCDUMP() {
    this.store.loader = true;
    this.restApi
      .saveMonitoringComponent({
        contextType: this.store.sdcParmas.contextType,
        serviceUuid: this.store.sdcParmas.uuid,
        vfiName: this.generalComponent.newVfcmt.vfni,
        vfcmtUuid: this.store.mcUuid,
        flowType: this.generalComponent.newVfcmt.flowType,
        cdump: this.store.cdump
      })
      .subscribe(
        success => {
          this.store.loader = false;
          this.store.mcUuid = success.uuid;
          this.toastr.success('', 'Save succeeded');
        },
        error => {
          this.store.loader = false;
          console.log(error.notes);
          this.store.ErrorContent = Object.values(error.requestError);
          this.store.displayErrorDialog = true;
        },
        () => {}
      );
  }

  saveAndCreateBlueprint() {
    this.store.loader = true;
    if (this.store.cdumpIsDirty) {
      this.restApi
        .saveMonitoringComponent({
          contextType: this.store.sdcParmas.contextType,
          serviceUuid: this.store.sdcParmas.uuid,
          vfiName: this.generalComponent.newVfcmt.vfni,
          vfcmtUuid: this.store.mcUuid,
          cdump: this.store.cdump
        })
        .subscribe(
          success => {
            this.store.loader = false;
            this.store.mcUuid = success.uuid;
            this.submitBlueprint();
          },
          error => {
            this.store.loader = false;
            console.log(error.notes);
            this.store.ErrorContent = Object.values(error.requestError);
            this.store.displayErrorDialog = true;
          },
          () => {}
        );
    } else {
      this.submitBlueprint();
    }
  }

  submitBlueprint() {
    this.store.loader = true;
    this.restApi
      .submitMonitoringComponent({
        contextType: this.store.sdcParmas.contextType,
        serviceUuid: this.store.sdcParmas.uuid,
        vfiName: this.generalComponent.newVfcmt.vfni,
        vfcmtUuid: this.store.mcUuid,
        flowType: this.store.cdump.flowType
      })
      .subscribe(
        success => {
          this.store.loader = false;

          this.toastr.success('', 'Save succeeded');
        },
        error => {
          this.store.loader = false;
          console.log(error.notes);
          this.store.ErrorContent = Object.values(error.requestError);
          this.store.displayErrorDialog = true;
        },
        () => {}
      );
  }

  handleChange(e) {
    this._ruleApi.callUpdateTabIndex(e.index - 1);
    this.store.setTabIndex(e.index - 1);
  }
}