Browse Source

[beeswax] Use the new assist events for db initialization

Johan Ahlen 10 năm trước cách đây
mục cha
commit
62be029

+ 15 - 1
apps/beeswax/src/beeswax/static/beeswax/js/beeswax.vm.js

@@ -72,7 +72,21 @@ function BeeswaxViewModel(server, assistHelper) {
     'isRedacted': false
   };
 
-  self.database = assistHelper.activeDatabase;
+  self.database = ko.observable(null);
+
+  var type = server === "beeswax" ? "hive" : "impala";
+  huePubSub.subscribe("assist.request.status", function () {
+    huePubSub.publish('assist.select.database', {
+      sourceType: type,
+      name: self.database()
+    });
+  });
+
+  huePubSub.subscribe("assist.database.selected", function (database) {
+    if (database.sourceType === type && self.database() !== database.name) {
+      self.database(database.name);
+    }
+  });
 
   self.design = ko.mapping.fromJS(DESIGN_DEFAULTS);
 

+ 6 - 0
desktop/core/src/desktop/static/desktop/js/assist/assistSource.js

@@ -103,6 +103,9 @@
     };
 
     self.setDatabase = function (databaseName) {
+      if (databaseName && self.selectedDatabase() && databaseName === self.selectedDatabase().definition.name) {
+        return;
+      }
       if (databaseName && dbIndex[databaseName]) {
         self.selectedDatabase(dbIndex[databaseName]);
         return;
@@ -116,6 +119,9 @@
     };
 
     self.initDatabases = function () {
+      if (self.loading()) {
+        return;
+      }
       self.loading(true);
       self.assistHelper.loadDatabases({
         sourceType: self.type,

+ 3 - 0
desktop/core/src/desktop/templates/assist.mako

@@ -310,6 +310,9 @@ from desktop.views import _ko
                 subscription.dispose();
               }
             });
+            if (! self.selectedSource().loaded() && ! self.selectedSource().loading()) {
+              self.selectedSource().initDatabases();
+            }
           }
         };
 

+ 5 - 4
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1021,10 +1021,11 @@
           name: self.snippets()[0].database()
         });
       }
-      huePubSub.publish('assist.select.database', {
-        sourceType: null,
-        name: null
-      });
+      // TODO: Uncomment when we switch to the new impala and hive editors
+      //huePubSub.publish('assist.select.database', {
+      //  sourceType: null,
+      //  name: null
+      //});
     });
   };