Skip to content

Commit

Permalink
Merge pull request #260 from EverythingMe/fix_queue_name
Browse files Browse the repository at this point in the history
Fix: dashboard filters broken after #252
  • Loading branch information
arikfr committed Aug 7, 2014
2 parents 762c331 + 59d5ba9 commit eba2ba1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 29 deletions.
60 changes: 33 additions & 27 deletions rd_ui/app/scripts/controllers/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function() {
var DashboardCtrl = function($scope, Events, Widget, $routeParams, $http, $timeout, Dashboard) {
var DashboardCtrl = function($scope, Events, Widget, $routeParams, $http, $timeout, $q, Dashboard) {
$scope.refreshEnabled = false;
$scope.refreshRate = 60;

Expand All @@ -8,43 +8,49 @@
Events.record(currentUser, "view", "dashboard", dashboard.id);

$scope.$parent.pageTitle = dashboard.name;
var filters = {};

var promises = [];

$scope.dashboard.widgets = _.map($scope.dashboard.widgets, function (row) {
return _.map(row, function (widget) {
var w = new Widget(widget);

if (w.visualization && dashboard.dashboard_filters_enabled) {
var queryFilters = w.getQuery().getQueryResult().getFilters();
_.each(queryFilters, function (filter) {
if (!_.has(filters, filter.name)) {
// TODO: first object should be a copy, otherwise one of the chart filters behaves different than the others.
filters[filter.name] = filter;
filters[filter.name].originFilters = [];

$scope.$watch(function () {
return filter.current
}, function (value) {
_.each(filter.originFilters, function (originFilter) {
originFilter.current = value;
})
});

}
;

// TODO: merge values.
filters[filter.name].originFilters.push(filter);
});
promises.push(w.getQuery().getQueryResultPromise());
}

return w;
});
});

if (dashboard.dashboard_filters_enabled) {
$scope.filters = _.values(filters);
}
$q.all(promises).then(function(queryResults) {
var filters = {};
_.each(queryResults, function(queryResult) {
var queryFilters = queryResult.getFilters();
_.each(queryFilters, function (filter) {
if (!_.has(filters, filter.name)) {
// TODO: first object should be a copy, otherwise one of the chart filters behaves different than the others.
filters[filter.name] = filter;
filters[filter.name].originFilters = [];

$scope.$watch(function () { return filter.current }, function (value) {
_.each(filter.originFilters, function (originFilter) {
originFilter.current = value;
});
});
};

// TODO: merge values.
filters[filter.name].originFilters.push(filter);
});
});

if (dashboard.dashboard_filters_enabled) {
$scope.filters = _.values(filters);
}
});


}, function () {
// error...
// try again. we wrap loadDashboard with throttle so it doesn't happen too often.\
Expand Down Expand Up @@ -131,7 +137,7 @@
};

angular.module('redash.controllers')
.controller('DashboardCtrl', ['$scope', 'Events', 'Widget', '$routeParams', '$http', '$timeout', 'Dashboard', DashboardCtrl])
.controller('DashboardCtrl', ['$scope', 'Events', 'Widget', '$routeParams', '$http', '$timeout', '$q', 'Dashboard', DashboardCtrl])
.controller('WidgetCtrl', ['$scope', 'Events', 'Query', WidgetCtrl])

})();
16 changes: 14 additions & 2 deletions rd_ui/app/scripts/services/resources.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function () {
var QueryResult = function ($resource, $timeout) {
var QueryResult = function ($resource, $timeout, $q) {
var QueryResultResource = $resource('/api/query_results/:id', {id: '@id'}, {'post': {'method': 'POST'}});
var Job = $resource('/api/jobs/:id', {id: '@id'});

Expand Down Expand Up @@ -32,6 +32,7 @@
}
});

this.deferred.resolve(this);
} else if (this.job.status == 3) {
this.status = "processing";
} else {
Expand All @@ -40,6 +41,7 @@
}

function QueryResult(props) {
this.deferred = $q.defer();
this.job = {};
this.query_result = {};
this.status = "waiting";
Expand Down Expand Up @@ -349,6 +351,10 @@
});

return queryResult;
};

QueryResult.prototype.toPromise = function() {
return this.deferred.promise;
}

QueryResult.get = function (data_source_id, query, ttl) {
Expand Down Expand Up @@ -404,9 +410,15 @@
return this.queryResult;
};

Query.prototype.getQueryResultPromise = function() {
return this.getQueryResult().toPromise();
}

return Query;
};



var DataSource = function ($resource) {
var DataSourceResource = $resource('/api/data_sources/:id', {id: '@id'}, {'get': {'method': 'GET', 'cache': true, 'isArray': true}});

Expand Down Expand Up @@ -435,7 +447,7 @@
}

angular.module('redash.services')
.factory('QueryResult', ['$resource', '$timeout', QueryResult])
.factory('QueryResult', ['$resource', '$timeout', '$q', QueryResult])
.factory('Query', ['$resource', 'QueryResult', 'DataSource', Query])
.factory('DataSource', ['$resource', DataSource])
.factory('Widget', ['$resource', 'Query', Widget]);
Expand Down

0 comments on commit eba2ba1

Please sign in to comment.