2 * # ============LICENSE_START=======================================================
3 * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
4 * # ================================================================================
5 * # Licensed under the Apache License, Version 2.0 (the "License");
6 * # you may not use this file except in compliance with the License.
7 * # You may obtain a copy of the License at
9 * # http://www.apache.org/licenses/LICENSE-2.0
11 * # Unless required by applicable law or agreed to in writing, software
12 * # distributed under the License is distributed on an "AS IS" BASIS,
13 * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * # See the License for the specific language governing permissions and
15 * # limitations under the License.
16 * # ============LICENSE_END=========================================================
19 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
20 import { InputTextModule } from 'primeng/inputtext';
21 import { DropdownModule } from 'primeng/dropdown';
22 import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
23 import { AuthService } from '../services/auth.service';
33 selector: 'app-ms-add-change',
34 templateUrl: './ms-add-change.component.html',
35 styleUrls: ['./ms-add-change.component.css']
38 export class MsAddChangeComponent implements OnInit {
40 guiHeader: string = "Microservice ADD"
41 // Used for the Add/Update button label
42 addOrUpdate: string = "Add";
45 // The loggged in user
51 serviceName: string = "";
60 locations: Location[];
62 // Return JSON to parent component
63 msAddChangeString: any;
66 constructor(private fb: FormBuilder, private authService: AuthService) {
69 @Input() visible: boolean;
70 @Input() currentRow: any;
71 @Output() handler: EventEmitter<any> = new EventEmitter();
75 this.username = this.authService.getUser().username;
77 this.msAddForm = new FormGroup({
78 name: new FormControl(),
79 tag: new FormControl(),
80 serviceName: new FormControl(),
81 type: new FormControl(),
82 //location: new FormControl(),
83 namespace: new FormControl(),
84 labels: new FormControl(),
85 notes: new FormControl()
88 // FORM fields and validations
89 this.msAddForm = this.fb.group({
90 name: ['', [Validators.required]],
91 tag: ['', [Validators.required, Validators.pattern('^([a-z0-9](-[a-z0-9])*)+$'), Validators.minLength(5), Validators.maxLength(50)]],
92 serviceName: ['', [Validators.pattern('^([a-z](-[a-z])*)+$'), Validators.maxLength(25)]],
93 type: ['', [Validators.required]],
94 //location: ['', [Validators.required]],
95 namespace: ['', [Validators.pattern('^([a-z0-9](-[a-z0-9])*)+$')]],
104 { type: 'FM_COLLECTOR' },
105 { type: 'PM_COLLECTOR' },
106 { type: 'ANALYTIC' },
112 { location: 'EDGE' },
113 { location: 'CENTRAL' },
114 { location: 'UNSPECIFIED' }
117 // "Update" was selected, so populate the current row data in the GUI
118 if (this.currentRow) {
119 this.guiHeader = "Microservice Update";
120 this.addOrUpdate = "Update";
121 this.populateFields();
127 let labelsStr: string;
128 if (this.currentRow['metadata']['labels']) {
129 labelsStr = this.currentRow['metadata']['labels'].join(' ')
132 // Prevent validation (length check) from failing in the html
133 if (this.currentRow['serviceName']) {
134 this.serviceName = this.currentRow['serviceName']
137 this.msAddForm.patchValue({
138 name: this.currentRow['name'],
139 tag: this.currentRow['tag'],
140 serviceName: this.serviceName,
141 type: {type: this.currentRow['type']},
142 //location: {location: this.currentRow['location']},
143 namespace: this.currentRow['namespace'],
145 notes: this.currentRow['metadata']['notes']
149 // The handler emits 'null' back to parent to close dialog and make it available again when clicked
151 this.visible = false;
152 this.handler.emit(null);
155 // Create the JSON to be sent to the parent component
156 // The "labels" functions below take into account leading/trailing spaces, multiple spaces between labels, and conversion into an array
158 this.msAddChangeString = {
159 name: this.msAddForm.value['name'].trim(),
160 tag: this.msAddForm.value['tag'],
161 serviceName: this.msAddForm.value['serviceName'],
162 type: this.msAddForm.value['type'].type,
163 location: 'UNSPECIFIED',
164 //location: this.msAddForm.value['location'].location,
165 namespace: this.msAddForm.value['namespace'].trim(),
167 labels: this.msAddForm.value['labels'].trim().replace(/\s{2,}/g, ' ').split(" "),
168 notes: this.msAddForm.value['notes']
175 this.createOutputJson();
176 this.msAddChangeJson = JSON.stringify(this.msAddChangeString);
177 this.handler.emit(this.msAddChangeJson);