Fixed admin area. Create project only from one place
This commit is contained in:
parent
2b683b0d0b
commit
552b3105fb
9 changed files with 42 additions and 101 deletions
|
@ -1,65 +1,44 @@
|
|||
class Admin::ProjectsController < AdminController
|
||||
before_filter :admin_project, only: [:edit, :show, :update, :destroy, :team_update]
|
||||
before_filter :project, only: [:edit, :show, :update, :destroy, :team_update]
|
||||
|
||||
def index
|
||||
@admin_projects = Project.scoped
|
||||
@admin_projects = @admin_projects.search(params[:name]) if params[:name].present?
|
||||
@admin_projects = @admin_projects.order("name ASC").page(params[:page]).per(20)
|
||||
@projects = Project.scoped
|
||||
@projects = @projects.search(params[:name]) if params[:name].present?
|
||||
@projects = @projects.order("name ASC").page(params[:page]).per(20)
|
||||
end
|
||||
|
||||
def show
|
||||
@users = User.scoped
|
||||
@users = @users.not_in_project(@admin_project) if @admin_project.users.present?
|
||||
@users = @users.not_in_project(@project) if @project.users.present?
|
||||
@users = @users.all
|
||||
end
|
||||
|
||||
def new
|
||||
@admin_project = Project.new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def team_update
|
||||
@admin_project.add_users_ids_to_team(params[:user_ids], params[:project_access])
|
||||
@project.add_users_ids_to_team(params[:user_ids], params[:project_access])
|
||||
|
||||
redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
|
||||
end
|
||||
|
||||
def create
|
||||
@admin_project = Project.new(params[:project])
|
||||
@admin_project.owner = current_user
|
||||
|
||||
if @admin_project.save
|
||||
redirect_to [:admin, @admin_project], notice: 'Project was successfully created.'
|
||||
else
|
||||
render action: "new"
|
||||
end
|
||||
redirect_to [:admin, @project], notice: 'Project was successfully updated.'
|
||||
end
|
||||
|
||||
def update
|
||||
owner_id = params[:project].delete(:owner_id)
|
||||
|
||||
if owner_id
|
||||
@admin_project.owner = User.find(owner_id)
|
||||
@project.owner = User.find(owner_id)
|
||||
end
|
||||
|
||||
if @admin_project.update_attributes(params[:project])
|
||||
redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
|
||||
if @project.update_attributes(params[:project], as: :admin)
|
||||
redirect_to [:admin, @project], notice: 'Project was successfully updated.'
|
||||
else
|
||||
render action: "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@admin_project.destroy
|
||||
@project.destroy
|
||||
|
||||
redirect_to admin_projects_url, notice: 'Project was successfully deleted.'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def admin_project
|
||||
@admin_project = Project.find_by_code(params[:id])
|
||||
redirect_to projects_url, notice: 'Project was successfully deleted.'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue