You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by co...@apache.org on 2016/08/09 12:03:10 UTC
zeppelin git commit: [ZEPPELIN-1290] Refactor Navbar Controller
Repository: zeppelin
Updated Branches:
refs/heads/master 7e491f8da -> 3a1ab28df
[ZEPPELIN-1290] Refactor Navbar Controller
### What is this PR for?
This is a small refactoring to keep this Controller following the [ControllerAs with vm](https://github.com/johnpapa/angular-styleguide/tree/master/a1#controlleras-with-vm)
rules, that it was based on.
Here is a list of things that were changed and why:
* Most of the controller's $scope values & fct (except from the search q) where moved to the vm.The controller is using vm, so storing in $scope to share with the view is not needed.
* Functions or Vars that are not used in the view were removed from the vm. (kept private to the controller)
* $rootscope functions was moved to `app.js`. I think the need for that function might need to be changed, but for the scope of this PR, we are just moving it to where the $rootScope values are declared.
* Gathering vm declaration before the functions and ordered alphabetically
* Re-order functions alphabetically
* Create `initController ` to regroup all the controller setup.
### What type of PR is it?
Refactoring
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1290
### How should this be tested?
You can Just verify that the below Navbar related features are still good:
* Search Form
* Connected Status
* Login button
* User Name and its dropdown menu
* Notebook list drop-down menu (and filer, folder inside of it)
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: Damien CORNEAU <co...@gmail.com>
Author: CORNEAU Damien <co...@gmail.com>
Author: Prabhjyot Singh <pr...@gmail.com>
Closes #1281 from corneadoug/Refactor/navbarCtrl and squashes the following commits:
31f9110 [CORNEAU Damien] Merge pull request #4 from prabhjyotsingh/logoutUserFix
4686a18 [Prabhjyot Singh] CI failure for testGroupPermission
2fde749 [Damien CORNEAU] finish cleaning the controller
be18547 [Damien CORNEAU] Remove functions from navbar controller
Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/3a1ab28d
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/3a1ab28d
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/3a1ab28d
Branch: refs/heads/master
Commit: 3a1ab28df7befdac5a2331c35e0fd817f8c9d313
Parents: 7e491f8
Author: Damien CORNEAU <co...@gmail.com>
Authored: Mon Aug 8 19:35:25 2016 +0900
Committer: Damien CORNEAU <co...@gmail.com>
Committed: Tue Aug 9 21:02:59 2016 +0900
----------------------------------------------------------------------
.../zeppelin/integration/AuthenticationIT.java | 2 +-
zeppelin-web/src/app/app.controller.js | 8 +-
.../src/components/navbar/navbar.controller.js | 91 ++++++++++----------
zeppelin-web/src/components/navbar/navbar.html | 12 +--
4 files changed, 58 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3a1ab28d/zeppelin-server/src/test/java/org/apache/zeppelin/integration/AuthenticationIT.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/integration/AuthenticationIT.java b/zeppelin-server/src/test/java/org/apache/zeppelin/integration/AuthenticationIT.java
index ea810cb..ea3f363 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/integration/AuthenticationIT.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/integration/AuthenticationIT.java
@@ -124,7 +124,7 @@ public class AuthenticationIT extends AbstractZeppelinIT {
userName + "')]")).click();
ZeppelinITUtils.sleep(500, false);
driver.findElement(By.xpath("//div[contains(@class, 'navbar-collapse')]//li[contains(.,'" +
- userName + "')]//a[@ng-click='logout()']")).click();
+ userName + "')]//a[@ng-click='navbar.logout()']")).click();
ZeppelinITUtils.sleep(5000, false);
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3a1ab28d/zeppelin-web/src/app/app.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/app.controller.js b/zeppelin-web/src/app/app.controller.js
index 8a0466b..ff30b82 100644
--- a/zeppelin-web/src/app/app.controller.js
+++ b/zeppelin-web/src/app/app.controller.js
@@ -13,7 +13,7 @@
*/
'use strict';
-angular.module('zeppelinWebApp').controller('MainCtrl', function($scope, $rootScope, $window) {
+angular.module('zeppelinWebApp').controller('MainCtrl', function($scope, $rootScope, $window, arrayOrderingSrv) {
$scope.looknfeel = 'default';
var init = function() {
@@ -41,6 +41,12 @@ angular.module('zeppelinWebApp').controller('MainCtrl', function($scope, $rootSc
$rootScope.$broadcast('setLookAndFeel', 'default');
});
+ $rootScope.noteName = function(note) {
+ if (!_.isEmpty(note)) {
+ return arrayOrderingSrv.getNoteName(note);
+ }
+ };
+
BootstrapDialog.defaultOptions.onshown = function() {
angular.element('#' + this.id).find('.btn:last').focus();
};
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3a1ab28d/zeppelin-web/src/components/navbar/navbar.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/components/navbar/navbar.controller.js b/zeppelin-web/src/components/navbar/navbar.controller.js
index c8da491..2007322 100644
--- a/zeppelin-web/src/components/navbar/navbar.controller.js
+++ b/zeppelin-web/src/components/navbar/navbar.controller.js
@@ -18,29 +18,50 @@ angular.module('zeppelinWebApp')
.controller('NavCtrl', function($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;
+
$scope.query = {q: ''};
- /** Current list of notes (ids) */
- $scope.showLoginWindow = function() {
- setTimeout(function() {
- angular.element('#userName').focus();
- }, 500);
- };
+ initController();
- var vm = this;
- vm.notes = notebookListDataFactory;
- vm.connected = websocketMsgSrv.isConnected();
- vm.websocketMsgSrv = websocketMsgSrv;
- vm.arrayOrderingSrv = arrayOrderingSrv;
- $scope.searchForm = searchService;
+ 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);
+ });
+ }
- angular.element('#notebook-list').perfectScrollbar({suppressScrollX: true});
+ function initController() {
+ angular.element('#notebook-list').perfectScrollbar({suppressScrollX: true});
- angular.element(document).click(function() {
- $scope.query.q = '';
- });
+ angular.element(document).click(function() {
+ $scope.query.q = '';
+ });
+
+ getZeppelinVersion();
+ loadNotes();
+ }
+
+ function isActive(noteId) {
+ return ($routeParams.noteId === noteId);
+ }
+
+ function loadNotes() {
+ websocketMsgSrv.getNotebookList();
+ }
- $scope.logout = function() {
+ function logout() {
var logoutURL = baseUrlSrv.getRestApiBase() + '/login/logout';
//for firefox and safari
@@ -60,42 +81,18 @@ angular.module('zeppelinWebApp')
}, 1000);
});
});
- };
-
- $scope.search = function(searchTerm) {
- $location.path('/search/' + searchTerm);
- };
-
- function loadNotes() {
- websocketMsgSrv.getNotebookList();
}
- function isActive(noteId) {
- return ($routeParams.noteId === noteId);
+ function search(searchTerm) {
+ $location.path('/search/' + searchTerm);
}
- $rootScope.noteName = function(note) {
- if (!_.isEmpty(note)) {
- return arrayOrderingSrv.getNoteName(note);
- }
- };
-
- 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);
- });
+ function showLoginWindow() {
+ setTimeout(function() {
+ angular.element('#userName').focus();
+ }, 500);
}
- vm.loadNotes = loadNotes;
- vm.isActive = isActive;
-
- getZeppelinVersion();
- vm.loadNotes();
-
/*
** $scope.$on functions below
*/
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3a1ab28d/zeppelin-web/src/components/navbar/navbar.html
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/components/navbar/navbar.html b/zeppelin-web/src/components/navbar/navbar.html
index 6b9e786..109e328 100644
--- a/zeppelin-web/src/components/navbar/navbar.html
+++ b/zeppelin-web/src/components/navbar/navbar.html
@@ -45,15 +45,15 @@ limitations under the License.
<li class="nav-component" ng-if="ticket">
<!--TODO(bzz): move to Typeahead https://angular-ui.github.io/bootstrap -->
- <form role="search" data-ng-model="searchForm"
+ <form role="search" data-ng-model="navbar.searchForm"
style="display: inline-block; margin: 0px"
class="navbar-form"
- ng-submit="search(searchForm.searchTerm)">
+ ng-submit="navbar.search(navbar.searchForm.searchTerm)">
<div class="input-group">
<input
type="text"
style="min-width:200px;"
- ng-model="searchForm.searchTerm"
+ ng-model="navbar.searchForm.searchTerm"
id="searchTermId"
ng-disabled="!navbar.connected"
class="form-control"
@@ -63,7 +63,7 @@ limitations under the License.
<button
type="submit"
class="btn btn-default"
- ng-disabled="!navbar.connected || !searchForm.searchTerm"
+ ng-disabled="!navbar.connected || !navbar.searchForm.searchTerm"
>
<i class="glyphicon glyphicon-search"></i>
</button>
@@ -89,13 +89,13 @@ limitations under the License.
<li><a href="#/credential">Credential</a></li>
<li><a href="#/configuration">Configuration</a></li>
<li ng-if="ticket.principal && ticket.principal !== 'anonymous'" role="separator" style="margin: 5px 0;" class="divider"></li>
- <li ng-if="ticket.principal && ticket.principal !== 'anonymous'"><a ng-click="logout()">Logout</a></li>
+ <li ng-if="ticket.principal && ticket.principal !== 'anonymous'"><a ng-click="navbar.logout()">Logout</a></li>
</ul>
</div>
</li>
<li class="nav-component" ng-if="!ticket">
<button class="btn nav-login-btn" data-toggle="modal" data-target="#loginModal"
- ng-click="showLoginWindow()">Login
+ ng-click="navbar.showLoginWindow()">Login
</button>
</li>
</ul>