|
12 | 12 | * limitations under the License. |
13 | 13 | */ |
14 | 14 | 'use strict'; |
| 15 | +(function() { |
15 | 16 |
|
16 | | -angular.module('zeppelinWebApp').controller('CredentialCtrl', function($scope, $rootScope, $http, baseUrlSrv, ngToast) { |
17 | | - $scope._ = _; |
| 17 | + angular.module('zeppelinWebApp').controller('CredentialCtrl', CredentialCtrl); |
18 | 18 |
|
19 | | - $scope.credentialInfo = []; |
20 | | - $scope.showAddNewCredentialInfo = false; |
| 19 | + CredentialCtrl.$inject = ['$scope', '$rootScope', '$http', 'baseUrlSrv', 'ngToast']; |
21 | 20 |
|
22 | | - var getCredentialInfo = function() { |
23 | | - $http.get(baseUrlSrv.getRestApiBase() + '/credential'). |
24 | | - success(function(data, status, headers, config) { |
25 | | - $scope.credentialInfo = _.map(data.body.userCredentials, function(value, prop) { |
26 | | - return {entity: prop, password: value.password, username: value.username}; |
| 21 | + function CredentialCtrl($scope, $rootScope, $http, baseUrlSrv, ngToast) { |
| 22 | + $scope._ = _; |
| 23 | + |
| 24 | + $scope.credentialInfo = []; |
| 25 | + $scope.showAddNewCredentialInfo = false; |
| 26 | + |
| 27 | + var getCredentialInfo = function() { |
| 28 | + $http.get(baseUrlSrv.getRestApiBase() + '/credential'). |
| 29 | + success(function(data, status, headers, config) { |
| 30 | + $scope.credentialInfo = _.map(data.body.userCredentials, function(value, prop) { |
| 31 | + return {entity: prop, password: value.password, username: value.username}; |
| 32 | + }); |
| 33 | + console.log('Success %o %o', status, $scope.credentialInfo); |
| 34 | + }). |
| 35 | + error(function(data, status, headers, config) { |
| 36 | + if (status === 401) { |
| 37 | + ngToast.danger({ |
| 38 | + content: 'You don\'t have permission on this page', |
| 39 | + verticalPosition: 'bottom', |
| 40 | + timeout: '3000' |
| 41 | + }); |
| 42 | + setTimeout(function() { |
| 43 | + window.location.replace('/'); |
| 44 | + }, 3000); |
| 45 | + } |
| 46 | + console.log('Error %o %o', status, data.message); |
27 | 47 | }); |
28 | | - console.log('Success %o %o', status, $scope.credentialInfo); |
29 | | - }). |
30 | | - error(function(data, status, headers, config) { |
31 | | - if (status === 401) { |
| 48 | + }; |
| 49 | + |
| 50 | + $scope.addNewCredentialInfo = function() { |
| 51 | + if ($scope.entity && _.isEmpty($scope.entity.trim()) && |
| 52 | + $scope.username && _.isEmpty($scope.username.trim())) { |
32 | 53 | ngToast.danger({ |
33 | | - content: 'You don\'t have permission on this page', |
| 54 | + content: 'Username \\ Entity can not be empty.', |
34 | 55 | verticalPosition: 'bottom', |
35 | 56 | timeout: '3000' |
36 | 57 | }); |
37 | | - setTimeout(function() { |
38 | | - window.location.replace('/'); |
39 | | - }, 3000); |
| 58 | + return; |
40 | 59 | } |
41 | | - console.log('Error %o %o', status, data.message); |
42 | | - }); |
43 | | - }; |
44 | | - |
45 | | - $scope.addNewCredentialInfo = function() { |
46 | | - if ($scope.entity && _.isEmpty($scope.entity.trim()) && |
47 | | - $scope.username && _.isEmpty($scope.username.trim())) { |
48 | | - ngToast.danger({ |
49 | | - content: 'Username \\ Entity can not be empty.', |
50 | | - verticalPosition: 'bottom', |
51 | | - timeout: '3000' |
52 | | - }); |
53 | | - return; |
54 | | - } |
55 | 60 |
|
56 | | - var newCredential = { |
57 | | - 'entity': $scope.entity, |
58 | | - 'username': $scope.username, |
59 | | - 'password': $scope.password |
60 | | - }; |
| 61 | + var newCredential = { |
| 62 | + 'entity': $scope.entity, |
| 63 | + 'username': $scope.username, |
| 64 | + 'password': $scope.password |
| 65 | + }; |
61 | 66 |
|
62 | | - $http.put(baseUrlSrv.getRestApiBase() + '/credential', newCredential). |
63 | | - success(function(data, status, headers, config) { |
64 | | - ngToast.success({ |
65 | | - content: 'Successfully saved credentials.', |
66 | | - verticalPosition: 'bottom', |
67 | | - timeout: '3000' |
| 67 | + $http.put(baseUrlSrv.getRestApiBase() + '/credential', newCredential). |
| 68 | + success(function(data, status, headers, config) { |
| 69 | + ngToast.success({ |
| 70 | + content: 'Successfully saved credentials.', |
| 71 | + verticalPosition: 'bottom', |
| 72 | + timeout: '3000' |
| 73 | + }); |
| 74 | + $scope.credentialInfo.push(newCredential); |
| 75 | + resetCredentialInfo(); |
| 76 | + $scope.showAddNewCredentialInfo = false; |
| 77 | + console.log('Success %o %o', status, data.message); |
| 78 | + }). |
| 79 | + error(function(data, status, headers, config) { |
| 80 | + ngToast.danger({ |
| 81 | + content: 'Error saving credentials', |
| 82 | + verticalPosition: 'bottom', |
| 83 | + timeout: '3000' |
| 84 | + }); |
| 85 | + console.log('Error %o %o', status, data.message); |
68 | 86 | }); |
69 | | - $scope.credentialInfo.push(newCredential); |
70 | | - resetCredentialInfo(); |
| 87 | + }; |
| 88 | + |
| 89 | + $scope.cancelCredentialInfo = function() { |
71 | 90 | $scope.showAddNewCredentialInfo = false; |
72 | | - console.log('Success %o %o', status, data.message); |
73 | | - }). |
74 | | - error(function(data, status, headers, config) { |
75 | | - ngToast.danger({ |
76 | | - content: 'Error saving credentials', |
77 | | - verticalPosition: 'bottom', |
78 | | - timeout: '3000' |
79 | | - }); |
80 | | - console.log('Error %o %o', status, data.message); |
81 | | - }); |
82 | | - }; |
| 91 | + resetCredentialInfo(); |
| 92 | + }; |
83 | 93 |
|
84 | | - $scope.cancelCredentialInfo = function() { |
85 | | - $scope.showAddNewCredentialInfo = false; |
86 | | - resetCredentialInfo(); |
87 | | - }; |
88 | | - |
89 | | - var resetCredentialInfo = function() { |
90 | | - $scope.entity = ''; |
91 | | - $scope.username = ''; |
92 | | - $scope.password = ''; |
93 | | - }; |
94 | | - |
95 | | - $scope.copyOriginCredentialsInfo = function() { |
96 | | - ngToast.info({ |
97 | | - content: 'Since entity is a unique key, you can edit only username & password', |
98 | | - verticalPosition: 'bottom', |
99 | | - timeout: '3000' |
100 | | - }); |
101 | | - }; |
102 | | - |
103 | | - $scope.updateCredentialInfo = function(form, data, entity) { |
104 | | - var request = { |
105 | | - entity: entity, |
106 | | - username: data.username, |
107 | | - password: data.password |
| 94 | + var resetCredentialInfo = function() { |
| 95 | + $scope.entity = ''; |
| 96 | + $scope.username = ''; |
| 97 | + $scope.password = ''; |
108 | 98 | }; |
109 | 99 |
|
110 | | - $http.put(baseUrlSrv.getRestApiBase() + '/credential/', request). |
111 | | - success(function(data, status, headers, config) { |
112 | | - var index = _.findIndex($scope.credentialInfo, {'entity': entity}); |
113 | | - $scope.credentialInfo[index] = request; |
114 | | - return true; |
115 | | - }). |
116 | | - error(function(data, status, headers, config) { |
117 | | - console.log('Error %o %o', status, data.message); |
118 | | - ngToast.danger({ |
119 | | - content: 'We couldn\'t save the credential', |
| 100 | + $scope.copyOriginCredentialsInfo = function() { |
| 101 | + ngToast.info({ |
| 102 | + content: 'Since entity is a unique key, you can edit only username & password', |
120 | 103 | verticalPosition: 'bottom', |
121 | 104 | timeout: '3000' |
122 | 105 | }); |
123 | | - form.$show(); |
124 | | - }); |
125 | | - return false; |
126 | | - }; |
127 | | - |
128 | | - $scope.removeCredentialInfo = function(entity) { |
129 | | - BootstrapDialog.confirm({ |
130 | | - closable: false, |
131 | | - closeByBackdrop: false, |
132 | | - closeByKeyboard: false, |
133 | | - title: '', |
134 | | - message: 'Do you want to delete this credential information?', |
135 | | - callback: function(result) { |
136 | | - if (result) { |
137 | | - $http.delete(baseUrlSrv.getRestApiBase() + '/credential/' + entity). |
138 | | - success(function(data, status, headers, config) { |
139 | | - var index = _.findIndex($scope.credentialInfo, {'entity': entity}); |
140 | | - $scope.credentialInfo.splice(index, 1); |
141 | | - console.log('Success %o %o', status, data.message); |
142 | | - }). |
143 | | - error(function(data, status, headers, config) { |
144 | | - console.log('Error %o %o', status, data.message); |
145 | | - }); |
| 106 | + }; |
| 107 | + |
| 108 | + $scope.updateCredentialInfo = function(form, data, entity) { |
| 109 | + var request = { |
| 110 | + entity: entity, |
| 111 | + username: data.username, |
| 112 | + password: data.password |
| 113 | + }; |
| 114 | + |
| 115 | + $http.put(baseUrlSrv.getRestApiBase() + '/credential/', request). |
| 116 | + success(function(data, status, headers, config) { |
| 117 | + var index = _.findIndex($scope.credentialInfo, {'entity': entity}); |
| 118 | + $scope.credentialInfo[index] = request; |
| 119 | + return true; |
| 120 | + }). |
| 121 | + error(function(data, status, headers, config) { |
| 122 | + console.log('Error %o %o', status, data.message); |
| 123 | + ngToast.danger({ |
| 124 | + content: 'We couldn\'t save the credential', |
| 125 | + verticalPosition: 'bottom', |
| 126 | + timeout: '3000' |
| 127 | + }); |
| 128 | + form.$show(); |
| 129 | + }); |
| 130 | + return false; |
| 131 | + }; |
| 132 | + |
| 133 | + $scope.removeCredentialInfo = function(entity) { |
| 134 | + BootstrapDialog.confirm({ |
| 135 | + closable: false, |
| 136 | + closeByBackdrop: false, |
| 137 | + closeByKeyboard: false, |
| 138 | + title: '', |
| 139 | + message: 'Do you want to delete this credential information?', |
| 140 | + callback: function(result) { |
| 141 | + if (result) { |
| 142 | + $http.delete(baseUrlSrv.getRestApiBase() + '/credential/' + entity). |
| 143 | + success(function(data, status, headers, config) { |
| 144 | + var index = _.findIndex($scope.credentialInfo, {'entity': entity}); |
| 145 | + $scope.credentialInfo.splice(index, 1); |
| 146 | + console.log('Success %o %o', status, data.message); |
| 147 | + }). |
| 148 | + error(function(data, status, headers, config) { |
| 149 | + console.log('Error %o %o', status, data.message); |
| 150 | + }); |
| 151 | + } |
146 | 152 | } |
147 | | - } |
148 | | - }); |
149 | | - }; |
| 153 | + }); |
| 154 | + }; |
| 155 | + |
| 156 | + var init = function() { |
| 157 | + getCredentialInfo(); |
| 158 | + }; |
150 | 159 |
|
151 | | - var init = function() { |
152 | | - getCredentialInfo(); |
153 | | - }; |
| 160 | + init(); |
| 161 | + } |
154 | 162 |
|
155 | | - init(); |
156 | | -}); |
| 163 | +})(); |
0 commit comments