Revert tailing changes
This commit is contained in:
parent
492802920e
commit
d7bef2b94e
|
@ -33,7 +33,7 @@ unless window.TravisApplication
|
||||||
|
|
||||||
@slider = new Travis.Slider()
|
@slider = new Travis.Slider()
|
||||||
@pusher = new Travis.Pusher(Travis.config.pusher_key) if Travis.config.pusher_key
|
@pusher = new Travis.Pusher(Travis.config.pusher_key) if Travis.config.pusher_key
|
||||||
@tailing = new Travis.Tailing($(window), '#tail', '#log')
|
@tailing = new Travis.Tailing()
|
||||||
|
|
||||||
@set('auth', Travis.Auth.create(app: this, endpoint: Travis.config.api_endpoint))
|
@set('auth', Travis.Auth.create(app: this, endpoint: Travis.config.api_endpoint))
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
class @Travis.Tailing
|
@Travis.Tailing = ->
|
||||||
|
@position = $(window).scrollTop()
|
||||||
|
$(window).scroll( $.throttle( 200, @onScroll.bind(this) ) )
|
||||||
|
this
|
||||||
|
|
||||||
|
$.extend Travis.Tailing.prototype,
|
||||||
options:
|
options:
|
||||||
timeout: 200
|
timeout: 200
|
||||||
|
|
||||||
tail: ->
|
|
||||||
$(@tail_selector)
|
|
||||||
log: ->
|
|
||||||
$(@log_selector)
|
|
||||||
|
|
||||||
constructor: (@window, @tail_selector, @log_selector) ->
|
|
||||||
@position = @window.scrollTop()
|
|
||||||
@window.scroll( $.throttle( 200, @onScroll.bind(this) ) )
|
|
||||||
this
|
|
||||||
|
|
||||||
run: ->
|
run: ->
|
||||||
@autoScroll()
|
@autoScroll()
|
||||||
@positionButton()
|
@positionButton()
|
||||||
|
@ -21,43 +16,37 @@ class @Travis.Tailing
|
||||||
if @active() then @stop() else @start()
|
if @active() then @stop() else @start()
|
||||||
|
|
||||||
active: ->
|
active: ->
|
||||||
@tail().hasClass('active')
|
$('#tail').hasClass('active')
|
||||||
|
|
||||||
start: ->
|
start: ->
|
||||||
@tail().addClass('active')
|
$('#tail').addClass('active')
|
||||||
@run()
|
@run()
|
||||||
|
|
||||||
stop: ->
|
stop: ->
|
||||||
@tail().removeClass('active')
|
$('#tail').removeClass('active')
|
||||||
|
|
||||||
autoScroll: ->
|
autoScroll: ->
|
||||||
return false unless @active()
|
return unless @active()
|
||||||
logBottom = @log().offset().top + @log().outerHeight() + 40
|
win = $(window)
|
||||||
winBottom = @window.scrollTop() + @window.height()
|
log = $('#log')
|
||||||
|
logBottom = log.offset().top + log.outerHeight() + 40
|
||||||
if logBottom - winBottom > 0
|
winBottom = win.scrollTop() + win.height()
|
||||||
@window.scrollTop(logBottom - @window.height())
|
win.scrollTop(logBottom - win.height()) if logBottom - winBottom > 0
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
|
|
||||||
onScroll: ->
|
onScroll: ->
|
||||||
@positionButton()
|
@positionButton()
|
||||||
position = @window.scrollTop()
|
position = $(window).scrollTop()
|
||||||
@stop() if position < @position
|
@stop() if position < @position
|
||||||
@position = position
|
@position = position
|
||||||
|
|
||||||
positionButton: ->
|
positionButton: ->
|
||||||
return if @tail().length is 0
|
tail = $('#tail')
|
||||||
offset = @window.scrollTop() - @log().offset().top
|
return if tail.length is 0
|
||||||
max = @log().height() - @tail().height() + 5
|
offset = $(window).scrollTop() - $('#log').offset().top
|
||||||
|
max = $('#log').height() - $('#tail').height() + 5
|
||||||
|
offset = max if offset > max
|
||||||
|
if offset > 0
|
||||||
|
tail.css(top: offset - 2)
|
||||||
|
else
|
||||||
|
tail.css(top: 0)
|
||||||
|
|
||||||
if offset > 0 && offset <= max
|
|
||||||
@tail().removeClass('bottom')
|
|
||||||
@tail().addClass('scrolling')
|
|
||||||
else
|
|
||||||
if offset > max
|
|
||||||
@tail().addClass('bottom')
|
|
||||||
else
|
|
||||||
@tail().removeClass('bottom')
|
|
||||||
@tail().removeClass('scrolling')
|
|
||||||
|
|
|
@ -1,14 +1,7 @@
|
||||||
<div id="log-container">
|
<div id="log-container">
|
||||||
<a href="#" id="tail" {{action "toggleTailing" target="view"}}>
|
<a href="#" id="tail" {{action "toggleTailing" target="view"}}>
|
||||||
<span class="status"></span>
|
<span class="status"></span>
|
||||||
|
<label>Follow logs</label>
|
||||||
<label>
|
|
||||||
{{#if view.job.isFinished}}
|
|
||||||
Scroll to end of logs
|
|
||||||
{{else}}
|
|
||||||
Follow logs
|
|
||||||
{{/if}}
|
|
||||||
</label>
|
|
||||||
</a>
|
</a>
|
||||||
<pre id="log" class="ansi"></pre>
|
<pre id="log" class="ansi"></pre>
|
||||||
|
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
fakeWindow =
|
|
||||||
scroll: sinon.spy()
|
|
||||||
scrollTop: sinon.stub().returns(0)
|
|
||||||
height: sinon.stub().returns(40)
|
|
||||||
element = jQuery('<div id="specTail"></div>')
|
|
||||||
log = jQuery('<div id="specLog"></div>')
|
|
||||||
tail = new Travis.Tailing(fakeWindow, '#specTail', '#specLog')
|
|
||||||
tail.tail = -> element
|
|
||||||
tail.log = -> log
|
|
||||||
|
|
||||||
module "Travis.Tailing",
|
|
||||||
setup: ->
|
|
||||||
jQuery('body').append(element)
|
|
||||||
jQuery('body').append(log)
|
|
||||||
|
|
||||||
teardown: ->
|
|
||||||
element.remove()
|
|
||||||
log.remove()
|
|
||||||
tail.stop()
|
|
||||||
|
|
||||||
test "toggle", ->
|
|
||||||
equal(element.hasClass('active'), false)
|
|
||||||
tail.toggle()
|
|
||||||
equal(element.hasClass('active'), true)
|
|
||||||
tail.toggle()
|
|
||||||
stop()
|
|
||||||
|
|
||||||
Ember.run.later ->
|
|
||||||
start()
|
|
||||||
equal(element.hasClass('active'), false)
|
|
||||||
, 300
|
|
||||||
|
|
||||||
test "active", ->
|
|
||||||
equal(tail.active(), false)
|
|
||||||
element.addClass('active')
|
|
||||||
equal(tail.active(), true)
|
|
||||||
|
|
||||||
test "autoscroll when inactive", ->
|
|
||||||
tail.scrollTo = sinon.spy()
|
|
||||||
|
|
||||||
equal(tail.active(), false)
|
|
||||||
equal(tail.autoScroll(), false)
|
|
||||||
equal(tail.scrollTo.called, false)
|
|
||||||
|
|
||||||
test "autoscroll", ->
|
|
||||||
element.addClass('active')
|
|
||||||
log.offset = -> {top: 1}
|
|
||||||
log.outerHeight = -> 1
|
|
||||||
|
|
||||||
equal(tail.active(), true)
|
|
||||||
equal(tail.autoScroll(), true)
|
|
||||||
equal(fakeWindow.scrollTop.calledWith(2), true)
|
|
||||||
|
|
||||||
test "autoscroll when we're at the bottom", ->
|
|
||||||
element.addClass('active')
|
|
||||||
log.offset = -> {top: 0}
|
|
||||||
log.outerHeight = -> 0
|
|
||||||
|
|
||||||
equal(tail.active(), true)
|
|
||||||
equal(tail.autoScroll(), false)
|
|
||||||
equal(fakeWindow.scrollTop.calledWith(0), false)
|
|
||||||
|
|
||||||
test 'should stop scrolling if the position changed', ->
|
|
||||||
element.addClass('active')
|
|
||||||
tail.position = 100
|
|
||||||
tail.onScroll()
|
|
||||||
equal(element.hasClass('active'), false)
|
|
||||||
|
|
||||||
test 'positionButton adds the scrolling class', ->
|
|
||||||
log.offset = -> {top: -1}
|
|
||||||
|
|
||||||
tail.positionButton()
|
|
||||||
equal(element.hasClass('scrolling'), true)
|
|
||||||
equal(element.hasClass('bottom'), false)
|
|
||||||
|
|
||||||
test 'positionButton removes the scrolling class', ->
|
|
||||||
log.offset = -> {top: 1}
|
|
||||||
tail.positionButton()
|
|
||||||
equal(element.hasClass('scrolling'), false)
|
|
||||||
equal(element.hasClass('bottom'), false)
|
|
||||||
|
|
||||||
test 'positionButton sets the button as bottom', ->
|
|
||||||
log.offset = -> {top: -100}
|
|
||||||
log.height = -> 50
|
|
||||||
tail.height = -> 1
|
|
||||||
|
|
||||||
tail.positionButton()
|
|
||||||
equal(element.hasClass('scrolling'), false)
|
|
||||||
equal(element.hasClass('bottom'), true)
|
|
|
@ -88,8 +88,7 @@ pre#log
|
||||||
#log-container
|
#log-container
|
||||||
position: relative
|
position: relative
|
||||||
|
|
||||||
#log-container
|
#log-container #tail
|
||||||
#tail
|
|
||||||
z-index: 99
|
z-index: 99
|
||||||
position: absolute
|
position: absolute
|
||||||
display: block
|
display: block
|
||||||
|
@ -119,14 +118,6 @@ pre#log
|
||||||
label
|
label
|
||||||
display: inline
|
display: inline
|
||||||
|
|
||||||
&.scrolling
|
|
||||||
position: fixed
|
|
||||||
right: 32px
|
|
||||||
|
|
||||||
&.bottom
|
|
||||||
bottom: 45px
|
|
||||||
top: inherit
|
|
||||||
|
|
||||||
.status
|
.status
|
||||||
display: inline-block
|
display: inline-block
|
||||||
margin-right: 1px
|
margin-right: 1px
|
||||||
|
@ -138,16 +129,3 @@ pre#log
|
||||||
|
|
||||||
&.active .status
|
&.active .status
|
||||||
background-color: #6b0
|
background-color: #6b0
|
||||||
|
|
||||||
.to-top
|
|
||||||
position: fixed
|
|
||||||
display: inline-block
|
|
||||||
bottom: 5px
|
|
||||||
right: 35px
|
|
||||||
width: 50px
|
|
||||||
float: right
|
|
||||||
margin-right: 2px
|
|
||||||
padding-right: 16px
|
|
||||||
text-align: right
|
|
||||||
color: #999
|
|
||||||
background: inline-image('ui/to-top.png') no-repeat right 6px
|
|
||||||
|
|
|
@ -3,3 +3,12 @@
|
||||||
// float: left
|
// float: left
|
||||||
margin-top: 0
|
margin-top: 0
|
||||||
color: #999
|
color: #999
|
||||||
|
.to-top
|
||||||
|
display: inline-block
|
||||||
|
width: 50px
|
||||||
|
float: right
|
||||||
|
margin-right: 2px
|
||||||
|
padding-right: 16px
|
||||||
|
text-align: right
|
||||||
|
color: #999
|
||||||
|
background: inline-image('ui/to-top.png') no-repeat right 6px
|
||||||
|
|
Loading…
Reference in New Issue
Block a user