diff --git a/zeppelin-web/src/components/elasticInputCtrl/elasticInput.controller.js b/zeppelin-web/src/components/elasticInputCtrl/elasticInput.controller.js index ec19e93d90..48d4cb234e 100644 --- a/zeppelin-web/src/components/elasticInputCtrl/elasticInput.controller.js +++ b/zeppelin-web/src/components/elasticInputCtrl/elasticInput.controller.js @@ -12,9 +12,13 @@ * limitations under the License. */ 'use strict'; +(function() { -angular.module('zeppelinWebApp') -.controller('ElasticInputCtrl', function() { - var vm = this; - vm.showEditor = false; -}); + angular.module('zeppelinWebApp').controller('ElasticInputCtrl', ElasticInputCtrl); + + function ElasticInputCtrl() { + var vm = this; + vm.showEditor = false; + } + +})(); diff --git a/zeppelin-web/src/components/login/login.controller.js b/zeppelin-web/src/components/login/login.controller.js index e47ca506ee..c30110cf3c 100644 --- a/zeppelin-web/src/components/login/login.controller.js +++ b/zeppelin-web/src/components/login/login.controller.js @@ -11,11 +11,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - 'use strict'; +(function() { -angular.module('zeppelinWebApp').controller('LoginCtrl', - function($scope, $rootScope, $http, $httpParamSerializer, baseUrlSrv) { + angular.module('zeppelinWebApp').controller('LoginCtrl', LoginCtrl); + + LoginCtrl.$inject = ['$scope', '$rootScope', '$http', '$httpParamSerializer', 'baseUrlSrv']; + + function LoginCtrl($scope, $rootScope, $http, $httpParamSerializer, baseUrlSrv) { $scope.loginParams = {}; $scope.login = function() { @@ -55,4 +58,5 @@ angular.module('zeppelinWebApp').controller('LoginCtrl', initValues(); }); } -); + +})(); diff --git a/zeppelin-web/src/components/navbar/navbar.controller.js b/zeppelin-web/src/components/navbar/navbar.controller.js index 2007322b5e..7838a824e2 100644 --- a/zeppelin-web/src/components/navbar/navbar.controller.js +++ b/zeppelin-web/src/components/navbar/navbar.controller.js @@ -11,102 +11,117 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - 'use strict'; +(function() { -angular.module('zeppelinWebApp') -.controller('NavCtrl', function($scope, $rootScope, $http, $routeParams, - $location, notebookListDataFactory, baseUrlSrv, websocketMsgSrv, arrayOrderingSrv, searchService) { + angular.module('zeppelinWebApp').controller('NavCtrl', NavCtrl); - var vm = this; - vm.arrayOrderingSrv = arrayOrderingSrv; - vm.connected = websocketMsgSrv.isConnected(); - vm.isActive = isActive; - vm.logout = logout; - vm.notes = notebookListDataFactory; - vm.search = search; - vm.searchForm = searchService; - vm.showLoginWindow = showLoginWindow; + NavCtrl.$inject = [ + '$scope', + '$rootScope', + '$http', + '$routeParams', + '$location', + 'notebookListDataFactory', + 'baseUrlSrv', + 'websocketMsgSrv', + 'arrayOrderingSrv', + 'searchService' + ]; - $scope.query = {q: ''}; + function NavCtrl($scope, $rootScope, $http, $routeParams, $location, + notebookListDataFactory, baseUrlSrv, websocketMsgSrv, + arrayOrderingSrv, searchService) { + var vm = this; + vm.arrayOrderingSrv = arrayOrderingSrv; + vm.connected = websocketMsgSrv.isConnected(); + vm.isActive = isActive; + vm.logout = logout; + vm.notes = notebookListDataFactory; + vm.search = search; + vm.searchForm = searchService; + vm.showLoginWindow = showLoginWindow; - initController(); + $scope.query = {q: ''}; - function getZeppelinVersion() { - $http.get(baseUrlSrv.getRestApiBase() + '/version').success( - function(data, status, headers, config) { - $rootScope.zeppelinVersion = data.body; - }).error( - function(data, status, headers, config) { - console.log('Error %o %o', status, data.message); - }); - } + initController(); - function initController() { - angular.element('#notebook-list').perfectScrollbar({suppressScrollX: true}); - - angular.element(document).click(function() { - $scope.query.q = ''; - }); - - getZeppelinVersion(); - loadNotes(); - } - - function isActive(noteId) { - return ($routeParams.noteId === noteId); - } - - function loadNotes() { - websocketMsgSrv.getNotebookList(); - } - - function logout() { - var logoutURL = baseUrlSrv.getRestApiBase() + '/login/logout'; - - //for firefox and safari - logoutURL = logoutURL.replace('//', '//false:false@'); - $http.post(logoutURL).error(function() { - //force authcBasic (if configured) to logout - $http.post(logoutURL).error(function() { - $rootScope.userName = ''; - $rootScope.ticket.principal = ''; - $rootScope.ticket.ticket = ''; - $rootScope.ticket.roles = ''; - BootstrapDialog.show({ - message: 'Logout Success' + function getZeppelinVersion() { + $http.get(baseUrlSrv.getRestApiBase() + '/version').success( + function(data, status, headers, config) { + $rootScope.zeppelinVersion = data.body; + }).error( + function(data, status, headers, config) { + console.log('Error %o %o', status, data.message); }); - setTimeout(function() { - window.location.replace('/'); - }, 1000); + } + + function initController() { + angular.element('#notebook-list').perfectScrollbar({suppressScrollX: true}); + + angular.element(document).click(function() { + $scope.query.q = ''; }); + + getZeppelinVersion(); + loadNotes(); + } + + function isActive(noteId) { + return ($routeParams.noteId === noteId); + } + + function loadNotes() { + websocketMsgSrv.getNotebookList(); + } + + function logout() { + var logoutURL = baseUrlSrv.getRestApiBase() + '/login/logout'; + + //for firefox and safari + logoutURL = logoutURL.replace('//', '//false:false@'); + $http.post(logoutURL).error(function() { + //force authcBasic (if configured) to logout + $http.post(logoutURL).error(function() { + $rootScope.userName = ''; + $rootScope.ticket.principal = ''; + $rootScope.ticket.ticket = ''; + $rootScope.ticket.roles = ''; + BootstrapDialog.show({ + message: 'Logout Success' + }); + setTimeout(function() { + window.location.replace('/'); + }, 1000); + }); + }); + } + + function search(searchTerm) { + $location.path('/search/' + searchTerm); + } + + function showLoginWindow() { + setTimeout(function() { + angular.element('#userName').focus(); + }, 500); + } + + /* + ** $scope.$on functions below + */ + + $scope.$on('setNoteMenu', function(event, notes) { + notebookListDataFactory.setNotes(notes); + }); + + $scope.$on('setConnectedStatus', function(event, param) { + vm.connected = param; + }); + + $scope.$on('loginSuccess', function(event, param) { + loadNotes(); }); } - function search(searchTerm) { - $location.path('/search/' + searchTerm); - } - - function showLoginWindow() { - setTimeout(function() { - angular.element('#userName').focus(); - }, 500); - } - - /* - ** $scope.$on functions below - */ - - $scope.$on('setNoteMenu', function(event, notes) { - notebookListDataFactory.setNotes(notes); - }); - - $scope.$on('setConnectedStatus', function(event, param) { - vm.connected = param; - }); - - $scope.$on('loginSuccess', function(event, param) { - loadNotes(); - }); - -}); +})(); diff --git a/zeppelin-web/src/components/noteName-create/notename.controller.js b/zeppelin-web/src/components/noteName-create/notename.controller.js index e42f862661..5090a77e85 100644 --- a/zeppelin-web/src/components/noteName-create/notename.controller.js +++ b/zeppelin-web/src/components/noteName-create/notename.controller.js @@ -11,76 +11,85 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - 'use strict'; +(function() { -angular.module('zeppelinWebApp').controller('NotenameCtrl', function($scope, notebookListDataFactory, - $routeParams, websocketMsgSrv) { - var vm = this; - vm.clone = false; - vm.notes = notebookListDataFactory; - vm.websocketMsgSrv = websocketMsgSrv; - $scope.note = {}; + angular.module('zeppelinWebApp').controller('NotenameCtrl', NotenameCtrl); - vm.createNote = function() { - if (!vm.clone) { - vm.websocketMsgSrv.createNotebook($scope.note.notename); - } else { - var noteId = $routeParams.noteId; - vm.websocketMsgSrv.cloneNotebook(noteId, $scope.note.notename); - } - }; + NotenameCtrl.$inject = [ + '$scope', + 'notebookListDataFactory', + '$routeParams', + 'websocketMsgSrv' + ]; - vm.handleNameEnter = function() { - angular.element('#noteNameModal').modal('toggle'); - vm.createNote(); - }; + function NotenameCtrl($scope, notebookListDataFactory, $routeParams, websocketMsgSrv) { + var vm = this; + vm.clone = false; + vm.notes = notebookListDataFactory; + vm.websocketMsgSrv = websocketMsgSrv; + $scope.note = {}; - vm.preVisible = function(clone, sourceNoteName) { - vm.clone = clone; - vm.sourceNoteName = sourceNoteName; - $scope.note.notename = vm.clone ? vm.cloneNoteName() : vm.newNoteName(); - $scope.$apply(); - }; - - vm.newNoteName = function() { - var newCount = 1; - angular.forEach(vm.notes.flatList, function(noteName) { - noteName = noteName.name; - if (noteName.match(/^Untitled Note [0-9]*$/)) { - var lastCount = noteName.substr(14) * 1; - if (newCount <= lastCount) { - newCount = lastCount + 1; - } + vm.createNote = function() { + if (!vm.clone) { + vm.websocketMsgSrv.createNotebook($scope.note.notename); + } else { + var noteId = $routeParams.noteId; + vm.websocketMsgSrv.cloneNotebook(noteId, $scope.note.notename); } - }); - return 'Untitled Note ' + newCount; - }; + }; - vm.cloneNoteName = function() { - var copyCount = 1; - var newCloneName = ''; - var lastIndex = vm.sourceNoteName.lastIndexOf(' '); - var endsWithNumber = !!vm.sourceNoteName.match('^.+?\\s\\d$'); - var noteNamePrefix = endsWithNumber ? vm.sourceNoteName.substr(0, lastIndex) : vm.sourceNoteName; - var regexp = new RegExp('^' + noteNamePrefix + ' .+'); + vm.handleNameEnter = function() { + angular.element('#noteNameModal').modal('toggle'); + vm.createNote(); + }; - angular.forEach(vm.notes.flatList, function(noteName) { - noteName = noteName.name; - if (noteName.match(regexp)) { - var lastCopyCount = noteName.substr(lastIndex).trim(); - newCloneName = noteNamePrefix; - lastCopyCount = parseInt(lastCopyCount); - if (copyCount <= lastCopyCount) { - copyCount = lastCopyCount + 1; + vm.preVisible = function(clone, sourceNoteName) { + vm.clone = clone; + vm.sourceNoteName = sourceNoteName; + $scope.note.notename = vm.clone ? vm.cloneNoteName() : vm.newNoteName(); + $scope.$apply(); + }; + + vm.newNoteName = function() { + var newCount = 1; + angular.forEach(vm.notes.flatList, function(noteName) { + noteName = noteName.name; + if (noteName.match(/^Untitled Note [0-9]*$/)) { + var lastCount = noteName.substr(14) * 1; + if (newCount <= lastCount) { + newCount = lastCount + 1; + } } + }); + return 'Untitled Note ' + newCount; + }; + + vm.cloneNoteName = function() { + var copyCount = 1; + var newCloneName = ''; + var lastIndex = vm.sourceNoteName.lastIndexOf(' '); + var endsWithNumber = !!vm.sourceNoteName.match('^.+?\\s\\d$'); + var noteNamePrefix = endsWithNumber ? vm.sourceNoteName.substr(0, lastIndex) : vm.sourceNoteName; + var regexp = new RegExp('^' + noteNamePrefix + ' .+'); + + angular.forEach(vm.notes.flatList, function(noteName) { + noteName = noteName.name; + if (noteName.match(regexp)) { + var lastCopyCount = noteName.substr(lastIndex).trim(); + newCloneName = noteNamePrefix; + lastCopyCount = parseInt(lastCopyCount); + if (copyCount <= lastCopyCount) { + copyCount = lastCopyCount + 1; + } + } + }); + + if (!newCloneName) { + newCloneName = vm.sourceNoteName; } - }); + return newCloneName + ' ' + copyCount; + }; + } - if (!newCloneName) { - newCloneName = vm.sourceNoteName; - } - return newCloneName + ' ' + copyCount; - }; - -}); +})(); diff --git a/zeppelin-web/src/components/noteName-import/notenameImport.controller.js b/zeppelin-web/src/components/noteName-import/notenameImport.controller.js index 4c9aa32e6d..abcff43f7f 100644 --- a/zeppelin-web/src/components/noteName-import/notenameImport.controller.js +++ b/zeppelin-web/src/components/noteName-import/notenameImport.controller.js @@ -1,128 +1,133 @@ /* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ 'use strict'; +(function() { -angular.module('zeppelinWebApp').controller('NoteImportCtrl', function($scope, $timeout, websocketMsgSrv) { - var vm = this; - $scope.note = {}; - $scope.note.step1 = true; - $scope.note.step2 = false; - $scope.maxLimit = ''; - var limit = 0; + angular.module('zeppelinWebApp').controller('NoteImportCtrl', NoteImportCtrl); - websocketMsgSrv.listConfigurations(); - $scope.$on('configurationsInfo', function(scope, event) { - limit = event.configurations['zeppelin.websocket.max.text.message.size']; - $scope.maxLimit = Math.round(limit / 1048576); - }); + NoteImportCtrl.$inject = ['$scope', '$timeout', 'websocketMsgSrv']; - vm.resetFlags = function() { + function NoteImportCtrl($scope, $timeout, websocketMsgSrv) { + var vm = this; $scope.note = {}; $scope.note.step1 = true; $scope.note.step2 = false; - angular.element('#noteImportFile').val(''); - }; + $scope.maxLimit = ''; + var limit = 0; - $scope.uploadFile = function() { - angular.element('#noteImportFile').click(); - }; + websocketMsgSrv.listConfigurations(); + $scope.$on('configurationsInfo', function(scope, event) { + limit = event.configurations['zeppelin.websocket.max.text.message.size']; + $scope.maxLimit = Math.round(limit / 1048576); + }); - $scope.importFile = function(element) { - $scope.note.errorText = ''; - $scope.note.importFile = element.files[0]; - var file = $scope.note.importFile; - var reader = new FileReader(); - - if (file.size > limit) { - $scope.note.errorText = 'File size limit Exceeded!'; - $scope.$apply(); - return; - } - - reader.onloadend = function() { - vm.processImportJson(reader.result); + vm.resetFlags = function() { + $scope.note = {}; + $scope.note.step1 = true; + $scope.note.step2 = false; + angular.element('#noteImportFile').val(''); }; - if (file) { - reader.readAsText(file); - } - }; + $scope.uploadFile = function() { + angular.element('#noteImportFile').click(); + }; - $scope.uploadURL = function() { - $scope.note.errorText = ''; - $scope.note.step1 = false; - $timeout(function() { - $scope.note.step2 = true; - }, 400); - }; + $scope.importFile = function(element) { + $scope.note.errorText = ''; + $scope.note.importFile = element.files[0]; + var file = $scope.note.importFile; + var reader = new FileReader(); - vm.importBack = function() { - $scope.note.errorText = ''; - $timeout(function() { - $scope.note.step1 = true; - }, 400); - $scope.note.step2 = false; - }; - - vm.importNote = function() { - $scope.note.errorText = ''; - if ($scope.note.importUrl) { - jQuery.getJSON($scope.note.importUrl, function(result) { - vm.processImportJson(result); - }).fail(function() { - $scope.note.errorText = 'Unable to Fetch URL'; - $scope.$apply(); - }); - } else { - $scope.note.errorText = 'Enter URL'; - $scope.$apply(); - } - }; - - vm.processImportJson = function(result) { - if (typeof result !== 'object') { - try { - result = JSON.parse(result); - } catch (e) { - $scope.note.errorText = 'JSON parse exception'; + if (file.size > limit) { + $scope.note.errorText = 'File size limit Exceeded!'; $scope.$apply(); return; } - } - if (result.paragraphs && result.paragraphs.length > 0) { - if (!$scope.note.noteImportName) { - $scope.note.noteImportName = result.name; - } else { - result.name = $scope.note.noteImportName; + reader.onloadend = function() { + vm.processImportJson(reader.result); + }; + + if (file) { + reader.readAsText(file); } - websocketMsgSrv.importNotebook(result); - //angular.element('#noteImportModal').modal('hide'); - } else { - $scope.note.errorText = 'Invalid JSON'; - } - $scope.$apply(); - }; + }; - /* - ** $scope.$on functions below - */ + $scope.uploadURL = function() { + $scope.note.errorText = ''; + $scope.note.step1 = false; + $timeout(function() { + $scope.note.step2 = true; + }, 400); + }; - $scope.$on('setNoteMenu', function(event, notes) { - vm.resetFlags(); - angular.element('#noteImportModal').modal('hide'); - }); + vm.importBack = function() { + $scope.note.errorText = ''; + $timeout(function() { + $scope.note.step1 = true; + }, 400); + $scope.note.step2 = false; + }; -}); + vm.importNote = function() { + $scope.note.errorText = ''; + if ($scope.note.importUrl) { + jQuery.getJSON($scope.note.importUrl, function(result) { + vm.processImportJson(result); + }).fail(function() { + $scope.note.errorText = 'Unable to Fetch URL'; + $scope.$apply(); + }); + } else { + $scope.note.errorText = 'Enter URL'; + $scope.$apply(); + } + }; + + vm.processImportJson = function(result) { + if (typeof result !== 'object') { + try { + result = JSON.parse(result); + } catch (e) { + $scope.note.errorText = 'JSON parse exception'; + $scope.$apply(); + return; + } + + } + if (result.paragraphs && result.paragraphs.length > 0) { + if (!$scope.note.noteImportName) { + $scope.note.noteImportName = result.name; + } else { + result.name = $scope.note.noteImportName; + } + websocketMsgSrv.importNotebook(result); + //angular.element('#noteImportModal').modal('hide'); + } else { + $scope.note.errorText = 'Invalid JSON'; + } + $scope.$apply(); + }; + + /* + ** $scope.$on functions below + */ + + $scope.$on('setNoteMenu', function(event, notes) { + vm.resetFlags(); + angular.element('#noteImportModal').modal('hide'); + }); + } + +})();