ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexantone...@apache.org
Subject ambari git commit: AMBARI-14742. Custom time range has broken situations (alexantonenko)
Date Wed, 20 Jan 2016 20:15:55 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 8926b86b0 -> 6f1c1b447


AMBARI-14742. Custom time range has broken situations (alexantonenko)


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

Branch: refs/heads/branch-2.2
Commit: 6f1c1b44799bfafaaaa569a7bac5380c4383d66d
Parents: 8926b86
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Wed Jan 20 18:26:14 2016 +0200
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Wed Jan 20 22:15:50 2016 +0200

----------------------------------------------------------------------
 .../mixins/common/widgets/time_range_mixin.js   | 32 ++++++-------
 .../app/views/common/chart/linear_time.js       | 18 ++++---
 .../app/views/common/custom_date_popup.js       |  7 +--
 .../app/views/common/select_custom_date_view.js |  4 +-
 .../common/widgets/time_range_mixin_test.js     | 10 ++--
 .../common/select_custom_date_view_test.js      | 49 ++++++++++++++++++++
 6 files changed, 86 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6f1c1b44/ambari-web/app/mixins/common/widgets/time_range_mixin.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/widgets/time_range_mixin.js b/ambari-web/app/mixins/common/widgets/time_range_mixin.js
index c88df56..e2a9c9b 100644
--- a/ambari-web/app/mixins/common/widgets/time_range_mixin.js
+++ b/ambari-web/app/mixins/common/widgets/time_range_mixin.js
@@ -87,35 +87,33 @@ App.TimeRangeMixin = Em.Mixin.create({
    * onclick handler for a time range option
    * @param {object} event
    * @param {function} callback
+   * @param {object} context
    */
-  setTimeRange: function (event, callback) {
-    var prevIndex = this.get('currentTimeRangeIndex'),
-      prevCustomTimeRange = {
-        start: this.get('customStartTime'),
-        end: this.get('customEndTime'),
-        duration: this.get('customDurationFormatted')
-      },
+  setTimeRange: function (event, callback, context) {
+    var prevCustomTimeRange = this.getProperties(['currentTimeRangeIndex', 'customStartTime',
'customEndTime', 'customDurationFormatted']),
       index = event.context.index,
       primary = function () {
+        var timeRange = {
+          customEndTime: timeRangePopup.endTime,
+          customStartTime: timeRangePopup.startTime,
+          customDurationFormatted: timeRangePopup.customDuration
+        };
         if (callback) {
           callback();
         }
+        this.setProperties(timeRange);
+        if (context) {
+          context.setProperties(timeRange);
+        }
       },
-      secondary = function () {
-        this.setProperties({
-          currentTimeRangeIndex: prevIndex,
-          customStartTime: prevCustomTimeRange.start,
-          customEndTime: prevCustomTimeRange.end,
-          customDurationFormatted: prevCustomTimeRange.duration
-        });
-      };
+      secondary = this.setProperties.bind(this, prevCustomTimeRange);
 
     if (index === 8) {
       // Custom start and end time is specified by user
       var defaultStartTime,
         defaultEndTime,
         duration;
-      if (prevIndex === 8) {
+      if (prevCustomTimeRange.currentTimeRangeIndex === 8) {
         // Custom time range is active
         defaultStartTime = new Date(this.get('customStartTime')).getTime();
         defaultEndTime = new Date(this.get('customEndTime')).getTime();
@@ -129,7 +127,7 @@ App.TimeRangeMixin = Em.Mixin.create({
         defaultEndTime.setMinutes(minutes);
         defaultStartTime = defaultEndTime.getTime() - duration;
       }
-      timeRangePopup.showCustomDatePopup(this, primary.bind(this), secondary.bind(this),
{
+      timeRangePopup.showCustomDatePopup(primary.bind(this), secondary.bind(this), {
         startDate: App.formatDateTimeWithTimeZone(defaultStartTime, 'MM/DD/YYYY'),
         hoursForStart: App.formatDateTimeWithTimeZone(defaultStartTime, 'hh'),
         minutesForStart: App.formatDateTimeWithTimeZone(defaultStartTime, 'mm'),

http://git-wip-us.apache.org/repos/asf/ambari/blob/6f1c1b44/ambari-web/app/views/common/chart/linear_time.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/chart/linear_time.js b/ambari-web/app/views/common/chart/linear_time.js
index b3e73bf..2cda391 100644
--- a/ambari-web/app/views/common/chart/linear_time.js
+++ b/ambari-web/app/views/common/chart/linear_time.js
@@ -935,9 +935,9 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin, {
         }.property('parentView.graph.isPopupReady'),
 
         currentTimeRangeIndex: self.get('currentTimeIndex'),
-        customStartTime: self.get('customStartTime'),
-        customEndTime: self.get('customEndTime'),
-        customDurationFormatted: self.get('customDurationFormatted'),
+        customStartTime: self.get('currentTimeIndex') === 8 ? self.get('customStartTime')
: null,
+        customEndTime: self.get('currentTimeIndex') === 8 ? self.get('customEndTime') : null,
+        customDurationFormatted: self.get('currentTimeIndex') === 8 ? self.get('customDurationFormatted')
: null,
 
         didInsertElement: function () {
           var popupBody = this;
@@ -1000,7 +1000,7 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin,
{
         setTimeRange: function (event) {
           var index = event.context.index,
             callback = this.get('parentView').reloadGraphByTime.bind(this.get('parentView'),
index);
-          this._super(event, callback);
+          this._super(event, callback, self);
 
           // Preset time range is specified by user
           if (index !== 8) {
@@ -1017,8 +1017,12 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin,
{
       secondary: null,
 
       onPrimary: function () {
+        var targetView = Em.isNone(self.get('parentView.currentTimeRangeIndex')) ? self.get('parentView.parentView')
: self.get('parentView');
         self.setProperties({
-          currentTimeIndex: !Em.isNone(self.get('parentView.currentTimeRangeIndex')) ? self.get('parentView.currentTimeRangeIndex')
: self.get('parentView.parentView.currentTimeRangeIndex'),
+          currentTimeIndex: targetView.get('currentTimeRangeIndex'),
+          customStartTime: targetView.get('customStartTime'),
+          customEndTime: targetView.get('customEndTime'),
+          customDurationFormatted: targetView.get('customDurationFormatted'),
           isPopup: false
         });
         this._super();
@@ -1073,7 +1077,7 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin,
{
     Em.run.once(this, function () {
       this.loadData();
     });
-  }.observes('timeUnitSeconds', 'customStartTime', 'customStartTime'),
+  }.observes('timeUnitSeconds', 'customStartTime', 'customEndTime'),
 
   timeStates: [
     {name: Em.I18n.t('graphs.timeRange.hour'), seconds: 3600},
@@ -1116,7 +1120,7 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin,
{
       // Custom start and end time is specified by user
       this.propertyDidChange('timeUnitSeconds');
     }
-  }.observes('currentTimeIndex')
+  }.observes('currentTimeIndex', 'parentView.childViews.lastObject.customStartTime', 'parentView.childViews.lastObject.customEndTime')
 
 });
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/6f1c1b44/ambari-web/app/views/common/custom_date_popup.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/custom_date_popup.js b/ambari-web/app/views/common/custom_date_popup.js
index c5a2837..03adc30 100644
--- a/ambari-web/app/views/common/custom_date_popup.js
+++ b/ambari-web/app/views/common/custom_date_popup.js
@@ -26,7 +26,7 @@ module.exports = Em.Object.create({
 
   customDuration: null,
 
-  showCustomDatePopup: function (context, primary, secondary, defaults) {
+  showCustomDatePopup: function (primary, secondary, defaults) {
     var self = this;
     defaults = defaults || {
       startDate: null,
@@ -43,11 +43,6 @@ module.exports = Em.Object.create({
     return App.ModalPopup.show({
       header: Em.I18n.t('jobs.table.custom.date.header'),
       onPrimary: function () {
-        context.setProperties({
-          customEndTime: self.endTime,
-          customStartTime: self.startTime,
-          customDurationFormatted: self.customDuration
-        });
         if (primary) {
           primary();
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/6f1c1b44/ambari-web/app/views/common/select_custom_date_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/select_custom_date_view.js b/ambari-web/app/views/common/select_custom_date_view.js
index 60e1339..ab8e11a 100644
--- a/ambari-web/app/views/common/select_custom_date_view.js
+++ b/ambari-web/app/views/common/select_custom_date_view.js
@@ -110,6 +110,9 @@ App.JobsCustomDatesSelectView = Em.View.extend({
         initialOption = this.get('content').find(function (item) {
           return duration === item.value || duration === item.label;
         }, this);
+      if (!initialOption) {
+        initialOption = this.get('content').findProperty('value', 0);
+      }
       this.set('selection', initialOption);
     }
   }),
@@ -119,7 +122,6 @@ App.JobsCustomDatesSelectView = Em.View.extend({
   }.property('customDateFormFields.duration.value'),
 
   didInsertElement: function () {
-    this.validate();
     $('.datepicker').datepicker({
       format: 'mm/dd/yyyy'
     }).on('changeDate', function() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/6f1c1b44/ambari-web/test/mixins/common/widgets/time_range_mixin_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/common/widgets/time_range_mixin_test.js b/ambari-web/test/mixins/common/widgets/time_range_mixin_test.js
index f57808d..39ce6f1 100644
--- a/ambari-web/test/mixins/common/widgets/time_range_mixin_test.js
+++ b/ambari-web/test/mixins/common/widgets/time_range_mixin_test.js
@@ -65,6 +65,7 @@ describe('App.TimeRangeMixin', function () {
           index: 1,
           customStartTime: null,
           customEndTime: null,
+          customDurationFormatted: null,
           title: 'time range is preset',
           testTitle: 'should reset time range boundaries'
         },
@@ -72,6 +73,7 @@ describe('App.TimeRangeMixin', function () {
           index: 8,
           customStartTime: 1,
           customEndTime: 1,
+          customDurationFormatted: '1 hour',
           title: 'time range is custom',
           testTitle: 'should not reset time range boundaries'
         }
@@ -116,7 +118,8 @@ describe('App.TimeRangeMixin', function () {
         beforeEach(function () {
           obj.setProperties({
             customStartTime: 1,
-            customEndTime: 1
+            customEndTime: 1,
+            customDurationFormatted: '1 hour'
           });
           obj.setTimeRange({
             context: {
@@ -126,9 +129,10 @@ describe('App.TimeRangeMixin', function () {
         });
 
         it(item.testTitle, function () {
-          expect(obj.getProperties(['customStartTime', 'customEndTime'])).to.eql({
+          expect(obj.getProperties(['customStartTime', 'customEndTime', 'customDurationFormatted'])).to.eql({
             customStartTime: item.customStartTime,
-            customEndTime: item.customEndTime
+            customEndTime: item.customEndTime,
+            customDurationFormatted: item.customDurationFormatted
           });
         });
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/6f1c1b44/ambari-web/test/views/common/select_custom_date_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/select_custom_date_view_test.js b/ambari-web/test/views/common/select_custom_date_view_test.js
index e7520cb..9d492e9 100644
--- a/ambari-web/test/views/common/select_custom_date_view_test.js
+++ b/ambari-web/test/views/common/select_custom_date_view_test.js
@@ -257,4 +257,53 @@ describe('App.JobsCustomDatesSelectView', function () {
 
   });
 
+  describe('#durationSelect', function () {
+
+    var select;
+
+    beforeEach(function () {
+      select = view.get('durationSelect').create();
+    });
+
+    describe('#willInsertElement', function () {
+
+      var cases = [
+        {
+          duration: 1800000,
+          selection: {
+            value: 1800000,
+            label: Em.I18n.t('jobs.customDateFilter.duration.30min')
+          },
+          title: 'should detect preset option by value'
+        },
+        {
+          duration: Em.I18n.t('jobs.customDateFilter.duration.2hr'),
+          selection: {
+            value: 7200000,
+            label: Em.I18n.t('jobs.customDateFilter.duration.2hr')
+          },
+          title: 'should detect preset option by label'
+        },
+        {
+          duration: '40 minutes',
+          selection: {
+            value: 0,
+            label: Em.I18n.t('common.custom')
+          },
+          title: 'should set "Custom" option if preset one can\'t be detected'
+        }
+      ];
+
+      cases.forEach(function (item) {
+        it(item.title, function () {
+          select.set('selection', item.duration);
+          select.willInsertElement();
+          expect(select.get('selection')).to.eql(item.selection);
+        });
+      });
+
+    });
+
+  });
+
 });


Mime
View raw message