Skip to content

Commit

Permalink
#399 Fix multiline chart filter computation
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Dec 18, 2017
1 parent 041410a commit 0cdd707
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
4 changes: 4 additions & 0 deletions ui/app/scripts/directives/dashboard/filter-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
return;
}
var field = scope.metadata[scope.entity].attributes[filter.field];

if(!field) {
return;
}
var type = field.type;

if ((type === 'string' || type === 'number') && field.values.length > 0) {
Expand Down
28 changes: 7 additions & 21 deletions ui/app/scripts/directives/dashboard/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,14 @@
scope.aggregations = DashboardSrv.aggregations;
scope.serieTypes = DashboardSrv.serieTypes;
scope.sortOptions = DashboardSrv.sortOptions;
scope.skipFields = DashboardSrv.skipFields;
scope.pickFields = DashboardSrv.pickFields;
scope.fieldsForAggregation = DashboardSrv.fieldsForAggregation;

scope.layout = {
activeTab: 0
};
scope.query = null;
scope.skipFields = function(fields, types) {
return _.filter(fields, function(item) {
return types.indexOf(item.type) === -1;
});
};

scope.pickFields = function(fields, types) {
return _.filter(fields, function(item) {
return types.indexOf(item.type) !== -1;
});
}

scope.fieldsForAggregation = function(fields, agg) {
if(agg === 'count') {
return [];
} else if(agg === 'sum' || agg === 'avg') {
return scope.pickFields(fields, ['number']);
} else {
return fields;
}
}

if(scope.component.id) {
scope.$on('edit-chart-' + scope.component.id, function(data) {
Expand Down Expand Up @@ -116,6 +98,10 @@
scope.setFilterField = function(filter, entity) {
var field = scope.metadata[entity].attributes[filter.field];

if(!field) {
return;
}

filter.type = field.type;

if (field.type === 'date') {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/directives/dashboard/multiline.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
return;
}

var query = DashboardSrv.buildChartQuery(null, scope.options.query);
var query = DashboardSrv.buildChartQuery(scope.filter, scope.options.query);
var postData = {
stats: _.map(scope.options.series, function(serie, index) {
return scope.buildSerie(serie, query, index);
Expand Down
22 changes: 22 additions & 0 deletions ui/app/scripts/services/DashboardSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,28 @@
}
];

this.skipFields = function(fields, types) {
return _.filter(fields, function(item) {
return types.indexOf(item.type) === -1;
});
};

this.pickFields = function(fields, types) {
return _.filter(fields, function(item) {
return types.indexOf(item.type) !== -1;
});
}

this.fieldsForAggregation = function(fields, agg) {
if(agg === 'count') {
return [];
} else if(agg === 'sum' || agg === 'avg') {
return self.pickFields(fields, ['number']);
} else {
return fields;
}
}

this.renderers = {
severity: function() {}
};
Expand Down

0 comments on commit 0cdd707

Please sign in to comment.