2011-10-08 17:36:38 -04:00
|
|
|
class Admin::ProjectsController < ApplicationController
|
2011-11-02 11:21:17 -04:00
|
|
|
layout "admin"
|
2011-10-08 17:36:38 -04:00
|
|
|
before_filter :authenticate_user!
|
|
|
|
before_filter :authenticate_admin!
|
|
|
|
|
|
|
|
def index
|
2012-06-21 11:54:57 -04:00
|
|
|
@admin_projects = Project.scoped
|
|
|
|
@admin_projects = @admin_projects.search(params[:name]) if params[:name].present?
|
|
|
|
@admin_projects = @admin_projects.page(params[:page])
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@admin_project = Project.find_by_code(params[:id])
|
2012-01-21 12:03:47 -05:00
|
|
|
|
|
|
|
@users = if @admin_project.users.empty?
|
|
|
|
User
|
|
|
|
else
|
|
|
|
User.not_in_project(@admin_project)
|
|
|
|
end.all
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@admin_project = Project.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@admin_project = Project.find_by_code(params[:id])
|
|
|
|
end
|
|
|
|
|
2012-01-21 11:06:14 -05:00
|
|
|
def team_update
|
|
|
|
@admin_project = Project.find_by_code(params[:id])
|
|
|
|
|
|
|
|
UsersProject.bulk_import(
|
|
|
|
@admin_project,
|
|
|
|
params[:user_ids],
|
2012-03-05 17:26:40 -05:00
|
|
|
params[:project_access]
|
2012-01-21 11:06:14 -05:00
|
|
|
)
|
|
|
|
|
2012-04-17 13:27:18 -04:00
|
|
|
@admin_project.update_repository
|
|
|
|
|
2012-01-21 11:06:14 -05:00
|
|
|
redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
|
|
|
|
end
|
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
def create
|
|
|
|
@admin_project = Project.new(params[:project])
|
2011-10-09 15:36:57 -04:00
|
|
|
@admin_project.owner = current_user
|
2011-10-08 17:36:38 -04:00
|
|
|
|
2011-10-27 09:44:29 -04:00
|
|
|
if @admin_project.save
|
|
|
|
redirect_to [:admin, @admin_project], notice: 'Project was successfully created.'
|
|
|
|
else
|
|
|
|
render :action => "new"
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@admin_project = Project.find_by_code(params[:id])
|
|
|
|
|
2012-02-21 15:46:34 -05:00
|
|
|
owner_id = params[:project].delete(:owner_id)
|
2012-01-29 16:59:12 -05:00
|
|
|
|
|
|
|
if owner_id
|
|
|
|
@admin_project.owner = User.find(owner_id)
|
|
|
|
end
|
|
|
|
|
2011-10-27 09:44:29 -04: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 17:36:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@admin_project = Project.find_by_code(params[:id])
|
|
|
|
@admin_project.destroy
|
|
|
|
|
2011-10-27 09:44:29 -04:00
|
|
|
redirect_to admin_projects_url
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
end
|