Add ability to pick the dates of the logs viewed

This commit is contained in:
Joseph Schorr 2013-12-09 17:28:23 -05:00
parent 7b38482fd9
commit a3b834cd66
8 changed files with 909 additions and 54 deletions

View file

@ -690,6 +690,10 @@ quayApp.directive('logsView', function () {
$scope.chartVisible = true;
$scope.logsPath = '';
var datetime = new Date();
$scope.logStartDate = new Date(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate() - 7);
$scope.logEndDate = new Date(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate());
var logDescriptions = {
'account_change_plan': 'Change plan',
'account_change_cc': 'Update credit card',
@ -770,11 +774,24 @@ quayApp.directive('logsView', function () {
'org_set_team_role': 'Change team permission'
};
var getDateString = function(date) {
return (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
};
var getOffsetDate = function(date, days) {
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + days);
};
var update = function() {
if (!$scope.visible || (!$scope.organization && !$scope.user && !$scope.repository)) {
return;
}
var twoWeeksAgo = getOffsetDate($scope.logEndDate, -14);
if ($scope.logStartDate >= $scope.logEndDate || $scope.logStartDate < twoWeeksAgo) {
$scope.logStartDate = twoWeeksAgo;
}
$scope.loading = true;
var url = getRestUrl('user/logs');
@ -785,10 +802,13 @@ quayApp.directive('logsView', function () {
url = getRestUrl('repository', $scope.repository.namespace, $scope.repository.name, 'logs');
}
url += '?starttime=' + encodeURIComponent(getDateString($scope.logStartDate));
url += '&endtime=' + encodeURIComponent(getDateString($scope.logEndDate));
if ($scope.performer) {
url += '?performer=' + encodeURIComponent($scope.performer.username);
url += '&performer=' + encodeURIComponent($scope.performer.username);
}
var loadLogs = Restangular.one(url);
loadLogs.customGET().then(function(resp) {
$scope.logsPath = '/api/' + url;
@ -800,7 +820,7 @@ quayApp.directive('logsView', function () {
});
}
$scope.chart.draw('bar-chart', resp.logs);
$scope.chart.draw('bar-chart', resp.logs, $scope.logStartDate, $scope.logEndDate);
$scope.kindsAllowed = null;
$scope.logs = resp.logs;
$scope.loading = false;
@ -858,6 +878,8 @@ quayApp.directive('logsView', function () {
$scope.$watch('repository', update);
$scope.$watch('visible', update);
$scope.$watch('performer', update);
$scope.$watch('logStartDate', update);
$scope.$watch('logEndDate', update);
}
};