Преглед на файлове

[core] Make the autocompleter mode-aware

It can be set initially and will also be dependent on the ace editor in focus.
Johan Ahlen преди 10 години
родител
ревизия
8ae1a8a

+ 2 - 1
apps/beeswax/src/beeswax/templates/execute.mako

@@ -1129,7 +1129,8 @@ var HIVE_AUTOCOMPLETE_GLOBAL_CALLBACK = function (data) {
 var autocompleter = new Autocompleter({
   baseUrl: HIVE_AUTOCOMPLETE_BASE_URL,
   app: HIVE_AUTOCOMPLETE_APP,
-  user: HIVE_AUTOCOMPLETE_USER
+  user: HIVE_AUTOCOMPLETE_USER,
+  mode: HIVE_AUTOCOMPLETE_APP
 });
 
 var escapeOutput = function (str) {

+ 14 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete.js

@@ -23,6 +23,7 @@ var TIME_TO_LIVE_IN_MILLIS = 86400000; // 1 day
  * @param options.app
  * @param options.user
  * @param options.db
+ * @param options.mode
  *
  * @constructor
  */
@@ -30,10 +31,19 @@ function Autocompleter(options) {
   var self = this;
   self.options = options;
   self.currentDb = options.db;
+  if (typeof options.mode === "undefined" || options.mode === null || options.mode === "beeswax") {
+    self.currentMode = "hive";
+  } else {
+    self.currentMode = options.mode;
+  }
 
   huePubSub.subscribe('assist.mainObjectChange', function (db) {
     self.currentDb = db;
   });
+
+  huePubSub.subscribe('hue.ace.activeMode', function(mode) {
+    self.currentMode = mode.split("/").pop();
+  })
 }
 
 Autocompleter.prototype.hasExpired = function (timestamp) {
@@ -126,7 +136,10 @@ Autocompleter.prototype.fetchAssistData = function (url, successCallback, errorC
 Autocompleter.prototype.autocomplete = function(beforeCursor, afterCursor, callback) {
   var self = this;
 
-  if (typeof self.currentDb == "undefined" || self.currentDb == null || self.currentDb == "") {
+  if (typeof self.currentDb == "undefined"
+    || self.currentDb == null
+    || self.currentDb == ""
+    || (self.currentMode !== "hive" && self.currentMode !== "impala")) {
     callback([]);
     return;
   }

+ 5 - 2
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -1665,12 +1665,15 @@ ko.bindingHandlers.aceEditor = {
     $el.text(options.value());
 
     var editor = ace.edit($el.attr("id"));
-    editor.session.setMode(options.mode());
+    editor.session.setMode(ko.utils.unwrapObservable(options.mode));
     if (ko.isObservable(options.mode)) {
-      options.mode.subscribe(function(newValue) {
+      options.mode.subscribe(function (newValue) {
         editor.session.setMode(newValue);
       });
     }
+    editor.on("focus", function () {
+      huePubSub.publish("hue.ace.activeMode", ko.utils.unwrapObservable(options.mode));
+    });
 
     if (ko.isObservable(options.errors)) {
       options.errors.subscribe(function(errors) {