debian-mirror-gitlab/app/assets/javascripts/ci/build.coffee

65 lines
2 KiB
CoffeeScript
Raw Normal View History

2015-09-25 12:07:36 +05:30
class CiBuild
@interval: null
2016-06-02 11:05:42 +05:30
@state: null
2015-09-25 12:07:36 +05:30
2016-06-02 11:05:42 +05:30
constructor: (build_url, build_status, build_state) ->
2015-09-25 12:07:36 +05:30
clearInterval(CiBuild.interval)
2016-06-02 11:05:42 +05:30
@state = build_state
@initScrollButtonAffix()
2015-09-25 12:07:36 +05:30
if build_status == "running" || build_status == "pending"
#
# Bind autoscroll button to follow build output
#
$("#autoscroll-button").bind "click", ->
state = $(this).data("state")
if "enabled" is state
$(this).data "state", "disabled"
$(this).text "enable autoscroll"
else
$(this).data "state", "enabled"
$(this).text "disable autoscroll"
#
# Check for new build output if user still watching build page
# Only valid for runnig build when output changes during time
#
CiBuild.interval = setInterval =>
2015-10-24 18:46:33 +05:30
if window.location.href.split("#").first() is build_url
2016-06-02 11:05:42 +05:30
last_state = @state
2015-09-25 12:07:36 +05:30
$.ajax
2016-06-02 11:05:42 +05:30
url: build_url + "/trace.json?state=" + encodeURIComponent(@state)
2015-09-25 12:07:36 +05:30
dataType: "json"
2016-06-02 11:05:42 +05:30
success: (log) =>
return unless last_state is @state
if log.state and log.status is "running"
@state = log.state
if log.append
$('.fa-refresh').before log.html
else
$('#build-trace code').html log.html
$('#build-trace code').append '<i class="fa fa-refresh fa-spin"/>'
2015-09-25 12:07:36 +05:30
@checkAutoscroll()
2016-06-02 11:05:42 +05:30
else if log.status isnt build_status
2015-09-25 12:07:36 +05:30
Turbolinks.visit build_url
, 4000
checkAutoscroll: ->
$("html,body").scrollTop $("#build-trace").height() if "enabled" is $("#autoscroll-button").data("state")
2016-06-02 11:05:42 +05:30
initScrollButtonAffix: ->
$buildScroll = $('#js-build-scroll')
$body = $('body')
$buildTrace = $('#build-trace')
$buildScroll.affix(
offset:
bottom: ->
$body.outerHeight() - ($buildTrace.outerHeight() + $buildTrace.offset().top)
)
2015-09-25 12:07:36 +05:30
@CiBuild = CiBuild