From 0e70a0dcf8dacffb46cb1c6ca466c6e0f1b0e265 Mon Sep 17 00:00:00 2001 From: Claudius Nicolae Date: Tue, 5 Mar 2013 16:29:46 +0200 Subject: [PATCH] work in detected timezone --- Gemfile | 10 ++++- Gemfile.lock | 37 +++++++++++++++++++ app/assets/javascripts/application.js.coffee | 3 ++ .../components/config.js.coffee.erb | 4 ++ app/controllers/application_controller.rb | 13 +++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/components/config.js.coffee.erb diff --git a/Gemfile b/Gemfile index 55697f0..83f819d 100644 --- a/Gemfile +++ b/Gemfile @@ -34,7 +34,7 @@ gem 'seedbank', '~> 0.1.3' gem 'rails_admin', '~> 0.4.5' gem 'rails-settings-cached', '~> 0.2.2' gem 'unicorn', '~> 4.5.0' -gem "audited-activerecord", '~> 3.0' +gem 'audited-activerecord', '~> 3.0' # Gems used only for assets and not required # in production environments by default. @@ -44,8 +44,13 @@ group :assets do gem 'bootstrap-sass', '~> 2.2.0' gem 'font-awesome-sass-rails', '~> 3.0.0' gem 'webshims-rails', '~> 0.4.7' + gem 'detect_timezone_rails', '~> 0.0.3' + gem 'jquery-cookie-rails', '~> 1.2.0', + git: 'git://github.com/RyanScottLewis/jquery-cookie-rails.git' gem 'coffee-rails', "~> 3.2.1" gem 'uglifier', '>= 1.0.3' + gem 'oily_png', '1.0.2' + gem 'turbo-sprockets-rails3', '0.3.6' gem 'therubyracer' end @@ -62,6 +67,9 @@ group :development do gem 'capistrano-ext', '~> 1.2.1' gem 'mongrel', '>= 1.2.0.pre2' gem 'quiet_assets', '~> 1.0.1' + gem 'meta_request', '0.2.1' + gem 'parallel_tests', '0.10.0' + gem 'progress_bar', require: false end group :test, :development do diff --git a/Gemfile.lock b/Gemfile.lock index 77be95c..94bf16c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,12 @@ +GIT + remote: git://github.com/RyanScottLewis/jquery-cookie-rails.git + revision: f35da80d8ff720f7164924cc40abd2688f834ca6 + specs: + jquery-cookie-rails (1.2.0) + jquery-rails (~> 2.0) + railties (>= 3.2.0, < 5.0) + thor (~> 0.14) + GIT remote: https://github.com/KimNorgaard/validates_hostname.git revision: 6421e9bd8261a2fe010c627191a0dbe30352469f @@ -101,6 +110,8 @@ GEM daemons (1.0.10) dalli (2.6.2) database_cleaner (0.7.2) + detect_timezone_rails (0.0.3) + railties (~> 3.1) devise (2.1.3) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) @@ -118,6 +129,7 @@ GEM railties (>= 3.0.0) faker (1.0.1) i18n (~> 0.4) + fattr (2.2.1) ffi (1.0.11) file-tail (1.0.12) tins (~> 0.5) @@ -164,6 +176,9 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mail_form (1.3.0) + meta_request (0.2.1) + rack-contrib + rails method_source (0.8.1) mime-types (1.21) mongrel (1.2.0.pre2) @@ -183,10 +198,20 @@ GEM activerecord (>= 3.0.0) activesupport (>= 3.0.0) nokogiri (1.5.6) + oily_png (1.0.2) + chunky_png (~> 1.2.1) + options (2.3.0) + fattr orm_adapter (0.4.0) + parallel (0.6.2) + parallel_tests (0.10.0) + parallel polyamorous (0.5.0) activerecord (~> 3.0) polyglot (0.3.3) + progress_bar (0.4.0) + highline (~> 1.6.1) + options (~> 2.3.0) pry (0.9.12) coderay (~> 1.0.5) method_source (~> 0.8) @@ -196,6 +221,8 @@ GEM rack (1.4.5) rack-cache (1.2) rack (>= 0.4) + rack-contrib (1.1.0) + rack (>= 0.9.1) rack-pjax (0.7.0) nokogiri (~> 1.5) rack (~> 1.3) @@ -317,6 +344,9 @@ GEM treetop (1.4.12) polyglot polyglot (>= 0.3.1) + turbo-sprockets-rails3 (0.3.6) + railties (> 3.2.8, < 4.0.0) + sprockets (>= 2.0.0) turbolinks (1.0.0) coffee-rails tzinfo (0.3.36) @@ -353,19 +383,25 @@ DEPENDENCIES concerned_with (~> 0.1.0) dalli (~> 2.6.2) database_cleaner (~> 0.7.1) + detect_timezone_rails (~> 0.0.3) devise (~> 2.1.0) factory_girl_rails (~> 1.6.0) faker (~> 1.0.1) font-awesome-sass-rails (~> 3.0.0) guard-rspec (~> 0.6.0) guard-spork (~> 0.5.1) + jquery-cookie-rails (~> 1.2.0)! jquery-rails (~> 2.1.3) libnotify (~> 0.7.2) mail_form (~> 1.3.0) + meta_request (= 0.2.1) mongrel (>= 1.2.0.pre2) mysql2 navigasmic (~> 0.5.6)! nilify_blanks (~> 1.0.0) + oily_png (= 1.0.2) + parallel_tests (= 0.10.0) + progress_bar quiet_assets (~> 1.0.1) rails (= 3.2.12) rails-backbone (~> 0.7.0) @@ -384,6 +420,7 @@ DEPENDENCIES squeel (~> 1.0.0) switch_user (~> 0.6.0) therubyracer + turbo-sprockets-rails3 (= 0.3.6) turbolinks (~> 1.0.0) uglifier (>= 1.0.3) unicorn (~> 4.5.0) diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index f89a71c..964cd74 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -11,5 +11,8 @@ #= require slides #= require bootstrap #= require active_scaffold +#= require jquery.cookie +#= require detect_timezone +#= require jquery.detect_timezone #= require_tree ./components #= require_self diff --git a/app/assets/javascripts/components/config.js.coffee.erb b/app/assets/javascripts/components/config.js.coffee.erb new file mode 100644 index 0000000..cec2958 --- /dev/null +++ b/app/assets/javascripts/components/config.js.coffee.erb @@ -0,0 +1,4 @@ +$.cookie('time_zone', + $.fn.get_timezone('default': '<%= Rails.configuration.time_zone %>'), + { path: '/' } +) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9097d47..53fb345 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,7 @@ class ApplicationController < ActionController::Base protect_from_forgery before_filter :check_honeypot + around_filter :set_timezone helper_method :client_remote_ip layout :scoped_layout @@ -11,6 +12,18 @@ class ApplicationController < ActionController::Base protected + def set_timezone + old_time_zone = Time.zone + if user_signed_in? && current_user.timezone.present? + Time.zone = current_user.timezone + elsif cookies[:time_zone].present? + Time.zone = cookies[:time_zone] + end + yield + ensure + Time.zone = old_time_zone + end + def scoped_layout return false if request.xhr? return 'admin' if devise_controller? && resource_name == :admin