Merge commit '1cdb9e8501' into rails3-multiple-recurring-tasks
Conflicts: Gemfile db/schema.rb
This commit is contained in:
commit
981944b869
7 changed files with 75 additions and 3 deletions
23
app/models/periodic_task_group.rb
Normal file
23
app/models/periodic_task_group.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class PeriodicTaskGroup < ActiveRecord::Base
|
||||
has_many :tasks, :inverse_of => :periodic_task_group, :dependent => :destroy
|
||||
|
||||
PeriodDays = 7
|
||||
|
||||
def has_next_task?
|
||||
return false if self.tasks.empty?
|
||||
return false if self.tasks.first.due_date.nil?
|
||||
return true
|
||||
end
|
||||
|
||||
def create_next_task
|
||||
template_task = self.tasks.first
|
||||
self.next_task_date ||= template_task.due_date + PeriodDays
|
||||
|
||||
next_task = template_task.dup
|
||||
next_task.due_date = self.next_task_date
|
||||
next_task.save
|
||||
|
||||
self.next_task_date += PeriodDays
|
||||
self.save
|
||||
end
|
||||
end
|
||||
|
|
@ -2,6 +2,7 @@ class Task < ActiveRecord::Base
|
|||
has_many :assignments, :dependent => :destroy
|
||||
has_many :users, :through => :assignments
|
||||
belongs_to :workgroup
|
||||
belongs_to :periodic_task_group, :inverse_of => :tasks
|
||||
|
||||
scope :non_group, where(workgroup_id: nil, done: false)
|
||||
scope :done, where(done: true)
|
||||
|
|
@ -46,6 +47,14 @@ class Task < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def periodic
|
||||
not periodic_task_group.nil?
|
||||
end
|
||||
|
||||
def periodic=(p)
|
||||
self.periodic_task_group = PeriodicTaskGroup.new if p == "1"
|
||||
end
|
||||
|
||||
def is_assigned?(user)
|
||||
self.assignments.detect {|ass| ass.user_id == user.id }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
= f.input :required_users
|
||||
= f.association :workgroup
|
||||
= f.input :due_date, as: :date_picker
|
||||
= f.input :periodic, as: :boolean
|
||||
= f.input :done
|
||||
.form-actions
|
||||
= f.submit class: 'btn'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue