diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb
index fa7693db..946dc831 100644
--- a/tracks/app/controllers/application.rb
+++ b/tracks/app/controllers/application.rb
@@ -62,18 +62,17 @@ class ApplicationController < ActionController::Base
wants.xml { render :text => 'An error occurred on the server.' + $! }
end
end
-
+
private
def get_current_user
@user = User.find(session['user_id']) if session['user_id']
- @prefs = @user.preference unless @user.nil?
+ @prefs = @user.prefs unless @user.nil?
end
def parse_date_per_user_prefs( s )
return nil if s.blank?
- Date.strptime(s, @user.preference.date_format)
- #Chronic.parse(s).to_date
+ @user.prefs.tz.unadjust(Date.strptime(s, @user.prefs.date_format)).utc.to_date
end
def init_data_for_sidebar
diff --git a/tracks/app/controllers/feed_controller.rb b/tracks/app/controllers/feed_controller.rb
index 9ca503d3..ed3e197d 100644
--- a/tracks/app/controllers/feed_controller.rb
+++ b/tracks/app/controllers/feed_controller.rb
@@ -90,8 +90,8 @@ protected
if params.key?('due')
due_within = params['due'].to_i
- condition_builder.add('todos.due <= ?', due_within.days.from_now)
- due_within_date_s = due_within.days.from_now.strftime("%Y-%m-%d")
+ condition_builder.add('todos.due <= ?', due_within.days.from_now.utc)
+ due_within_date_s = @user.prefs.tz.adjust(due_within.days.from_now.utc).strftime("%Y-%m-%d")
@title << " due today" if (due_within == 0)
@title << " due within a week" if (due_within == 6)
@description << " with a due date #{due_within_date_s} or earlier"
@@ -99,7 +99,7 @@ protected
if params.key?('done')
done_in_last = params['done'].to_i
- condition_builder.add('todos.completed_at >= ?', done_in_last.days.ago)
+ condition_builder.add('todos.completed_at >= ?', done_in_last.days.ago.utc)
@title << " actions completed"
@description << " in the last #{done_in_last.to_s} days"
end
diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb
index d1c0dcf8..af6eecd1 100644
--- a/tracks/app/controllers/todo_controller.rb
+++ b/tracks/app/controllers/todo_controller.rb
@@ -16,7 +16,7 @@ class TodoController < ApplicationController
# If you've set no_completed to zero, the completed items box
# isn't shown on the home page
- max_completed = @user.preference.show_number_completed
+ max_completed = @user.prefs.show_number_completed
@done = @user.completed_todos.find(:all, :limit => max_completed) unless max_completed == 0
@contexts_to_show = @contexts.reject {|x| x.hide? }
@@ -60,7 +60,7 @@ class TodoController < ApplicationController
if @item.due?
@date = parse_date_per_user_prefs(p['todo']['due'])
- @item.due = @date.to_s(:db)
+ @item.due = @date
else
@item.due = ""
end
@@ -206,15 +206,15 @@ class TodoController < ApplicationController
def completed
@page_title = "TRACKS::Completed tasks"
@done = @user.completed_todos
- @done_today = @done.completed_within 1.day.ago
- @done_this_week = @done.completed_within 1.week.ago
- @done_this_month = @done.completed_within 4.week.ago
+ @done_today = @done.completed_within 1.day.ago.utc
+ @done_this_week = @done.completed_within 1.week.ago.utc
+ @done_this_month = @done.completed_within 4.week.ago.utc
end
def completed_archive
@page_title = "TRACKS::Archived completed tasks"
@done = @user.completed_todos
- @done_archive = @done.completed_more_than 28.day.ago
+ @done_archive = @done.completed_more_than 28.day.ago.utc
end
def tickler
diff --git a/tracks/app/controllers/user_controller.rb b/tracks/app/controllers/user_controller.rb
index dc9bd57e..0a034297 100644
--- a/tracks/app/controllers/user_controller.rb
+++ b/tracks/app/controllers/user_controller.rb
@@ -39,28 +39,6 @@ class UserController < ApplicationController
end
end
- def preferences
- @page_title = "TRACKS::Preferences"
- @prefs = @user.preference
- end
-
- def edit_preferences
- @page_title = "TRACKS::Edit Preferences"
- @prefs = @user.preference
-
- render :action => "preference_edit_form", :object => @prefs
- end
-
- def update_preferences
- user_success = @user.update_attributes(params['user'])
- prefs_success = @user.preference.update_attributes(params['prefs'])
- if user_success && prefs_success
- redirect_to :action => 'preferences'
- else
- render :action => 'edit_preferences'
- end
- end
-
def change_password
@page_title = "TRACKS::Change password"
end
diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb
index 400f1a4a..6d7fbda8 100644
--- a/tracks/app/helpers/application_helper.rb
+++ b/tracks/app/helpers/application_helper.rb
@@ -6,12 +6,17 @@ module ApplicationHelper
#
def format_date(date)
if date
- date_format = @user.preference.date_format
- formatted_date = date.strftime("#{date_format}")
+ date_format = @user.prefs.date_format
+ formatted_date = @user.prefs.tz.adjust(date).strftime("#{date_format}")
else
formatted_date = ''
end
end
+
+ def user_time
+ @user.prefs.tz.adjust(Time.now.utc)
+ end
+
# Uses RedCloth to transform text using either Textile or Markdown
# Need to require redcloth above
@@ -39,6 +44,11 @@ module ApplicationHelper
"#{name || url} "
end
+ def days_from_today(date)
+ today = Time.now.utc.to_date
+ @user.prefs.tz.adjust(date).to_date - @user.prefs.tz.adjust(today).to_date
+ end
+
# Check due date in comparison to today's date
# Flag up date appropriately with a 'traffic light' colour code
#
@@ -47,27 +57,26 @@ module ApplicationHelper
return ""
end
- @now = Date.today
- @days = due-@now
+ days = days_from_today(due)
- case @days
+ case days
# overdue or due very soon! sound the alarm!
when -1000..-1
- "Overdue by " + (@days * -1).to_s + " days "
+ "Overdue by " + (days * -1).to_s + " days "
when 0
"Due Today "
when 1
"Due Tomorrow "
# due 2-7 days away
when 2..7
- if @user.preference.due_style == "1"
+ if @user.prefs.due_style == "1"
"Due on " + due.strftime("%A") + " "
else
- "Due in " + @days.to_s + " days "
+ "Due in " + days.to_s + " days "
end
# more than a week away - relax
else
- "Due in " + @days.to_s + " days "
+ "Due in " + days.to_s + " days "
end
end
@@ -80,10 +89,9 @@ module ApplicationHelper
return ""
end
- @now = Date.today
- @days = due-@now
+ days = days_from_today(due)
- case @days
+ case days
# overdue or due very soon! sound the alarm!
when -1000..-1
"" + format_date(due) +" "
@@ -130,13 +138,13 @@ module ApplicationHelper
def item_link_to_context(item)
descriptor = "[C]"
- descriptor = "[#{item.context.name}]" if (@user.preference.verbose_action_descriptors)
+ descriptor = "[#{item.context.name}]" if (@user.prefs.verbose_action_descriptors)
link_to_context( item.context, descriptor )
end
def item_link_to_project(item)
descriptor = "[P]"
- descriptor = "[#{item.project.name}]" if (@user.preference.verbose_action_descriptors)
+ descriptor = "[#{item.project.name}]" if (@user.prefs.verbose_action_descriptors)
link_to_project( item.project, descriptor )
end
diff --git a/tracks/app/helpers/todo_helper.rb b/tracks/app/helpers/todo_helper.rb
index fb9eb102..c2c97a9f 100644
--- a/tracks/app/helpers/todo_helper.rb
+++ b/tracks/app/helpers/todo_helper.rb
@@ -42,11 +42,11 @@ module TodoHelper
def staleness_class(item)
if item.due || item.completed?
return ""
- elsif item.created_at < (@user.preference.staleness_starts * 3).days.ago
+ elsif item.created_at < (@user.prefs.staleness_starts * 3).days.ago.utc
return " stale_l3"
- elsif item.created_at < (@user.preference.staleness_starts * 2).days.ago
+ elsif item.created_at < (@user.prefs.staleness_starts * 2).days.ago.utc
return " stale_l2"
- elsif item.created_at < (@user.preference.staleness_starts).days.ago
+ elsif item.created_at < (@user.prefs.staleness_starts).days.ago.utc
return " stale_l1"
else
return ""
@@ -61,33 +61,32 @@ module TodoHelper
return ""
end
- @now = Date.today
- @days = due-@now
+ days = days_from_today(due)
- case @days
+ case days
# overdue or due very soon! sound the alarm!
when -1000..-1
- "Shown on " + (@days * -1).to_s + " days "
+ "Shown on " + (days * -1).to_s + " days "
when 0
"Show Today "
when 1
"Show Tomorrow "
# due 2-7 days away
when 2..7
- if @user.preference.due_style == 1
+ if @user.prefs.due_style == 1
"Show on " + due.strftime("%A") + " "
else
- "Show in " + @days.to_s + " days "
+ "Show in " + days.to_s + " days "
end
# more than a week away - relax
else
- "Show in " + @days.to_s + " days "
+ "Show in " + days.to_s + " days "
end
end
def calendar_setup( input_field )
- date_format = @user.preference.date_format
- week_starts = @user.preference.week_starts
+ date_format = @user.prefs.date_format
+ week_starts = @user.prefs.week_starts
str = "Calendar.setup({ ifFormat:\"#{date_format}\""
str << ",firstDay:#{week_starts},showOthers:true,range:[2004, 2010]"
str << ",step:1,inputField:\"" + input_field + "\",cache:true,align:\"TR\" })\n"
diff --git a/tracks/app/models/preference.rb b/tracks/app/models/preference.rb
index 316f2e22..19d9664e 100644
--- a/tracks/app/models/preference.rb
+++ b/tracks/app/models/preference.rb
@@ -1,6 +1,9 @@
class Preference < ActiveRecord::Base
belongs_to :user
-
+ composed_of :tz,
+ :class_name => 'TimeZone',
+ :mapping => %w(time_zone name)
+
def self.day_number_to_name_map
{ 0 => "Sunday",
1 => "Monday",
diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb
index d02052f5..e11c3807 100644
--- a/tracks/app/models/todo.rb
+++ b/tracks/app/models/todo.rb
@@ -9,7 +9,7 @@ class Todo < ActiveRecord::Base
state :active, :enter => Proc.new { |t| t[:show_from] = nil }
state :project_hidden
- state :completed, :enter => Proc.new { |t| t.completed_at = Time.now() }, :exit => Proc.new { |t| t.completed_at = nil }
+ state :completed, :enter => Proc.new { |t| t.completed_at = Time.now.utc }, :exit => Proc.new { |t| t.completed_at = nil }
state :deferred
event :defer do
@@ -45,7 +45,7 @@ class Todo < ActiveRecord::Base
validates_presence_of :context
def validate
- if deferred? && !show_from.blank? && show_from < Date.today()
+ if deferred? && !show_from.blank? && show_from < Time.now.utc.to_date
errors.add("Show From", "must be a date in the future.")
end
end
@@ -65,7 +65,7 @@ class Todo < ActiveRecord::Base
def show_from=(date)
activate! if deferred? && date.blank?
- defer! if active? && !date.blank? && date > Date.today()
+ defer! if active? && !date.blank? && date > Time.now.utc.to_date
self[:show_from] = date
end
@@ -78,7 +78,7 @@ class Todo < ActiveRecord::Base
alias_method :original_set_initial_state, :set_initial_state
def set_initial_state
- if show_from && (show_from > Date.today)
+ if show_from && (show_from > Time.now.utc.to_date)
write_attribute self.class.state_column, 'deferred'
else
original_set_initial_state
diff --git a/tracks/app/models/user.rb b/tracks/app/models/user.rb
index 3f0e5894..3ec3277e 100644
--- a/tracks/app/models/user.rb
+++ b/tracks/app/models/user.rb
@@ -15,7 +15,7 @@ class User < ActiveRecord::Base
:conditions => [ 'state = ?', 'deferred' ],
:order => 'show_from ASC, created_at DESC' do
def find_and_activate_ready
- find(:all, :conditions => ['show_from <= ?', Date.today ]).collect { |t| t.activate_and_save! }
+ find(:all, :conditions => ['show_from <= ?', Time.now.utc.to_date ]).collect { |t| t.activate_and_save! }
end
end
has_many :completed_todos,
@@ -45,6 +45,8 @@ class User < ActiveRecord::Base
validates_inclusion_of :auth_type, :in => Tracks::Config.auth_schemes, :message=>"not a valid authentication type"
validates_presence_of :open_id_url, :if => Proc.new{|user| user.auth_type == 'open_id'}
+ alias_method :prefs, :preference
+
def self.authenticate(login, pass)
candidate = find(:first, :conditions => ["login = ?", login])
return nil if candidate.nil?
diff --git a/tracks/app/views/context/show.rhtml b/tracks/app/views/context/show.rhtml
index f4aa9aad..e0a3f013 100644
--- a/tracks/app/views/context/show.rhtml
+++ b/tracks/app/views/context/show.rhtml
@@ -1,6 +1,6 @@
<%= render :partial => "context/context", :locals => { :context => @context, :collapsible => false } %>
-<%= render :partial => "todo/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{@user.preference.show_number_completed})" } %>
+<%= render :partial => "todo/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{@user.prefs.show_number_completed})" } %>
diff --git a/tracks/app/views/layouts/standard.rhtml b/tracks/app/views/layouts/standard.rhtml
index 54310988..370ce912 100644
--- a/tracks/app/views/layouts/standard.rhtml
+++ b/tracks/app/views/layouts/standard.rhtml
@@ -27,7 +27,7 @@
<% if @count %>
<%= @count %>
<% end %>
- <%= Time.now.strftime("%A, %d %B %Y") %> <%= image_tag("spinner.gif", :size => "16X16", :border => 0, :id => 'busy', :style => 'display:none' ) %>
+ <%= user_time.strftime("%A, %d %B %Y") %> <%= image_tag("spinner.gif", :size => "16X16", :border => 0, :id => 'busy', :style => 'display:none' ) %>
diff --git a/tracks/app/views/mobile/_mobile_edit.rhtml b/tracks/app/views/mobile/_mobile_edit.rhtml
index f1a5675d..8a1dfb6b 100644
--- a/tracks/app/views/mobile/_mobile_edit.rhtml
+++ b/tracks/app/views/mobile/_mobile_edit.rhtml
@@ -1,7 +1,7 @@
<%= error_messages_for("item") %>
-<% this_year = Date.today.strftime("%Y").to_i -%>
+<% this_year = user_time.to_date.strftime("%Y").to_i -%>
Done?
<%= check_box( "item", "state", "tabindex" => 1) %>
Next action
diff --git a/tracks/app/views/preferences/edit.rhtml b/tracks/app/views/preferences/edit.rhtml
index 3897c615..7dcf3e5d 100644
--- a/tracks/app/views/preferences/edit.rhtml
+++ b/tracks/app/views/preferences/edit.rhtml
@@ -3,6 +3,8 @@
The preference settings should mostly be self-explanatory, but some hints are included below:
first name and last name: Used for display purposes if set
+ time zone: your local time zone
+ date format: the format in which you'd like dates to be shown. For example, for the date 31st January 2006, %d/%m/%Y will show 31/01/2006, %b-%e-%y will show Jan-31-06. See the strftime manual for more formatting options for the date.
week starts: day of the week shown as the start of the week on the popup calendar.
due style: style in which due dates are shown, e.g. "Due in 3 days", "Due on Wednesday"
show completed projects in sidebar: whether or not projects marked as complete are shown in the sidebar on the home page and elsewhere
@@ -11,7 +13,6 @@
admin email: email address for the admin user of Tracks (displayed on the signup page for users to contact to obtain an account)
<% end %>
staleness starts: the number of days before items with no due date get marked as stale (with a yellow highlight)
- date format: the format in which you'd like dates to be shown. For example, for the date 31st January 2006, %d/%m/%Y will show 31/01/2006, %b-%e-%y will show Jan-31-06. See the strftime manual for more formatting options for the date.
show number completed: number of completed actions to show on the home page. If you set this to zero, the completed actions box will not be shown on the home page or on the individual context or project pages. You can still see all your completed items by clicking the 'Done' link in the navigation bar at the top of each page.
refresh: automatic refresh interval for each of the pages (in minutes)
verbose action descriptor: when true, show project/context name in action listing; when false show [P]/[C] with tool tips
@@ -46,7 +47,9 @@
table_row(pref_name, nowrap_label) { text_field('prefs', pref_name) }
end
%>
+ <%= table_row('time_zone', false) { time_zone_select('prefs','time_zone') } %>
+ <%= row_with_text_field('date_format') %>
<%= row_with_select_field("week_starts", Preference.day_number_to_name_map.invert.sort{|a,b| a[1]<=>b[1]})%>
<%= row_with_select_field("due_style", [['Due in ___ days',0],['Due on _______',1]]) %>
<%= row_with_select_field("show_completed_projects_in_sidebar") %>
@@ -56,7 +59,6 @@
<% if @user.is_admin? %> <%= row_with_text_field('admin_email') %> <% end %>
<%= row_with_text_field('staleness_starts', true) %>
- <%= row_with_text_field('date_format') %>
<%= row_with_text_field('show_number_completed') %>
<%= row_with_text_field('refresh') %>
<%= row_with_select_field("verbose_action_descriptors") %>
diff --git a/tracks/app/views/preferences/index.rhtml b/tracks/app/views/preferences/index.rhtml
index ced88bbe..577c99c0 100644
--- a/tracks/app/views/preferences/index.rhtml
+++ b/tracks/app/views/preferences/index.rhtml
@@ -5,6 +5,7 @@
First name: <%= @user.first_name %>
Last name: <%= @user.last_name %>
+ Time zone: <%= @prefs.tz %>
Date format: <%= @prefs.date_format %>
Week starts on: <%= Preference.day_number_to_name_map[@prefs.week_starts] %>
Show the last <%= @prefs.show_number_completed %> completed items on the home page
diff --git a/tracks/app/views/sidebar/sidebar.rhtml b/tracks/app/views/sidebar/sidebar.rhtml
index e2756ec7..1b71062d 100644
--- a/tracks/app/views/sidebar/sidebar.rhtml
+++ b/tracks/app/views/sidebar/sidebar.rhtml
@@ -4,13 +4,13 @@
:locals => { :list_name => 'Active Projects',
:projects => @projects.select{|p| p.active? } } -%>
- <% if @user.preference.show_hidden_projects_in_sidebar -%>
+ <% if @user.prefs.show_hidden_projects_in_sidebar -%>
<%= render :partial => "sidebar/project_list",
:locals => { :list_name => 'Hidden Projects',
:projects => @projects.select{|p| p.hidden? } } -%>
<% end -%>
- <% if @user.preference.show_completed_projects_in_sidebar -%>
+ <% if @user.prefs.show_completed_projects_in_sidebar -%>
<%= render :partial => "sidebar/project_list",
:locals => { :list_name => 'Completed Projects',
:projects => @projects.select{|p| p.completed? } } -%>
@@ -20,7 +20,7 @@
:locals => { :list_name => 'Active Contexts',
:contexts => @contexts.reject{|c| c.hide? } } -%>
- <% if @user.preference.show_hidden_contexts_in_sidebar -%>
+ <% if @user.prefs.show_hidden_contexts_in_sidebar -%>
<%= render :partial => "sidebar/context_list",
:locals => { :list_name => 'Hidden Contexts',
:contexts => @contexts.select{|c| c.hide? } } -%>
diff --git a/tracks/app/views/todo/toggle_check.rjs b/tracks/app/views/todo/toggle_check.rjs
index f02e3981..c0b69ac6 100644
--- a/tracks/app/views/todo/toggle_check.rjs
+++ b/tracks/app/views/todo/toggle_check.rjs
@@ -2,7 +2,7 @@ if @saved
page[@item].remove
if @item.completed?
# Don't try to insert contents into a non-existent container!
- unless @user.preference.hide_completed_actions?
+ unless @user.prefs.hide_completed_actions?
page.insert_html :top, "completed", :partial => 'todo/item', :locals => { :parent_container_type => "completed" }
page.visual_effect :highlight, dom_id(@item, 'line'), {'startcolor' => "'#99ff99'"}
page[empty_container_msg_div_id].show if @down_count == 0 && !empty_container_msg_div_id.nil?
diff --git a/tracks/db/migrate/020_pref_to_show_hidden_projects_in_sidebar.rb b/tracks/db/migrate/020_pref_to_show_hidden_projects_in_sidebar.rb
index 3968cb4b..ea346a90 100644
--- a/tracks/db/migrate/020_pref_to_show_hidden_projects_in_sidebar.rb
+++ b/tracks/db/migrate/020_pref_to_show_hidden_projects_in_sidebar.rb
@@ -1,7 +1,5 @@
class PrefToShowHiddenProjectsInSidebar < ActiveRecord::Migration
- class Preferences < ActiveRecord::Base; end
-
def self.up
add_column :preferences, :show_hidden_projects_in_sidebar, :boolean, :default => true, :null => false
end
diff --git a/tracks/db/migrate/021_add_time_zone_preference.rb b/tracks/db/migrate/021_add_time_zone_preference.rb
new file mode 100644
index 00000000..63a9f16a
--- /dev/null
+++ b/tracks/db/migrate/021_add_time_zone_preference.rb
@@ -0,0 +1,11 @@
+class AddTimeZonePreference < ActiveRecord::Migration
+
+ def self.up
+ add_column :preferences, :time_zone, :string, :limit => 255, :default => 'London', :null => false
+ end
+
+ def self.down
+ remove_column :preferences, :time_zone
+ end
+
+end
diff --git a/tracks/db/schema.rb b/tracks/db/schema.rb
index ccb5a200..c44ce4f9 100644
--- a/tracks/db/schema.rb
+++ b/tracks/db/schema.rb
@@ -1,96 +1,97 @@
-# This file is autogenerated. Instead of editing this file, please use the
-# migrations feature of ActiveRecord to incrementally modify your database, and
-# then regenerate this schema definition.
-
-ActiveRecord::Schema.define(:version => 20) do
-
- create_table "contexts", :force => true do |t|
- t.column "name", :string, :default => "", :null => false
- t.column "position", :integer, :default => 0, :null => false
- t.column "hide", :boolean, :default => false
- t.column "user_id", :integer, :default => 1
- end
-
- create_table "notes", :force => true do |t|
- t.column "user_id", :integer, :default => 0, :null => false
- t.column "project_id", :integer, :default => 0, :null => false
- t.column "body", :text
- t.column "created_at", :datetime
- t.column "updated_at", :datetime
- end
-
- create_table "open_id_associations", :force => true do |t|
- t.column "server_url", :binary
- t.column "handle", :string
- t.column "secret", :binary
- t.column "issued", :integer
- t.column "lifetime", :integer
- t.column "assoc_type", :string
- end
-
- create_table "open_id_nonces", :force => true do |t|
- t.column "nonce", :string
- t.column "created", :integer
- end
-
- create_table "open_id_settings", :force => true do |t|
- t.column "setting", :string
- t.column "value", :binary
- end
-
- create_table "preferences", :force => true do |t|
- t.column "user_id", :integer, :default => 0, :null => false
- t.column "date_format", :string, :limit => 40, :default => "%d/%m/%Y", :null => false
- t.column "week_starts", :integer, :default => 0, :null => false
- t.column "show_number_completed", :integer, :default => 5, :null => false
- t.column "staleness_starts", :integer, :default => 7, :null => false
- t.column "show_completed_projects_in_sidebar", :boolean, :default => true, :null => false
- t.column "show_hidden_contexts_in_sidebar", :boolean, :default => true, :null => false
- t.column "due_style", :integer, :default => 0, :null => false
- t.column "admin_email", :string, :default => "butshesagirl@rousette.org.uk", :null => false
- t.column "refresh", :integer, :default => 0, :null => false
- t.column "verbose_action_descriptors", :boolean, :default => false, :null => false
- t.column "show_hidden_projects_in_sidebar", :boolean, :default => true, :null => false
- end
-
- create_table "projects", :force => true do |t|
- t.column "name", :string, :default => "", :null => false
- t.column "position", :integer, :default => 0, :null => false
- t.column "user_id", :integer, :default => 1
- t.column "description", :text
- t.column "state", :string, :limit => 20, :default => "active", :null => false
- end
-
- create_table "sessions", :force => true do |t|
- t.column "session_id", :string
- t.column "data", :text
- t.column "updated_at", :datetime
- end
-
- add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
-
- create_table "todos", :force => true do |t|
- t.column "context_id", :integer, :default => 0, :null => false
- t.column "project_id", :integer
- t.column "description", :string, :default => "", :null => false
- t.column "notes", :text
- t.column "created_at", :datetime
- t.column "due", :date
- t.column "completed_at", :datetime
- t.column "user_id", :integer, :default => 1
- t.column "show_from", :date
- t.column "state", :string, :limit => 20, :default => "immediate", :null => false
- end
-
- create_table "users", :force => true do |t|
- t.column "login", :string, :limit => 80, :default => "", :null => false
- t.column "password", :string, :limit => 40, :default => "", :null => false
- t.column "word", :string
- t.column "is_admin", :boolean, :default => false, :null => false
- t.column "first_name", :string
- t.column "last_name", :string
- t.column "auth_type", :string, :default => "database", :null => false
- t.column "open_id_url", :string
- end
-
-end
+# This file is autogenerated. Instead of editing this file, please use the
+# migrations feature of ActiveRecord to incrementally modify your database, and
+# then regenerate this schema definition.
+
+ActiveRecord::Schema.define(:version => 21) do
+
+ create_table "contexts", :force => true do |t|
+ t.column "name", :string, :default => "", :null => false
+ t.column "hide", :integer, :limit => 4, :default => 0, :null => false
+ t.column "position", :integer, :default => 0, :null => false
+ t.column "user_id", :integer, :default => 0, :null => false
+ end
+
+ create_table "notes", :force => true do |t|
+ t.column "user_id", :integer, :default => 0, :null => false
+ t.column "project_id", :integer, :default => 0, :null => false
+ t.column "body", :text
+ t.column "created_at", :datetime
+ t.column "updated_at", :datetime
+ end
+
+ create_table "open_id_associations", :force => true do |t|
+ t.column "server_url", :binary
+ t.column "handle", :string
+ t.column "secret", :binary
+ t.column "issued", :integer
+ t.column "lifetime", :integer
+ t.column "assoc_type", :string
+ end
+
+ create_table "open_id_nonces", :force => true do |t|
+ t.column "nonce", :string
+ t.column "created", :integer
+ end
+
+ create_table "open_id_settings", :force => true do |t|
+ t.column "setting", :string
+ t.column "value", :binary
+ end
+
+ create_table "preferences", :force => true do |t|
+ t.column "user_id", :integer, :default => 0, :null => false
+ t.column "date_format", :string, :limit => 40, :default => "%d/%m/%Y", :null => false
+ t.column "week_starts", :integer, :default => 0, :null => false
+ t.column "show_number_completed", :integer, :default => 5, :null => false
+ t.column "staleness_starts", :integer, :default => 7, :null => false
+ t.column "show_completed_projects_in_sidebar", :boolean, :default => true, :null => false
+ t.column "show_hidden_contexts_in_sidebar", :boolean, :default => true, :null => false
+ t.column "due_style", :integer, :default => 0, :null => false
+ t.column "admin_email", :string, :default => "butshesagirl@rousette.org.uk", :null => false
+ t.column "refresh", :integer, :default => 0, :null => false
+ t.column "verbose_action_descriptors", :boolean, :default => false, :null => false
+ t.column "show_hidden_projects_in_sidebar", :boolean, :default => true, :null => false
+ t.column "time_zone", :string, :default => "London", :null => false
+ end
+
+ create_table "projects", :force => true do |t|
+ t.column "name", :string, :default => "", :null => false
+ t.column "position", :integer, :default => 0, :null => false
+ t.column "user_id", :integer, :default => 0, :null => false
+ t.column "description", :text
+ t.column "state", :string, :limit => 20, :default => "active", :null => false
+ end
+
+ create_table "sessions", :force => true do |t|
+ t.column "session_id", :string
+ t.column "data", :text
+ t.column "updated_at", :datetime
+ end
+
+ add_index "sessions", ["session_id"], :name => "sessions_session_id_index"
+
+ create_table "todos", :force => true do |t|
+ t.column "context_id", :integer, :default => 0, :null => false
+ t.column "description", :string, :limit => 100, :default => "", :null => false
+ t.column "notes", :text
+ t.column "created_at", :datetime
+ t.column "due", :date
+ t.column "completed_at", :datetime
+ t.column "project_id", :integer
+ t.column "user_id", :integer, :default => 0, :null => false
+ t.column "show_from", :date
+ t.column "state", :string, :limit => 20, :default => "immediate", :null => false
+ end
+
+ create_table "users", :force => true do |t|
+ t.column "login", :string, :limit => 80
+ t.column "password", :string, :limit => 40
+ t.column "word", :string
+ t.column "is_admin", :integer, :limit => 4, :default => 0, :null => false
+ t.column "first_name", :string
+ t.column "last_name", :string
+ t.column "auth_type", :string, :default => "database", :null => false
+ t.column "open_id_url", :string
+ end
+
+end
diff --git a/tracks/lib/todo_list.rb b/tracks/lib/todo_list.rb
index 5e3015c0..41dd8498 100644
--- a/tracks/lib/todo_list.rb
+++ b/tracks/lib/todo_list.rb
@@ -33,7 +33,7 @@ module Tracks
def find_done_todos
self.todos.find(:all, :conditions => ["todos.state = ?", "completed"],
- :order => "todos.completed_at DESC", :limit => self.user.preference.show_number_completed)
+ :order => "todos.completed_at DESC", :limit => self.user.prefs.show_number_completed)
end
def not_done_todo_count(opts={})
diff --git a/tracks/public/javascripts/calendar-setup.js b/tracks/public/javascripts/calendar-setup.js
index 1d81868a..d09ade8d 100644
--- a/tracks/public/javascripts/calendar-setup.js
+++ b/tracks/public/javascripts/calendar-setup.js
@@ -213,9 +213,8 @@ Calendar.setup = function (params) {
* they still work properly. Pressing '+' when no date is entered in the
* field will set the date to tomorrow, and likewise '-' with no date
* entered will set the date to yesterday.
- * 2006-10-24: Commented out while trying to use Chronic library for the field
*/
-/*DateDueKeyboardShortcutSupport = Class.create();
+DateDueKeyboardShortcutSupport = Class.create();
DateDueKeyboardShortcutSupport.prototype = {
initialize: function(element, dateFormat) {
this.element = $(element);
@@ -298,4 +297,4 @@ DateDueKeyboardShortcutSupport.prototype = {
((event.which) ? event.which : 0));
return String.fromCharCode(charCode);
}
-};*/
+};
diff --git a/tracks/test/fixtures/notes.yml b/tracks/test/fixtures/notes.yml
index ad914f3f..a01942ab 100644
--- a/tracks/test/fixtures/notes.yml
+++ b/tracks/test/fixtures/notes.yml
@@ -1,15 +1,15 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<%
def today
- Time.now.to_s(:db)
+ Time.now.utc.to_s(:db)
end
def next_week
- 1.week.from_now.to_s(:db)
+ 1.week.from_now.utc.to_s(:db)
end
def last_week
- 1.week.ago.to_s(:db)
+ 1.week.ago.utc.to_s(:db)
end
%>
diff --git a/tracks/test/fixtures/preferences.yml b/tracks/test/fixtures/preferences.yml
index e48c5d17..b0457a39 100644
--- a/tracks/test/fixtures/preferences.yml
+++ b/tracks/test/fixtures/preferences.yml
@@ -12,6 +12,7 @@ admin_user_prefs:
week_starts: 1
due_style: 0
refresh: 0
+ time_zone: "London"
verbose_action_descriptors: true
other_user_prefs:
@@ -27,4 +28,5 @@ other_user_prefs:
week_starts: 1
due_style: 0
refresh: 0
+ time_zone: "London"
verbose_action_descriptors: false
diff --git a/tracks/test/fixtures/todos.yml b/tracks/test/fixtures/todos.yml
index cff6ed0b..2c7b6f89 100644
--- a/tracks/test/fixtures/todos.yml
+++ b/tracks/test/fixtures/todos.yml
@@ -2,19 +2,19 @@
<%
def today
- Time.now.to_s(:db)
+ Time.now.utc.to_s(:db)
end
def next_week
- 1.week.from_now.to_s(:db)
+ 1.week.from_now.utc.to_s(:db)
end
def last_week
- 1.week.ago.to_s(:db)
+ 1.week.ago.utc.to_s(:db)
end
def two_weeks_hence
- 2.week.from_now.to_s(:db)
+ 2.week.from_now.utc.to_s(:db)
end
%>
diff --git a/tracks/test/functional/project_controller_test.rb b/tracks/test/functional/project_controller_test.rb
index e98ac5a0..af2886cf 100644
--- a/tracks/test/functional/project_controller_test.rb
+++ b/tracks/test/functional/project_controller_test.rb
@@ -25,7 +25,7 @@ class ProjectControllerTest < TodoContainerControllerTestBase
assert_equal 1, assigns['deferred'].size
t = p.not_done_todos[0]
- t.show_from = 1.days.from_now.to_date
+ t.show_from = 1.days.from_now.utc.to_date
t.save!
get :show, :url_friendly_name => p.url_friendly_name
diff --git a/tracks/test/functional/todo_controller_test.rb b/tracks/test/functional/todo_controller_test.rb
index 55e9c7fb..5b958c47 100644
--- a/tracks/test/functional/todo_controller_test.rb
+++ b/tracks/test/functional/todo_controller_test.rb
@@ -71,7 +71,9 @@ class TodoControllerTest < Test::Unit::TestCase
#assert_rjs :page, "todo_1", :visual_effect, :highlight, :duration => '1'
t = Todo.find(1)
assert_equal "Call Warren Buffet to find out how much he makes per day", t.description
- assert_equal Date.new(2006,11,30), t.due
+ expected = Date.new(2006,11,30).to_time.utc.to_date
+ actual = t.due
+ assert_equal expected, actual, "Expected #{expected.to_s(:db)}, was #{actual.to_s(:db)}"
end
diff --git a/tracks/test/unit/preference_test.rb b/tracks/test/unit/preference_test.rb
new file mode 100644
index 00000000..669f172f
--- /dev/null
+++ b/tracks/test/unit/preference_test.rb
@@ -0,0 +1,18 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class PreferenceTest < Test::Unit::TestCase
+ fixtures :users, :preferences
+
+ def setup
+ assert_equal "test", ENV['RAILS_ENV']
+ assert_equal "change-me", Tracks::Config.salt
+ @admin_user = User.find(1)
+ @other_user = User.find(2)
+ end
+
+ def test_time_zone
+ assert_equal 'London', @admin_user.preference.time_zone
+ assert_equal @admin_user.preference.tz, TimeZone['London']
+ end
+
+end
diff --git a/tracks/test/unit/project_test.rb b/tracks/test/unit/project_test.rb
index 7ebac68f..02daf054 100644
--- a/tracks/test/unit/project_test.rb
+++ b/tracks/test/unit/project_test.rb
@@ -102,7 +102,7 @@ class ProjectTest < Test::Unit::TestCase
def test_deferred_todos
assert_equal 1, @timemachine.deferred_todos.size
t = @timemachine.not_done_todos[0]
- t.show_from = 1.days.from_now.to_date
+ t.show_from = 1.days.from_now.utc.to_date
t.save!
assert_equal 2, Project.find(@timemachine.id).deferred_todos.size
end
diff --git a/tracks/test/unit/todo_test.rb b/tracks/test/unit/todo_test.rb
index ddd8e3e3..27bbf13f 100644
--- a/tracks/test/unit/todo_test.rb
+++ b/tracks/test/unit/todo_test.rb
@@ -19,8 +19,8 @@ class TodoTest < Test::Unit::TestCase
assert_equal "Call Bill Gates to find out how much he makes per day", @not_completed1.description
assert_nil @not_completed1.notes
assert @not_completed1.completed? == false
- assert_equal 1.week.ago.strftime("%Y-%m-%d %H:%M"), @not_completed1.created_at.strftime("%Y-%m-%d %H:%M")
- assert_equal 2.week.from_now.strftime("%Y-%m-%d"), @not_completed1.due.strftime("%Y-%m-%d")
+ assert_equal 1.week.ago.utc.strftime("%Y-%m-%d %H:%M"), @not_completed1.created_at.strftime("%Y-%m-%d %H:%M")
+ assert_equal 2.week.from_now.utc.strftime("%Y-%m-%d"), @not_completed1.due.strftime("%Y-%m-%d")
assert_nil @not_completed1.completed_at
assert_equal 1, @not_completed1.user_id
end
diff --git a/tracks/test/unit/user_test.rb b/tracks/test/unit/user_test.rb
index eda75dae..3b8a85d4 100644
--- a/tracks/test/unit/user_test.rb
+++ b/tracks/test/unit/user_test.rb
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class UserTest < Test::Unit::TestCase
- fixtures :users
+ fixtures :users, :preferences
def setup
assert_equal "test", ENV['RAILS_ENV']
@@ -134,5 +134,9 @@ class UserTest < Test::Unit::TestCase
@other_user.last_name = nil
assert_equal @other_user.login, @other_user.display_name
end
+
+ def test_prefs_is_short_for_preference
+ assert_equal @admin_user.preference, @admin_user.prefs
+ end
end