mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 04:35:45 +08:00
admins 页面的修改
This commit is contained in:
83
app/controllers/admins/project_categories_controller.rb
Normal file
83
app/controllers/admins/project_categories_controller.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
class Admins::ProjectCategoriesController < Admins::BaseController
|
||||
before_action :get_category, only: [:edit,:update, :destroy]
|
||||
before_action :validate_names, only: [:create, :update]
|
||||
|
||||
def index
|
||||
sort_by = params[:sort_by] ||= 'created_at'
|
||||
sort_direction = params[:sort_direction] ||= 'desc'
|
||||
q = ProjectCategory.ransack(name_cont: params[:name])
|
||||
project_categories = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||
@project_categories = paginate(project_categories)
|
||||
|
||||
end
|
||||
|
||||
def new
|
||||
@project_category = ProjectCategory.new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
max_position_items = ProjectCategory.select(:id, :position).pluck(:position).reject!(&:blank?)
|
||||
max_position = max_position_items.present? ? max_position_items.max.to_i : 0
|
||||
|
||||
@project_category = ProjectCategory.new(name: @name,position: max_position)
|
||||
if @project_category.save
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = '创建成功'
|
||||
else
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:danger] = '创建失败'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @project_category.update_attribute(:name, @name)
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = '更新成功'
|
||||
else
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = '更新失败'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @project_language.destroy
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = "删除成功"
|
||||
else
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:danger] = "删除失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_category
|
||||
@project_category = ProjectCategory.find_by(id: params[:id])
|
||||
unless @project_category.present?
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:danger] = "分类不存在"
|
||||
end
|
||||
end
|
||||
|
||||
def check_language_present?(name)
|
||||
return true if name.blank?
|
||||
name_downcase = name.downcase
|
||||
name_upcase = name.upcase
|
||||
name_first_big = name.capitalize
|
||||
ProjectCategory.exists?(name: name_downcase) || ProjectCategory.exists?(name: name_upcase) || ProjectCategory.exists?(name: name_first_big)
|
||||
end
|
||||
|
||||
def validate_names
|
||||
@name = params[:project_category][:name].to_s.first(64)
|
||||
if @name.blank?
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:danger] = '名称不能为空'
|
||||
elsif check_language_present?(@name) && @project_category.blank?
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:danger] = '分类已存在'
|
||||
end
|
||||
end
|
||||
end
|
||||
120
app/controllers/admins/project_ignores_controller.rb
Normal file
120
app/controllers/admins/project_ignores_controller.rb
Normal file
@@ -0,0 +1,120 @@
|
||||
class Admins::ProjectIgnoresController < Admins::BaseController
|
||||
before_action :set_ignore, only: [:edit,:update, :destroy,:show]
|
||||
before_action :validate_params, only: [:create, :update]
|
||||
|
||||
def index
|
||||
sort_by = params[:sort_by] ||= 'created_at'
|
||||
sort_direction = params[:sort_direction] ||= 'desc'
|
||||
q = Ignore.ransack(name_cont: params[:search])
|
||||
project_ignores = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||
@project_ignores = paginate(project_ignores)
|
||||
end
|
||||
|
||||
def new
|
||||
@project_ignore = Ignore.new
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def create
|
||||
# conditions = params[:license][:conditions_array].reject(&:blank?).join(",") if params[:license][:conditions_array].present?
|
||||
# permissions = params[:license][:permissions_array].reject(&:blank?).join(",") if params[:license][:permissions_array].present?
|
||||
# limitations = params[:license][:limitations_array].reject(&:blank?).join(",") if params[:license][:limitations_array].present?
|
||||
# max_position_items = License.select(:id, :position).pluck(:position).reject!(&:blank?)
|
||||
# max_position = max_position_items.present? ? max_position_items.max.to_i : 0
|
||||
# other_params = {
|
||||
# conditions: conditions.to_s,
|
||||
# permissions: permissions.to_s,
|
||||
# limitations: limitations.to_s,
|
||||
# position: max_position
|
||||
# }
|
||||
@project_ignore = Ignore.new(ignore_params)
|
||||
|
||||
if @project_ignore.save!
|
||||
redirect_to admins_project_ignores_path
|
||||
flash[:success] = "创建成功"
|
||||
else
|
||||
render :new
|
||||
flash[:danger] = "创建失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
# conditions = params[:license][:conditions_array].reject(&:blank?).join(",") if params[:license][:conditions_array].present?
|
||||
# permissions = params[:license][:permissions_array].reject(&:blank?).join(",") if params[:license][:permissions_array].present?
|
||||
# limitations = params[:license][:limitations_array].reject(&:blank?).join(",") if params[:license][:limitations_array].present?
|
||||
|
||||
# other_params = {
|
||||
# conditions: conditions.to_s,
|
||||
# permissions: permissions.to_s,
|
||||
# limitations: limitations.to_s
|
||||
# }
|
||||
if @project_ignore.update_attributes(ignore_params)
|
||||
redirect_to admins_project_ignores_path
|
||||
flash[:success] = "更新成功"
|
||||
else
|
||||
render :edit
|
||||
flash[:danger] = "更新失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @project_ignore.present?
|
||||
if @project_ignore.destroy
|
||||
redirect_to admins_project_ignores_path
|
||||
flash[:success] = "删除成功"
|
||||
else
|
||||
redirect_to admins_project_ignores_path
|
||||
flash[:success] = "删除失败"
|
||||
end
|
||||
else
|
||||
redirect_to admins_project_ignores_path
|
||||
flash[:success] = "删除失败:许可证已被项目引用"
|
||||
end
|
||||
end
|
||||
|
||||
# def move
|
||||
# cate_opt = params[:opr]
|
||||
# cate_position = @project_license.position.to_i
|
||||
# move_status = up_and_down(cate_opt,@project_license,cate_position,"license")
|
||||
# if move_status == 0
|
||||
# @c_msg = "移动成功"
|
||||
# else
|
||||
# @c_msg = "移动失败"
|
||||
# end
|
||||
# end
|
||||
|
||||
private
|
||||
def set_ignore
|
||||
@project_ignore = Ignore.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def ignore_params
|
||||
params.require(:ignore).permit(:name,:content)
|
||||
end
|
||||
|
||||
def validate_params
|
||||
name = params[:ignore][:name]
|
||||
if name.blank?
|
||||
flash[:danger] = "名称不允许为空"
|
||||
redirect_to admins_project_ignores_path
|
||||
elsif check_ignore_present?(name) && @project_ignore.blank?
|
||||
flash[:danger] = "创建失败:名称已存在"
|
||||
redirect_to admins_project_ignores_path
|
||||
end
|
||||
end
|
||||
|
||||
def check_ignore_present?(name)
|
||||
return true if name.blank?
|
||||
name_downcase = name.downcase
|
||||
name_upcase = name.upcase
|
||||
name_first_big = name.capitalize
|
||||
Ignore.exists?(name: name_downcase) || Ignore.exists?(name: name_upcase) || Ignore.exists?(name: name_first_big)
|
||||
end
|
||||
|
||||
end
|
||||
82
app/controllers/admins/project_languages_controller.rb
Normal file
82
app/controllers/admins/project_languages_controller.rb
Normal file
@@ -0,0 +1,82 @@
|
||||
class Admins::ProjectLanguagesController < Admins::BaseController
|
||||
before_action :get_language, only: [:edit,:update, :destroy]
|
||||
before_action :validate_names, only: [:create, :update]
|
||||
|
||||
def index
|
||||
sort_by = params[:sort_by] ||= 'created_at'
|
||||
sort_direction = params[:sort_direction] ||= 'desc'
|
||||
q = ProjectLanguage.ransack(name_cont: params[:search])
|
||||
project_languages = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||
@project_languages = paginate(project_languages)
|
||||
|
||||
end
|
||||
|
||||
def new
|
||||
@project_language = ProjectLanguage.new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def create
|
||||
max_position_items = ProjectLanguage.select(:id, :position).pluck(:position).reject!(&:blank?)
|
||||
max_position = max_position_items.present? ? max_position_items.max.to_i : 0
|
||||
@project_language = ProjectLanguage.new(name: @name,position:max_position)
|
||||
if @project_language.save
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:success] = '创建成功'
|
||||
else
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:danger] = '创建失败'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @project_language.update_attribute(:name, @name)
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:success] = '更新成功'
|
||||
else
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:success] = '更新失败'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @project_language.destroy
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:success] = "项目语言删除成功"
|
||||
else
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:danger] = "项目语言删除失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_language
|
||||
@project_language = ProjectLanguage.find_by(id: params[:id])
|
||||
unless @project_language.present?
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:danger] = "项目语言不存在"
|
||||
end
|
||||
end
|
||||
|
||||
def check_language_present?(name)
|
||||
return true if name.blank?
|
||||
name_downcase = name.downcase
|
||||
name_upcase = name.upcase
|
||||
name_first_big = name.capitalize
|
||||
ProjectLanguage.exists?(name: name_downcase) || ProjectLanguage.exists?(name: name_upcase) || ProjectLanguage.exists?(name: name_first_big)
|
||||
end
|
||||
|
||||
def validate_names
|
||||
@name = params[:project_language][:name].to_s.first(64)
|
||||
if @name.blank?
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:danger] = '名称不能为空'
|
||||
elsif check_language_present?(@name) && @project_language.blank?
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:danger] = '项目语言已存在'
|
||||
end
|
||||
end
|
||||
end
|
||||
120
app/controllers/admins/project_licenses_controller.rb
Normal file
120
app/controllers/admins/project_licenses_controller.rb
Normal file
@@ -0,0 +1,120 @@
|
||||
class Admins::ProjectLicensesController < Admins::BaseController
|
||||
before_action :set_license, only: [:edit,:update, :destroy,:show]
|
||||
before_action :validate_params, only: [:create, :update]
|
||||
|
||||
def index
|
||||
sort_by = params[:sort_by] ||= 'created_at'
|
||||
sort_direction = params[:sort_direction] ||= 'desc'
|
||||
q = License.ransack(name_cont: params[:search])
|
||||
project_licenses = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||
@project_licenses = paginate(project_licenses)
|
||||
end
|
||||
|
||||
def new
|
||||
@project_license = License.new
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def create
|
||||
# conditions = params[:license][:conditions_array].reject(&:blank?).join(",") if params[:license][:conditions_array].present?
|
||||
# permissions = params[:license][:permissions_array].reject(&:blank?).join(",") if params[:license][:permissions_array].present?
|
||||
# limitations = params[:license][:limitations_array].reject(&:blank?).join(",") if params[:license][:limitations_array].present?
|
||||
# max_position_items = License.select(:id, :position).pluck(:position).reject!(&:blank?)
|
||||
# max_position = max_position_items.present? ? max_position_items.max.to_i : 0
|
||||
# other_params = {
|
||||
# conditions: conditions.to_s,
|
||||
# permissions: permissions.to_s,
|
||||
# limitations: limitations.to_s,
|
||||
# position: max_position
|
||||
# }
|
||||
@project_license = License.new(license_params)
|
||||
|
||||
if @project_license.save!
|
||||
redirect_to admins_project_licenses_path
|
||||
flash[:success] = "创建成功"
|
||||
else
|
||||
render :new
|
||||
flash[:danger] = "创建失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
# conditions = params[:license][:conditions_array].reject(&:blank?).join(",") if params[:license][:conditions_array].present?
|
||||
# permissions = params[:license][:permissions_array].reject(&:blank?).join(",") if params[:license][:permissions_array].present?
|
||||
# limitations = params[:license][:limitations_array].reject(&:blank?).join(",") if params[:license][:limitations_array].present?
|
||||
|
||||
# other_params = {
|
||||
# conditions: conditions.to_s,
|
||||
# permissions: permissions.to_s,
|
||||
# limitations: limitations.to_s
|
||||
# }
|
||||
if @project_license.update_attributes(license_params)
|
||||
redirect_to admins_project_licenses_path
|
||||
flash[:success] = "更新成功"
|
||||
else
|
||||
render :edit
|
||||
flash[:danger] = "更新失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @project_license.present?
|
||||
if @project_license.destroy
|
||||
redirect_to admins_project_licenses_path
|
||||
flash[:success] = "删除成功"
|
||||
else
|
||||
redirect_to admins_project_licenses_path
|
||||
flash[:success] = "删除失败"
|
||||
end
|
||||
else
|
||||
redirect_to admins_project_licenses_path
|
||||
flash[:success] = "删除失败:许可证已被项目引用"
|
||||
end
|
||||
end
|
||||
|
||||
# def move
|
||||
# cate_opt = params[:opr]
|
||||
# cate_position = @project_license.position.to_i
|
||||
# move_status = up_and_down(cate_opt,@project_license,cate_position,"license")
|
||||
# if move_status == 0
|
||||
# @c_msg = "移动成功"
|
||||
# else
|
||||
# @c_msg = "移动失败"
|
||||
# end
|
||||
# end
|
||||
|
||||
private
|
||||
def set_license
|
||||
@project_license = License.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def license_params
|
||||
params.require(:license).permit(:name,:content)
|
||||
end
|
||||
|
||||
def validate_params
|
||||
name = params[:license][:name]
|
||||
if name.blank?
|
||||
flash[:danger] = "名称不允许为空"
|
||||
redirect_to admins_project_licenses_path
|
||||
elsif check_license_present?(name) && @project_license.blank?
|
||||
flash[:danger] = "创建失败:名称已存在"
|
||||
redirect_to admins_project_licenses_path
|
||||
end
|
||||
end
|
||||
|
||||
def check_license_present?(name)
|
||||
return true if name.blank?
|
||||
name_downcase = name.downcase
|
||||
name_upcase = name.upcase
|
||||
name_first_big = name.capitalize
|
||||
License.exists?(name: name_downcase) || License.exists?(name: name_upcase) || License.exists?(name: name_first_big)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,10 +1,11 @@
|
||||
class Admins::ProjectsController < Admins::BaseController
|
||||
|
||||
def index
|
||||
default_sort('created_at', 'desc')
|
||||
sort_by = params[:sort_by] ||= 'created_on'
|
||||
sort_direction = params[:sort_direction] ||= 'desc'
|
||||
|
||||
search = params[:search].to_s.strip
|
||||
projects = Project.where("name like ?", "%#{search}%")
|
||||
projects = Project.where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}")
|
||||
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
||||
end
|
||||
|
||||
@@ -21,5 +22,4 @@ class Admins::ProjectsController < Admins::BaseController
|
||||
render_delete_success
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -4,7 +4,7 @@ class Admins::UsersController < Admins::BaseController
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
|
||||
users = Admins::UserQuery.call(params)
|
||||
@users = paginate users.includes(:user_extension)
|
||||
@users = paginate users.includes(:user_extension, projects: :members)
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
Reference in New Issue
Block a user