Added time selection for ticket conditions.

This commit is contained in:
Martin Edenhofer 2013-03-13 02:19:20 +01:00
parent daa15738f9
commit bd9a3353aa
4 changed files with 222 additions and 18 deletions

View file

@ -419,12 +419,21 @@ class App.ControllerForm extends App.Controller
) )
@delay( a, 180 ) @delay( a, 180 )
# radio # working_hour
else if attribute.tag is 'working_hour' else if attribute.tag is 'working_hour'
if !attribute.value if !attribute.value
attribute.value = {} attribute.value = {}
item = $( App.view('generic/working_hour')( attribute: attribute ) ) 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 # ticket attribute selection
else if attribute.tag is 'ticket_attribute_selection' else if attribute.tag is 'ticket_attribute_selection'
@ -437,6 +446,9 @@ class App.ControllerForm extends App.Controller
addShownAttribute = ( key, value ) => addShownAttribute = ( key, value ) =>
console.log( 'addShownAttribute', key, value ) console.log( 'addShownAttribute', key, value )
parts = key.split(/::/)
key = parts[0]
type = parts[1]
if key is 'tickets.number' if key is 'tickets.number'
attribute_config = { attribute_config = {
name: attribute.name + '::tickets.number' name: attribute.name + '::tickets.number'
@ -561,6 +573,86 @@ class App.ControllerForm extends App.Controller
class: 'medium' class: 'medium'
remove: true 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 else
attribute_config = { attribute_config = {
name: attribute.name + '::' + key name: attribute.name + '::' + key
@ -649,6 +741,54 @@ class App.ControllerForm extends App.Controller
selected: true selected: true
disable: false 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' # value: 'tag'
@ -1057,11 +1197,18 @@ class App.ControllerForm extends App.Controller
inputSelectObject = {} inputSelectObject = {}
for key of param for key of param
parts = key.split '::' parts = key.split '::'
if parts[0] && parts[1] if parts[0] && parts[1] && !parts[2]
if !inputSelectObject[ parts[0] ] if !inputSelectObject[ parts[0] ]
inputSelectObject[ parts[0] ] = {} inputSelectObject[ parts[0] ] = {}
inputSelectObject[ parts[0] ][ parts[1] ] = param[ key ] inputSelectObject[ parts[0] ][ parts[1] ] = param[ key ]
delete 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} # check {input_select}
for key of param for key of param

View file

@ -12,7 +12,7 @@ class App.Sla extends Spine.Model
name: 'data' name: 'data'
display: 'Business Times' display: 'Business Times'
tag: 'working_hour' tag: 'working_hour'
default: { default:
Mon: true Mon: true
Tue: true Tue: true
Wed: true Wed: true
@ -20,16 +20,15 @@ class App.Sla extends Spine.Model
Fri: true Fri: true
beginning_of_workday: '8:00' beginning_of_workday: '8:00'
end_of_workday: '18:00' end_of_workday: '18:00'
}
null: true null: true
nulloption: true nulloption: true
translate: true translate: true
options: options:
customer: 'Customer' customer: 'Customer'
ticket_state: 'State' ticket_state: 'State'
ticket_priority: 'Priority' ticket_priority: 'Priority'
group: 'Group' group: 'Group'
owner: 'Owner' owner: 'Owner'
class: 'span4' class: 'span4'
}, },
{ name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 }, { name: 'updated_at', display: 'Updated', type: 'time', readonly: 1 },

View file

@ -325,7 +325,7 @@ class Ticket < ApplicationModel
overviews.each { |overview| overviews.each { |overview|
# get count # 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 # get meta info
all = { all = {
@ -348,7 +348,7 @@ class Ticket < ApplicationModel
end end
tickets = Ticket.select( 'id' ). tickets = Ticket.select( 'id' ).
where( :group_id => group_ids ). where( :group_id => group_ids ).
where( overview_selected.condition ). where( self._condition( overview_selected.condition ) ).
order( order_by ). order( order_by ).
limit( 500 ) limit( 500 )
@ -358,7 +358,7 @@ class Ticket < ApplicationModel
} }
tickets_count = Ticket.where( :group_id => group_ids ). tickets_count = Ticket.where( :group_id => group_ids ).
where( overview_selected.condition ). where( self._condition( overview_selected.condition ) ).
count() count()
return { return {
@ -371,13 +371,13 @@ class Ticket < ApplicationModel
# get tickets for overview # get tickets for overview
data[:start_page] ||= 1 data[:start_page] ||= 1
tickets = Ticket.where( :group_id => group_ids ). tickets = Ticket.where( :group_id => group_ids ).
where( overview_selected.condition ). where( self._condition( overview_selected.condition ) ).
order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ). order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s )#.
limit( overview_selected.view[ data[:view_mode].to_sym ][:per_page] ). # 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 ) ) # 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 ). tickets_count = Ticket.where( :group_id => group_ids ).
where( overview_selected.condition ). where( self._condition( overview_selected.condition ) ).
count() count()
return { return {
@ -387,6 +387,64 @@ class Ticket < ApplicationModel
} }
end 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 def self.number_adapter

View file

@ -1295,7 +1295,7 @@ Overview.create_if_not_exists(
:prio => 1010, :prio => 1010,
:role_id => overview_role.id, :role_id => overview_role.id,
:condition => { :condition => {
'tickets.ticket_state_id' => [1,2,3], 'tickets.escalation_time' =>{ 'direction' => 'before', 'count'=> 5, 'area' => 'minute' },
}, },
:order => { :order => {
:by => 'escalation_time', :by => 'escalation_time',