2011-03-10 11:35:46 +00:00
|
|
|
class ProjectsController < ApplicationController
|
2011-03-10 13:38:50 +00:00
|
|
|
before_filter :authenticate_user!
|
2011-10-16 21:50:56 +01:00
|
|
|
# before_filter :find_platform
|
|
|
|
# before_filter :find_repository
|
2011-04-11 17:37:09 +01:00
|
|
|
before_filter :find_project, :only => [:show, :destroy, :build, :process_build]
|
2011-10-17 15:21:29 +01:00
|
|
|
before_filter :get_paths, :only => [:new, :create]
|
2011-03-10 13:38:50 +00:00
|
|
|
|
|
|
|
def new
|
2011-10-17 15:21:29 +01:00
|
|
|
@project = Project.new
|
2011-03-10 13:38:50 +00:00
|
|
|
end
|
|
|
|
|
2011-03-10 14:20:09 +00:00
|
|
|
def show
|
2011-04-07 14:20:21 +01:00
|
|
|
@current_build_lists = @project.build_lists.current.recent.paginate :page => params[:page]
|
2011-03-10 14:20:09 +00:00
|
|
|
end
|
|
|
|
|
2011-04-11 17:37:09 +01:00
|
|
|
def build
|
|
|
|
@branches = @project.git_repository.branches
|
|
|
|
@arches = Arch.recent
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_build
|
|
|
|
@arch_ids = params[:build][:arches].select{|_,v| v == "1"}.collect{|x| x[0].to_i }
|
|
|
|
@arches = Arch.where(:id => @arch_ids)
|
|
|
|
|
|
|
|
@branches = @project.git_repository.branches
|
|
|
|
@branch = @branches.select{|branch| branch.name == params[:build][:branch] }.first
|
|
|
|
|
|
|
|
if !check_arches || !check_branches
|
|
|
|
@arches = Arch.recent
|
|
|
|
render :action => "build"
|
|
|
|
else
|
|
|
|
flash[:notice], flash[:error] = "", ""
|
|
|
|
@arches.each do |arch|
|
|
|
|
build_list = @project.build_lists.new(:arch => arch, :branch_name => @branch.name)
|
|
|
|
|
|
|
|
if build_list.save
|
|
|
|
flash[:notice] += t("flash.build_list.saved", :branch_name => @branch.name, :arch => arch.name)
|
|
|
|
else
|
|
|
|
flash[:error] += t("flash.build_list.save_error", :branch_name => @branch.name, :arch => arch.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to platform_repository_project_path(@platform, @repository, @project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-10 13:38:50 +00:00
|
|
|
def create
|
2011-10-17 15:21:29 +01:00
|
|
|
@project = Project.new params[:project]
|
2011-10-17 17:07:53 +01:00
|
|
|
# @project.owner = get_acter
|
2011-10-17 15:21:29 +01:00
|
|
|
|
2011-03-10 13:38:50 +00:00
|
|
|
if @project.save
|
|
|
|
flash[:notice] = t('flash.project.saved')
|
2011-10-17 17:07:53 +01:00
|
|
|
# redirect_to @project.owner
|
|
|
|
redirect_to @project
|
2011-03-10 13:38:50 +00:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.project.save_error')
|
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-31 02:56:20 +01:00
|
|
|
def destroy
|
|
|
|
@project.destroy
|
|
|
|
|
2011-03-31 03:00:21 +01:00
|
|
|
flash[:notice] = t("flash.project.destroyed")
|
2011-03-31 02:56:20 +01:00
|
|
|
redirect_to platform_repository_path(@platform, @repository)
|
|
|
|
end
|
|
|
|
|
2011-03-10 13:38:50 +00:00
|
|
|
protected
|
|
|
|
|
2011-10-17 15:21:29 +01:00
|
|
|
def get_paths
|
|
|
|
if params[:user_id]
|
|
|
|
@user = User.find params[:user_id]
|
|
|
|
@projects_path = user_projects_path @user
|
|
|
|
@new_project_path = new_user_project_path @user
|
|
|
|
elsif params[:group_id]
|
|
|
|
@group = Group.find params[:group_id]
|
|
|
|
@projects_path = group_projects_path @group
|
|
|
|
@new_projects_path = new_group_project_path @group
|
|
|
|
else
|
|
|
|
@projects_path = projects_path
|
|
|
|
@new_projects_path = new_project_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-10 13:38:50 +00:00
|
|
|
def find_platform
|
|
|
|
@platform = Platform.find params[:platform_id]
|
|
|
|
end
|
2011-03-10 14:20:09 +00:00
|
|
|
|
2011-03-11 16:08:41 +00:00
|
|
|
def find_repository
|
2011-03-11 16:30:02 +00:00
|
|
|
@repository = @platform.repositories.find(params[:repository_id])
|
2011-03-11 16:08:41 +00:00
|
|
|
end
|
|
|
|
|
2011-03-10 14:20:09 +00:00
|
|
|
def find_project
|
2011-10-16 21:50:56 +01:00
|
|
|
@project = Project.find params[:id]
|
2011-03-10 14:20:09 +00:00
|
|
|
end
|
2011-04-11 17:37:09 +01:00
|
|
|
|
|
|
|
def check_arches
|
|
|
|
if @arch_ids.blank?
|
|
|
|
flash[:error] = t("flash.build_list.no_arch_selected")
|
|
|
|
false
|
|
|
|
elsif @arch_ids.length != @arches.length
|
|
|
|
flash[:error] = t("flash.build_list.no_arch_found")
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_branches
|
|
|
|
if @branch.blank?
|
|
|
|
flash[:error] = t("flash.build_list.no_branch_selected")
|
|
|
|
false
|
|
|
|
elsif !@branches.include?(@branch)
|
|
|
|
flash[:error] = t("flash.build_list.no_branch_found")
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2011-03-10 11:35:46 +00:00
|
|
|
end
|