From 6c1d2afc0f9e093dc50607205697b9fb265aef0c Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 27 Nov 2013 16:56:07 -0500 Subject: [PATCH] CL fixes --- data/model.py | 10 +++++----- endpoints/index.py | 2 -- static/js/app.js | 8 +++----- static/js/controllers.js | 4 ++-- static/js/graphing.js | 16 +++++++++------- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/data/model.py b/data/model.py index 896f6545f..976868a26 100644 --- a/data/model.py +++ b/data/model.py @@ -1057,14 +1057,14 @@ def delete_webhook(namespace_name, repository_name, public_id): webhook.delete_instance() def list_logs(user_or_organization_name): - account = User.get(User.username == user_or_organization_name) week_ago = datetime.today() - timedelta(7) # One week - return LogEntry.select().where(LogEntry.account == account, LogEntry.datetime >= week_ago).order_by(LogEntry.datetime.desc()) + joined = LogEntry.select().join(User) + return joined.where(User.username == user_or_organization_name, LogEntry.datetime >= week_ago).order_by(LogEntry.datetime.desc()) def log_action(kind_name, user_or_organization_name, performer=None, repository=None, access_token=None, ip=None, description=None, metadata={}): kind = LogEntryKind.get(LogEntryKind.name == kind_name) account = User.get(User.username == user_or_organization_name) - entry = LogEntry.create(kind = kind, account = account, performer = performer, - repository = repository, access_token = access_token, ip = ip, - description = description, metadata_json = json.dumps(metadata)) + entry = LogEntry.create(kind=kind, account=account, performer=performer, + repository=repository, access_token=access_token, ip=ip, + description=description, metadata_json=json.dumps(metadata)) diff --git a/endpoints/index.py b/endpoints/index.py index cc1163687..a04bdbda4 100644 --- a/endpoints/index.py +++ b/endpoints/index.py @@ -16,8 +16,6 @@ from auth.permissions import (ModifyRepositoryPermission, UserPermission, ReadRepositoryPermission, CreateRepositoryPermission) -from util.log import log_action - logger = logging.getLogger(__name__) diff --git a/static/js/app.js b/static/js/app.js index 990938646..708e9b3c5 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -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; }); diff --git a/static/js/controllers.js b/static/js/controllers.js index eeb389fa0..5e913b7c2 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -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) { diff --git a/static/js/graphing.js b/static/js/graphing.js index 302f3d0aa..798f8a1f1 100644 --- a/static/js/graphing.js +++ b/static/js/graphing.js @@ -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 = ''; + // 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()