Added time selection for ticket conditions.
This commit is contained in:
parent
daa15738f9
commit
bd9a3353aa
4 changed files with 222 additions and 18 deletions
|
@ -419,12 +419,21 @@ class App.ControllerForm extends App.Controller
|
|||
)
|
||||
@delay( a, 180 )
|
||||
|
||||
# radio
|
||||
# working_hour
|
||||
else if attribute.tag is 'working_hour'
|
||||
if !attribute.value
|
||||
attribute.value = {}
|
||||
item = $( App.view('generic/working_hour')( attribute: attribute ) )
|
||||
|
||||
# working_hour
|
||||
else if attribute.tag is 'time_before_last'
|
||||
if !attribute.value
|
||||
attribute.value = {}
|
||||
item = $( App.view('generic/time_before_last')( attribute: attribute ) )
|
||||
item.find( "[name=\"#{attribute.name}::direction\"]").find("option[value=\"#{attribute.value.direction}\"]").attr( 'selected', 'selected' )
|
||||
item.find( "[name=\"#{attribute.name}::count\"]").find("option[value=\"#{attribute.value.count}\"]").attr( 'selected', 'selected' )
|
||||
item.find( "[name=\"#{attribute.name}::area\"]").find("option[value=\"#{attribute.value.area}\"]").attr( 'selected', 'selected' )
|
||||
|
||||
# ticket attribute selection
|
||||
else if attribute.tag is 'ticket_attribute_selection'
|
||||
|
||||
|
@ -437,6 +446,9 @@ class App.ControllerForm extends App.Controller
|
|||
|
||||
addShownAttribute = ( key, value ) =>
|
||||
console.log( 'addShownAttribute', key, value )
|
||||
parts = key.split(/::/)
|
||||
key = parts[0]
|
||||
type = parts[1]
|
||||
if key is 'tickets.number'
|
||||
attribute_config = {
|
||||
name: attribute.name + '::tickets.number'
|
||||
|
@ -561,6 +573,86 @@ class App.ControllerForm extends App.Controller
|
|||
class: 'medium'
|
||||
remove: true
|
||||
}
|
||||
else if key is 'tickets.created_at' && ( type is '<>' || value.count )
|
||||
attribute_config = {
|
||||
name: attribute.name + '::tickets.created_at'
|
||||
display: 'Created (before / last)'
|
||||
tag: 'time_before_last'
|
||||
value: value
|
||||
translate: true
|
||||
class: 'medium'
|
||||
remove: true
|
||||
}
|
||||
else if key is 'tickets.created_at' && ( type is '><' || 0 )
|
||||
attribute_config = {
|
||||
name: attribute.name + '::tickets.created_at'
|
||||
display: 'Created (between)'
|
||||
tag: 'time_range'
|
||||
value: value
|
||||
translate: true
|
||||
class: 'medium'
|
||||
remove: true
|
||||
}
|
||||
else if key is 'tickets.close_time' && ( type is '<>' || value.count )
|
||||
attribute_config = {
|
||||
name: attribute.name + '::tickets.close_time'
|
||||
display: 'Closed (before / last)'
|
||||
tag: 'time_before_last'
|
||||
value: value
|
||||
translate: true
|
||||
class: 'medium'
|
||||
remove: true
|
||||
}
|
||||
else if key is 'tickets.close_time' && ( type is '><' || 0 )
|
||||
attribute_config = {
|
||||
name: attribute.name + '::tickets.close_time'
|
||||
display: 'Closed (between)'
|
||||
tag: 'time_range'
|
||||
value: value
|
||||
translate: true
|
||||
class: 'medium'
|
||||
remove: true
|
||||
}
|
||||
else if key is 'tickets.updated_at' && ( type is '<>' || value.count )
|
||||
attribute_config = {
|
||||
name: attribute.name + '::tickets.updated_at'
|
||||
display: 'Updated (before / last)'
|
||||
tag: 'time_before_last'
|
||||
value: value
|
||||
translate: true
|
||||
class: 'medium'
|
||||
remove: true
|
||||
}
|
||||
else if key is 'tickets.updated_at' && ( type is '><' || 0 )
|
||||
attribute_config = {
|
||||
name: attribute.name + '::tickets.updated_at'
|
||||
display: 'Updated (between)'
|
||||
tag: 'time_range'
|
||||
value: value
|
||||
translate: true
|
||||
class: 'medium'
|
||||
remove: true
|
||||
}
|
||||
else if key is 'tickets.escalation_time' && ( type is '<>' || value.count )
|
||||
attribute_config = {
|
||||
name: attribute.name + '::tickets.escalation_time'
|
||||
display: 'Escalation (before / last)'
|
||||
tag: 'time_before_last'
|
||||
value: value
|
||||
translate: true
|
||||
class: 'medium'
|
||||
remove: true
|
||||
}
|
||||
else if key is 'tickets.escalation_time' && ( type is '><' || 0 )
|
||||
attribute_config = {
|
||||
name: attribute.name + '::tickets.escalation_time'
|
||||
display: 'Escatlation (between)'
|
||||
tag: 'time_range'
|
||||
value: value
|
||||
translate: true
|
||||
class: 'medium'
|
||||
remove: true
|
||||
}
|
||||
else
|
||||
attribute_config = {
|
||||
name: attribute.name + '::' + key
|
||||
|
@ -649,6 +741,54 @@ class App.ControllerForm extends App.Controller
|
|||
selected: true
|
||||
disable: false
|
||||
},
|
||||
{
|
||||
value: 'tickets.created_at::<>'
|
||||
name: 'Created (before/last)'
|
||||
selected: true
|
||||
disable: false
|
||||
},
|
||||
{
|
||||
value: 'tickets.created_at::><'
|
||||
name: 'Created (between)'
|
||||
selected: true
|
||||
disable: false
|
||||
},
|
||||
{
|
||||
value: 'tickets.close_time::<>'
|
||||
name: 'Closed (before/last)'
|
||||
selected: true
|
||||
disable: false
|
||||
},
|
||||
{
|
||||
value: 'tickets.close_time::><'
|
||||
name: 'Closed (between)'
|
||||
selected: true
|
||||
disable: false
|
||||
},
|
||||
{
|
||||
value: 'tickets.updated_at::<>'
|
||||
name: 'Updated (before/last)'
|
||||
selected: true
|
||||
disable: false
|
||||
},
|
||||
{
|
||||
value: 'tickets.updated_at::><'
|
||||
name: 'Updated (between)'
|
||||
selected: true
|
||||
disable: false
|
||||
},
|
||||
{
|
||||
value: 'tickets.escalation_time::<>'
|
||||
name: 'Escalation (before/last)'
|
||||
selected: true
|
||||
disable: false
|
||||
},
|
||||
{
|
||||
value: 'tickets.escalation_time::><'
|
||||
name: 'Escalation (between)'
|
||||
selected: true
|
||||
disable: false
|
||||
},
|
||||
|
||||
# {
|
||||
# value: 'tag'
|
||||
|
@ -1057,11 +1197,18 @@ class App.ControllerForm extends App.Controller
|
|||
inputSelectObject = {}
|
||||
for key of param
|
||||
parts = key.split '::'
|
||||
if parts[0] && parts[1]
|
||||
if parts[0] && parts[1] && !parts[2]
|
||||
if !inputSelectObject[ parts[0] ]
|
||||
inputSelectObject[ parts[0] ] = {}
|
||||
inputSelectObject[ parts[0] ][ parts[1] ] = param[ key ]
|
||||
delete param[ key ]
|
||||
if parts[0] && parts[1] && parts[2]
|
||||
if !inputSelectObject[ parts[0] ]
|
||||
inputSelectObject[ parts[0] ] = {}
|
||||
if !inputSelectObject[ parts[0] ][ parts[1] ]
|
||||
inputSelectObject[ parts[0] ][ parts[1] ] = {}
|
||||
inputSelectObject[ parts[0] ][ parts[1] ][ parts[2] ] = param[ key ]
|
||||
delete param[ key ]
|
||||
|
||||
# check {input_select}
|
||||
for key of param
|
||||
|
|
|
@ -12,7 +12,7 @@ class App.Sla extends Spine.Model
|
|||
name: 'data'
|
||||
display: 'Business Times'
|
||||
tag: 'working_hour'
|
||||
default: {
|
||||
default:
|
||||
Mon: true
|
||||
Tue: true
|
||||
Wed: true
|
||||
|
@ -20,16 +20,15 @@ class App.Sla extends Spine.Model
|
|||
Fri: true
|
||||
beginning_of_workday: '8:00'
|
||||
end_of_workday: '18:00'
|
||||
}
|
||||
null: true
|
||||
nulloption: true
|
||||
translate: true
|
||||
options:
|
||||
customer: 'Customer'
|
||||
ticket_state: 'State'
|
||||
ticket_priority: 'Priority'
|
||||
group: 'Group'
|
||||
owner: 'Owner'
|
||||
customer: 'Customer'
|
||||
ticket_state: 'State'
|
||||
ticket_priority: 'Priority'
|
||||
group: 'Group'
|
||||
owner: 'Owner'
|
||||
class: 'span4'
|
||||
},
|
||||
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },
|
||||
|
|
|
@ -325,7 +325,7 @@ class Ticket < ApplicationModel
|
|||
overviews.each { |overview|
|
||||
|
||||
# get count
|
||||
count = Ticket.where( :group_id => group_ids ).where( overview.condition ).count()
|
||||
count = Ticket.where( :group_id => group_ids ).where( self._condition( overview.condition ) ).count()
|
||||
|
||||
# get meta info
|
||||
all = {
|
||||
|
@ -348,7 +348,7 @@ class Ticket < ApplicationModel
|
|||
end
|
||||
tickets = Ticket.select( 'id' ).
|
||||
where( :group_id => group_ids ).
|
||||
where( overview_selected.condition ).
|
||||
where( self._condition( overview_selected.condition ) ).
|
||||
order( order_by ).
|
||||
limit( 500 )
|
||||
|
||||
|
@ -358,7 +358,7 @@ class Ticket < ApplicationModel
|
|||
}
|
||||
|
||||
tickets_count = Ticket.where( :group_id => group_ids ).
|
||||
where( overview_selected.condition ).
|
||||
where( self._condition( overview_selected.condition ) ).
|
||||
count()
|
||||
|
||||
return {
|
||||
|
@ -371,13 +371,13 @@ class Ticket < ApplicationModel
|
|||
# get tickets for overview
|
||||
data[:start_page] ||= 1
|
||||
tickets = Ticket.where( :group_id => group_ids ).
|
||||
where( overview_selected.condition ).
|
||||
order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ).
|
||||
limit( overview_selected.view[ data[:view_mode].to_sym ][:per_page] ).
|
||||
offset( overview_selected.view[ data[:view_mode].to_sym ][:per_page].to_i * ( data[:start_page].to_i - 1 ) )
|
||||
where( self._condition( overview_selected.condition ) ).
|
||||
order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s )#.
|
||||
# limit( overview_selected.view[ data[:view_mode].to_sym ][:per_page] ).
|
||||
# offset( overview_selected.view[ data[:view_mode].to_sym ][:per_page].to_i * ( data[:start_page].to_i - 1 ) )
|
||||
|
||||
tickets_count = Ticket.where( :group_id => group_ids ).
|
||||
where( overview_selected.condition ).
|
||||
where( self._condition( overview_selected.condition ) ).
|
||||
count()
|
||||
|
||||
return {
|
||||
|
@ -387,6 +387,64 @@ class Ticket < ApplicationModel
|
|||
}
|
||||
|
||||
end
|
||||
def self._condition(condition)
|
||||
sql = ''
|
||||
bind = [nil]
|
||||
condition.each {|key, value|
|
||||
if sql != ''
|
||||
sql += ' AND '
|
||||
end
|
||||
if value.class == Array
|
||||
sql += " #{key} IN (?)"
|
||||
bind.push value
|
||||
elsif value.class == Hash || value.class == ActiveSupport::HashWithIndifferentAccess
|
||||
time = Time.now
|
||||
if value['area'] == 'minute'
|
||||
if value['direction'] == 'last'
|
||||
time -= value['count'].to_i * 60
|
||||
else
|
||||
time += value['count'].to_i * 60
|
||||
end
|
||||
elsif value['area'] == 'hour'
|
||||
if value['direction'] == 'last'
|
||||
time -= value['count'].to_i * 60 * 60
|
||||
else
|
||||
time += value['count'].to_i * 60 * 60
|
||||
end
|
||||
elsif value['area'] == 'day'
|
||||
if value['direction'] == 'last'
|
||||
time -= value['count'].to_i * 60 * 60 * 24
|
||||
else
|
||||
time += value['count'].to_i * 60 * 60 * 24
|
||||
end
|
||||
elsif value['area'] == 'month'
|
||||
if value['direction'] == 'last'
|
||||
time -= value['count'].to_i * 60 * 60 * 24 * 31
|
||||
else
|
||||
time += value['count'].to_i * 60 * 60 * 24 * 31
|
||||
end
|
||||
elsif value['area'] == 'year'
|
||||
if value['direction'] == 'last'
|
||||
time -= value['count'].to_i * 60 * 60 * 24 * 365
|
||||
else
|
||||
time += value['count'].to_i * 60 * 60 * 24 * 365
|
||||
end
|
||||
end
|
||||
if value['direction'] == 'last'
|
||||
sql += " #{key} > ?"
|
||||
bind.push time
|
||||
else
|
||||
sql += " #{key} < ?"
|
||||
bind.push time
|
||||
end
|
||||
else
|
||||
sql += " #{key} = ?"
|
||||
bind.push value
|
||||
end
|
||||
}
|
||||
bind[0] = sql
|
||||
return bind
|
||||
end
|
||||
|
||||
def self.number_adapter
|
||||
|
||||
|
|
|
@ -1295,7 +1295,7 @@ Overview.create_if_not_exists(
|
|||
:prio => 1010,
|
||||
:role_id => overview_role.id,
|
||||
:condition => {
|
||||
'tickets.ticket_state_id' => [1,2,3],
|
||||
'tickets.escalation_time' =>{ 'direction' => 'before', 'count'=> 5, 'area' => 'minute' },
|
||||
},
|
||||
:order => {
|
||||
:by => 'escalation_time',
|
||||
|
|
Loading…
Reference in a new issue