forked from Gitlink/forgeplus
fixed 搜索用户项目时过虑表情字符
This commit is contained in:
parent
d993df7df4
commit
6f7b40ec24
|
@ -8,14 +8,17 @@ class Organizations::ProjectsController < Organizations::BaseController
|
|||
.joins(team_projects: {team: :team_users})
|
||||
.where(team_users: {user_id: current_user.id}).to_sql
|
||||
@projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects")
|
||||
|
||||
@projects = @projects.ransack(name_or_identifier_cont: params[:search]).result if params[:search].present?
|
||||
# 表情处理
|
||||
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
@projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present?
|
||||
@projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}")
|
||||
@projects = paginate(@projects)
|
||||
end
|
||||
|
||||
def search
|
||||
tip_exception("请输入搜索关键词") if params[:search].nil?
|
||||
# 表情处理
|
||||
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
public_projects_sql = @organization.projects.where(is_public: true).to_sql
|
||||
private_projects_sql = @organization.projects
|
||||
.where(is_public: false)
|
||||
|
@ -23,7 +26,7 @@ class Organizations::ProjectsController < Organizations::BaseController
|
|||
.where(team_users: {user_id: current_user.id}).to_sql
|
||||
@projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects")
|
||||
|
||||
@projects = @projects.ransack(name_or_identifier_cont: params[:search]).result
|
||||
@projects = @projects.ransack(name_or_identifier_cont: keywords).result
|
||||
@projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}")
|
||||
end
|
||||
|
||||
|
|
|
@ -240,6 +240,8 @@ class Project < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.search_project(search)
|
||||
# 表情处理
|
||||
search = search.to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
ransack(name_or_identifier_cont: search)
|
||||
end
|
||||
# 创建者
|
||||
|
|
|
@ -52,8 +52,10 @@ class Projects::ListMyQuery < ApplicationQuery
|
|||
elsif params[:project_type].to_s === "sync_mirror"
|
||||
projects = projects.sync_mirror
|
||||
end
|
||||
|
||||
q = projects.ransack(name_or_identifier_cont: params[:search])
|
||||
|
||||
# 表情处理
|
||||
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
q = projects.ransack(name_or_identifier_cont: keywords)
|
||||
|
||||
scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users)
|
||||
|
||||
|
|
|
@ -51,7 +51,9 @@ class Projects::ListQuery < ApplicationQuery
|
|||
# items = items.where(id: @ids).by_name_or_identifier(params[:search])
|
||||
items = items.where(id: @ids)
|
||||
else
|
||||
items = items.by_name_or_identifier(params[:search]).or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id)))
|
||||
# 表情处理
|
||||
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
items = items.by_name_or_identifier(keywords).or(main_collection.where(user_id: Owner.like(keywords).pluck(:id)))
|
||||
end
|
||||
items
|
||||
end
|
||||
|
|
|
@ -73,8 +73,10 @@ class Api::V1::Users::Projects::ListService < ApplicationService
|
|||
end
|
||||
|
||||
|
||||
projects = projects.with_project_type(project_type)
|
||||
projects = projects.with_project_type(project_type)
|
||||
|
||||
# 表情处理
|
||||
search = search.to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
q = projects.ransack(name_or_identifier_cont: search)
|
||||
|
||||
scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users)
|
||||
|
|
Loading…
Reference in New Issue