Allow editing recurring task groups, basic functionality for #152
This commit is contained in:
parent
17cbc57850
commit
fd51b07e21
3 changed files with 17 additions and 1 deletions
|
@ -42,9 +42,11 @@ class TasksController < ApplicationController
|
|||
|
||||
def update
|
||||
@task = Task.find(params[:id])
|
||||
task_group = @task.periodic_task_group
|
||||
was_periodic = @task.periodic?
|
||||
@task.attributes=(params[:task])
|
||||
if @task.errors.empty? && @task.save
|
||||
task_group.update_tasks_including(@task) if params[:periodic]
|
||||
flash[:notice] = I18n.t('tasks.update.notice')
|
||||
if was_periodic && !@task.periodic?
|
||||
flash[:notice] = I18n.t('tasks.update.notice_converted')
|
||||
|
|
|
@ -25,6 +25,20 @@ class PeriodicTaskGroup < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def update_tasks_including(template_task)
|
||||
group_tasks = tasks + [template_task]
|
||||
tasks.each do |task|
|
||||
task.update!(name: template_task.name,
|
||||
description: template_task.description,
|
||||
duration: template_task.duration,
|
||||
required_users: template_task.required_users,
|
||||
workgroup: template_task.workgroup)
|
||||
end
|
||||
group_tasks.each do |task|
|
||||
task.update_columns(periodic_task_group_id: self.id)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# @return [Number] Number of days between two periodic tasks
|
||||
|
|
|
@ -26,6 +26,6 @@
|
|||
= f.input :done
|
||||
.form-actions
|
||||
= f.submit class: 'btn btn-primary'
|
||||
- if @task.new_record?
|
||||
- if @task.new_record? or @task.periodic?
|
||||
= f.submit t('.submit.periodic'), name: 'periodic', class: 'btn'
|
||||
= link_to t('ui.or_cancel'), :back
|
||||
|
|
Loading…
Reference in a new issue