|
|
|
@@ -20,11 +20,11 @@ class Projects::ListMyQuery < ApplicationQuery |
|
|
|
if params[:category].blank? |
|
|
|
normal_projects = projects.members_projects(user.id).to_sql |
|
|
|
org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: user.id}).to_sql |
|
|
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct |
|
|
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects")#.distinct |
|
|
|
elsif params[:category].to_s == "join" |
|
|
|
normal_projects = projects.where.not(user_id: user.id).members_projects(user.id).to_sql |
|
|
|
org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: user.id}).to_sql |
|
|
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct |
|
|
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects")#.distinct |
|
|
|
elsif params[:category].to_s == "manage" |
|
|
|
projects = projects.where(user_id: user.id) |
|
|
|
elsif params[:category].to_s == "watched" #我关注的 |
|
|
|
@@ -37,7 +37,7 @@ class Projects::ListMyQuery < ApplicationQuery |
|
|
|
elsif params[:category].to_s == "admin" |
|
|
|
normal_projects = projects.joins(members: :roles).where(members: {user_id: user.id}, roles: {name: %w(Manager)}).to_sql |
|
|
|
org_projects = projects.joins(team_projects: [team: :team_users]).where(teams: {authorize: %w(owner admin)},team_users: {user_id: user.id}).to_sql |
|
|
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct |
|
|
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects")#.distinct |
|
|
|
# elsif params[:category].to_s == "public" |
|
|
|
# projects = projects.visible.joins(:members).where(members: { user_id: user.id }) |
|
|
|
# elsif params[:category].to_s == "private" |
|
|
|
@@ -71,11 +71,17 @@ 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) |
|
|
|
|
|
|
|
if params[:choosed].present? && params[:choosed].is_a?(Array) |
|
|
|
scope.order("FIELD(id, #{params[:choosed].reverse.join(",")}) desc") |
|
|
|
scope.distinct.order("FIELD(id, #{params[:choosed].reverse.join(",")}) desc") |
|
|
|
else |
|
|
|
scope.order("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 |
|
|
|
end |
|
|
|
end |
|
|
|
end |