From 86cd0f8a1380422da50159aff41f77810381fc0b Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 18 Aug 2015 14:21:02 +0200 Subject: [PATCH] Fix switching log when redirecting without changing routes When the log changes, but without a route change (like when you switch from one job to another job), we need to properly clean up and set up a new log. The best way I figured out is to do it in didUpdateAttrs hook, but only when the log actually changes. In such situation the old and the new log should be past to teardown and setup functions. --- app/components/log-content.coffee | 35 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/app/components/log-content.coffee b/app/components/log-content.coffee index 78c774c3..f3289c00 100644 --- a/app/components/log-content.coffee +++ b/app/components/log-content.coffee @@ -56,19 +56,21 @@ LogContentComponent = Ember.Component.extend console.log 'log view: will destroy' if Log.DEBUG @teardownLog() - teardownLog: -> - if log = @get('log') + teardownLog: (log) -> + if log || log = @get('log') parts = log.get('parts') parts.removeArrayObserver(@, didChange: 'partsDidChange', willChange: 'noop') parts.destroy() log.notifyPropertyChange('parts') @lineSelector?.willDestroy() - # log should do it on destroy - this.$('#log').empty() + if logElement = this.$('#log') + logElement.empty() + + createEngine: (log) -> + if log || log = @get('log') + if logElement = this.$('#log') + logElement.empty() - createEngine: -> - if log = @get('log') - console.log 'log view: create engine' if Log.DEBUG log.onClear => @teardownLog() @createEngine() @@ -81,17 +83,24 @@ LogContentComponent = Ember.Component.extend @engine.limit = @limit @logFolder = new LogFolder(@$('#log')) @lineSelector = new LinesSelector(@$('#log'), @scroll, @logFolder) - @observeParts() + @observeParts(log) - didUpdateAttrs: -> - @teardownLog() - @createEngine() + didUpdateAttrs: (changes) -> + @_super.apply(this, arguments) + + return unless changes.oldAttrs + + if changes.newAttrs.job.value && changes.oldAttrs.job.value && + changes.newAttrs.job.value != changes.oldAttrs.job.value + + @teardownLog(changes.oldAttrs.job.value.get('log')) + @createEngine(changes.newAttrs.job.value.get('log')) unfoldHighlight: -> @lineSelector.unfoldLines() - observeParts: -> - if log = @get('log') + observeParts: (log) -> + if log || log = @get('log') parts = log.get('parts') parts.addArrayObserver(@, didChange: 'partsDidChange', willChange: 'noop') parts = parts.slice(0)