This commit is contained in:
Joseph Schorr 2013-11-27 16:56:07 -05:00
parent cca5daf097
commit 6c1d2afc0f
5 changed files with 19 additions and 21 deletions

View file

@ -720,22 +720,20 @@ quayApp.directive('logsView', function () {
return;
}
if ($scope.logs) {
return;
}
$scope.loading = true;
var url = $scope.organization ? getRestUrl('organization', $scope.organization.name, 'logs') :
getRestUrl('user/logs');
var loadLogs = Restangular.one(url);
loadLogs.customGET().then(function(resp) {
if (!$scope.chart) {
$scope.chart = new LogUsageChart(resp.logs, logKinds);
$scope.chart.draw('bar-chart');
$scope.chart = new LogUsageChart(logKinds);
$($scope.chart).bind('filteringChanged', function(e) {
$scope.$apply(function() { $scope.kindsAllowed = e.allowed; });
});
}
$scope.chart.draw('bar-chart', resp.logs);
$scope.logs = resp.logs;
$scope.loading = false;
});

View file

@ -1154,10 +1154,10 @@ function OrgAdminCtrl($rootScope, $scope, Restangular, $routeParams, UserService
$scope.membersLoading = true;
$scope.membersFound = null;
$scope.invoiceLoading = true;
$scope.logsShown = false;
$scope.logsShown = 0;
$scope.loadLogs = function() {
$scope.logsShown = true;
$scope.logsShown++;
};
$scope.planChanged = function(plan) {

View file

@ -1269,8 +1269,7 @@ RepositoryUsageChart.prototype.draw = function(container) {
/**
* A chart which displays the last seven days of actions in the account.
*/
function LogUsageChart(logData, titleMap) {
this.logs_ = logData;
function LogUsageChart(titleMap) {
this.titleMap_ = titleMap;
this.colorScale_ = d3.scale.category20();
}
@ -1279,15 +1278,15 @@ function LogUsageChart(logData, titleMap) {
/**
* Builds the D3-representation of the data.
*/
LogUsageChart.prototype.buildData_ = function() {
LogUsageChart.prototype.buildData_ = function(logs) {
var parseDate = d3.time.format("%a, %d %b %Y %H:%M:%S GMT").parse
// Build entries for each kind of event that occurred, on each day. We have one
// entry per {kind, day} pair.
var map = {};
var entries = [];
for (var i = 0; i < this.logs_.length; ++i) {
var log = this.logs_[i];
for (var i = 0; i < logs.length; ++i) {
var log = logs[i];
var title = this.titleMap_[log.kind] || log.kind;
var datetime = parseDate(log.datetime);
var formatted = (datetime.getMonth() + 1) + '/' + datetime.getDate();
@ -1424,7 +1423,10 @@ LogUsageChart.prototype.handleStateChange_ = function(e) {
/**
* Draws the chart in the given container element.
*/
LogUsageChart.prototype.draw = function(container) {
LogUsageChart.prototype.draw = function(container, logData) {
// Reset the container's contents.
document.getElementById(container).innerHTML = '<svg></svg>';
// Returns a date offset from the given date by "days" Days.
var offsetDate = function(d, days) {
var copy = new Date(d.getTime());
@ -1433,7 +1435,7 @@ LogUsageChart.prototype.draw = function(container) {
};
var that = this;
var data = this.buildData_();
var data = this.buildData_(logData);
nv.addGraph(function() {
// Build the chart itself.
var chart = nv.models.multiBarChart()