Moved to global search widget to use clickable tag search.

This commit is contained in:
Martin Edenhofer 2016-06-08 15:01:32 +02:00
parent db20bb5fc9
commit cebc8a04fc
5 changed files with 154 additions and 22 deletions

View file

@ -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

View file

@ -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')

View file

@ -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')

View file

@ -10,8 +10,8 @@
<% for item in @list: %>
<tr data-id="<%= item.id %>" class="js-edit u-clickable">
<td class="js-name"><%= item.name %></td>
<td><%= item.count %></td>
<td><a href="#" class="js-delete" title="<%- @Ti('Delete') %>"><%- @Icon('trash') %></a></td>
<td class="js-search"><a href="#"><%= item.count %></a></td>
<td class="js-delete"><a href="#" title="<%- @Ti('Delete') %>"><%- @Icon('trash') %></a></td>
</tr>
<% end %>
</tbody>

View file

@ -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