Application Onboarding page changes
[portal.git] / ecomp-portal-FE-os / client / src / views / applications / applications.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 ApplicationsCtrl {
41
42         constructor($log, $cookies, conf, ngDialog,
43                                 applicationsService, confirmBoxService, userProfileService, utilsService,$modal,$scope) {
44             this.emptyImgForPreview = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
45             $scope.isAdmin = false;
46             let getOnboardingApps = () => {
47                 this.isLoadingTable = true;
48                 applicationsService.getOnboardingApps()
49                     .then(appsList => {
50                         // Use proper back-end URL to load image
51                         for (var i = 0; i < appsList.length; i++) {
52                                 appsList[i].imageLink = '';
53                                 if (appsList[i].imageUrl){
54                                         appsList[i].imageLink = conf.api.appThumbnail.replace(':appId', appsList[i].id);
55                                         appsList[i].imageLink = appsList[i].imageLink+'?' + new Date().getTime();
56                                 }
57                         }
58                         if(appsList.length == 0)
59                                 {
60                                 confirmBoxService.showInformation('You do not have applications to edit').then(isConfirmed => {});
61                                 }
62                         this.appsList = appsList;
63                     }).catch(err => {
64                         confirmBoxService.showInformation('There was a problem retrieving the Applications. ' +
65                             'Please try again later. Error Status: '+ err.status).then(isConfirmed => {});
66                         $log.error('ApplicationsCtrl:openAddNewAppModal: Error: ', err);
67                     }).finally(()=> {
68                         this.isLoadingTable = false;
69                     });
70             };
71
72             let checkIfUserIsSuperAdmin = () => {
73                 applicationsService.checkIfUserIsSuperAdmin().then(res => {   
74                         if(res) {
75                                 $scope.isAdmin = true;
76                                 }
77                         }).catch(err => {
78                             $log.error('ApplicationsCtrl.checkIfUserIsSuperAdmin:: Failed - ' + err);
79                         }).finally(()=> {
80                             this.isSaving = false;
81                         });
82               };
83                  
84             let init = () => {
85                 this.isLoadingTable = false;
86                 checkIfUserIsSuperAdmin();
87                 getOnboardingApps();
88                 this.searchString = '';
89                 this.appsTableHeaders = [
90                     {name: 'Application Name', value: 'name', isSortable: true},
91                     {name: 'Active', value: 'isEnabled', isSortable: true},
92                     {name: 'Integration Type', value: 'restrictedApp', isSortable: true},
93                     {name: 'Guest Access', value: 'isOpen', isSortable: true},
94                     {name: 'URL', value: 'url', isSortable: true},
95                     {name: 'REST URL', value: 'restUrl', isSortable: true},                
96                     {name: 'Communication Topic', value: 'uebTopicName', isSortable: true},
97                     {name: 'Communication Key', value: 'uebKey', isSortable: true},
98                     {name: 'Communication Secret', value: 'uebSecret', isSortable: true},
99                     {name: 'Application Namespace', value: 'nameSpace', isSortable: true},
100                     {name: 'Central Access Type', value: 'isCentralAuth', isSortable: true}
101                 ];
102                 this.appsList = [];
103             };
104
105             init();
106
107             this.openAddNewAppModal = (selectedApp) => {
108                 let data = null;
109                 if (selectedApp) {
110                     if (!selectedApp.id) {
111                         $log.error('App id not found');
112                         return;
113                     }
114                     data = {
115                         app: selectedApp
116                     }
117                 }
118                 var modalInstance = $modal.open({
119                     templateUrl: 'app/views/applications/application-details-dialog/application-details.modal.html',
120                     controller: 'AppDetailsModalCtrl as appDetails',
121                     sizeClass: 'modal-large', 
122                         windowClass:"modal-docked",
123                     resolve: {
124                                         items: function () {
125                                   return data;
126                                         }
127                         }
128                 })
129                 
130                 modalInstance.result.finally(function (){
131                                 getOnboardingApps();
132                 });
133
134             };
135
136             this.deleteApp = application => {
137                 $log.debug('ApplicationsCtrl:deleteApp:: ', application.name);
138
139                 confirmBoxService.deleteItem(application.name).then(isConfirmed => {
140                     if(isConfirmed){
141                         if(!application || !application.id){
142                             $log.error('ApplicationsCtrl:deleteApp:: No application or ID... cannot delete');
143                             return;
144                         }
145                         applicationsService.deleteOnboardingApp(application.id).then(() => {
146                             this.appsList.splice(this.appsList.indexOf(application), 1);
147                         }).catch(err => {
148                             confirmBoxService.showInformation('There was a problem deleting the Application. ' +
149                                 'Please try again later. Error Status: '+ err.status).then(isConfirmed => {});
150                             $log.error('ApplicationsCtrl:deleteApp: Error: ', err);
151                         });
152                     }
153                 }).catch(err => {
154                     confirmBoxService.showInformation('There was a problem deleting the Application. ' +
155                         'Please try again later. Error Status: '+ err.status).then(isConfirmed => {});
156                     $log.error('ApplicationsCtrl:deleteApp error:: ', err);
157                 });
158
159             };
160
161         }
162     }
163     ApplicationsCtrl.$inject = ['$log', '$cookies', 'conf', 'ngDialog',
164                                 'applicationsService', 'confirmBoxService', 'userProfileService', 'utilsService','$modal', '$scope'];
165     angular.module('ecompApp').controller('ApplicationsCtrl', ApplicationsCtrl);
166 })();