Add messaging when archived build logs loads fail.

This code also checks for an ad blocker, and adjusts the message accordingly.

Fixes #184
This commit is contained in:
Joseph Schorr 2015-06-28 09:14:48 +03:00
parent cea4ad2d85
commit 094c94c0fb
5 changed files with 245 additions and 8 deletions

View file

@ -14,7 +14,7 @@ angular.module('quay').directive('buildLogsView', function () {
'buildUpdated': '&buildUpdated'
},
controller: function($scope, $element, $interval, $sanitize, ansi2html, AngularViewArray,
AngularPollChannel, ApiService, Restangular) {
AngularPollChannel, ApiService, Restangular, UtilService) {
var result = $element.find('#copyButton').clipboardCopy();
if (!result) {
@ -26,6 +26,7 @@ angular.module('quay').directive('buildLogsView', function () {
$scope.logStartIndex = 0;
$scope.buildLogsText = '';
$scope.currentBuild = null;
$scope.loadError = null;
var pollChannel = null;
@ -112,12 +113,22 @@ angular.module('quay').directive('buildLogsView', function () {
ApiService.getRepoBuildLogsAsResource(params, true).withOptions(options).get(function(resp) {
// If we get a logs url back, then we need to make another XHR request to retrieve the
// data.
if (resp['logs_url']) {
var logsUrl = resp['logs_url'];
if (logsUrl) {
$.ajax({
url: resp['logs_url'],
url: logsUrl,
}).done(function(r) {
handleLogsData(r, callback);
}).error(function(xhr) {
if (xhr.status == 0) {
UtilService.isAdBlockEnabled(function(result) {
$scope.loadError = result ? 'blocked': 'request-failed';
});
} else {
$scope.loadError = 'request-failed';
}
});
return;
}

View file

@ -4,6 +4,29 @@
angular.module('quay').factory('UtilService', ['$sanitize', function($sanitize) {
var utilService = {};
var adBlockEnabled = null;
utilService.isAdBlockEnabled = function(callback) {
if (adBlockEnabled !== null) {
callback(adBlockEnabled);
return;
}
if(typeof blockAdBlock === 'undefined') {
callback(true);
return;
}
var bab = new BlockAdBlock({
checkOnLoad: false,
resetOnEnd: true
});
bab.onDetected(function() { adBlockEnabled = true; callback(true); });
bab.onNotDetected(function() { adBlockEnabled = false; callback(false); });
bab.check();
};
utilService.isEmailAddress = function(val) {
var emailRegex = /^[a-zA-Z0-9.!#$%&*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
return emailRegex.test(val);