Browse Source

HUE-6028 [importer] The page shouldn't fail if the sample has less than 2 rows

Enrico Berti 8 years ago
parent
commit
defc5d8

+ 8 - 4
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -4339,6 +4339,7 @@
             });
           });
 
+      var withNiceScroll = !options.disableNiceScroll;
       var $wrapper = $element.parent();
       if (!$wrapper.hasClass('foreach-wrapper')) {
         $wrapper = $('<div>').css({
@@ -4351,7 +4352,7 @@
           'width': '100%'
         }).appendTo($wrapper);
 
-        if ($.fn.niceScroll) {
+        if ($.fn.niceScroll && withNiceScroll) {
           $container.niceScroll({
             cursorcolor: "#C1C1C1",
             cursorborder: "1px solid #C1C1C1",
@@ -4365,7 +4366,7 @@
         }
       } else {
         window.setTimeout(function(){
-          if ($.fn.niceScroll) {
+          if ($.fn.niceScroll && withNiceScroll) {
             $container.getNiceScroll().resize();
           }
         }, 200);
@@ -5201,9 +5202,12 @@
 
   ko.bindingHandlers.truncatedText = {
     update: function (element, valueAccessor, allBindingsAccessor) {
-      var text = ko.isObservable(valueAccessor()) ? ko.utils.unwrapObservable(valueAccessor()) : valueAccessor(),
-        length = ko.utils.unwrapObservable(allBindingsAccessor().maxLength) || 20,
+      var text = ko.isObservable(valueAccessor()) ? ko.utils.unwrapObservable(valueAccessor()) : valueAccessor();
+      var length = ko.utils.unwrapObservable(allBindingsAccessor().maxLength) || 20;
+      var truncated = '';
+      if (typeof text !== 'undefined' && text !== null){
         truncated = text.length > length ? text.substring(0, length) + '...' : text;
+      }
       ko.bindingHandlers.text.update(element, function () {
         return truncated;
       });

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

@@ -672,7 +672,7 @@ ${ assist.assistPanel() }
           <div class="card step">
             <h3 class="card-heading simple show-edit-on-hover">${_('Fields')} <!-- ko if: $root.createWizard.isGuessingFieldTypes --><i class="fa fa-spinner fa-spin"></i><!-- /ko --> <a class="inactive-action pointer" data-bind="visible: columns().length > 0" href="#fieldsBulkEditor" data-toggle="modal"><i class="fa fa-edit"></i></a></h3>
             <div class="card-body no-margin-top">
-              <form class="form-inline inline-table columns-form" data-bind="foreachVisible: { data: columns, minHeight: 44, container: '.content-panel' }">
+              <form class="form-inline inline-table columns-form" data-bind="foreachVisible: { data: columns, minHeight: 44, container: '.content-panel', disableNiceScroll: true }">
                 <!-- ko if: $parent.outputFormat() == 'table' -->
                   <!-- ko if: $root.createWizard.source.inputFormat() == 'manual' -->
                   <a class="pointer pull-right margin-top-20" data-bind="click: function() { $parent.columns.remove($data); }"><i class="fa fa-minus"></i></a>
@@ -796,8 +796,15 @@ ${ assist.assistPanel() }
       <a data-bind="click: function() { $parent.nested.remove($data); }"><i class="fa fa-minus"></i></a>
     <!-- /ko -->
     <!-- ko if: $root.createWizard.source.inputFormat() != 'manual' && level() == 0 && (typeof isPartition === 'undefined' || !isPartition()) -->
-      <div class="inline-block muted field-content-preview" data-bind="truncatedText: $root.createWizard.source.sample()[0][$index()]"></div>
-      <div class="inline-block muted field-content-preview" data-bind="truncatedText: $root.createWizard.source.sample()[1][$index()]"></div>
+      <!-- ko if: $root.createWizard.source.sample() && $root.createWizard.source.sample().length > 0 -->
+        <div class="inline-block muted field-content-preview" data-bind="truncatedText: $root.createWizard.source.sample()[0][$index()]"></div>
+        <!-- ko if: $root.createWizard.source.sample().length > 1 -->
+        <div class="inline-block muted field-content-preview" data-bind="truncatedText: $root.createWizard.source.sample()[1][$index()]"></div>
+        <!-- /ko -->
+      <!-- /ko -->
+      <!-- ko if: !$root.createWizard.source.sample() || $root.createWizard.source.sample().length === 0 -->
+      <div class="inline-block muted field-content-preview">${ _("No sample to be shown") }</div>
+      <!-- /ko -->
     <!-- /ko -->
 
     <!-- ko if: type() == 'array' || type() == 'map' || type() == 'struct' -->