Просмотр исходного кода

HUE-5005 [assist] Add filter for showing only active editor tables

Johan Ahlen 9 лет назад
Родитель
Сommit
982d7cb56c

+ 17 - 1
desktop/core/src/desktop/static/desktop/js/assist/assistDbEntry.js

@@ -81,11 +81,27 @@
     });
 
     self.filteredEntries = ko.pureComputed(function () {
-      if (self.filter == null || (self.filter.showTables && self.filter.showTables() && self.filter.showViews() && self.filter.query().length === 0)) {
+      if (self.filter == null || (self.filter.showTables && self.filter.showTables() && self.filter.showViews() && !self.filter.showActive() && self.filter.query().length === 0)) {
         return self.entries();
       }
       var result = [];
       $.each(self.entries(), function (index, entry) {
+        if (self.filter.showActive()) {
+          var found = false;
+          for (var i = 0; i < self.filter.activeEditorTables().length; i++) {
+            var activeTable = self.filter.activeEditorTables()[i];
+            if (activeTable.db && self.definition.name !== activeTable.db) {
+              continue;
+            }
+            if (activeTable.table === entry.definition.name) {
+              found = true;
+              break;
+            }
+          }
+          if (!found) {
+            return;
+          }
+        }
         if ((entry.definition.isTable && !self.filter.showTables()) || (entry.definition.isView && !self.filter.showViews()) ) {
           return;
         }

+ 15 - 1
desktop/core/src/desktop/static/desktop/js/assist/assistDbSource.js

@@ -113,8 +113,22 @@
     var nestedFilter = {
       query: ko.observable("").extend({ rateLimit: { timeout: 250, method: 'notifyWhenChangesStop' } }),
       showTables: ko.observable(true),
-      showViews: ko.observable(true)
+      enableActiveFilter: typeof window.Worker !== 'undefined',
+      showActive: ko.observable(false),
+      showViews: ko.observable(true),
+      activeEditorTables: ko.observableArray([])
     };
+
+    huePubSub.subscribe('editor.active.locations', function (locations) {
+      var activeTables = [];
+      locations.forEach(function (location) {
+        if (location.type === 'table') {
+          activeTables.push(location.identifierChain.length == 2 ? { table: location.identifierChain[1].name, db: location.identifierChain[0].name} : { table: location.identifierChain[0].name });
+        }
+      });
+      nestedFilter.activeEditorTables(activeTables);
+    });
+
     var updateDatabases = function (names, lastSelectedDb) {
       dbIndex = {};
       self.databases($.map(names, function(name) {

+ 1 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -2853,6 +2853,7 @@
               }
             });
           }
+          huePubSub.publish('editor.active.locations', e.data.locations);
           e.data.locations.forEach(function (location) {
             var token = editor.session.getTokenAt(location.location.first_line - 1, location.location.first_column);
             if (token !== null) {

+ 5 - 1
desktop/core/src/desktop/templates/assist.mako

@@ -785,7 +785,11 @@ from metadata.conf import has_navigator
       </div>
     </div>
     <div class="assist-flex-table-search" data-bind="visible: hasEntries() && isSearchVisible() && !$parent.loading() && !$parent.hasErrors()">
-      <div><label class="checkbox inline-block margin-left-5"><input type="checkbox" data-bind="checked: filter.showTables" />Tables</label><label class="checkbox inline-block margin-left-10"><input type="checkbox" data-bind="checked: filter.showViews" />Views</label></div>
+      <div>
+        <label class="checkbox inline-block margin-left-5"><input type="checkbox" data-bind="checked: filter.showTables" />${_('Tables')}</label>
+        <label class="checkbox inline-block margin-left-10"><input type="checkbox" data-bind="checked: filter.showViews" />${_('Views')}</label>
+        <label class="checkbox inline-block margin-left-10"><input type="checkbox" data-bind="visible: filter.enableActiveFilter, checked: filter.showActive" />${_('Active')}</label>
+      </div>
       <div><input id="searchInput" class="clearable" type="text" placeholder="${ _('Table name...') }" style="width:90%;" data-bind="hasFocus: editingSearch, clearable: filter.query, value: filter.query, valueUpdate: 'afterkeydown'"/></div>
     </div>
     <div class="assist-flex-fill assist-db-scrollable" data-bind="visible: ! hasErrors() && ! loading()" style="display: none;">