Added rake task for auto create of upcoming workgroup tasks (weekly tasks).
This commit is contained in:
parent
7e2506baa2
commit
d8cdbe4abb
6 changed files with 39 additions and 9 deletions
|
@ -13,11 +13,8 @@ class TasksController < ApplicationController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
if params[:id]
|
if params[:id]
|
||||||
group = Group.find(params[:id])
|
group = Workgroup.find(params[:id])
|
||||||
@task = group.tasks.build :name => group.task_name,
|
@task = group.tasks.build(group.task_attributes(group.next_weekly_tasks[params[:task_from_now].to_i]))
|
||||||
:required_users => group.task_required_users,
|
|
||||||
:description => group.task_description,
|
|
||||||
:due_date => group.next_weekly_tasks[params[:task_from_now].to_i]
|
|
||||||
else
|
else
|
||||||
@task = Task.new
|
@task = Task.new
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,9 +55,19 @@ class Workgroup < Group
|
||||||
nextTasks = Array.new
|
nextTasks = Array.new
|
||||||
number.times do
|
number.times do
|
||||||
nextTasks << nextTask
|
nextTasks << nextTask
|
||||||
nextTask = 1.week.from_now(nextTask)
|
nextTask = 1.week.from_now(nextTask).to_date
|
||||||
end
|
end
|
||||||
return nextTasks
|
return nextTasks
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def task_attributes(date)
|
||||||
|
{
|
||||||
|
:name => task_name,
|
||||||
|
:description => task_description,
|
||||||
|
:due_date => date,
|
||||||
|
:required_users => task_required_users,
|
||||||
|
:weekly => true
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
= form.error_messages
|
= form.error_messages
|
||||||
|
= form.hidden_field :weekly
|
||||||
%p
|
%p
|
||||||
%b Name
|
%b Name
|
||||||
%br/
|
%br/
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
%th Wer machts?
|
%th Wer machts?
|
||||||
%th Aufgabe übernehmen
|
%th Aufgabe übernehmen
|
||||||
- i = 0
|
- i = 0
|
||||||
- for next_task in @group.next_weekly_tasks
|
- for next_date in @group.next_weekly_tasks
|
||||||
%tr{:class => cycle("even","odd")}
|
%tr{:class => cycle("even","odd")}
|
||||||
%td= I18n.l next_task, :format => "%a, %d.%m.%Y"
|
%td= I18n.l next_date, :format => "%a, %d.%m.%Y"
|
||||||
- if task = @group.tasks.find(:first, :conditions => ["due_date = ? AND name = ?",next_task.strftime("%Y-%m-%d"),@group.task_name])
|
- if task = @group.tasks.find(:first, :conditions => {:due_date => next_date, :weekly => true})
|
||||||
- unless task.users.empty?
|
- unless task.users.empty?
|
||||||
- owner = Array.new
|
- owner = Array.new
|
||||||
- task.assignments.each do |ass|
|
- task.assignments.each do |ass|
|
||||||
|
|
9
db/migrate/20090811144901_add_weekly_to_tasks.rb
Normal file
9
db/migrate/20090811144901_add_weekly_to_tasks.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
class AddWeeklyToTasks < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column :tasks, :weekly, :boolean
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_column :tasks, :weekly
|
||||||
|
end
|
||||||
|
end
|
|
@ -39,6 +39,19 @@ namespace :foodsoft do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Create upcoming workgroups tasks (next 3 to 7 weeks)"
|
||||||
|
task :create_upcoming_weekly_tasks => :environment do
|
||||||
|
workgroups = Workgroup.all :conditions => {:weekly_task => true}
|
||||||
|
for workgroup in workgroups
|
||||||
|
puts "Create weekly tasks for #{workgroup.name}"
|
||||||
|
workgroup.next_weekly_tasks(8)[3..7].each do |date|
|
||||||
|
unless workgroup.tasks.exists?({:due_date => date, :weekly => true})
|
||||||
|
workgroup.tasks.create(workgroup.task_attributes(date))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
desc "Notify users of finished orders"
|
desc "Notify users of finished orders"
|
||||||
task :notify_order_finished => :environment do
|
task :notify_order_finished => :environment do
|
||||||
order = Order.find(ENV["ORDER_ID"])
|
order = Order.find(ENV["ORDER_ID"])
|
||||||
|
|
Loading…
Reference in a new issue