2012-04-16 08:48:01 +02:00
|
|
|
# encoding: utf-8
|
2009-01-06 11:49:19 +01:00
|
|
|
class TasksController < ApplicationController
|
|
|
|
#auto_complete_for :user, :nick
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
def index
|
2016-02-24 20:58:32 +01:00
|
|
|
@non_group_tasks = Task.non_group.order('due_date', 'name').includes(assignments: :user)
|
2017-08-11 04:14:57 +02:00
|
|
|
@groups = Workgroup.order(:name).includes(open_tasks: {assignments: :user})
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2010-03-20 13:45:58 +01:00
|
|
|
def user
|
2012-11-12 09:03:23 +01:00
|
|
|
@unaccepted_tasks = Task.unaccepted_tasks_for(current_user)
|
|
|
|
@accepted_tasks = Task.accepted_tasks_for(current_user)
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
def new
|
2012-11-12 09:03:23 +01:00
|
|
|
@task = Task.new(current_user_id: current_user.id)
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
def create
|
2020-02-18 19:04:46 +01:00
|
|
|
@task = Task.new(current_user_id: current_user.id)
|
2020-03-06 13:04:03 +01:00
|
|
|
@task.created_by = current_user
|
2020-02-18 19:04:46 +01:00
|
|
|
@task.attributes=(task_params)
|
2013-06-21 13:48:48 +02:00
|
|
|
if params[:periodic]
|
|
|
|
@task.periodic_task_group = PeriodicTaskGroup.new
|
|
|
|
end
|
2011-05-14 19:02:52 +02:00
|
|
|
if @task.save
|
2016-02-24 20:47:09 +01:00
|
|
|
@task.periodic_task_group.create_tasks_for_upfront_days if params[:periodic]
|
2013-04-12 00:00:02 +02:00
|
|
|
redirect_to tasks_url, :notice => I18n.t('tasks.create.notice')
|
2009-01-06 11:49:19 +01:00
|
|
|
else
|
|
|
|
render :template => "tasks/new"
|
|
|
|
end
|
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
def show
|
|
|
|
@task = Task.find(params[:id])
|
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
def edit
|
|
|
|
@task = Task.find(params[:id])
|
2015-05-08 17:39:20 +02:00
|
|
|
@periodic = !!params[:periodic]
|
2012-11-12 09:03:23 +01:00
|
|
|
@task.current_user_id = current_user.id
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
def update
|
|
|
|
@task = Task.find(params[:id])
|
2015-05-01 21:14:16 +02:00
|
|
|
task_group = @task.periodic_task_group
|
2013-07-11 10:30:55 +02:00
|
|
|
was_periodic = @task.periodic?
|
2015-05-01 21:31:06 +02:00
|
|
|
prev_due_date = @task.due_date
|
2019-10-29 15:16:43 +01:00
|
|
|
@task.current_user_id = current_user.id
|
2020-02-18 19:04:46 +01:00
|
|
|
@task.attributes=(task_params)
|
2012-11-12 21:31:04 +01:00
|
|
|
if @task.errors.empty? && @task.save
|
2015-05-01 21:31:06 +02:00
|
|
|
task_group.update_tasks_including(@task, prev_due_date) if params[:periodic]
|
2013-04-12 00:00:02 +02:00
|
|
|
flash[:notice] = I18n.t('tasks.update.notice')
|
2015-01-14 22:56:32 +01:00
|
|
|
if was_periodic && !@task.periodic?
|
2013-07-11 10:30:55 +02:00
|
|
|
flash[:notice] = I18n.t('tasks.update.notice_converted')
|
|
|
|
end
|
2009-01-15 12:14:01 +01:00
|
|
|
if @task.workgroup
|
2012-08-24 11:11:40 +02:00
|
|
|
redirect_to workgroup_tasks_url(workgroup_id: @task.workgroup_id)
|
2009-01-06 11:49:19 +01:00
|
|
|
else
|
2012-08-24 11:11:40 +02:00
|
|
|
redirect_to tasks_url
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
render :template => "tasks/edit"
|
|
|
|
end
|
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
def destroy
|
2012-12-16 19:03:04 +01:00
|
|
|
task = Task.find(params[:id])
|
|
|
|
# Save user_ids to update apple statistics after destroy
|
|
|
|
user_ids = task.user_ids
|
2013-06-21 22:04:36 +02:00
|
|
|
if params[:periodic]
|
|
|
|
task.periodic_task_group.exclude_tasks_before(task)
|
|
|
|
task.periodic_task_group.destroy
|
|
|
|
else
|
|
|
|
task.destroy
|
|
|
|
end
|
2012-12-16 19:03:04 +01:00
|
|
|
task.update_ordergroup_stats(user_ids)
|
|
|
|
|
2013-04-12 00:00:02 +02:00
|
|
|
redirect_to tasks_url, :notice => I18n.t('tasks.destroy.notice')
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# assign current_user to the task and set the assignment to "accepted"
|
|
|
|
# if there is already an assignment, only accepted will be set to true
|
|
|
|
def accept
|
|
|
|
task = Task.find(params[:id])
|
|
|
|
if ass = task.is_assigned?(current_user)
|
|
|
|
ass.update_attribute(:accepted, true)
|
|
|
|
else
|
|
|
|
task.assignments.create(:user => current_user, :accepted => true)
|
|
|
|
end
|
2013-04-12 00:00:02 +02:00
|
|
|
redirect_to user_tasks_path, :notice => I18n.t('tasks.accept.notice')
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2020-02-18 19:04:46 +01:00
|
|
|
# deletes assignment between current_user and given taskcurrent_user_id: current_user.id
|
2009-01-06 11:49:19 +01:00
|
|
|
def reject
|
|
|
|
Task.find(params[:id]).users.delete(current_user)
|
|
|
|
redirect_to :action => "index"
|
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2012-10-08 21:52:03 +02:00
|
|
|
def set_done
|
|
|
|
Task.find(params[:id]).update_attribute :done, true
|
2013-04-12 00:00:02 +02:00
|
|
|
redirect_to tasks_url, :notice => I18n.t('tasks.set_done.notice')
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Shows all tasks, which are already done
|
|
|
|
def archive
|
2012-12-16 19:03:04 +01:00
|
|
|
@tasks = Task.done.page(params[:page]).per(@per_page).order('tasks.updated_on DESC').includes(assignments: :user)
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2015-05-08 17:39:20 +02:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# shows workgroup (normal group) to edit weekly_tasks_template
|
|
|
|
def workgroup
|
2012-08-24 11:11:40 +02:00
|
|
|
@group = Group.find(params[:workgroup_id])
|
2009-01-14 12:46:01 +01:00
|
|
|
if @group.is_a? Ordergroup
|
2013-04-12 01:08:35 +02:00
|
|
|
redirect_to tasks_url, :alert => I18n.t('tasks.error_not_found')
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
end
|
2019-10-29 15:16:43 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def task_params
|
|
|
|
params
|
|
|
|
.require(:task)
|
2020-02-18 19:04:46 +01:00
|
|
|
.permit(:name, :description, :duration, :user_list, :required_users, :workgroup_id, :due_date, :done)
|
2019-10-29 15:16:43 +01:00
|
|
|
end
|
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|