ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [06/50] [abbrv] ambari git commit: AMBARI-19796 Log Search portal date range picker - fix minor issues (mgergely)
Date Fri, 03 Feb 2017 14:53:10 GMT
AMBARI-19796 Log Search portal date range picker - fix minor issues (mgergely)

Change-Id: I39ad475f1a7a91cd0b477b2847b3db8679ea67b0


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4e689afe
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4e689afe
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4e689afe

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 4e689afe5a5bbc04d893b16f1d117988efa3ff3e
Parents: c4f59ef
Author: Miklos Gergely <mgergely@hortonworks.com>
Authored: Wed Feb 1 10:53:04 2017 +0100
Committer: Miklos Gergely <mgergely@hortonworks.com>
Committed: Wed Feb 1 10:53:04 2017 +0100

----------------------------------------------------------------------
 .../other/daterangepicker/js/daterangepicker.js | 90 ++++----------------
 .../src/main/webapp/scripts/utils/ViewUtils.js  |  2 +-
 .../scripts/views/common/DatePickerLayout.js    | 40 ++++-----
 3 files changed, 36 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4e689afe/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/other/daterangepicker/js/daterangepicker.js
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/other/daterangepicker/js/daterangepicker.js
b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/other/daterangepicker/js/daterangepicker.js
index dc571e8..e88b45f 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/other/daterangepicker/js/daterangepicker.js
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/other/daterangepicker/js/daterangepicker.js
@@ -49,7 +49,6 @@
         this.linkedCalendars = true;
         this.autoUpdateInput = true;
         this.alwaysShowCalendars = false;
-        this.ranges = {};
 
         this.opens = 'right';
         if (this.element.hasClass('pull-right'))
@@ -301,45 +300,8 @@
         }
 
         if (typeof options.ranges === 'object') {
-            for (range in options.ranges) {
-
-                if (typeof options.ranges[range][0] === 'string')
-                    start = moment(options.ranges[range][0], this.locale.format);
-                else
-                    start = moment(options.ranges[range][0]);
-
-                if (typeof options.ranges[range][1] === 'string')
-                    end = moment(options.ranges[range][1], this.locale.format);
-                else
-                    end = moment(options.ranges[range][1]);
-
-                // If the start or end date exceed those allowed by the minDate or dateLimit
-                // options, shorten the range to the allowable period.
-                if (this.minDate && start.isBefore(this.minDate))
-                    start = this.minDate.clone();
-
-                var maxDate = this.maxDate;
-                if (this.dateLimit && maxDate && start.clone().add(this.dateLimit).isAfter(maxDate))
-                    maxDate = start.clone().add(this.dateLimit);
-                if (maxDate && end.isAfter(maxDate))
-                    end = maxDate.clone();
-
-                // If the end of the range is before the minimum or the start of the range
is
-                // after the maximum, don't display this range option at all.
-                if ((this.minDate && end.isBefore(this.minDate, this.timepicker ?
'minute' : 'day')) 
-                  || (maxDate && start.isAfter(maxDate, this.timepicker ? 'minute'
: 'day')))
-                    continue;
-
-                //Support unicode chars in the range names.
-                var elem = document.createElement('textarea');
-                elem.innerHTML = range;
-                var rangeHtml = elem.value;
-
-                this.ranges[rangeHtml] = [start, end];
-            }
-
             var list = '<ul>';
-            for (range in this.ranges) {
+            for (range of options.ranges) {
                 list += '<li data-range-key="' + range + '">' + range + '</li>';
             }
             if (this.showCustomRangeLabel) {
@@ -614,9 +576,9 @@
 
             //highlight any predefined range matching the current start and end dates
             this.container.find('.ranges li').removeClass('active');
+            this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
             if (this.endDate == null) return;
-
-            this.calculateChosenLabel();
+            this.showCalendars();
         },
 
         renderCalendar: function(side) {
@@ -649,11 +611,14 @@
             }
 
             //populate the calendar with date objects
+            var curDate;
             var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1;
-            if (startDay > daysInLastMonth + 1)
-                startDay -= 7;
-
-            var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]);
+            if (startDay == daysInLastMonth + 1)
+                curDate = moment([year, month, 1, 12, minute, second]);
+            else if (startDay > daysInLastMonth )
+                curDate = moment([lastYear, lastMonth, startDay-7, 12, minute, second]);
+            else
+                curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]);
 
             var col, row;
             for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24,
'hour')) {
@@ -1180,7 +1145,6 @@
         },
 
         hoverRange: function(e) {
-
             //ignore mouse movements while an above-calendar text input has focus
             if (this.container.find('input[name=daterangepicker_start]').is(":focus") ||
this.container.find('input[name=daterangepicker_end]').is(":focus"))
                 return;
@@ -1190,7 +1154,8 @@
             if (label == this.locale.customRangeLabel) {
                 this.updateView();
             } else {
-                var dates = this.ranges[label];
+                var Utils = require('utils/Utils');
+                var dates = Utils.dateUtil.getRelativeDateFromString(label);
                 this.container.find('input[name=daterangepicker_start]').val(dates[0].format(this.locale.format));
                 this.container.find('input[name=daterangepicker_end]').val(dates[1].format(this.locale.format));
             }
@@ -1203,7 +1168,8 @@
             if (label == this.locale.customRangeLabel) {
                 this.showCalendars();
             } else {
-                var dates = this.ranges[label];
+                var Utils = require('utils/Utils');
+                var dates = Utils.dateUtil.getRelativeDateFromString(label);
                 this.startDate = dates[0];
                 this.endDate = dates[1];
 
@@ -1346,7 +1312,7 @@
                 }
                 this.setEndDate(date.clone());
                 if (this.autoApply) {
-                  this.calculateChosenLabel();
+                  this.showCalendars();
                   this.clickApply();
                 }
             }
