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