diff --git a/tracks/app/controllers/context_controller.rb b/tracks/app/controllers/context_controller.rb index e1b653b8..c8a9cf8f 100644 --- a/tracks/app/controllers/context_controller.rb +++ b/tracks/app/controllers/context_controller.rb @@ -60,7 +60,7 @@ class ContextController < ApplicationController @saved = @item.save @on_page = "context" if @saved - @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.context_id IN (?)", @user.id, @item.context_id]).size.to_s + @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ? and todos.context_id IN (?)", @user.id, false, @item.context_id]).size.to_s end return if request.xhr? @@ -91,7 +91,7 @@ class ContextController < ApplicationController @saved = @item.destroy if @saved - @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.context_id IN (?)", @user.id, @item.context_id]).size.to_s + @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ? and todos.context_id IN (?)", @user.id, false, @item.context_id]).size.to_s end return if request.xhr? @@ -123,8 +123,8 @@ class ContextController < ApplicationController @item.completed = Time.now() # For some reason, the before_save in todo.rb stopped working @saved = @item.save if @saved - @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.context_id IN (?)", @user.id, @item.context_id]).size.to_s - @done_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 1 and todos.context_id IN (?)", @user.id, @item.context_id]).size.to_s + @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ? and todos.context_id IN (?)", @user.id, false, @item.context_id]).size.to_s + @done_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ? and todos.context_id IN (?)", @user.id, true, @item.context_id]).size.to_s end return if request.xhr? @@ -221,7 +221,7 @@ class ContextController < ApplicationController @projects = @user.projects.collect { |x| x.done? ? nil:x }.compact @contexts = @user.contexts @todos = @user.todos - @done = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 1", @user.id], :include => [:project], :order => "completed DESC") + @done = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ?", @user.id, true], :include => [:project], :order => "completed DESC") end def init_todos diff --git a/tracks/app/controllers/login_controller.rb b/tracks/app/controllers/login_controller.rb index 394077e2..98496635 100644 --- a/tracks/app/controllers/login_controller.rb +++ b/tracks/app/controllers/login_controller.rb @@ -76,5 +76,27 @@ class LoginController < ApplicationController def welcome end + + def check_expiry + # Gets called by periodically_call_remote to check whether + # the session has timed out yet + unless @session == nil + return if @controller_name == 'feed' or @session['noexpiry'] == "on" + # If the method is called by the feed controller + # (which we don't have under session control) + # or if we checked the box to keep logged in on login + # then the session is not going to get called + if @session + # Get expiry time (allow ten seconds window for the case where we have none) + expiry_time = @session['expiry_time'] || Time.now + 10 + @time_left = expiry_time - Time.now + if @time_left < (10*60) # Session will time out before the next check + @msg = "Session has timed out. Please " + else + @msg = "" + end + end + end + end end diff --git a/tracks/app/controllers/project_controller.rb b/tracks/app/controllers/project_controller.rb index 0d0bd3dc..12aaeb58 100644 --- a/tracks/app/controllers/project_controller.rb +++ b/tracks/app/controllers/project_controller.rb @@ -79,7 +79,7 @@ class ProjectController < ApplicationController @saved = @item.save @on_page = "project" if @saved - @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.project_id IN (?)", @user.id, @item.project_id]).size.to_s + @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ? and todos.project_id IN (?)", @user.id, false, @item.project_id]).size.to_s end return if request.xhr? @@ -111,7 +111,7 @@ class ProjectController < ApplicationController @saved = @item.destroy @on_page = "project" if @saved - @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.project_id IN (?)", @user.id, @item.project_id]).size.to_s + @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ? and todos.project_id IN (?)", @user.id, false, @item.project_id]).size.to_s end return if request.xhr? @@ -144,8 +144,8 @@ class ProjectController < ApplicationController @saved = @item.save @on_page = "project" if @saved - @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.project_id IN (?)", @user.id, @item.project_id]).size.to_s - @done_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 1 and todos.project_id IN (?)", @user.id, @item.project_id]).size.to_s + @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ? and todos.project_id IN (?)", @user.id, false, @item.project_id]).size.to_s + @done_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ? and todos.project_id IN (?)", @user.id, true, @item.project_id]).size.to_s end return if request.xhr? @@ -249,10 +249,10 @@ class ProjectController < ApplicationController def init @user = @session['user'] - @projects = @user.projects.collect { |x| x.done? ? nil:x }.compact + @projects = @user.projects @contexts = @user.contexts @todos = @user.todos - @done = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 1", @user.id], :include => [:project], :order => "completed DESC") + @done = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ?", @user.id, true], :include => [:project], :order => "completed DESC") end def init_todos diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index be54a23a..29441d34 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -208,7 +208,7 @@ class TodoController < ApplicationController @projects = @user.projects @contexts = @user.contexts @todos = @user.todos - @done = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 1", @user.id], :include => [:project], :order => "completed DESC") + @done = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = ?", @user.id, true], :include => [:project], :order => "completed DESC") # for some reason, this generates an error about anil object under 0.14.2 #@done = @todos.collect { |x| x.done? ? x:nil }.compact.sort! {|x,y| y.completed <=> x.completed } end diff --git a/tracks/app/models/context.rb b/tracks/app/models/context.rb index 67b1483b..fa8725b1 100644 --- a/tracks/app/models/context.rb +++ b/tracks/app/models/context.rb @@ -12,18 +12,18 @@ class Context < ActiveRecord::Base validates_length_of :name, :maximum => 255, :message => "context name must be less than %d" validates_uniqueness_of :name, :message => "already exists", :scope => "user_id" - def self.list_of(hidden=0) + def self.list_of(hidden=false) find(:all, :conditions => [ "hide = ?" , hidden ], :order => "position ASC") end def find_not_done_todos - todos = Todo.find :all, :conditions => "todos.context_id = #{id} AND todos.done = 0", + todos = Todo.find :all, :conditions => ["todos.context_id = #{id} AND todos.done = ?", false], :include => [:context, :project], :order => "due IS NULL, due ASC, created_at ASC" end def find_done_todos - todos = Todo.find :all, :conditions => "todos.context_id = #{id} AND todos.done = 1", + todos = Todo.find :all, :conditions => ["todos.context_id = #{id} AND todos.done = ?", true], :include => [:context, :project], :order => "due IS NULL, due ASC, created_at ASC" end @@ -43,7 +43,7 @@ class Context < ActiveRecord::Base end def hidden? - self.hide == 1 + self.hide == true end end diff --git a/tracks/app/models/project.rb b/tracks/app/models/project.rb index 37d7e5b3..210f21d9 100644 --- a/tracks/app/models/project.rb +++ b/tracks/app/models/project.rb @@ -14,16 +14,16 @@ class Project < ActiveRecord::Base validates_uniqueness_of :name, :message => "already exists", :scope =>"user_id" def self.list_of(isdone=0) - find(:all, :conditions => [ "done = ?" , isdone ], :order => "position ASC") + find(:all, :conditions => [ "done = ?" , true ], :order => "position ASC") end def find_not_done_todos - todos = Todo.find :all, :conditions => "project_id = #{id} AND done = 0", + todos = Todo.find :all, :conditions => ["project_id = #{id} AND done = ?", false], :order => "due IS NULL, due ASC, created_at ASC" end def find_done_todos - todos = Todo.find :all, :conditions => "project_id = #{id} AND done = 1", + todos = Todo.find :all, :conditions => ["project_id = #{id} AND done = ?", true], :order => "due IS NULL, due ASC, created_at ASC" end diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb index 22a65799..690d2e58 100644 --- a/tracks/app/models/todo.rb +++ b/tracks/app/models/todo.rb @@ -13,8 +13,7 @@ class Todo < ActiveRecord::Base validates_length_of :notes, :maximum => 60000 def self.not_done( id=id ) - self.find(:all, :conditions =>[ "done = 0 AND context_id = ?", id], \ - :order =>"due IS NULL, due ASC, created_at ASC") + self.find(:all, :conditions =>[ "done = ? AND context_id = ?", false, id], :order =>"due IS NULL, due ASC, created_at ASC") end end diff --git a/tracks/app/views/layouts/standard.rhtml b/tracks/app/views/layouts/standard.rhtml index 58b93200..ffa17e38 100644 --- a/tracks/app/views/layouts/standard.rhtml +++ b/tracks/app/views/layouts/standard.rhtml @@ -39,6 +39,11 @@
  • <%= link_to "Logout (#{@session['user']['login']}) »", :controller => "login", :action=>"logout"%>
  • +
    +<% unless @controller_name == 'feed' or @session['noexpiry'] == "on" -%> +<%= periodically_call_remote( :url => {:controller => "login", :action => "check_expiry"}, + :frequency => (5*60)) %> +<% end -%> <%= @content_for_layout %>