Added counter support for sidebar tab (per default show open tickets of customer).

This commit is contained in:
Martin Edenhofer 2018-01-28 19:10:22 +01:00
parent cc1d38f506
commit a324553072
7 changed files with 127 additions and 15 deletions

View file

@ -2,10 +2,16 @@ class SidebarCustomer extends App.Controller
sidebarItem: => sidebarItem: =>
return if !@permissionCheck('ticket.agent') return if !@permissionCheck('ticket.agent')
return if _.isEmpty(@params.customer_id) return if _.isEmpty(@params.customer_id)
counter = ''
if App.User.exists(@params.customer_id)
user = App.User.find(@params.customer_id)
counter = @sidebarItemCounter(user)
{ {
head: 'Customer' head: 'Customer'
name: 'customer' name: 'customer'
icon: 'person' icon: 'person'
counter: counter
counterPossible: true
actions: [ actions: [
{ {
title: 'Edit Customer' title: 'Edit Customer'
@ -16,12 +22,28 @@ class SidebarCustomer extends App.Controller
callback: @showCustomer callback: @showCustomer
} }
sidebarItemCounter: (user) ->
counter = ''
if user && user.preferences && user.preferences.tickets_open
counter = user.preferences.tickets_open
counter
sidebarItemUpdate: (user) =>
counter = @sidebarItemCounter(user)
element = @el.closest('.tabsSidebar-holder').find('.tabsSidebar .tabsSidebar-tabs .tabsSidebar-tab[data-tab=customer] .js-tabCounter')
if !counter || counter is 0
element.addClass('hide')
else
element.removeClass('hide')
element.text(counter)
showCustomer: (el) => showCustomer: (el) =>
@el = el @el = el
return if _.isEmpty(@params.customer_id) return if _.isEmpty(@params.customer_id)
new App.WidgetUser( new App.WidgetUser(
el: @el el: @el
user_id: @params.customer_id user_id: @params.customer_id
callback: @sidebarItemUpdate
) )
editCustomer: => editCustomer: =>

View file

@ -1,10 +1,16 @@
class SidebarCustomer extends App.Controller class SidebarCustomer extends App.Controller
sidebarItem: => sidebarItem: =>
return if !@permissionCheck('ticket.agent') return if !@permissionCheck('ticket.agent')
counter = ''
if App.User.exists(@ticket.customer_id)
user = App.User.find(@ticket.customer_id)
counter = @sidebarItemCounter(user)
items = { items = {
head: 'Customer' head: 'Customer'
name: 'customer' name: 'customer'
icon: 'person' icon: 'person'
counter: counter
counterPossible: true
actions: [ actions: [
{ {
title: 'Change Customer' title: 'Change Customer'
@ -22,11 +28,27 @@ class SidebarCustomer extends App.Controller
} }
items items
sidebarItemCounter: (user) ->
counter = ''
if user && user.preferences && user.preferences.tickets_open
counter = user.preferences.tickets_open
counter
sidebarItemUpdate: (user) =>
counter = @sidebarItemCounter(user)
element = @el.closest('.tabsSidebar-holder').find('.tabsSidebar .tabsSidebar-tabs .tabsSidebar-tab[data-tab=customer] .js-tabCounter')
if !counter || counter is 0
element.addClass('hide')
else
element.removeClass('hide')
element.text(counter)
showCustomer: (el) => showCustomer: (el) =>
@el = el @el = el
new App.WidgetUser( new App.WidgetUser(
el: @el el: @el
user_id: @ticket.customer_id user_id: @ticket.customer_id
callback: @sidebarItemUpdate
) )
editCustomer: => editCustomer: =>

View file

@ -251,7 +251,7 @@ class App.Ticket extends App.Model
group_ids = App.Session.get('group_ids') group_ids = App.Session.get('group_ids')
if _.isEmpty(group_ids[@group_id]) if _.isEmpty(group_ids[@group_id])
return false return false
else if group_ids[@group_id] && !_.include(group_ids[@group_id], 'edit') && !_.include(group_ids[@group_id], 'full') else if group_ids[@group_id] && !_.include(group_ids[@group_id], 'change') && !_.include(group_ids[@group_id], 'full')
return false return false
true true

View file

@ -14,6 +14,9 @@
<div class="tabsSidebar-tabs" style="<%- if @dir is 'rtl' then 'margin-right' else 'margin-left' %>: -<%- @scrollbarWidth %>px"> <div class="tabsSidebar-tabs" style="<%- if @dir is 'rtl' then 'margin-right' else 'margin-left' %>: -<%- @scrollbarWidth %>px">
<% for item in @items: %> <% for item in @items: %>
<div class="tabsSidebar-tab" data-tab="<%= item.name %>"> <div class="tabsSidebar-tab" data-tab="<%= item.name %>">
<% if item.counterPossible is true: %>
<div class="tabsSidebar-tab-count js-tabCounter <% if !item.counter || item.counter is 0: %>hide<% end %>"><%= item.counter %></div>
<% end %>
<%- @Icon(item.icon) %> <%- @Icon(item.icon) %>
</div> </div>
<% end %> <% end %>

View file

@ -5556,9 +5556,54 @@ footer {
fill: hsl(197,19%,78%); fill: hsl(197,19%,78%);
} }
.tabsSidebar-tab.active .icon { .tabsSidebar-tab.active {
.tabsSidebar-tab-count {
background: hsl(206,7%,37%);
&:after {
border-right-color: hsl(206,7%,37%);
}
}
.icon {
fill: hsl(206,7%,37%); fill: hsl(206,7%,37%);
} }
}
.tabsSidebar-tab-count {
position: absolute;
left: 9px;
top: 5px;
background: hsl(197,19%,78%);
width: 16px;
height: 13px;
text-align: center;
border-radius: 2px;
font-size: 9px;
line-height: 14px;
color: hsl(197,20%,93%);
[data-tab="organization"] & {
left: 7px;
+ .icon {
margin-left: 3px;
}
}
+ .icon {
margin-top: 6px;
}
&:after {
content: "";
position: absolute;
top: 100%;
right: 20%;
border-bottom: 3px solid transparent;
border-right: 5px solid hsl(197,19%,78%);
}
}
.sidebar .text-muted { .sidebar .text-muted {
color: hsl(198,22%,82%); color: hsl(198,22%,82%);

View file

@ -86,7 +86,7 @@ returns
types.push 'email' types.push 'email'
end end
types.each do |type_name| types.each do |type_name|
type = Ticket::Article::Type.lookup( name: type_name ) type = Ticket::Article::Type.lookup(name: type_name)
next if type.blank? next if type.blank?
type_ids.push type.id type_ids.push type.id
end end
@ -99,7 +99,7 @@ returns
filter[:group_id] = [] filter[:group_id] = []
groups = if params[:current_user].permissions?('ticket.agent') groups = if params[:current_user].permissions?('ticket.agent')
if params[:ticket].present? if params[:ticket].present?
params[:current_user].groups_access(%w[edit]) params[:current_user].groups_access(%w[change])
else else
params[:current_user].groups_access(%w[create]) params[:current_user].groups_access(%w[create])
end end

View file

@ -313,10 +313,10 @@ class TicketScreenOptionsTest < ActiveSupport::TestCase
Ticket::Article::Type.lookup(name: 'note').id, Ticket::Article::Type.lookup(name: 'note').id,
], result[:form_meta][:filter][:type_id].sort) ], result[:form_meta][:filter][:type_id].sort)
assert(result[:form_meta][:filter][:group_id]) assert(result[:form_meta][:filter][:group_id])
assert_equal([group1.id, group3.id], result[:form_meta][:filter][:group_id].sort) assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
assert(result[:form_meta][:dependencies]) assert(result[:form_meta][:dependencies])
assert(result[:form_meta][:dependencies][:group_id]) assert(result[:form_meta][:dependencies][:group_id])
assert_equal(3, result[:form_meta][:dependencies][:group_id].count) assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
assert(result[:form_meta][:dependencies][:group_id]['']) assert(result[:form_meta][:dependencies][:group_id][''])
assert(result[:form_meta][:dependencies][:group_id][''][:owner_id]) assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id]) assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
@ -327,6 +327,10 @@ class TicketScreenOptionsTest < ActiveSupport::TestCase
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
assert(result[:form_meta][:dependencies][:group_id][group2.id])
assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
assert(result[:form_meta][:dependencies][:group_id][group3.id]) assert(result[:form_meta][:dependencies][:group_id][group3.id])
assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id]) assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count) assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
@ -360,10 +364,10 @@ class TicketScreenOptionsTest < ActiveSupport::TestCase
Ticket::Article::Type.lookup(name: 'note').id, Ticket::Article::Type.lookup(name: 'note').id,
], result[:form_meta][:filter][:type_id].sort) ], result[:form_meta][:filter][:type_id].sort)
assert(result[:form_meta][:filter][:group_id]) assert(result[:form_meta][:filter][:group_id])
assert_equal([group1.id, group3.id], result[:form_meta][:filter][:group_id].sort) assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
assert(result[:form_meta][:dependencies]) assert(result[:form_meta][:dependencies])
assert(result[:form_meta][:dependencies][:group_id]) assert(result[:form_meta][:dependencies][:group_id])
assert_equal(3, result[:form_meta][:dependencies][:group_id].count) assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
assert(result[:form_meta][:dependencies][:group_id]['']) assert(result[:form_meta][:dependencies][:group_id][''])
assert(result[:form_meta][:dependencies][:group_id][''][:owner_id]) assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id]) assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
@ -374,6 +378,10 @@ class TicketScreenOptionsTest < ActiveSupport::TestCase
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
assert(result[:form_meta][:dependencies][:group_id][group2.id])
assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
assert(result[:form_meta][:dependencies][:group_id][group3.id]) assert(result[:form_meta][:dependencies][:group_id][group3.id])
assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id]) assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count) assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
@ -407,10 +415,10 @@ class TicketScreenOptionsTest < ActiveSupport::TestCase
Ticket::Article::Type.lookup(name: 'note').id, Ticket::Article::Type.lookup(name: 'note').id,
], result[:form_meta][:filter][:type_id].sort) ], result[:form_meta][:filter][:type_id].sort)
assert(result[:form_meta][:filter][:group_id]) assert(result[:form_meta][:filter][:group_id])
assert_equal([group1.id, group3.id], result[:form_meta][:filter][:group_id].sort) assert_equal([group1.id, group2.id, group3.id], result[:form_meta][:filter][:group_id].sort)
assert(result[:form_meta][:dependencies]) assert(result[:form_meta][:dependencies])
assert(result[:form_meta][:dependencies][:group_id]) assert(result[:form_meta][:dependencies][:group_id])
assert_equal(3, result[:form_meta][:dependencies][:group_id].count) assert_equal(4, result[:form_meta][:dependencies][:group_id].count)
assert(result[:form_meta][:dependencies][:group_id]['']) assert(result[:form_meta][:dependencies][:group_id][''])
assert(result[:form_meta][:dependencies][:group_id][''][:owner_id]) assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id]) assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
@ -421,6 +429,10 @@ class TicketScreenOptionsTest < ActiveSupport::TestCase
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
assert(result[:form_meta][:dependencies][:group_id][group2.id])
assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
assert(result[:form_meta][:dependencies][:group_id][group3.id]) assert(result[:form_meta][:dependencies][:group_id][group3.id])
assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id]) assert(result[:form_meta][:dependencies][:group_id][group3.id][:owner_id])
assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count) assert_equal(2, result[:form_meta][:dependencies][:group_id][group3.id][:owner_id].count)
@ -455,10 +467,10 @@ class TicketScreenOptionsTest < ActiveSupport::TestCase
Ticket::Article::Type.lookup(name: 'note').id, Ticket::Article::Type.lookup(name: 'note').id,
], result[:form_meta][:filter][:type_id].sort) ], result[:form_meta][:filter][:type_id].sort)
assert(result[:form_meta][:filter][:group_id]) assert(result[:form_meta][:filter][:group_id])
assert_equal([group1.id], result[:form_meta][:filter][:group_id].sort) assert_equal([group1.id, group2.id], result[:form_meta][:filter][:group_id].sort)
assert(result[:form_meta][:dependencies]) assert(result[:form_meta][:dependencies])
assert(result[:form_meta][:dependencies][:group_id]) assert(result[:form_meta][:dependencies][:group_id])
assert_equal(2, result[:form_meta][:dependencies][:group_id].count) assert_equal(3, result[:form_meta][:dependencies][:group_id].count)
assert(result[:form_meta][:dependencies][:group_id]['']) assert(result[:form_meta][:dependencies][:group_id][''])
assert(result[:form_meta][:dependencies][:group_id][''][:owner_id]) assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id]) assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
@ -469,6 +481,10 @@ class TicketScreenOptionsTest < ActiveSupport::TestCase
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
assert(result[:form_meta][:dependencies][:group_id][group2.id])
assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
result = Ticket::ScreenOptions.attributes_to_change( result = Ticket::ScreenOptions.attributes_to_change(
ticket_id: ticket2.id, ticket_id: ticket2.id,
@ -497,10 +513,10 @@ class TicketScreenOptionsTest < ActiveSupport::TestCase
Ticket::Article::Type.lookup(name: 'note').id, Ticket::Article::Type.lookup(name: 'note').id,
], result[:form_meta][:filter][:type_id].sort) ], result[:form_meta][:filter][:type_id].sort)
assert(result[:form_meta][:filter][:group_id]) assert(result[:form_meta][:filter][:group_id])
assert_equal([group1.id], result[:form_meta][:filter][:group_id].sort) assert_equal([group1.id, group2.id], result[:form_meta][:filter][:group_id].sort)
assert(result[:form_meta][:dependencies]) assert(result[:form_meta][:dependencies])
assert(result[:form_meta][:dependencies][:group_id]) assert(result[:form_meta][:dependencies][:group_id])
assert_equal(2, result[:form_meta][:dependencies][:group_id].count) assert_equal(3, result[:form_meta][:dependencies][:group_id].count)
assert(result[:form_meta][:dependencies][:group_id]['']) assert(result[:form_meta][:dependencies][:group_id][''])
assert(result[:form_meta][:dependencies][:group_id][''][:owner_id]) assert(result[:form_meta][:dependencies][:group_id][''][:owner_id])
assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id]) assert_equal([], result[:form_meta][:dependencies][:group_id][''][:owner_id])
@ -511,6 +527,10 @@ class TicketScreenOptionsTest < ActiveSupport::TestCase
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent2.id))
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent3.id))
assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id)) assert(result[:form_meta][:dependencies][:group_id][group1.id][:owner_id].include?(agent4.id))
assert(result[:form_meta][:dependencies][:group_id][group2.id])
assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id])
assert_equal(1, result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].count)
assert(result[:form_meta][:dependencies][:group_id][group2.id][:owner_id].include?(agent3.id))
result = Ticket::ScreenOptions.attributes_to_change( result = Ticket::ScreenOptions.attributes_to_change(
ticket_id: ticket1.id, ticket_id: ticket1.id,