Repository: ambari Updated Branches: refs/heads/trunk 1e49680b1 -> 03c399c0f
AMBARI-13384. Unable to export metrics data from dashboard during the first visit of this page Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/03c399c0 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/03c399c0 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/03c399c0 Branch: refs/heads/trunk Commit: 03c399c0f2cb5945cfbc3c89f986ffa6b959a5b6 Parents: 1e49680 Author: Alex Antonenko <hiv...@gmail.com> Authored: Mon Oct 12 12:20:03 2015 +0300 Committer: Alex Antonenko <hiv...@gmail.com> Committed: Mon Oct 12 12:23:44 2015 +0300 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 1 + .../main/dashboard/widgets/cluster_metrics.hbs | 2 +- .../dashboard/widgets/cluster_metrics_widget.js | 4 +- .../widgets/cluster_metrics_widget_test.js | 88 ++++++++++++++++++++ 4 files changed, 92 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/03c399c0/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 dc86bcf..5b5f588 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -238,6 +238,7 @@ var files = [ 'test/views/main/dashboard/widgets/links_widget_test', 'test/views/main/dashboard/widgets/pie_chart_widget_test', 'test/views/main/dashboard/widgets/namenode_cpu_test', + 'test/views/main/dashboard/widgets/cluster_metrics_widget_test', 'test/views/main/host/details_test', 'test/views/main/host/summary_test', 'test/views/main/host/menu_test', http://git-wip-us.apache.org/repos/asf/ambari/blob/03c399c0/ambari-web/app/templates/main/dashboard/widgets/cluster_metrics.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/dashboard/widgets/cluster_metrics.hbs b/ambari-web/app/templates/main/dashboard/widgets/cluster_metrics.hbs index 5b5bea1..ac5ab3a 100644 --- a/ambari-web/app/templates/main/dashboard/widgets/cluster_metrics.hbs +++ b/ambari-web/app/templates/main/dashboard/widgets/cluster_metrics.hbs @@ -24,7 +24,7 @@ </a> <div class="caption span10">{{view.title}}</div> {{#if view.isDataLoaded}} - {{#if view.childViews.firstObject.hasData}} + {{#if view.childViews.lastObject.hasData}} <a class="corner-icon span1" href="#" {{action toggleFormatsList target="view"}}> <i class="icon-save"></i> </a> http://git-wip-us.apache.org/repos/asf/ambari/blob/03c399c0/ambari-web/app/views/main/dashboard/widgets/cluster_metrics_widget.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/dashboard/widgets/cluster_metrics_widget.js b/ambari-web/app/views/main/dashboard/widgets/cluster_metrics_widget.js index 58dfecb..a3d7f84 100644 --- a/ambari-web/app/views/main/dashboard/widgets/cluster_metrics_widget.js +++ b/ambari-web/app/views/main/dashboard/widgets/cluster_metrics_widget.js @@ -34,10 +34,10 @@ App.ClusterMetricsDashboardWidgetView = App.DashboardWidgetView.extend(App.Expor exportGraphData: function (event) { this._super(); - var ajaxIndex = this.get('childViews.firstObject.ajaxIndex'); + var ajaxIndex = this.get('childViews.lastObject.ajaxIndex'); App.ajax.send({ name: ajaxIndex, - data: $.extend(this.get('childViews.firstObject').getDataForAjaxRequest(), { + data: $.extend(this.get('childViews.lastObject').getDataForAjaxRequest(), { isCSV: !!event.context }), sender: this, http://git-wip-us.apache.org/repos/asf/ambari/blob/03c399c0/ambari-web/test/views/main/dashboard/widgets/cluster_metrics_widget_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/dashboard/widgets/cluster_metrics_widget_test.js b/ambari-web/test/views/main/dashboard/widgets/cluster_metrics_widget_test.js new file mode 100644 index 0000000..1471aac --- /dev/null +++ b/ambari-web/test/views/main/dashboard/widgets/cluster_metrics_widget_test.js @@ -0,0 +1,88 @@ +/** + * 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/main/dashboard/widgets/cluster_metrics_widget'); + +describe('App.ClusterMetricsDashboardWidgetView', function () { + + var view; + + beforeEach(function () { + view = App.ClusterMetricsDashboardWidgetView.create(); + }); + + describe('#exportGraphData', function () { + + beforeEach(function () { + sinon.stub(App.ajax, 'send', Em.K); + view.get('childViews').pushObjects([ + { + ajaxIndex: 'ai0', + getDataForAjaxRequest: function () { + return { + p0: 'v0' + } + } + }, + { + ajaxIndex: 'ai1', + getDataForAjaxRequest: function () { + return { + p1: 'v1' + } + } + } + ]); + }); + + afterEach(function () { + App.ajax.send.restore(); + }); + + var cases = [ + { + event: {}, + isCSV: false, + title: 'JSON export' + }, + { + event: { + context: true + }, + isCSV: true, + title: 'CSV export' + } + ]; + + cases.forEach(function (item) { + it(item.title, function () { + view.exportGraphData(item.event); + expect(App.ajax.send.calledOnce).to.be.true; + expect(App.ajax.send.firstCall.args[0].name).to.equal('ai1'); + expect(App.ajax.send.firstCall.args[0].data).to.eql({ + p1: 'v1', + isCSV: item.isCSV + }); + }); + }); + + }); + +});