summaryrefslogtreecommitdiffstats
path: root/mod2/ui/src/app/microservices
diff options
context:
space:
mode:
Diffstat (limited to 'mod2/ui/src/app/microservices')
-rw-r--r--mod2/ui/src/app/microservices/microservices.component.css121
-rw-r--r--mod2/ui/src/app/microservices/microservices.component.html185
-rw-r--r--mod2/ui/src/app/microservices/microservices.component.spec.ts134
-rw-r--r--mod2/ui/src/app/microservices/microservices.component.ts311
4 files changed, 751 insertions, 0 deletions
diff --git a/mod2/ui/src/app/microservices/microservices.component.css b/mod2/ui/src/app/microservices/microservices.component.css
new file mode 100644
index 0000000..5f86e73
--- /dev/null
+++ b/mod2/ui/src/app/microservices/microservices.component.css
@@ -0,0 +1,121 @@
+/*
+ * # ============LICENSE_START=======================================================
+ * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+ * # ================================================================================
+ * # Licensed under the Apache License, Version 2.0 (the "License");
+ * # you may not use this file except in compliance with the License.
+ * # You may obtain a copy of the License at
+ * #
+ * # http://www.apache.org/licenses/LICENSE-2.0
+ * #
+ * # Unless required by applicable law or agreed to in writing, software
+ * # distributed under the License is distributed on an "AS IS" BASIS,
+ * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * # See the License for the specific language governing permissions and
+ * # limitations under the License.
+ * # ============LICENSE_END=========================================================
+ */
+
+td{
+ word-break:break-all
+}
+
+textarea
+{
+ font-size: 12px;
+}
+
+.table_actions_button{
+ background-color: transparent;
+ border: none;
+ width: 20px;
+ height: 20px;
+ vertical-align: middle;
+}
+
+.row-expand-layout{
+ display: grid;
+ grid-template-columns: 30% 40% auto;
+ grid-gap: 10px;
+ grid-auto-rows: minmax(100px, auto);
+}
+
+.row-expand-card{
+ font-size: 12px;
+ grid-row: 1;
+ border-radius: 5px;
+ border: 1px solid slategray;
+ padding: 10px;
+ /* This height prevents vertical scroll bar in Notes */
+ height: 92px;
+ overflow: hidden;
+}
+
+label {
+ cursor: pointer;
+}
+
+.fa-refresh{
+ cursor: pointer;
+}
+
+.input{
+ padding-top: 10px;
+}
+
+.inputLabel {
+ font-weight: 600;
+ margin-left: 20px;
+ width: 140px;
+}
+
+.inputFieldSm {
+ width: 200px;
+ height: 35px;
+ padding-left: 6px;
+}
+.inputFieldMed {
+ width: 300px;
+ height: 35px;
+ padding-left: 6px;
+}
+.inputFieldLg {
+ width: 400px;
+ height: 35px;
+ padding-left: 6px;
+}
+
+.table_action_item{
+ outline: none;
+ font-size: 12px;
+}
+
+::ng-deep .mat-menu-content {
+padding-top: 0px !important;
+padding-bottom: 0px !important;
+}
+.mat-menu-item{
+line-height:30px;
+height:30px;
+}
+
+.greenStatus{
+ background-color: rgba(80, 233, 105, 0.87)
+}
+
+.redStatus{
+ background-color: rgba(255, 29, 29, 0.733)
+}
+
+.blueStatus{
+ background-color: rgba(0, 183, 255, 0.432)
+}
+
+.greyStatus{
+ background-color: rgba(150, 150, 150, 0.432)
+}
+
+.ui-state-highlight {
+ background-color: #878C94 !important;
+ color: black !important;
+}
diff --git a/mod2/ui/src/app/microservices/microservices.component.html b/mod2/ui/src/app/microservices/microservices.component.html
new file mode 100644
index 0000000..95ec45c
--- /dev/null
+++ b/mod2/ui/src/app/microservices/microservices.component.html
@@ -0,0 +1,185 @@
+<!--
+ # ============LICENSE_START=======================================================
+ # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+ # ================================================================================
+ # Licensed under the Apache License, Version 2.0 (the "License");
+ # you may not use this file except in compliance with the License.
+ # You may obtain a copy of the License at
+ #
+ # http://www.apache.org/licenses/LICENSE-2.0
+ #
+ # Unless required by applicable law or agreed to in writing, software
+ # distributed under the License is distributed on an "AS IS" BASIS,
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+ # ============LICENSE_END=========================================================
+ -->
+
+<ng4-loading-spinner [timeout]="1000000"></ng4-loading-spinner>
+<div style="margin: 0px 0px 10px 20px; width: 97%; min-width: 900px; border: 1px solid darkslategray">
+ <!--Table of base microservices-->
+ <p-table #dt *ngIf="loadTable" [columns]="cols" [value]="msElements" sortMode="multiple" [paginator]="true"
+ [rows]="18" [rowsPerPageOptions]="[10,12,14,16,18,20,25,50]" (onFilter)="onTableFiltered(dt.filteredValue)" dataKey="id">
+
+ <!--Top caption row-->
+ <ng-template pTemplate="caption">
+
+ <div style="margin-left: -5%; width: 90%; max-height: 25px; display: inline-flex;">
+ <!--Microservices Table Header-->
+ <div style="float: left;">
+ <!--Refresh-->
+ <i class="fa fa-refresh" (click)="getAllMs()"></i>
+ <!--Global Filter-->
+ <input type="text" pInputText size="50" placeholder="Global Filter"
+ (input)="dt.filterGlobal($event.target.value, 'contains')"
+ style="width: 250px; height:25px; font-size: 12px; margin-left: 15px">
+ <i class="fa fa-search" style="margin:4px 0px 0 8px"></i>
+ </div>
+
+ <h4 style="margin-left: 15%"><b>Microservices</b></h4>
+
+ </div>
+
+ <div style="float: right;">
+ <button pButton type="button" (click)="showAddChangeDialog()" matTooltip="Add Microservice" matTooltipPosition="above"
+ style="border-radius: 5px; width: 65px; height: 27px; font-size: 14px; border: none; display: inline-flex;">
+ <i class="pi pi-plus" style="margin-top: 5px; margin-left: 10px;"></i>
+ <label style="font-weight: 800; margin-top: 3px">MS</label>
+ </button>
+ </div>
+
+ </ng-template>
+
+ <!--Header row with dynamic column names. Columns include microservice Name, Type, Location and Namespace-->
+ <ng-template pTemplate="header" let-columns>
+ <tr style="text-align: center">
+ <th style="width: 3em"></th>
+ <th class="ui-state-highlight" *ngFor="let col of columns" [pSortableColumn]="col.field" style="font-size: 12px; outline: none; vertical-align: bottom;" [ngStyle]="{'width': col.width}">
+ {{col.header}}<br>
+ <p-sortIcon [field]="col.field"></p-sortIcon>
+ </th>
+ <th style="font-size: 13px; width: 6.5%; vertical-align: top;">
+ Actions
+ </th>
+ </tr>
+
+ <!--Second header row for individual column filters-->
+ <tr style="text-align: center;">
+ <th style="width: 3em"></th>
+ <th *ngFor="let col of columns" [ngSwitch]="col.field">
+ <input pInputText type="text"
+ (input)="dt.filter($event.target.value, col.field, 'contains')" style="width: 100%; height: 20px; font-size: 10px;"
+ placeholder="Filter">
+ </th>
+ <th></th>
+ </tr>
+ </ng-template>
+
+ <!--dynamic rows generated from columns object and msElems object-->
+ <ng-template pTemplate="body" let-rowData let-expanded="expanded" let-msElem>
+ <tr style="font-size: 12px;">
+ <!--Column for row expand buttons-->
+ <td>
+ <a href="#" [pRowToggler]="rowData">
+ <i [ngClass]="expanded ? 'pi pi-chevron-down' : 'pi pi-chevron-right'"></i>
+ </a>
+ </td>
+
+ <td *ngFor="let col of cols">
+ <div *ngIf="col.field==='status'"
+ style="width: fit-content; width: -moz-max-content; padding: 0px 5px 0px 5px; border-radius: 3px; font-weight: 600;"
+ [ngClass]="{'greenStatus' : msElem[col.field] === 'ACTIVE',
+ 'greyStatus' : msElem[col.field] === 'INACTIVE'}">
+ {{msElem[col.field]}}
+ </div>
+ <div *ngIf="col.field!=='status'">{{msElem[col.field]}}</div>
+ </td>
+
+ <!--Actions Column-->
+ <td>
+ <div style="text-align: center;">
+ <button pButton type="button" style="background-color: transparent; border: none; width: 20px; height: 20px; vertical-align: middle;" class="ui-button-secondary" [matMenuTriggerFor]="menu">
+ <i class="pi pi-ellipsis-h" style="color: grey;"></i>
+ </button>
+ <mat-menu #menu="matMenu" xPosition="before">
+
+ <div style="background-color: rgba(128, 128, 128, 0.25);">
+ <span style="font-size: 12px; margin-left: 10px; font-weight: 500;"><i class="pi pi-plus"
+ style="font-size: 10px;"></i> Add</span>
+ </div>
+
+ <button mat-menu-item class="table_action_item" (click)="showAddChangeMsInstanceDialog(rowData)">Add MS
+ Instance...</button>
+
+ <div style="background-color: rgba(128, 128, 128, 0.25);">
+ <span style="font-size: 12px; margin-left: 10px; font-weight: 500;"><i class="pi pi-pencil"></i> Update</span>
+ </div>
+
+ <button mat-menu-item class="table_action_item" (click)="showAddChangeDialog(rowData)">Update Microservice...</button>
+ </mat-menu>
+ </div>
+ </td>
+ </tr>
+ </ng-template>
+
+ <!--Row expand content-->
+ <ng-template pTemplate="rowexpansion" let-rowData let-columns="columns">
+ <tr>
+ <td [attr.colspan]="columns.length + 2">
+ <div class="row-expand-layout" [@rowExpansionTrigger]="'active'">
+ <!-- Audit Fields -->
+ <div class="row-expand-card" style="background-color: rgba(95, 158, 160, 0.295)">
+ <b>Created By:</b> {{rowData.metadata.createdBy}}<br>
+ <b>Created On:</b> {{rowData.metadata.createdOn}}<br>
+ <b>Updated By:</b> {{rowData.metadata.updatedBy}}<br>
+ <b>Updated On:</b> {{rowData.metadata.updatedOn}}
+ </div>
+ <!-- Notes -->
+ <div class="row-expand-card" style="background-color: rgba(100, 148, 237, 0.219)">
+ <b>Notes:</b><br>
+ <p-scrollPanel [style]="{width: '100%', height: '62px'}">
+ <div style="font-size: 12px; word-break: normal;">{{rowData.metadata.notes}}</div>
+ </p-scrollPanel>
+ </div>
+ <!-- Labels -->
+ <div class="row-expand-card" style="background-color: rgba(76, 65, 225, 0.199)">
+ <b style="padding-bottom: 5px;">Labels:</b><br>
+ <div *ngFor="let label of rowData['metadata']['labels']" style="display: inline-flex; margin-top: 5px;">
+ <div style="padding: 2px 7px 3px 0px;">
+ <span style="background-color: rgba(80, 80, 80, 0.185); padding: 3px; border-radius: 3px;">{{label}}</span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </td>
+ </tr>
+ </ng-template>
+ </p-table>
+
+ <!--download buttons for exporting table to either csv or excel file-->
+ <div *ngIf="loadTable" style="margin-left: 10px; margin-top: -32px; float: left;">
+ <button pButton type="button" (click)="exportTable('csv')"
+ matTooltip="Export Table to CSV" matTooltipPosition="above"
+ style="border-radius: 5px; width: 65px; height: 22px; font-size: 14px; border: none; margin-top: 4px; display: inline-flex;">
+ <i class="pi pi-file" style="margin-top: 2px; margin-left: 8px;"></i>
+ <label style="font-weight: 800; vertical-align: middle;">CSV</label>
+ </button>
+ <button pButton type="button" (click)="exportTable('excel')"
+ matTooltip="Export Table to XLSX" matTooltipPosition="above"
+ style="border-radius: 5px; width: 65px; height: 22px; margin-left: 7px; font-size: 14px; background-color: green; border: none; display: inline-flex;">
+ <i class="pi pi-file-excel" style="margin-top: 2px; margin-left: 4px;"></i>
+ <label style="font-weight: 800; vertical-align: middle;">Excel</label>
+ </button>
+ </div>
+
+ <!-- Dialog to Add or Change a MS -->
+ <app-ms-add-change *ngIf="showMsAddChangeDialog" [visible]="showMsAddChangeDialog" [currentRow]="currentRow" (handler)="addOrChangeMs($event)"></app-ms-add-change>
+
+ <!-- Dialog to Add (or Change) a MS Instance -->
+ <app-ms-instance-add *ngIf="showAddChangeMsInstance" [visible]="showAddChangeMsInstance" [msName]="addInstanceTo" [currentRow]="currentRow" (handler)="addMsInstance($event)"></app-ms-instance-add>
+
+ <!-- Shared success message -->
+ <p-toast key="addChangeSuccess"></p-toast>
+
+</div> \ No newline at end of file
diff --git a/mod2/ui/src/app/microservices/microservices.component.spec.ts b/mod2/ui/src/app/microservices/microservices.component.spec.ts
new file mode 100644
index 0000000..2d2e5f1
--- /dev/null
+++ b/mod2/ui/src/app/microservices/microservices.component.spec.ts
@@ -0,0 +1,134 @@
+/*
+ * # ============LICENSE_START=======================================================
+ * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+ * # ================================================================================
+ * # Licensed under the Apache License, Version 2.0 (the "License");
+ * # you may not use this file except in compliance with the License.
+ * # You may obtain a copy of the License at
+ * #
+ * # http://www.apache.org/licenses/LICENSE-2.0
+ * #
+ * # Unless required by applicable law or agreed to in writing, software
+ * # distributed under the License is distributed on an "AS IS" BASIS,
+ * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * # See the License for the specific language governing permissions and
+ * # limitations under the License.
+ * # ============LICENSE_END=========================================================
+ */
+
+import { HttpClientTestingModule } from '@angular/common/http/testing';
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { FormsModule, ReactiveFormsModule } from '@angular/forms';
+import { MatMenuModule } from '@angular/material';
+import { RouterTestingModule } from '@angular/router/testing';
+import { JwtHelperService, JWT_OPTIONS } from '@auth0/angular-jwt';
+import { Ng4LoadingSpinnerModule } from 'ng4-loading-spinner';
+import { MessageService } from 'primeng/api';
+import { ButtonModule } from 'primeng/button';
+import { CalendarModule } from 'primeng/calendar';
+import { DialogModule } from 'primeng/dialog';
+import { DropdownModule } from 'primeng/dropdown';
+import { ScrollPanelModule } from 'primeng/scrollpanel';
+import { TableModule } from 'primeng/table';
+import { ToastModule } from 'primeng/toast';
+import { MsAddChangeComponent } from '../ms-add-change/ms-add-change.component';
+import { MsInstanceAddComponent } from '../ms-instance-add/ms-instance-add.component';
+
+import { MicroservicesComponent } from './microservices.component';
+
+describe('MicroservicesComponent', () => {
+ let component: MicroservicesComponent;
+ let fixture: ComponentFixture<MicroservicesComponent>;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [
+ MicroservicesComponent,
+ MsAddChangeComponent,
+ MsInstanceAddComponent,
+ ],
+ imports: [
+ Ng4LoadingSpinnerModule,
+ TableModule,
+ MatMenuModule,
+ ScrollPanelModule,
+ ToastModule,
+ DialogModule,
+ DropdownModule,
+ FormsModule,
+ ReactiveFormsModule,
+ ButtonModule,
+ CalendarModule,
+ HttpClientTestingModule,
+ ToastModule,
+ RouterTestingModule
+ ],
+ providers: [
+ MessageService,
+ { provide: JWT_OPTIONS, useValue: JWT_OPTIONS },
+ JwtHelperService
+ ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(MicroservicesComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+
+ it(`should fill msInstances Object`, () => {
+ const fixture = TestBed.createComponent(MicroservicesComponent);
+ const app = fixture.debugElement.componentInstance;
+
+ let mockMicroservice = [{
+ id: 'testId1234',
+ name: 'test-MS',
+ tag: 'test-MS-tag',
+ serviceName: 'testServiceName',
+ type: 'testType',
+ location: 'TestLocation',
+ namespace: 'testNameSpace',
+ status: 'testStatus',
+ metadata: {
+ createdBy: 'test',
+ createdOn: '01-01-2020 12:00',
+ updatedBy: 'test',
+ updatedOn: '01-01-2020 12:00',
+ notes: 'test',
+ labels: ['test'],
+ },
+ msInstances: 'test'
+ }]
+
+ app.fillTable(mockMicroservice)
+
+ expect(app.loadTable).toEqual(true);
+ expect(app.msElements.length).toEqual(1);
+ });
+
+ it(`should set addOrChange to "Add"`, () => {
+ const fixture = TestBed.createComponent(MicroservicesComponent);
+ const app = fixture.debugElement.componentInstance;
+
+ let mockRowData = null
+ app.showAddChangeDialog(mockRowData)
+
+ expect(app.addOrChange).toEqual('Add');
+ });
+
+ it(`should set addOrChange to "Change"`, () => {
+ const fixture = TestBed.createComponent(MicroservicesComponent);
+ const app = fixture.debugElement.componentInstance;
+
+ let mockRowData = {field: 'test'}
+ app.showAddChangeDialog(mockRowData)
+
+ expect(app.addOrChange).toEqual('Change');
+ });
+});
diff --git a/mod2/ui/src/app/microservices/microservices.component.ts b/mod2/ui/src/app/microservices/microservices.component.ts
new file mode 100644
index 0000000..640e750
--- /dev/null
+++ b/mod2/ui/src/app/microservices/microservices.component.ts
@@ -0,0 +1,311 @@
+/*
+ * # ============LICENSE_START=======================================================
+ * # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
+ * # ================================================================================
+ * # Licensed under the Apache License, Version 2.0 (the "License");
+ * # you may not use this file except in compliance with the License.
+ * # You may obtain a copy of the License at
+ * #
+ * # http://www.apache.org/licenses/LICENSE-2.0
+ * #
+ * # Unless required by applicable law or agreed to in writing, software
+ * # distributed under the License is distributed on an "AS IS" BASIS,
+ * # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * # See the License for the specific language governing permissions and
+ * # limitations under the License.
+ * # ============LICENSE_END=========================================================
+ */
+
+import { Component, OnInit, ViewChild, ElementRef, Input, EventEmitter, Output } from '@angular/core';
+import { MatTableDataSource } from '@angular/material/table';
+import { Table } from 'primeng/table';
+import { MessageService } from 'primeng/api';
+import { trigger, state, style, transition, animate } from '@angular/animations';
+import { BaseMicroserviceService } from '../services/base-microservice.service';
+import { MsAddService } from '../services/ms-add.service';
+import { MicroserviceInstanceService } from '../services/microservice-instance.service';
+import { AuthService } from '../services/auth.service';
+import { DatePipe } from '@angular/common';
+import { Ng4LoadingSpinnerService } from 'ng4-loading-spinner';
+import { DownloadService } from '../services/download.service';
+
+@Component({
+ selector: 'app-microservices',
+ templateUrl: './microservices.component.html',
+ styleUrls: ['./microservices.component.css'],
+ animations: [
+ trigger('rowExpansionTrigger', [
+ state('void', style({
+ transform: 'translateX(-10%)',
+ opacity: 0
+ })),
+ state('active', style({
+ transform: 'translateX(0)',
+ opacity: 1
+ })),
+ transition('* <=> *', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
+ ])
+ ],
+ providers: [DatePipe]
+})
+export class MicroservicesComponent implements OnInit {
+ @ViewChild(Table, { static: false }) dt: Table;
+
+ /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
+ msElements: any[] = [];
+ dataSource = new MatTableDataSource<any>(this.msElements);
+ cols: any[] = [
+ { field: 'name', header: 'MS Name' },
+ { field: 'tag', header: 'MS Tag' },
+ { field: 'serviceName', header: 'Service Short Name'},
+ { field: 'type', header: 'Type', width: '11%' },
+ { field: 'namespace', header: 'Namespace', width: '15%' },
+ { field: 'status', header: 'Status', width: '90px' }
+ ];
+ columns: any[];
+ loadTable: boolean;
+ filteredRows: any;
+ downloadItems: { label: string; command: () => void; }[];
+ showAddChangeMsInstance: boolean;
+ addInstanceTo: string = "";
+ msInstanceStates: { label: string, value: string }[] = [
+ { label: 'New', value: 'new' },
+ { label: 'In Dev', value: 'in-dev' },
+ { label: 'Dev Complete', value: 'dev-complete' },
+ { label: 'In Test', value: 'in-test' },
+ { label: 'Certified', value: 'certified' },
+ { label: 'Prod Deployed', value: 'prod-deployed' }
+ ]
+
+ // Json to add MS to DB, returned from child
+ msAddChangeJson: any;
+
+ showMsAddChangeDialog: boolean = false;
+ currentRow: any;
+ currentMsRow: string = "";
+ addOrChange: string;
+ username: string;
+ errorMessage: any;
+ successMessage: string;
+
+ constructor(private spinnerService: Ng4LoadingSpinnerService, private baseMsService: BaseMicroserviceService,
+ private msInstanceApi: MicroserviceInstanceService, private messageService: MessageService,
+ private addChangeMsApi: MsAddService, private authService: AuthService, private datePipe: DatePipe,
+ private downloadService: DownloadService) { }
+
+ ngOnInit() {
+ this.username = this.authService.getUser().username;
+ this.getAllMs();
+ }
+
+ getAllMs() {
+ this.spinnerService.show();
+ this.msElements = [];
+ this.loadTable = false;
+
+ this.baseMsService.getAllBaseMs()
+ .subscribe((data: any[]) => {
+ this.fillTable(data)
+ })
+
+ this.columns = this.cols.map(col => ({ title: col.header, dataKey: col.field }));
+ }
+
+ /*checks when table is filtered and stores filtered data in new
+ object to be downloaded when download button is clicked*/
+ onTableFiltered(values) {
+ if (values !== null) {
+ this.filteredRows = values;
+ } else {
+ this.filteredRows = this.msElements;
+ }
+ }
+
+ //download table as excel file
+ exportTable(exportTo: string) {
+ let downloadElements: any[] = []
+
+ //labels array not handled well by excel download so converted them to a single string
+ for (let row of this.filteredRows) {
+ let labels;
+ let notes;
+ if (exportTo === "excel") {
+ if (row.metadata.labels !== undefined) {
+ labels = row.metadata.labels.join(",")
+ }
+ } else {
+ labels = row.metadata.labels
+ }
+
+ if (row.metadata.notes !== null && row.metadata.notes !== undefined && row.metadata.notes !== '') {
+ notes = encodeURI(row.metadata.notes).replace(/%20/g, " ").replace(/%0A/g, "\\n")
+ }
+
+ downloadElements.push({
+ MS_Name: row.name,
+ MS_Tag: row.tag,
+ Service_Short_Name: row.serviceName,
+ Type: row.type,
+ Location: row.location,
+ Namespace: row.namespace,
+ Status: row.status,
+ Created_By: row.metadata.createdBy,
+ Created_On: row.metadata.createdOn,
+ Updated_By: row.metadata.updatedBy,
+ Updated_On: row.metadata.updatedOn,
+ Notes: notes,
+ Labels: labels
+ })
+ }
+
+ let csvHeaders = []
+
+ if (exportTo === "csv") {
+ csvHeaders = [
+ "MS_Name",
+ "MS_Tag",
+ "Service_Short_Name",
+ "Type",
+ "Location",
+ "Namespace",
+ "Status",
+ "Created_By",
+ "Created_On",
+ "Updated_By",
+ "Updated_On",
+ "Notes",
+ "Labels"
+ ];
+ }
+
+ this.downloadService.exportTableData(exportTo, downloadElements, csvHeaders)
+ }
+
+ // * * * * * Show the Dialog to Add a MS (<app-ms-add-change> tag in the html) * * * * *
+ showAddChangeDialog(rowData) {
+ this.showMsAddChangeDialog = true;
+ this.currentRow = rowData;
+ if (this.currentRow) {
+ this.addOrChange = "Change";
+ } else {
+ this.addOrChange = "Add";
+ }
+ }
+
+ // * * * * * Add or Change a MS * * * * *
+ // The response includes the entire MS record that was Added or Changed, (along with ID and audit fields).
+ // When Added, the response is added directly to the table. When Changed, the current record is updated field-by-field.
+ addOrChangeMs(jsonFromChildDialog) {
+ if (jsonFromChildDialog) {
+ this.msAddChangeJson = jsonFromChildDialog;
+ if (this.addOrChange == "Change") {
+ this.currentMsRow = this.currentRow['id']
+ }
+ this.addChangeMsApi.addChangeMsToCatalog(this.addOrChange, this.currentMsRow, this.msAddChangeJson).subscribe(
+ (response: any) => {
+ if (this.addOrChange == "Add") {
+ this.msElements.unshift(response);
+ this.successMessage = "Microservice Added";
+ } else {
+ this.updateCurrentRow(jsonFromChildDialog);
+ this.successMessage = "Microservice Updated";
+ }
+ this.showMsAddChangeDialog = false;
+ this.messageService.add({ key: 'addChangeSuccess', severity: 'success', summary: 'Success', detail: this.successMessage, life: 5000 });
+ },
+ errResponse => {
+ // for testing only - this.updateCurrentRow(jsonFromChildDialog);
+ this.messageService.add({ key: 'msAddChangeError', severity: 'error', summary: 'Error', detail: errResponse.error.message, sticky: true });
+ }
+ )
+ }
+ else {
+ this.showMsAddChangeDialog = false;
+ };
+ }
+
+ updateCurrentRow(jsonFromChildDialog) {
+ const newRow = JSON.parse(jsonFromChildDialog);
+ this.currentRow['name'] = newRow['name'];
+ this.currentRow['serviceName'] = newRow['serviceName'];
+ this.currentRow['type'] = newRow['type'];
+ this.currentRow['location'] = newRow['location'];
+ this.currentRow['namespace'] = newRow['namespace'];
+ this.currentRow['metadata']['labels'] = newRow['metadata']['labels'];
+ this.currentRow['metadata']['notes'] = newRow['metadata']['notes'];
+ }
+
+ /* * * * Show pop up for Adding a new MS Instance * * * */
+ showAddChangeMsInstanceDialog(data) {
+ this.addInstanceTo = data['name']
+ this.showAddChangeMsInstance = true
+ }
+
+ /* * * * Call API to Add a new MS Instance * * * */
+ addMsInstance(body) {
+ if (body === null) {
+ this.showAddChangeMsInstance = false;
+ } else {
+ this.msInstanceApi.addChangeMsInstance("ADD", this.addInstanceTo, body).subscribe(
+ (data) => {
+ this.messageService.add({ key: 'addChangeSuccess', severity: 'success', summary: 'Success', detail: "MS Instance Added", life: 5000 });
+ this.showAddChangeMsInstance = false;
+ },
+ (errResponse) => {
+ console.log(errResponse)
+ this.messageService.add({ key: 'instanceAddChangeError', severity: 'error', summary: 'Error', detail: errResponse.error.message, sticky: true });
+ }
+ )
+ }
+ }
+
+ //fill object with microservice data, to be used to fill table.
+ //checks if fields are empty and if they are, store 'N/A' as the values
+ fillTable(data) {
+ for (let elem of data) {
+ var tempMsElement: any = {
+ id: elem.id,
+ name: elem.name,
+ tag: elem.tag,
+ serviceName: elem.serviceName,
+ type: elem.type,
+ location: elem.location,
+ namespace: elem.namespace,
+ status: elem.status,
+ metadata: {
+ createdBy: elem.metadata.createdBy,
+ createdOn: this.datePipe.transform(elem.metadata.createdOn, 'MM-dd-yyyy HH:mm'),
+ updatedBy: elem.metadata.updatedBy,
+ updatedOn: this.datePipe.transform(elem.metadata.updatedOn, 'MM-dd-yyyy HH:mm'),
+ notes: elem.metadata.notes,
+ labels: elem.metadata.labels
+ },
+ msInstances: elem.msInstances
+ }
+ this.msElements.push(tempMsElement)
+ }
+ this.filteredRows = this.msElements
+ this.loadTable = true;
+ this.spinnerService.hide();
+ }
+}
+
+export interface AddMsInstance{
+ name: string,
+ release: string,
+ metadata: {
+ scrumLead: string,
+ scrumLeadId: string,
+ systemsEngineer: string,
+ systemsEngineerId: string,
+ developer: string;
+ developerId: string;
+ pstDueDate: string,
+ pstDueIteration: string,
+ eteDueDate: string,
+ eteDueIteration: string,
+ labels: string[],
+ notes: string
+ }
+ user: string
+}