mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-28 01:54:07 +01:00
Work in progress: has_many_polymorphs does not work with rails 3.2 because of intrusive changes in rails internals. I think we need to rip out this dependency...
This commit is contained in:
parent
a83c8b3f92
commit
86afd42148
162 changed files with 704 additions and 8724 deletions
|
|
@ -5,19 +5,19 @@ class Context < ActiveRecord::Base
|
|||
has_many :recurring_todos, :dependent => :delete_all
|
||||
belongs_to :user
|
||||
|
||||
named_scope :active, :conditions => { :hide => false }
|
||||
named_scope :hidden, :conditions => { :hide => true }
|
||||
scope :active, :conditions => { :hide => false }
|
||||
scope :hidden, :conditions => { :hide => true }
|
||||
|
||||
acts_as_list :scope => :user, :top_of_list => 0
|
||||
extend NamePartFinder
|
||||
include Tracks::TodoList
|
||||
# extend NamePartFinder
|
||||
# include Tracks::TodoList
|
||||
|
||||
attr_protected :user
|
||||
|
||||
validates_presence_of :name, :message => "context must have a name"
|
||||
validates_length_of :name, :maximum => 255, :message => "context name must be less than 256 characters"
|
||||
validates_uniqueness_of :name, :message => "already exists", :scope => "user_id"
|
||||
validates_does_not_contain :name, :string => ',', :message => "cannot contain the comma (',') character"
|
||||
# validates_does_not_contain :name, :string => ',', :message => "cannot contain the comma (',') character"
|
||||
|
||||
def self.feed_options(user)
|
||||
# TODO: move to view or helper
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ class Project < ActiveRecord::Base
|
|||
belongs_to :default_context, :class_name => "Context", :foreign_key => "default_context_id"
|
||||
belongs_to :user
|
||||
|
||||
named_scope :active, :conditions => { :state => 'active' }
|
||||
named_scope :hidden, :conditions => { :state => 'hidden' }
|
||||
named_scope :completed, :conditions => { :state => 'completed'}
|
||||
named_scope :uncompleted, :conditions => ["NOT(state = ?)", 'completed']
|
||||
scope :active, :conditions => { :state => 'active' }
|
||||
scope :hidden, :conditions => { :state => 'hidden' }
|
||||
scope :completed, :conditions => { :state => 'completed'}
|
||||
scope :uncompleted, :conditions => ["NOT(state = ?)", 'completed']
|
||||
|
||||
validates_presence_of :name
|
||||
validates_length_of :name, :maximum => 255
|
||||
|
|
@ -21,8 +21,8 @@ class Project < ActiveRecord::Base
|
|||
aasm_column :state
|
||||
aasm_initial_state :active
|
||||
|
||||
extend NamePartFinder
|
||||
#include Tracks::TodoList
|
||||
# extend NamePartFinder
|
||||
# include Tracks::TodoList
|
||||
|
||||
aasm_state :active
|
||||
aasm_state :hidden, :enter => :hide_todos, :exit => :unhide_todos
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ class RecurringTodo < ActiveRecord::Base
|
|||
|
||||
include IsTaggable
|
||||
|
||||
named_scope :active, :conditions => { :state => 'active'}
|
||||
named_scope :completed, :conditions => { :state => 'completed'}
|
||||
scope :active, :conditions => { :state => 'active'}
|
||||
scope :completed, :conditions => { :state => 'completed'}
|
||||
|
||||
attr_protected :user
|
||||
|
||||
|
|
|
|||
|
|
@ -23,33 +23,33 @@ class Todo < ActiveRecord::Base
|
|||
:source => :successor, :conditions => ['todos.state = ?', 'pending']
|
||||
|
||||
# scopes for states of this todo
|
||||
named_scope :active, :conditions => { :state => 'active' }
|
||||
named_scope :active_or_hidden, :conditions => ["todos.state = ? OR todos.state = ?", 'active', 'project_hidden']
|
||||
named_scope :not_completed, :conditions => ['NOT (todos.state = ?)', 'completed']
|
||||
named_scope :completed, :conditions => ["NOT (todos.completed_at IS NULL)"]
|
||||
named_scope :deferred, :conditions => ["todos.completed_at IS NULL AND NOT (todos.show_from IS NULL)"]
|
||||
named_scope :blocked, :conditions => ['todos.state = ?', 'pending']
|
||||
named_scope :pending, :conditions => ['todos.state = ?', 'pending']
|
||||
named_scope :deferred_or_blocked, :conditions => ["(todos.completed_at IS NULL AND NOT(todos.show_from IS NULL)) OR (todos.state = ?)", "pending"]
|
||||
named_scope :not_deferred_or_blocked, :conditions => ["(todos.completed_at IS NULL) AND (todos.show_from IS NULL) AND (NOT todos.state = ?)", "pending"]
|
||||
named_scope :hidden,
|
||||
scope :active, :conditions => { :state => 'active' }
|
||||
scope :active_or_hidden, :conditions => ["todos.state = ? OR todos.state = ?", 'active', 'project_hidden']
|
||||
scope :not_completed, :conditions => ['NOT (todos.state = ?)', 'completed']
|
||||
scope :completed, :conditions => ["NOT (todos.completed_at IS NULL)"]
|
||||
scope :deferred, :conditions => ["todos.completed_at IS NULL AND NOT (todos.show_from IS NULL)"]
|
||||
scope :blocked, :conditions => ['todos.state = ?', 'pending']
|
||||
scope :pending, :conditions => ['todos.state = ?', 'pending']
|
||||
scope :deferred_or_blocked, :conditions => ["(todos.completed_at IS NULL AND NOT(todos.show_from IS NULL)) OR (todos.state = ?)", "pending"]
|
||||
scope :not_deferred_or_blocked, :conditions => ["(todos.completed_at IS NULL) AND (todos.show_from IS NULL) AND (NOT todos.state = ?)", "pending"]
|
||||
scope :hidden,
|
||||
:joins => "INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id",
|
||||
:conditions => ["todos.state = ? OR (c_hidden.hide = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?))",
|
||||
'project_hidden', true, 'active', 'deferred', 'pending']
|
||||
named_scope :not_hidden,
|
||||
scope :not_hidden,
|
||||
:joins => "INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id",
|
||||
:conditions => ['NOT(todos.state = ? OR (c_hidden.hide = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?)))',
|
||||
'project_hidden', true, 'active', 'deferred', 'pending']
|
||||
|
||||
# other scopes
|
||||
named_scope :are_due, :conditions => ['NOT (todos.due IS NULL)']
|
||||
named_scope :with_tag, lambda { |tag_id| {:joins => :taggings, :conditions => ["taggings.tag_id = ? ", tag_id] } }
|
||||
named_scope :with_tags, lambda { |tag_ids| {:conditions => ["EXISTS(SELECT * from taggings t WHERE t.tag_id IN (?) AND t.taggable_id=todos.id AND t.taggable_type='Todo')", tag_ids] } }
|
||||
named_scope :of_user, lambda { |user_id| {:conditions => ["todos.user_id = ? ", user_id] } }
|
||||
named_scope :completed_after, lambda { |date| {:conditions => ["todos.completed_at > ?", date] } }
|
||||
named_scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ?", date] } }
|
||||
named_scope :created_after, lambda { |date| {:conditions => ["todos.created_at > ?", date] } }
|
||||
named_scope :created_before, lambda { |date| {:conditions => ["todos.created_at < ?", date] } }
|
||||
scope :are_due, :conditions => ['NOT (todos.due IS NULL)']
|
||||
scope :with_tag, lambda { |tag_id| {:joins => :taggings, :conditions => ["taggings.tag_id = ? ", tag_id] } }
|
||||
scope :with_tags, lambda { |tag_ids| {:conditions => ["EXISTS(SELECT * from taggings t WHERE t.tag_id IN (?) AND t.taggable_id=todos.id AND t.taggable_type='Todo')", tag_ids] } }
|
||||
scope :of_user, lambda { |user_id| {:conditions => ["todos.user_id = ? ", user_id] } }
|
||||
scope :completed_after, lambda { |date| {:conditions => ["todos.completed_at > ?", date] } }
|
||||
scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ?", date] } }
|
||||
scope :created_after, lambda { |date| {:conditions => ["todos.created_at > ?", date] } }
|
||||
scope :created_before, lambda { |date| {:conditions => ["todos.created_at < ?", date] } }
|
||||
|
||||
STARRED_TAG_NAME = "starred"
|
||||
DEFAULT_INCLUDES = [ :project, :context, :tags, :taggings, :pending_successors, :uncompleted_predecessors, :recurring_todo ]
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ class User < ActiveRecord::Base
|
|||
has_many :contexts,
|
||||
:order => 'position ASC',
|
||||
:dependent => :delete_all do
|
||||
def find_by_params(params)
|
||||
find(params['id'] || params['context_id']) || nil
|
||||
end
|
||||
# def find_by_params(params)
|
||||
# find(params['id'] || params['context_id']) || nil
|
||||
# end
|
||||
def update_positions(context_ids)
|
||||
context_ids.each_with_index {|id, position|
|
||||
context = self.detect { |c| c.id == id.to_i }
|
||||
|
|
@ -23,9 +23,9 @@ class User < ActiveRecord::Base
|
|||
has_many :projects,
|
||||
:order => 'projects.position ASC',
|
||||
:dependent => :delete_all do
|
||||
def find_by_params(params)
|
||||
find(params['id'] || params['project_id'])
|
||||
end
|
||||
# def find_by_params(params)
|
||||
# find(params['id'] || params['project_id'])
|
||||
# end
|
||||
def update_positions(project_ids)
|
||||
project_ids.each_with_index {|id, position|
|
||||
project = self.detect { |p| p.id == id.to_i }
|
||||
|
|
@ -100,11 +100,11 @@ class User < ActiveRecord::Base
|
|||
validates_confirmation_of :password
|
||||
validates_length_of :login, :within => 3..80
|
||||
validates_uniqueness_of :login, :on => :create
|
||||
validates_presence_of :open_id_url, :if => :using_openid?
|
||||
# validates_presence_of :open_id_url, :if => :using_openid?
|
||||
|
||||
before_create :crypt_password, :generate_token
|
||||
before_update :crypt_password
|
||||
before_save :normalize_open_id_url
|
||||
# before_save :normalize_open_id_url
|
||||
|
||||
#for will_paginate plugin
|
||||
cattr_accessor :per_page
|
||||
|
|
@ -145,10 +145,10 @@ class User < ActiveRecord::Base
|
|||
return nil
|
||||
end
|
||||
|
||||
def self.find_by_open_id_url(raw_identity_url)
|
||||
normalized_open_id_url = OpenIdAuthentication.normalize_identifier(raw_identity_url)
|
||||
find(:first, :conditions => ['open_id_url = ?', normalized_open_id_url])
|
||||
end
|
||||
# def self.find_by_open_id_url(raw_identity_url)
|
||||
# normalized_open_id_url = OpenIdAuthentication.normalize_identifier(raw_identity_url)
|
||||
# find(:first, :conditions => ['open_id_url = ?', normalized_open_id_url])
|
||||
# end
|
||||
|
||||
def self.no_users_yet?
|
||||
count == 0
|
||||
|
|
@ -192,7 +192,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def generate_token
|
||||
self.token = sha1 "#{Time.now.to_i}#{rand}"
|
||||
self.token = Digest::SHA1.hexdigest "#{Time.now.to_i}#{rand}"
|
||||
end
|
||||
|
||||
def remember_token?
|
||||
|
|
@ -202,14 +202,14 @@ class User < ActiveRecord::Base
|
|||
# These create and unset the fields required for remembering users between browser closes
|
||||
def remember_me
|
||||
self.remember_token_expires_at = 2.weeks.from_now.utc
|
||||
self.remember_token ||= sha1("#{login}--#{remember_token_expires_at}")
|
||||
save(false)
|
||||
self.remember_token ||= Digest::SHA1.hexdigest("#{login}--#{remember_token_expires_at}")
|
||||
save
|
||||
end
|
||||
|
||||
def forget_me
|
||||
self.remember_token_expires_at = nil
|
||||
self.remember_token = nil
|
||||
save(false)
|
||||
save
|
||||
end
|
||||
|
||||
# Returns true if the user has a password hashed using SHA-1.
|
||||
|
|
@ -248,19 +248,19 @@ protected
|
|||
auth_type == 'database' && crypted_password.blank? || !password.blank?
|
||||
end
|
||||
|
||||
def using_openid?
|
||||
auth_type == 'open_id'
|
||||
end
|
||||
|
||||
def normalize_open_id_url
|
||||
return if open_id_url.nil?
|
||||
|
||||
# fixup empty url value
|
||||
if open_id_url.empty?
|
||||
self.open_id_url = nil
|
||||
return
|
||||
end
|
||||
|
||||
self.open_id_url = OpenIdAuthentication.normalize_identifier(open_id_url)
|
||||
end
|
||||
# def using_openid?
|
||||
# auth_type == 'open_id'
|
||||
# end
|
||||
#
|
||||
# def normalize_open_id_url
|
||||
# return if open_id_url.nil?
|
||||
#
|
||||
# # fixup empty url value
|
||||
# if open_id_url.empty?
|
||||
# self.open_id_url = nil
|
||||
# return
|
||||
# end
|
||||
#
|
||||
# self.open_id_url = OpenIdAuthentication.normalize_identifier(open_id_url)
|
||||
# end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue