Merge commit '1cdb9e85017a17e4dbee276cd87feaa2aab75932' 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 :assignments, :dependent => :destroy
|
||||||
has_many :users, :through => :assignments
|
has_many :users, :through => :assignments
|
||||||
belongs_to :workgroup
|
belongs_to :workgroup
|
||||||
|
belongs_to :periodic_task_group, :inverse_of => :tasks
|
||||||
|
|
||||||
scope :non_group, where(workgroup_id: nil, done: false)
|
scope :non_group, where(workgroup_id: nil, done: false)
|
||||||
scope :done, where(done: true)
|
scope :done, where(done: true)
|
||||||
|
@ -46,6 +47,14 @@ class Task < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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)
|
def is_assigned?(user)
|
||||||
self.assignments.detect {|ass| ass.user_id == user.id }
|
self.assignments.detect {|ass| ass.user_id == user.id }
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
= f.input :required_users
|
= f.input :required_users
|
||||||
= f.association :workgroup
|
= f.association :workgroup
|
||||||
= f.input :due_date, as: :date_picker
|
= f.input :due_date, as: :date_picker
|
||||||
|
= f.input :periodic, as: :boolean
|
||||||
= f.input :done
|
= f.input :done
|
||||||
.form-actions
|
.form-actions
|
||||||
= f.submit class: 'btn'
|
= f.submit class: 'btn'
|
||||||
|
|
|
@ -324,6 +324,7 @@ de:
|
||||||
required_users: 'Anzahl'
|
required_users: 'Anzahl'
|
||||||
due_date: 'Wann erledigen?'
|
due_date: 'Wann erledigen?'
|
||||||
workgroup: 'Arbeitsgruppe'
|
workgroup: 'Arbeitsgruppe'
|
||||||
|
periodic: 'Wöchentlich wiederholen'
|
||||||
done: Erledigt?
|
done: Erledigt?
|
||||||
message:
|
message:
|
||||||
sent_to_all: 'An alle Mitglieder schicken'
|
sent_to_all: 'An alle Mitglieder schicken'
|
||||||
|
|
13
db/migrate/20121115073715_create_periodic_task_groups.rb
Normal file
13
db/migrate/20121115073715_create_periodic_task_groups.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
class CreatePeriodicTaskGroups < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :periodic_task_groups do |t|
|
||||||
|
t.date :next_task_date
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
change_table :tasks do |t|
|
||||||
|
t.references :periodic_task_group
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
14
db/schema.rb
14
db/schema.rb
|
@ -268,6 +268,12 @@ ActiveRecord::Schema.define(:version => 20121230142516) do
|
||||||
add_index "pages", ["permalink"], :name => "index_pages_on_permalink"
|
add_index "pages", ["permalink"], :name => "index_pages_on_permalink"
|
||||||
add_index "pages", ["title"], :name => "index_pages_on_title"
|
add_index "pages", ["title"], :name => "index_pages_on_title"
|
||||||
|
|
||||||
|
create_table "periodic_task_groups", :force => true do |t|
|
||||||
|
t.date "next_task_date"
|
||||||
|
t.datetime "created_at", :null => false
|
||||||
|
t.datetime "updated_at", :null => false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "stock_changes", :force => true do |t|
|
create_table "stock_changes", :force => true do |t|
|
||||||
t.integer "delivery_id"
|
t.integer "delivery_id"
|
||||||
t.integer "order_id"
|
t.integer "order_id"
|
||||||
|
@ -313,11 +319,19 @@ ActiveRecord::Schema.define(:version => 20121230142516) do
|
||||||
t.date "due_date"
|
t.date "due_date"
|
||||||
t.boolean "done", :default => false
|
t.boolean "done", :default => false
|
||||||
t.integer "workgroup_id"
|
t.integer "workgroup_id"
|
||||||
|
<<<<<<< HEAD
|
||||||
t.datetime "created_on", :null => false
|
t.datetime "created_on", :null => false
|
||||||
t.datetime "updated_on", :null => false
|
t.datetime "updated_on", :null => false
|
||||||
t.integer "required_users", :default => 1
|
t.integer "required_users", :default => 1
|
||||||
|
=======
|
||||||
|
t.boolean "assigned", :default => false
|
||||||
|
t.datetime "created_on", :null => false
|
||||||
|
t.datetime "updated_on", :null => false
|
||||||
|
t.integer "required_users", :default => 1
|
||||||
|
>>>>>>> 1cdb9e85017a17e4dbee276cd87feaa2aab75932
|
||||||
t.boolean "weekly"
|
t.boolean "weekly"
|
||||||
t.integer "duration", :default => 1
|
t.integer "duration", :default => 1
|
||||||
|
t.integer "periodic_task_group_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "tasks", ["due_date"], :name => "index_tasks_on_due_date"
|
add_index "tasks", ["due_date"], :name => "index_tasks_on_due_date"
|
||||||
|
|
|
@ -51,4 +51,15 @@ namespace :foodsoft do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Create upcoming periodic tasks"
|
||||||
|
task :create_upcoming_periodic_tasks => :environment do
|
||||||
|
for tg in PeriodicTaskGroup.all
|
||||||
|
if tg.has_next_task?
|
||||||
|
while tg.next_task_date.nil? or tg.next_task_date < Date.today + 30
|
||||||
|
tg.create_next_task
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue