2011-03-11 16:15:06 +00:00
|
|
|
class RepositoriesController < ApplicationController
|
2011-03-11 16:08:41 +00:00
|
|
|
before_filter :authenticate_user!
|
2011-10-17 15:20:35 +01:00
|
|
|
# before_filter :find_platform, :except => [:index, :new, :create]
|
2011-03-31 01:58:27 +01:00
|
|
|
before_filter :find_repository, :only => [:show, :destroy]
|
2011-10-17 15:20:35 +01:00
|
|
|
before_filter :get_paths, :only => [:new, :create]
|
|
|
|
before_filter :find_platforms, :only => [:new, :create]
|
|
|
|
|
|
|
|
def index
|
|
|
|
@repositories = Repository.paginate(:page => params[:repository_page])
|
|
|
|
end
|
2011-03-11 16:08:41 +00:00
|
|
|
|
|
|
|
def show
|
2011-04-28 12:01:58 +01:00
|
|
|
if params[:query]
|
|
|
|
@projects = @repository.projects.recent.by_name(params[:query]).paginate :page => params[:page], :per_page => 30
|
|
|
|
else
|
|
|
|
@projects = @repository.projects.recent.paginate :page => params[:page], :per_page => 30
|
|
|
|
end
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2011-10-17 15:20:35 +01:00
|
|
|
@repository = Repository.new
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2011-03-31 01:58:27 +01:00
|
|
|
@repository.destroy
|
|
|
|
|
2011-03-31 03:00:21 +01:00
|
|
|
flash[:notice] = t("flash.repository.destroyed")
|
2011-03-31 01:58:27 +01:00
|
|
|
redirect_to platform_path(@platform)
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2011-10-17 15:20:35 +01:00
|
|
|
@repository = Repository.new(params[:repository])
|
|
|
|
@repository.owner = get_acter
|
2011-03-11 16:08:41 +00:00
|
|
|
if @repository.save
|
2011-03-31 01:59:12 +01:00
|
|
|
flash[:notice] = t('flash.repository.saved')
|
2011-10-17 15:20:35 +01:00
|
|
|
redirect_to @repositories_path
|
2011-03-11 16:08:41 +00:00
|
|
|
else
|
2011-03-31 01:59:12 +01:00
|
|
|
flash[:error] = t('flash.repository.save_error')
|
2011-03-11 16:08:41 +00:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2011-10-17 15:20:35 +01:00
|
|
|
def get_paths
|
|
|
|
if params[:user_id]
|
|
|
|
@user = User.find params[:user_id]
|
|
|
|
@repositories_path = user_repositories_path @user
|
|
|
|
@new_repository_path = new_user_repository_path @user
|
|
|
|
elsif params[:group_id]
|
|
|
|
@group = Group.find params[:group_id]
|
|
|
|
@repositories_path = group_repositories_path @group
|
|
|
|
@new_repository_path = new_group_repository_path @group
|
|
|
|
elsif params[:platform_id]
|
|
|
|
@platform = Platform.find params[:platform_id]
|
|
|
|
@repositories_path = platform_repositories_path @platform
|
|
|
|
@new_repository_path = new_platform_repository_path @platform
|
|
|
|
else
|
|
|
|
@repositories_path = repositories_path
|
|
|
|
@new_repository_path = new_repository_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_platforms
|
|
|
|
@platforms = Platform.all
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|
2011-03-31 01:58:27 +01:00
|
|
|
|
|
|
|
def find_repository
|
2011-10-17 15:20:35 +01:00
|
|
|
@repository = Repository.find(params[:id])
|
2011-03-31 01:58:27 +01:00
|
|
|
end
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|