Fix log errors on 1.8.1

This part needs further refactoring, but for now I just fixed log view to
teardown and setup things properly in all cases something changes (when element
is inserted or removed, but also when log object is changed).
This commit is contained in:
Piotr Sarnacki 2014-12-22 14:12:05 +01:00
parent e6800c80c6
commit 0a69a5424d
5 changed files with 78 additions and 47 deletions

View File

@ -1,7 +1,6 @@
Travis.JobController = Em.Controller.extend
needs: ['repo']
jobBinding: 'controllers.repo.job'
repoBinding: 'controllers.repo.repo'
commitBinding: 'job.commit'
annotationsBinding: 'job.annotations'

View File

@ -1,8 +1,9 @@
Travis.RepoController = Travis.Controller.extend
needs: ['repos', 'currentUser', 'build', 'request']
needs: ['repos', 'currentUser', 'build', 'request', 'job']
currentUserBinding: 'controllers.currentUser'
build: Ember.computed.alias('controllers.build.build')
job: Ember.computed.alias('controllers.job.job')
request: Ember.computed.alias('controllers.request.model')
slug: (-> @get('repo.slug') ).property('repo.slug')
@ -24,6 +25,9 @@ Travis.RepoController = Travis.Controller.extend
if build && jobs = build.get('jobs')
jobs.forEach (j) -> j.updateTimes()
deactivate: ->
@stopObservingLastBuild()
activate: (action) ->
@stopObservingLastBuild()
this["view#{$.camelize(action)}"]()

View File

@ -6,9 +6,6 @@ require 'travis/log_chunks'
isLoaded: false
length: 0
init: ->
@setParts()
fetchMissingParts: (partNumbers, after) ->
return if @get('notStarted')
@ -27,31 +24,34 @@ require 'travis/log_chunks'
for part in parts
@append part
setParts: ->
if parts = @get('parts')
parts: (->
#if Travis.config.pusher_log_fallback
# Travis.LogChunks.create(content: [], missingPartsCallback: => @fetchMissingParts.apply(this, arguments))
#else
Ember.ArrayProxy.create(content: [])
).property()
clearParts: ->
parts = @get('parts')
@notifyPropertyChange('parts')
Ember.run.next ->
# destroy old parts after they're refreshed
parts.destroy()
if Travis.config.pusher_log_fallback
parts = Travis.LogChunks.create(content: [], missingPartsCallback: => @fetchMissingParts.apply(this, arguments))
else
parts = Ember.ArrayProxy.create(content: [])
@set 'parts', parts
# @set 'parts', Travis.ChunkBuffer.create(content: [])
fetch: ->
console.log 'log model: fetching log' if Log.DEBUG
@setParts()
@clearParts()
handlers =
json: (json) => @loadParts(json['log']['parts'])
text: (text) => @loadText(text)
Travis.Log.Request.create(id: id, handlers: handlers).run() if id = @get('job.id')
clear: ->
@setParts()
@clearParts()
@incrementProperty('version')
append: (part) ->
return if @get('parts').isDestroying || @get('parts').isDestroyed
@get('parts').pushObject(part)
loadParts: (parts) ->

View File

