2016-11-15 09:08:06 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, space-before-blocks, prefer-rest-params, wrap-iife, no-use-before-define, no-param-reassign, no-undef, quotes, yoda, no-else-return, consistent-return, comma-dangle, semi, object-shorthand, prefer-template, one-var, one-var-declaration-per-line, no-unused-vars, max-len, vars-on-top, padded-blocks, max-len */
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
|
|
|
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
|
|
|
|
|
|
|
this.Build = (function() {
|
|
|
|
Build.interval = null;
|
|
|
|
|
|
|
|
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-07-24 16:45:11 -04:00
|
|
|
clearInterval(Build.interval);
|
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-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
|
|
|
}
|
2016-09-08 11:50:36 -04:00
|
|
|
if (this.buildStatus === "running" || this.buildStatus === "pending") {
|
2016-09-20 11:50:32 -04:00
|
|
|
// Bind autoscroll button to follow build output
|
2016-07-24 16:45:11 -04:00
|
|
|
$('#autoscroll-button').on('click', function() {
|
|
|
|
var state;
|
|
|
|
state = $(this).data("state");
|
|
|
|
if ("enabled" === state) {
|
|
|
|
$(this).data("state", "disabled");
|
2016-09-08 11:50:36 -04:00
|
|
|
return $(this).text("Enable autoscroll");
|
2016-07-24 16:45:11 -04:00
|
|
|
} else {
|
|
|
|
$(this).data("state", "enabled");
|
2016-09-08 11:50:36 -04:00
|
|
|
return $(this).text("Disable autoscroll");
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Build.interval = setInterval((function(_this) {
|
2016-09-20 11:50:32 -04:00
|
|
|
// Check for new build output if user still watching build page
|
|
|
|
// Only valid for runnig build when output changes during time
|
2016-07-24 16:45:11 -04:00
|
|
|
return function() {
|
2016-09-20 11:50:32 -04:00
|
|
|
if (_this.location() === _this.pageUrl) {
|
2016-07-24 16:45:11 -04:00
|
|
|
return _this.getBuildTrace();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})(this), 4000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 18:44:58 -04:00
|
|
|
Build.prototype.initSidebar = function() {
|
|
|
|
this.$sidebar = $('.js-build-sidebar');
|
|
|
|
this.sidebarTranslationLimits = {
|
|
|
|
min: $('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight()
|
|
|
|
}
|
|
|
|
this.sidebarTranslationLimits.max = this.sidebarTranslationLimits.min + $('.scrolling-tabs-container').outerHeight();
|
|
|
|
this.$sidebar.css({
|
|
|
|
top: this.sidebarTranslationLimits.max
|
|
|
|
});
|
|
|
|
this.$sidebar.niceScroll();
|
|
|
|
this.$document.off('click', '.js-sidebar-build-toggle').on('click', '.js-sidebar-build-toggle', this.toggleSidebar);
|
|
|
|
this.$document.off('scroll.translateSidebar').on('scroll.translateSidebar', this.translateSidebar.bind(this));
|
|
|
|
};
|
|
|
|
|
2016-09-20 11:50:32 -04:00
|
|
|
Build.prototype.location = function() {
|
|
|
|
return window.location.href.split("#")[0];
|
|
|
|
};
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
Build.prototype.getInitialBuildTrace = function() {
|
2016-08-30 05:43:09 -04:00
|
|
|
var removeRefreshStatuses = ['success', 'failed', 'canceled', 'skipped']
|
|
|
|
|
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-09-08 11:50:36 -04:00
|
|
|
success: function(buildData) {
|
|
|
|
$('.js-build-output').html(buildData.trace_html);
|
|
|
|
if (removeRefreshStatuses.indexOf(buildData.status) >= 0) {
|
2016-07-24 16:45:11 -04:00
|
|
|
return $('.js-build-refresh').remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (log.state) {
|
|
|
|
_this.state = log.state;
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
return Turbolinks.visit(_this.pageUrl);
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
})(this)
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Build.prototype.checkAutoscroll = function() {
|
|
|
|
if ("enabled" === $("#autoscroll-button").data("state")) {
|
|
|
|
return $("html,body").scrollTop($("#build-trace").height());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-08 11:50:36 -04:00
|
|
|
Build.prototype.initScrollButtonAffix = function() {
|
|
|
|
var $body, $buildTrace;
|
2016-07-24 16:45:11 -04:00
|
|
|
$body = $('body');
|
|
|
|
$buildTrace = $('#build-trace');
|
2016-09-08 11:50:36 -04:00
|
|
|
return this.$buildScroll.affix({
|
2016-07-24 16:45:11 -04:00
|
|
|
offset: {
|
|
|
|
bottom: function() {
|
|
|
|
return $body.outerHeight() - ($buildTrace.outerHeight() + $buildTrace.offset().top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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-08-24 18:44:58 -04:00
|
|
|
Build.prototype.translateSidebar = function(e) {
|
2016-10-22 18:14:52 -04:00
|
|
|
var newPosition = this.sidebarTranslationLimits.max - (document.body.scrollTop || document.documentElement.scrollTop);
|
2016-08-24 18:44:58 -04:00
|
|
|
if (newPosition < this.sidebarTranslationLimits.min) newPosition = this.sidebarTranslationLimits.min;
|
|
|
|
this.$sidebar.css({
|
|
|
|
top: newPosition
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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-09-09 15:01:48 -04:00
|
|
|
e.preventDefault();
|
|
|
|
$currentTarget = $(e.currentTarget);
|
|
|
|
$.scrollTo($currentTarget.attr('href'), {
|
|
|
|
offset: -($('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight())
|
|
|
|
});
|
2016-09-09 14:50:53 -04:00
|
|
|
};
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return Build;
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
}).call(this);
|