Przeglądaj źródła

HUE-5635 [importer] Document chooser should be used for queries

Enrico Berti 9 lat temu
rodzic
commit
b884eeea1f

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

@@ -4919,6 +4919,9 @@
           if (options.document) {
           if (options.document) {
             options.document(this.options[val]);
             options.document(this.options[val]);
           }
           }
+          if (options.mappedDocument) {
+            options.mappedDocument(ko.mapping.fromJS(this.options[val]));
+          }
         },
         },
         onLoad: function () {
         onLoad: function () {
           if (options.value) {
           if (options.value) {
@@ -4936,6 +4939,10 @@
       if (options.value) {
       if (options.value) {
         element.selectize.setValue(options.value());
         element.selectize.setValue(options.value());
       }
       }
+      if (options.dependentValue && options.dependentValue() !== '') {
+        element.selectize.setValue(options.dependentValue());
+        options.dependentValue('');
+      }
     }
     }
   };
   };
 
 

+ 3 - 40
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -317,7 +317,7 @@ ${ assist.assistPanel() }
 
 
           <div class="control-group" data-bind="visible: createWizard.source.inputFormat() == 'query'">
           <div class="control-group" data-bind="visible: createWizard.source.inputFormat() == 'query'">
             <label for="path" class="control-label"><div>${ _('Query') }</div>
             <label for="path" class="control-label"><div>${ _('Query') }</div>
-              <select data-bind="selectize: createWizard.source.queries, value: createWizard.source.query, optionsText: 'name', optionsAfterRender: createWizard.source.selectQuery"></select>
+              <select placeholder="${ _('Search your documents...') }" data-bind="documentChooser: { dependentValue: createWizard.source.draggedQuery, mappedDocument: createWizard.source.query }"></select>
             </label>
             </label>
           </div>
           </div>
         </div>
         </div>
@@ -991,9 +991,6 @@ ${ assist.assistPanel() }
       self.inputFormat = ko.observable('file');
       self.inputFormat = ko.observable('file');
       self.inputFormat.subscribe(function(val) {
       self.inputFormat.subscribe(function(val) {
         wizard.destination.columns.removeAll();
         wizard.destination.columns.removeAll();
-        if (val == 'query') {
-          self.getDocuments();
-        }
       });
       });
       self.inputFormats = ko.observableArray([
       self.inputFormats = ko.observableArray([
           {'value': 'file', 'name': 'File'},
           {'value': 'file', 'name': 'File'},
@@ -1033,36 +1030,7 @@ ${ assist.assistPanel() }
 
 
       // Queries
       // Queries
       self.query = ko.observable('');
       self.query = ko.observable('');
-      self.queries = ko.observableArray([]);
       self.draggedQuery = ko.observable();
       self.draggedQuery = ko.observable();
-      self.getDocuments = function() {
-        $.get('/desktop/api2/docs/', {
-          type: 'query-hive',
-          include_trashed: false,
-          sort: '-last_modified',
-          limit: 100
-        }, function(data) {
-          if (data && data.documents) {
-            var queries = [];
-            $.each(data.documents, function(index, query) {
-              queries.push(ko.mapping.fromJS(query));
-            });
-            self.queries(queries);
-          }
-        });
-      };
-
-      var waitForRendered = -1;
-      self.selectQuery = function () {
-        window.clearTimeout(waitForRendered);
-        waitForRendered = window.setTimeout(function(){
-          if (self.draggedQuery()){
-            self.query(ko.utils.arrayFilter(self.queries(), function(q) {
-              return q.id() === self.draggedQuery();
-            })[0]);
-          }
-        }, 50);
-      }
 
 
       self.format = ko.observable();
       self.format = ko.observable();
       self.format.subscribe(function(newVal) {
       self.format.subscribe(function(newVal) {
@@ -1096,7 +1064,7 @@ ${ assist.assistPanel() }
           }
           }
         } else if (self.inputFormat() == 'query') {
         } else if (self.inputFormat() == 'query') {
           if (self.query()) {
           if (self.query()) {
-            name = val.name();
+            name = self.name();
           }
           }
         } else if (self.inputFormat() == 'manual') {
         } else if (self.inputFormat() == 'manual') {
           name = wizard.prefill.target_path ? wizard.prefill.target_path() + '.' : '';
           name = wizard.prefill.target_path ? wizard.prefill.target_path() + '.' : '';
@@ -1636,18 +1604,13 @@ ${ assist.assistPanel() }
               if (draggableMeta.definition.type === 'query-hive'){
               if (draggableMeta.definition.type === 'query-hive'){
                 generatedName += draggableMeta.definition.name;
                 generatedName += draggableMeta.definition.name;
                 viewModel.createWizard.source.inputFormat('query');
                 viewModel.createWizard.source.inputFormat('query');
-                viewModel.createWizard.source.draggedQuery(draggableMeta.definition.id);
+                viewModel.createWizard.source.draggedQuery(draggableMeta.definition.uuid);
               }
               }
               break;
               break;
           }
           }
           if (generatedName !== 'idx' && viewModel.createWizard.source.name() === ''){
           if (generatedName !== 'idx' && viewModel.createWizard.source.name() === ''){
             viewModel.createWizard.source.name(generatedName);
             viewModel.createWizard.source.name(generatedName);
           }
           }
-          else {
-            if (draggableMeta.table !== ''){
-              viewModel.createWizard.source.selectQuery();
-            }
-          }
         }
         }
       });
       });
     });
     });