You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2015/10/07 15:52:07 UTC
[26/31] ambari git commit: AMBARI-13331. Allow user to customize time
period for graphs on dashboard and host summary page.
AMBARI-13331. Allow user to customize time period for graphs on dashboard and host summary page.
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8eceffe5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8eceffe5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8eceffe5
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 8eceffe5de2e82ce1ca38430d068e35cda56be45
Parents: 828c7fa
Author: Alex Antonenko <hi...@gmail.com>
Authored: Wed Oct 7 11:35:04 2015 +0300
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Wed Oct 7 11:35:04 2015 +0300
----------------------------------------------------------------------
ambari-web/app/assets/test/tests.js | 1 +
ambari-web/app/messages.js | 1 +
ambari-web/app/mixins.js | 1 +
.../mixins/common/widgets/time_range_mixin.js | 58 ++++++++++++++++++++
.../app/templates/common/time_range_list.hbs | 26 +++++++++
.../app/templates/main/dashboard/widgets.hbs | 8 ++-
ambari-web/app/templates/main/host/summary.hbs | 1 +
.../app/templates/main/service/info/summary.hbs | 11 +---
ambari-web/app/views.js | 1 +
.../app/views/common/chart/linear_time.js | 8 ++-
ambari-web/app/views/common/time_range_list.js | 27 +++++++++
ambari-web/app/views/main/dashboard/widgets.js | 4 +-
ambari-web/app/views/main/host/summary.js | 2 +-
.../app/views/main/service/info/summary.js | 24 +-------
.../common/widgets/time_range_mixin_test.js | 58 ++++++++++++++++++++
.../test/views/common/chart/linear_time_test.js | 44 ++++++++++++++-
16 files changed, 236 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index 4a5af5c..b3b0e2c 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -141,6 +141,7 @@ var files = [
'test/mixins/common/configs/toggle_isrequired_test',
'test/mixins/common/chart/storm_linear_time_test',
'test/mixins/common/widgets/export_metrics_mixin_test',
+ 'test/mixins/common/widgets/time_range_mixin_test',
'test/mixins/common/widgets/widget_section_test',
'test/mixins/common/localStorage_test',
'test/mixins/common/reload_popup_test',
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 0d60a91..14df65e 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -2343,6 +2343,7 @@ Em.I18n.translations = {
'dashboard.button.switchShort': 'Switch',
'dashboard.button.reset': 'Reset all widgets to default ',
'dashboard.button.gangliaLink': 'View metrics in Ganglia',
+ 'dashboard.widgets.actions.title': 'Metric Actions',
'dashboard.widgets.create': 'Create Widget',
'dashboard.widgets.actions.browse': 'Browse Widgets',
'dashboard.widgets.layout.import': 'Import a layout',
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/mixins.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins.js b/ambari-web/app/mixins.js
index f5000eb..4c9da09 100644
--- a/ambari-web/app/mixins.js
+++ b/ambari-web/app/mixins.js
@@ -50,6 +50,7 @@ require('mixins/common/configs/configs_loader');
require('mixins/common/configs/configs_comparator');
require('mixins/common/configs/toggle_isrequired');
require('mixins/common/widgets/export_metrics_mixin');
+require('mixins/common/widgets/time_range_mixin');
require('mixins/common/widgets/widget_mixin');
require('mixins/common/widgets/widget_section');
require('mixins/unit_convert/base_unit_convert_mixin');
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/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
new file mode 100644
index 0000000..c3f7c02
--- /dev/null
+++ b/ambari-web/app/mixins/common/widgets/time_range_mixin.js
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+require('views/common/time_range_list');
+
+App.TimeRangeMixin = Em.Mixin.create({
+
+ timeRangeClassName: 'pull-right',
+
+ /**
+ * time range options for service metrics, a dropdown will list all options
+ * value set in hours
+ */
+ timeRangeOptions: [
+ {index: 0, name: Em.I18n.t('graphs.timeRange.hour'), value: '1'},
+ {index: 1, name: Em.I18n.t('graphs.timeRange.twoHours'), value: '2'},
+ {index: 2, name: Em.I18n.t('graphs.timeRange.fourHours'), value: '4'},
+ {index: 3, name: Em.I18n.t('graphs.timeRange.twelveHours'), value: '12'},
+ {index: 4, name: Em.I18n.t('graphs.timeRange.day'), value: '24'},
+ {index: 5, name: Em.I18n.t('graphs.timeRange.week'), value: '168'},
+ {index: 6, name: Em.I18n.t('graphs.timeRange.month'), value: '720'},
+ {index: 7, name: Em.I18n.t('graphs.timeRange.year'), value: '8760'}
+ ],
+
+ currentTimeRangeIndex: 0,
+
+ currentTimeRange: function() {
+ return this.get('timeRangeOptions').objectAt(this.get('currentTimeRangeIndex'));
+ }.property('currentTimeRangeIndex'),
+
+ /**
+ * onclick handler for a time range option
+ * @param {object} event
+ */
+ setTimeRange: function (event) {
+ this.set('currentTimeRangeIndex', event.context.index);
+ },
+
+ timeRangeListView: App.TimeRangeListView.extend()
+
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/templates/common/time_range_list.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/time_range_list.hbs b/ambari-web/app/templates/common/time_range_list.hbs
new file mode 100644
index 0000000..8e6f075
--- /dev/null
+++ b/ambari-web/app/templates/common/time_range_list.hbs
@@ -0,0 +1,26 @@
+{{!
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+}}
+
+<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
+ {{view.parentView.currentTimeRange.name}} <span class="caret"></span>
+</button>
+<ul class="dropdown-menu">
+ {{#each option in view.parentView.timeRangeOptions}}
+ <li><a href="#" {{action setTimeRange option target="view.parentView"}}>{{option.name}}</a></li>
+ {{/each}}
+</ul>
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/templates/main/dashboard/widgets.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/dashboard/widgets.hbs b/ambari-web/app/templates/main/dashboard/widgets.hbs
index 56e681d..f55b9b9 100644
--- a/ambari-web/app/templates/main/dashboard/widgets.hbs
+++ b/ambari-web/app/templates/main/dashboard/widgets.hbs
@@ -17,10 +17,10 @@
}}
{{#if view.isDataLoaded}}
- <div id="widgets-options-menu" class="dropdown">
+ <div id="widgets-options-menu" class="dropdown btn-group pull-left">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
- <span>Metric Actions</span>
- <span class="caret"></span>
+ <span>{{t dashboard.widgets.actions.title}}</span>
+ <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li class="dropdown-submenu add-widgets-text">
@@ -46,6 +46,8 @@
</li>
</ul>
</div>
+ {{view view.timeRangeListView}}
+ <div class="clearfix"></div>
<div class="dashboard-widgets-box">
<div id="dashboard-widgets" class="widgets-container">
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/templates/main/host/summary.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/summary.hbs b/ambari-web/app/templates/main/host/summary.hbs
index 7026bc8..02cbcd1 100644
--- a/ambari-web/app/templates/main/host/summary.hbs
+++ b/ambari-web/app/templates/main/host/summary.hbs
@@ -183,6 +183,7 @@
{{/if}}
</div>
{{/if}}
+ {{view view.timeRangeListView}}
</div>
<div>
{{view App.MainHostMetricsView contentBinding="view.content"}}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/templates/main/service/info/summary.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/service/info/summary.hbs b/ambari-web/app/templates/main/service/info/summary.hbs
index 85d7414..9326623 100644
--- a/ambari-web/app/templates/main/service/info/summary.hbs
+++ b/ambari-web/app/templates/main/service/info/summary.hbs
@@ -76,16 +76,7 @@
<div class="box-header">
<h4>{{t services.service.metrics}}</h4>
{{#if showTimeRangeControl}}
- <div class="btn-group pull-right">
- <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
- {{view.currentTimeRange.name}} <span class="caret"></span>
- </button>
- <ul class="dropdown-menu">
- {{#each option in view.timeRangeOptions}}
- <li><a href="#" {{action setTimeRange option target="view"}}>{{option.name}}</a></li>
- {{/each}}
- </ul>
- </div>
+ {{view view.timeRangeListView}}
{{/if}}
{{#if isServiceWithEnhancedWidgets}}
{{#if isAmbariMetricsInstalled}}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/views.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views.js b/ambari-web/app/views.js
index 33403a3..857fcec 100644
--- a/ambari-web/app/views.js
+++ b/ambari-web/app/views.js
@@ -39,6 +39,7 @@ require('views/common/rolling_restart_view');
require('views/common/select_custom_date_view');
require('views/common/metric');
require('views/common/time_range');
+require('views/common/time_range_list');
require('views/common/form/field');
require('views/common/form/spinner_input_view');
require('views/common/quick_view_link_view');
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/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 4cb496b..5ffc628 100644
--- a/ambari-web/app/views/common/chart/linear_time.js
+++ b/ambari-web/app/views/common/chart/linear_time.js
@@ -814,7 +814,8 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin, {
onPrimary: function () {
self.setProperties({
- currentTimeIndex: 0,
+ currentTimeIndex: self.get('controller.isServiceWithEnhancedWidgets') === false ?
+ self.get('parentView.currentTimeRangeIndex') : self.get('parentView.parentView.currentTimeRangeIndex'),
isPopup: false
});
this._super();
@@ -880,6 +881,11 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin, {
],
// should be set by time range control dropdown list when create current graph
currentTimeIndex: 0,
+ setCurrentTimeIndexFromParent: function () {
+ var index = this.get('controller.isServiceWithEnhancedWidgets') === false ?
+ this.get('parentView.currentTimeRangeIndex') : this.get('parentView.parentView.currentTimeRangeIndex');
+ this.set('currentTimeIndex', index);
+ }.observes('parentView.parentView.currentTimeRangeIndex', 'parentView.currentTimeRangeIndex'),
timeUnitSeconds: function () {
return this.get('timeStates').objectAt(this.get('currentTimeIndex')).seconds;
}.property('currentTimeIndex'),
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/views/common/time_range_list.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/time_range_list.js b/ambari-web/app/views/common/time_range_list.js
new file mode 100644
index 0000000..9a895f2
--- /dev/null
+++ b/ambari-web/app/views/common/time_range_list.js
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+App.TimeRangeListView = Em.View.extend({
+
+ templateName: require('templates/common/time_range_list'),
+
+ classNameBindings: [':btn-group', 'parentView.timeRangeClassName']
+
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/views/main/dashboard/widgets.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/dashboard/widgets.js b/ambari-web/app/views/main/dashboard/widgets.js
index c3a9941..264fda7 100644
--- a/ambari-web/app/views/main/dashboard/widgets.js
+++ b/ambari-web/app/views/main/dashboard/widgets.js
@@ -19,7 +19,7 @@
var App = require('app');
var filters = require('views/common/filter_view');
-App.MainDashboardWidgetsView = Em.View.extend(App.UserPref, App.LocalStorage, {
+App.MainDashboardWidgetsView = Em.View.extend(App.UserPref, App.LocalStorage, App.TimeRangeMixin, {
name: 'mainDashboardWidgetsView',
@@ -51,6 +51,8 @@ App.MainDashboardWidgetsView = Em.View.extend(App.UserPref, App.LocalStorage, {
*/
isMoving: false,
+ timeRangeClassName: 'pull-left',
+
/**
* Make widgets' list sortable on New Dashboard style
*/
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/views/main/host/summary.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/summary.js b/ambari-web/app/views/main/host/summary.js
index a97ebaf..0d76a04 100644
--- a/ambari-web/app/views/main/host/summary.js
+++ b/ambari-web/app/views/main/host/summary.js
@@ -18,7 +18,7 @@
var App = require('app');
-App.MainHostSummaryView = Em.View.extend({
+App.MainHostSummaryView = Em.View.extend(App.TimeRangeMixin, {
templateName: require('templates/main/host/summary'),
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/app/views/main/service/info/summary.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/summary.js b/ambari-web/app/views/main/service/info/summary.js
index 6a5d801..c1f96d9 100644
--- a/ambari-web/app/views/main/service/info/summary.js
+++ b/ambari-web/app/views/main/service/info/summary.js
@@ -21,7 +21,7 @@ var misc = require('utils/misc');
require('views/main/service/service');
require('data/service_graph_config');
-App.MainServiceInfoSummaryView = Em.View.extend(App.UserPref, {
+App.MainServiceInfoSummaryView = Em.View.extend(App.UserPref, App.TimeRangeMixin, {
templateName: require('templates/main/service/info/summary'),
/**
* @property {Number} chunkSize - number of columns in Metrics section
@@ -499,31 +499,11 @@ App.MainServiceInfoSummaryView = Em.View.extend(App.UserPref, {
},
/**
- * time range options for service metrics, a dropdown will list all options
- * value set in hours
- */
- timeRangeOptions: [
- {index: 0, name: Em.I18n.t('graphs.timeRange.hour'), value: '1'},
- {index: 1, name: Em.I18n.t('graphs.timeRange.twoHours'), value: '2'},
- {index: 2, name: Em.I18n.t('graphs.timeRange.fourHours'), value: '4'},
- {index: 3, name: Em.I18n.t('graphs.timeRange.twelveHours'), value: '12'},
- {index: 4, name: Em.I18n.t('graphs.timeRange.day'), value: '24'},
- {index: 5, name: Em.I18n.t('graphs.timeRange.week'), value: '168'},
- {index: 6, name: Em.I18n.t('graphs.timeRange.month'), value: '720'},
- {index: 7, name: Em.I18n.t('graphs.timeRange.year'), value: '8760'}
- ],
-
- currentTimeRangeIndex: 0,
- currentTimeRange: function() {
- return this.get('timeRangeOptions').objectAt(this.get('currentTimeRangeIndex'));
- }.property('currentTimeRangeIndex'),
-
- /**
* onclick handler for a time range option
* @param {object} event
*/
setTimeRange: function (event) {
- this.set('currentTimeRangeIndex', event.context.index);
+ this._super(event);
this.get('controller.widgets').filterProperty('widgetType', 'GRAPH').forEach(function (widget) {
widget.set('properties.time_range', event.context.value);
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/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
new file mode 100644
index 0000000..0f360fc
--- /dev/null
+++ b/ambari-web/test/mixins/common/widgets/time_range_mixin_test.js
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+require('mixins/common/widgets/time_range_mixin');
+
+describe('App.TimeRangeMixin', function () {
+
+ var obj;
+
+ beforeEach(function () {
+ obj = Em.Object.create(App.TimeRangeMixin);
+ });
+
+ describe('#currentTimeRange', function () {
+
+ var cases = Em.Object.create(App.TimeRangeMixin).get('timeRangeOptions'),
+ title = 'should set "{0}" time range';
+
+ cases.forEach(function (item) {
+ it(title.format(item.name), function () {
+ obj.set('currentTimeRangeIndex', item.index);
+ expect(obj.get('currentTimeRange')).to.eql(item);
+ });
+ });
+
+ });
+
+ describe('#setTimeRange', function () {
+
+ it('should set time range', function () {
+ obj.setTimeRange({
+ context: {
+ index: 1
+ }
+ });
+ expect(obj.get('currentTimeRangeIndex')).to.equal(1);
+ });
+
+ });
+
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/8eceffe5/ambari-web/test/views/common/chart/linear_time_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/chart/linear_time_test.js b/ambari-web/test/views/common/chart/linear_time_test.js
index 66ac5c0..7730e9c 100644
--- a/ambari-web/test/views/common/chart/linear_time_test.js
+++ b/ambari-web/test/views/common/chart/linear_time_test.js
@@ -93,7 +93,7 @@ describe('App.ChartLinearTimeView', function () {
expect(App.ChartLinearTimeView.BytesFormatter(test.i)).to.equal(test.e);
});
});
- }),
+ });
describe('#PercentageFormatter', function() {
var tests = [
{m:'undefined to "0 %"',i:undefined,e:'0 %'},
@@ -208,6 +208,48 @@ describe('App.ChartLinearTimeView', function () {
services.yarnService = [];
});
});
+
+ describe('#setCurrentTimeIndexFromParent', function () {
+
+ var view,
+ cases = [
+ {
+ isServiceWithEnhancedWidgets: false,
+ currentTimeIndex: 1,
+ title: 'service with enhanced widgets'
+ },
+ {
+ isServiceWithEnhancedWidgets: true,
+ currentTimeIndex: 2,
+ title: 'service without enhanced widgets'
+ },
+ {
+ currentTimeIndex: 2,
+ title: 'other view'
+ }
+ ];
+
+ beforeEach(function () {
+ view = App.ChartLinearTimeView.create({
+ controller: {},
+ parentView: {
+ currentTimeRangeIndex: 1,
+ parentView: {
+ currentTimeRangeIndex: 2
+ }
+ }
+ });
+ });
+
+ cases.forEach(function (item) {
+ it(item.title, function () {
+ view.set('controller.isServiceWithEnhancedWidgets', item.isServiceWithEnhancedWidgets);
+ view.propertyDidChange('parentView.currentTimeRangeIndex');
+ expect(view.get('currentTimeIndex')).to.equal(item.currentTimeIndex);
+ });
+ });
+
+ });
});