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 { MicroserviceInstanceService } from '../services/microservice-instance.service';
21 import { MessageService } from 'primeng/api';
22 import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
23 import { AuthService } from '../services/auth.service';
24 import { DatePipe } from '@angular/common';
27 selector: 'app-ms-instance-add',
28 templateUrl: './ms-instance-add.component.html',
29 styleUrls: ['./ms-instance-add.component.css']
31 export class MsInstanceAddComponent implements OnInit {
33 guiHeader: string = "Microservice Instance ADD";
34 // Used for the Add/Update button label
35 addOrUpdate: string = "Add";
37 msInstanceAddForm: FormGroup;
38 msInstanceToAdd: AddMsInstance;
39 addInstanceTo: string = "";
41 msInstanceReleases: { label: string, value: string }[] = [
42 { label: '2004', value: '2004' },
43 { label: '2006', value: '2006' },
44 { label: '2008', value: '2008' },
45 { label: '2009', value: '2009' },
46 { label: '2010', value: '2010' },
47 { label: '2011', value: '2011' },
48 { label: '2012', value: '2012' }
51 @Input() visible: boolean;
52 @Input() msName: string;
53 @Input() msInstanceChange: string; // Use to differentiate Add from Change, since currentRow can be problematic
54 @Input() currentRow: any;
55 @Output() handler: EventEmitter<any> = new EventEmitter();
57 constructor(private addChangeMsInstanceApi: MicroserviceInstanceService, private messageService: MessageService, private fb: FormBuilder, private authService: AuthService, private datePipe: DatePipe) { }
60 this.username = this.authService.getUser().username;
62 this.msInstanceAddForm = new FormGroup({
63 name: new FormControl(),
64 release: new FormControl(),
65 scrumLead: new FormControl(),
66 scrumLeadId: new FormControl(),
67 systemsEngineer: new FormControl(),
68 systemsEngineerId: new FormControl(),
69 developer: new FormControl(),
70 developerId: new FormControl(),
71 status: new FormControl(),
72 pstDueDate: new FormControl(),
73 pstDueIteration: new FormControl(),
74 eteDueDate: new FormControl(),
75 eteDueIteration: new FormControl(),
76 labels: new FormControl(),
77 notes: new FormControl()
80 this.msInstanceAddForm = this.fb.group({
82 release: ['', [Validators.required]],
84 scrumLeadId: ['', []],
85 systemsEngineer: ['', []],
86 systemsEngineerId: ['', []],
87 developer: ['', [Validators.required]],
88 developerId: ['', [Validators.required]],
91 pstDueIteration: ['', []],
93 eteDueIteration: ['', []],
98 if (this.msInstanceChange) {
99 this.guiHeader = "Microservice Instance Update";
100 this.addOrUpdate = "Update";
101 this.populateFields();
106 this.msName = this.currentRow['name'];
108 let labelsStr: string;
109 if (this.currentRow['metadata']['labels']) {
110 labelsStr = this.currentRow['metadata']['labels'].join(' ')
113 this.msInstanceAddForm.patchValue({
114 release: this.currentRow['release'],
115 scrumLead: this.currentRow['metadata']['scrumLead'],
116 scrumLeadId: this.currentRow['metadata']['scrumLeadId'],
117 systemsEngineer: this.currentRow['metadata']['systemsEngineer'],
118 systemsEngineerId: this.currentRow['metadata']['systemsEngineerId'],
119 developer: this.currentRow['metadata']['developer'],
120 developerId: this.currentRow['metadata']['developerId'],
121 pstDueDate: this.currentRow['pstDueDate'],
122 pstDueIteration: this.currentRow['pstDueIteration'],
123 eteDueDate: this.currentRow['eteDueDate'],
124 eteDueIteration: this.currentRow['eteDueIteration'],
126 notes: this.currentRow['metadata']['notes']
130 /* * * * On click of cancel * * * */
132 this.visible = false;
133 this.handler.emit(null)
136 /* * * * On click of add * * * */
138 // Prevent error on "split" if record existed before "labels" were implemented
139 let labels: string[] = []
140 if (!this.msInstanceAddForm.value['labels']){
143 labels = this.msInstanceAddForm.value['labels'].trim().replace(/\s{2,}/g, ' ').split(" ")
147 this.msInstanceToAdd = {
149 release: this.msInstanceAddForm.value['release'],
151 scrumLead: this.msInstanceAddForm.value['scrumLead'],
152 scrumLeadId: this.msInstanceAddForm.value['scrumLeadId'],
153 systemsEngineer: this.msInstanceAddForm.value['systemsEngineer'],
154 systemsEngineerId: this.msInstanceAddForm.value['systemsEngineerId'],
155 developer: this.msInstanceAddForm.value['developer'],
156 developerId: this.msInstanceAddForm.value['developerId'],
157 pstDueDate: this.msInstanceAddForm.value['pstDueDate'],
158 pstDueIteration: this.msInstanceAddForm.value['pstDueIteration'],
159 eteDueDate: this.msInstanceAddForm.value['eteDueDate'],
160 eteDueIteration: this.msInstanceAddForm.value['eteDueIteration'],
162 notes: this.msInstanceAddForm.value['notes']
167 this.handler.emit(this.msInstanceToAdd) //return request body back to parent
171 export interface AddMsInstance {
177 systemsEngineer: string,
178 systemsEngineerId: string,
182 pstDueIteration: string,
184 eteDueIteration: string,