From cebc8a04fcf91a1b121dd7772c7238778973dbf5 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 8 Jun 2016 15:01:32 +0200 Subject: [PATCH] Moved to global search widget to use clickable tag search. --- .../javascripts/app/controllers/tag.coffee | 7 ++ .../controllers/widget/global_search.coffee | 38 +++++++ .../app/controllers/widget/tag.coffee | 22 +--- .../javascripts/app/views/tag/table.jst.eco | 4 +- .../agent_ticket_actions_level8_test.rb | 105 ++++++++++++++++++ 5 files changed, 154 insertions(+), 22 deletions(-) create mode 100644 app/assets/javascripts/app/controllers/widget/global_search.coffee diff --git a/app/assets/javascripts/app/controllers/tag.coffee b/app/assets/javascripts/app/controllers/tag.coffee index 3dc9545af..7e7696841 100644 --- a/app/assets/javascripts/app/controllers/tag.coffee +++ b/app/assets/javascripts/app/controllers/tag.coffee @@ -54,6 +54,7 @@ class Table extends App.Controller events: 'click .js-delete': 'destroy' 'click .js-edit': 'edit' + 'click .js-search': 'search' constructor: -> super @@ -95,6 +96,12 @@ class Table extends App.Controller row: row ) + search: (e) -> + e.preventDefault() + e.stopPropagation() + item = $(e.target).closest('tr').find('.js-name').text() + App.GlobalSearchWidget.search(item, 'tag') + class Edit extends App.ControllerModal buttonClose: true buttonCancel: true diff --git a/app/assets/javascripts/app/controllers/widget/global_search.coffee b/app/assets/javascripts/app/controllers/widget/global_search.coffee new file mode 100644 index 000000000..b551b7d0b --- /dev/null +++ b/app/assets/javascripts/app/controllers/widget/global_search.coffee @@ -0,0 +1,38 @@ +class App.GlobalSearchWidget extends Spine.Module + shiftHeld = false + + constructor: -> + $('body').on('mousedown', (e) => + @shiftHeldToogle(e) + ) + App.Event.bind('global:search:set', (data) => + item = data[0] + attribute = data[1] + item = item.replace('"', '') + if item.match(/\W/) + item = "\"#{item}\"" + if !attribute + searchAttribute = "#{item}" + else + searchAttribute = "#{attribute}:#{item}" + currentValue = $('#global-search').val() + + if @shiftHeld && currentValue + currentValue += ' AND ' + currentValue += searchAttribute + else + currentValue = searchAttribute + + $('#global-search').val(currentValue) + delay = -> + $('#global-search').focus() + App.Delay.set(delay, 20, 'global-search-delay') + ) + + shiftHeldToogle: (e) -> + @shiftHeld = e.shiftKey + + @search: (item, attribute) -> + App.Event.trigger('global:search:set', [item, attribute]) + +App.Config.set('global_navigation', App.GlobalSearchWidget, 'Widgets') diff --git a/app/assets/javascripts/app/controllers/widget/tag.coffee b/app/assets/javascripts/app/controllers/widget/tag.coffee index bbe4f535b..ceecabb57 100644 --- a/app/assets/javascripts/app/controllers/widget/tag.coffee +++ b/app/assets/javascripts/app/controllers/widget/tag.coffee @@ -1,6 +1,5 @@ class App.WidgetTag extends App.Controller possibleTags: {} - shiftHeld: false elements: '.js-newTagLabel': 'newTagLabel' '.js-newTagInput': 'newTagInput' @@ -11,7 +10,6 @@ class App.WidgetTag extends App.Controller 'click .js-newTagInput': 'onAddTag' 'submit form': 'onAddTag' 'click .js-delete': 'onRemoveTag' - 'mousedown .js-tag': 'shiftHeldToogle' 'click .js-tag': 'searchTag' constructor: -> @@ -126,23 +124,7 @@ class App.WidgetTag extends App.Controller @fetch() ) - searchTag: (e) => + searchTag: (e) -> e.preventDefault() item = $(e.target).text() - item = item.replace('"', '') - if item.match(/\W/) - item = "\"#{item}\"" - searchAttribute = "tag:#{item}" - currentValue = $('#global-search').val() - if @shiftHeld && currentValue - currentValue += ' AND ' - currentValue += searchAttribute - else - currentValue = searchAttribute - $('#global-search').val(currentValue) - delay = -> - $('#global-search').focus() - @delay(delay, 20) - - shiftHeldToogle: (e) => - @shiftHeld = e.shiftKey + App.GlobalSearchWidget.search(item, 'tag') diff --git a/app/assets/javascripts/app/views/tag/table.jst.eco b/app/assets/javascripts/app/views/tag/table.jst.eco index 7b57c8078..355535465 100644 --- a/app/assets/javascripts/app/views/tag/table.jst.eco +++ b/app/assets/javascripts/app/views/tag/table.jst.eco @@ -10,8 +10,8 @@ <% for item in @list: %> <%= item.name %> - <%= item.count %> - <%- @Icon('trash') %> + <%= item.count %> + <%- @Icon('trash') %> <% end %> diff --git a/test/browser/agent_ticket_actions_level8_test.rb b/test/browser/agent_ticket_actions_level8_test.rb index 4f850c09b..8e8788297 100644 --- a/test/browser/agent_ticket_actions_level8_test.rb +++ b/test/browser/agent_ticket_actions_level8_test.rb @@ -239,6 +239,111 @@ class AgentTicketActionLevel8Test < TestCase 'tag5' => true, } ) + + # verify changes via admin interface + click( + browser: browser2, + css: 'a[href="#manage"]', + ) + click( + browser: browser2, + css: 'a[href="#manage/tags"]', + ) + sleep 3 + execute( + browser: browser2, + js: "$('#content .js-name:contains(\"tag3\")').click()", + ) + sleep 2 + set( + browser: browser2, + css: '.modal [name="name"]', + value: 'TAGXX', + ) + click( + browser: browser2, + css: '.modal .js-submit', + ) + sleep 4 + ticket_open_by_search( + browser: browser2, + number: ticket3[:number], + ) + + # verify tags + tags_verify( + tags: { + 'tag1' => false, + 'tag 2' => true, + 'tag2' => false, + 'tag3' => false, + 'tag4' => true, + 'tag5' => true, + 'TAGXX' => true, + } + ) + tags_verify( + browser: browser2, + tags: { + 'tag1' => false, + 'tag 2' => true, + 'tag2' => false, + 'tag3' => false, + 'tag4' => true, + 'tag5' => true, + 'TAGXX' => true, + } + ) + + click( + browser: browser2, + css: 'a[href="#manage"]', + ) + click( + browser: browser2, + css: 'a[href="#manage/tags"]', + ) + sleep 3 + execute( + browser: browser2, + js: "$('#content .js-name:contains(\"tag5\")').closest('tr').find('.js-delete').click()", + ) + sleep 2 + click( + browser: browser2, + css: '.modal .js-submit', + ) + sleep 4 + ticket_open_by_search( + browser: browser2, + number: ticket3[:number], + ) + + # verify tags + tags_verify( + tags: { + 'tag1' => false, + 'tag 2' => true, + 'tag2' => false, + 'tag3' => false, + 'tag4' => true, + 'tag5' => false, + 'TAGXX' => true, + } + ) + tags_verify( + browser: browser2, + tags: { + 'tag1' => false, + 'tag 2' => true, + 'tag2' => false, + 'tag3' => false, + 'tag4' => true, + 'tag5' => false, + 'TAGXX' => true, + } + ) + end def test_b_tags