Эх сурвалжийг харах

HUE-2727 [spark] Only accept numeric input for numeric spark execution settings

With this commit the spark setting inputs for number of cores and executors are forced integers.

This commit adds a new ko binding handler for numeric text input. The binding can be used instead of the extender when desired, for instance when using the ko mapping plugin without custom mapping configuration. The binding makes use of the existing numeric extender and the ko textInput binding.

(cherry picked from commit e2f34f6e2b27b063b97b7d7e7d40234aac33f331)
Johan Ahlen 10 жил өмнө
parent
commit
d59014bded

+ 3 - 3
apps/spark/src/spark/templates/editor.mako

@@ -714,7 +714,7 @@ ${ commonheader(_('Query'), app_name, user, "68px") | n,unicode }
             <div class="control-group" style="float: left;">
               <label class="control-label">${_('Executor Cores')}</label>
               <div class="controls">
-                <input class="input-small" type="text" data-bind="textInput: executor_cores" />
+                <input class="input-small" type="text" data-bind="numericTextInput: { value: executor_cores, precision: 0 }" />
               </div>
             </div>
             <div class="control-group" style="float: left;">
@@ -726,13 +726,13 @@ ${ commonheader(_('Query'), app_name, user, "68px") | n,unicode }
             <div class="control-group" style="float: left;">
               <label class="control-label">${_('Executor Count')}</label>
               <div class="controls">
-                <input class="input-small" type="text" data-bind="textInput: executor_count" />
+                <input class="input-small" type="text" data-bind="numericTextInput: { value: executor_count, precision: 0 }" />
               </div>
             </div>
             <div class="control-group cl" style="float: left; clear: left;">
               <label class="control-label">${_('Driver Cores')}</label>
               <div class="controls">
-                <input class="input-small" type="text" data-bind="textInput: driver_cores" />
+                <input class="input-small" type="text" data-bind="numericTextInput: { value: driver_cores, precision: 0 }" />
               </div>
             </div>
             <div class="control-group" style="float: left;">

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

@@ -60,6 +60,15 @@ ko.extenders.numeric = function (target, precision) {
   return result;
 };
 
+ko.bindingHandlers.numericTextInput = {
+  init: function (element, valueAccessor, allBindings) {
+    var bindingOptions = ko.unwrap(valueAccessor());
+    var numericValue = ko.observable(bindingOptions.value()).extend({ numeric: bindingOptions.precision });
+    numericValue.subscribe(function(newValue) { bindingOptions.value(newValue) });
+    ko.bindingHandlers.textInput.init(element, function() { return numericValue }, allBindings);
+  }
+};
+
 ko.bindingHandlers.freshereditor = {
   init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
     var _el = $(element);