- Add copy button to the build logs

- Add support for timestamps in the build logs
- Other small UI improvements to the build view
This commit is contained in:
Joseph Schorr 2015-02-27 16:00:32 -05:00
parent e227d7e526
commit ed46d37ea7
12 changed files with 189 additions and 18 deletions

View file

@ -10,18 +10,35 @@ angular.module('quay').directive('buildLogsView', function () {
restrict: 'C',
scope: {
'build': '=build',
'useTimestamps': '=useTimestamps',
'buildUpdated': '&buildUpdated'
},
controller: function($scope, $element, $interval, $sanitize, ansi2html, AngularViewArray,
AngularPollChannel, ApiService, Restangular) {
var result = $element.find('#copyButton').clipboardCopy();
if (!result) {
$element.find('#copyButton').hide();
}
$scope.logEntries = null;
$scope.currentParentEntry = null;
$scope.logStartIndex = 0;
$scope.buildLogsText = '';
var pollChannel = null;
var currentBuild = null;
var appendToTextLog = function(type, message) {
if (type == 'phase') {
text = 'Starting phase: ' + message + '\n';
} else {
text = message + '\n';
}
$scope.buildLogsText += text.replace(new RegExp("\\033\\[[^m]+m"), '');
};
var processLogs = function(logs, startIndex, endIndex) {
if (!$scope.logEntries) { $scope.logEntries = []; }
@ -43,6 +60,8 @@ angular.module('quay').directive('buildLogsView', function () {
} else if ($scope.currentParentEntry) {
$scope.currentParentEntry['logs'].push(entry);
}
appendToTextLog(type, entry['message']);
}
return endIndex;
@ -112,6 +131,11 @@ angular.module('quay').directive('buildLogsView', function () {
}
};
$scope.$watch('useTimestamps', function() {
if (!$scope.logEntries) { return; }
$scope.logEntries = $scope.logEntries.slice();
});
$scope.$watch('build', function(build) {
if (build) {
startWatching(build);
@ -124,6 +148,11 @@ angular.module('quay').directive('buildLogsView', function () {
return container.logs.hasEntries;
};
$scope.formatDatetime = function(datetimeString) {
var dt = new Date(datetimeString);
return dt.toLocaleString();
}
$scope.processANSI = function(message, container) {
var filter = container.logs._filter = (container.logs._filter || ansi2html.create());

View file

@ -23,6 +23,9 @@ $.fn.clipboardCopy = function() {
ZeroClipboard.on('aftercopy', function(e) {
var container = e.target.parentNode.parentNode.parentNode;
var message = $(container).find('.clipboard-copied-message')[0];
if (!message) {
return;
}
// Resets the animation.
var elem = message;

View file

@ -8,11 +8,13 @@
});
}]);
function BuildViewCtrl($scope, ApiService, $routeParams, AngularPollChannel) {
function BuildViewCtrl($scope, ApiService, $routeParams, AngularPollChannel, CookieService) {
$scope.namespace = $routeParams.namespace;
$scope.name = $routeParams.name;
$scope.build_uuid = $routeParams.buildid;
$scope.showLogTimestamps = CookieService.get('quay.showBuildLogTimestamps') == 'true';
var loadBuild = function() {
var params = {
'repository': $scope.namespace + '/' + $scope.name,
@ -39,6 +41,26 @@
loadRepository();
loadBuild();
$scope.askCancelBuild = function(build) {
bootbox.confirm('Are you sure you want to cancel this build?', function(r) {
if (r) {
var params = {
'repository': $scope.namespace + '/' + $scope.name,
'build_uuid': build.id
};
ApiService.cancelRepoBuild(null, params).then(function() {
document.location = '/repository/' + $scope.namespace + '/' + $scope.name;
}, ApiService.errorDisplay('Cannot cancel build'));
}
});
};
$scope.toggleTimestamps = function() {
$scope.showLogTimestamps = !$scope.showLogTimestamps;
CookieService.putPermanent('quay.showBuildLogTimestamps', $scope.showLogTimestamps);
};
$scope.setUpdatedBuild = function(build) {
$scope.build = build;
};