BigW Consortium Gitlab

build.coffee 1.66 KB
Newer Older
1 2 3 4 5 6
class CiBuild
  @interval: null

  constructor: (build_url, build_status) ->
    clearInterval(CiBuild.interval)

7 8
    @initScrollButtonAffix()

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    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 =>
27
        if window.location.href.split("#").first() is build_url
28 29 30 31 32 33
          $.ajax
            url: build_url
            dataType: "json"
            success: (build) =>
              if build.status == "running"
                $('#build-trace code').html build.trace_html
34
                $('#build-trace code').append '<i class="fa fa-refresh fa-spin"/>'
35
                @checkAutoscroll()
36
              else if build.status != build_status
37 38 39 40 41 42
                Turbolinks.visit build_url
      , 4000

  checkAutoscroll: ->
    $("html,body").scrollTop $("#build-trace").height()  if "enabled" is $("#autoscroll-button").data("state")

43
  initScrollButtonAffix: ->
Phil Hughes committed
44 45 46
    $buildScroll = $('#js-build-scroll')
    $body = $('body')
    $buildTrace = $('#build-trace')
47

Phil Hughes committed
48
    $buildScroll.affix(
49 50
      offset:
        bottom: ->
Phil Hughes committed
51
          $body.outerHeight() - ($buildTrace.outerHeight() + $buildTrace.offset().top)
52 53
    )

54
@CiBuild = CiBuild