parent
e30d200371
commit
285705b935
@ -1,2 +1,9 @@
|
|||||||
module ProjectsHelper
|
module ProjectsHelper
|
||||||
|
|
||||||
|
def render_zh_project_type(project_type)
|
||||||
|
case project_type
|
||||||
|
when 'common' then "开源托管项目"
|
||||||
|
when 'mirror' then "开源镜像项目"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
module Matchable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
scope :like, lambda { |keywords|
|
||||||
|
where("name LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
|
||||||
|
}
|
||||||
|
scope :with_project_category, ->(category_id) { where(project_category_id: category_id) unless category_id.blank? }
|
||||||
|
scope :with_project_language, ->(language_id) { where(project_language_id: language_id) unless language_id.blank? }
|
||||||
|
scope :with_project_type, ->(project_type) { where(project_type: project_type) if Project.project_types.include?(project_type) }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,21 @@
|
|||||||
|
class Projects::ListQuery < ApplicationQuery
|
||||||
|
include CustomSortable
|
||||||
|
|
||||||
|
attr_reader :params
|
||||||
|
|
||||||
|
sort_columns :updated_on, :created_on, :forked_count, :praises_count, default_by: :updated_on, default_direction: :desc
|
||||||
|
|
||||||
|
def initialize(params)
|
||||||
|
@params = params
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
scope = Project.like(params[:search])
|
||||||
|
.with_project_type(params[:project_type])
|
||||||
|
.with_project_category(params[:category_id])
|
||||||
|
.with_project_language(params[:language_id])
|
||||||
|
.includes(:project_category, :project_language, :repository, :owner)
|
||||||
|
|
||||||
|
custom_sort(scope, params[:sort_by], params[:sort_direction])
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
json.array! @category_group_list do |category|
|
||||||
|
json.id category.project_category_id
|
||||||
|
json.name category.name
|
||||||
|
json.projects_count category.projects_count
|
||||||
|
end
|
@ -0,0 +1,8 @@
|
|||||||
|
json.id project.identifier
|
||||||
|
json.name project.name
|
||||||
|
json.description project.description
|
||||||
|
json.visits project.visits
|
||||||
|
json.forked_count project.forked_count
|
||||||
|
json.is_public project.is_public
|
||||||
|
json.mirror_url project.repository&.mirror_url
|
||||||
|
json.last_update_time render_unix_time(project.updated_on)
|
@ -0,0 +1,5 @@
|
|||||||
|
json.array! @project_group_list do |group|
|
||||||
|
json.project_type group.project_type
|
||||||
|
json.name render_zh_project_type(group.project_type)
|
||||||
|
json.projects_count group.projects_count
|
||||||
|
end
|
@ -1 +1,22 @@
|
|||||||
json.projects []
|
json.array! @projects do |project|
|
||||||
|
json.partial! 'project', project: project
|
||||||
|
json.author do
|
||||||
|
json.name project.owner.login
|
||||||
|
end
|
||||||
|
json.category do
|
||||||
|
if project.project_category.blank?
|
||||||
|
json.nil!
|
||||||
|
else
|
||||||
|
json.id project.project_category.id
|
||||||
|
json.name project.project_category.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
json.language do
|
||||||
|
if project.project_language.blank?
|
||||||
|
json.nil!
|
||||||
|
else
|
||||||
|
json.id project.project_language.id
|
||||||
|
json.name project.project_language.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
Reference in new issue