From fe11c1eab3fcc718e3323be3bc950f3b03c2b22d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 19 Nov 2019 15:45:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E4=B8=8A=E5=AE=9E=E9=AA=8C=E5=AE=A4?= =?UTF-8?q?=E8=AF=BE=E5=A0=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/admins/laboratories/index.js | 11 +++++++++++ app/controllers/admins/laboratories_controller.rb | 4 ++++ app/controllers/courses_controller.rb | 2 +- app/controllers/shixuns_controller.rb | 4 +--- app/controllers/subjects_controller.rb | 5 ++--- app/controllers/users/courses_controller.rb | 2 +- app/models/laboratory.rb | 4 ++++ .../laboratories/shared/_laboratory_item.html.erb | 5 +++++ app/views/admins/laboratories/shared/_list.html.erb | 3 ++- .../admins/laboratories/update_sync_course.js.erb | 1 + config/routes.rb | 1 + ...19064245_add_sync_course_to_laboratory_settings.rb | 5 +++++ 12 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 app/views/admins/laboratories/update_sync_course.js.erb create mode 100644 db/migrate/20191119064245_add_sync_course_to_laboratory_settings.rb diff --git a/app/assets/javascripts/admins/laboratories/index.js b/app/assets/javascripts/admins/laboratories/index.js index 689910446..ec559cb92 100644 --- a/app/assets/javascripts/admins/laboratories/index.js +++ b/app/assets/javascripts/admins/laboratories/index.js @@ -160,5 +160,16 @@ $(document).on('turbolinks:load', function() { $addMemberModal.modal('hide'); } }); + + $(".laboratory-list-container").on("change", '.laboratory-sync-course', function () { + var s_id = $(this).attr("data-id"); + var json = {}; + $.ajax({ + url: "/admins/laboratories/" + s_id + "/update_sync_course", + type: "POST", + dataType:'script', + data: json + }) + }); } }); \ No newline at end of file diff --git a/app/controllers/admins/laboratories_controller.rb b/app/controllers/admins/laboratories_controller.rb index dcfdc443b..6bd068a66 100644 --- a/app/controllers/admins/laboratories_controller.rb +++ b/app/controllers/admins/laboratories_controller.rb @@ -56,6 +56,10 @@ class Admins::LaboratoriesController < Admins::BaseController users.update_all(laboratory_id: current_laboratory.id) end + def update_sync_course + current_laboratory.update!(sync_course: !current_laboratory.sync_course) + @laboratory = current_laboratory + end private diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 7e2432fc4..f78844a58 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -61,7 +61,7 @@ class CoursesController < ApplicationController @user = current_user # 根据分类查询课堂(全部,我的,最新,最热) @order = params[:order].present? ? params[:order] : "all" - @courses = current_laboratory.courses.not_deleted + @courses = current_laboratory.all_courses.not_deleted if @order == "visits" order_str = "courses.id = 1309 DESC, courses.visits DESC" @courses = @courses.where(is_hidden: 0) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 30f6d1bd3..e7555f927 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -977,9 +977,7 @@ class ShixunsController < ApplicationController @courses = Course.where(:id => course_ids) ## 云上实验室过滤 - unless current_laboratory.main_site? - @courses = @courses.where(laboratory_id: current_laboratory.id ) - end + @courses = @courses.where(id: current_laboratory.all_courses) @course_count = @courses.count @courses = @courses.page(page).per(limit) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index d4f1281a2..d38293a8f 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -218,9 +218,8 @@ class SubjectsController < ApplicationController AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) @courses = Course.where(id: course_ids) ## 云上实验室过滤 - unless current_laboratory.main_site? - @courses = @courses.where(laboratory_id: current_laboratory.id ) - end + @courses = @courses.where(id: current_laboratory.all_courses) + @none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id).to_i}").pluck(:shixun_id) end diff --git a/app/controllers/users/courses_controller.rb b/app/controllers/users/courses_controller.rb index 4198e17ba..95a006392 100644 --- a/app/controllers/users/courses_controller.rb +++ b/app/controllers/users/courses_controller.rb @@ -2,7 +2,7 @@ class Users::CoursesController < Users::BaseController def index courses = Users::CourseService.new(observed_user, query_params).call - courses = courses.where(laboratory_id: current_laboratory.id) + courses = courses.where(id: current_laboratory.all_courses) @count = courses.count @courses = paginate(courses.includes(teacher: { user_extension: :school }), special: observed_user.is_teacher?) diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index 466e6d4d8..102e964b1 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -54,6 +54,10 @@ class Laboratory < ApplicationRecord main_site? ? Subject.all : Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id }) end + def all_courses + main_site? || !sync_course ? courses : courses.or(Course.where(school_id: school_id)) + end + def shixun_repertoires where_sql = ShixunTagRepertoire.where("shixun_tag_repertoires.tag_repertoire_id = tag_repertoires.id") diff --git a/app/views/admins/laboratories/shared/_laboratory_item.html.erb b/app/views/admins/laboratories/shared/_laboratory_item.html.erb index 539e7d09f..be9a228b1 100644 --- a/app/views/admins/laboratories/shared/_laboratory_item.html.erb +++ b/app/views/admins/laboratories/shared/_laboratory_item.html.erb @@ -29,6 +29,11 @@
单位名称 | +单位名称 | 域名 | 统计链接 | 管理员 | <%= sort_tag('创建时间', name: 'id', path: admins_laboratories_path) %> | +同步课堂 | 操作 |
---|