2017-01-11 23:27:41 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, no-use-before-define, no-param-reassign, quotes, yoda, no-else-return, consistent-return, comma-dangle, object-shorthand, prefer-template, one-var, one-var-declaration-per-line, no-unused-vars, max-len, vars-on-top */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Breakpoints */
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
2017-01-11 23:27:41 -05:00
|
|
|
var bind = function(fn, me) { return function() { return fn.apply(me, arguments); }; };
|
2016-12-20 23:41:05 -05:00
|
|
|
var AUTO_SCROLL_OFFSET = 75;
|
2017-01-12 10:49:49 -05:00
|
|
|
var DOWN_BUILD_TRACE = '#down-build-trace';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
this.Build = (function() {
|
2017-02-14 21:36:46 -05:00
|
|
|
Build.timeout = null;
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
Build.state = null;
|
|
|
|
|
2016-08-17 14:43:28 -04:00
|
|
|
function Build(options) {
|
2016-09-08 11:50:36 -04:00
|
|
|
options = options || $('.js-build-options').data();
|
|
|
|
this.pageUrl = options.pageUrl;
|
|
|
|
this.buildUrl = options.buildUrl;
|
|
|
|
this.buildStatus = options.buildStatus;
|
2016-11-22 08:48:14 -05:00
|
|
|
this.state = options.logState;
|
2016-09-08 11:50:36 -04:00
|
|
|
this.buildStage = options.buildStage;
|
2016-08-03 16:04:40 -04:00
|
|
|
this.updateDropdown = bind(this.updateDropdown, this);
|
2016-08-24 18:44:58 -04:00
|
|
|
this.$document = $(document);
|
2016-12-09 07:26:25 -05:00
|
|
|
this.$body = $('body');
|
|
|
|
this.$buildTrace = $('#build-trace');
|
|
|
|
this.$autoScrollContainer = $('.autoscroll-container');
|
|
|
|
this.$autoScrollStatus = $('#autoscroll-status');
|
2016-12-12 11:42:24 -05:00
|
|
|
this.$autoScrollStatusText = this.$autoScrollStatus.find('.status-text');
|
2016-12-09 07:26:25 -05:00
|
|
|
this.$upBuildTrace = $('#up-build-trace');
|
2017-01-12 10:49:49 -05:00
|
|
|
this.$downBuildTrace = $(DOWN_BUILD_TRACE);
|
2016-12-09 07:26:25 -05:00
|
|
|
this.$scrollTopBtn = $('#scroll-top');
|
|
|
|
this.$scrollBottomBtn = $('#scroll-bottom');
|
2016-12-13 07:44:04 -05:00
|
|
|
this.$buildRefreshAnimation = $('.js-build-refresh');
|
2016-12-09 07:26:25 -05:00
|
|
|
|
2017-02-14 21:36:46 -05:00
|
|
|
clearTimeout(Build.timeout);
|
2016-07-26 23:32:10 -04:00
|
|
|
// Init breakpoint checker
|
2016-07-24 16:45:11 -04:00
|
|
|
this.bp = Breakpoints.get();
|
2016-09-08 11:50:36 -04:00
|
|
|
|
2016-08-24 18:44:58 -04:00
|
|
|
this.initSidebar();
|
2016-09-08 11:50:36 -04:00
|
|
|
this.$buildScroll = $('#js-build-scroll');
|
2016-08-03 16:40:10 -04:00
|
|
|
|
2016-09-08 11:50:36 -04:00
|
|
|
this.populateJobs(this.buildStage);
|
|
|
|
this.updateStageDropdownText(this.buildStage);
|
|
|
|
this.sidebarOnResize();
|
2016-08-03 16:40:10 -04:00
|
|
|
|
2016-09-08 11:50:36 -04:00
|
|
|
this.$document.off('click', '.js-sidebar-build-toggle').on('click', '.js-sidebar-build-toggle', this.sidebarOnClick.bind(this));
|
2016-08-24 18:44:58 -04:00
|
|
|
this.$document.off('click', '.stage-item').on('click', '.stage-item', this.updateDropdown);
|
2016-12-05 05:32:45 -05:00
|
|
|
this.$document.on('scroll', this.initScrollMonitor.bind(this));
|
2016-09-08 11:50:36 -04:00
|
|
|
$(window).off('resize.build').on('resize.build', this.sidebarOnResize.bind(this));
|
|
|
|
$('a', this.$buildScroll).off('click.stepTrace').on('click.stepTrace', this.stepTrace);
|
2016-07-24 16:45:11 -04:00
|
|
|
this.updateArtifactRemoveDate();
|
|
|
|
if ($('#build-trace').length) {
|
|
|
|
this.getInitialBuildTrace();
|
2016-09-08 11:50:36 -04:00
|
|
|
this.initScrollButtonAffix();
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2017-02-14 21:36:46 -05:00
|
|
|
this.invokeBuildTrace();
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
|
2016-08-24 18:44:58 -04:00
|
|
|
Build.prototype.initSidebar = function() {
|
|
|
|
this.$sidebar = $('.js-build-sidebar');
|
|
|
|
this.$sidebar.niceScroll();
|
|
|
|
this.$document.off('click', '.js-sidebar-build-toggle').on('click', '.js-sidebar-build-toggle', this.toggleSidebar);
|
|
|
|
};
|
|
|
|
|
2016-09-20 11:50:32 -04:00
|
|
|
Build.prototype.location = function() {
|
|
|
|
return window.location.href.split("#")[0];
|
|
|
|
};
|
|
|
|
|
2017-02-14 21:36:46 -05:00
|
|
|
Build.prototype.invokeBuildTrace = function() {
|
|
|
|
var continueRefreshStatuses = ['running', 'pending'];
|
|
|
|
// Continue to update build trace when build is running or pending
|
|
|
|
if (continueRefreshStatuses.indexOf(this.buildStatus) !== -1) {
|
|
|
|
// Check for new build output if user still watching build page
|
|
|
|
// Only valid for runnig build when output changes during time
|
|
|
|
Build.timeout = setTimeout((function(_this) {
|
|
|
|
return function() {
|
|
|
|
if (_this.location() === _this.pageUrl) {
|
|
|
|
return _this.getBuildTrace();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})(this), 4000);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
Build.prototype.getInitialBuildTrace = function() {
|
2017-01-10 17:54:56 -05:00
|
|
|
var removeRefreshStatuses = ['success', 'failed', 'canceled', 'skipped'];
|
2016-08-30 05:43:09 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.ajax({
|
2016-09-08 11:50:36 -04:00
|
|
|
url: this.buildUrl,
|
2016-07-24 16:45:11 -04:00
|
|
|
dataType: 'json',
|
2016-12-12 11:35:17 -05:00
|
|
|
success: function(buildData) {
|
|
|
|
$('.js-build-output').html(buildData.trace_html);
|
2017-01-12 10:49:49 -05:00
|
|
|
if (window.location.hash === DOWN_BUILD_TRACE) {
|
2017-01-02 02:31:27 -05:00
|
|
|
$("html,body").scrollTop(this.$buildTrace.height());
|
|
|
|
}
|
2017-02-25 07:43:26 -05:00
|
|
|
if (removeRefreshStatuses.indexOf(buildData.status) !== -1) {
|
2016-12-23 08:25:49 -05:00
|
|
|
this.$buildRefreshAnimation.remove();
|
|
|
|
return this.initScrollMonitor();
|
2016-12-12 11:35:17 -05:00
|
|
|
}
|
|
|
|
}.bind(this)
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Build.prototype.getBuildTrace = function() {
|
|
|
|
return $.ajax({
|
2016-09-08 11:50:36 -04:00
|
|
|
url: this.pageUrl + "/trace.json?state=" + (encodeURIComponent(this.state)),
|
2016-07-24 16:45:11 -04:00
|
|
|
dataType: "json",
|
|
|
|
success: (function(_this) {
|
|
|
|
return function(log) {
|
2017-01-02 02:31:27 -05:00
|
|
|
var pageUrl;
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
if (log.state) {
|
|
|
|
_this.state = log.state;
|
|
|
|
}
|
2017-02-14 21:36:46 -05:00
|
|
|
_this.invokeBuildTrace();
|
2016-07-24 16:45:11 -04:00
|
|
|
if (log.status === "running") {
|
|
|
|
if (log.append) {
|
|
|
|
$('.js-build-output').append(log.html);
|
|
|
|
} else {
|
|
|
|
$('.js-build-output').html(log.html);
|
|
|
|
}
|
|
|
|
return _this.checkAutoscroll();
|
2016-09-08 11:50:36 -04:00
|
|
|
} else if (log.status !== _this.buildStatus) {
|
2017-01-02 02:31:27 -05:00
|
|
|
pageUrl = _this.pageUrl;
|
|
|
|
if (_this.$autoScrollStatus.data('state') === 'enabled') {
|
2017-01-12 10:49:49 -05:00
|
|
|
pageUrl += DOWN_BUILD_TRACE;
|
2017-01-02 02:31:27 -05:00
|
|
|
}
|
|
|
|
|
2017-01-13 16:54:16 -05:00
|
|
|
return gl.utils.visitUrl(pageUrl);
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
})(this)
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Build.prototype.checkAutoscroll = function() {
|
2016-12-21 02:40:35 -05:00
|
|
|
if (this.$autoScrollStatus.data("state") === "enabled") {
|
|
|
|
return $("html,body").scrollTop(this.$buildTrace.height());
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2016-12-09 10:04:19 -05:00
|
|
|
|
|
|
|
// Handle a situation where user started new build
|
|
|
|
// but never scrolled a page
|
|
|
|
if (!this.$scrollTopBtn.is(':visible') &&
|
|
|
|
!this.$scrollBottomBtn.is(':visible') &&
|
2016-12-20 23:34:12 -05:00
|
|
|
!gl.utils.isInViewport(this.$downBuildTrace.get(0))) {
|
2016-12-09 10:04:19 -05:00
|
|
|
this.$scrollBottomBtn.show();
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
2016-09-08 11:50:36 -04:00
|
|
|
Build.prototype.initScrollButtonAffix = function() {
|
2016-12-09 10:04:19 -05:00
|
|
|
// Hide everything initially
|
2016-12-09 09:35:36 -05:00
|
|
|
this.$scrollTopBtn.hide();
|
2016-12-09 10:04:19 -05:00
|
|
|
this.$scrollBottomBtn.hide();
|
2016-12-09 07:26:25 -05:00
|
|
|
this.$autoScrollContainer.hide();
|
2017-01-10 17:54:56 -05:00
|
|
|
};
|
2016-12-05 05:32:45 -05:00
|
|
|
|
|
|
|
// Page scroll listener to detect if user has scrolling page
|
|
|
|
// and handle following cases
|
|
|
|
// 1) User is at Top of Build Log;
|
|
|
|
// - Hide Top Arrow button
|
|
|
|
// - Show Bottom Arrow button
|
|
|
|
// - Disable Autoscroll and hide indicator (when build is running)
|
|
|
|
// 2) User is at Bottom of Build Log;
|
|
|
|
// - Show Top Arrow button
|
|
|
|
// - Hide Bottom Arrow button
|
|
|
|
// - Enable Autoscroll and show indicator (when build is running)
|
|
|
|
// 3) User is somewhere in middle of Build Log;
|
|
|
|
// - Show Top Arrow button
|
|
|
|
// - Show Bottom Arrow button
|
|
|
|
// - Disable Autoscroll and hide indicator (when build is running)
|
|
|
|
Build.prototype.initScrollMonitor = function() {
|
2016-12-21 03:12:11 -05:00
|
|
|
if (!gl.utils.isInViewport(this.$upBuildTrace.get(0)) && !gl.utils.isInViewport(this.$downBuildTrace.get(0))) {
|
|
|
|
// User is somewhere in middle of Build Log
|
|
|
|
|
2016-12-13 07:44:04 -05:00
|
|
|
this.$scrollTopBtn.show();
|
2016-12-13 10:43:27 -05:00
|
|
|
|
|
|
|
if (this.buildStatus === 'success' || this.buildStatus === 'failed') { // Check if Build is completed
|
|
|
|
this.$scrollBottomBtn.show();
|
2016-12-20 23:34:12 -05:00
|
|
|
} else if (this.$buildRefreshAnimation.is(':visible') && !gl.utils.isInViewport(this.$buildRefreshAnimation.get(0))) {
|
2016-12-13 10:43:27 -05:00
|
|
|
this.$scrollBottomBtn.show();
|
|
|
|
} else {
|
|
|
|
this.$scrollBottomBtn.hide();
|
|
|
|
}
|
2016-12-05 05:32:45 -05:00
|
|
|
|
2016-12-13 07:44:04 -05:00
|
|
|
// Hide Autoscroll Status Indicator
|
2016-12-13 10:43:27 -05:00
|
|
|
if (this.$scrollBottomBtn.is(':visible')) {
|
|
|
|
this.$autoScrollContainer.hide();
|
|
|
|
this.$autoScrollStatusText.removeClass('animate');
|
|
|
|
} else {
|
2016-12-21 03:01:51 -05:00
|
|
|
this.$autoScrollContainer.css({ top: this.$body.outerHeight() - AUTO_SCROLL_OFFSET }).show();
|
2016-12-13 10:43:27 -05:00
|
|
|
this.$autoScrollStatusText.addClass('animate');
|
|
|
|
}
|
2016-12-21 03:12:11 -05:00
|
|
|
} else if (gl.utils.isInViewport(this.$upBuildTrace.get(0)) && !gl.utils.isInViewport(this.$downBuildTrace.get(0))) {
|
|
|
|
// User is at Top of Build Log
|
|
|
|
|
2016-12-13 07:44:04 -05:00
|
|
|
this.$scrollTopBtn.hide();
|
|
|
|
this.$scrollBottomBtn.show();
|
2016-12-13 10:51:13 -05:00
|
|
|
|
|
|
|
this.$autoScrollContainer.hide();
|
|
|
|
this.$autoScrollStatusText.removeClass('animate');
|
2016-12-20 23:34:12 -05:00
|
|
|
} else if ((!gl.utils.isInViewport(this.$upBuildTrace.get(0)) && gl.utils.isInViewport(this.$downBuildTrace.get(0))) ||
|
2016-12-21 03:12:11 -05:00
|
|
|
(this.$buildRefreshAnimation.is(':visible') && gl.utils.isInViewport(this.$buildRefreshAnimation.get(0)))) {
|
|
|
|
// User is at Bottom of Build Log
|
|
|
|
|
2016-12-09 09:35:36 -05:00
|
|
|
this.$scrollTopBtn.show();
|
|
|
|
this.$scrollBottomBtn.hide();
|
2016-12-05 05:32:45 -05:00
|
|
|
|
2016-12-09 07:26:25 -05:00
|
|
|
// Show and Reposition Autoscroll Status Indicator
|
2016-12-21 03:01:51 -05:00
|
|
|
this.$autoScrollContainer.css({ top: this.$body.outerHeight() - AUTO_SCROLL_OFFSET }).show();
|
2016-12-12 11:42:24 -05:00
|
|
|
this.$autoScrollStatusText.addClass('animate');
|
2016-12-21 03:12:11 -05:00
|
|
|
} else if (gl.utils.isInViewport(this.$upBuildTrace.get(0)) && gl.utils.isInViewport(this.$downBuildTrace.get(0))) {
|
|
|
|
// Build Log height is small
|
|
|
|
|
2016-12-13 07:44:04 -05:00
|
|
|
this.$scrollTopBtn.hide();
|
|
|
|
this.$scrollBottomBtn.hide();
|
2016-12-05 05:32:45 -05:00
|
|
|
|
2016-12-09 07:26:25 -05:00
|
|
|
// Hide Autoscroll Status Indicator
|
|
|
|
this.$autoScrollContainer.hide();
|
2016-12-12 11:42:24 -05:00
|
|
|
this.$autoScrollStatusText.removeClass('animate');
|
2016-12-05 05:32:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.buildStatus === "running" || this.buildStatus === "pending") {
|
2016-12-05 07:10:01 -05:00
|
|
|
// Check if Refresh Animation is in Viewport and enable Autoscroll, disable otherwise.
|
2016-12-20 23:34:12 -05:00
|
|
|
this.$autoScrollStatus.data("state", gl.utils.isInViewport(this.$buildRefreshAnimation.get(0)) ? 'enabled' : 'disabled');
|
2016-12-05 05:32:45 -05:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
2016-09-08 11:50:36 -04:00
|
|
|
Build.prototype.shouldHideSidebarForViewport = function() {
|
2016-07-24 16:45:11 -04:00
|
|
|
var bootstrapBreakpoint;
|
|
|
|
bootstrapBreakpoint = this.bp.getBreakpointSize();
|
|
|
|
return bootstrapBreakpoint === 'xs' || bootstrapBreakpoint === 'sm';
|
|
|
|
};
|
|
|
|
|
2016-09-08 11:50:36 -04:00
|
|
|
Build.prototype.toggleSidebar = function(shouldHide) {
|
|
|
|
var shouldShow = typeof shouldHide === 'boolean' ? !shouldHide : undefined;
|
|
|
|
this.$buildScroll.toggleClass('sidebar-expanded', shouldShow)
|
|
|
|
.toggleClass('sidebar-collapsed', shouldHide);
|
|
|
|
this.$sidebar.toggleClass('right-sidebar-expanded', shouldShow)
|
|
|
|
.toggleClass('right-sidebar-collapsed', shouldHide);
|
|
|
|
};
|
|
|
|
|
|
|
|
Build.prototype.sidebarOnResize = function() {
|
|
|
|
this.toggleSidebar(this.shouldHideSidebarForViewport());
|
|
|
|
};
|
|
|
|
|
|
|
|
Build.prototype.sidebarOnClick = function() {
|
|
|
|
if (this.shouldHideSidebarForViewport()) this.toggleSidebar();
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
Build.prototype.updateArtifactRemoveDate = function() {
|
|
|
|
var $date, date;
|
|
|
|
$date = $('.js-artifacts-remove');
|
|
|
|
if ($date.length) {
|
|
|
|
date = $date.text();
|
2016-11-18 07:26:08 -05:00
|
|
|
return $date.text(gl.utils.timeFor(new Date(date.replace(/([0-9]+)-([0-9]+)-([0-9]+)/g, '$1/$2/$3')), ' '));
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-17 12:46:41 -04:00
|
|
|
Build.prototype.populateJobs = function(stage) {
|
2016-08-03 16:04:40 -04:00
|
|
|
$('.build-job').hide();
|
|
|
|
$('.build-job[data-stage="' + stage + '"]').show();
|
|
|
|
};
|
|
|
|
|
2016-08-03 16:40:10 -04:00
|
|
|
Build.prototype.updateStageDropdownText = function(stage) {
|
|
|
|
$('.stage-selection').text(stage);
|
|
|
|
};
|
|
|
|
|
2016-08-03 16:04:40 -04:00
|
|
|
Build.prototype.updateDropdown = function(e) {
|
|
|
|
e.preventDefault();
|
2016-08-17 14:43:28 -04:00
|
|
|
var stage = e.currentTarget.text;
|
2016-08-03 16:40:10 -04:00
|
|
|
this.updateStageDropdownText(stage);
|
2016-08-17 12:46:41 -04:00
|
|
|
this.populateJobs(stage);
|
2016-08-01 16:46:50 -04:00
|
|
|
};
|
|
|
|
|
2016-09-09 14:50:53 -04:00
|
|
|
Build.prototype.stepTrace = function(e) {
|
2016-12-14 00:26:26 -05:00
|
|
|
var $currentTarget;
|
2016-09-09 15:01:48 -04:00
|
|
|
e.preventDefault();
|
|
|
|
$currentTarget = $(e.currentTarget);
|
|
|
|
$.scrollTo($currentTarget.attr('href'), {
|
2017-01-04 14:27:20 -05:00
|
|
|
offset: 0
|
2016-09-09 15:01:48 -04:00
|
|
|
});
|
2016-09-09 14:50:53 -04:00
|
|
|
};
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return Build;
|
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|