From 9169b6fb889a0744c52c4e6a1cb211de4f991bbd Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 9 Jun 2016 12:46:53 +0200 Subject: [PATCH] Improved tag and link widget. --- .../app/controllers/ticket_zoom.coffee | 5 +-- .../app/controllers/widget/link.coffee | 18 ++++---- .../app/controllers/widget/tag.coffee | 42 +++++++++++-------- .../agent_ticket_actions_level8_test.rb | 9 ++-- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index 85159f38b..b85e113c0 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -198,7 +198,6 @@ class App.TicketZoom extends App.Controller "#ticket/zoom/#{@ticket_id}" show: (params) => - @navupdate(url: '#', type: 'menu') # set all notifications to seen @@ -413,8 +412,8 @@ class App.TicketZoom extends App.Controller @initDone = true # if shown was before init rendering, start actions again - if @shown - @positionPageHeaderStart() + return if !@shown + @positionPageHeaderStart() App.Event.trigger('ui::ticket::shown', { ticket_id: @ticket_id }) scrollToBottom: => diff --git a/app/assets/javascripts/app/controllers/widget/link.coffee b/app/assets/javascripts/app/controllers/widget/link.coffee index be77e8144..97a851d9c 100644 --- a/app/assets/javascripts/app/controllers/widget/link.coffee +++ b/app/assets/javascripts/app/controllers/widget/link.coffee @@ -9,9 +9,11 @@ class App.WidgetLink extends App.Controller # if links are given, do not init fetch if @links + @localLinks = _.clone(@links) @render() - else - @fetch() + return + + @fetch() fetch: => # fetch item on demand @@ -25,20 +27,20 @@ class App.WidgetLink extends App.Controller link_object_value: @object.id processData: true success: (data, status, xhr) => - @links = data.links + @localLinks = data.links App.Collection.loadAssets(data.assets) @render() ) - reload: (links) -> - @links = links + reload: (links) => + @localLinks = _.clone(links) @render() render: => - return if @lastLinks && _.isEqual(@lastLinks, @links) - @lastLinks = @links + return if @lastLocalLinks && _.isEqual(@lastLocalLinks, @localLinks) + @lastLocalLinks = _.clone(@localLinks) list = {} - for item in @links + for item in @localLinks if !list[ item['link_type'] ] list[ item['link_type'] ] = [] diff --git a/app/assets/javascripts/app/controllers/widget/tag.coffee b/app/assets/javascripts/app/controllers/widget/tag.coffee index ceecabb57..3bcef170e 100644 --- a/app/assets/javascripts/app/controllers/widget/tag.coffee +++ b/app/assets/javascripts/app/controllers/widget/tag.coffee @@ -1,4 +1,6 @@ class App.WidgetTag extends App.Controller + editMode: false + pendingRefresh: false possibleTags: {} elements: '.js-newTagLabel': 'newTagLabel' @@ -18,12 +20,14 @@ class App.WidgetTag extends App.Controller @key = "tags::#{@object_type}::#{@object.id}" if @tags + @localTags = _.clone(@tags) @render() return @fetch() fetch: => + @pendingRefresh = false @ajax( id: @key type: 'GET' @@ -33,19 +37,22 @@ class App.WidgetTag extends App.Controller o_id: @object.id processData: true success: (data, status, xhr) => - @tags = data.tags + @localTags = data.tags @render() ) - reload: (tags) -> - @tags = tags + reload: (tags) => + if @editMode + @pendingRefresh = true + return + @localTags = _.clone(tags) @render() - render: -> - return if @lastTags && _.isEqual(@lastTags, @tags) - @lastTags = @tags + render: => + return if @lastLocalTags && _.isEqual(@lastLocalTags, @localTags) + @lastLocalTags = _.clone(@localTags) @html App.view('widget/tag')( - tags: @tags || [], + tags: @localTags || [], ) source = "#{App.Config.get('api_path')}/tag_search" @@ -59,21 +66,26 @@ class App.WidgetTag extends App.Controller @possibleTags[item.value] = true ) - showInput: (e) -> + showInput: (e) => e.preventDefault() @newTagLabel.addClass('hide') @newTagInput.removeClass('hide').focus() + @editMode = true - hideOrAddInput: (e) -> + hideOrAddInput: (e) => e.preventDefault() @newTagLabel.removeClass('hide') @newTagInput.addClass('hide') @onAddTag(e) + @editMode = false onAddTag: (e) => e.preventDefault() item = @$('[name="new_tag"]').val().trim() - return if !item + if !item + if @pendingRefresh + @fetch() + return @add(item) add: (items) => @@ -82,11 +94,11 @@ class App.WidgetTag extends App.Controller @addItem(item) addItem: (item) => - if _.contains(@tags, item) + if _.contains(@localTags, item) @render() return return if App.Config.get('tag_new') is false && !@possibleTags[item] - @tags.push item + @localTags.push item @render() @ajax( @@ -97,8 +109,6 @@ class App.WidgetTag extends App.Controller o_id: @object.id item: item processData: true, - success: (data, status, xhr) => - @fetch() ) onRemoveTag: (e) => @@ -109,7 +119,7 @@ class App.WidgetTag extends App.Controller remove: (item) => - @tags = _.filter(@tags, (tagItem) -> return tagItem if tagItem isnt item) + @localTags = _.filter(@localTags, (tagItem) -> return tagItem if tagItem isnt item) @render() @ajax( @@ -120,8 +130,6 @@ class App.WidgetTag extends App.Controller o_id: @object.id item: item processData: true - success: (data, status, xhr) => - @fetch() ) searchTag: (e) -> diff --git a/test/browser/agent_ticket_actions_level8_test.rb b/test/browser/agent_ticket_actions_level8_test.rb index 8e8788297..585bf68ff 100644 --- a/test/browser/agent_ticket_actions_level8_test.rb +++ b/test/browser/agent_ticket_actions_level8_test.rb @@ -114,10 +114,11 @@ class AgentTicketActionLevel8Test < TestCase css: '.content.active .js-newTagInput', value: 'tag1', ) + sleep 2 sendkey( value: :enter, ) - sleep 0.5 + sleep 2 # set tag #2 click( @@ -130,7 +131,7 @@ class AgentTicketActionLevel8Test < TestCase sendkey( value: :enter, ) - sleep 0.5 + sleep 2 # set tag #3 + #4 click( @@ -143,7 +144,7 @@ class AgentTicketActionLevel8Test < TestCase sendkey( value: :enter, ) - sleep 0.5 + sleep 2 # set tag #5 click( @@ -156,7 +157,7 @@ class AgentTicketActionLevel8Test < TestCase click( css: '#global-search', ) - sleep 0.5 + sleep 2 # verify tags tags_verify(