This is an automated email from the ASF dual-hosted git repository.

zjffdu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/master by this push:
     new e543d71  [ZEPPELIN-3751]. Interpreter Binding menu of note only shows 
default interpreter
e543d71 is described below

commit e543d716a8b7f8bbb9ed679fcbdcd3e7e73c7d48
Author: Jeff Zhang <zjf...@apache.org>
AuthorDate: Wed Feb 12 22:03:23 2020 +0800

    [ZEPPELIN-3751]. Interpreter Binding menu of note only shows default 
interpreter
    
    ### What is this PR for?
    This PR allow user to set default interpreter in frontend.  After this PR, 
user can only change default interpreter group in frontend via move it to the 
first of interpreter binding list. User still don't need to bind/unbind 
interpreters explicitly. They can use what ever interpreter they want. And we 
will list the default interpreter group, interpreter group with the same group 
of default interpreter group and all the interpreters used in the note.
    
    ### What type of PR is it?
    [Feature]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-3751
    
    ### How should this be tested?
    * CI pass
    
    ### Screenshots (if appropriate)
    
![spark_switch](https://user-images.githubusercontent.com/164491/74298501-f33b6800-4d84-11ea-8352-f63d227a996f.gif)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Jeff Zhang <zjf...@apache.org>
    
    Closes #3641 from zjffdu/ZEPPELIN-3751 and squashes the following commits:
    
    817d3ec9d [Jeff Zhang] address comment
    188a5a225 [Jeff Zhang] [ZEPPELIN-3751]. Interpreter Binding menu of note 
only shows default interpreter
---
 .../org/apache/zeppelin/socket/NotebookServer.java | 25 ++++++++++++++++++++++
 .../src/app/notebook/notebook.controller.js        | 10 ++++-----
 zeppelin-web/src/app/notebook/notebook.html        |  2 --
 .../websocket/websocket-message.service.js         |  4 ++--
 .../java/org/apache/zeppelin/notebook/Note.java    | 24 +++++++++++++++------
 .../apache/zeppelin/notebook/socket/Message.java   |  1 +
 6 files changed, 50 insertions(+), 16 deletions(-)

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 292b96f..0f1188b 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
@@ -422,6 +422,9 @@ public class NotebookServer extends WebSocketServlet
         case GET_INTERPRETER_BINDINGS:
           getInterpreterBindings(conn, messagereceived);
           break;
+        case SAVE_INTERPRETER_BINDINGS:
+          saveInterpreterBindings(conn, messagereceived);
+          break;
         case EDITOR_SETTING:
           getEditorSetting(conn, messagereceived);
           break;
@@ -539,6 +542,28 @@ public class NotebookServer extends WebSocketServlet
         new Message(OP.INTERPRETER_BINDINGS).put("interpreterBindings", 
settingList)));
   }
 
+  public void saveInterpreterBindings(NotebookSocket conn, Message 
fromMessage) throws IOException {
+    List<InterpreterSettingsList> settingList = new ArrayList<>();
+    String noteId = (String) fromMessage.data.get("noteId");
+    Note note = getNotebook().getNote(noteId);
+    if (note != null) {
+      List<String> settingIdList =
+              
gson.fromJson(String.valueOf(fromMessage.data.get("selectedSettingIds")),
+                      new TypeToken<ArrayList<String>>() {}.getType());
+      if (!settingIdList.isEmpty()) {
+        note.setDefaultInterpreterGroup(settingIdList.get(0));
+      }
+      List<InterpreterSetting> bindedSettings = 
note.getBindedInterpreterSettings();
+      for (InterpreterSetting setting : bindedSettings) {
+        settingList.add(new InterpreterSettingsList(setting.getId(), 
setting.getName(),
+                setting.getInterpreterInfos(), true));
+      }
+    }
+
+    conn.send(serializeMessage(
+            new Message(OP.INTERPRETER_BINDINGS).put("interpreterBindings", 
settingList)));
+  }
+
   public void broadcastNote(Note note) {
     inlineBroadcastNote(note);
     broadcastClusterEvent(ClusterEvent.BROADCAST_NOTE, note);
diff --git a/zeppelin-web/src/app/notebook/notebook.controller.js 
b/zeppelin-web/src/app/notebook/notebook.controller.js
index 8ce4408..aed2abe 100644
--- a/zeppelin-web/src/app/notebook/notebook.controller.js
+++ b/zeppelin-web/src/app/notebook/notebook.controller.js
@@ -1251,11 +1251,11 @@ function NotebookCtrl($scope, $route, $routeParams, 
$location, $rootScope,
   };
 
   const isSettingDirty = function() {
-    // if (angular.equals($scope.interpreterBindings, 
$scope.interpreterBindingsOrig)) {
-    //   return false;
-    // } else {
-    return false;
-    // }
+    if (angular.equals($scope.interpreterBindings, 
$scope.interpreterBindingsOrig)) {
+      return false;
+    } else {
+      return true;
+    }
   };
 
   const isPermissionsDirty = function() {
diff --git a/zeppelin-web/src/app/notebook/notebook.html 
b/zeppelin-web/src/app/notebook/notebook.html
index ae23f76..666e257 100644
--- a/zeppelin-web/src/app/notebook/notebook.html
+++ b/zeppelin-web/src/app/notebook/notebook.html
@@ -42,12 +42,10 @@ limitations under the License.
         <div data-ng-repeat="item in interpreterBindings" as-sortable-item>
           <div>
             <a ng-click="restartInterpreter(item)"
-               ng-class="{'inactivelink': !item.selected}"
                uib-tooltip="Restart">
               <span class="glyphicon glyphicon-refresh btn-md"></span>
             </a>&nbsp
             <div as-sortable-item-handle
-                 ng-click="item.selected = !item.selected"
                  class="btn"
                  ng-class="{'btn-info': item.selected, 'btn-default': 
!item.selected}">
               <font style="font-size:16px">{{item.name}}</font>
