Changes to notification about whether login session has timed out and changes to improve compatibility with SQLite and PostgreSQL databases:

* Set up notification of the session timing out. If you haven't checked the 'Keep logged in' checkbox at login, a method is run periodically (every 5 minutes) to check whether there is more than 10 minutes remaining on your session. When there's less than 10 minutes left, a red warning box appears dynamically at the top of the page appears to tell you that your session has timed out, and asking you to login again (with a link to the login page). This basically prevents the situation when you return to the browser window after more than an hour has elapsed, and try to add a new item without knowing that your session has timed out.
* Changed the find methods that previously used 'done = 0' or 'done = 1' to test for truth or falsity instead. This means that it's compatible with both MySQL (which uses tinyint 0 or 1 values) and SQLite/SQLite3 and PostgreSQL (which use boolean 't' or 'f' values). By using true or false, ActiveRecord translates the values to the correct format depending on which database adapter is being used. 



git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@178 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
bsag 2006-01-15 14:38:57 +00:00
parent a56b4611c8
commit 0a1fed570e
13 changed files with 72 additions and 40 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -39,6 +39,11 @@
<li><%= link_to "Logout (#{@session['user']['login']}) &#187;", :controller => "login", :action=>"logout"%></li>
</ul>
</div>
<div id="info"></div>
<% unless @controller_name == 'feed' or @session['noexpiry'] == "on" -%>
<%= periodically_call_remote( :url => {:controller => "login", :action => "check_expiry"},
:frequency => (5*60)) %>
<% end -%>
<%= @content_for_layout %>
<div id="footer">

View file

@ -0,0 +1,3 @@
unless @msg == ""
page.replace_html "info", content_tag("div", @msg + link_to("log in again.", :controller => "login", :action => "login"), "class" => "warning")
end

View file

@ -9,6 +9,7 @@
end
%>
<% hide_link ||= false %>
<% unless hide_link -%>
<%= link_to_function(
add_string,

View file

@ -3,9 +3,9 @@ class AddUserId < ActiveRecord::Migration
add_column :contexts, :user_id, :integer, :null => false
add_column :projects, :user_id, :integer, :null => false
add_column :todos, :user_id, :integer, :null => false
execute "UPDATE `contexts` SET `user_id` = 1;"
execute "UPDATE `projects` SET `user_id` = 1;"
execute "UPDATE `todos` SET `user_id` = 1;"
execute "UPDATE 'contexts' SET 'user_id' = 1;"
execute "UPDATE 'projects' SET 'user_id' = 1;"
execute "UPDATE 'todos' SET 'user_id' = 1;"
end
def self.down

View file

@ -5,43 +5,43 @@
ActiveRecord::Schema.define(:version => 5) 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 "name", :string, :null => false
t.column "position", :integer, :null => false
t.column "hide", :boolean, :default => false
t.column "user_id", :integer, :default => 0, :null => false
t.column "user_id", :integer, :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 "user_id", :integer, :null => false
t.column "project_id", :integer, :null => false
t.column "body", :text
t.column "created_at", :datetime
t.column "updated_at", :datetime
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 "name", :string, :null => false
t.column "position", :integer, :null => false
t.column "done", :boolean, :default => false
t.column "user_id", :integer, :default => 0, :null => false
t.column "description", :text
t.column "user_id", :integer, :null => false
t.column "description", :text, :default => ""
end
create_table "todos", :force => true do |t|
t.column "context_id", :integer, :default => 0, :null => false
t.column "context_id", :integer, :null => false
t.column "project_id", :integer
t.column "description", :string, :default => "", :null => false
t.column "description", :string, :null => false
t.column "notes", :text
t.column "done", :boolean, :default => false, :null => false
t.column "created_at", :datetime
t.column "due", :date
t.column "completed", :datetime
t.column "user_id", :integer, :default => 0, :null => false
t.column "user_id", :integer, :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 "login", :string, :limit => 80, :null => false
t.column "password", :string, :limit => 40, :null => false
t.column "word", :string
t.column "is_admin", :boolean, :default => false, :null => false
end

View file

@ -277,15 +277,17 @@ a.footer_link:hover {color: #fff; background-color: #cc3334 !important;}
text-align: center;
}
#warning {
#warning, .warning {
padding: 2px;
border: 1px solid #ED2E38;
background-color: #F6979C;
color: #ED2E38;
color: #FFFFFF;
margin-bottom: 15px;
text-align: center;
}
.warning p {color: #FFFFFF;}
.project_completed {
border: 1px solid #007E00;
background-color: #c2ffc2;