فهرست منبع

HUE-4982 [editor] Use the nav api endpoint for search autocomplete

Johan Ahlen 9 سال پیش
والد
کامیت
7c3683a
2فایلهای تغییر یافته به همراه53 افزوده شده و 7 حذف شده
  1. 16 0
      desktop/core/src/desktop/static/desktop/js/apiHelper.js
  2. 37 7
      desktop/core/src/desktop/templates/assist.mako

+ 16 - 0
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -1148,6 +1148,22 @@
     }));
   };
 
+  ApiHelper.prototype.navSearchAutocomplete = function (options) {
+    var self = this;
+    $.post('/metadata/api/navigator/search_entities_interactive', {
+      query_s: options.query,
+      limit: 5,
+      sources: '["hive"]',
+      field_facets: '["tags"]'
+    }).done(function (data) {
+      if (data.status === 0 && !self.successResponseIsError(data)) {
+        options.successCallback(data);
+      } else {
+        self.assistErrorCallback(options)(data);
+      }
+    }).fail(self.assistErrorCallback(options));
+  };
+
   /**
    * @param {Object} options
    * @param {string} options.sourceType

+ 37 - 7
desktop/core/src/desktop/templates/assist.mako

@@ -1246,7 +1246,43 @@ from metadata.conf import has_navigator
 
         self.navAutocompleteSource = function (request, callback) {
           var term = request.term;
-          callback([{ data: { label: 'a', icon: 'fa-beer' }, value: 'a' }, { data: { label: 'b', icon: 'fa-bullhorn' }, value: 'b' }]);
+          self.apiHelper.navSearchAutocomplete({
+            query:  term + '*',
+            successCallback: function (data) {
+              var values = [];
+              if (typeof data.facets !== 'undefined') {
+                Object.keys(data.facets).forEach(function (facet) {
+                  if (facet === 'tags') {
+                    values.push({ data: { label: 'tags:', icon: 'fa-tags' }, value: 'tags:'});
+                  }
+                });
+              }
+              if (typeof data.results !== 'undefined') {
+                data.results.forEach(function (result) {
+                  var icon = '';
+                  switch (result.type) {
+                    case 'TABLE':
+                      icon = 'fa-table';
+                      break;
+                    case 'VIEW':
+                      icon = 'fa-eye';
+                      break;
+                  }
+                  if (data.highlting && data.highlighting[result.identity] && data.highlighting[result.identity].originalName) {
+                    values.push({ data: { label: data.highlighting[result.identity].originalName, icon: icon }, value: result.originalName });
+                  } else {
+                    values.push({ data: { label: result.originalName, icon: icon }, value: result.originalName });
+                  }
+                });
+                callback(values);
+              }
+            },
+            silenceErrors: true,
+            errorCallback: function () {
+              callback([]);
+            }
+          });
+
         };
 
         self.searchHasFocus = ko.observable(false);
@@ -1258,12 +1294,6 @@ from metadata.conf import has_navigator
 
         var lastQuery = -1;
 
-        self.searchHasFocus.subscribe(function (newValue) {
-          if (newValue && lastQuery !== self.searchInput()) {
-            window.setTimeout(self.performSearch, 200);
-          }
-        });
-
         self.loading = ko.observable(false);
 
         self.availablePanels = [