Skip to content

Commit

Permalink
Allow editing recurring task groups, basic functionality for #152
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert committed May 1, 2015
1 parent 17cbc57 commit fd51b07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/tasks_controller.rb
Expand Up @@ -42,9 +42,11 @@ def edit

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')
Expand Down
14 changes: 14 additions & 0 deletions app/models/periodic_task_group.rb
Expand Up @@ -25,6 +25,20 @@ def exclude_tasks_before(task)
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
Expand Down
2 changes: 1 addition & 1 deletion app/views/tasks/_form.html.haml
Expand Up @@ -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

0 comments on commit fd51b07

Please sign in to comment.