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/09/29 01:12:33 UTC

zeppelin git commit: Zeppelin-2922 Allow removing last paragrap

Repository: zeppelin
Updated Branches:
  refs/heads/master f7c47af9b -> 009184985


Zeppelin-2922 Allow removing last paragrap

### What is this PR for?
Before this change, it was not allowed to remove the last paragraph which would not make the notebook look clean.

After this change, it will be allowed to remove the last paragraph.
- Whenever there will be only one paragraph in the notebook, remove paragraph option will be hidden so that user will not able to make the notebook empty.

### What type of PR is it?
[Improvement]

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-2922

### How should this be tested?
1. Build: mvn clean package -Denforcer.skip -DskipTests -Drat.skip
2. Create paragraphs in a notebook and try to remove it
3. You can delete any paragraphs(even last paragraphs), but when there will be only one paragraph, remove button will be hidden

### Screenshots (if appropriate)

After:

![zep-2922 after](https://user-images.githubusercontent.com/1881135/30252063-78ee443c-9689-11e7-92dc-faae2ca273b2.gif)

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

Author: Malay Majithia <ma...@gmail.com>

Closes #2579 from malayhm/ZEPPELIN-2922 and squashes the following commits:

7c815ce [Malay Majithia] Removed unwanted line
1220f13 [Malay Majithia] Merge branch 'master' into ZEPPELIN-2922
73fd065 [Malay Majithia] ZEPPELIN-2922 Allow removing last paragraph


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

Branch: refs/heads/master
Commit: 00918498513a4217b3869acd65572c329c3cf9ce
Parents: f7c47af
Author: Malay Majithia <ma...@gmail.com>
Authored: Sun Sep 10 23:51:21 2017 +0530
Committer: Lee moon soo <mo...@apache.org>
Committed: Thu Sep 28 18:12:30 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/zeppelin/socket/NotebookServer.java   |  5 +++--
 .../src/app/notebook/paragraph/paragraph-control.html     |  2 +-
 .../src/app/notebook/paragraph/paragraph.controller.js    | 10 ++--------
 .../src/main/java/org/apache/zeppelin/notebook/Note.java  |  4 ++++
 4 files changed, 10 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00918498/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
index 2e3a5c7..1e7b74f 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
@@ -1297,9 +1297,10 @@ public class NotebookServer extends WebSocketServlet
       return;
     }
 
-    /** We dont want to remove the last paragraph */
     final Note note = notebook.getNote(noteId);
-    if (!note.isLastParagraph(paragraphId)) {
+
+    /** Don't allow removing paragraph when there is only one paragraph in the Notebook */
+    if (note.getParagraphCount() > 1) {
       AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
       Paragraph para = note.removeParagraph(subject.getUser(), paragraphId);
       note.persist(subject);

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00918498/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 fd4d701..d659972 100644
--- a/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html
+++ b/zeppelin-web/src/app/notebook/paragraph/paragraph-control.html
@@ -191,7 +191,7 @@ limitations under the License.
         </li>
         <li>
           <!-- remove paragraph -->
-          <a ng-click="removeParagraph(paragraph)" ng-hide="$last"><span class="fa fa-times shortcut-icon"></span>
+          <a ng-click="removeParagraph(paragraph)" ng-if="note.paragraphs.length > 1"><span class="fa fa-times shortcut-icon"></span>
             <span class="shortcut-keys">Ctrl+{{ isMac ? 'Option' : 'Alt'}}+D</span>
             Remove
           </a>

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00918498/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 b4c79dd..edc808f 100644
--- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
+++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
@@ -516,16 +516,10 @@ function ParagraphCtrl ($scope, $rootScope, $route, $window, $routeParams, $loca
   }
 
   $scope.removeParagraph = function (paragraph) {
-    let paragraphs = angular.element('div[id$="_paragraphColumn_main"]')
-    if (paragraphs[paragraphs.length - 1].id.indexOf(paragraph.id) === 0) {
+    if ($scope.note.paragraphs.length === 1) {
       BootstrapDialog.alert({
         closable: true,
-        message: 'The last paragraph can\'t be deleted.',
-        callback: function (result) {
-          if (result) {
-            $scope.editor.focus()
-          }
-        }
+        message: 'All the paragraphs can\'t be deleted.'
       })
     } else {
       BootstrapDialog.confirm({

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/00918498/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
index 5a42f37..03c5046 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java
@@ -507,6 +507,10 @@ public class Note implements ParagraphJobListener, JsonSerializable {
     return true;
   }
 
+  public int getParagraphCount() {
+    return paragraphs.size();
+  }
+
   public Paragraph getParagraph(String paragraphId) {
     synchronized (paragraphs) {
       for (Paragraph p : paragraphs) {