You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2017/01/11 02:42:11 UTC

[5/6] zeppelin git commit: [ZEPPELIN-1927] Remove useless function wrapping in all js files

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/4c60b27c/zeppelin-web/src/app/jobmanager/jobmanager.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/jobmanager/jobmanager.controller.js b/zeppelin-web/src/app/jobmanager/jobmanager.controller.js
index 47e42fb..4c437da 100644
--- a/zeppelin-web/src/app/jobmanager/jobmanager.controller.js
+++ b/zeppelin-web/src/app/jobmanager/jobmanager.controller.js
@@ -11,167 +11,165 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-(function() {
 
-  angular.module('zeppelinWebApp')
-    .controller('JobmanagerCtrl', JobmanagerCtrl);
+angular.module('zeppelinWebApp')
+  .controller('JobmanagerCtrl', JobmanagerCtrl);
 
-  JobmanagerCtrl.$inject = ['$scope', 'websocketMsgSrv', '$interval', 'ngToast', '$q', '$timeout', 'jobManagerFilter'];
+JobmanagerCtrl.$inject = ['$scope', 'websocketMsgSrv', '$interval', 'ngToast', '$q', '$timeout', 'jobManagerFilter'];
 
-  function JobmanagerCtrl($scope, websocketMsgSrv, $interval, ngToast, $q, $timeout, jobManagerFilter) {
-    ngToast.dismiss();
-    var asyncNotebookJobFilter = function(jobInfomations, filterConfig) {
-      return $q(function(resolve, reject) {
-        $scope.JobInfomationsByFilter = $scope.jobTypeFilter(jobInfomations, filterConfig);
-        resolve($scope.JobInfomationsByFilter);
+function JobmanagerCtrl($scope, websocketMsgSrv, $interval, ngToast, $q, $timeout, jobManagerFilter) {
+  ngToast.dismiss();
+  var asyncNotebookJobFilter = function(jobInfomations, filterConfig) {
+    return $q(function(resolve, reject) {
+      $scope.JobInfomationsByFilter = $scope.jobTypeFilter(jobInfomations, filterConfig);
+      resolve($scope.JobInfomationsByFilter);
+    });
+  };
+
+  $scope.doFiltering = function(jobInfomations, filterConfig) {
+    asyncNotebookJobFilter(jobInfomations, filterConfig).then(
+      function() {
+        // success
+        $scope.isLoadingFilter = false;
+      },
+      function() {
+        // failed
       });
-    };
-
-    $scope.doFiltering = function(jobInfomations, filterConfig) {
-      asyncNotebookJobFilter(jobInfomations, filterConfig).then(
-        function() {
-          // success
-          $scope.isLoadingFilter = false;
-        },
-        function() {
-          // failed
-        });
-    };
-
-    $scope.filterValueToName = function(filterValue, maxStringLength) {
-      if ($scope.activeInterpreters === undefined) {
-        return;
+  };
+
+  $scope.filterValueToName = function(filterValue, maxStringLength) {
+    if ($scope.activeInterpreters === undefined) {
+      return;
+    }
+    var index = _.findIndex($scope.activeInterpreters, {value: filterValue});
+    if ($scope.activeInterpreters[index].name !== undefined) {
+      if (maxStringLength !== undefined && maxStringLength > $scope.activeInterpreters[index].name) {
+        return $scope.activeInterpreters[index].name.substr(0, maxStringLength - 3) + '...';
       }
-      var index = _.findIndex($scope.activeInterpreters, {value: filterValue});
-      if ($scope.activeInterpreters[index].name !== undefined) {
-        if (maxStringLength !== undefined && maxStringLength > $scope.activeInterpreters[index].name) {
-          return $scope.activeInterpreters[index].name.substr(0, maxStringLength - 3) + '...';
-        }
-        return $scope.activeInterpreters[index].name;
-      } else {
-        return 'Interpreter is not set';
-      }
-    };
-
-    $scope.setFilterValue = function(filterValue) {
-      $scope.filterConfig.filterValueInterpreter = filterValue;
-      $scope.doFiltering($scope.jobInfomations, $scope.filterConfig);
-    };
-
-    $scope.onChangeRunJobToAlwaysTopToggle = function() {
-      $scope.filterConfig.isRunningAlwaysTop = !$scope.filterConfig.isRunningAlwaysTop;
-      $scope.doFiltering($scope.jobInfomations, $scope.filterConfig);
-    };
-
-    $scope.onChangeSortAsc = function() {
-      $scope.filterConfig.isSortByAsc = !$scope.filterConfig.isSortByAsc;
-      $scope.doFiltering($scope.jobInfomations, $scope.filterConfig);
-    };
-
-    $scope.doFilterInputTyping = function(keyEvent, jobInfomations, filterConfig) {
-      var RETURN_KEY_CODE = 13;
-      $timeout.cancel($scope.dofilterTimeoutObject);
-      $scope.isActiveSearchTimer = true;
-      $scope.dofilterTimeoutObject = $timeout(function() {
-        $scope.doFiltering(jobInfomations, filterConfig);
-        $scope.isActiveSearchTimer = false;
-      }, 10000);
-      if (keyEvent.which === RETURN_KEY_CODE) {
-        $timeout.cancel($scope.dofilterTimeoutObject);
-        $scope.doFiltering(jobInfomations, filterConfig);
-        $scope.isActiveSearchTimer = false;
-      }
-    };
-
-    $scope.doForceFilterInputTyping = function(keyEvent, jobInfomations, filterConfig) {
+      return $scope.activeInterpreters[index].name;
+    } else {
+      return 'Interpreter is not set';
+    }
+  };
+
+  $scope.setFilterValue = function(filterValue) {
+    $scope.filterConfig.filterValueInterpreter = filterValue;
+    $scope.doFiltering($scope.jobInfomations, $scope.filterConfig);
+  };
+
+  $scope.onChangeRunJobToAlwaysTopToggle = function() {
+    $scope.filterConfig.isRunningAlwaysTop = !$scope.filterConfig.isRunningAlwaysTop;
+    $scope.doFiltering($scope.jobInfomations, $scope.filterConfig);
+  };
+
+  $scope.onChangeSortAsc = function() {
+    $scope.filterConfig.isSortByAsc = !$scope.filterConfig.isSortByAsc;
+    $scope.doFiltering($scope.jobInfomations, $scope.filterConfig);
+  };
+
+  $scope.doFilterInputTyping = function(keyEvent, jobInfomations, filterConfig) {
+    var RETURN_KEY_CODE = 13;
+    $timeout.cancel($scope.dofilterTimeoutObject);
+    $scope.isActiveSearchTimer = true;
+    $scope.dofilterTimeoutObject = $timeout(function() {
+      $scope.doFiltering(jobInfomations, filterConfig);
+      $scope.isActiveSearchTimer = false;
+    }, 10000);
+    if (keyEvent.which === RETURN_KEY_CODE) {
       $timeout.cancel($scope.dofilterTimeoutObject);
       $scope.doFiltering(jobInfomations, filterConfig);
       $scope.isActiveSearchTimer = false;
+    }
+  };
+
+  $scope.doForceFilterInputTyping = function(keyEvent, jobInfomations, filterConfig) {
+    $timeout.cancel($scope.dofilterTimeoutObject);
+    $scope.doFiltering(jobInfomations, filterConfig);
+    $scope.isActiveSearchTimer = false;
+  };
+
+  $scope.init = function() {
+    $scope.isLoadingFilter = true;
+    $scope.jobInfomations = [];
+    $scope.JobInfomationsByFilter = $scope.jobInfomations;
+    $scope.filterConfig = {
+      isRunningAlwaysTop: true,
+      filterValueNotebookName: '',
+      filterValueInterpreter: '*',
+      isSortByAsc: true
     };
+    $scope.jobTypeFilter = jobManagerFilter;
 
-    $scope.init = function() {
-      $scope.isLoadingFilter = true;
-      $scope.jobInfomations = [];
-      $scope.JobInfomationsByFilter = $scope.jobInfomations;
-      $scope.filterConfig = {
-        isRunningAlwaysTop: true,
-        filterValueNotebookName: '',
-        filterValueInterpreter: '*',
-        isSortByAsc: true
-      };
-      $scope.jobTypeFilter = jobManagerFilter;
-
-      websocketMsgSrv.getNoteJobsList();
-
-      $scope.$on('$destroy', function() {
-        websocketMsgSrv.unsubscribeJobManager();
-      });
-    };
+    websocketMsgSrv.getNoteJobsList();
 
-    /*
-     ** $scope.$on functions below
-     */
-
-    $scope.$on('setNoteJobs', function(event, responseData) {
-      $scope.lastJobServerUnixTime = responseData.lastResponseUnixTime;
-      $scope.jobInfomations = responseData.jobs;
-      $scope.jobInfomationsIndexs = $scope.jobInfomations ? _.indexBy($scope.jobInfomations, 'noteId') : {};
-      $scope.jobTypeFilter($scope.jobInfomations, $scope.filterConfig);
-      $scope.activeInterpreters = [
-        {
-          name: 'ALL',
-          value: '*'
-        }
-      ];
-      var interpreterLists = _.uniq(_.pluck($scope.jobInfomations, 'interpreter'), false);
-      for (var index = 0, length = interpreterLists.length; index < length; index++) {
-        $scope.activeInterpreters.push({
-          name: interpreterLists[index],
-          value: interpreterLists[index]
-        });
-      }
-      $scope.doFiltering($scope.jobInfomations, $scope.filterConfig);
+    $scope.$on('$destroy', function() {
+      websocketMsgSrv.unsubscribeJobManager();
     });
+  };
+
+  /*
+   ** $scope.$on functions below
+   */
+
+  $scope.$on('setNoteJobs', function(event, responseData) {
+    $scope.lastJobServerUnixTime = responseData.lastResponseUnixTime;
+    $scope.jobInfomations = responseData.jobs;
+    $scope.jobInfomationsIndexs = $scope.jobInfomations ? _.indexBy($scope.jobInfomations, 'noteId') : {};
+    $scope.jobTypeFilter($scope.jobInfomations, $scope.filterConfig);
+    $scope.activeInterpreters = [
+      {
+        name: 'ALL',
+        value: '*'
+      }
+    ];
+    var interpreterLists = _.uniq(_.pluck($scope.jobInfomations, 'interpreter'), false);
+    for (var index = 0, length = interpreterLists.length; index < length; index++) {
+      $scope.activeInterpreters.push({
+        name: interpreterLists[index],
+        value: interpreterLists[index]
+      });
+    }
+    $scope.doFiltering($scope.jobInfomations, $scope.filterConfig);
+  });
+
+  $scope.$on('setUpdateNoteJobs', function(event, responseData) {
+    var jobInfomations = $scope.jobInfomations;
+    var indexStore = $scope.jobInfomationsIndexs;
+    $scope.lastJobServerUnixTime = responseData.lastResponseUnixTime;
+    var notes = responseData.jobs;
+    notes.map(function(changedItem) {
+      if (indexStore[changedItem.noteId] === undefined) {
+        var newItem = angular.copy(changedItem);
+        jobInfomations.push(newItem);
+        indexStore[changedItem.noteId] = newItem;
+      } else {
+        var changeOriginTarget = indexStore[changedItem.noteId];
 
-    $scope.$on('setUpdateNoteJobs', function(event, responseData) {
-      var jobInfomations = $scope.jobInfomations;
-      var indexStore = $scope.jobInfomationsIndexs;
-      $scope.lastJobServerUnixTime = responseData.lastResponseUnixTime;
-      var notes = responseData.jobs;
-      notes.map(function(changedItem) {
-        if (indexStore[changedItem.noteId] === undefined) {
-          var newItem = angular.copy(changedItem);
-          jobInfomations.push(newItem);
-          indexStore[changedItem.noteId] = newItem;
-        } else {
-          var changeOriginTarget = indexStore[changedItem.noteId];
-
-          if (changedItem.isRemoved !== undefined && changedItem.isRemoved === true) {
-
-            // remove Item.
-            var removeIndex = _.findIndex(indexStore, changedItem.noteId);
-            if (removeIndex > -1) {
-              indexStore.splice(removeIndex, 1);
-            }
-
-            removeIndex = _.findIndex(jobInfomations, {'noteId': changedItem.noteId});
-            if (removeIndex) {
-              jobInfomations.splice(removeIndex, 1);
-            }
-
-          } else {
-            // change value for item.
-            changeOriginTarget.isRunningJob = changedItem.isRunningJob;
-            changeOriginTarget.noteName = changedItem.noteName;
-            changeOriginTarget.noteType = changedItem.noteType;
-            changeOriginTarget.interpreter = changedItem.interpreter;
-            changeOriginTarget.unixTimeLastRun = changedItem.unixTimeLastRun;
-            changeOriginTarget.paragraphs = changedItem.paragraphs;
+        if (changedItem.isRemoved !== undefined && changedItem.isRemoved === true) {
+
+          // remove Item.
+          var removeIndex = _.findIndex(indexStore, changedItem.noteId);
+          if (removeIndex > -1) {
+            indexStore.splice(removeIndex, 1);
+          }
+
+          removeIndex = _.findIndex(jobInfomations, {'noteId': changedItem.noteId});
+          if (removeIndex) {
+            jobInfomations.splice(removeIndex, 1);
           }
+
+        } else {
+          // change value for item.
+          changeOriginTarget.isRunningJob = changedItem.isRunningJob;
+          changeOriginTarget.noteName = changedItem.noteName;
+          changeOriginTarget.noteType = changedItem.noteType;
+          changeOriginTarget.interpreter = changedItem.interpreter;
+          changeOriginTarget.unixTimeLastRun = changedItem.unixTimeLastRun;
+          changeOriginTarget.paragraphs = changedItem.paragraphs;
         }
-      });
-      $scope.doFiltering(jobInfomations, $scope.filterConfig);
+      }
     });
-  }
+    $scope.doFiltering(jobInfomations, $scope.filterConfig);
+  });
+}
 
-})();

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/4c60b27c/zeppelin-web/src/app/jobmanager/jobmanager.filter.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/jobmanager/jobmanager.filter.js b/zeppelin-web/src/app/jobmanager/jobmanager.filter.js
index baf3c5d..62e85fd 100644
--- a/zeppelin-web/src/app/jobmanager/jobmanager.filter.js
+++ b/zeppelin-web/src/app/jobmanager/jobmanager.filter.js
@@ -11,35 +11,33 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-(function() {
 
-  angular.module('zeppelinWebApp').filter('jobManager', jobManagerFilter);
+angular.module('zeppelinWebApp').filter('jobManager', jobManagerFilter);
 
-  function jobManagerFilter() {
-    function filterContext(jobItems, filterConfig) {
-      var filterValueInterpreter = filterConfig.filterValueInterpreter;
-      var filterValueNotebookName = filterConfig.filterValueNotebookName;
-      var filterItems = jobItems;
+function jobManagerFilter() {
+  function filterContext(jobItems, filterConfig) {
+    var filterValueInterpreter = filterConfig.filterValueInterpreter;
+    var filterValueNotebookName = filterConfig.filterValueNotebookName;
+    var filterItems = jobItems;
 
-      if (filterValueInterpreter === undefined) {
-        filterItems = _.filter(filterItems, function(jobItem) {
-          return jobItem.interpreter === undefined ? true : false;
-        });
-      } else if (filterValueInterpreter !== '*') {
-        filterItems = _.where(filterItems, {interpreter: filterValueInterpreter});
-      }
-
-      if (filterValueNotebookName !== '') {
-        filterItems = _.filter(filterItems, function(jobItem) {
-          var lowerFilterValue = filterValueNotebookName.toLocaleLowerCase();
-          var lowerNotebookName = jobItem.noteName.toLocaleLowerCase();
-          return lowerNotebookName.match(new RegExp('.*' + lowerFilterValue + '.*'));
-        });
-      }
+    if (filterValueInterpreter === undefined) {
+      filterItems = _.filter(filterItems, function(jobItem) {
+        return jobItem.interpreter === undefined ? true : false;
+      });
+    } else if (filterValueInterpreter !== '*') {
+      filterItems = _.where(filterItems, {interpreter: filterValueInterpreter});
+    }
 
-      return filterItems;
+    if (filterValueNotebookName !== '') {
+      filterItems = _.filter(filterItems, function(jobItem) {
+        var lowerFilterValue = filterValueNotebookName.toLocaleLowerCase();
+        var lowerNotebookName = jobItem.noteName.toLocaleLowerCase();
+        return lowerNotebookName.match(new RegExp('.*' + lowerFilterValue + '.*'));
+      });
     }
-    return filterContext;
+
+    return filterItems;
   }
+  return filterContext;
+}
 
-})();

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/4c60b27c/zeppelin-web/src/app/jobmanager/jobs/job.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/jobmanager/jobs/job.controller.js b/zeppelin-web/src/app/jobmanager/jobs/job.controller.js
index c2155ab..8bf9d87 100644
--- a/zeppelin-web/src/app/jobmanager/jobs/job.controller.js
+++ b/zeppelin-web/src/app/jobmanager/jobs/job.controller.js
@@ -11,99 +11,97 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-(function() {
 
-  angular.module('zeppelinWebApp').controller('JobCtrl', JobCtrl);
+angular.module('zeppelinWebApp').controller('JobCtrl', JobCtrl);
 
-  JobCtrl.$inject = ['$scope', '$http', 'baseUrlSrv'];
+JobCtrl.$inject = ['$scope', '$http', 'baseUrlSrv'];
 
-  function JobCtrl($scope, $http, baseUrlSrv) {
-    $scope.init = function(jobInformation) {
-      $scope.progressValue = 0;
-    };
+function JobCtrl($scope, $http, baseUrlSrv) {
+  $scope.init = function(jobInformation) {
+    $scope.progressValue = 0;
+  };
 
-    $scope.getProgress = function() {
-      var statusList = _.pluck($scope.notebookJob.paragraphs, 'status');
-      var runningJob = _.countBy(statusList, function(status) {
-        if (status === 'FINISHED' || status === 'RUNNING') {
-          return 'matchCount';
-        } else {
-          return 'none';
-        }
-      });
-      var totalCount = statusList.length;
-      var runningJobCount = runningJob.matchCount;
-      var result = Math.ceil(runningJobCount / totalCount * 100);
-      return isNaN(result) ? 0 : result;
-    };
+  $scope.getProgress = function() {
+    var statusList = _.pluck($scope.notebookJob.paragraphs, 'status');
+    var runningJob = _.countBy(statusList, function(status) {
+      if (status === 'FINISHED' || status === 'RUNNING') {
+        return 'matchCount';
+      } else {
+        return 'none';
+      }
+    });
+    var totalCount = statusList.length;
+    var runningJobCount = runningJob.matchCount;
+    var result = Math.ceil(runningJobCount / totalCount * 100);
+    return isNaN(result) ? 0 : result;
+  };
 
-    $scope.runNotebookJob = function(notebookId) {
-      BootstrapDialog.confirm({
-        closable: true,
-        title: '',
-        message: 'Run all paragraphs?',
-        callback: function(result) {
-          if (result) {
-            $http({
-              method: 'POST',
-              url: baseUrlSrv.getRestApiBase() + '/notebook/job/' + notebookId,
-              headers: {
-                'Content-Type': 'application/x-www-form-urlencoded'
-              }
-            }).then(function successCallback(response) {
-              // success
-            }, function errorCallback(errorResponse) {
-              var errorText = 'SERVER ERROR';
-              if (!!errorResponse.data.message) {
-                errorText = errorResponse.data.message;
-              }
-              BootstrapDialog.alert({
-                closable: true,
-                title: 'Execution Failure',
-                message: errorText
-              });
+  $scope.runNotebookJob = function(notebookId) {
+    BootstrapDialog.confirm({
+      closable: true,
+      title: '',
+      message: 'Run all paragraphs?',
+      callback: function(result) {
+        if (result) {
+          $http({
+            method: 'POST',
+            url: baseUrlSrv.getRestApiBase() + '/notebook/job/' + notebookId,
+            headers: {
+              'Content-Type': 'application/x-www-form-urlencoded'
+            }
+          }).then(function successCallback(response) {
+            // success
+          }, function errorCallback(errorResponse) {
+            var errorText = 'SERVER ERROR';
+            if (!!errorResponse.data.message) {
+              errorText = errorResponse.data.message;
+            }
+            BootstrapDialog.alert({
+              closable: true,
+              title: 'Execution Failure',
+              message: errorText
             });
-          }
+          });
         }
-      });
-    };
+      }
+    });
+  };
 
-    $scope.stopNotebookJob = function(notebookId) {
-      BootstrapDialog.confirm({
-        closable: true,
-        title: '',
-        message: 'Stop all paragraphs?',
-        callback: function(result) {
-          if (result) {
-            $http({
-              method: 'DELETE',
-              url: baseUrlSrv.getRestApiBase() + '/notebook/job/' + notebookId,
-              headers: {
-                'Content-Type': 'application/x-www-form-urlencoded'
-              }
-            }).then(function successCallback(response) {
-              // success
-            }, function errorCallback(errorResponse) {
-              var errorText = 'SERVER ERROR';
-              if (!!errorResponse.data.message) {
+  $scope.stopNotebookJob = function(notebookId) {
+    BootstrapDialog.confirm({
+      closable: true,
+      title: '',
+      message: 'Stop all paragraphs?',
+      callback: function(result) {
+        if (result) {
+          $http({
+            method: 'DELETE',
+            url: baseUrlSrv.getRestApiBase() + '/notebook/job/' + notebookId,
+            headers: {
+              'Content-Type': 'application/x-www-form-urlencoded'
+            }
+          }).then(function successCallback(response) {
+            // success
+          }, function errorCallback(errorResponse) {
+            var errorText = 'SERVER ERROR';
+            if (!!errorResponse.data.message) {
 
-                errorText = errorResponse.data.message;
-              }
-              BootstrapDialog.alert({
-                closable: true,
-                title: 'Stop Failure',
-                message: errorText
-              });
+              errorText = errorResponse.data.message;
+            }
+            BootstrapDialog.alert({
+              closable: true,
+              title: 'Stop Failure',
+              message: errorText
             });
-          }
+          });
         }
-      });
-    };
+      }
+    });
+  };
 
-    $scope.lastExecuteTime = function(unixtime) {
-      return moment.unix(unixtime / 1000).fromNow();
-    };
+  $scope.lastExecuteTime = function(unixtime) {
+    return moment.unix(unixtime / 1000).fromNow();
+  };
 
-  }
+}
 
-})();

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/4c60b27c/zeppelin-web/src/app/notebook/notebook.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/notebook.controller.js b/zeppelin-web/src/app/notebook/notebook.controller.js
index b1b5447..248ef8a 100644
--- a/zeppelin-web/src/app/notebook/notebook.controller.js
+++ b/zeppelin-web/src/app/notebook/notebook.controller.js
@@ -11,1006 +11,1004 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-(function() {
-
-  angular.module('zeppelinWebApp').controller('NotebookCtrl', NotebookCtrl);
-
-  NotebookCtrl.$inject = [
-    '$scope',
-    '$route',
-    '$routeParams',
-    '$location',
-    '$rootScope',
-    '$http',
-    'websocketMsgSrv',
-    'baseUrlSrv',
-    '$timeout',
-    'saveAsService',
-    'ngToast',
-    'noteActionSrv',
-    'noteVarShareService',
-    'TRASH_FOLDER_ID'
+
+angular.module('zeppelinWebApp').controller('NotebookCtrl', NotebookCtrl);
+
+NotebookCtrl.$inject = [
+  '$scope',
+  '$route',
+  '$routeParams',
+  '$location',
+  '$rootScope',
+  '$http',
+  'websocketMsgSrv',
+  'baseUrlSrv',
+  '$timeout',
+  'saveAsService',
+  'ngToast',
+  'noteActionSrv',
+  'noteVarShareService',
+  'TRASH_FOLDER_ID'
+];
+
+function NotebookCtrl($scope, $route, $routeParams, $location, $rootScope,
+                      $http, websocketMsgSrv, baseUrlSrv, $timeout, saveAsService,
+                      ngToast, noteActionSrv, noteVarShareService, TRASH_FOLDER_ID) {
+
+  ngToast.dismiss();
+
+  $scope.note = null;
+  $scope.moment = moment;
+  $scope.editorToggled = false;
+  $scope.tableToggled = false;
+  $scope.viewOnly = false;
+  $scope.showSetting = false;
+  $scope.looknfeelOption = ['default', 'simple', 'report'];
+  $scope.cronOption = [
+    {name: 'None', value: undefined},
+    {name: '1m', value: '0 0/1 * * * ?'},
+    {name: '5m', value: '0 0/5 * * * ?'},
+    {name: '1h', value: '0 0 0/1 * * ?'},
+    {name: '3h', value: '0 0 0/3 * * ?'},
+    {name: '6h', value: '0 0 0/6 * * ?'},
+    {name: '12h', value: '0 0 0/12 * * ?'},
+    {name: '1d', value: '0 0 0 * * ?'}
   ];
 
-  function NotebookCtrl($scope, $route, $routeParams, $location, $rootScope,
-                        $http, websocketMsgSrv, baseUrlSrv, $timeout, saveAsService,
-                        ngToast, noteActionSrv, noteVarShareService, TRASH_FOLDER_ID) {
+  $scope.interpreterSettings = [];
+  $scope.interpreterBindings = [];
+  $scope.isNoteDirty = null;
+  $scope.saveTimer = null;
 
-    ngToast.dismiss();
+  var connectedOnce = false;
+  var isRevisionPath = function(path) {
+    var pattern = new RegExp('^.*\/notebook\/[a-zA-Z0-9_]*\/revision\/[a-zA-Z0-9_]*');
+    return pattern.test(path);
+  };
 
-    $scope.note = null;
-    $scope.moment = moment;
-    $scope.editorToggled = false;
-    $scope.tableToggled = false;
-    $scope.viewOnly = false;
-    $scope.showSetting = false;
-    $scope.looknfeelOption = ['default', 'simple', 'report'];
-    $scope.cronOption = [
-      {name: 'None', value: undefined},
-      {name: '1m', value: '0 0/1 * * * ?'},
-      {name: '5m', value: '0 0/5 * * * ?'},
-      {name: '1h', value: '0 0 0/1 * * ?'},
-      {name: '3h', value: '0 0 0/3 * * ?'},
-      {name: '6h', value: '0 0 0/6 * * ?'},
-      {name: '12h', value: '0 0 0/12 * * ?'},
-      {name: '1d', value: '0 0 0 * * ?'}
-    ];
-
-    $scope.interpreterSettings = [];
-    $scope.interpreterBindings = [];
-    $scope.isNoteDirty = null;
-    $scope.saveTimer = null;
-
-    var connectedOnce = false;
-    var isRevisionPath = function(path) {
-      var pattern = new RegExp('^.*\/notebook\/[a-zA-Z0-9_]*\/revision\/[a-zA-Z0-9_]*');
-      return pattern.test(path);
-    };
-
-    $scope.noteRevisions = [];
-    $scope.currentRevision = 'Head';
-    $scope.revisionView = isRevisionPath($location.path());
-
-    $scope.$on('setConnectedStatus', function(event, param) {
-      if (connectedOnce && param) {
-        initNotebook();
-      }
-      connectedOnce = true;
-    });
+  $scope.noteRevisions = [];
+  $scope.currentRevision = 'Head';
+  $scope.revisionView = isRevisionPath($location.path());
 
-    $scope.getCronOptionNameFromValue = function(value) {
-      if (!value) {
-        return '';
-      }
+  $scope.$on('setConnectedStatus', function(event, param) {
+    if (connectedOnce && param) {
+      initNotebook();
+    }
+    connectedOnce = true;
+  });
 
-      for (var o in $scope.cronOption) {
-        if ($scope.cronOption[o].value === value) {
-          return $scope.cronOption[o].name;
-        }
-      }
-      return value;
-    };
-
-    $scope.blockAnonUsers = function() {
-      var zeppelinVersion = $rootScope.zeppelinVersion;
-      var url = 'https://zeppelin.apache.org/docs/' + zeppelinVersion + '/security/notebook_authorization.html';
-      var content = 'Only authenticated user can set the permission.' +
-        '<a data-toggle="tooltip" data-placement="top" title="Learn more" target="_blank" href=' + url + '>' +
-        '<i class="icon-question" />' +
-        '</a>';
-      BootstrapDialog.show({
-        closable: false,
-        closeByBackdrop: false,
-        closeByKeyboard: false,
-        title: 'No permission',
-        message: content,
-        buttons: [{
-          label: 'Close',
-          action: function(dialog) {
-            dialog.close();
-          }
-        }]
-      });
-    };
+  $scope.getCronOptionNameFromValue = function(value) {
+    if (!value) {
+      return '';
+    }
 
-    /** Init the new controller */
-    var initNotebook = function() {
-      noteVarShareService.clear();
-      if ($routeParams.revisionId) {
-        websocketMsgSrv.getNoteByRevision($routeParams.noteId, $routeParams.revisionId);
-      } else {
-        websocketMsgSrv.getNote($routeParams.noteId);
+    for (var o in $scope.cronOption) {
+      if ($scope.cronOption[o].value === value) {
+        return $scope.cronOption[o].name;
       }
-      websocketMsgSrv.listRevisionHistory($routeParams.noteId);
-      var currentRoute = $route.current;
-      if (currentRoute) {
-        setTimeout(
-          function() {
-            var routeParams = currentRoute.params;
-            var $id = angular.element('#' + routeParams.paragraph + '_container');
-
-            if ($id.length > 0) {
-              // adjust for navbar
-              var top = $id.offset().top - 103;
-              angular.element('html, body').scrollTo({top: top, left: 0});
-            }
-          },
-          1000
-        );
-      }
-    };
-
-    initNotebook();
-
-    // force notebook reload on user change
-    $scope.$on('setNoteMenu', function(event, note) {
-      initNotebook();
+    }
+    return value;
+  };
+
+  $scope.blockAnonUsers = function() {
+    var zeppelinVersion = $rootScope.zeppelinVersion;
+    var url = 'https://zeppelin.apache.org/docs/' + zeppelinVersion + '/security/notebook_authorization.html';
+    var content = 'Only authenticated user can set the permission.' +
+      '<a data-toggle="tooltip" data-placement="top" title="Learn more" target="_blank" href=' + url + '>' +
+      '<i class="icon-question" />' +
+      '</a>';
+    BootstrapDialog.show({
+      closable: false,
+      closeByBackdrop: false,
+      closeByKeyboard: false,
+      title: 'No permission',
+      message: content,
+      buttons: [{
+        label: 'Close',
+        action: function(dialog) {
+          dialog.close();
+        }
+      }]
     });
+  };
+
+  /** Init the new controller */
+  var initNotebook = function() {
+    noteVarShareService.clear();
+    if ($routeParams.revisionId) {
+      websocketMsgSrv.getNoteByRevision($routeParams.noteId, $routeParams.revisionId);
+    } else {
+      websocketMsgSrv.getNote($routeParams.noteId);
+    }
+    websocketMsgSrv.listRevisionHistory($routeParams.noteId);
+    var currentRoute = $route.current;
+    if (currentRoute) {
+      setTimeout(
+        function() {
+          var routeParams = currentRoute.params;
+          var $id = angular.element('#' + routeParams.paragraph + '_container');
+
+          if ($id.length > 0) {
+            // adjust for navbar
+            var top = $id.offset().top - 103;
+            angular.element('html, body').scrollTo({top: top, left: 0});
+          }
+        },
+        1000
+      );
+    }
+  };
 
-    $scope.focusParagraphOnClick = function(clickEvent) {
-      if (!$scope.note) {
-        return;
-      }
-      for (var i = 0; i < $scope.note.paragraphs.length; i++) {
-        var paragraphId = $scope.note.paragraphs[i].id;
-        if (jQuery.contains(angular.element('#' + paragraphId + '_container')[0], clickEvent.target)) {
-          $scope.$broadcast('focusParagraph', paragraphId, 0, true);
-          break;
-        }
-      }
-    };
+  initNotebook();
 
-    // register mouseevent handler for focus paragraph
-    document.addEventListener('click', $scope.focusParagraphOnClick);
+  // force notebook reload on user change
+  $scope.$on('setNoteMenu', function(event, note) {
+    initNotebook();
+  });
 
-    $scope.keyboardShortcut = function(keyEvent) {
-      // handle keyevent
-      if (!$scope.viewOnly && !$scope.revisionView) {
-        $scope.$broadcast('keyEvent', keyEvent);
+  $scope.focusParagraphOnClick = function(clickEvent) {
+    if (!$scope.note) {
+      return;
+    }
+    for (var i = 0; i < $scope.note.paragraphs.length; i++) {
+      var paragraphId = $scope.note.paragraphs[i].id;
+      if (jQuery.contains(angular.element('#' + paragraphId + '_container')[0], clickEvent.target)) {
+        $scope.$broadcast('focusParagraph', paragraphId, 0, true);
+        break;
       }
-    };
-
-    // register mouseevent handler for focus paragraph
-    document.addEventListener('keydown', $scope.keyboardShortcut);
-
-    $scope.paragraphOnDoubleClick = function(paragraphId) {
-      $scope.$broadcast('doubleClickParagraph', paragraphId);
-    };
-
-    // Move the note to trash and go back to the main page
-    $scope.moveNoteToTrash = function(noteId) {
-      noteActionSrv.moveNoteToTrash(noteId, true);
-    };
-
-    // Remove the note permanently if it's in the trash
-    $scope.removeNote = function(noteId) {
-      noteActionSrv.removeNote(noteId, true);
-    };
-
-    $scope.isTrash = function(note) {
-      return note ? note.name.split('/')[0] === TRASH_FOLDER_ID : false;
-    };
-
-    //Export notebook
-    $scope.exportNote = function() {
-      var jsonContent = JSON.stringify($scope.note);
-      saveAsService.saveAs(jsonContent, $scope.note.name, 'json');
-    };
-
-    //Clone note
-    $scope.cloneNote = function(noteId) {
-      BootstrapDialog.confirm({
-        closable: true,
-        title: '',
-        message: 'Do you want to clone this note?',
-        callback: function(result) {
-          if (result) {
-            websocketMsgSrv.cloneNote(noteId);
-            $location.path('/');
-          }
-        }
-      });
-    };
+    }
+  };
 
-    // checkpoint/commit notebook
-    $scope.checkpointNote = function(commitMessage) {
-      BootstrapDialog.confirm({
-        closable: true,
-        title: '',
-        message: 'Commit note to current repository?',
-        callback: function(result) {
-          if (result) {
-            websocketMsgSrv.checkpointNote($routeParams.noteId, commitMessage);
-          }
-        }
-      });
-      document.getElementById('note.checkpoint.message').value = '';
-    };
+  // register mouseevent handler for focus paragraph
+  document.addEventListener('click', $scope.focusParagraphOnClick);
 
-    // set notebook head to given revision
-    $scope.setNoteRevision = function() {
-      BootstrapDialog.confirm({
-        closable: true,
-        title: '',
-        message: 'Set notebook head to current revision?',
-        callback: function(result) {
-          if (result) {
-            websocketMsgSrv.setNoteRevision($routeParams.noteId, $routeParams.revisionId);
-          }
-        }
-      });
-    };
-
-    $scope.$on('listRevisionHistory', function(event, data) {
-      console.log('received list of revisions %o', data);
-      $scope.noteRevisions = data.revisionList;
-      $scope.noteRevisions.splice(0, 0, {
-        id: 'Head',
-        message: 'Head'
-      });
-      if ($routeParams.revisionId) {
-        var index = _.findIndex($scope.noteRevisions, {'id': $routeParams.revisionId});
-        if (index > -1) {
-          $scope.currentRevision = $scope.noteRevisions[index].message;
+  $scope.keyboardShortcut = function(keyEvent) {
+    // handle keyevent
+    if (!$scope.viewOnly && !$scope.revisionView) {
+      $scope.$broadcast('keyEvent', keyEvent);
+    }
+  };
+
+  // register mouseevent handler for focus paragraph
+  document.addEventListener('keydown', $scope.keyboardShortcut);
+
+  $scope.paragraphOnDoubleClick = function(paragraphId) {
+    $scope.$broadcast('doubleClickParagraph', paragraphId);
+  };
+
+  // Move the note to trash and go back to the main page
+  $scope.moveNoteToTrash = function(noteId) {
+    noteActionSrv.moveNoteToTrash(noteId, true);
+  };
+
+  // Remove the note permanently if it's in the trash
+  $scope.removeNote = function(noteId) {
+    noteActionSrv.removeNote(noteId, true);
+  };
+
+  $scope.isTrash = function(note) {
+    return note ? note.name.split('/')[0] === TRASH_FOLDER_ID : false;
+  };
+
+  //Export notebook
+  $scope.exportNote = function() {
+    var jsonContent = JSON.stringify($scope.note);
+    saveAsService.saveAs(jsonContent, $scope.note.name, 'json');
+  };
+
+  //Clone note
+  $scope.cloneNote = function(noteId) {
+    BootstrapDialog.confirm({
+      closable: true,
+      title: '',
+      message: 'Do you want to clone this note?',
+      callback: function(result) {
+        if (result) {
+          websocketMsgSrv.cloneNote(noteId);
+          $location.path('/');
         }
       }
     });
-
-    $scope.$on('noteRevision', function(event, data) {
-      console.log('received note revision %o', data);
-      if (data.note) {
-        $scope.note = data.note;
-        initializeLookAndFeel();
-      } else {
-        $location.path('/');
+  };
+
+  // checkpoint/commit notebook
+  $scope.checkpointNote = function(commitMessage) {
+    BootstrapDialog.confirm({
+      closable: true,
+      title: '',
+      message: 'Commit note to current repository?',
+      callback: function(result) {
+        if (result) {
+          websocketMsgSrv.checkpointNote($routeParams.noteId, commitMessage);
+        }
       }
     });
-
-    $scope.$on('setNoteRevisionResult', function(event, data) {
-      console.log('received set note revision result %o', data);
-      if (data.status) {
-        $location.path('/notebook/' + $routeParams.noteId);
+    document.getElementById('note.checkpoint.message').value = '';
+  };
+
+  // set notebook head to given revision
+  $scope.setNoteRevision = function() {
+    BootstrapDialog.confirm({
+      closable: true,
+      title: '',
+      message: 'Set notebook head to current revision?',
+      callback: function(result) {
+        if (result) {
+          websocketMsgSrv.setNoteRevision($routeParams.noteId, $routeParams.revisionId);
+        }
       }
     });
-
-    $scope.visitRevision = function(revision) {
-      if (revision.id) {
-        if (revision.id === 'Head') {
-          $location.path('/notebook/' + $routeParams.noteId);
-        } else {
-          $location.path('/notebook/' + $routeParams.noteId + '/revision/' + revision.id);
-        }
-      } else {
-        ngToast.danger({content: 'There is a problem with this Revision',
-          verticalPosition: 'top', dismissOnTimeout: false});
+  };
+
+  $scope.$on('listRevisionHistory', function(event, data) {
+    console.log('received list of revisions %o', data);
+    $scope.noteRevisions = data.revisionList;
+    $scope.noteRevisions.splice(0, 0, {
+      id: 'Head',
+      message: 'Head'
+    });
+    if ($routeParams.revisionId) {
+      var index = _.findIndex($scope.noteRevisions, {'id': $routeParams.revisionId});
+      if (index > -1) {
+        $scope.currentRevision = $scope.noteRevisions[index].message;
       }
-    };
+    }
+  });
 
-    $scope.runAllParagraphs = function(noteId) {
-      BootstrapDialog.confirm({
-        closable: true,
-        title: '',
-        message: 'Run all paragraphs?',
-        callback: function(result) {
-          if (result) {
-            const paragraphs = $scope.note.paragraphs.map(p => {
-              return {
-                id: p.id,
-                title: p.title,
-                paragraph: p.text,
-                config: p.config,
-                params: p.settings.params
-              };
-            });
-            websocketMsgSrv.runAllParagraphs(noteId, paragraphs);
-          }
-        }
-      });
-    };
-
-    $scope.saveNote = function() {
-      if ($scope.note && $scope.note.paragraphs) {
-        _.forEach($scope.note.paragraphs, function(par) {
-          angular
-            .element('#' + par.id + '_paragraphColumn_main')
-            .scope()
-            .saveParagraph(par);
-        });
-        $scope.isNoteDirty = null;
-      }
-    };
+  $scope.$on('noteRevision', function(event, data) {
+    console.log('received note revision %o', data);
+    if (data.note) {
+      $scope.note = data.note;
+      initializeLookAndFeel();
+    } else {
+      $location.path('/');
+    }
+  });
 
-    $scope.clearAllParagraphOutput = function(noteId) {
-      noteActionSrv.clearAllParagraphOutput(noteId);
-    };
+  $scope.$on('setNoteRevisionResult', function(event, data) {
+    console.log('received set note revision result %o', data);
+    if (data.status) {
+      $location.path('/notebook/' + $routeParams.noteId);
+    }
+  });
 
-    $scope.toggleAllEditor = function() {
-      if ($scope.editorToggled) {
-        $scope.$broadcast('openEditor');
+  $scope.visitRevision = function(revision) {
+    if (revision.id) {
+      if (revision.id === 'Head') {
+        $location.path('/notebook/' + $routeParams.noteId);
       } else {
-        $scope.$broadcast('closeEditor');
+        $location.path('/notebook/' + $routeParams.noteId + '/revision/' + revision.id);
+      }
+    } else {
+      ngToast.danger({content: 'There is a problem with this Revision',
+        verticalPosition: 'top', dismissOnTimeout: false});
+    }
+  };
+
+  $scope.runAllParagraphs = function(noteId) {
+    BootstrapDialog.confirm({
+      closable: true,
+      title: '',
+      message: 'Run all paragraphs?',
+      callback: function(result) {
+        if (result) {
+          const paragraphs = $scope.note.paragraphs.map(p => {
+            return {
+              id: p.id,
+              title: p.title,
+              paragraph: p.text,
+              config: p.config,
+              params: p.settings.params
+            };
+          });
+          websocketMsgSrv.runAllParagraphs(noteId, paragraphs);
+        }
       }
-      $scope.editorToggled = !$scope.editorToggled;
-    };
+    });
+  };
+
+  $scope.saveNote = function() {
+    if ($scope.note && $scope.note.paragraphs) {
+      _.forEach($scope.note.paragraphs, function(par) {
+        angular
+          .element('#' + par.id + '_paragraphColumn_main')
+          .scope()
+          .saveParagraph(par);
+      });
+      $scope.isNoteDirty = null;
+    }
+  };
 
-    $scope.showAllEditor = function() {
-      $scope.$broadcast('openEditor');
-    };
+  $scope.clearAllParagraphOutput = function(noteId) {
+    noteActionSrv.clearAllParagraphOutput(noteId);
+  };
 
-    $scope.hideAllEditor = function() {
+  $scope.toggleAllEditor = function() {
+    if ($scope.editorToggled) {
+      $scope.$broadcast('openEditor');
+    } else {
       $scope.$broadcast('closeEditor');
-    };
+    }
+    $scope.editorToggled = !$scope.editorToggled;
+  };
 
-    $scope.toggleAllTable = function() {
-      if ($scope.tableToggled) {
-        $scope.$broadcast('openTable');
-      } else {
-        $scope.$broadcast('closeTable');
-      }
-      $scope.tableToggled = !$scope.tableToggled;
-    };
+  $scope.showAllEditor = function() {
+    $scope.$broadcast('openEditor');
+  };
 
-    $scope.showAllTable = function() {
-      $scope.$broadcast('openTable');
-    };
+  $scope.hideAllEditor = function() {
+    $scope.$broadcast('closeEditor');
+  };
 
-    $scope.hideAllTable = function() {
+  $scope.toggleAllTable = function() {
+    if ($scope.tableToggled) {
+      $scope.$broadcast('openTable');
+    } else {
       $scope.$broadcast('closeTable');
-    };
-
-    $scope.isNoteRunning = function() {
-      var running = false;
-      if (!$scope.note) { return false; }
-      for (var i = 0; i < $scope.note.paragraphs.length; i++) {
-        if ($scope.note.paragraphs[i].status === 'PENDING' || $scope.note.paragraphs[i].status === 'RUNNING') {
-          running = true;
-          break;
-        }
-      }
-      return running;
-    };
+    }
+    $scope.tableToggled = !$scope.tableToggled;
+  };
 
-    $scope.killSaveTimer = function() {
-      if ($scope.saveTimer) {
-        $timeout.cancel($scope.saveTimer);
-        $scope.saveTimer = null;
-      }
-    };
-
-    $scope.startSaveTimer = function() {
-      $scope.killSaveTimer();
-      $scope.isNoteDirty = true;
-      //console.log('startSaveTimer called ' + $scope.note.id);
-      $scope.saveTimer = $timeout(function() {
-        $scope.saveNote();
-      }, 10000);
-    };
-
-    angular.element(window).on('beforeunload', function(e) {
-      $scope.killSaveTimer();
-      $scope.saveNote();
-    });
+  $scope.showAllTable = function() {
+    $scope.$broadcast('openTable');
+  };
 
-    $scope.setLookAndFeel = function(looknfeel) {
-      $scope.note.config.looknfeel = looknfeel;
-      if ($scope.revisionView === true) {
-        $rootScope.$broadcast('setLookAndFeel', $scope.note.config.looknfeel);
-      } else {
-        $scope.setConfig();
+  $scope.hideAllTable = function() {
+    $scope.$broadcast('closeTable');
+  };
+
+  $scope.isNoteRunning = function() {
+    var running = false;
+    if (!$scope.note) { return false; }
+    for (var i = 0; i < $scope.note.paragraphs.length; i++) {
+      if ($scope.note.paragraphs[i].status === 'PENDING' || $scope.note.paragraphs[i].status === 'RUNNING') {
+        running = true;
+        break;
       }
-    };
+    }
+    return running;
+  };
 
-    /** Set cron expression for this note **/
-    $scope.setCronScheduler = function(cronExpr) {
-      $scope.note.config.cron = cronExpr;
-      $scope.setConfig();
-    };
+  $scope.killSaveTimer = function() {
+    if ($scope.saveTimer) {
+      $timeout.cancel($scope.saveTimer);
+      $scope.saveTimer = null;
+    }
+  };
 
-    /** Set the username of the user to be used to execute all notes in notebook **/
-    $scope.setCronExecutingUser = function(cronExecutingUser) {
-      $scope.note.config.cronExecutingUser = cronExecutingUser;
-      $scope.setConfig();
-    };
+  $scope.startSaveTimer = function() {
+    $scope.killSaveTimer();
+    $scope.isNoteDirty = true;
+    //console.log('startSaveTimer called ' + $scope.note.id);
+    $scope.saveTimer = $timeout(function() {
+      $scope.saveNote();
+    }, 10000);
+  };
 
-    /** Set release resource for this note **/
-    $scope.setReleaseResource = function(value) {
-      $scope.note.config.releaseresource = value;
-      $scope.setConfig();
-    };
+  angular.element(window).on('beforeunload', function(e) {
+    $scope.killSaveTimer();
+    $scope.saveNote();
+  });
 
-    /** Update note config **/
-    $scope.setConfig = function(config) {
-      if (config) {
-        $scope.note.config = config;
-      }
+  $scope.setLookAndFeel = function(looknfeel) {
+    $scope.note.config.looknfeel = looknfeel;
+    if ($scope.revisionView === true) {
+      $rootScope.$broadcast('setLookAndFeel', $scope.note.config.looknfeel);
+    } else {
+      $scope.setConfig();
+    }
+  };
+
+  /** Set cron expression for this note **/
+  $scope.setCronScheduler = function(cronExpr) {
+    $scope.note.config.cron = cronExpr;
+    $scope.setConfig();
+  };
+
+  /** Set the username of the user to be used to execute all notes in notebook **/
+  $scope.setCronExecutingUser = function(cronExecutingUser) {
+    $scope.note.config.cronExecutingUser = cronExecutingUser;
+    $scope.setConfig();
+  };
+
+  /** Set release resource for this note **/
+  $scope.setReleaseResource = function(value) {
+    $scope.note.config.releaseresource = value;
+    $scope.setConfig();
+  };
+
+  /** Update note config **/
+  $scope.setConfig = function(config) {
+    if (config) {
+      $scope.note.config = config;
+    }
+    websocketMsgSrv.updateNote($scope.note.id, $scope.note.name, $scope.note.config);
+  };
+
+  /** Update the note name */
+  $scope.updateNoteName = function(newName) {
+    const trimmedNewName = newName.trim();
+    if (trimmedNewName.length > 0 && $scope.note.name !== trimmedNewName) {
+      $scope.note.name = trimmedNewName;
       websocketMsgSrv.updateNote($scope.note.id, $scope.note.name, $scope.note.config);
-    };
-
-    /** Update the note name */
-    $scope.updateNoteName = function(newName) {
-      const trimmedNewName = newName.trim();
-      if (trimmedNewName.length > 0 && $scope.note.name !== trimmedNewName) {
-        $scope.note.name = trimmedNewName;
-        websocketMsgSrv.updateNote($scope.note.id, $scope.note.name, $scope.note.config);
-      }
-    };
+    }
+  };
 
-    var initializeLookAndFeel = function() {
-      if (!$scope.note.config.looknfeel) {
-        $scope.note.config.looknfeel = 'default';
-      } else {
-        $scope.viewOnly = $scope.note.config.looknfeel === 'report' ? true : false;
-      }
+  var initializeLookAndFeel = function() {
+    if (!$scope.note.config.looknfeel) {
+      $scope.note.config.looknfeel = 'default';
+    } else {
+      $scope.viewOnly = $scope.note.config.looknfeel === 'report' ? true : false;
+    }
 
-      if ($scope.note.paragraphs && $scope.note.paragraphs[0]) {
-        $scope.note.paragraphs[0].focus = true;
-      }
-      $rootScope.$broadcast('setLookAndFeel', $scope.note.config.looknfeel);
-    };
-
-    var cleanParagraphExcept = function(paragraphId, note) {
-      var noteCopy = {};
-      noteCopy.id = note.id;
-      noteCopy.name = note.name;
-      noteCopy.config = note.config;
-      noteCopy.info = note.info;
-      noteCopy.paragraphs = [];
-      for (var i = 0; i < note.paragraphs.length; i++) {
-        if (note.paragraphs[i].id === paragraphId) {
-          noteCopy.paragraphs[0] = note.paragraphs[i];
-          if (!noteCopy.paragraphs[0].config) {
-            noteCopy.paragraphs[0].config = {};
-          }
-          noteCopy.paragraphs[0].config.editorHide = true;
-          noteCopy.paragraphs[0].config.tableHide = false;
-          break;
+    if ($scope.note.paragraphs && $scope.note.paragraphs[0]) {
+      $scope.note.paragraphs[0].focus = true;
+    }
+    $rootScope.$broadcast('setLookAndFeel', $scope.note.config.looknfeel);
+  };
+
+  var cleanParagraphExcept = function(paragraphId, note) {
+    var noteCopy = {};
+    noteCopy.id = note.id;
+    noteCopy.name = note.name;
+    noteCopy.config = note.config;
+    noteCopy.info = note.info;
+    noteCopy.paragraphs = [];
+    for (var i = 0; i < note.paragraphs.length; i++) {
+      if (note.paragraphs[i].id === paragraphId) {
+        noteCopy.paragraphs[0] = note.paragraphs[i];
+        if (!noteCopy.paragraphs[0].config) {
+          noteCopy.paragraphs[0].config = {};
         }
+        noteCopy.paragraphs[0].config.editorHide = true;
+        noteCopy.paragraphs[0].config.tableHide = false;
+        break;
       }
-      return noteCopy;
-    };
-
-    var addPara = function(paragraph, index) {
-      $scope.note.paragraphs.splice(index, 0, paragraph);
-      _.each($scope.note.paragraphs, function(para) {
-        if (para.id === paragraph.id) {
-          para.focus = true;
-          $scope.$broadcast('focusParagraph', para.id, 0, false);
-        }
-      });
-    };
-
-    var removePara = function(paragraphId) {
-      var removeIdx;
-      _.each($scope.note.paragraphs, function(para, idx) {
-        if (para.id === paragraphId) {
-          removeIdx = idx;
-        }
-      });
-      return $scope.note.paragraphs.splice(removeIdx, 1);
-    };
-
-    $scope.$on('addParagraph', function(event, paragraph, index) {
-      addPara(paragraph, index);
-    });
-
-    $scope.$on('removeParagraph', function(event, paragraphId) {
-      removePara(paragraphId);
-    });
+    }
+    return noteCopy;
+  };
 
-    $scope.$on('moveParagraph', function(event, paragraphId, newIdx) {
-      var removedPara = removePara(paragraphId);
-      if (removedPara && removedPara.length === 1) {
-        addPara(removedPara[0], newIdx);
+  var addPara = function(paragraph, index) {
+    $scope.note.paragraphs.splice(index, 0, paragraph);
+    _.each($scope.note.paragraphs, function(para) {
+      if (para.id === paragraph.id) {
+        para.focus = true;
+        $scope.$broadcast('focusParagraph', para.id, 0, false);
       }
     });
+  };
 
-    $scope.$on('updateNote', function(event, name, config, info) {
-      /** update Note name */
-      if (name !== $scope.note.name) {
-        console.log('change note name to : %o', $scope.note.name);
-        $scope.note.name = name;
+  var removePara = function(paragraphId) {
+    var removeIdx;
+    _.each($scope.note.paragraphs, function(para, idx) {
+      if (para.id === paragraphId) {
+        removeIdx = idx;
       }
-      $scope.note.config = config;
-      $scope.note.info = info;
-      initializeLookAndFeel();
     });
+    return $scope.note.paragraphs.splice(removeIdx, 1);
+  };
 
-    var getInterpreterBindings = function() {
-      websocketMsgSrv.getInterpreterBindings($scope.note.id);
-    };
+  $scope.$on('addParagraph', function(event, paragraph, index) {
+    addPara(paragraph, index);
+  });
 
-    $scope.$on('interpreterBindings', function(event, data) {
-      $scope.interpreterBindings = data.interpreterBindings;
-      $scope.interpreterBindingsOrig = angular.copy($scope.interpreterBindings); // to check dirty
+  $scope.$on('removeParagraph', function(event, paragraphId) {
+    removePara(paragraphId);
+  });
 
-      var selected = false;
-      var key;
-      var setting;
+  $scope.$on('moveParagraph', function(event, paragraphId, newIdx) {
+    var removedPara = removePara(paragraphId);
+    if (removedPara && removedPara.length === 1) {
+      addPara(removedPara[0], newIdx);
+    }
+  });
 
-      for (key in $scope.interpreterBindings) {
-        setting = $scope.interpreterBindings[key];
-        if (setting.selected) {
-          selected = true;
-          break;
-        }
-      }
+  $scope.$on('updateNote', function(event, name, config, info) {
+    /** update Note name */
+    if (name !== $scope.note.name) {
+      console.log('change note name to : %o', $scope.note.name);
+      $scope.note.name = name;
+    }
+    $scope.note.config = config;
+    $scope.note.info = info;
+    initializeLookAndFeel();
+  });
 
-      if (!selected) {
-        // make default selection
-        var selectedIntp = {};
-        for (key in $scope.interpreterBindings) {
-          setting = $scope.interpreterBindings[key];
-          if (!selectedIntp[setting.name]) {
-            setting.selected = true;
-            selectedIntp[setting.name] = true;
-          }
-        }
-        $scope.showSetting = true;
-      }
-    });
+  var getInterpreterBindings = function() {
+    websocketMsgSrv.getInterpreterBindings($scope.note.id);
+  };
 
-    $scope.interpreterSelectionListeners = {
-      accept: function(sourceItemHandleScope, destSortableScope) {return true;},
-      itemMoved: function(event) {},
-      orderChanged: function(event) {}
-    };
+  $scope.$on('interpreterBindings', function(event, data) {
+    $scope.interpreterBindings = data.interpreterBindings;
+    $scope.interpreterBindingsOrig = angular.copy($scope.interpreterBindings); // to check dirty
 
-    $scope.openSetting = function() {
-      $scope.showSetting = true;
-      getInterpreterBindings();
-    };
+    var selected = false;
+    var key;
+    var setting;
 
-    $scope.closeSetting = function() {
-      if (isSettingDirty()) {
-        BootstrapDialog.confirm({
-          closable: true,
-          title: '',
-          message: 'Interpreter setting changes will be discarded.',
-          callback: function(result) {
-            if (result) {
-              $scope.$apply(function() {
-                $scope.showSetting = false;
-              });
-            }
-          }
-        });
-      } else {
-        $scope.showSetting = false;
+    for (key in $scope.interpreterBindings) {
+      setting = $scope.interpreterBindings[key];
+      if (setting.selected) {
+        selected = true;
+        break;
       }
-    };
-
-    $scope.saveSetting = function() {
-      var selectedSettingIds = [];
-      for (var no in $scope.interpreterBindings) {
-        var setting = $scope.interpreterBindings[no];
-        if (setting.selected) {
-          selectedSettingIds.push(setting.id);
+    }
+
+    if (!selected) {
+      // make default selection
+      var selectedIntp = {};
+      for (key in $scope.interpreterBindings) {
+        setting = $scope.interpreterBindings[key];
+        if (!selectedIntp[setting.name]) {
+          setting.selected = true;
+          selectedIntp[setting.name] = true;
         }
       }
-      websocketMsgSrv.saveInterpreterBindings($scope.note.id, selectedSettingIds);
-      console.log('Interpreter bindings %o saved', selectedSettingIds);
+      $scope.showSetting = true;
+    }
+  });
+
+  $scope.interpreterSelectionListeners = {
+    accept: function(sourceItemHandleScope, destSortableScope) {return true;},
+    itemMoved: function(event) {},
+    orderChanged: function(event) {}
+  };
+
+  $scope.openSetting = function() {
+    $scope.showSetting = true;
+    getInterpreterBindings();
+  };
 
-      _.forEach($scope.note.paragraphs, function(n, key) {
-        var regExp = /^\s*%/g;
-        if (n.text && !regExp.exec(n.text)) {
-          $scope.$broadcast('saveInterpreterBindings', n.id);
+  $scope.closeSetting = function() {
+    if (isSettingDirty()) {
+      BootstrapDialog.confirm({
+        closable: true,
+        title: '',
+        message: 'Interpreter setting changes will be discarded.',
+        callback: function(result) {
+          if (result) {
+            $scope.$apply(function() {
+              $scope.showSetting = false;
+            });
+          }
         }
       });
-
+    } else {
       $scope.showSetting = false;
-    };
+    }
+  };
 
-    $scope.toggleSetting = function() {
-      if ($scope.showSetting) {
-        $scope.closeSetting();
-      } else {
-        $scope.openSetting();
-        $scope.closePermissions();
+  $scope.saveSetting = function() {
+    var selectedSettingIds = [];
+    for (var no in $scope.interpreterBindings) {
+      var setting = $scope.interpreterBindings[no];
+      if (setting.selected) {
+        selectedSettingIds.push(setting.id);
       }
-    };
-
-    var getPermissions = function(callback) {
-      $http.get(baseUrlSrv.getRestApiBase() + '/notebook/' + $scope.note.id + '/permissions').
-      success(function(data, status, headers, config) {
-        $scope.permissions = data.body;
-        $scope.permissionsOrig = angular.copy($scope.permissions); // to check dirty
-
-        var selectJson = {
-          tokenSeparators: [',', ' '],
-          ajax: {
-            url: function(params) {
-              if (!params.term) {
-                return false;
-              }
-              return baseUrlSrv.getRestApiBase() + '/security/userlist/' + params.term;
-            },
-            delay: 250,
-            processResults: function(data, params) {
-              var results = [];
-
-              if (data.body.users.length !== 0) {
-                var users = [];
-                for (var len = 0; len < data.body.users.length; len++) {
-                  users.push({
-                    'id': data.body.users[len],
-                    'text': data.body.users[len]
-                  });
-                }
-                results.push({
-                  'text': 'Users :',
-                  'children': users
+    }
+    websocketMsgSrv.saveInterpreterBindings($scope.note.id, selectedSettingIds);
+    console.log('Interpreter bindings %o saved', selectedSettingIds);
+
+    _.forEach($scope.note.paragraphs, function(n, key) {
+      var regExp = /^\s*%/g;
+      if (n.text && !regExp.exec(n.text)) {
+        $scope.$broadcast('saveInterpreterBindings', n.id);
+      }
+    });
+
+    $scope.showSetting = false;
+  };
+
+  $scope.toggleSetting = function() {
+    if ($scope.showSetting) {
+      $scope.closeSetting();
+    } else {
+      $scope.openSetting();
+      $scope.closePermissions();
+    }
+  };
+
+  var getPermissions = function(callback) {
+    $http.get(baseUrlSrv.getRestApiBase() + '/notebook/' + $scope.note.id + '/permissions').
+    success(function(data, status, headers, config) {
+      $scope.permissions = data.body;
+      $scope.permissionsOrig = angular.copy($scope.permissions); // to check dirty
+
+      var selectJson = {
+        tokenSeparators: [',', ' '],
+        ajax: {
+          url: function(params) {
+            if (!params.term) {
+              return false;
+            }
+            return baseUrlSrv.getRestApiBase() + '/security/userlist/' + params.term;
+          },
+          delay: 250,
+          processResults: function(data, params) {
+            var results = [];
+
+            if (data.body.users.length !== 0) {
+              var users = [];
+              for (var len = 0; len < data.body.users.length; len++) {
+                users.push({
+                  'id': data.body.users[len],
+                  'text': data.body.users[len]
                 });
               }
-              if (data.body.roles.length !== 0) {
-                var roles = [];
-                for (var len = 0; len < data.body.roles.length; len++) {
-                  roles.push({
-                    'id': data.body.roles[len],
-                    'text': data.body.roles[len]
-                  });
-                }
-                results.push({
-                  'text': 'Roles :',
-                  'children': roles
+              results.push({
+                'text': 'Users :',
+                'children': users
+              });
+            }
+            if (data.body.roles.length !== 0) {
+              var roles = [];
+              for (var len = 0; len < data.body.roles.length; len++) {
+                roles.push({
+                  'id': data.body.roles[len],
+                  'text': data.body.roles[len]
                 });
               }
-              return {
-                results: results,
-                pagination: {
-                  more: false
-                }
-              };
-            },
-            cache: false
-          },
-          width: ' ',
-          tags: true,
-          minimumInputLength: 3
-        };
-
-        $scope.setIamOwner();
-        angular.element('#selectOwners').select2(selectJson);
-        angular.element('#selectReaders').select2(selectJson);
-        angular.element('#selectWriters').select2(selectJson);
-        if (callback) {
-          callback();
-        }
-      }).
-      error(function(data, status, headers, config) {
-        if (status !== 0) {
-          console.log('Error %o %o', status, data.message);
-        }
-      });
-    };
-
-    $scope.openPermissions = function() {
-      $scope.showPermissions = true;
-      getPermissions();
-    };
-
-    $scope.closePermissions = function() {
-      if (isPermissionsDirty()) {
-        BootstrapDialog.confirm({
-          closable: true,
-          title: '',
-          message: 'Changes will be discarded.',
-          callback: function(result) {
-            if (result) {
-              $scope.$apply(function() {
-                $scope.showPermissions = false;
+              results.push({
+                'text': 'Roles :',
+                'children': roles
               });
             }
-          }
-        });
-      } else {
-        $scope.showPermissions = false;
+            return {
+              results: results,
+              pagination: {
+                more: false
+              }
+            };
+          },
+          cache: false
+        },
+        width: ' ',
+        tags: true,
+        minimumInputLength: 3
+      };
+
+      $scope.setIamOwner();
+      angular.element('#selectOwners').select2(selectJson);
+      angular.element('#selectReaders').select2(selectJson);
+      angular.element('#selectWriters').select2(selectJson);
+      if (callback) {
+        callback();
+      }
+    }).
+    error(function(data, status, headers, config) {
+      if (status !== 0) {
+        console.log('Error %o %o', status, data.message);
       }
-    };
+    });
+  };
 
-    function convertPermissionsToArray() {
-      $scope.permissions.owners = angular.element('#selectOwners').val();
-      $scope.permissions.readers = angular.element('#selectReaders').val();
-      $scope.permissions.writers = angular.element('#selectWriters').val();
-    }
+  $scope.openPermissions = function() {
+    $scope.showPermissions = true;
+    getPermissions();
+  };
 
-    $scope.restartInterpreter = function(interpeter) {
-      var thisConfirm = BootstrapDialog.confirm({
-        closable: false,
-        closeByBackdrop: false,
-        closeByKeyboard: false,
+  $scope.closePermissions = function() {
+    if (isPermissionsDirty()) {
+      BootstrapDialog.confirm({
+        closable: true,
         title: '',
-        message: 'Do you want to restart ' + interpeter.name + ' interpreter?',
+        message: 'Changes will be discarded.',
         callback: function(result) {
           if (result) {
-            var payload  = {
-              'noteId': $scope.note.id
-            };
+            $scope.$apply(function() {
+              $scope.showPermissions = false;
+            });
+          }
+        }
+      });
+    } else {
+      $scope.showPermissions = false;
+    }
+  };
 
-            thisConfirm.$modalFooter.find('button').addClass('disabled');
-            thisConfirm.$modalFooter.find('button:contains("OK")')
-              .html('<i class="fa fa-circle-o-notch fa-spin"></i> Saving Setting');
+  function convertPermissionsToArray() {
+    $scope.permissions.owners = angular.element('#selectOwners').val();
+    $scope.permissions.readers = angular.element('#selectReaders').val();
+    $scope.permissions.writers = angular.element('#selectWriters').val();
+  }
 
-            $http.put(baseUrlSrv.getRestApiBase() + '/interpreter/setting/restart/' + interpeter.id, payload)
-              .success(function(data, status, headers, config) {
+  $scope.restartInterpreter = function(interpeter) {
+    var thisConfirm = BootstrapDialog.confirm({
+      closable: false,
+      closeByBackdrop: false,
+      closeByKeyboard: false,
+      title: '',
+      message: 'Do you want to restart ' + interpeter.name + ' interpreter?',
+      callback: function(result) {
+        if (result) {
+          var payload  = {
+            'noteId': $scope.note.id
+          };
+
+          thisConfirm.$modalFooter.find('button').addClass('disabled');
+          thisConfirm.$modalFooter.find('button:contains("OK")')
+            .html('<i class="fa fa-circle-o-notch fa-spin"></i> Saving Setting');
+
+          $http.put(baseUrlSrv.getRestApiBase() + '/interpreter/setting/restart/' + interpeter.id, payload)
+            .success(function(data, status, headers, config) {
               var index = _.findIndex($scope.interpreterSettings, {'id': interpeter.id});
               $scope.interpreterSettings[index] = data.body;
               thisConfirm.close();
             }).error(function(data, status, headers, config) {
-              thisConfirm.close();
-              console.log('Error %o %o', status, data.message);
-              BootstrapDialog.show({
-                title: 'Error restart interpreter.',
-                message: data.message
-              });
-            });
-            return false;
-          }
-        }
-      });
-    };
-
-    $scope.savePermissions = function() {
-      convertPermissionsToArray();
-      $http.put(baseUrlSrv.getRestApiBase() + '/notebook/' + $scope.note.id + '/permissions',
-        $scope.permissions, {withCredentials: true}).
-        success(function(data, status, headers, config) {
-          getPermissions(function() {
-            console.log('Note permissions %o saved', $scope.permissions);
-            BootstrapDialog.alert({
-              closable: true,
-              title: 'Permissions Saved Successfully!!!',
-              message: 'Owners : ' + $scope.permissions.owners + '\n\n' + 'Readers : ' +
-              $scope.permissions.readers + '\n\n' + 'Writers  : ' + $scope.permissions.writers
+            thisConfirm.close();
+            console.log('Error %o %o', status, data.message);
+            BootstrapDialog.show({
+              title: 'Error restart interpreter.',
+              message: data.message
             });
-            $scope.showPermissions = false;
-          });
-        }).
-        error(function(data, status, headers, config) {
-          console.log('Error %o %o', status, data.message);
-          BootstrapDialog.show({
-            closable: false,
-            closeByBackdrop: false,
-            closeByKeyboard: false,
-            title: 'Insufficient privileges',
-            message: data.message,
-            buttons: [
-              {
-                label: 'Login',
-                action: function(dialog) {
-                  dialog.close();
-                  angular.element('#loginModal').modal({
-                    show: 'true'
-                  });
-                }
-              },
-              {
-                label: 'Cancel',
-                action: function(dialog) {
-                  dialog.close();
-                  $location.path('/');
-                }
-              }
-            ]
           });
-        });
-    };
-
-    $scope.togglePermissions = function() {
-      var principal = $rootScope.ticket.principal;
-      $scope.isAnonymous = principal === 'anonymous' ? true : false;
-      if (!!principal && $scope.isAnonymous) {
-        $scope.blockAnonUsers();
-      } else {
-        if ($scope.showPermissions) {
-          $scope.closePermissions();
-          angular.element('#selectOwners').select2({});
-          angular.element('#selectReaders').select2({});
-          angular.element('#selectWriters').select2({});
-        } else {
-          $scope.openPermissions();
-          $scope.closeSetting();
+          return false;
         }
       }
-    };
-
-    $scope.setIamOwner = function() {
-      if ($scope.permissions.owners.length > 0 &&
-          _.indexOf($scope.permissions.owners, $rootScope.ticket.principal) < 0) {
-        $scope.isOwner = false;
-        return false;
-      }
-      $scope.isOwner = true;
-      return true;
-    };
-
-    $scope.toggleNotePersonalizedMode = function() {
-      var personalizedMode = $scope.note.config.personalizedMode;
-      if ($scope.isOwner) {
-        BootstrapDialog.confirm({
+    });
+  };
+
+  $scope.savePermissions = function() {
+    convertPermissionsToArray();
+    $http.put(baseUrlSrv.getRestApiBase() + '/notebook/' + $scope.note.id + '/permissions',
+      $scope.permissions, {withCredentials: true}).
+    success(function(data, status, headers, config) {
+      getPermissions(function() {
+        console.log('Note permissions %o saved', $scope.permissions);
+        BootstrapDialog.alert({
           closable: true,
-          title: 'Setting the result display',
-          message: function(dialog) {
-            var modeText = $scope.note.config.personalizedMode === 'true' ? 'collaborate' : 'personalize';
-            return 'Do you want to <span class="text-info">' + modeText + '</span> your analysis?';
+          title: 'Permissions Saved Successfully!!!',
+          message: 'Owners : ' + $scope.permissions.owners + '\n\n' + 'Readers : ' +
+          $scope.permissions.readers + '\n\n' + 'Writers  : ' + $scope.permissions.writers
+        });
+        $scope.showPermissions = false;
+      });
+    }).
+    error(function(data, status, headers, config) {
+      console.log('Error %o %o', status, data.message);
+      BootstrapDialog.show({
+        closable: false,
+        closeByBackdrop: false,
+        closeByKeyboard: false,
+        title: 'Insufficient privileges',
+        message: data.message,
+        buttons: [
+          {
+            label: 'Login',
+            action: function(dialog) {
+              dialog.close();
+              angular.element('#loginModal').modal({
+                show: 'true'
+              });
+            }
           },
-          callback: function(result) {
-            if (result) {
-              if ($scope.note.config.personalizedMode === undefined) {
-                $scope.note.config.personalizedMode = 'false';
-              }
-              $scope.note.config.personalizedMode = personalizedMode === 'true' ?  'false' : 'true';
-              websocketMsgSrv.updatePersonalizedMode($scope.note.id, $scope.note.config.personalizedMode);
+          {
+            label: 'Cancel',
+            action: function(dialog) {
+              dialog.close();
+              $location.path('/');
             }
           }
-        });
-      }
-    };
-
-    var isSettingDirty = function() {
-      if (angular.equals($scope.interpreterBindings, $scope.interpreterBindingsOrig)) {
-        return false;
+        ]
+      });
+    });
+  };
+
+  $scope.togglePermissions = function() {
+    var principal = $rootScope.ticket.principal;
+    $scope.isAnonymous = principal === 'anonymous' ? true : false;
+    if (!!principal && $scope.isAnonymous) {
+      $scope.blockAnonUsers();
+    } else {
+      if ($scope.showPermissions) {
+        $scope.closePermissions();
+        angular.element('#selectOwners').select2({});
+        angular.element('#selectReaders').select2({});
+        angular.element('#selectWriters').select2({});
       } else {
-        return true;
+        $scope.openPermissions();
+        $scope.closeSetting();
       }
-    };
+    }
+  };
 
-    var isPermissionsDirty = function() {
-      if (angular.equals($scope.permissions, $scope.permissionsOrig)) {
-        return false;
-      } else {
-        return true;
-      }
-    };
+  $scope.setIamOwner = function() {
+    if ($scope.permissions.owners.length > 0 &&
+      _.indexOf($scope.permissions.owners, $rootScope.ticket.principal) < 0) {
+      $scope.isOwner = false;
+      return false;
+    }
+    $scope.isOwner = true;
+    return true;
+  };
 
-    angular.element(document).click(function() {
-      angular.element('.ace_autocomplete').hide();
-    });
+  $scope.toggleNotePersonalizedMode = function() {
+    var personalizedMode = $scope.note.config.personalizedMode;
+    if ($scope.isOwner) {
+      BootstrapDialog.confirm({
+        closable: true,
+        title: 'Setting the result display',
+        message: function(dialog) {
+          var modeText = $scope.note.config.personalizedMode === 'true' ? 'collaborate' : 'personalize';
+          return 'Do you want to <span class="text-info">' + modeText + '</span> your analysis?';
+        },
+        callback: function(result) {
+          if (result) {
+            if ($scope.note.config.personalizedMode === undefined) {
+              $scope.note.config.personalizedMode = 'false';
+            }
+            $scope.note.config.personalizedMode = personalizedMode === 'true' ?  'false' : 'true';
+            websocketMsgSrv.updatePersonalizedMode($scope.note.id, $scope.note.config.personalizedMode);
+          }
+        }
+      });
+    }
+  };
 
-    /*
-    ** $scope.$on functions below
-    */
+  var isSettingDirty = function() {
+    if (angular.equals($scope.interpreterBindings, $scope.interpreterBindingsOrig)) {
+      return false;
+    } else {
+      return true;
+    }
+  };
 
-    $scope.$on('setConnectedStatus', function(event, param) {
-      if (connectedOnce && param) {
-        initNotebook();
-      }
-      connectedOnce = true;
-    });
+  var isPermissionsDirty = function() {
+    if (angular.equals($scope.permissions, $scope.permissionsOrig)) {
+      return false;
+    } else {
+      return true;
+    }
+  };
 
-    $scope.$on('moveParagraphUp', function(event, paragraph) {
-      var newIndex = -1;
-      for (var i = 0; i < $scope.note.paragraphs.length; i++) {
-        if ($scope.note.paragraphs[i].id === paragraph.id) {
-          newIndex = i - 1;
-          break;
-        }
-      }
-      if (newIndex < 0 || newIndex >= $scope.note.paragraphs.length) {
-        return;
-      }
-      // save dirtyText of moving paragraphs.
-      var prevParagraph = $scope.note.paragraphs[newIndex];
-      angular
-        .element('#' + paragraph.id + '_paragraphColumn_main')
-        .scope()
-        .saveParagraph(paragraph);
-      angular
-        .element('#' + prevParagraph.id + '_paragraphColumn_main')
-        .scope()
-        .saveParagraph(prevParagraph);
-      websocketMsgSrv.moveParagraph(paragraph.id, newIndex);
-    });
+  angular.element(document).click(function() {
+    angular.element('.ace_autocomplete').hide();
+  });
 
-    $scope.$on('moveParagraphDown', function(event, paragraph) {
-      var newIndex = -1;
-      for (var i = 0; i < $scope.note.paragraphs.length; i++) {
-        if ($scope.note.paragraphs[i].id === paragraph.id) {
-          newIndex = i + 1;
-          break;
-        }
-      }
+  /*
+   ** $scope.$on functions below
+   */
 
-      if (newIndex < 0 || newIndex >= $scope.note.paragraphs.length) {
-        return;
-      }
-      // save dirtyText of moving paragraphs.
-      var nextParagraph = $scope.note.paragraphs[newIndex];
-      angular
-        .element('#' + paragraph.id + '_paragraphColumn_main')
-        .scope()
-        .saveParagraph(paragraph);
-      angular
-        .element('#' + nextParagraph.id + '_paragraphColumn_main')
-        .scope()
-        .saveParagraph(nextParagraph);
-      websocketMsgSrv.moveParagraph(paragraph.id, newIndex);
-    });
+  $scope.$on('setConnectedStatus', function(event, param) {
+    if (connectedOnce && param) {
+      initNotebook();
+    }
+    connectedOnce = true;
+  });
 
-    $scope.$on('moveFocusToPreviousParagraph', function(event, currentParagraphId) {
-      var focus = false;
-      for (var i = $scope.note.paragraphs.length - 1; i >= 0; i--) {
-        if (focus === false) {
-          if ($scope.note.paragraphs[i].id === currentParagraphId) {
-            focus = true;
-            continue;
-          }
-        } else {
-          $scope.$broadcast('focusParagraph', $scope.note.paragraphs[i].id, -1);
-          break;
-        }
+  $scope.$on('moveParagraphUp', function(event, paragraph) {
+    var newIndex = -1;
+    for (var i = 0; i < $scope.note.paragraphs.length; i++) {
+      if ($scope.note.paragraphs[i].id === paragraph.id) {
+        newIndex = i - 1;
+        break;
       }
-    });
-
-    $scope.$on('moveFocusToNextParagraph', function(event, currentParagraphId) {
-      var focus = false;
-      for (var i = 0; i < $scope.note.paragraphs.length; i++) {
-        if (focus === false) {
-          if ($scope.note.paragraphs[i].id === currentParagraphId) {
-            focus = true;
-            continue;
-          }
-        } else {
-          $scope.$broadcast('focusParagraph', $scope.note.paragraphs[i].id, 0);
-          break;
-        }
+    }
+    if (newIndex < 0 || newIndex >= $scope.note.paragraphs.length) {
+      return;
+    }
+    // save dirtyText of moving paragraphs.
+    var prevParagraph = $scope.note.paragraphs[newIndex];
+    angular
+      .element('#' + paragraph.id + '_paragraphColumn_main')
+      .scope()
+      .saveParagraph(paragraph);
+    angular
+      .element('#' + prevParagraph.id + '_paragraphColumn_main')
+      .scope()
+      .saveParagraph(prevParagraph);
+    websocketMsgSrv.moveParagraph(paragraph.id, newIndex);
+  });
+
+  $scope.$on('moveParagraphDown', function(event, paragraph) {
+    var newIndex = -1;
+    for (var i = 0; i < $scope.note.paragraphs.length; i++) {
+      if ($scope.note.paragraphs[i].id === paragraph.id) {
+        newIndex = i + 1;
+        break;
       }
-    });
+    }
 
-    $scope.$on('insertParagraph', function(event, paragraphId, position) {
-      var newIndex = -1;
-      for (var i = 0; i < $scope.note.paragraphs.length; i++) {
-        if ($scope.note.paragraphs[i].id === paragraphId) {
-          //determine position of where to add new paragraph; default is below
-          if (position === 'above') {
-            newIndex = i;
-          } else {
-            newIndex = i + 1;
-          }
-          break;
+    if (newIndex < 0 || newIndex >= $scope.note.paragraphs.length) {
+      return;
+    }
+    // save dirtyText of moving paragraphs.
+    var nextParagraph = $scope.note.paragraphs[newIndex];
+    angular
+      .element('#' + paragraph.id + '_paragraphColumn_main')
+      .scope()
+      .saveParagraph(paragraph);
+    angular
+      .element('#' + nextParagraph.id + '_paragraphColumn_main')
+      .scope()
+      .saveParagraph(nextParagraph);
+    websocketMsgSrv.moveParagraph(paragraph.id, newIndex);
+  });
+
+  $scope.$on('moveFocusToPreviousParagraph', function(event, currentParagraphId) {
+    var focus = false;
+    for (var i = $scope.note.paragraphs.length - 1; i >= 0; i--) {
+      if (focus === false) {
+        if ($scope.note.paragraphs[i].id === currentParagraphId) {
+          focus = true;
+          continue;
         }
+      } else {
+        $scope.$broadcast('focusParagraph', $scope.note.paragraphs[i].id, -1);
+        break;
       }
-
-      if (newIndex < 0 || newIndex > $scope.note.paragraphs.length) {
-        return;
-      }
-      websocketMsgSrv.insertParagraph(newIndex);
-    });
-
-    $scope.$on('setNoteContent', function(event, note) {
-      if (note === undefined) {
-        $location.path('/');
+    }
+  });
+
+  $scope.$on('moveFocusToNextParagraph', function(event, currentParagraphId) {
+    var focus = false;
+    for (var i = 0; i < $scope.note.paragraphs.length; i++) {
+      if (focus === false) {
+        if ($scope.note.paragraphs[i].id === currentParagraphId) {
+          focus = true;
+          continue;
+        }
+      } else {
+        $scope.$broadcast('focusParagraph', $scope.note.paragraphs[i].id, 0);
+        break;
       }
-
-      $scope.paragraphUrl = $routeParams.paragraphId;
-      $scope.asIframe = $routeParams.asIframe;
-      if ($scope.paragraphUrl) {
-        note = cleanParagraphExcept($scope.paragraphUrl, note);
-        $rootScope.$broadcast('setIframe', $scope.asIframe);
+    }
+  });
+
+  $scope.$on('insertParagraph', function(event, paragraphId, position) {
+    var newIndex = -1;
+    for (var i = 0; i < $scope.note.paragraphs.length; i++) {
+      if ($scope.note.paragraphs[i].id === paragraphId) {
+        //determine position of where to add new paragraph; default is below
+        if (position === 'above') {
+          newIndex = i;
+        } else {
+          newIndex = i + 1;
+        }
+        break;
       }
+    }
 
-      $scope.note = note;
-      initializeLookAndFeel();
-      //open interpreter binding setting when there're none selected
-      getInterpreterBindings();
-      getPermissions();
-      var isPersonalized = $scope.note.config.personalizedMode;
-      isPersonalized = isPersonalized === undefined ?  'false' : isPersonalized;
-      $scope.note.config.personalizedMode = isPersonalized;
-    });
+    if (newIndex < 0 || newIndex > $scope.note.paragraphs.length) {
+      return;
+    }
+    websocketMsgSrv.insertParagraph(newIndex);
+  });
 
-    $scope.$on('$destroy', function() {
-      angular.element(window).off('beforeunload');
-      $scope.killSaveTimer();
-      $scope.saveNote();
+  $scope.$on('setNoteContent', function(event, note) {
+    if (note === undefined) {
+      $location.path('/');
+    }
 
-      document.removeEventListener('click', $scope.focusParagraphOnClick);
-      document.removeEventListener('keydown', $scope.keyboardShortcut);
-    });
+    $scope.paragraphUrl = $routeParams.paragraphId;
+    $scope.asIframe = $routeParams.asIframe;
+    if ($scope.paragraphUrl) {
+      note = cleanParagraphExcept($scope.paragraphUrl, note);
+      $rootScope.$broadcast('setIframe', $scope.asIframe);
+    }
 
-    angular.element(window).bind('resize', function() {
-      const actionbarHeight = document.getElementById('actionbar').lastElementChild.clientHeight;
-      angular.element(document.getElementById('content')).css('padding-top', actionbarHeight - 20);
-    });
-  }
+    $scope.note = note;
+    initializeLookAndFeel();
+    //open interpreter binding setting when there're none selected
+    getInterpreterBindings();
+    getPermissions();
+    var isPersonalized = $scope.note.config.personalizedMode;
+    isPersonalized = isPersonalized === undefined ?  'false' : isPersonalized;
+    $scope.note.config.personalizedMode = isPersonalized;
+  });
+
+  $scope.$on('$destroy', function() {
+    angular.element(window).off('beforeunload');
+    $scope.killSaveTimer();
+    $scope.saveNote();
+
+    document.removeEventListener('click', $scope.focusParagraphOnClick);
+    document.removeEventListener('keydown', $scope.keyboardShortcut);
+  });
+
+  angular.element(window).bind('resize', function() {
+    const actionbarHeight = document.getElementById('actionbar').lastElementChild.clientHeight;
+    angular.element(document.getElementById('content')).css('padding-top', actionbarHeight - 20);
+  });
+}
 
-})();