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
|
|
|
|
|
|
|
|
def index
|
2009-01-15 12:14:01 +01:00
|
|
|
@non_group_tasks = Task.non_group
|
2009-02-06 20:51:14 +01:00
|
|
|
@groups = Workgroup.all
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def create
|
|
|
|
@task = Task.new(params[:task])
|
2011-05-14 19:02:52 +02:00
|
|
|
if @task.save
|
|
|
|
redirect_to tasks_url, :notice => "Aufgabe wurde erstellt"
|
2009-01-06 11:49:19 +01:00
|
|
|
else
|
|
|
|
render :template => "tasks/new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@task = Task.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@task = Task.find(params[:id])
|
2012-11-12 09:03:23 +01:00
|
|
|
@task.current_user_id = current_user.id
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@task = Task.find(params[:id])
|
|
|
|
@task.attributes=(params[:task])
|
2012-11-12 21:31:04 +01:00
|
|
|
if @task.errors.empty? && @task.save
|
2009-01-06 11:49:19 +01:00
|
|
|
flash[:notice] = "Aufgabe wurde aktualisiert"
|
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
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
Task.find(params[:id]).destroy
|
2011-05-15 22:06:54 +02:00
|
|
|
redirect_to tasks_url, :notice => "Aufgabe wurde gelöscht"
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# 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
|
2011-05-15 22:06:54 +02:00
|
|
|
redirect_to user_tasks_path, :notice => "Du hast die Aufgabe übernommen"
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# deletes assignment between current_user and given task
|
|
|
|
def reject
|
|
|
|
Task.find(params[:id]).users.delete(current_user)
|
|
|
|
redirect_to :action => "index"
|
|
|
|
end
|
|
|
|
|
2012-10-08 21:52:03 +02:00
|
|
|
def set_done
|
|
|
|
Task.find(params[:id]).update_attribute :done, true
|
2011-05-15 22:06:54 +02:00
|
|
|
redirect_to tasks_url, :notice => "Aufgabenstatus wurde aktualisiert"
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# Shows all tasks, which are already done
|
|
|
|
def archive
|
2012-10-08 21:52:03 +02:00
|
|
|
@tasks = Task.done.page(params[:page]).per(@per_page)
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# 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
|
2011-05-15 22:06:54 +02:00
|
|
|
redirect_to tasks_url, :alert => "Keine Arbeitsgruppe gefunden"
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|