瀏覽代碼

AMBARI-10929 Adjusting time range in zoomed-in graph widget does not work. (atkach)

Andrii Tkach 10 年之前
父節點
當前提交
272095e049

+ 9 - 3
ambari-web/app/mixins/common/widgets/widget_mixin.js

@@ -44,6 +44,11 @@ App.WidgetMixin = Ember.Mixin.create({
    */
   CLONE_SUFFIX: '(Copy)',
 
+  /**
+   * @type {number|null}
+   */
+  timeoutId: null,
+
   /**
    * common metrics container
    * @type {Array}
@@ -108,7 +113,7 @@ App.WidgetMixin = Ember.Mixin.create({
         });
       }
     }
-  },
+  }.observes('customTimeRange'),
 
   /**
    * get data formatted for request
@@ -332,9 +337,10 @@ App.WidgetMixin = Ember.Mixin.create({
     var self = this;
     this.set('isLoaded', true);
     this.drawWidget();
-    setTimeout(function () {
+    clearTimeout(this.get('timeoutId'));
+    this.set('timeoutId', setTimeout(function () {
       self.loadMetrics();
-    }, App.contentUpdateInterval);
+    }, App.contentUpdateInterval));
   },
 
 

+ 23 - 6
ambari-web/app/views/common/widget/graph_widget_view.js

@@ -28,18 +28,24 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, {
   metrics: [],
 
   /**
-   * 3600000 ms in 1 hour
+   * 3600 sec in 1 hour
    * @const
    */
-  TIME_FACTOR: 3600000,
+  TIME_FACTOR: 3600,
 
   /**
-   * value in ms
+   * custom time range, set when graph opened in popup
+   * @type {number|null}
+   */
+  customTimeRange: null,
+
+  /**
+   * value in seconds
    * @type {number}
    */
   timeRange: function () {
-    return parseInt(this.get('content.properties.time_range')) * this.get('TIME_FACTOR');
-  }.property('content.properties.time_range'),
+    return this.get('customTimeRange') || parseInt(this.get('content.properties.time_range')) * this.get('TIME_FACTOR');
+  }.property('content.properties.time_range', 'customTimeRange'),
 
   /**
    * value in ms
@@ -213,7 +219,7 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, {
    */
   addTimeProperties: function (metricPaths) {
     var toSeconds = Math.round(App.dateTime() / 1000);
-    var fromSeconds = toSeconds - (this.get('timeRange')/1000);
+    var fromSeconds = toSeconds - this.get('timeRange');
     var step = this.get('timeStep');
     var result = [];
 
@@ -233,6 +239,17 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, {
     noTitleUnderGraph: true,
     inWidget: true,
 
+    /**
+     * set custom time range for graph widget
+     */
+    setTimeRange: function () {
+      if (this.get('isPopup')) {
+        this.set('parentView.customTimeRange', this.get('timeUnitSeconds'));
+      } else {
+        this.set('parentView.customTimeRange', null);
+      }
+    }.observes('isPopup', 'timeUnitSeconds'),
+
     /**
      * graph height
      * @type {number}