瀏覽代碼

HUE-6060 [importer] Ko-ify prefilling properly in order to work with responsive

Romain Rigaux 8 年之前
父節點
當前提交
b2c7c01

+ 1 - 1
desktop/core/src/desktop/templates/responsive.mako

@@ -678,7 +678,7 @@ ${ assist.assistPanel() }
           } else if (href.startsWith('/indexer/importer/prefill')){
               self.currentApp('importer');
               self.getActiveAppViewModel(function (viewModel) {
-                var arguments = href.match(/\/indexer\/importer\/prefill\/?([^/]+)\/?([^/]+)\/?([^/]+)/);
+                var arguments = href.match(/\/indexer\/importer\/prefill\/?([^/]+)\/?([^/]+)\/?([^/]+)?/);
                 if (! arguments) {
                   console.warn('Could not match ' + href)
                 }

+ 28 - 20
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -1139,14 +1139,14 @@ ${ assist.assistPanel() }
       self.sample = ko.observableArray();
       self.sampleCols = ko.observableArray();
 
-      self.inputFormat = ko.observable('file');
+      self.inputFormat = ko.observable(wizard.prefill.source_type() == 'manual' ? 'manual' : 'file');
       self.inputFormat.subscribe(function(val) {
         wizard.destination.columns.removeAll();
         self.sample.removeAll();
         self.path('');
         resizeElements();
       });
-      self.inputFormats = ko.observableArray([
+      self.inputFormatsAll = ko.observableArray([
           {'value': 'file', 'name': 'File'},
           {'value': 'manual', 'name': 'Manually'},
           % if ENABLE_NEW_INDEXER.get():
@@ -1156,15 +1156,16 @@ ${ assist.assistPanel() }
           ##{'value': 'dbms', 'name': 'DBMS'},
           ##{'value': 'text', 'name': 'Paste Text'},
       ]);
-      if (wizard.prefill.source_type().length > 0) {
-        self.inputFormats([
-            {'value': 'file', 'name': 'File'},
-            {'value': 'manual', 'name': 'Manually'},
-        ]);
+      self.inputFormatsManual = ko.observableArray([
+          {'value': 'manual', 'name': 'Manually'}
+      ]);
+      self.inputFormats = ko.pureComputed(function() {
         if (wizard.prefill.source_type() == 'manual') {
-          self.inputFormat(wizard.prefill.source_type());
+          return self.inputFormatsManual();
+        } else {
+          return self.inputFormatsAll();
         }
-      }
+      });
 
       // File
       self.path = ko.observable('');
@@ -1178,7 +1179,7 @@ ${ assist.assistPanel() }
       self.isObjectStore = ko.computed(function() {
         return self.inputFormat() == 'file' && /^s3a:\/\/.*$/.test(self.path());
       });
-      self.isObjectStore.subscribe(function(newVal) {console.log(newVal);
+      self.isObjectStore.subscribe(function(newVal) {
         vm.createWizard.destination.useDefaultLocation(! newVal);
       });
 
@@ -1314,9 +1315,9 @@ ${ assist.assistPanel() }
       self.apiHelperType = ko.observable('hive');
 
       self.description = ko.observable('');
-      self.outputFormat = ko.observable('table');
+      self.outputFormat = ko.observable(wizard.prefill.target_type() || 'table');
       self.outputFormat.subscribe(function (newValue) {
-        if (newValue != 'database') {
+        if (newValue && newValue != 'database' && (newValue == 'table' && wizard.source.path().length > 0)) {
           wizard.guessFieldTypes();
           resizeElements();
         }
@@ -1338,12 +1339,14 @@ ${ assist.assistPanel() }
           return true;
         })
       });
-      if (wizard.prefill.target_type().length > 0) {
-        self.outputFormat(wizard.prefill.target_type());
-        if (wizard.prefill.target_type() == 'database') {
+      wizard.prefill.target_type.subscribe(function(newValue) {
+        self.outputFormat(newValue || 'table');
+        if (newValue == 'database') {
           vm.currentStep(2);
-        };
-      }
+        } else {
+          vm.currentStep(1);
+        }
+      });
 
       self.format = ko.observable();
       self.columns = ko.observableArray();
@@ -1476,6 +1479,10 @@ ${ assist.assistPanel() }
       self.fileTypes = ${file_types_json | n};
       self.prefill = ko.mapping.fromJS(${prefill | n});
 
+      self.prefill.source_type.subscribe(function(newValue) {
+        self.source.inputFormat(newValue == 'manual' ? 'manual' : 'file');
+      });
+
       self.show = ko.observable(true);
       self.showCreate = ko.observable(false);
 
@@ -1773,14 +1780,16 @@ ${ assist.assistPanel() }
       self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
       self.loadDefaultField = loadDefaultField;
 
+      self.createWizard = new CreateWizard(self);
+
       // Wizard related
       self.wizardEnabled = ko.observable(false);
-      self.currentStep = ko.observable(1);
+      self.currentStep = ko.observable(self.createWizard.prefill.target_type() == 'database' ? 2 : 1);
       self.currentStep.subscribe(function () {
         $('.content-panel').scrollTop(0);
       });
       self.previousStepVisible = ko.pureComputed(function(){
-        return self.currentStep() > 1;
+        return self.currentStep() > 1 && self.createWizard.destination.outputFormat() != 'database';
       });
       self.nextStepVisible = ko.pureComputed(function(){
         return self.currentStep() < 3 && self.wizardEnabled();
@@ -1796,7 +1805,6 @@ ${ assist.assistPanel() }
         }
       }
 
-      self.createWizard = new CreateWizard(self);
       self.isLoading = ko.observable(false);
     };
 

+ 1 - 1
desktop/libs/indexer/src/indexer/views.py

@@ -97,7 +97,7 @@ def importer_prefill(request, source_type, target_type, target_path=None):
   prefill = {
     'source_type': source_type,
     'target_type': target_type,
-    'target_path': target_path
+    'target_path': target_path or ''
   }
   
   return _importer(request, prefill)

+ 1 - 1
desktop/libs/notebook/src/notebook/api.py

@@ -375,7 +375,7 @@ def _historify(notebook, user):
     type=query_type,
     owner=user,
     is_history=True,
-    is_managed=notebook.get('isManaged') == True
+    is_managed=notebook.get('isManaged') == True # No None
   )
 
   # Link history of saved query