@ -208,18 +208,17 @@ Travis.BuildRoute = Travis.Route.extend
model = Travis.Build.find(model) if model && !model.get
repo = @controllerFor('repo')
repo.set('build', model)
repo.activate('build')
#repo.set('build', model)
@controllerFor('build').set('build', model)
repo.set('build', model)
repo.activate('build')
#repo.set('build', model)
model: (params) ->
Travis.Build.fetch(params.build_id)
deactivate: ->
repo = @controllerFor('repo')
repo.set('build', null)
repo.set('job', null)
@controllerFor('job').set('job', null)
@controllerFor('build').set('build', null)
Travis.JobRoute = Travis.Route.extend
serialize: (model, params) ->
@ -231,19 +230,19 @@ Travis.JobRoute = Travis.Route.extend
model = Travis.Job.find(model) if model && !model.get
repo = @controllerFor('repo')
repo.set('job', model)
@controllerFor('job').set('job', model)
repo.activate('job')
if build = model.get('build')
@controllerFor('build').set('build', build)
repo.set('build', build)
model: (params) ->
Travis.Job.fetch(params.job_id)
deactivate: ->
repo = @controllerFor('repo')
repo.set('job', null)
@controllerFor('build').set('build', null)
@controllerFor('job').set('job', null)
Travis.RepoIndexRoute = Travis.Route.extend
setupController: (controller, model) ->
@ -258,8 +257,8 @@ Travis.RepoIndexRoute = Travis.Route.extend
deactivate: ->
repo = @controllerFor('repo')
repo.set('build', null)
repo.set('job', null)
@controllerFor('build').set('build', null)
@controllerFor('job').set('job', null)
Travis.RepoRoute = Travis.Route.extend
renderTemplate: ->
@ -280,6 +279,9 @@ Travis.RepoRoute = Travis.Route.extend
slug = "#{params.owner}/#{params.name}"
Travis.Repo.fetchBySlug(slug)
resetController: ->
@controllerFor('repo').deactivate()
actions:
error: (error) ->
# if error throwed has a slug (ie. it was probably repo not found)

View File

@ -2,28 +2,46 @@ require 'log'
require 'travis/lines_selector'
require 'travis/log_folder'
Log.DEBUG = false
Log.DEBUG = true
Log.LIMIT = 10000
Travis.reopen
LogView: Travis.View.extend
templateName: 'jobs/log'
logBinding: 'job.log'
contextBinding: 'job'
didInsertElement: ->
@setupLog()
logDidChange: (->
@setupLog()
).observes('log')
logWillChange: (->
@teardownLog()
).observesBefore('log')
willDestroyElement: ->
@teardownLog()
teardownLog: ->
job = @get('job')
job.unsubscribe() if job
setupLog: ->
job = @get('job')
if job
job.get('log').fetch()
job.subscribe()
willDestroyElement: ->
job = @get('job')
job.unsubscribe() if job
PreView: Em.View.extend
templateName: 'jobs/pre'
logWillChange: (->
console.log 'log view: log will change' if Log.DEBUG
@teardownLog()
).observesBefore('log')
didInsertElement: ->
console.log 'log view: did insert' if Log.DEBUG
@_super.apply this, arguments
@ -31,10 +49,7 @@ Travis.reopen
willDestroyElement: ->
console.log 'log view: will destroy' if Log.DEBUG
parts = @get('log.parts')
parts.removeArrayObserver(@, didChange: 'partsDidChange', willChange: 'noop')
parts.destroy()
@lineSelector?.willDestroy()
@teardownLog()
versionDidChange: (->
@rerender() if @get('_state') == 'inDOM'
@ -42,17 +57,28 @@ Travis.reopen
logDidChange: (->
console.log 'log view: log did change: rerender' if Log.DEBUG
@rerender() if @get('_state') == 'inDOM'
if @get('log')
@createEngine()
@rerender() if @get('_state') == 'inDOM'
).observes('log')
teardownLog: ->
if @get('log')
parts = @get('log.parts')
parts.removeArrayObserver(@, didChange: 'partsDidChange', willChange: 'noop')
parts.destroy()
@lineSelector?.willDestroy()
createEngine: ->
console.log 'log view: create engine' if Log.DEBUG
@scroll = new Log.Scroll beforeScroll: =>
@unfoldHighlight()
@engine = Log.create(limit: Log.LIMIT, listeners: [@scroll])
@logFolder = new Travis.LogFolder(@$().find('#log'))
@lineSelector = new Travis.LinesSelector(@$().find('#log'), @scroll, @logFolder)
@observeParts()
if @get('log')
console.log 'log view: create engine' if Log.DEBUG
@scroll = new Log.Scroll beforeScroll: =>
@unfoldHighlight()
@engine = Log.create(limit: Log.LIMIT, listeners: [@scroll])
@logFolder = new Travis.LogFolder(@$().find('#log'))
@lineSelector = new Travis.LinesSelector(@$().find('#log'), @scroll, @logFolder)
@observeParts()
unfoldHighlight: ->
@lineSelector.unfoldLines()