Delete only the FOLLOWING tasks.
This commit is contained in:
parent
c52e482743
commit
990397a7f0
6 changed files with 19 additions and 20 deletions
|
@ -1,8 +0,0 @@
|
||||||
class PeriodicTaskGroupsController < ApplicationController
|
|
||||||
def destroy
|
|
||||||
@task_group = PeriodicTaskGroup.find(params[:id])
|
|
||||||
@task_group.destroy
|
|
||||||
|
|
||||||
redirect_to tasks_url, notice: I18n.t('periodic_task_groups.destroy.notice')
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -56,7 +56,12 @@ class TasksController < ApplicationController
|
||||||
task = Task.find(params[:id])
|
task = Task.find(params[:id])
|
||||||
# Save user_ids to update apple statistics after destroy
|
# Save user_ids to update apple statistics after destroy
|
||||||
user_ids = task.user_ids
|
user_ids = task.user_ids
|
||||||
|
if params[:periodic]
|
||||||
|
task.periodic_task_group.exclude_tasks_before(task)
|
||||||
|
task.periodic_task_group.destroy
|
||||||
|
else
|
||||||
task.destroy
|
task.destroy
|
||||||
|
end
|
||||||
task.update_ordergroup_stats(user_ids)
|
task.update_ordergroup_stats(user_ids)
|
||||||
|
|
||||||
redirect_to tasks_url, :notice => I18n.t('tasks.destroy.notice')
|
redirect_to tasks_url, :notice => I18n.t('tasks.destroy.notice')
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
module PeriodicTaskGroupsHelper
|
|
||||||
end
|
|
|
@ -1,23 +1,29 @@
|
||||||
class PeriodicTaskGroup < ActiveRecord::Base
|
class PeriodicTaskGroup < ActiveRecord::Base
|
||||||
has_many :tasks, :dependent => :destroy
|
has_many :tasks, dependent: :destroy
|
||||||
|
|
||||||
PeriodDays = 7
|
PeriodDays = 7
|
||||||
|
|
||||||
def has_next_task?
|
def has_next_task?
|
||||||
return false if self.tasks.empty?
|
return false if tasks.empty?
|
||||||
return false if self.tasks.first.due_date.nil?
|
return false if tasks.first.due_date.nil?
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_next_task
|
def create_next_task
|
||||||
template_task = self.tasks.first
|
template_task = tasks.first
|
||||||
self.next_task_date ||= template_task.due_date + PeriodDays
|
self.next_task_date ||= template_task.due_date + PeriodDays
|
||||||
|
|
||||||
next_task = template_task.dup
|
next_task = template_task.dup
|
||||||
next_task.due_date = self.next_task_date
|
next_task.due_date = next_task_date
|
||||||
next_task.save
|
next_task.save
|
||||||
|
|
||||||
self.next_task_date += PeriodDays
|
self.next_task_date += PeriodDays
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def exclude_tasks_before(task)
|
||||||
|
tasks.where("due_date < '#{task.due_date}'").each do |t|
|
||||||
|
t.update_attribute(:periodic_task_group, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,5 +30,5 @@
|
||||||
= link_to t('ui.delete'), task_path(@task), :method => :delete, :confirm => "Die Aufgabe wirklich löschen?",
|
= link_to t('ui.delete'), task_path(@task), :method => :delete, :confirm => "Die Aufgabe wirklich löschen?",
|
||||||
class: 'btn btn-danger'
|
class: 'btn btn-danger'
|
||||||
- if @task.periodic?
|
- if @task.periodic?
|
||||||
= link_to t('ui.delete_all'), periodic_task_group_path(@task.periodic_task_group), :method => :delete,
|
= link_to 'Aufgabe und folgende löschen', task_path(@task, periodic: true), method: :delete,
|
||||||
:confirm => "Alle Aufgaben dieser wöchentlichen Aufgabe wirklich löschen?", class: 'btn btn-danger'
|
confirm: "Diese und alle folgenden wöchentlichen Aufgaben wirklich löschen?", class: 'btn btn-danger'
|
||||||
|
|
|
@ -70,8 +70,6 @@ Foodsoft::Application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :periodic_task_groups, only: [:destroy]
|
|
||||||
|
|
||||||
resources :messages, :only => [:index, :show, :new, :create]
|
resources :messages, :only => [:index, :show, :new, :create]
|
||||||
|
|
||||||
namespace :foodcoop do
|
namespace :foodcoop do
|
||||||
|
|
Loading…
Reference in a new issue