diff --git a/rd_ui/app/scripts/controllers/query_view.js b/rd_ui/app/scripts/controllers/query_view.js
index 93e8c2ea08..63a7379772 100644
--- a/rd_ui/app/scripts/controllers/query_view.js
+++ b/rd_ui/app/scripts/controllers/query_view.js
@@ -168,6 +168,8 @@
return;
}
+ $scope.filters = $scope.queryResult.getFilters();
+
if ($scope.queryResult.getId() == null) {
$scope.dataUri = "";
} else {
diff --git a/rd_ui/app/scripts/ng_highchart.js b/rd_ui/app/scripts/ng_highchart.js
index 9bbc2b1ee0..8aed056e73 100644
--- a/rd_ui/app/scripts/ng_highchart.js
+++ b/rd_ui/app/scripts/ng_highchart.js
@@ -181,17 +181,13 @@
}, true);
//Update when charts data changes
- scope.$watch(function () {
- // TODO: this might be an issue in case the series change, but they stay
- // with the same length
- return (scope.series && scope.series.length) || 0;
- }, function (length) {
- if (!length || length == 0) {
+ scope.$watchCollection('series', function (series) {
+ if (!series || series.length == 0) {
scope.chart.showLoading();
} else {
drawChart();
};
- }, true);
+ });
});
function initChart(options) {
diff --git a/rd_ui/app/scripts/services/services.js b/rd_ui/app/scripts/services/services.js
index 9a4f5d870d..8d95659a48 100644
--- a/rd_ui/app/scripts/services/services.js
+++ b/rd_ui/app/scripts/services/services.js
@@ -7,6 +7,8 @@
angular.extend(this, props);
if ('query_result' in props) {
this.status = "done";
+ this.filters = undefined;
+ this.filterFreeze = undefined;
_.each(this.query_result.data.rows, function (row) {
_.each(row, function (v, k) {
@@ -26,6 +28,8 @@
this.job = {};
this.query_result = {};
this.status = "waiting";
+ this.filters = undefined;
+ this.filterFreeze = undefined;
this.updatedAt = moment();
@@ -76,15 +80,51 @@
return this.query_result.runtime;
}
- QueryResult.prototype.getData = function() {
+ QueryResult.prototype.getRawData = function() {
if (!this.query_result.data) {
return null;
}
var data = this.query_result.data.rows;
+
return data;
}
+ QueryResult.prototype.getData = function() {
+ if (!this.query_result.data) {
+ return null;
+ }
+
+ var filterValues = function(filters) {
+ if (!filters) {
+ return null;
+ }
+
+ return _.reduce(filters, function(str, filter) {
+ return str + filter.current;
+ }, "")
+ }
+
+ var filters = this.getFilters();
+ var filterFreeze = filterValues(filters);
+
+ if (this.filterFreeze != filterFreeze) {
+ this.filterFreeze = filterFreeze;
+
+ if (filters) {
+ this.filteredData = _.filter(this.query_result.data.rows, function (row) {
+ return _.reduce(filters, function (memo, filter) {
+ return (memo && row[filter.name] == filter.current);
+ }, true);
+ });
+ } else {
+ this.filteredData = this.query_result.data.rows;
+ }
+ }
+
+ return this.filteredData;
+ }
+
QueryResult.prototype.getChartData = function () {
var series = {};
@@ -181,6 +221,14 @@
}
QueryResult.prototype.getFilters = function () {
+ if (!this.filters) {
+ this.prepareFilters();
+ }
+
+ return this.filters;
+ };
+
+ QueryResult.prototype.prepareFilters = function() {
var filterNames = [];
_.each(this.getColumns(), function (col) {
if (col.split('::')[1] == 'filter') {
@@ -189,7 +237,7 @@
});
var filterValues = [];
- _.each(this.getData(), function (row) {
+ _.each(this.getRawData(), function (row) {
_.each(filterNames, function (filter, i) {
if (filterValues[i] == undefined) {
filterValues[i] = [];
@@ -198,7 +246,7 @@
})
});
- var filters = _.map(filterNames, function (filter, i) {
+ this.filters = _.map(filterNames, function (filter, i) {
var f = {
name: filter,
friendlyName: this.getColumnFriendlyName(filter),
@@ -208,9 +256,7 @@
f.current = f.values[0];
return f;
}, this);
-
- return filters;
- };
+ }
var refreshStatus = function(queryResult, query, ttl) {
Job.get({'id': queryResult.job.id}, function(response) {
diff --git a/rd_ui/app/scripts/visualizations/base.js b/rd_ui/app/scripts/visualizations/base.js
index d940edbe04..5a0a34daf4 100644
--- a/rd_ui/app/scripts/visualizations/base.js
+++ b/rd_ui/app/scripts/visualizations/base.js
@@ -64,8 +64,11 @@
// TODO: using switch here (and in the options editor) might introduce errors and bad
// performance wise. It's better to eventually show the correct template based on the
// visualization type and not make the browser render all of them.
- template: Visualization.renderVisualizationsTemplate,
- replace: false
+ template: '