Added rake task for auto create of upcoming workgroup tasks (weekly tasks).

This commit is contained in:
Benjamin Meichsner 2009-08-11 17:17:18 +02:00
parent 7e2506baa2
commit d8cdbe4abb
6 changed files with 39 additions and 9 deletions

View File

@ -13,11 +13,8 @@ class TasksController < ApplicationController
def new
if params[:id]
group = Group.find(params[:id])
@task = group.tasks.build :name => group.task_name,
:required_users => group.task_required_users,
:description => group.task_description,
:due_date => group.next_weekly_tasks[params[:task_from_now].to_i]
group = Workgroup.find(params[:id])
@task = group.tasks.build(group.task_attributes(group.next_weekly_tasks[params[:task_from_now].to_i]))
else
@task = Task.new
end

View File

@ -55,9 +55,19 @@ class Workgroup < Group
nextTasks = Array.new
number.times do
nextTasks << nextTask
nextTask = 1.week.from_now(nextTask)
nextTask = 1.week.from_now(nextTask).to_date
end
return nextTasks
end
def task_attributes(date)
{
:name => task_name,
:description => task_description,
:due_date => date,
:required_users => task_required_users,
:weekly => true
}
end
end

View File

@ -1,4 +1,5 @@
= form.error_messages
= form.hidden_field :weekly
%p
%b Name
%br/

View File

@ -16,10 +16,10 @@
%th Wer machts?
%th Aufgabe übernehmen
- i = 0
- for next_task in @group.next_weekly_tasks
- for next_date in @group.next_weekly_tasks
%tr{:class => cycle("even","odd")}
%td= I18n.l next_task, :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])
%td= I18n.l next_date, :format => "%a, %d.%m.%Y"
- if task = @group.tasks.find(:first, :conditions => {:due_date => next_date, :weekly => true})
- unless task.users.empty?
- owner = Array.new
- task.assignments.each do |ass|

View 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

View File

@ -39,6 +39,19 @@ namespace :foodsoft do
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"
task :notify_order_finished => :environment do
order = Order.find(ENV["ORDER_ID"])