Преглед изворни кода

HUE-8054 [dashboard] Allow to specify time in fixed time settings

jdesjean пре 7 година
родитељ
комит
de6e53f

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

@@ -3457,16 +3457,13 @@
     init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
       var _el = $(element);
       var _options = ko.unwrap(valueAccessor());
-      var disableUTC = _options.disableUTC || false;
       _el.datepicker({
         format: "yyyy-mm-dd"
       }).on("show", function (e) {
         if (_options.momentFormat) {
-          var m = moment(_el.val());
-          if (!disableUTC) {
-            m = m.utc();
-          }
+          var m = moment(_el.val()).utc();
           _el.datepicker("setValue", m.format("YYYY-MM-DD"));
+          _el.val(m.format(_options.momentFormat)); // Set value again as datepicker clears the time component
         }
       }).on("changeDate", function (e) {
         setDate(e.date);
@@ -3477,10 +3474,13 @@
       function setDate(d) {
         if (_options.momentFormat) {
           var m = moment(d);
-          if (!disableUTC) {
-            m = m.utc();
-          }
-          _el.val(m.format(_options.momentFormat));
+          // Keep time intact
+          var previous = moment(allBindings().value()).utc();
+          previous.date(m.date());
+          previous.month(m.month());
+          previous.year(m.year());
+
+          _el.val(previous.format(_options.momentFormat));
         }
         allBindings().value(_el.val());
       }

+ 2 - 2
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -2833,13 +2833,13 @@ ${ dashboard.layout_skeleton(suffix='search') }
               <div class="control-group" data-bind="visible: collection.timeFilter.type() == 'fixed'">
                 <label class="control-label">${ _('Start date/time') }</label>
                 <div class="controls">
-                  <input type="text" data-bind="value: collection.timeFilter.from, datepicker: {momentFormat: 'YYYY-MM-DD[T]HH:mm:SS[Z]', disableUTC: true}" />
+                  <input type="text" data-bind="value: collection.timeFilter.from, datepicker: {momentFormat: 'YYYY-MM-DD[T]HH:mm:ss[Z]'}" />
                 </div>
               </div>
               <div class="control-group" data-bind="visible: collection.timeFilter.type() == 'fixed'">
                 <label class="control-label">${ _('End date/time') }</label>
                 <div class="controls">
-                  <input type="text" data-bind="value: collection.timeFilter.to, datepicker: {momentFormat: 'YYYY-MM-DD[T]HH:mm:SS[Z]', disableUTC: true}" />
+                  <input type="text" data-bind="value: collection.timeFilter.to, datepicker: {momentFormat: 'YYYY-MM-DD[T]HH:mm:ss[Z]'}" />
                 </div>
               </div>
               <!-- ko if: collection.timeFilter.type() == 'rolling' -->