2011-10-08 23:36:38 +02:00
|
|
|
class Admin::ProjectsController < ApplicationController
|
2011-11-02 16:21:17 +01:00
|
|
|
layout "admin"
|
2011-10-08 23:36:38 +02:00
|
|
|
before_filter :authenticate_user!
|
|
|
|
before_filter :authenticate_admin!
|
2012-07-31 07:32:49 +02:00
|
|
|
before_filter :admin_project, :only => [:edit, :show, :update, :destroy, :team_update]
|
2011-10-08 23:36:38 +02:00
|
|
|
|
|
|
|
def index
|
2012-06-21 17:54:57 +02:00
|
|
|
@admin_projects = Project.scoped
|
|
|
|
@admin_projects = @admin_projects.search(params[:name]) if params[:name].present?
|
2012-07-19 06:05:57 +02:00
|
|
|
@admin_projects = @admin_projects.page(params[:page]).per(20)
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2012-07-31 07:32:49 +02:00
|
|
|
@users = User.scoped
|
|
|
|
@users = @users.not_in_project(@admin_project) if @admin_project.users.present?
|
|
|
|
@users = @users.all
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@admin_project = Project.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2012-01-21 17:06:14 +01:00
|
|
|
def team_update
|
2012-07-31 07:32:49 +02:00
|
|
|
@admin_project.add_users_ids_to_team(params[:user_ids], params[:project_access])
|
2012-04-17 19:27:18 +02:00
|
|
|
|
2012-01-21 17:06:14 +01:00
|
|
|
redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
|
|
|
|
end
|
|
|
|
|
2011-10-08 23:36:38 +02:00
|
|
|
def create
|
|
|
|
@admin_project = Project.new(params[:project])
|
2011-10-09 21:36:57 +02:00
|
|
|
@admin_project.owner = current_user
|
2011-10-08 23:36:38 +02:00
|
|
|
|
2011-10-27 15:44:29 +02:00
|
|
|
if @admin_project.save
|
|
|
|
redirect_to [:admin, @admin_project], notice: 'Project was successfully created.'
|
|
|
|
else
|
|
|
|
render :action => "new"
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-02-21 21:46:34 +01:00
|
|
|
owner_id = params[:project].delete(:owner_id)
|
2012-01-29 22:59:12 +01:00
|
|
|
|
|
|
|
if owner_id
|
|
|
|
@admin_project.owner = User.find(owner_id)
|
|
|
|
end
|
|
|
|
|
2011-10-27 15:44:29 +02:00
|
|
|
if @admin_project.update_attributes(params[:project])
|
|
|
|
redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
|
|
|
|
else
|
|
|
|
render :action => "edit"
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@admin_project.destroy
|
|
|
|
|
2012-07-16 14:01:32 +02:00
|
|
|
redirect_to admin_projects_url, notice: 'Project was successfully deleted.'
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
2012-07-31 07:32:49 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def admin_project
|
|
|
|
@admin_project = Project.find_by_code(params[:id])
|
|
|
|
end
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|