Replace ecomp references
[portal.git] / ecomp-portal-FE-common / client / app / views / microservice-onboarding / microservice-onboarding.controller.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 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 'use strict';
39 (function () {
40     class MicroserviceOnboardingCtrl {
41         constructor($log, applicationsService, microserviceService, ngDialog, confirmBoxService,
42                     userProfileService, $cookies, $scope,$modal) {
43                 
44                 
45             let getOnboardingServices = () => {
46                 microserviceService.getServiceList().then(res => {
47                      $scope.serviceList = res;
48                 }).catch(err => {
49                     $log.error('MicroserviceOnboardingCtrl::getOnboardingServices caught error', err);
50                 });
51             };
52             
53             
54             
55             let init = () => {
56                 $scope.serviceList = [];
57                 getOnboardingServices();
58                 this.serviceTableHeaders = [
59                     {name: 'Microservice Name', value: 'name', isSortable: false},
60                     {name: 'Service Endpoint URL', value: 'url', isSortable: false},
61                     {name: 'Security Type', value: 'securityType', isSortable: false}
62                 ];
63             };
64             
65             this.openAddNewMicroserviceModal = (selectedService) => {
66                 let data = null; 
67                                 if(selectedService){
68                                         if(!selectedService.id){
69                                                 $log.error('MicroserviceOnboardingCtrl:openAddNewMicroserviceModal:service id not found');
70                                                 return; 
71                                         } 
72                                         data = { 
73                                                 service:selectedService,
74                                                 list: $scope.serviceList
75                                         }
76                                 }else{
77                                         data = {
78                                                 list: $scope.serviceList        
79                                         }
80                                 }
81                                 
82                                 var modalInstance = $modal.open({
83                     templateUrl: 'app/views/microservice-onboarding/microservice-add-details/microservice-add-details.html',
84                     controller: 'MicroserviceAddDetailsCtrl as microserviceAddDetails',
85                     sizeClass: 'modal-large', 
86                     resolve: {
87                                         items: function () {
88                                   return data;
89                                         }
90                         }
91                 })
92                 
93                 modalInstance.result.finally(function (){
94                                 getOnboardingServices();
95                 });
96
97             };
98                         
99             this.deleteService = service => { 
100                    confirmBoxService.deleteItem(service.name).then(isConfirmed => {   
101                 if(isConfirmed){
102                                 if(!service || !service.id){
103                            $log.error('MicroserviceOnboardingCtrl::deleteService: No service or ID... cannot delete');
104                            return;
105                        }
106                        microserviceService.deleteService(service.id).then((res) => {                               
107                            if(res.status == "WARN"){
108                                    confirmBoxService.showInformation("Failed: widgets " +  res.response + " are assoicated with this microservice!");
109                            }else{
110                                    $scope.serviceList.splice($scope.serviceList.indexOf(service), 1);
111                            }
112                        }).catch(err => {
113                            $log.error('MicroserviceOnboardingCtrl::deleteService error:',err);
114                        });
115                    }
116                }).catch(err => {
117                    $log.error('MicroserviceOnboardingCtrl::deleteService error:',err);
118                });
119
120                 
121             };
122             
123             init();
124         }
125     }
126     MicroserviceOnboardingCtrl.$inject = ['$log', 'applicationsService', 'microserviceService', 'ngDialog', 'confirmBoxService',
127         'userProfileService','$cookies', '$scope','$modal'];
128     angular.module('ecompApp').controller('MicroserviceOnboardingCtrl', MicroserviceOnboardingCtrl);
129 })();