diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index a96fe528..b9436f65 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -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 diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index 9ddf175a..8b029840 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -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 diff --git a/app/views/tasks/_form.html.haml b/app/views/tasks/_form.html.haml index 4aa53899..0b195ed8 100644 --- a/app/views/tasks/_form.html.haml +++ b/app/views/tasks/_form.html.haml @@ -1,4 +1,5 @@ = form.error_messages += form.hidden_field :weekly %p %b Name %br/ diff --git a/app/views/tasks/workgroup.haml b/app/views/tasks/workgroup.haml index 46ffbfd5..9c7870b0 100644 --- a/app/views/tasks/workgroup.haml +++ b/app/views/tasks/workgroup.haml @@ -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| diff --git a/db/migrate/20090811144901_add_weekly_to_tasks.rb b/db/migrate/20090811144901_add_weekly_to_tasks.rb new file mode 100644 index 00000000..11f1568d --- /dev/null +++ b/db/migrate/20090811144901_add_weekly_to_tasks.rb @@ -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 diff --git a/lib/tasks/foodsoft.rake b/lib/tasks/foodsoft.rake index 2ddd5c72..78ae441b 100644 --- a/lib/tasks/foodsoft.rake +++ b/lib/tasks/foodsoft.rake @@ -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"])