gitlab-org--gitlab-foss/app/assets/javascripts/ci/build.coffee

42 lines
1.4 KiB
CoffeeScript
Raw Normal View History

2015-08-25 21:42:46 -04:00
class CiBuild
@interval: null
constructor: (build_url, build_status) ->
clearInterval(CiBuild.interval)
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-21 06:34:09 -04:00
if window.location.href.split("#").first() is build_url
2015-08-25 21:42:46 -04:00
$.ajax
url: build_url
dataType: "json"
success: (build) =>
if build.status == "running"
$('#build-trace code').html build.trace_html
$('#build-trace code').append '<i class="fa fa-refresh fa-spin"/>'
2015-08-25 21:42:46 -04:00
@checkAutoscroll()
2015-10-23 05:40:57 -04:00
else if build.status != build_status
2015-08-25 21:42:46 -04:00
Turbolinks.visit build_url
, 4000
checkAutoscroll: ->
$("html,body").scrollTop $("#build-trace").height() if "enabled" is $("#autoscroll-button").data("state")
@CiBuild = CiBuild