新增:列表返回是否置顶字段

This commit is contained in:
yystopf 2024-07-16 10:17:09 +08:00
parent d577f1691a
commit 21eb842766
4 changed files with 10 additions and 8 deletions

View File

@ -11,10 +11,10 @@ class Users::OrganizationsController < Users::BaseController
@organizations = @organizations.ransack(login_cont: params[:search]).result if params[:search].present?
home_top_ids = @organizations.joins(:home_top_settings).where(home_top_settings: {user_id: observed_user.id}).order("home_top_settings.created_at asc").pluck(:id)
@home_top_ids = @organizations.joins(:home_top_settings).where(home_top_settings: {user_id: observed_user.id}).order("home_top_settings.created_at asc").pluck(:id)
if home_top_ids.present?
@organizations = @organizations.joins(:organization_extension).order("FIELD(users.id, #{home_top_ids.join(",")}) desc, organization_extensions.#{sort_by} #{sort_direction}")
if @home_top_ids.present?
@organizations = @organizations.joins(:organization_extension).order("FIELD(users.id, #{@home_top_ids.join(",")}) desc, organization_extensions.#{sort_by} #{sort_direction}")
else
@organizations = @organizations.joins(:organization_extension).order("organization_extensions.#{sort_by} #{sort_direction}")
end

View File

@ -72,13 +72,13 @@ class Projects::ListMyQuery < ApplicationQuery
sort = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : "updated_on"
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : "desc"
home_top_ids = scope.joins(:home_top_settings).where(home_top_settings: {user_id: user.id}).order("home_top_settings.created_at asc").pluck(:id)
@home_top_ids = scope.joins(:home_top_settings).where(home_top_settings: {user_id: user.id}).order("home_top_settings.created_at asc").pluck(:id)
if params[:choosed].present? && params[:choosed].is_a?(Array)
scope.distinct.order("FIELD(id, #{params[:choosed].reverse.join(",")}) desc")
else
if home_top_ids.present?
scope.distinct.order("FIELD(id, #{home_top_ids.join(",")}) desc, projects.#{sort} #{sort_direction}")
if @home_top_ids.present?
scope.distinct.order("FIELD(id, #{@home_top_ids.join(",")}) desc, projects.#{sort} #{sort_direction}")
else
scope.distinct.order("projects.#{sort} #{sort_direction}")
end

View File

@ -1,4 +1,5 @@
json.total_count @organizations.total_count
json.organizations @organizations do |organization|
json.partial! "/organizations/organizations/detail", organization: organization
json.is_home_top @home_top_ids.include?(organization.id)
end

View File

@ -1,4 +1,5 @@
json.count @total_count
json.projects do
json.partial! '/projects/project_detail', collection: @projects, as: :project
json.projects @projects do |project|
json.partial! '/projects/project_detail', project: project
json.is_home_top @home_top_ids.include?(project.id)
end