Merge pull request #331 from foodcoops/feature/configure-upfront-tasks
Configure upfront tasks
This commit is contained in:
commit
cee2ac8f9f
11 changed files with 46 additions and 44 deletions
|
|
@ -1,8 +1,6 @@
|
|||
class PeriodicTaskGroup < ActiveRecord::Base
|
||||
has_many :tasks, dependent: :destroy
|
||||
|
||||
PeriodDays = 7
|
||||
|
||||
def has_next_task?
|
||||
return false if tasks.empty?
|
||||
return false if tasks.first.due_date.nil?
|
||||
|
|
@ -11,13 +9,13 @@ class PeriodicTaskGroup < ActiveRecord::Base
|
|||
|
||||
def create_next_task
|
||||
template_task = tasks.first
|
||||
self.next_task_date ||= template_task.due_date + PeriodDays
|
||||
self.next_task_date ||= template_task.due_date + period_days
|
||||
|
||||
next_task = template_task.dup
|
||||
next_task.due_date = next_task_date
|
||||
next_task.save
|
||||
|
||||
self.next_task_date += PeriodDays
|
||||
self.next_task_date += period_days
|
||||
self.save
|
||||
end
|
||||
|
||||
|
|
@ -26,4 +24,12 @@ class PeriodicTaskGroup < ActiveRecord::Base
|
|||
t.update_attribute(:periodic_task_group, nil)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# @return [Number] Number of days between two periodic tasks
|
||||
def period_days
|
||||
# minimum of one to avoid inifite loop when value is invalid
|
||||
[FoodsoftConfig[:tasks_period_days].to_i, 1].max
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ class Task < ActiveRecord::Base
|
|||
end
|
||||
|
||||
|
||||
# find all tasks in the next week (or another number of days)
|
||||
def self.next_assigned_tasks_for(user, number = 7)
|
||||
# find all tasks in the period (or another number of days)
|
||||
def self.next_assigned_tasks_for(user, number = FoodsoftConfig[:tasks_period_days].to_i)
|
||||
user.tasks.undone.where(assignments: {accepted: true}).
|
||||
where(["tasks.due_date >= ? AND tasks.due_date <= ?", Time.now, number.days.from_now])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
-#= config_use_heading form, :use_tasks do
|
||||
%fieldset
|
||||
%label
|
||||
%h4= t '.periodic_title'
|
||||
= config_input form, :tasks_period_days do
|
||||
.input-append
|
||||
= config_input_field form, :tasks_period_days, as: :numeric, class: 'input-mini'
|
||||
%span.add-on days
|
||||
= config_input form, :tasks_upfront_days do
|
||||
.input-append
|
||||
= config_input_field form, :tasks_upfront_days, as: :numeric, class: 'input-mini'
|
||||
%span.add-on days
|
||||
|
||||
= config_use_heading form, :use_apple_points do
|
||||
= config_input form, :stop_ordering_under, as: :numeric, input_html: {class: 'input-small'}
|
||||
|
|
|
|||
|
|
@ -8,22 +8,7 @@
|
|||
|
||||
- content_for :javascript do
|
||||
:javascript
|
||||
function toggleWeeklyTaskFields() {
|
||||
if ($('#workgroup_weekly_task').is(':checked')) {
|
||||
$('#weekly_task_fields .control-group').show();
|
||||
$('#weekly_task_fields input').removeAttr('disabled');
|
||||
} else {
|
||||
$('#weekly_task_fields .control-group').hide();
|
||||
$('#weekly_task_fields input').attr('disabled', 'disabled');
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
toggleWeeklyTaskFields();
|
||||
$('#workgroup_weekly_task').click(function() {
|
||||
toggleWeeklyTaskFields();
|
||||
});
|
||||
|
||||
$("##{f.object.class.to_s.underscore}_user_tokens").tokenInput("#{users_path(:format => :json)}", {
|
||||
crossDomain: false,
|
||||
prePopulate: $("##{f.object.class.to_s.underscore}_user_tokens").data("pre"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue