Allow changing number of automaticly created next weekly tasks.
This commit is contained in:
parent
ca68091914
commit
7d54a416df
5 changed files with 35 additions and 19 deletions
|
@ -4,15 +4,17 @@ class Workgroup < Group
|
||||||
# returns all non-finished tasks
|
# returns all non-finished tasks
|
||||||
has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC'
|
has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC'
|
||||||
|
|
||||||
validates_presence_of :task_name, :weekday, :task_required_users,
|
validates_presence_of :task_name, :weekday, :task_required_users, :next_weekly_tasks_number,
|
||||||
:if => Proc.new {|workgroup| workgroup.weekly_task }
|
:if => :weekly_task
|
||||||
|
validates_numericality_of :next_weekly_tasks_number, :greater_than => 0, :less_than => 21, :only_integer => true,
|
||||||
|
:if => :weekly_task
|
||||||
|
|
||||||
def self.weekdays
|
def self.weekdays
|
||||||
[["Montag", "1"], ["Dienstag", "2"], ["Mittwoch","3"],["Donnerstag","4"],["Freitag","5"],["Samstag","6"],["Sonntag","0"]]
|
[["Montag", "1"], ["Dienstag", "2"], ["Mittwoch","3"],["Donnerstag","4"],["Freitag","5"],["Samstag","6"],["Sonntag","0"]]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an Array with date-objects to represent the next weekly-tasks
|
# Returns an Array with date-objects to represent the next weekly-tasks
|
||||||
def next_weekly_tasks(number = 8)
|
def next_weekly_tasks
|
||||||
# our system starts from 0 (sunday) to 6 (saturday)
|
# our system starts from 0 (sunday) to 6 (saturday)
|
||||||
# get difference between groups weekday and now
|
# get difference between groups weekday and now
|
||||||
diff = self.weekday - Time.now.wday
|
diff = self.weekday - Time.now.wday
|
||||||
|
@ -25,7 +27,7 @@ class Workgroup < Group
|
||||||
end
|
end
|
||||||
# now generate the Array
|
# now generate the Array
|
||||||
nextTasks = Array.new
|
nextTasks = Array.new
|
||||||
number.times do
|
next_weekly_tasks_number.times do
|
||||||
nextTasks << nextTask.to_date
|
nextTasks << nextTask.to_date
|
||||||
nextTask = 1.week.from_now(nextTask)
|
nextTask = 1.week.from_now(nextTask)
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,6 +39,10 @@
|
||||||
%td
|
%td
|
||||||
= @form.label :task_description, "Beschreibung:"
|
= @form.label :task_description, "Beschreibung:"
|
||||||
%td= @form.text_area :task_description, :size => "30x10"
|
%td= @form.text_area :task_description, :size => "30x10"
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
= @form.label :next_weekly_tasks_number, "Für wieviel Wochen im Voraus sollen Aufgaben erstellt werden?"
|
||||||
|
%td= @form.text_field :next_weekly_tasks_number, :size => 3
|
||||||
|
|
||||||
%script{ 'type' => "text/javascript"}
|
%script{ 'type' => "text/javascript"}
|
||||||
:plain
|
:plain
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
class AddNextWeeklyTasksNumberToWorkgroups < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column :groups, :next_weekly_tasks_number, :integer, :default => 8
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_column :groups, :next_weekly_tasks_number
|
||||||
|
end
|
||||||
|
end
|
27
db/schema.rb
27
db/schema.rb
|
@ -9,7 +9,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20110507192928) do
|
ActiveRecord::Schema.define(:version => 20120622094337) do
|
||||||
|
|
||||||
create_table "article_categories", :force => true do |t|
|
create_table "article_categories", :force => true do |t|
|
||||||
t.string "name", :default => "", :null => false
|
t.string "name", :default => "", :null => false
|
||||||
|
@ -129,28 +129,29 @@ ActiveRecord::Schema.define(:version => 20110507192928) do
|
||||||
add_index "group_orders", ["ordergroup_id"], :name => "index_group_orders_on_ordergroup_id"
|
add_index "group_orders", ["ordergroup_id"], :name => "index_group_orders_on_ordergroup_id"
|
||||||
|
|
||||||
create_table "groups", :force => true do |t|
|
create_table "groups", :force => true do |t|
|
||||||
t.string "type", :default => "", :null => false
|
t.string "type", :default => "", :null => false
|
||||||
t.string "name", :default => "", :null => false
|
t.string "name", :default => "", :null => false
|
||||||
t.string "description"
|
t.string "description"
|
||||||
t.decimal "account_balance", :precision => 8, :scale => 2, :default => 0.0, :null => false
|
t.decimal "account_balance", :precision => 8, :scale => 2, :default => 0.0, :null => false
|
||||||
t.datetime "account_updated"
|
t.datetime "account_updated"
|
||||||
t.datetime "created_on", :null => false
|
t.datetime "created_on", :null => false
|
||||||
t.boolean "role_admin", :default => false, :null => false
|
t.boolean "role_admin", :default => false, :null => false
|
||||||
t.boolean "role_suppliers", :default => false, :null => false
|
t.boolean "role_suppliers", :default => false, :null => false
|
||||||
t.boolean "role_article_meta", :default => false, :null => false
|
t.boolean "role_article_meta", :default => false, :null => false
|
||||||
t.boolean "role_finance", :default => false, :null => false
|
t.boolean "role_finance", :default => false, :null => false
|
||||||
t.boolean "role_orders", :default => false, :null => false
|
t.boolean "role_orders", :default => false, :null => false
|
||||||
t.boolean "weekly_task", :default => false
|
t.boolean "weekly_task", :default => false
|
||||||
t.integer "weekday"
|
t.integer "weekday"
|
||||||
t.string "task_name"
|
t.string "task_name"
|
||||||
t.string "task_description"
|
t.string "task_description"
|
||||||
t.integer "task_required_users", :default => 1
|
t.integer "task_required_users", :default => 1
|
||||||
t.datetime "deleted_at"
|
t.datetime "deleted_at"
|
||||||
t.string "contact_person"
|
t.string "contact_person"
|
||||||
t.string "contact_phone"
|
t.string "contact_phone"
|
||||||
t.string "contact_address"
|
t.string "contact_address"
|
||||||
t.text "stats"
|
t.text "stats"
|
||||||
t.integer "task_duration", :default => 1
|
t.integer "task_duration", :default => 1
|
||||||
|
t.integer "next_weekly_tasks_number", :default => 8
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "groups", ["name"], :name => "index_groups_on_name", :unique => true
|
add_index "groups", ["name"], :name => "index_groups_on_name", :unique => true
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace :foodsoft do
|
||||||
workgroups = Workgroup.all :conditions => {:weekly_task => true}
|
workgroups = Workgroup.all :conditions => {:weekly_task => true}
|
||||||
for workgroup in workgroups
|
for workgroup in workgroups
|
||||||
puts "Create weekly tasks for #{workgroup.name}"
|
puts "Create weekly tasks for #{workgroup.name}"
|
||||||
workgroup.next_weekly_tasks(8)[3..5].each do |date|
|
workgroup.next_weekly_tasks[3..5].each do |date|
|
||||||
unless workgroup.tasks.exists?({:due_date => date, :weekly => true})
|
unless workgroup.tasks.exists?({:due_date => date, :weekly => true})
|
||||||
workgroup.tasks.create(workgroup.task_attributes(date))
|
workgroup.tasks.create(workgroup.task_attributes(date))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue