From 783b34726080d4d61035a263ecd0f256f77bb726 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 7 Oct 2015 07:32:28 +0200 Subject: [PATCH] Improve rerender of articles. --- .../ticket_zoom/article_view.coffee | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee index 138f3cd14..3565dcd45 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_view.coffee @@ -20,7 +20,7 @@ class App.TicketZoomArticleView extends App.Controller @el.append( all ) class ArticleViewItem extends App.Controller - hasChangedAttributes: ['from', 'to', 'cc', 'subject', 'body', 'internal', 'preferences'] + hasChangedAttributes: ['from', 'to', 'cc', 'subject', 'body', 'preferences'] elements: '.textBubble-content': 'textBubbleContent' @@ -59,7 +59,7 @@ class ArticleViewItem extends App.Controller App.TicketArticle.unsubscribe(@subscribeId) setHighlighter: => - return if !@el.is(':visible') + return if @el.is(':hidden') # use delay do no ui blocking #@highligher.loadHighlights(@ticket_article_id) d = => @@ -69,19 +69,19 @@ class ArticleViewItem extends App.Controller hasChanged: (article) => # if no last article exists, remember it and return true - if !@article_last_updated - @article_last_updated = {} + if !@articleAttributesLastUpdate + @articleAttributesLastUpdate = {} for item in @hasChangedAttributes - @article_last_updated[item] = article[item] + @articleAttributesLastUpdate[item] = article[item] return true # compare last and current article attributes - article_last_updated_check = {} + articleAttributesLastUpdateCheck = {} for item in @hasChangedAttributes - article_last_updated_check[item] = article[item] - diff = difference(@article_last_updated, article_last_updated_check) + articleAttributesLastUpdateCheck[item] = article[item] + diff = difference(@articleAttributesLastUpdate, articleAttributesLastUpdateCheck) return false if !diff || _.isEmpty( diff ) - @article_last_updated = article_last_updated_check + @articleAttributesLastUpdate = articleAttributesLastUpdateCheck true render: (article) => @@ -90,16 +90,22 @@ class ArticleViewItem extends App.Controller @article = App.TicketArticle.fullLocal( @ticket_article_id ) # set @el attributes - @el.addClass("ticket-article-item #{@article.sender.name.toLowerCase()}") - if @article.internal is true - @el.addClass('is-internal') - else - @el.removeClass('is-internal') - @el.attr('data-id', @article.id) - @el.attr('id', "article-#{@article.id}") + if !article + @el.addClass("ticket-article-item #{@article.sender.name.toLowerCase()}") + @el.attr('data-id', @article.id) + @el.attr('id', "article-#{@article.id}") + + # set internal change directly in dom, without rerender while article + if !article || ( @lastArticle && @lastArticle.internal isnt @article.internal ) + if @article.internal is true + @el.addClass('is-internal') + else + @el.removeClass('is-internal') # check if rerender is needed - return if !@hasChanged(@article) + if !@hasChanged(@article) + @lastArticle = @article.attributes() + return # prepare html body if @article.content_type is 'text/html' @@ -128,14 +134,16 @@ class ArticleViewItem extends App.Controller # set see more @shown = false - @setSeeMore() + a = => + @setSeeMore() + @delay( a, 50 ) # set highlighter @setHighlighter() # set see more options setSeeMore: => - return if !@el.is(':visible') + return if @el.is(':hidden') return if @shown @shown = true