From 9f88b4db97c70c9713b287eaf9ab95a737b2db26 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Fri, 10 Jan 2014 11:56:49 -0700 Subject: [PATCH] Fix Add Metric in a less stupid way --- panels/stats_table/editor.html | 5 ++--- panels/stats_table/module.js | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/panels/stats_table/editor.html b/panels/stats_table/editor.html index cad59134a4b0d..f28f42804202b 100644 --- a/panels/stats_table/editor.html +++ b/panels/stats_table/editor.html @@ -81,14 +81,13 @@ - +
- - +
\ No newline at end of file diff --git a/panels/stats_table/module.js b/panels/stats_table/module.js index d2491e3e14846..7b5169ec15714 100644 --- a/panels/stats_table/module.js +++ b/panels/stats_table/module.js @@ -163,7 +163,7 @@ define([ } }; - $scope.metricDefaults = function (m) { + var metricDefaults = function (m) { if (_.isUndefined($scope.modeInfo[$scope.panel.mode])) { return []; } @@ -188,7 +188,7 @@ define([ $scope.panel.metrics = _.map($scope.panel.metrics, function (m) { - return $scope.metricDefaults(m); + return metricDefaults(m); }); $scope.$watch('panel.mode', function (m) { @@ -198,7 +198,7 @@ define([ $scope.panel.display_field = $scope.modeInfo[m].defaults.display_field; $scope.panel.persistent_field = $scope.modeInfo[m].defaults.persistent_field; $scope.panel.metrics = _.map($scope.modeInfo[m].defaults.metrics, function (m) { - return $scope.metricDefaults(m); + return metricDefaults(m); }); }); @@ -710,6 +710,16 @@ define([ }; + $scope.addMetric = function (panel,metric) { + metric = metric || {}; + metric = metricDefaults(metric); + panel.metrics.push(metric); + if (!metric.field) { + // no field defined, got into edit mode.. + $scope.metricEditor.index = panel.metrics.length - 1; + } + }; + // This is expensive, it would be better to populate a scope object $scope.addMetricOptions = function (m) { if (_.isUndefined($scope.modeInfo[m])) { @@ -739,8 +749,8 @@ define([ $scope.$emit('render'); }; - $scope.deleteMetric = function (index) { - $scope.panel.metrics = _.without($scope.panel.metrics, $scope.panel.metrics[index]); + $scope.deleteMetric = function (panel,index) { + panel.metrics = _.without(panel.metrics, panel.metrics[index]); };