Repository: zeppelin
Updated Branches:
  refs/heads/master 625b26855 -> 38ba2d475


[Zeppelin-2571] & [Zeppelin-465] Run paragraphs: from first/current to 
current/last

### What is this PR for?
This pr add the ability to run all paragraphs from the first to the current and 
from the current to the last. This makes it easier to update the data if 
changes are made in one of the related paragraphs.

### What type of PR is it?
Feature

### What is the Jira issue?
[ZEPPELIN-2571](https://issues.apache.org/jira/browse/ZEPPELIN-2571) - (Add a 
"Run to here" option on paragraphs)
[ZEPPELIN-465](https://issues.apache.org/jira/browse/ZEPPELIN-465)     - 
(Capability to run all cells below the current cell)

### How should this be tested?
1. Click on the "Run: from first to this" or "Run: from this to last" in the 
dropdown menu. Paragraphs from the first/current to the current/last will be 
started in order.
2. Press the key combination: CTRL + SHIFT + ENTER.
A window will appear with the choice of the desired action.
![capture2](https://user-images.githubusercontent.com/25951039/33269914-58eff828-d393-11e7-9ebf-6437ec11c8f2.PNG)
Choose one of two actions. The selected action will be performed.

### Screenshots (if appropriate)

![capture1_edit](https://user-images.githubusercontent.com/25951039/33269915-5951b19e-d393-11e7-831b-42d4523908ae.png)

### Questions:
* Does the licenses files need update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? no

Author: tinkoff-dwh <tinkoff....@gmail.com>

Closes #2688 from tinkoff-dwh/ZEPPELIN-2571&465 and squashes the following 
commits:

304c196 [tinkoff-dwh] [ZEPPELIN-2517]&[ZEPPELIN-465] fix shortcut description
3d57b30 [tinkoff-dwh] [ZEPPELIN-2517]&[ZEPPELIN-465] save paragraph's focus
70f130c [tinkoff-dwh] [Zeppelin-2517]&[Zeppelin-465] some text change
8ca1df2 [tinkoff-dwh] [Zeppelin-2517]&[Zeppelin-465] line reduction
a7a4158 [tinkoff-dwh] [ZEPPELIN-2517]&[ZEPPELIN-465] logic change
9fbcdb6 [tinkoff-dwh] [ZEPPELIN-2517]&[ZEPPELIN-465] add keyboard shortcut
bfc3891 [tinkoff-dwh] [ZEPPELIN-2517]&[ZEPPELIN-465] Run paragraphs from 1st to 
this. From this to last


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/38ba2d47
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/38ba2d47
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/38ba2d47

Branch: refs/heads/master
Commit: 38ba2d47569300dd2a31bc9141d7439b0d370091
Parents: 625b268
Author: tinkoff-dwh <tinkoff....@gmail.com>
Authored: Thu Nov 30 10:55:14 2017 +0300
Committer: Lee moon soo <m...@apache.org>
Committed: Fri Dec 1 11:53:49 2017 -0800

----------------------------------------------------------------------
 .../src/app/notebook/notebook.controller.js     | 90 +++++++++++++++++++-
 .../notebook/paragraph/paragraph-control.html   | 18 ++++
 .../notebook/paragraph/paragraph.controller.js  | 56 ++++++++++--
 zeppelin-web/src/app/notebook/shortcut.html     | 11 +++
 4 files changed, 166 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/38ba2d47/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 48fc6e7..1fa6323 100644
--- a/zeppelin-web/src/app/notebook/notebook.controller.js
+++ b/zeppelin-web/src/app/notebook/notebook.controller.js
@@ -164,7 +164,7 @@ function NotebookCtrl ($scope, $route, $routeParams, 
$location, $rootScope,
     for (let i = 0; i < $scope.note.paragraphs.length; i++) {
       let paragraphId = $scope.note.paragraphs[i].id
       if (jQuery.contains(angular.element('#' + paragraphId + 
'_container')[0], clickEvent.target)) {
-        $scope.$broadcast('focusParagraph', paragraphId, 0, true)
+        $scope.$broadcast('focusParagraph', paragraphId, 0, null, true)
         break
       }
     }
@@ -512,7 +512,7 @@ function NotebookCtrl ($scope, $route, $routeParams, 
$location, $rootScope,
         para.focus = true
 
         // we need `$timeout` since angular DOM might not be initialized
-        $timeout(() => { $scope.$broadcast('focusParagraph', para.id, 0, 
false) })
+        $timeout(() => { $scope.$broadcast('focusParagraph', para.id, 0, null, 
false) })
       }
     })
   }
@@ -1188,6 +1188,92 @@ function NotebookCtrl ($scope, $route, $routeParams, 
$location, $rootScope,
    ** $scope.$on functions below
    */
 
+  $scope.$on('runAllAbove', function (event, paragraph, isNeedConfirm) {
+    let allParagraphs = $scope.note.paragraphs
+    let toRunParagraphs = []
+
+    for (let i = 0; allParagraphs[i] !== paragraph; i++) {
+      if (i === allParagraphs.length - 1) { return } // if paragraph not in 
array of all paragraphs
+      toRunParagraphs.push(allParagraphs[i])
+    }
+
+    const paragraphs = toRunParagraphs.map(p => {
+      return {
+        id: p.id,
+        title: p.title,
+        paragraph: p.text,
+        config: p.config,
+        params: p.settings.params
+      }
+    })
+
+    if (!isNeedConfirm) {
+      websocketMsgSrv.runAllParagraphs($scope.note.id, paragraphs)
+    } else {
+      BootstrapDialog.confirm({
+        closable: true,
+        title: '',
+        message: 'Run all above?',
+        callback: function (result) {
+          if (result) {
+            websocketMsgSrv.runAllParagraphs($scope.note.id, paragraphs)
+          }
+        }
+      })
+    }
+
+    $scope.saveCursorPosition(paragraph)
+  })
+
+  $scope.$on('runAllBelowAndCurrent', function (event, paragraph, 
isNeedConfirm) {
+    let allParagraphs = $scope.note.paragraphs
+    let toRunParagraphs = []
+
+    for (let i = allParagraphs.length - 1; allParagraphs[i] !== paragraph; 
i--) {
+      if (i < 0) { return } // if paragraph not in array of all paragraphs
+      toRunParagraphs.push(allParagraphs[i])
+    }
+
+    toRunParagraphs.push(paragraph)
+    toRunParagraphs.reverse()
+
+    const paragraphs = toRunParagraphs.map(p => {
+      return {
+        id: p.id,
+        title: p.title,
+        paragraph: p.text,
+        config: p.config,
+        params: p.settings.params
+      }
+    })
+
+    if (!isNeedConfirm) {
+      websocketMsgSrv.runAllParagraphs($scope.note.id, paragraphs)
+    } else {
+      BootstrapDialog.confirm({
+        closable: true,
+        title: '',
+        message: 'Run current and all below?',
+        callback: function (result) {
+          if (result) {
+            websocketMsgSrv.runAllParagraphs($scope.note.id, paragraphs)
+          }
+        }
+      })
+    }
+
+    $scope.saveCursorPosition(paragraph)
+  })
+
+  $scope.saveCursorPosition = function (paragraph) {
+    let angParagEditor = angular
+      .element('#' + paragraph.id + '_paragraphColumn_main')
+      .scope().editor
+    let col = angParagEditor.selection.lead.column
+    let row = angParagEditor.selection.lead.row
+    $scope.$broadcast('focusParagraph', paragraph.id, row + 1, col)
+  }
+
   $scope.$on('setConnectedStatus', function (event, param) {
     if (connectedOnce && param) {
       initNotebook()

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/38ba2d47/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html 
b/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html
index d659972..0b4ca1e 100644
--- a/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html
+++ b/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html
@@ -141,6 +141,24 @@ limitations under the License.
           </a>
         </li>
         <li>
+          <a ng-click="runAllToThis(paragraph)" ng-hide="$first">
+            <span class="icon-action-redo shortcut-icon"
+                  style="position: relative; transform: rotate(-90deg); left: 
-4px;">
+            </span>
+            <span class="shortcut-keys">Ctrl+Shift+Enter</span>
+            Run all above
+          </a>
+        </li>
+        <li>
+          <a ng-click="runAllFromThis(paragraph)" ng-hide="$last">
+            <span class="icon-action-undo shortcut-icon"
+                  style="position: relative; transform: rotate(-90deg); left: 
-4px;">
+            </span>
+            <span class="shortcut-keys">Ctrl+Shift+Enter</span>
+             Run all below
+          </a>
+        </li>
+        <li>
           <a ng-click="copyParagraph(getEditorValue())"><span class="fa 
fa-copy shortcut-icon"></span>
             <span class="shortcut-keys">Ctrl+Shift+C</span>
             Clone paragraph

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/38ba2d47/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js 
b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
index c578841..d3ed346 100644
--- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
+++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
@@ -471,6 +471,43 @@ function ParagraphCtrl ($scope, $rootScope, $route, 
$window, $routeParams, $loca
     $scope.runParagraph($scope.getEditorValue(), false, false)
   }
 
+  $scope.runAllToThis = function(paragraph) {
+    $scope.$emit('runAllAbove', paragraph, true)
+  }
+
+  $scope.runAllFromThis = function(paragraph) {
+    $scope.$emit('runAllBelowAndCurrent', paragraph, true)
+  }
+
+  $scope.runAllToOrFromThis = function (paragraph) {
+    BootstrapDialog.show({
+      message: 'Run paragraphs:',
+      title: '',
+      buttons: [{
+        label: 'Close',
+        action: function(dialog) {
+          dialog.close()
+        }
+      },
+      {
+        label: 'Run all above',
+        cssClass: 'btn-primary',
+        action: function(dialog) {
+          $scope.$emit('runAllAbove', paragraph, false)
+          dialog.close()
+        }
+      },
+      {
+        label: 'Run current and all below',
+        cssClass: 'btn-primary',
+        action: function(dialog) {
+          $scope.$emit('runAllBelowAndCurrent', paragraph, false)
+          dialog.close()
+        }
+      }]
+    })
+  }
+
   $scope.turnOnAutoRun = function (paragraph) {
     paragraph.config.runOnSelectionChange = 
!paragraph.config.runOnSelectionChange
     commitParagraph(paragraph)
@@ -1446,8 +1483,10 @@ function ParagraphCtrl ($scope, $rootScope, $route, 
$window, $routeParams, $loca
         // move focus to next paragraph
         // $timeout stops chaining effect of focus propogation
         $timeout(() => $scope.$emit('moveFocusToNextParagraph', paragraphId))
-      } else if (keyEvent.shiftKey && keyCode === 13) { // Shift + Enter
+      } else if (!keyEvent.ctrlKey && keyEvent.shiftKey && keyCode === 13) { 
// Shift + Enter
         $scope.runParagraphFromShortcut($scope.getEditorValue())
+      } else if (keyEvent.ctrlKey && keyEvent.shiftKey && keyCode === 13) { // 
Ctrl + Shift + Enter
+        $scope.runAllToOrFromThis($scope.paragraph)
       } else if (keyEvent.ctrlKey && keyEvent.altKey && keyCode === 67) { // 
Ctrl + Alt + c
         $scope.cancelParagraph($scope.paragraph)
       } else if (keyEvent.ctrlKey && keyEvent.altKey && keyCode === 68) { // 
Ctrl + Alt + d
@@ -1500,7 +1539,10 @@ function ParagraphCtrl ($scope, $rootScope, $route, 
$window, $routeParams, $loca
     }
   })
 
-  $scope.$on('focusParagraph', function (event, paragraphId, cursorPos, 
mouseEvent) {
+  $scope.$on('focusParagraph', function (event, paragraphId, cursorPosRow, 
cursorPosCol, mouseEvent) {
+    if (cursorPosCol === null || cursorPosCol === undefined) {
+      cursorPosCol = 0
+    }
     if ($scope.paragraph.id === paragraphId) {
       // focus editor
       if (!$scope.paragraph.config.editorHide) {
@@ -1508,14 +1550,14 @@ function ParagraphCtrl ($scope, $rootScope, $route, 
$window, $routeParams, $loca
           $scope.editor.focus()
           // move cursor to the first row (or the last row)
           let row
-          if (cursorPos >= 0) {
-            row = cursorPos
-            $scope.editor.gotoLine(row, 0)
+          if (cursorPosRow >= 0) {
+            row = cursorPosRow
+            $scope.editor.gotoLine(row, cursorPosCol)
           } else {
             row = $scope.editor.session.getLength()
-            $scope.editor.gotoLine(row, 0)
+            $scope.editor.gotoLine(row, cursorPosCol)
           }
-          $scope.scrollToCursor($scope.paragraph.id, 0)
+          $scope.scrollToCursor($scope.paragraph.id, cursorPosCol)
         }
       }
       handleFocus(true)

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/38ba2d47/zeppelin-web/src/app/notebook/shortcut.html
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/shortcut.html 
b/zeppelin-web/src/app/notebook/shortcut.html
index c4b4009..9bc5597 100644
--- a/zeppelin-web/src/app/notebook/shortcut.html
+++ b/zeppelin-web/src/app/notebook/shortcut.html
@@ -39,6 +39,17 @@ limitations under the License.
 
           <tr>
             <td>
+              <div class="col-md-8">Run all above/below paragraphs</div>
+            </td>
+            <td>
+              <div class="keys">
+                <kbd class="kbd-default">Ctrl</kbd> + <kbd 
class="kbd-default">Shift</kbd> + <kbd class="kbd-default">Enter</kbd>
+              </div>
+            </td>
+          </tr>
+
+          <tr>
+            <td>
               <div class="col-md-8">Cancel</div>
             </td>
             <td>

Reply via email to