Pārlūkot izejas kodu

HUE-8073 [editor] Add default value for variable calendar widget

jdesjean 7 gadi atpakaļ
vecāks
revīzija
a86118a67c

+ 9 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -731,6 +731,8 @@ var EditorViewModel = (function() {
         variableValues[variable.name()].value = variable.value();
         variableValues[variable.name()].sampleUser = variable.sampleUser();
         variableValues[variable.name()].catalogEntry = variable.catalogEntry;
+        variableValues[variable.name()].path = variable.path;
+        variableValues[variable.name()].type = variable.type;
         return variableValues;
       }, self.variableValues);
       if (needsMore) {
@@ -786,6 +788,7 @@ var EditorViewModel = (function() {
           case 'timestamp':
             variablesValues.type = 'datetime-local';
             variablesValues.step = '1';
+            variablesValues.value = moment(Date.parse(variable.value()) || Date.now()).utc().format().substring(0, 19);
             break;
           case 'decimal':
           case 'double':
@@ -803,6 +806,7 @@ var EditorViewModel = (function() {
           case 'date':
             variablesValues.type = 'date';
             variablesValues.step = '';
+            variablesValues.value = moment(Date.parse(variable.value()) || Date.now()).utc().format().substring(0, 10);
             break;
           case 'boolean':
             variablesValues.type = 'checkbox';
@@ -812,6 +816,11 @@ var EditorViewModel = (function() {
             variablesValues.type = 'text';
             variablesValues.step = '';
         }
+        if (variablesValues.value) {
+          setTimeout(function () {
+            variable.value(variablesValues.value);
+          }, 0);
+        }
         variable.type(variablesValues.type);
         variable.step(variablesValues.step);
       };

+ 5 - 0
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1243,7 +1243,12 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
               <input class="input-medium" type="text" data-bind="value: value, attr: { type: type, placeholder: meta.placeholder() || '${ _ko('Variable value') }' }, valueUpdate: 'afterkeydown', event: { 'keydown': $parent.onKeydownInVariable }, autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }">
             <!-- /ko -->
             <!-- ko ifnot: meta.placeholder() -->
+              <!-- ko if: type() == 'datetime-local' || type() == 'date' -->
+              <input class="input-large" type="text" required="true" data-bind="value: value, attr: { type: type() || 'text', step: step }, valueUpdate: 'afterkeydown', event: { 'keydown': $parent.onKeydownInVariable }, css:{ 'input-large': type() == 'datetime-local', 'input-medium': type() == 'date'}">
+              <!-- /ko -->
+              <!-- ko ifnot: (type() == 'datetime-local' || type() == 'date') -->
               <input class="input-medium" type="text" data-bind="value: value, attr: { type: type() || 'text', step: step }, valueUpdate: 'afterkeydown', event: { 'keydown': $parent.onKeydownInVariable }, autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }">
+              <!-- /ko -->
             <!-- /ko -->
           <!-- /ko -->
           <!-- ko if: meta.type() == 'select' -->