@@ -1364,32 +1330,6 @@
 
         },
 
-        calculateChosenLabel: function() {
-          var customRange = true;
-          var i = 0;
-          for (var range in this.ranges) {
-              if (this.timePicker) {
-                  if (this.startDate.isSame(this.ranges[range][0]) && this.endDate.isSame(this.ranges[range][1]))
{
-                      customRange = false;
-                      this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
-                      break;
-                  }
-              } else {
-                  //ignore times when comparing dates if time picker is not enabled
-                  if (this.startDate.format('YYYY-MM-DD') == this.ranges[range][0].format('YYYY-MM-DD')
&& this.endDate.format('YYYY-MM-DD') == this.ranges[range][1].format('YYYY-MM-DD'))
{
-                      customRange = false;
-                      this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
-                      break;
-                  }
-              }
-              i++;
-          }
-          if (customRange && this.showCustomRangeLabel) {
-              this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
-              this.showCalendars();
-          }
-        },
-
         clickApply: function(e) {
             this.hide();
             this.element.trigger('apply.daterangepicker', this);

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e689afe/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/ViewUtils.js
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/ViewUtils.js
b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/ViewUtils.js
index 6d587cd..9934572 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/ViewUtils.js
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/ViewUtils.js
@@ -33,7 +33,7 @@ define(['require',
     var params = Utils.getQueryParams(window.location.search);
     this.defaultParams = {
       q: "*:*",
-      from: moment().hours("00").minutes("00").seconds("01").milliseconds("000").toJSON(),
+      from: moment().hours("00").minutes("00").seconds("00").milliseconds("000").toJSON(),
       to: moment().hours("23").minutes("59").seconds("59").milliseconds("999").toJSON(),
       unit: "+1HOUR",
       level: "FATAL,ERROR,WARN"

http://git-wip-us.apache.org/repos/asf/ambari/blob/4e689afe/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/DatePickerLayout.js
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/DatePickerLayout.js
b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/DatePickerLayout.js
index 3beb776..22a9b30 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/DatePickerLayout.js
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/DatePickerLayout.js
@@ -69,22 +69,22 @@ define(['require',
                     this.setValues(options);
                 }, this);
                 this.listenTo(this.vent, "date:click", function(options) {
-                	this.isEventTriggerdFromVent = true;
+                    this.isEventTriggerdFromVent = true;
                     this.setValues(options);
                     this.ui.dateRange.data('daterangepicker').clickApply();
                 }, this);
                 this.listenTo(this.vent, "date:getValues", function(obj) {
-                	var dates = this.getValues();
-                	obj.dates = [dates[0], dates[1]];
-                	obj.dateRangeLabel = this.dateRangeLabel;
-                	obj.unit = this.unit;
+                    var dates = this.getValues();
+                    obj.dates = [dates[0], dates[1]];
+                    obj.dateRangeLabel = this.dateRangeLabel;
+                    obj.unit = this.unit;
                 }, this);
 
             },
             onRender: function() {
                 var that = this;
                 if(this.hideFireButton){
-                	this.$(".goBtn").hide();
+                    this.$(".goBtn").hide();
                 }
                 if(this.buttonLabel){
                 	this.$(".goBtn").text(this.buttonLabel);
@@ -128,10 +128,10 @@ define(['require',
                 this.dateRangeLabel = val.dateRangeLabel;
             },
             getValues : function(){
-            	var obj = this.ui.dateRange.data("daterangepicker");
-            	if(obj){
-            		return [obj.startDate, obj.endDate];
-            	}
+                var obj = this.ui.dateRange.data("daterangepicker");
+                if(obj){
+                    return [obj.startDate, obj.endDate];
+                }
             },
             initializeDateRangePicker: function() {
                 var that = this,
@@ -141,7 +141,7 @@ define(['require',
                     ranges[k.text] = [];
                 })
                 this.ui.dateRange.daterangepicker(_.extend({
-                    'ranges': ranges
+                    'ranges': Object.keys(ranges)
                 }, {
                     "timePicker": true,
                     "timePickerIncrement": 1,
@@ -167,15 +167,15 @@ define(['require',
 
 
                 this.ui.dateRange.on('apply.daterangepicker ', function(ev, picker) {
-                	if(! that.isEventTriggerdFromVent && !(_.isUndefined(picker.chosenLabel))
){
-                		that.dateRangeLabel = picker.chosenLabel;
-                	}else{
-                		that.isEventTriggerdFromVent = false;
-                	}
-                	if (that.dateRangeLabel !== "Custom Range") {
-                		var last1Hour = that.dateUtil.getRelativeDateFromString(that.dateRangeLabel);
-                		that.setDateText(last1Hour[0], last1Hour[1]);  
-                	}
+                    if(! that.isEventTriggerdFromVent && !(_.isUndefined(picker.chosenLabel))
){
+                        that.dateRangeLabel = picker.chosenLabel;
+                    }else{
+                        that.isEventTriggerdFromVent = false;
+                    }
+                    if (that.dateRangeLabel !== "Custom Range") {
+                        var range = that.dateUtil.getRelativeDateFromString(that.dateRangeLabel);
+                        that.setDateText(range[0], range[1]);  
+                    }
                     that.ui.dateRangeTitle.html(that.dateRangeLabel);
                     that.unit = that.checkDateRange(picker);
                     var options = {


Mime
View raw message