diff --git a/zeppelin-web/src/components/noteName-create/notename.controller.js b/zeppelin-web/src/components/noteName-create/notename.controller.js index a81ffbad6d3..430e60db38e 100644 --- a/zeppelin-web/src/components/noteName-create/notename.controller.js +++ b/zeppelin-web/src/components/noteName-create/notename.controller.js @@ -14,41 +14,45 @@ 'use strict'; -angular.module('zeppelinWebApp').controller('NotenameCtrl', function($scope, $rootScope, $routeParams, websocketMsgSrv) { +angular.module('zeppelinWebApp').controller('NotenameCtrl', function($scope, $rootScope, $routeParams, websocketMsgSrv, $location) { var vm = this; vm.websocketMsgSrv = websocketMsgSrv; $scope.note = {}; - vm.createNote = function(){ - if(!vm.clone){ - vm.websocketMsgSrv.createNotebook($scope.note.notename); - }else{ - var noteId = $routeParams.noteId; - vm.websocketMsgSrv.cloneNotebook(noteId, $scope.note.notename); - } + + vm.createNote = function() { + if (!vm.clone) { + vm.websocketMsgSrv.createNotebook($scope.note.notename); + } else { + var noteId = $routeParams.noteId; + vm.websocketMsgSrv.cloneNotebook(noteId, $scope.note.notename); + } }; $scope.$on('setNoteContent', function(event, note) { - if(note !== undefined) { - window.location = '#/notebook/' + note.id; - console.log(note); + //a hack, to make it run only after notebook creation + //it should not run i.e in case of linking to the paragraph + if (note && $location.path().indexOf(note.id) < 0) { + $location.path('notebook/' + note.id); } }); - vm.preVisible = function(clone){ - var generatedName = vm.generateName(); - $scope.note.notename = 'Note ' + generatedName; - vm.clone = clone; - $scope.$apply(); + vm.preVisible = function(clone) { + var generatedName = vm.generateName(); + $scope.note.notename = 'Note ' + generatedName; + vm.clone = clone; + $scope.$apply(); }; + vm.generateName = function () { - var DICTIONARY = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', - 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', - 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ]; - var randIndex, name = ''; - for (var i = 0; i < 9; i++) { - randIndex = Math.floor(Math.random() * 32); - name += DICTIONARY[randIndex]; - } - return name; - }; + var DICTIONARY = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', + 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ]; + var randIndex, name = ''; + for (var i = 0; i < 9; i++) { + randIndex = Math.floor(Math.random() * 32); + name += DICTIONARY[randIndex]; + } + return name; + }; + });