Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Fix Add Metric in a less stupid way
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Jan 10, 2014
1 parent b411de4 commit 9f88b4d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
5 changes: 2 additions & 3 deletions panels/stats_table/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@
<i class="pointer icon-check" ng-click="metricEditor.index=-1"></i>
</td>
<td ng-show="metricEditor.index == $index">
<i ng-click="deleteMetric($index); metricEditor.index = -1;" class="pointer icon-trash"></i>
<i ng-click="deleteMetric(panel,$index); metricEditor.index = -1;" class="pointer icon-trash"></i>
<td ng-show="metricEditor.index == $index">
<i class="icon"></i></td>
</tr>
</table>
<form class="form-inline">
<!-- Not a big fan of this ng-click -->
<button class="btn btn-success" ng-click="needs_refresh(); panel.metrics.push(metricDefaults({})); metricEditor.index = panel.metrics.length-1">Add Metric</button>
<button class="btn btn-success" ng-click="needs_refresh(); addMetric(panel)">Add Metric</button>
</form>
</div>
</div>
20 changes: 15 additions & 5 deletions panels/stats_table/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ define([
}
};

$scope.metricDefaults = function (m) {
var metricDefaults = function (m) {
if (_.isUndefined($scope.modeInfo[$scope.panel.mode])) {
return [];
}
Expand All @@ -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) {
Expand All @@ -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);
});
});

Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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]);
};


Expand Down

0 comments on commit 9f88b4d

Please sign in to comment.