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, ViewChild, ElementRef } from '@angular/core';
20 import { compSpecsService } from '../services/comp-specs-service.service';
21 import { Table } from 'primeng/table';
22 import { MessageService } from 'primeng/api';
23 import { Ng4LoadingSpinnerService } from 'ng4-loading-spinner';
24 import { DatePipe } from '@angular/common';
25 import { trigger, state, transition, style, animate } from '@angular/animations';
26 import { ActivatedRoute } from '@angular/router';
27 import { DownloadService } from '../services/download.service';
30 selector: 'app-comp-specs',
31 templateUrl: './comp-specs.component.html',
32 styleUrls: ['./comp-specs.component.css'],
34 trigger('rowExpansionTrigger', [
36 transform: 'translateX(-10%)',
39 state('active', style({
40 transform: 'translateX(0)',
43 transition('* <=> *', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
48 export class CompSpecsComponent implements OnInit {
49 @ViewChild(Table, { static: false }) dt: Table;
51 csElements: any[] = [];
54 { field: 'instanceName', header: 'Instance Name' },
55 { field: 'release', header: 'Release', width: '15%' },
56 { field: 'type', header: 'Type', width: '15%' },
57 { field: 'policy', header: 'Policy', width: '15%' },
58 { field: 'status', header: 'Status', width: '15%' }
65 downloadItems: { label: string; command: () => void; }[];
69 msInstanceRelease: any;
71 constructor(private csApis: compSpecsService, private messageService: MessageService,
72 private spinnerService: Ng4LoadingSpinnerService, private datePipe: DatePipe,
73 private route: ActivatedRoute, private downloadService: DownloadService) { }
75 //create table of comp specs
77 this.loadTable = false;
79 this.route.queryParams.subscribe((params) => {
80 this.msInstanceId = params['instanceId'];
90 this.csApis.getAllCompSpecs(this.msInstanceId)
91 .subscribe((data: any[]) => {
95 this.columns = this.cols.map(col => ({ title: col.header, dataKey: col.field }));
99 onTableFiltered(values) {
100 if (values) { this.filteredRows = values; }
101 else { this.filteredRows = this.summaryRows; }
104 /* * * * Export ms instance table to excel or csv * * * */
105 exportTable(exportTo) {
106 let downloadElements: any[] = []
108 //labels array not handled well by excel download so converted them to a single string
109 for (let row of this.filteredRows) {
112 if (exportTo === "excel") {
113 if (row.metadata.labels !== undefined) {
114 labels = row.metadata.labels.join(",")
117 labels = row.metadata.labels
120 if (row.metadata.notes !== null && row.metadata.notes !== undefined && row.metadata.notes !== '') {
121 notes = encodeURI(row.metadata.notes).replace(/%20/g, " ").replace(/%0A/g, "\\n")
124 downloadElements.push({
125 Instance_Name: row.instanceName,
126 Release: row.release,
129 Created_By: row.metadata.createdBy,
130 Created_On: row.metadata.createdOn,
131 Updated_By: row.metadata.updatedBy,
132 Updated_On: row.metadata.updatedOn,
140 if (exportTo === "csv") {
155 this.downloadService.exportTableData(exportTo, downloadElements, arrHeader)
158 //fill object with microservice data, to be used to fill table.
159 //checks if fields are empty and if they are, store 'N/A' as the values
161 for (let elem of data) {
163 if(elem.policyJson){policy = "Included"}
165 let tempCsElement: any = {
167 instanceName: elem.msInstanceInfo.name,
168 release: elem.msInstanceInfo.release,
172 specContent: elem.specContent,
173 policyJson: elem.policyJson,
175 createdBy: elem.metadata.createdBy,
176 createdOn: this.datePipe.transform(elem.metadata.createdOn, 'MM-dd-yyyy HH:mm'),
177 updatedBy: elem.metadata.updatedBy,
178 updatedOn: this.datePipe.transform(elem.metadata.updatedOn, 'MM-dd-yyyy HH:mm'),
179 notes: elem.metadata.notes,
180 labels: elem.metadata.labels
183 this.csElements.unshift(tempCsElement)
185 this.msInstanceName = this.csElements[0]['instanceName']
186 this.msInstanceRelease = this.csElements[0]['release']
187 this.filteredRows = this.csElements
188 this.loadTable = true;
189 this.spinnerService.hide();
192 showViewCs: boolean = false;
193 specContentToView: string;
194 showViewCsDialog(data) {
195 this.showViewCs = true;
196 this.specContentToView = data.specContent;
199 showViewPolicy: boolean = false;
200 policyJsonToView: string;
201 showViewPolicyDialog(data) {
202 this.showViewPolicy = true;
203 this.policyJsonToView = data.policyJson;
206 /* * * * Download single spec file or policy * * * */
207 download(content, contentType) {
208 let fileName = `${this.msInstanceName}_${this.msInstanceRelease}_${contentType}`
209 this.downloadService.downloadJSON(content, fileName)