Removed obsolete code of old workgroup-centric weekly task concept.

This commit is contained in:
Robert Waltemath 2013-06-22 18:14:11 +02:00
parent ef329b5647
commit a7fd7a7936
9 changed files with 2 additions and 147 deletions

View file

@ -6,51 +6,9 @@ class Workgroup < Group
has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC'
validates_uniqueness_of :name
validates_presence_of :task_name, :weekday, :task_required_users, :next_weekly_tasks_number,
:if => :weekly_task
validates_numericality_of :next_weekly_tasks_number, :greater_than => 0, :less_than => 21, :only_integer => true,
:if => :weekly_task
validates_length_of :task_description, maximum: 250
validate :last_admin_on_earth, :on => :update
before_destroy :check_last_admin_group
def self.weekdays
days = I18n.t('date.day_names')
(0..days.length-1).map {|i| [days[i], i.to_s]}
end
# Returns an Array with date-objects to represent the next weekly-tasks
def next_weekly_tasks
# our system starts from 0 (sunday) to 6 (saturday)
# get difference between groups weekday and now
diff = self.weekday - Time.now.wday
if diff >= 0
# weektask is in current week
nextTask = diff.day.from_now
else
# weektask is in the next week
nextTask = (diff + 7).day.from_now
end
# now generate the Array
nextTasks = Array.new
next_weekly_tasks_number.times do
nextTasks << nextTask.to_date
nextTask = 1.week.from_now(nextTask)
end
return nextTasks
end
def task_attributes(date)
{
:name => task_name,
:description => task_description,
:due_date => date,
:required_users => task_required_users,
:duration => task_duration,
:weekly => true
}
end
protected
# Check before destroy a group, if this is the last group with admin role

View file

@ -45,26 +45,6 @@
= f.label :role_orders
%br/
= f.check_box :role_orders
%p
= f.label :weekly_task
%br/
= f.check_box :weekly_task
%p
= f.label :weekday
%br/
= f.text_field :weekday
%p
= f.label :task_name
%br/
= f.text_field :task_name
%p
= f.label :task_description
%br/
= f.text_field :task_description
%p
= f.label :task_required_users
%br/
= f.text_field :task_required_users
%p
= f.label :deleted_at
%br/

View file

@ -12,11 +12,6 @@
%th Role Article Meta
%th Role Finance
%th Role Orders
%th Weekly Task
%th Weekday
%th Task Name
%th Task Description
%th Task Required Users
%th Deleted At
%th Contact Person
%th Contact Phone
@ -34,11 +29,6 @@
%td= h ordergroup.role_article_meta
%td= h ordergroup.role_finance
%td= h ordergroup.role_orders
%td= h ordergroup.weekly_task
%td= h ordergroup.weekday
%td= h ordergroup.task_name
%td= h ordergroup.task_description
%td= h ordergroup.task_required_users
%td= h ordergroup.deleted_at
%td= h ordergroup.contact_person
%td= h ordergroup.contact_phone

View file

@ -13,13 +13,6 @@
- members = group.users
= "(#{members.size})"
= members.collect(&:nick).join(", ")
- if group.is_a?(Workgroup)
%dt= t('.weekly_job') + ':'
%dd
- if group.weekly_task
=h "#{group.task_name} am #{weekday(group.weekday)}"
- else
= t '.no_weekly_job'
- else
- unless group.is_a?(Workgroup)
%dt= t '.apple_limit'
%dd= group.ignore_apple_restriction ? t('.deactivated') : t('.activated')

View file

@ -3,17 +3,6 @@
= yield
- if f.object.is_a?(Workgroup)
%h3= t '.title'
= f.input :weekly_task
#weekly_task_fields
= f.input :weekday, as: :select, collection: Workgroup.weekdays
= f.input :task_name
= f.input :task_required_users
= f.input :task_duration, :as => :select, :collection => (1..3)
= f.input :task_description, as: :text, input_html: {rows: 5}
= f.input :next_weekly_tasks_number
= f.input :user_tokens, :as => :string,
:input_html => { 'data-pre' => f.object.users.map { |u| u.token_attributes }.to_json }

View file

@ -1,16 +1,6 @@
- title t('.title', workgroup: @group.name)
= render 'nav'
%section.well
%h3= t '.weekly.title'
- if @group.weekly_task
= t('.weekly.desc', weekday: weekday(@group.weekday), task: @group.task_name).html_safe
- else
= t('.weekly.empty').html_safe
- if @current_user.member_of?(@group) or @current_user.role_admin?
= link_to t('.weekly.edit'), edit_foodcoop_workgroup_path(@group), class: 'btn'
%section
%h3= t '.title_all'
= render 'list', tasks: @group.open_tasks

View file

@ -45,26 +45,6 @@
= f.label :role_orders
%br/
= f.check_box :role_orders
%p
= f.label :weekly_task
%br/
= f.check_box :weekly_task
%p
= f.label :weekday
%br/
= f.text_field :weekday
%p
= f.label :task_name
%br/
= f.text_field :task_name
%p
= f.label :task_description
%br/
= f.text_field :task_description
%p
= f.label :task_required_users
%br/
= f.text_field :task_required_users
%p
= f.label :deleted_at
%br/

View file

@ -12,11 +12,6 @@
%th Role Article Meta
%th Role Finance
%th Role Orders
%th Weekly Task
%th Weekday
%th Task Name
%th Task Description
%th Task Required Users
%th Deleted At
%th Contact Person
%th Contact Phone
@ -34,11 +29,6 @@
%td= h workgroup.role_article_meta
%td= h workgroup.role_finance
%td= h workgroup.role_orders
%td= h workgroup.weekly_task
%td= h workgroup.weekday
%td= h workgroup.task_name
%td= h workgroup.task_description
%td= h workgroup.task_required_users
%td= h workgroup.deleted_at
%td= h workgroup.contact_person
%td= h workgroup.contact_phone

View file

@ -16,21 +16,6 @@ namespace :foodsoft do
end
end
desc "Create upcoming workgroups tasks (next 3 to 7 weeks)"
task :create_upcoming_weekly_tasks => :environment do
workgroups = Workgroup.where(weekly_task: true)
for workgroup in workgroups
puts "Create weekly tasks for #{workgroup.name}"
# Loop through next tasks weekly tasks method,
# skip the next 3 weeks, to allow manually deleting tasks
workgroup.next_weekly_tasks[3..-1].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 workgroup of upcoming weekly task"
task :notify_users_of_weekly_task => :environment do
for workgroup in Workgroup.all
@ -55,7 +40,7 @@ namespace :foodsoft do
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
while tg.next_task_date.nil? or tg.next_task_date < Date.today + 50
tg.create_next_task
end
end