diff --git a/app/assets/javascripts/app/controllers/widget/user.coffee b/app/assets/javascripts/app/controllers/widget/user.coffee index f0ad335c5..76ce45329 100644 --- a/app/assets/javascripts/app/controllers/widget/user.coffee +++ b/app/assets/javascripts/app/controllers/widget/user.coffee @@ -14,6 +14,15 @@ class App.WidgetUser extends App.Controller release: => App.User.unsubscribe(@subscribeId) + getAdvancedSearchUrl: (customer_id, states) -> + states_string = '' + if states.length > 1 + states_string = ' AND state.name:("' + states.join('" OR "') + '")' + else + states_string = " AND state.name:\"#{states[0]}\"" + + return "/#search/customer_id:#{customer_id}#{states_string}" + render: (user) => # execute callback on render/rerender @@ -48,8 +57,9 @@ class App.WidgetUser extends App.Controller if user.preferences items = [] if user.preferences.tickets_open > 0 + states_open = App.TicketState.byCategory('open').map((state) -> state.name) item = - url: '' + url: @getAdvancedSearchUrl(@user_id, states_open) name: 'open' count: user.preferences.tickets_open title: 'Open Tickets' @@ -57,8 +67,9 @@ class App.WidgetUser extends App.Controller data: 'open' items.push item if user.preferences.tickets_closed > 0 + states_closed = App.TicketState.byCategory('closed').map((state) -> state.name) item = - url: '' + url: @getAdvancedSearchUrl(@user_id, states_closed) name: 'closed' count: user.preferences.tickets_closed title: 'Closed Tickets' diff --git a/app/assets/javascripts/app/models/ticket_state.coffee b/app/assets/javascripts/app/models/ticket_state.coffee index 5e3ab39fb..f57a57ce5 100644 --- a/app/assets/javascripts/app/models/ticket_state.coffee +++ b/app/assets/javascripts/app/models/ticket_state.coffee @@ -11,4 +11,54 @@ class App.TicketState extends App.Model @configure_translate = true @configure_overview = [ 'name', - ] \ No newline at end of file + ] + + @byCategory: (category) -> + switch category + when 'open' + state_types = ['new', 'open', 'pending reminder', 'pending action'] + break + when 'pending_reminder' + state_types = ['pending reminder'] + break + when 'pending_action' + state_types = ['pending action'] + break + when 'pending' + state_types = ['pending reminder', 'pending action'] + break + when 'work_on' + state_types = ['new', 'open'] + break + when 'work_on_all' + state_types = ['new', 'open', 'pending reminder'] + break + when 'viewable' + state_types = ['new', 'open', 'pending reminder', 'pending action', 'closed', 'removed'] + break + when 'viewable_agent_new' + state_types = ['new', 'open', 'pending reminder', 'pending action', 'closed'] + break + when 'viewable_agent_edit' + state_types = ['open', 'pending reminder', 'pending action', 'closed'] + break + when 'viewable_customer_new' + state_types = ['new', 'closed'] + break + when 'viewable_customer_edit' + state_types = ['open', 'closed'] + break + when 'closed' + state_types = ['closed'] + break + when 'merged' + state_types = ['merged'] + break + else + state_types = [] + + result = [] + for state in App.TicketState.all() + continue if !_.contains(state_types, App.TicketStateType.find(state.state_type_id).name) + result.push(state) + result diff --git a/spec/system/ticket/zoom_spec.rb b/spec/system/ticket/zoom_spec.rb index 8c5b83d74..085706104 100644 --- a/spec/system/ticket/zoom_spec.rb +++ b/spec/system/ticket/zoom_spec.rb @@ -1652,4 +1652,30 @@ RSpec.describe 'Ticket zoom', type: :system do end end end + + context 'Sidebar - Open & Closed Tickets', searchindex: true, authenticated_as: :authenticate do + let(:customer) { create(:customer, :with_org) } + let(:ticket_open) { create(:ticket, group: Group.find_by(name: 'Users'), customer: customer, title: SecureRandom.uuid) } + let(:ticket_closed) { create(:ticket, group: Group.find_by(name: 'Users'), customer: customer, state: Ticket::State.find_by(name: 'closed'), title: SecureRandom.uuid) } + + def authenticate + ticket_open + ticket_closed + configure_elasticsearch(required: true, rebuild: true) + Scheduler.worker(true) + true + end + + it 'does show open and closed tickets in advanced search url' do + visit "#ticket/zoom/#{ticket_open.id}" + click '.tabsSidebar-tab[data-tab=customer]' + click '.user-tickets[data-type=open]' + expect(page).to have_text(ticket_open.title, wait: 20) + + visit "#ticket/zoom/#{ticket_open.id}" + click '.tabsSidebar-tab[data-tab=customer]' + click '.user-tickets[data-type=closed]' + expect(page).to have_text(ticket_closed.title, wait: 20) + end + end end