diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 48c942e65..ba07d42c9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -26,12 +26,27 @@ class HomeController < ApplicationController @rep_list << {rep_id: rep.id, rep_name: rep.name, sub_rep_list: sub_rep_list} end - @shixuns = Shixun.where(homepage_show: 1).includes(:tag_repertoires, :challenges).limit(8) + shixuns = current_laboratory.shixuns + subjects = current_laboratory.subjects + + if current_laboratory.main_site? + shixuns = shixuns.where(homepage_show: true) + subjects = subjects.where(homepage_show: true) + else + shixuns = shixuns.where(laboratory_shixuns: { homepage: true }) + subjects = subjects.where(laboratory_subjects: { homepage: true }) + end + + @shixuns = shixuns.includes(:tag_repertoires, :challenges).limit(8) + @subjects = subjects.includes(:repertoire, :shixuns).limit(8) - @subjects = Subject.where(homepage_show: 1).includes(:shixuns, :repertoire).limit(8) + @main_shixuns = Shixun.where(homepage_show: true).includes(:tag_repertoires, :challenges).limit(8) + @main_subjects = Subject.where(homepage_show: true).includes(:shixuns, :repertoire).limit(8) - @tea_users = User.where(homepage_teacher: 1).includes(:user_extension).limit(10).order("experience desc") - @stu_users = User.where(is_test: 0).includes(:user_extension).where(user_extensions: {identity: 1}).limit(10).order("experience desc") + if current_laboratory.main_site? + @tea_users = User.where(homepage_teacher: 1).includes(:user_extension).limit(10).order("experience desc") + @stu_users = User.where(is_test: 0).includes(:user_extension).where(user_extensions: {identity: 1}).limit(10).order("experience desc") + end end def search diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index e2b78ee4b..cfe6141ee 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -33,7 +33,12 @@ class ShixunsController < ApplicationController current_user.my_shixuns else Shixun.unhidden - end + end + + ## 云上实验室过滤 + unless current_laboratory.main_site? + @shixuns = @shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: current_laboratory.id }) + end ## 方向 if params[:tag_level].present? && params[:tag_id].present? diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 9c6980b69..b76db8a20 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -23,16 +23,17 @@ class SubjectsController < ApplicationController # 最热排序 if reorder == "myshixun_count" + laboratory_join = current_laboratory.main_site? ? '' : " JOIN laboratory_subjects ls ON ls.subject_id = subjects.id AND ls.laboratory_id = #{current_laboratory.id} " if select @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns - on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id #{laboratory_join} where subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' AND subjects.repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") else @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns - on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id #{laboratory_join} where subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' GROUP BY subjects.id ORDER BY myshixun_member_count DESC") end @@ -52,6 +53,11 @@ class SubjectsController < ApplicationController @subjects = Subject.visible.unhidden end + # 云上实验室过滤 + unless current_laboratory.main_site? + @subjects = @subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: current_laboratory.id }) + end + # 类型 if select @subjects = @subjects.where(repertoire_id: select) diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index ff8f89c5e..672294b63 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -38,4 +38,17 @@ class Laboratory < ApplicationRecord def self.current Thread.current[:current_laboratory] ||= Laboratory.find(1) end + + def shixuns + main_site? ? Shixun.all : Shixun.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: id }) + end + + def subjects + main_site? ? Subject.all : Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id }) + end + + # 是否为主站 + def main_site? + id == 1 + end end \ No newline at end of file diff --git a/app/views/home/index.json.jbuilder b/app/views/home/index.json.jbuilder index aa29ae7ff..5bbd1b799 100644 --- a/app/views/home/index.json.jbuilder +++ b/app/views/home/index.json.jbuilder @@ -3,17 +3,19 @@ json.images_url @images_url json.reps @rep_list json.shixuns do - json.partial! 'shixuns/shixun', locals: {shixuns: @shixuns} + json.partial! 'shixuns/shixun', locals: {shixuns: @shixuns.present? ? @shixuns : @main_shixuns} end json.subjects do - json.partial! 'subjects/subject', locals: {subjects: @subjects} + json.partial! 'subjects/subject', locals: {subjects: @subjects.present? ? @subjects : @main_subjects} end -json.teachers do - json.partial! 'users/user_small', users: @tea_users -end +if current_laboratory.main_site? + json.teachers do + json.partial! 'users/user_small', users: @tea_users + end -json.students do - json.partial! 'users/user_small', users: @stu_users + json.students do + json.partial! 'users/user_small', users: @stu_users + end end diff --git a/public/react/src/modules/home/shixunsHome.js b/public/react/src/modules/home/shixunsHome.js index 8cdee3554..40bc8c69d 100644 --- a/public/react/src/modules/home/shixunsHome.js +++ b/public/react/src/modules/home/shixunsHome.js @@ -394,6 +394,7 @@ class ShixunsHome extends Component { {/*导师排行榜*/} + { homedatalist !== undefined && homedatalist.teachers !== undefined && (