From 7b15323315e0b7cf9a99473b451fb03895b8c8e0 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 6 Jun 2013 09:34:09 +0200 Subject: [PATCH] Added time zone support for slas. --- .../_application_controller_form.js.coffee | 35 +++++++++++++++---- .../javascripts/app/models/sla.js.coffee | 5 +-- app/controllers/application_controller.rb | 18 +++++++++- db/migrate/20130606070432_sla_timezone.rb | 9 +++++ 4 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20130606070432_sla_timezone.rb diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee index 0ea55400f..8e1042fdf 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee @@ -157,7 +157,7 @@ class App.ControllerForm extends App.Controller # set value if @params - + # check if we have a references parts = attribute.name.split '::' if parts[0] && parts[1] @@ -201,8 +201,8 @@ class App.ControllerForm extends App.Controller # build options list if _.isEmpty(attribute.options) attribute.options = [ - { name: 'active', value: true } - { name: 'inactive', value: false } + { name: 'active', value: true } + { name: 'inactive', value: false } ] # update boolean types @@ -221,6 +221,27 @@ class App.ControllerForm extends App.Controller else if attribute.tag is 'select' item = $( App.view('generic/select')( attribute: attribute ) ) + # timezone + else if attribute.tag is 'timezone' + attribute.options = [] + timezones = App.Config.get('timezones') + + # build list based on config + for timezone_value, timezone_diff of timezones + if timezone_diff > 0 + timezone_diff = '+' + timezone_diff + item = + name: "#{timezone_value} (GMT#{timezone_diff})" + value: timezone_value + attribute.options.push item + + # finde selected item of list + for record in attribute.options + if record.value is attribute.value + record.selected = 'selected' + + item = $( App.view('generic/select')( attribute: attribute ) ) + # select else if attribute.tag is 'input_select' item = $('
') @@ -374,7 +395,7 @@ class App.ControllerForm extends App.Controller onRemoveTag: onRemoveTag ) siteUpdate(true) - + # update box size App.Event.bind 'ui:rerender:content', => siteUpdate(true) @@ -493,7 +514,7 @@ class App.ControllerForm extends App.Controller name = 'owner_id' if key is 'customer_id' display = 'Customer' - name = 'customer_id' + name = 'customer_id' attribute_config = { name: attribute.name + '::tickets.' + name display: display @@ -674,7 +695,7 @@ class App.ControllerForm extends App.Controller ) # itemSub.append('') item.find('.ticket_attribute_item').append( itemSub ) - + # list of shown attributes show = [] @@ -793,7 +814,7 @@ class App.ControllerForm extends App.Controller selected: true disable: false }, - + # { # value: 'tag' # name: 'Tag' diff --git a/app/assets/javascripts/app/models/sla.js.coffee b/app/assets/javascripts/app/models/sla.js.coffee index 7f50cf6fb..e89e0b9cf 100644 --- a/app/assets/javascripts/app/models/sla.js.coffee +++ b/app/assets/javascripts/app/models/sla.js.coffee @@ -1,5 +1,5 @@ class App.Sla extends App.Model - @configure 'Sla', 'name', 'first_response_time', 'update_time', 'close_time', 'condition', 'data', 'active' + @configure 'Sla', 'name', 'first_response_time', 'update_time', 'close_time', 'condition', 'timezone', 'data', 'active' @extend Spine.Model.Ajax @url: 'api/slas' @configure_attributes = [ @@ -8,7 +8,8 @@ class App.Sla extends App.Model { name: 'update_time', display: 'Update Time', tag: 'input', type: 'text', limit: 100, null: true, 'class': 'span4', note: 'In minutes, only business times are counted.' }, { name: 'close_time', display: 'Solution Time', tag: 'input', type: 'text', limit: 100, null: true, 'class': 'span4', note: 'In minutes, only business times are counted.' }, { name: 'condition', display: 'Conditions where SLA is used', tag: 'ticket_attribute_selection', null: true, class: 'span4' }, - { + { name: 'timezone', display: 'Timezone', tag: 'timezone', null: true, class: 'span4' }, + { name: 'data' display: 'Business Times' tag: 'working_hour' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b4d5fe246..7ba669f47 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -196,12 +196,28 @@ class ApplicationController < ActionController::Base end def config_frontend - + # config config = {} Setting.select('name').where( :frontend => true ).each { |setting| config[setting.name] = Setting.get(setting.name) } + + # get all time zones + config['timezones'] = {} + TZInfo::Timezone.all.each { |t| + + # ignore the following time zones + next if t.name =~ /^GMT/ + next if t.name =~ /^Etc/ + next if t.name =~ /^MET/ + next if t.name =~ /^MST/ + next if t.name =~ /^ROC/ + next if t.name =~ /^ROK/ + diff = t.current_period.utc_total_offset / 60 /60 + config['timezones'][ t.name ] = diff + } + return config end diff --git a/db/migrate/20130606070432_sla_timezone.rb b/db/migrate/20130606070432_sla_timezone.rb new file mode 100644 index 000000000..495e63175 --- /dev/null +++ b/db/migrate/20130606070432_sla_timezone.rb @@ -0,0 +1,9 @@ +class SlaTimezone < ActiveRecord::Migration + def up + add_column :slas, :timezone, :string, :limit => 50, :null => true + end + + def down + remove_column :slas, :timezone + end +end