summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/services/services-list/mdons-creation/mdons-creation.component.ts
blob: 8d0f256267d2c077660541b9ce93a08d37d29aa4 (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
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { ServiceListService } from '../../../../core/services/serviceList.service';
import { FormGroup, FormBuilder, Validators, FormArray } from '@angular/forms';

import * as d3 from 'd3';

@Component({
  selector: 'app-mdons-creation',
  templateUrl: './mdons-creation.component.html',
  styleUrls: ['./mdons-creation.component.less']
})
export class MdonsCreationComponent implements OnInit {
  mdons_creation_form: FormGroup;

  uniList = [];
  uniIdSelected = { id: null };
  enniList = [];
  enniIdSelected = { id: null };
  nniList = [];
  nniIdSelected = { id: null };

  nniMap: Map<any, any> = new Map<any, any>();

  templateParameters = {
    invariantUUID: "",
    uuid: "",
    name: "",
    type: "",
    version: "",
    description: "",
    category: "",
    subcategory: "",
    customizationUuid: "",
    inputs: [],
    nestedTemplates: []
  };

  // mdons requstbody
  service = {
    name: "", // <== service instance name
    description: "",
    serviceInvariantUuid: "",
    serviceUuid: "", // uuid ??
    globalSubscriberId: "",   // "customer.id",
    serviceType: "",    // "serviceType.value",
    parameters: {
      locationConstraints: [

      ],
      resources: [],
      requestInputs: {
        name: "",
        customer: "",
        service_provider: "",
        due_date: "",
        end_date: "",
        uni_id: "",
        enni_id: ""
      }
    }
  }

  mdonsModelShow: boolean = false;
  constructor(private myhttp: ServiceListService, private fb: FormBuilder) {


  }
  @Input() createParams;
  @Input() mdons_temParametersContent;
  @Output() mdonsCloseCreate = new EventEmitter();

  ngOnInit() {
    this.getalluni();
    this.getallenni();
    this.getallnni();
    this.templateParameters = this.mdons_temParametersContent;
    this.mdonsModelShow = true;
    this.mdons_creation_form = this.fb.group({});
    this.buildFormArrayOfGroupsFromArr();
  }

  buildFormArrayOfGroupsFromArr() {
    for (let i of this.templateParameters.inputs) {
      if (i.isRequired === "true" && !(i.name.includes('_id'))) {
        this.mdons_creation_form.addControl(i.name, this.fb.control('', [Validators.required]))
      } else {
        this.mdons_creation_form.addControl(i.name, this.fb.control(''))
      }
    }
  }

  getalluni() {
    this.myhttp.getAllNI("UNI")
      .subscribe((data) => {
        this.uniList = data.map(item => ({ id: item }));
        if (data.length !== 0) {
          this.uniIdSelected = this.uniList[0];
        }
      })
  }

  getallenni() {
    this.myhttp.getAllNI("ENNI")
      .subscribe((data) => {
        this.enniList = data.map(item => ({ id: item }));
        if (data.length !== 0) {
          this.enniIdSelected = this.enniList[0];
        }
      })
  }

  getallnni() {
    this.myhttp.getAllNI("NNI")
      .subscribe((data) => {
        this.nniList = data.map(item => ({ id: item }));
        if (data.length !== 0) {
          this.nniIdSelected = this.nniList[0];
        }
      })
  }

  chooseUni(parameterName, item) {
    //if(this.uniIdSelected !== item) this.uniIdSelected = item;
    this.nniMap.set(parameterName, item);
  }

  chooseEnni(parameterName, item) {
    //if(this.enniIdSelected !== item) this.enniIdSelected = item;
    this.nniMap.set(parameterName, item);
  }

  chooseNni(parameterName, item) {
    //if(this.nniIdSelected !== item) this.nniIdSelected = item;
    this.nniMap.set(parameterName, item);
  }

  goback() {
    this.mdonsCloseCreate.emit();
  }



  createService() {
    if (this.mdons_creation_form.invalid) {
      return;
    } else {
      this.service.serviceInvariantUuid = this.templateParameters.invariantUUID;
      this.service.name = this.templateParameters.name;
      this.service.description = this.templateParameters.description;
      this.service.serviceUuid = this.templateParameters.uuid;
      this.service.globalSubscriberId = this.createParams.commonParams.customer.id;
      this.service.serviceType = this.createParams.commonParams.serviceType.name;

      this.templateParameters.inputs.forEach((ipnut) => {
        this.service.parameters.requestInputs[ipnut.name] = ipnut.value == undefined ? ipnut.defaultValue : ipnut.value;
        if (ipnut.name.includes('uni') && ipnut.name.includes('id')) {
          this.service.parameters.requestInputs[ipnut.name] = this.nniMap.get(ipnut.name) == undefined ? this.uniIdSelected.id : this.nniMap.get(ipnut.name).id;
        }
        if (ipnut.name.includes('enni') && ipnut.name.includes('id')) {
          this.service.parameters.requestInputs[ipnut.name] = this.nniMap.get(ipnut.name) == undefined ? this.enniIdSelected.id : this.nniMap.get(ipnut.name).id;
        }
        if (ipnut.name.includes('nni') && ipnut.name.includes('id')) {
          this.service.parameters.requestInputs[ipnut.name] = this.nniMap.get(ipnut.name) == undefined ? this.nniIdSelected.id : this.nniMap.get(ipnut.name).id;
        }
        if (ipnut.name === 'name') {
          this.service.name = ipnut.value == undefined ? ipnut.defaultValue : ipnut.value;
        }
      })
      this.mdonsCloseCreate.emit({ service: this.service });
    }
  }

  markFormTouched(group: FormGroup | FormArray) {
    Object.keys(group.controls).forEach((key: string) => {
      const control = group.controls[key];
      if (control instanceof FormGroup || control instanceof FormArray) { control.markAsTouched(); this.markFormTouched(control); }
      else { control.markAsTouched(); };
    });
  };



}