Browse Source

HUE-3856 [editor] Backend search for the query history

Enrico Berti 9 years ago
parent
commit
6cfac76c05

+ 6 - 7
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -33,8 +33,7 @@
       "ace", "autocompleter", "availableSnippets", "history", "images", "inFocus", "selectedStatement", "user",
       "availableDatabases", "hasProperties", "aceMode", "snippetImage", "errorLoadingQueries",
       "cleanedStringMeta", "cleanedDateTimeMeta", "cleanedMeta", "cleanedNumericMeta",
-      "dependents", "canWrite",
-      "filteredHistory", "queries"
+      "dependents", "canWrite", "queries"
     ]
   };
 
@@ -1068,11 +1067,10 @@
     self.historyFilter = ko.observable('');
     self.historyFilterVisible = ko.observable(false);
     self.historyFilter.extend({ rateLimit: 300 });
-    self.filteredHistory = ko.computed(function () {
-      return ko.utils.arrayFilter(self.history(), function (item) {
-        return item.name().toLowerCase().indexOf(self.historyFilter()) > -1 || item.query().toLowerCase().indexOf(self.historyFilter()) > -1
-      });
+    self.historyFilter.subscribe(function(val){
+      self.fetchHistory();
     });
+
     self.loadingHistory = ko.observable(self.history().length == 0);
     // TODO: Move fetchHistory and clearHistory into the Snippet and drop self.selectedSnippet. Actually, history should go in the assist in Hue 4.
     self.getSession = function (session_type) {
@@ -1374,7 +1372,8 @@
       self.loadingHistory(true);
       $.get("/notebook/api/get_history", {
         doc_type: self.selectedSnippet(),
-        limit: 50
+        limit: 50,
+        doc_text: self.historyFilter()
       }, function(data) {
         var parsedHistory = [];
         if (data && data.history){

+ 10 - 7
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1033,7 +1033,7 @@ ${ hueIcons.symbols() }
       <ul class="nav nav-tabs">
         <li data-bind="click: function(){ currentQueryTab('queryHistory'); }, css: {'active': currentQueryTab() == 'queryHistory'}">
           <a class="inactive-action" href="#queryHistory" data-toggle="tab">${_('Query History')}
-            <div class="inline-block inactive-action margin-left-10 pointer" title="${_('Search the query history')}" data-bind="visible: $parent.history().length > 0, click: function(data, e){ $parent.historyFilterVisible(!$parent.historyFilterVisible()); window.setTimeout(function(){ $(e.target).parent().siblings('input').focus(); }, 0); }"><i class="snippet-icon fa fa-search"></i></div>
+            <div class="inline-block inactive-action margin-left-10 pointer" title="${_('Search the query history')}" data-bind="click: function(data, e){ $parent.historyFilterVisible(!$parent.historyFilterVisible()); window.setTimeout(function(){ $(e.target).parent().siblings('input').focus(); }, 0); }"><i class="snippet-icon fa fa-search"></i></div>
             <input class="input-small history-filter" type="text" data-bind="visible: $parent.historyFilterVisible, clearable: $parent.historyFilter, valueUpdate:'afterkeydown'" placeholder="${ _('Search...') }">
             <div class="inline-block inactive-action pointer" title="${_('Clear the query history')}" data-target="#clearHistoryModal" data-toggle="modal" rel="tooltip" data-bind="visible: $parent.history().length > 0"><i class="snippet-icon fa fa-calendar-times-o"></i></div>
           </a>
@@ -1068,15 +1068,18 @@ ${ hueIcons.symbols() }
           <!-- /ko -->
 
           <!-- ko ifnot: $parent.loadingHistory -->
-            <!-- ko if: $parent.history().length === 0 -->
+
+            <!-- ko if: $parent.history().length === 0 && $parent.historyFilter() === '' -->
             <div class="margin-top-20 margin-left-10" style="font-style: italic">${ _("No queries to be shown.") }</div>
             <!-- /ko -->
+            <!-- ko if: $parent.history().length === 0 && $parent.historyFilter() !== '' -->
+            <div class="margin-top-20 margin-left-10" style="font-style: italic">${ _('No queries found for') } <strong data-bind="text: $parent.historyFilter"></strong>.</div>
+            <!-- /ko -->
+
+
             <!-- ko if: $parent.history().length > 0 -->
-              <!-- ko if: $parent.history().length > 0 && $parent.filteredHistory().length == 0 -->
-                <div class="muted margin-left-10 margin-top-10">${ _('No queries found for') } <strong data-bind="text: $parent.historyFilter"></strong>.</div>
-              <!-- /ko -->
             <table class="table table-condensed margin-top-10 history-table">
-              <tbody data-bind="foreach: $parent.filteredHistory">
+              <tbody data-bind="foreach: $parent.history">
                 <tr data-bind="click: function() { if (uuid() != $root.selectedNotebook().uuid()) { $root.openNotebook(uuid()); } }, css: { 'highlight': uuid() == $root.selectedNotebook().uuid(), 'pointer': uuid() != $root.selectedNotebook().uuid() }">
                   <td style="width: 100px" class="muted" data-bind="style: {'border-top-width': $index() == 0 ? '0' : ''}">
                     <span data-bind="momentFromNow: {data: lastExecuted, interval: 10000, titleFormat: 'LLL'}"></span>
@@ -1106,7 +1109,7 @@ ${ hueIcons.symbols() }
           <!-- /ko -->
         </div>
 
-        <div class="tab-pane" id="savedQueries" data-bind="css: {'active': currentQueryTab() == 'savedQueries'}">
+        <div class="tab-pane" id="savedQueries" data-bind="css: {'active': currentQueryTab() == 'savedQueries'}" style="overflow: hidden">
           <!-- ko if: loadingQueries -->
           <div style="padding: 20px">
             <i class="fa fa-spinner fa-spin muted"></i>