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

HUE-8073 [editor] Changed editing for date variables

jdesjean 7 жил өмнө
parent
commit
cb8c38ad1a

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

@@ -3645,7 +3645,7 @@
         format: "yyyy-mm-dd"
       }).on("show", function (e) {
         if (_options.momentFormat) {
-          var m = moment(_el.val()).utc();
+          var m = moment.utc(_el.val());
           _el.datepicker("setValue", m.format("YYYY-MM-DD"));
           _el.val(m.format(_options.momentFormat)); // Set value again as datepicker clears the time component
         }
@@ -3659,7 +3659,7 @@
         if (_options.momentFormat) {
           var m = moment(d);
           // Keep time intact
-          var previous = moment(allBindings().value()).utc();
+          var previous = moment.utc(allBindings().value());
           previous.date(m.date());
           previous.month(m.month());
           previous.year(m.year());

+ 5 - 4
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -731,8 +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;
+        variableValues[variable.name()].path = variable.path();
+        variableValues[variable.name()].type = variable.type();
         return variableValues;
       }, self.variableValues);
       if (needsMore) {
@@ -784,11 +784,12 @@ var EditorViewModel = (function() {
           type = 'string';
         }
         var variablesValues = {};
+        var value = variable.value();
         switch (type) {
           case 'timestamp':
             variablesValues.type = 'datetime-local';
             variablesValues.step = '1';
-            variablesValues.value = moment(Date.parse(variable.value()) || Date.now()).utc().format().substring(0, 19);
+            variablesValues.value = value && moment.utc(value).format("YYYY-MM-DD HH:mm:ss.S") || moment(Date.now()).format("YYYY-MM-DD 00:00:00.0");
             break;
           case 'decimal':
           case 'double':
@@ -806,7 +807,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);
+            variablesValues.value = value && moment.utc(value).format("YYYY-MM-DD") || moment(Date.now()).format("YYYY-MM-DD");
             break;
           case 'boolean':
             variablesValues.type = 'checkbox';

+ 7 - 2
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -39,7 +39,9 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 <link rel="stylesheet" href="${ static('desktop/ext/css/medium-editor.min.css') }">
 <link rel="stylesheet" href="${ static('desktop/css/bootstrap-medium-editor.css') }">
 <link rel="stylesheet" href="${ static('desktop/ext/css/jquery.mCustomScrollbar.min.css') }">
+<link rel="stylesheet" href="${ static('desktop/ext/css/bootstrap-datepicker.min.css') }">
 
+<script src="${ static('desktop/ext/js/bootstrap-datepicker.min.js') }" type="text/javascript" charset="utf-8"></script>
 % if not is_embeddable:
 <script src="${ static('desktop/ext/js/jquery/plugins/jquery-ui-1.10.4.custom.min.js') }"></script>
 <script src="${ static('desktop/ext/js/knockout-sortable.min.js') }"></script>
@@ -1243,8 +1245,11 @@ ${ 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 if: type() == 'datetime-local' -->
+              <input class="input-medium" type="text" data-bind="value: value, datepicker: { momentFormat: 'YYYY-MM-DD HH:mm:ss.S' }">
+              <!-- /ko -->
+              <!-- ko if: type() == 'date' -->
+              <input class="input-medium" type="text" data-bind="value: value, datepicker: { momentFormat: 'YYYY-MM-DD' }">
               <!-- /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 }">