mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-03 22:41:48 +01:00
Complete the transition of acts_as_todo_container to todo_list, a simple module.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@350 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
807cb1e759
commit
fed0daa96d
6 changed files with 53 additions and 94 deletions
|
|
@ -1,11 +1,11 @@
|
|||
class Context < ActiveRecord::Base
|
||||
|
||||
has_many :todos, :dependent => :delete_all, :order => "completed_at DESC"
|
||||
has_many :todos, :dependent => :delete_all, :include => :project, :order => "completed_at DESC"
|
||||
belongs_to :user
|
||||
|
||||
acts_as_list :scope => :user
|
||||
extend NamePartFinder
|
||||
acts_as_todo_container :find_todos_include => :project
|
||||
include Tracks::TodoList
|
||||
|
||||
attr_protected :user
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class Project < ActiveRecord::Base
|
||||
has_many :todos, :dependent => :delete_all
|
||||
has_many :todos, :dependent => :delete_all, :include => :context
|
||||
has_many :notes, :dependent => true, :order => "created_at DESC"
|
||||
belongs_to :user
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ class Project < ActiveRecord::Base
|
|||
acts_as_list :scope => :user
|
||||
acts_as_state_machine :initial => :active, :column => 'state'
|
||||
extend NamePartFinder
|
||||
acts_as_todo_container :find_todos_include => :context
|
||||
include Tracks::TodoList
|
||||
|
||||
state :active
|
||||
state :hidden, :enter => :hide_todos, :exit => :unhide_todos
|
||||
|
|
|
|||
|
|
@ -63,13 +63,9 @@ SALT = "change-me"
|
|||
AUTHENTICATION_SCHEMES = ['database']
|
||||
|
||||
require 'name_part_finder'
|
||||
require 'acts_as_todo_container'
|
||||
require 'todo_list'
|
||||
require 'config'
|
||||
|
||||
ActiveRecord::Base.class_eval do
|
||||
include Tracks::Acts::TodoContainer
|
||||
end
|
||||
|
||||
if (AUTHENTICATION_SCHEMES.include? 'ldap')
|
||||
require 'net/ldap' #requires ruby-net-ldap gem be installed
|
||||
require 'simple_ldap_authenticator'
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ ActiveRecord::Schema.define(:version => 20) 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 "hide", :boolean, :default => false
|
||||
t.column "user_id", :integer, :default => 1
|
||||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
end
|
||||
|
||||
create_table "notes", :force => true do |t|
|
||||
|
|
@ -56,7 +56,7 @@ ActiveRecord::Schema.define(:version => 20) do
|
|||
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 "user_id", :integer, :default => 0, :null => false
|
||||
t.column "description", :text
|
||||
t.column "state", :string, :limit => 20, :default => "active", :null => false
|
||||
end
|
||||
|
|
@ -71,22 +71,22 @@ ActiveRecord::Schema.define(:version => 20) do
|
|||
|
||||
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 "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 "user_id", :integer, :default => 1
|
||||
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, :default => "", :null => false
|
||||
t.column "password", :string, :limit => 40, :default => "", :null => false
|
||||
t.column "login", :string, :limit => 80
|
||||
t.column "password", :string, :limit => 40
|
||||
t.column "word", :string
|
||||
t.column "is_admin", :boolean, :default => false, :null => false
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,76 +0,0 @@
|
|||
module Tracks
|
||||
module Acts #:nodoc:
|
||||
module TodoContainer #:nodoc:
|
||||
|
||||
# This act provides the capabilities for finding todos that belong to the entity
|
||||
|
||||
def self.included(base) #:nodoc:
|
||||
base.extend ActMacro
|
||||
end
|
||||
|
||||
module ActMacro
|
||||
def acts_as_todo_container(opts = {})
|
||||
|
||||
opts[:find_todos_include] = [] unless opts.key?(:find_todos_include)
|
||||
opts[:find_todos_include] = [opts[:find_todos_include]] unless opts[:find_todos_include].is_a?(Array)
|
||||
write_inheritable_attribute :find_todos_include, [base_class.name.singularize.downcase] + opts[:find_todos_include]
|
||||
|
||||
class_inheritable_reader :find_todos_include
|
||||
|
||||
class_eval "include Tracks::Acts::TodoContainer::InstanceMethods"
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def not_done_todos(opts={})
|
||||
@not_done_todos ||= self.find_not_done_todos(opts)
|
||||
end
|
||||
|
||||
def done_todos
|
||||
@done_todos ||= self.find_done_todos
|
||||
end
|
||||
|
||||
def find_not_done_todos(opts={})
|
||||
where_state_sql = "todos.state = 'active'"
|
||||
if opts.has_key?(:include_project_hidden_todos) && (opts[:include_project_hidden_todos] == true)
|
||||
where_state_sql = "(todos.state = 'active' or todos.state = 'project_hidden')"
|
||||
end
|
||||
todos = Todo.find(:all,
|
||||
:conditions => ["todos.#{self.class.base_class.name.singularize.downcase}_id = ? and #{where_state_sql}", id],
|
||||
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
|
||||
:include => find_todos_include)
|
||||
|
||||
end
|
||||
|
||||
def find_done_todos
|
||||
todos = Todo.find(:all, :conditions => ["todos.#{self.class.base_class.name.singularize.downcase}_id = ? AND todos.state = ?", id, "completed"],
|
||||
:order => "completed_at DESC",
|
||||
:include => find_todos_include,
|
||||
:limit => self.user.preference.show_number_completed)
|
||||
end
|
||||
|
||||
def not_done_todo_count(opts={})
|
||||
where_state_sql = "todos.state = 'active'"
|
||||
if opts.has_key?(:include_project_hidden_todos) && (opts[:include_project_hidden_todos] == true)
|
||||
where_state_sql = "(todos.state = 'active' or todos.state = 'project_hidden')"
|
||||
end
|
||||
Todo.count(:conditions => ["todos.#{self.class.base_class.name.singularize.downcase}_id = ? and #{where_state_sql}", id],
|
||||
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
|
||||
:include => find_todos_include)
|
||||
|
||||
end
|
||||
|
||||
def done_todo_count
|
||||
Todo.count(:conditions => ["todos.#{self.class.base_class.name.singularize.downcase}_id = ? AND todos.state = ?", id, "completed"],
|
||||
:order => "completed_at DESC",
|
||||
:include => find_todos_include,
|
||||
:limit => self.user.preference.show_number_completed)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
39
tracks/lib/todo_list.rb
Normal file
39
tracks/lib/todo_list.rb
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
module Tracks
|
||||
module TodoList
|
||||
|
||||
def not_done_todos(opts={})
|
||||
@not_done_todos ||= self.find_not_done_todos(opts)
|
||||
end
|
||||
|
||||
def done_todos
|
||||
@done_todos ||= self.find_done_todos
|
||||
end
|
||||
|
||||
def find_not_done_todos(opts={})
|
||||
self.todos.find(:all, :conditions => not_done_conditions(opts),
|
||||
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC")
|
||||
end
|
||||
|
||||
def not_done_conditions(opts)
|
||||
conditions = ["todos.state = ?", 'active']
|
||||
if opts.has_key?(:include_project_hidden_todos) && (opts[:include_project_hidden_todos] == true)
|
||||
conditions = ["(todos.state = ? or todos.state = ?)", 'active', 'project_hidden']
|
||||
end
|
||||
conditions
|
||||
end
|
||||
|
||||
def find_done_todos
|
||||
self.todos.find(:all, :conditions => ["todos.state = ?", "completed"],
|
||||
:order => "todos.completed_at DESC", :limit => self.user.preference.show_number_completed)
|
||||
end
|
||||
|
||||
def not_done_todo_count(opts={})
|
||||
self.todos.count(not_done_conditions(opts))
|
||||
end
|
||||
|
||||
def done_todo_count
|
||||
self.todos.count_in_state(:completed)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue