forked from Trustie/forgeplus
增加组织的精选项目配置
This commit is contained in:
parent
e69f9263b2
commit
380ef5e057
|
|
@ -0,0 +1,58 @@
|
|||
class Organizations::IsPinnedProjectsController < Organizations::BaseController
|
||||
before_action :load_organization
|
||||
|
||||
def index
|
||||
@is_pinned_projects = @organization.pinned_projects.order(position: :desc, created_at: :asc).includes(project: [:project_category, :project_language, :repository]).order(position: :desc)
|
||||
@is_pinned_projects = kaminari_paginate(@is_pinned_projects)
|
||||
end
|
||||
|
||||
def pin
|
||||
tip_exception "参数错误" if params[:is_pinned_project_ids].blank?
|
||||
params[:is_pinned_project_ids].each do |project_id|
|
||||
@organization.pinned_projects.create!(project_id: 906)
|
||||
end
|
||||
|
||||
render_ok
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
render_not_found
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def update
|
||||
@pinned_project = PinnedProject.find_by_id(params[:id])
|
||||
@pinned_project.attributes = pinned_project_params
|
||||
if @pinned_project.save
|
||||
render_ok
|
||||
else
|
||||
render_error
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_organization
|
||||
@organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id])
|
||||
return render_not_found("组织不存在") if @organization.nil?
|
||||
return render_forbidden("没有查看组织的权限") if org_limited_condition || org_privacy_condition
|
||||
end
|
||||
|
||||
# def is_pinned_project_ids
|
||||
# if params[:is_pinned_project_ids].present?
|
||||
# return params[:is_pinned_project_ids].select { |id| @organization.full_member_projects.visible.pluck(:id).include?(id.to_i) }
|
||||
# end
|
||||
# if params[:is_pinned_project_id].present?
|
||||
# return @organization.is_pinned_project_ids unless @organization.full_member_projects.visible.pluck(:id).include?(params[:is_pinned_project_id].to_i)
|
||||
# return @organization.is_pinned_project_ids.include?(params[:is_pinned_project_id].to_i) ? @organization.is_pinned_project_ids : @organization.is_pinned_project_ids.push(params[:is_pinned_project_id].to_i)
|
||||
# end
|
||||
# end
|
||||
|
||||
def pinned_project_params
|
||||
params.require(:pinned_project).permit(:position)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -7,10 +7,21 @@ class Organizations::ProjectsController < Organizations::BaseController
|
|||
.where(is_public: false)
|
||||
.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")
|
||||
|
||||
if params[:is_public].present? && params[:is_public].to_s == "public"
|
||||
@projects = Project.from("( #{ public_projects_sql}) AS projects")
|
||||
@projects = @projects.secret_and_visible
|
||||
else
|
||||
@projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects")
|
||||
end
|
||||
|
||||
@projects = @projects.ransack(name_or_identifier_cont: params[:search]).result if params[:search].present?
|
||||
@projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}")
|
||||
@projects = @projects.includes(:owner)
|
||||
if params[:choosed].present? && params[:choosed].is_a?(Array)
|
||||
@projects = @projects.order("FIELD(id, #{params[:choosed].reverse.join(",")}) desc")
|
||||
else
|
||||
@projects = @projects.order("projects.#{sort} #{sort_direction}")
|
||||
end
|
||||
@projects = paginate(@projects)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,8 @@ class Organization < Owner
|
|||
has_many :teams, dependent: :destroy
|
||||
has_many :organization_users, dependent: :destroy
|
||||
has_many :team_users, dependent: :destroy
|
||||
has_many :pinned_projects, class_name: 'PinnedProject', foreign_key: :user_id, dependent: :destroy
|
||||
has_many :is_pinned_projects, through: :pinned_projects, source: :project, validate: false
|
||||
|
||||
validates :login, presence: true
|
||||
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
|
||||
|
|
|
|||
|
|
@ -67,5 +67,6 @@ class Owner < ApplicationRecord
|
|||
has_many :projects, foreign_key: :user_id, dependent: :destroy
|
||||
has_many :repositories, foreign_key: :user_id, dependent: :destroy
|
||||
has_many :applied_transfer_projects, dependent: :destroy
|
||||
has_many :pinned_projects, foreign_key: :user_id, dependent: :destroy
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
class PinnedProject < ApplicationRecord
|
||||
|
||||
belongs_to :user
|
||||
# belongs_to :user
|
||||
belongs_to :owner, class_name: 'Owner', foreign_key: :user_id, optional: true
|
||||
belongs_to :project
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
json.total_count @is_pinned_projects.total_count
|
||||
json.projects @is_pinned_projects.each do |project|
|
||||
json.partial! "projects/project_detail", project: project&.project
|
||||
json.id project.id
|
||||
json.position project.position
|
||||
json.project_id project.project_id
|
||||
end
|
||||
|
|
@ -149,6 +149,11 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
get :recommend, on: :collection
|
||||
resources :is_pinned_projects, only: [:index, :update] do
|
||||
collection do
|
||||
post :pin
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue