nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / views / applications / applications.controller.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 'use strict';
21 (function () {
22     class ApplicationsCtrl {
23         constructor($log, applicationsService, confirmBoxService, ngDialog,userProfileService,$cookies) {
24             $log.info('ApplicationsCtrl::init: Starting up');
25
26             this.emptyImgForPreview = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
27             let getOnboardingApps = () => {
28                 this.isLoadingTable = true;
29                 applicationsService.getOnboardingApps()
30                     .then(appsList => {
31                         this.appsList = appsList;
32                     }).catch(err => {
33                         $log.error(err);
34                     }).finally(()=> {
35                         this.isLoadingTable = false;
36                     });
37             };
38
39             let init = () => {
40                 this.isLoadingTable = false;
41                 getOnboardingApps();
42
43                 this.searchString = '';
44                 this.appsTableHeaders = [
45                     {name: 'Application Name', value: 'name', isSortable: true},
46                     {name: 'Active', value: 'isEnabled', isSortable: true},
47                     {name: 'Integration Type', value: 'restrictedApp', isSortable: true},
48                     {name: 'Guest Access', value: 'isOpen', isSortable: true},
49                     {name: 'URL', value: 'url', isSortable: true},
50                     {name: 'REST URL', value: 'restUrl', isSortable: true},                
51                     {name: 'Communication Topic', value: 'uebTopicName', isSortable: true},
52                     {name: 'Communication Key', value: 'uebKey', isSortable: true},
53                     {name: 'Communication Secret', value: 'uebSecret', isSortable: true},
54                 ];
55                 this.appsList = [];
56             };
57
58             init();
59
60             this.openAddNewAppModal = (selectedApp) => {
61                 let data = null;
62                 if (selectedApp) {
63                     if (!selectedApp.id) {
64                         $log.error('App id not found');
65                         return;
66                     }
67                     data = {
68                         app: selectedApp
69                     }
70                 }
71                 ngDialog.open({
72                     templateUrl: 'app/views/applications/application-details-dialog/application-details.modal.html',
73                     controller: 'AppDetailsModalCtrl',
74                     controllerAs: 'appDetails',
75                     data: data
76                 }).closePromise.then(needUpdate => {
77                     if (needUpdate.value === true) {
78                         $log.debug('ApplicationsCtrl:openAddNewAppModal:: updating table data...');
79                         getOnboardingApps();
80                     }
81                 });
82
83
84             };
85
86             this.deleteApp = application => {
87                 $log.debug('ApplicationsCtrl:deleteApp:: ', application.name);
88
89                 confirmBoxService.deleteItem(application.name).then(isConfirmed => {
90                     if(isConfirmed){
91                         if(!application || !application.id){
92                             $log.error('ApplicationsCtrl:deleteApp:: No application or ID... cannot delete');
93                             return;
94                         }
95                         applicationsService.deleteOnboardingApp(application.id).then(() => {
96                             this.appsList.splice(this.appsList.indexOf(application), 1);
97                         }).catch(err => {
98                             $log.error(err);
99                         });
100                     }
101                 }).catch(err => {
102                     $log.error('ApplicationsCtrl:deleteApp error:: ', err);
103                 });
104
105             };
106
107         }
108     }
109     ApplicationsCtrl.$inject = ['$log', 'applicationsService', 'confirmBoxService', 'ngDialog','userProfileService','$cookies'];
110     angular.module('ecompApp').controller('ApplicationsCtrl', ApplicationsCtrl);
111 })();