Skip to content

Commit 966cb27

Browse files
committed
refactor components controllers
1 parent 1807cf6 commit 966cb27

File tree

5 files changed

+299
-262
lines changed

5 files changed

+299
-262
lines changed

zeppelin-web/src/components/elasticInputCtrl/elasticInput.controller.js

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

16-
angular.module('zeppelinWebApp')
17-
.controller('ElasticInputCtrl', function() {
18-
var vm = this;
19-
vm.showEditor = false;
20-
});
17+
angular.module('zeppelinWebApp').controller('ElasticInputCtrl', ElasticInputCtrl);
18+
19+
function ElasticInputCtrl() {
20+
var vm = this;
21+
vm.showEditor = false;
22+
}
23+
24+
})();

zeppelin-web/src/components/login/login.controller.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
1514
'use strict';
15+
(function() {
16+
17+
angular.module('zeppelinWebApp').controller('LoginCtrl', LoginCtrl);
1618

17-
angular.module('zeppelinWebApp').controller('LoginCtrl',
18-
function($scope, $rootScope, $http, $httpParamSerializer, baseUrlSrv) {
19+
LoginCtrl.$inject = ['$scope', '$rootScope', '$http', '$httpParamSerializer', 'baseUrlSrv'];
20+
21+
function LoginCtrl($scope, $rootScope, $http, $httpParamSerializer, baseUrlSrv) {
1922
$scope.loginParams = {};
2023
$scope.login = function() {
2124

@@ -55,4 +58,5 @@ angular.module('zeppelinWebApp').controller('LoginCtrl',
5558
initValues();
5659
});
5760
}
58-
);
61+
62+
})();

zeppelin-web/src/components/navbar/navbar.controller.js

Lines changed: 96 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -11,102 +11,117 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
1514
'use strict';
15+
(function() {
16+
17+
angular.module('zeppelinWebApp').controller('NavCtrl', NavCtrl);
18+
19+
NavCtrl.$inject = [
20+
'$scope',
21+
'$rootScope',
22+
'$http',
23+
'$routeParams',
24+
'$location',
25+
'notebookListDataFactory',
26+
'baseUrlSrv',
27+
'websocketMsgSrv',
28+
'arrayOrderingSrv',
29+
'searchService'
30+
];
31+
32+
function NavCtrl($scope, $rootScope, $http, $routeParams, $location,
33+
notebookListDataFactory, baseUrlSrv, websocketMsgSrv,
34+
arrayOrderingSrv, searchService) {
35+
var vm = this;
36+
vm.arrayOrderingSrv = arrayOrderingSrv;
37+
vm.connected = websocketMsgSrv.isConnected();
38+
vm.isActive = isActive;
39+
vm.logout = logout;
40+
vm.notes = notebookListDataFactory;
41+
vm.search = search;
42+
vm.searchForm = searchService;
43+
vm.showLoginWindow = showLoginWindow;
44+
45+
$scope.query = {q: ''};
46+
47+
initController();
48+
49+
function getZeppelinVersion() {
50+
$http.get(baseUrlSrv.getRestApiBase() + '/version').success(
51+
function(data, status, headers, config) {
52+
$rootScope.zeppelinVersion = data.body;
53+
}).error(
54+
function(data, status, headers, config) {
55+
console.log('Error %o %o', status, data.message);
56+
});
57+
}
1658

17-
angular.module('zeppelinWebApp')
18-
.controller('NavCtrl', function($scope, $rootScope, $http, $routeParams,
19-
$location, notebookListDataFactory, baseUrlSrv, websocketMsgSrv, arrayOrderingSrv, searchService) {
20-
21-
var vm = this;
22-
vm.arrayOrderingSrv = arrayOrderingSrv;
23-
vm.connected = websocketMsgSrv.isConnected();
24-
vm.isActive = isActive;
25-
vm.logout = logout;
26-
vm.notes = notebookListDataFactory;
27-
vm.search = search;
28-
vm.searchForm = searchService;
29-
vm.showLoginWindow = showLoginWindow;
30-
31-
$scope.query = {q: ''};
32-
33-
initController();
34-
35-
function getZeppelinVersion() {
36-
$http.get(baseUrlSrv.getRestApiBase() + '/version').success(
37-
function(data, status, headers, config) {
38-
$rootScope.zeppelinVersion = data.body;
39-
}).error(
40-
function(data, status, headers, config) {
41-
console.log('Error %o %o', status, data.message);
42-
});
43-
}
44-
45-
function initController() {
46-
angular.element('#notebook-list').perfectScrollbar({suppressScrollX: true});
59+
function initController() {
60+
angular.element('#notebook-list').perfectScrollbar({suppressScrollX: true});
4761

48-
angular.element(document).click(function() {
49-
$scope.query.q = '';
50-
});
62+
angular.element(document).click(function() {
63+
$scope.query.q = '';
64+
});
5165

52-
getZeppelinVersion();
53-
loadNotes();
54-
}
66+
getZeppelinVersion();
67+
loadNotes();
68+
}
5569

56-
function isActive(noteId) {
57-
return ($routeParams.noteId === noteId);
58-
}
70+
function isActive(noteId) {
71+
return ($routeParams.noteId === noteId);
72+
}
5973

60-
function loadNotes() {
61-
websocketMsgSrv.getNotebookList();
62-
}
74+
function loadNotes() {
75+
websocketMsgSrv.getNotebookList();
76+
}
6377

64-
function logout() {
65-
var logoutURL = baseUrlSrv.getRestApiBase() + '/login/logout';
78+
function logout() {
79+
var logoutURL = baseUrlSrv.getRestApiBase() + '/login/logout';
6680

67-
//for firefox and safari
68-
logoutURL = logoutURL.replace('//', '//false:false@');
69-
$http.post(logoutURL).error(function() {
70-
//force authcBasic (if configured) to logout
81+
//for firefox and safari
82+
logoutURL = logoutURL.replace('//', '//false:false@');
7183
$http.post(logoutURL).error(function() {
72-
$rootScope.userName = '';
73-
$rootScope.ticket.principal = '';
74-
$rootScope.ticket.ticket = '';
75-
$rootScope.ticket.roles = '';
76-
BootstrapDialog.show({
77-
message: 'Logout Success'
84+
//force authcBasic (if configured) to logout
85+
$http.post(logoutURL).error(function() {
86+
$rootScope.userName = '';
87+
$rootScope.ticket.principal = '';
88+
$rootScope.ticket.ticket = '';
89+
$rootScope.ticket.roles = '';
90+
BootstrapDialog.show({
91+
message: 'Logout Success'
92+
});
93+
setTimeout(function() {
94+
window.location.replace('/');
95+
}, 1000);
7896
});
79-
setTimeout(function() {
80-
window.location.replace('/');
81-
}, 1000);
8297
});
83-
});
84-
}
98+
}
8599

86-
function search(searchTerm) {
87-
$location.path('/search/' + searchTerm);
88-
}
100+
function search(searchTerm) {
101+
$location.path('/search/' + searchTerm);
102+
}
89103

90-
function showLoginWindow() {
91-
setTimeout(function() {
92-
angular.element('#userName').focus();
93-
}, 500);
94-
}
104+
function showLoginWindow() {
105+
setTimeout(function() {
106+
angular.element('#userName').focus();
107+
}, 500);
108+
}
95109

96-
/*
97-
** $scope.$on functions below
98-
*/
110+
/*
111+
** $scope.$on functions below
112+
*/
99113

100-
$scope.$on('setNoteMenu', function(event, notes) {
101-
notebookListDataFactory.setNotes(notes);
102-
});
114+
$scope.$on('setNoteMenu', function(event, notes) {
115+
notebookListDataFactory.setNotes(notes);
116+
});
103117

104-
$scope.$on('setConnectedStatus', function(event, param) {
105-
vm.connected = param;
106-
});
118+
$scope.$on('setConnectedStatus', function(event, param) {
119+
vm.connected = param;
120+
});
107121

108-
$scope.$on('loginSuccess', function(event, param) {
109-
loadNotes();
110-
});
122+
$scope.$on('loginSuccess', function(event, param) {
123+
loadNotes();
124+
});
125+
}
111126

112-
});
127+
})();

zeppelin-web/src/components/noteName-create/notename.controller.js

Lines changed: 70 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,76 +11,85 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
1514
'use strict';
15+
(function() {
16+
17+
angular.module('zeppelinWebApp').controller('NotenameCtrl', NotenameCtrl);
1618

17-
angular.module('zeppelinWebApp').controller('NotenameCtrl', function($scope, notebookListDataFactory,
18-
$routeParams, websocketMsgSrv) {
19-
var vm = this;
20-
vm.clone = false;
21-
vm.notes = notebookListDataFactory;
22-
vm.websocketMsgSrv = websocketMsgSrv;
23-
$scope.note = {};
19+
NotenameCtrl.$inject = [
20+
'$scope',
21+
'notebookListDataFactory',
22+
'$routeParams',
23+
'websocketMsgSrv'
24+
];
2425

25-
vm.createNote = function() {
26-
if (!vm.clone) {
27-
vm.websocketMsgSrv.createNotebook($scope.note.notename);
28-
} else {
29-
var noteId = $routeParams.noteId;
30-
vm.websocketMsgSrv.cloneNotebook(noteId, $scope.note.notename);
31-
}
32-
};
26+
function NotenameCtrl($scope, notebookListDataFactory, $routeParams, websocketMsgSrv) {
27+
var vm = this;
28+
vm.clone = false;
29+
vm.notes = notebookListDataFactory;
30+
vm.websocketMsgSrv = websocketMsgSrv;
31+
$scope.note = {};
32+
33+
vm.createNote = function() {
34+
if (!vm.clone) {
35+
vm.websocketMsgSrv.createNotebook($scope.note.notename);
36+
} else {
37+
var noteId = $routeParams.noteId;
38+
vm.websocketMsgSrv.cloneNotebook(noteId, $scope.note.notename);
39+
}
40+
};
3341

34-
vm.handleNameEnter = function() {
35-
angular.element('#noteNameModal').modal('toggle');
36-
vm.createNote();
37-
};
42+
vm.handleNameEnter = function() {
43+
angular.element('#noteNameModal').modal('toggle');
44+
vm.createNote();
45+
};
3846

39-
vm.preVisible = function(clone, sourceNoteName) {
40-
vm.clone = clone;
41-
vm.sourceNoteName = sourceNoteName;
42-
$scope.note.notename = vm.clone ? vm.cloneNoteName() : vm.newNoteName();
43-
$scope.$apply();
44-
};
47+
vm.preVisible = function(clone, sourceNoteName) {
48+
vm.clone = clone;
49+
vm.sourceNoteName = sourceNoteName;
50+
$scope.note.notename = vm.clone ? vm.cloneNoteName() : vm.newNoteName();
51+
$scope.$apply();
52+
};
4553

46-
vm.newNoteName = function() {
47-
var newCount = 1;
48-
angular.forEach(vm.notes.flatList, function(noteName) {
49-
noteName = noteName.name;
50-
if (noteName.match(/^Untitled Note [0-9]*$/)) {
51-
var lastCount = noteName.substr(14) * 1;
52-
if (newCount <= lastCount) {
53-
newCount = lastCount + 1;
54+
vm.newNoteName = function() {
55+
var newCount = 1;
56+
angular.forEach(vm.notes.flatList, function(noteName) {
57+
noteName = noteName.name;
58+
if (noteName.match(/^Untitled Note [0-9]*$/)) {
59+
var lastCount = noteName.substr(14) * 1;
60+
if (newCount <= lastCount) {
61+
newCount = lastCount + 1;
62+
}
5463
}
55-
}
56-
});
57-
return 'Untitled Note ' + newCount;
58-
};
64+
});
65+
return 'Untitled Note ' + newCount;
66+
};
5967

60-
vm.cloneNoteName = function() {
61-
var copyCount = 1;
62-
var newCloneName = '';
63-
var lastIndex = vm.sourceNoteName.lastIndexOf(' ');
64-
var endsWithNumber = !!vm.sourceNoteName.match('^.+?\\s\\d$');
65-
var noteNamePrefix = endsWithNumber ? vm.sourceNoteName.substr(0, lastIndex) : vm.sourceNoteName;
66-
var regexp = new RegExp('^' + noteNamePrefix + ' .+');
68+
vm.cloneNoteName = function() {
69+
var copyCount = 1;
70+
var newCloneName = '';
71+
var lastIndex = vm.sourceNoteName.lastIndexOf(' ');
72+
var endsWithNumber = !!vm.sourceNoteName.match('^.+?\\s\\d$');
73+
var noteNamePrefix = endsWithNumber ? vm.sourceNoteName.substr(0, lastIndex) : vm.sourceNoteName;
74+
var regexp = new RegExp('^' + noteNamePrefix + ' .+');
6775

68-
angular.forEach(vm.notes.flatList, function(noteName) {
69-
noteName = noteName.name;
70-
if (noteName.match(regexp)) {
71-
var lastCopyCount = noteName.substr(lastIndex).trim();
72-
newCloneName = noteNamePrefix;
73-
lastCopyCount = parseInt(lastCopyCount);
74-
if (copyCount <= lastCopyCount) {
75-
copyCount = lastCopyCount + 1;
76+
angular.forEach(vm.notes.flatList, function(noteName) {
77+
noteName = noteName.name;
78+
if (noteName.match(regexp)) {
79+
var lastCopyCount = noteName.substr(lastIndex).trim();
80+
newCloneName = noteNamePrefix;
81+
lastCopyCount = parseInt(lastCopyCount);
82+
if (copyCount <= lastCopyCount) {
83+
copyCount = lastCopyCount + 1;
84+
}
7685
}
77-
}
78-
});
86+
});
7987

80-
if (!newCloneName) {
81-
newCloneName = vm.sourceNoteName;
82-
}
83-
return newCloneName + ' ' + copyCount;
84-
};
88+
if (!newCloneName) {
89+
newCloneName = vm.sourceNoteName;
90+
}
91+
return newCloneName + ' ' + copyCount;
92+
};
93+
}
8594

86-
});
95+
})();

0 commit comments

Comments
 (0)