Sfoglia il codice sorgente

HUE-5590 [importer] Fixed file type selectize

Enrico Berti 9 anni fa
parent
commit
8c1b943

+ 9 - 5
desktop/core/src/desktop/static/desktop/js/ko.selectize.js

@@ -38,10 +38,14 @@ ko.bindingHandlers.selectize = {
 
     ko.bindingHandlers.options.update(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
 
-    var options = {
-      valueField: allBindingsAccessor.get('optionsValue'),
-      labelField: allBindingsAccessor.get('optionsText'),
-      searchField: allBindingsAccessor.get('optionsText')
+    var options = {};
+    if (allBindingsAccessor.get('optionsValue')) {
+      options.valueField = allBindingsAccessor.get('optionsValue');
+    }
+
+    if (allBindingsAccessor.get('optionsText')) {
+      options.labelField = allBindingsAccessor.get('optionsText'),
+      options.searchField = allBindingsAccessor.get('optionsText')
     }
 
     if (allBindingsAccessor.has('selectizeOptions')) {
@@ -123,7 +127,7 @@ ko.bindingHandlers.selectize = {
   update: function (element, valueAccessor, allBindingsAccessor) {
 
     if (allBindingsAccessor.has('object')) {
-      var optionsValue = allBindingsAccessor.get('optionsValue') || 'id';
+      var optionsValue = allBindingsAccessor.get('optionsValue') || 'value';
       var value_accessor = valueAccessor();
       var selected_obj = $.grep(value_accessor(), function (i) {
         if (typeof i[optionsValue] == 'function')

+ 23 - 7
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -280,7 +280,7 @@ ${ assist.assistPanel() }
       <!-- ko ifnot: createWizard.isGuessingFormat -->
       <h3 class="card-heading simple">${_('Format')}</h3>
       <div class="card-body">
-        <label data-bind="visible: ! createWizard.prefill.source_type"><div>${_('File Type')}</div> <select data-bind="selectize: $root.createWizard.fileTypes, value: $root.createWizard.fileType, optionsText: 'description'"></select></label>
+        <label data-bind="visible: ! createWizard.prefill.source_type"><div>${_('File Type')}</div> <select data-bind="selectize: $root.createWizard.fileTypes, value: $root.createWizard.fileTypeName, optionsText: 'description', optionsValue: 'name'"></select></label>
         <span data-bind="with: createWizard.source.format, visible: createWizard.source.show">
           <!-- ko template: {name: 'format-settings'} --> <!-- /ko -->
         </span>
@@ -1135,6 +1135,16 @@ ${ assist.assistPanel() }
         }
       });
 
+      self.fileTypeName = ko.observable();
+      self.fileTypeName.subscribe(function (newType) {
+        for (var i = 0; i < self.fileTypes.length; i++) {
+          if (self.fileTypes[i].name == newType) {
+            self.fileType(self.fileTypes[i]);
+            break;
+          }
+        }
+      });
+
       self.operationTypes = ${operators_json | n};
 
       self.fieldTypes = ${fields_json | n}.solr;
@@ -1171,20 +1181,26 @@ ${ assist.assistPanel() }
         return self.destination.name().length > 0 && validFields;
       });
 
-      self.source.format.subscribe(function () {
+      self.formatTypeSubscribed = false;
+
+      self.source.format.subscribe(function (newVal) {
         for (var i = 0; i < self.fileTypes.length; i++) {
           if (self.fileTypes[i].name == self.source.format().type()) {
             self.fileType(self.fileTypes[i]);
+            self.fileTypeName(self.fileTypes[i].name);
             break;
           }
         }
 
         if (self.source.format().type) {
-          self.source.format().type.subscribe(function (newType) {
-            self.source.format(new FileType(newType));
-            self.destination.columns.removeAll();
-            self.guessFieldTypes();
-          });
+          if (!self.formatTypeSubscribed) {
+            self.formatTypeSubscribed = true;
+            self.source.format().type.subscribe(function (newType) {
+              self.source.format(new FileType(newType));
+              self.destination.columns.removeAll();
+              self.guessFieldTypes();
+            });
+          }
         }
       });