Sha256: e3aca19c3678529c7d1c4691dfb06292d8cf76063a160ce14578c028adb065ba

Contents?: true

Size: 1.88 KB

Versions: 11

Compression:

Stored size: 1.88 KB

Contents

class Teabag.Reporters.HTML.ProgressView extends Teabag.Reporters.BaseView

  @create: (displayProgress = true) ->
    return new Teabag.Reporters.HTML.ProgressView() unless displayProgress
    if Teabag.Reporters.HTML.RadialProgressView.supported
      new Teabag.Reporters.HTML.RadialProgressView()
    else
      new Teabag.Reporters.HTML.SimpleProgressView()


  build: ->
    @el = @createEl("div", "teabag-indicator modeset-logo")


  update: ->
    # do nothing



class Teabag.Reporters.HTML.SimpleProgressView extends Teabag.Reporters.HTML.ProgressView

  build: ->
    @el = @createEl("div", "simple-progress")
    @el.innerHTML = """
      <em id="teabag-progress-percent">0%</em>
      <span id="teabag-progress-span" class="teabag-indicator"></span>
    """


  update: (total, run) ->
    percent = if total then Math.ceil((run * 100) / total) else 0
    @setHtml("progress-percent", "#{percent}%")



class Teabag.Reporters.HTML.RadialProgressView extends Teabag.Reporters.HTML.ProgressView

  @supported: !!document.createElement("canvas").getContext

  build: ->
    @el = @createEl("div", "teabag-indicator radial-progress")
    @el.innerHTML = """
      <canvas id="teabag-progress-canvas"></canvas>
      <em id="teabag-progress-percent">0%</em>
    """

  appendTo: ->
    super
    @size = 80
    try
      canvas = @findEl("progress-canvas")
      canvas.width = canvas.height = canvas.style.width = canvas.style.height = @size
      @ctx = canvas.getContext("2d")
      @ctx.strokeStyle = "#fff"
      @ctx.lineWidth = 1.5
    catch e # intentionally do nothing


  update: (total, run) ->
    percent = if total then Math.ceil((run * 100) / total) else 0
    @setHtml("progress-percent", "#{percent}%")
    return unless @ctx
    half = @size / 2
    @ctx.clearRect(0, 0, @size, @size)
    @ctx.beginPath()
    @ctx.arc(half, half, half - 1, 0, Math.PI * 2 * (percent / 100), false)
    @ctx.stroke()

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
teabag-0.7.3 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee
teabag-0.7.2 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee
teabag-0.7.1 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee
teabag-0.7.0 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee
teabag-0.6.0 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee
teabag-0.5.5 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee
teabag-0.5.4 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee
teabag-0.5.3 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee
teabag-0.5.2 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee
teabag-0.5.1 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee
teabag-0.5.0 app/assets/javascripts/teabag/base/reporters/html/progress_view.coffee