diff --git a/zeppelin-web/src/components/websocket/websocket-message.service.js 
b/zeppelin-web/src/components/websocket/websocket-message.service.js
index 8c30368..bbf987b 100644
--- a/zeppelin-web/src/components/websocket/websocket-message.service.js
+++ b/zeppelin-web/src/components/websocket/websocket-message.service.js
@@ -363,8 +363,8 @@ function WebsocketMessageService($rootScope, 
websocketEvents) {
     },
 
     saveInterpreterBindings: function(noteId, selectedSettingIds) {
-      // websocketEvents.sendNewEvent({op: 'SAVE_INTERPRETER_BINDINGS',
-      //   data: {noteId: noteId, selectedSettingIds: selectedSettingIds}});
+      websocketEvents.sendNewEvent({op: 'SAVE_INTERPRETER_BINDINGS',
+        data: {noteId: noteId, selectedSettingIds: selectedSettingIds}});
     },
 
     listConfigurations: function() {
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 ef6c9b2..966f5ba 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
@@ -976,7 +976,22 @@ public class Note implements JsonSerializable {
   }
 
   public List<InterpreterSetting> getBindedInterpreterSettings() {
-    Set<InterpreterSetting> settings = new HashSet<>();
+    // use LinkedHashSet because order matters, the first one represent the 
default interpreter setting.
+    Set<InterpreterSetting> settings = new LinkedHashSet<>();
+    // add the default interpreter group
+    InterpreterSetting defaultIntpSetting =
+            interpreterSettingManager.getByName(getDefaultInterpreterGroup());
+    if (defaultIntpSetting != null) {
+      settings.add(defaultIntpSetting);
+    }
+    // add the interpreter setting with the same group of default interpreter 
group
+    for (InterpreterSetting intpSetting : interpreterSettingManager.get()) {
+      if (intpSetting.getGroup().equals(defaultIntpSetting.getGroup())) {
+        settings.add(intpSetting);
+      }
+    }
+
+    // add interpreter group used by each paragraph
     for (Paragraph p : getParagraphs()) {
       try {
         Interpreter intp = p.getBindedInterpreter();
@@ -986,12 +1001,7 @@ public class Note implements JsonSerializable {
         // ignore this
       }
     }
-    // add the default interpreter group
-    InterpreterSetting defaultIntpSetting =
-            interpreterSettingManager.getByName(getDefaultInterpreterGroup());
-    if (defaultIntpSetting != null) {
-      settings.add(defaultIntpSetting);
-    }
+
     return new ArrayList<>(settings);
   }
 
diff --git 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/socket/Message.java
 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/socket/Message.java
index add65df..102f0fe 100644
--- 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/socket/Message.java
+++ 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/socket/Message.java
@@ -172,6 +172,7 @@ public class Message implements JsonSerializable {
     UNSUBSCRIBE_UPDATE_NOTE_JOBS, // [c-s] unsubscribe job information for job 
management
     // @param unixTime
     GET_INTERPRETER_BINDINGS,    // [c-s] get interpreter bindings
+    SAVE_INTERPRETER_BINDINGS,    // [c-s] save interpreter bindings
     INTERPRETER_BINDINGS,         // [s-c] interpreter bindings
 
     GET_INTERPRETER_SETTINGS,     // [c-s] get interpreter settings

Reply via email to