2013-01-20 11:20:50 +00:00
|
|
|
class Admin::TeamsController < Admin::ApplicationController
|
2013-01-19 17:11:11 +00:00
|
|
|
def index
|
|
|
|
@teams = UserTeam.order('name ASC')
|
|
|
|
@teams = @teams.search(params[:name]) if params[:name].present?
|
|
|
|
@teams = @teams.page(params[:page]).per(20)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@projects = Project.scoped
|
2013-01-22 17:29:19 +00:00
|
|
|
@projects = @projects.without_team(user_team) if user_team.projects.any?
|
2013-01-19 17:11:11 +00:00
|
|
|
#@projects.reject!(&:empty_repo?)
|
|
|
|
|
|
|
|
@users = User.active
|
2013-01-22 17:29:19 +00:00
|
|
|
@users = @users.not_in_team(user_team) if user_team.members.any?
|
2013-01-19 17:11:11 +00:00
|
|
|
@users = UserDecorator.decorate @users
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@team = UserTeam.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-01-22 17:29:19 +00:00
|
|
|
user_team
|
2013-01-19 17:11:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2013-01-22 17:29:19 +00:00
|
|
|
user_team = UserTeam.new(params[:user_team])
|
|
|
|
user_team.path = user_team.name.dup.parameterize if user_team.name
|
|
|
|
user_team.owner = current_user
|
2013-01-19 17:11:11 +00:00
|
|
|
|
2013-01-22 17:29:19 +00:00
|
|
|
if user_team.save
|
|
|
|
redirect_to admin_team_path(user_team), notice: 'UserTeam was successfully created.'
|
2013-01-19 17:11:11 +00:00
|
|
|
else
|
|
|
|
render action: "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
user_team_params = params[:user_team].dup
|
|
|
|
owner_id = user_team_params.delete(:owner_id)
|
|
|
|
|
|
|
|
if owner_id
|
2013-01-22 17:29:19 +00:00
|
|
|
user_team.owner = User.find(owner_id)
|
2013-01-19 17:11:11 +00:00
|
|
|
end
|
|
|
|
|
2013-01-22 17:29:19 +00:00
|
|
|
if user_team.update_attributes(user_team_params)
|
|
|
|
redirect_to admin_team_path(user_team), notice: 'UserTeam was successfully updated.'
|
2013-01-19 17:11:11 +00:00
|
|
|
else
|
|
|
|
render action: "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2013-01-22 17:29:19 +00:00
|
|
|
user_team.destroy
|
2013-01-19 17:11:11 +00:00
|
|
|
|
|
|
|
redirect_to admin_user_teams_path, notice: 'UserTeam was successfully deleted.'
|
|
|
|
end
|
|
|
|
|
2013-01-22 17:29:19 +00:00
|
|
|
protected
|
2013-01-19 17:11:11 +00:00
|
|
|
|
|
|
|
def user_team
|
2013-01-22 17:29:19 +00:00
|
|
|
@team ||= UserTeam.find_by_path(params[:id])
|
2013-01-19 17:11:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|