Merge "InvalidRoleException-junits"
[portal.git] / portal-FE-common / src / app / pages / microservice-onboarding / microservice-onboarding.component.ts
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38
39 import { Component, OnInit, ViewChild, Input } from '@angular/core';
40 import { MicroserviceService, WidgetOnboardingService } from '../../shared/services/index'
41 import { IMircroservies } from 'src/app/shared/model/microservice-onboarding/microservices';
42 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
43 import { MatTableDataSource } from '@angular/material';
44 import { MatSort, MatPaginator } from '@angular/material';
45 import { MicroserviceAddDetailsComponent } from './microservice-add-details/microservice-add-details.component';
46 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
47 import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
48
49 @Component({
50   selector: 'app-microservice-onboarding',
51   templateUrl: './microservice-onboarding.component.html',
52   styleUrls: ['./microservice-onboarding.component.scss']
53 })
54 export class MicroserviceOnboardingComponent implements OnInit {
55
56   showSpinner = true;
57   microServiceList: Array<IMircroservies> = [];
58   result: any;
59   isEditMode: boolean = false;
60   
61   displayedColumns: string[] = ['microserviceName', 'serviceEndPointURL', 'securityType','delete'];
62   dataSource = new MatTableDataSource(this.microServiceList);
63   @ViewChild(MatSort) sort: MatSort;
64   @ViewChild(MatPaginator) paginator: MatPaginator;
65
66   constructor(public microservice: MicroserviceService, public ngbModal: NgbModal ) { }
67
68   ngOnInit() {
69     this.getOnboardingServices();
70   }
71
72   getOnboardingServices(){
73     //console.log("getOnboardingServices called");
74     this.microservice.getServiceList()
75     .subscribe(_data => {
76         this.result = _data;
77         if (this.result == null || this.result == 'undefined') {
78              console.log('MicroserviceService::getServiceList Failed: Result or result.data is null');
79          }else {
80           this.microServiceList = this.result;
81           this.populateTableData(this.microServiceList);
82          }
83     }, error =>{
84       console.log(error);
85     });
86   }
87
88   deleteService(microserviceObj: IMircroservies, isConfirmed: boolean): void {
89     let confirmationMsg = 'You are about to delete this Microservice : ' + microserviceObj.name+ '. Click OK to continue.';
90     this.openInformationModal("Confirmation",confirmationMsg).result.then((result) => {
91       if (result === 'Ok') {
92         if(!microserviceObj || microserviceObj == null){
93           console.log('MicroserviceOnboardingCtrl::deleteService: No service or ID... cannot delete');
94           return;
95         }
96         //console.log("service id to delete", microserviceObj.id)
97         this.microServiceList.splice(this.microServiceList.indexOf(microserviceObj), 1);
98         this.populateTableData(this.microServiceList);
99         this.microservice.deleteService(microserviceObj.id)
100           .subscribe( data => {
101             this.result = data;
102             this.microServiceList = [];
103             this.getOnboardingServices();
104           }, error => {
105             console.log(error);
106         }); 
107       }
108     }, (resut) => {
109       return;
110     })
111   }
112
113  
114   openAddNewMicroserviceModal(rowData: any){
115     //console.log("openAddNewMicroserviceModal getting called...");
116     const modalRef = this.ngbModal.open(MicroserviceAddDetailsComponent, { size: 'lg' });
117     modalRef.componentInstance.title = 'Microservice Onboarding';
118     if(rowData != 'undefined' && rowData){
119       modalRef.componentInstance.ms = rowData;
120       this.isEditMode = true;
121     }else{
122       modalRef.componentInstance.ms  = {};
123       this.isEditMode = false;
124     }
125     modalRef.componentInstance.passEntry.subscribe((receivedEntry: any) => {
126       //console.log("receivedEntry >>> ",receivedEntry);
127       if(receivedEntry){
128         this.microServiceList = [];
129         this.getOnboardingServices();
130       }
131     });
132   }
133
134   populateTableData(microServiceList: Array<IMircroservies>){
135     this.dataSource = new MatTableDataSource(microServiceList);
136     this.dataSource.sort = this.sort;
137     this.dataSource.paginator = this.paginator;
138   }
139
140   applyFilter(filterValue: string) {
141     this.dataSource.filter = filterValue.trim().toLowerCase();
142   }
143
144   openConfirmationModal(_title: string, _message: string) {
145     const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent);
146     modalInfoRef.componentInstance.title = _title;
147     modalInfoRef.componentInstance.message = _message;
148   }
149
150   openInformationModal(_title: string, _message: string){
151     const modalInfoRef = this.ngbModal.open(InformationModalComponent);
152     modalInfoRef.componentInstance.title = _title;
153     modalInfoRef.componentInstance.message = _message;
154     return modalInfoRef;
155   }
156 }