Skip to content

Commit 4c45e08

Browse files
committed
Refactor for IIFE credential, home and interpreter controller
1 parent 7e88eef commit 4c45e08

File tree

3 files changed

+196
-172
lines changed

3 files changed

+196
-172
lines changed

zeppelin-web/src/app/credential/credential.controller.js

Lines changed: 127 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -12,145 +12,152 @@
1212
* limitations under the License.
1313
*/
1414
'use strict';
15+
(function() {
1516

16-
angular.module('zeppelinWebApp').controller('CredentialCtrl', function($scope, $rootScope, $http, baseUrlSrv, ngToast) {
17-
$scope._ = _;
17+
angular.module('zeppelinWebApp').controller('CredentialCtrl', CredentialCtrl);
1818

19-
$scope.credentialInfo = [];
20-
$scope.showAddNewCredentialInfo = false;
19+
CredentialCtrl.$inject = ['$scope', '$rootScope', '$http', 'baseUrlSrv', 'ngToast'];
2120

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);
2747
});
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())) {
3253
ngToast.danger({
33-
content: 'You don\'t have permission on this page',
54+
content: 'Username \\ Entity can not be empty.',
3455
verticalPosition: 'bottom',
3556
timeout: '3000'
3657
});
37-
setTimeout(function() {
38-
window.location.replace('/');
39-
}, 3000);
58+
return;
4059
}
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-
}
5560

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+
};
6166

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);
6886
});
69-
$scope.credentialInfo.push(newCredential);
70-
resetCredentialInfo();
87+
};
88+
89+
$scope.cancelCredentialInfo = function() {
7190
$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+
};
8393

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 = '';
10898
};
10999

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',
120103
verticalPosition: 'bottom',
121104
timeout: '3000'
122105
});
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+
}
146152
}
147-
}
148-
});
149-
};
153+
});
154+
};
155+
156+
var init = function() {
157+
getCredentialInfo();
158+
};
150159

151-
var init = function() {
152-
getCredentialInfo();
153-
};
160+
init();
161+
}
154162

155-
init();
156-
});
163+
})();

zeppelin-web/src/app/home/home.controller.js

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,77 @@
1212
* limitations under the License.
1313
*/
1414
'use strict';
15+
(function() {
1516

16-
angular.module('zeppelinWebApp').controller('HomeCtrl', function($scope, notebookListDataFactory, websocketMsgSrv,
17-
$rootScope, arrayOrderingSrv) {
18-
var vm = this;
19-
vm.notes = notebookListDataFactory;
20-
vm.websocketMsgSrv = websocketMsgSrv;
21-
vm.arrayOrderingSrv = arrayOrderingSrv;
22-
23-
vm.notebookHome = false;
24-
if ($rootScope.ticket !== undefined) {
25-
vm.staticHome = false;
26-
} else {
27-
vm.staticHome = true;
28-
}
17+
angular.module('zeppelinWebApp').controller('HomeCtrl', HomeCtrl);
2918

30-
$scope.isReloading = false;
19+
HomeCtrl.$inject = [
20+
'$scope',
21+
'notebookListDataFactory',
22+
'websocketMsgSrv',
23+
'$rootScope',
24+
'arrayOrderingSrv'
25+
];
3126

32-
var initHome = function() {
33-
websocketMsgSrv.getHomeNotebook();
34-
};
27+
function HomeCtrl($scope, notebookListDataFactory, websocketMsgSrv, $rootScope, arrayOrderingSrv) {
28+
var vm = this;
29+
vm.notes = notebookListDataFactory;
30+
vm.websocketMsgSrv = websocketMsgSrv;
31+
vm.arrayOrderingSrv = arrayOrderingSrv;
3532

36-
initHome();
33+
vm.notebookHome = false;
34+
if ($rootScope.ticket !== undefined) {
35+
vm.staticHome = false;
36+
} else {
37+
vm.staticHome = true;
38+
}
3739

38-
$scope.reloadNotebookList = function() {
39-
websocketMsgSrv.reloadAllNotesFromRepo();
40-
$scope.isReloadingNotes = true;
41-
};
40+
$scope.isReloading = false;
4241

43-
$scope.toggleFolderNode = function(node) {
44-
node.hidden = !node.hidden;
45-
};
42+
var initHome = function() {
43+
websocketMsgSrv.getHomeNotebook();
44+
};
4645

47-
angular.element('#loginModal').on('hidden.bs.modal', function(e) {
48-
$rootScope.$broadcast('initLoginValues');
49-
});
46+
initHome();
5047

51-
/*
52-
** $scope.$on functions below
53-
*/
48+
$scope.reloadNotebookList = function() {
49+
websocketMsgSrv.reloadAllNotesFromRepo();
50+
$scope.isReloadingNotes = true;
51+
};
5452

55-
$scope.$on('setNoteMenu', function(event, notes) {
56-
$scope.isReloadingNotes = false;
57-
});
53+
$scope.toggleFolderNode = function(node) {
54+
node.hidden = !node.hidden;
55+
};
5856

59-
$scope.$on('setNoteContent', function(event, note) {
60-
if (note) {
61-
vm.note = note;
57+
angular.element('#loginModal').on('hidden.bs.modal', function(e) {
58+
$rootScope.$broadcast('initLoginValues');
59+
});
6260

63-
// initialize look And Feel
64-
$rootScope.$broadcast('setLookAndFeel', 'home');
61+
/*
62+
** $scope.$on functions below
63+
*/
6564

66-
// make it read only
67-
vm.viewOnly = true;
65+
$scope.$on('setNoteMenu', function(event, notes) {
66+
$scope.isReloadingNotes = false;
67+
});
6868

69-
vm.notebookHome = true;
70-
vm.staticHome = false;
71-
} else {
72-
vm.staticHome = true;
73-
vm.notebookHome = false;
74-
}
75-
});
69+
$scope.$on('setNoteContent', function(event, note) {
70+
if (note) {
71+
vm.note = note;
72+
73+
// initialize look And Feel
74+
$rootScope.$broadcast('setLookAndFeel', 'home');
75+
76+
// make it read only
77+
vm.viewOnly = true;
78+
79+
vm.notebookHome = true;
80+
vm.staticHome = false;
81+
} else {
82+
vm.staticHome = true;
83+
vm.notebookHome = false;
84+
}
85+
});
86+
}
7687

77-
});
88+
})();

0 commit comments

Comments
 (0)