فهرست منبع

HUE-6807 [search] The rolling time picker should consider the user's timezone

Enrico Berti 8 سال پیش
والد
کامیت
3be2254e8e

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

@@ -3265,11 +3265,16 @@
     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) {
-          _el.datepicker("setValue", moment(_el.val()).utc().format("YYYY-MM-DD"));
+          var m = moment(_el.val());
+          if (!disableUTC) {
+            m = m.utc();
+          }
+          _el.datepicker("setValue", m.format("YYYY-MM-DD"));
         }
       }).on("changeDate", function (e) {
         setDate(e.date);
@@ -3279,7 +3284,11 @@
 
       function setDate(d) {
         if (_options.momentFormat) {
-          _el.val(moment(d).utc().format(_options.momentFormat));
+          var m = moment(d);
+          if (!disableUTC) {
+            m = m.utc();
+          }
+          _el.val(m.format(_options.momentFormat));
         }
         allBindings().value(_el.val());
       }

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

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