You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by wu...@apache.org on 2022/11/26 08:21:36 UTC

[ambari] branch trunk updated: AMBARI-25573: Ambari Metrics save as JSON/CSV use custom fileName instead of default name fixed (#3576)

This is an automated email from the ASF dual-hosted git repository.

wuzhiguo pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new b5294cbe51 AMBARI-25573: Ambari Metrics save as JSON/CSV use custom fileName instead of default name fixed (#3576)
b5294cbe51 is described below

commit b5294cbe51345ced2ef43ce3375893dc068288e5
Author: Yu Hou <52...@qq.com>
AuthorDate: Sat Nov 26 16:21:31 2022 +0800

    AMBARI-25573: Ambari Metrics save as JSON/CSV use custom fileName instead of default name fixed (#3576)
---
 .../mixins/common/widgets/export_metrics_mixin.js  |  9 +++--
 .../app/views/common/widget/graph_widget_view.js   | 39 +++++++++++++---------
 2 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/ambari-web/app/mixins/common/widgets/export_metrics_mixin.js b/ambari-web/app/mixins/common/widgets/export_metrics_mixin.js
index aa4f77c389..4be7bea5f5 100644
--- a/ambari-web/app/mixins/common/widgets/export_metrics_mixin.js
+++ b/ambari-web/app/mixins/common/widgets/export_metrics_mixin.js
@@ -63,14 +63,19 @@ App.ExportMetricsMixin = Em.Mixin.create({
     });
   },
 
+  getCustomFileName: function () {
+    return this.get('targetView.title').replace(/\s+/g, '_').toLowerCase();
+  },
+
   exportGraphDataSuccessCallback: function (response, request, params) {
     var seriesData = this.get('targetView').getData(response);
     if (!seriesData.length) {
       App.showAlertPopup(Em.I18n.t('graphs.noData.title'), Em.I18n.t('graphs.noData.tooltip.title'));
     } else {
       var fileType = params.isCSV ? 'csv' : 'json',
-        fileName = 'data.' + fileType,
-        data = params.isCSV ? this.prepareCSV(seriesData) : JSON.stringify(seriesData, this.jsonReplacer(), 4);
+          fileName = (Em.isEmpty(this.get('targetView.title')) ? 'data' : this.getCustomFileName()) + '.' + fileType,
+          data = params.isCSV ? this.prepareCSV(seriesData) : JSON.stringify(seriesData, this.jsonReplacer(), 4);
+
       fileUtils.downloadTextFile(data, fileType, fileName);
     }
   },
diff --git a/ambari-web/app/views/common/widget/graph_widget_view.js b/ambari-web/app/views/common/widget/graph_widget_view.js
index 324358efb8..c1b7020492 100644
--- a/ambari-web/app/views/common/widget/graph_widget_view.js
+++ b/ambari-web/app/views/common/widget/graph_widget_view.js
@@ -364,21 +364,28 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, App.ExportMetricsMixin, {
     }.observes('parentView.data')
   }),
 
-  exportGraphData: function (event) {
-    this.set('isExportMenuHidden', true);
-    var data,
-      isCSV = !!event.context,
-      fileType = isCSV ? 'csv' : 'json',
-      fileName = 'data.' + fileType,
-      metrics = this.get('data'),
-      hasData = Em.isArray(metrics) && metrics.some(function (item) {
-        return Em.isArray(item.data);
-      });
-    if (hasData) {
-      data = isCSV ? this.prepareCSV(metrics) : JSON.stringify(metrics, this.jsonReplacer(), 4);
-      fileUtils.downloadTextFile(data, fileType, fileName);
-    } else {
-      App.showAlertPopup(Em.I18n.t('graphs.noData.title'), Em.I18n.t('graphs.noData.tooltip.title'));
+    getCustomFileName: function () {
+        // get current service name if it exists.
+        var currentServiceName = Em.isEmpty(this.get('controller.content.serviceName')) ? "" : this.get('controller.content.serviceName') + '_';
+        // serviceName_widgetName_metricName
+        return (currentServiceName + this.get('content.widgetName').replace(/\s+/g, '_')).toLowerCase();
+    },
+
+    exportGraphData: function (event) {
+        this.set('isExportMenuHidden', true);
+        var data,
+            isCSV = !!event.context,
+            fileType = isCSV ? 'csv' : 'json',
+            fileName = (Em.isEmpty(this.get('content.widgetName')) ? 'data' : this.getCustomFileName()) + '.' + fileType,
+            metrics = this.get('data'),
+            hasData = Em.isArray(metrics) && metrics.some(function (item) {
+                return Em.isArray(item.data);
+            });
+        if (hasData) {
+            data = isCSV ? this.prepareCSV(metrics) : JSON.stringify(metrics, this.jsonReplacer(), 4);
+            fileUtils.downloadTextFile(data, fileType, fileName);
+        } else {
+            App.showAlertPopup(Em.I18n.t('graphs.noData.title'), Em.I18n.t('graphs.noData.tooltip.title'));
+        }
     }
-  }
 });


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ambari.apache.org
For additional commands, e-mail: commits-help@ambari.apache.org