子站同步实践课程和实训

chromesetting
cxt 5 years ago
parent 9b83e4ac8d
commit d829679137

@ -171,5 +171,19 @@ $(document).on('turbolinks:load', function() {
data: json data: json
}) })
}); });
$(".laboratory-list-container").on("change", '.laboratory-sync-form', function () {
var s_id = $(this).attr("data-id");
var s_value = $(this).val();
var s_name = $(this).attr("name");
var json = {};
json[s_name] = s_value;
$.ajax({
url: "/admins/laboratories/" + s_id,
type: "PUT",
dataType:'script',
data: json
});
});
} }
}); });

@ -29,9 +29,7 @@ class Admins::CoursesController < Admins::BaseController
end end
def update def update
if @course.update_attributes(setting_params) unless @course.update_attributes!(setting_params)
render_ok
else
redirect_to admins_courses_path redirect_to admins_courses_path
flash[:danger] = "更新失败" flash[:danger] = "更新失败"
end end

@ -61,6 +61,14 @@ class Admins::LaboratoriesController < Admins::BaseController
@laboratory = current_laboratory @laboratory = current_laboratory
end end
def update
@laboratory = current_laboratory
unless @laboratory.update_attributes!(setting_params)
redirect_to admins_laboratories_path
flash[:danger] = "更新失败"
end
end
private private
def current_laboratory def current_laboratory
@ -70,4 +78,8 @@ class Admins::LaboratoriesController < Admins::BaseController
def create_params def create_params
params.permit(:school_id) params.permit(:school_id)
end end
def setting_params
params.permit(:sync_course, :sync_subject, :sync_shixun)
end
end end

@ -10,7 +10,7 @@ module LaboratoryHelper
end end
def current_laboratory def current_laboratory
@_current_laboratory ||= (Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(1)) @_current_laboratory ||= (Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(2))
end end
def default_laboratory def default_laboratory

@ -25,15 +25,9 @@ class SubjectsController < ApplicationController
# 最热排序 # 最热排序
if reorder == "myshixun_count" if reorder == "myshixun_count"
if current_laboratory.main_site? subject_ids = current_laboratory.subjects.pluck(:id)
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{current_laboratory.id}").pluck(:id) subject_ids = subject_ids.length > 0 ? "(" + subject_ids.join(",") + ")" : "(-1)"
not_subject_ids = not_subject_ids.length > 0 ? "(" + not_subject_ids.join(",") + ")" : "(-1)" laboratory_join = " AND subjects.id in #{subject_ids} "
laboratory_join = " AND subjects.id not in #{not_subject_ids} "
else
subject_ids = Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: current_laboratory.id }).pluck(:id)
subject_ids = subject_ids.length > 0 ? "(" + subject_ids.join(",") + ")" : "(-1)"
laboratory_join = " AND subjects.id in #{subject_ids} "
end
if select if select
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
@ -49,6 +43,7 @@ class SubjectsController < ApplicationController
GROUP BY subjects.id ORDER BY myshixun_member_count DESC") GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
end end
else else
@subjects = current_laboratory.subjects
# 我的路径 # 我的路径
if reorder == "mine" if reorder == "mine"
tip_exception(401, "..") unless current_user.logged? tip_exception(401, "..") unless current_user.logged?
@ -57,19 +52,11 @@ class SubjectsController < ApplicationController
(select distinct(shixun_id) from myshixuns where user_id=#{current_user.id})").map(&:subject_id) (select distinct(shixun_id) from myshixuns where user_id=#{current_user.id})").map(&:subject_id)
manage_subject_id = SubjectMember.where(user_id: current_user.id).pluck(:subject_id) manage_subject_id = SubjectMember.where(user_id: current_user.id).pluck(:subject_id)
total_subject_id = (mine_subject_id + manage_subject_id).uniq total_subject_id = (mine_subject_id + manage_subject_id).uniq
@subjects = Subject.where(id: total_subject_id) @subjects = @subjects.where(id: total_subject_id)
elsif reorder == "publish_time" elsif reorder == "publish_time"
@subjects = Subject.unhidden @subjects = @subjects.unhidden
else
@subjects = Subject.visible.unhidden
end
# 云上实验室过滤
unless current_laboratory.main_site?
@subjects = @subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: current_laboratory.id })
else else
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{current_laboratory.id}") @subjects = @subjects.visible.unhidden
@subjects = @subjects.where.not(id: not_subject_ids)
end end
# 类型 # 类型

@ -2,13 +2,7 @@ class Users::SubjectsController < Users::BaseController
def index def index
subjects = Users::SubjectService.new(observed_user, query_params).call subjects = Users::SubjectService.new(observed_user, query_params).call
## 云上实验室过滤 subjects = subjects.where(id: current_laboratory.subjects)
if current_laboratory.main_site?
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{current_laboratory.id}")
subjects = subjects.where.not(id: not_subject_ids)
else
subjects = subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: current_laboratory.id })
end
@count = subjects.count @count = subjects.count
@subjects = paginate(subjects.includes(:user, :repertoire), special: observed_user.is_teacher?) @subjects = paginate(subjects.includes(:user, :repertoire), special: observed_user.is_teacher?)

@ -47,11 +47,29 @@ class Laboratory < ApplicationRecord
end end
def shixuns def shixuns
main_site? ? Shixun.all : Shixun.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: id }) if main_site?
Shixun.where.not(id: laboratory_shixuns.pluck(:shixun_id))
elsif sync_subject
laboratory_shixun_ids = laboratory_shixuns.pluck(:shixun_id)
school_shixun_ids = Shixun.joins("join user_extensions on shixuns.user_id=user_extensions.user_id").where(user_extensions: { school_id: school_id }).pluck(:id)
shixun_ids = laboratory_shixun_ids + school_shixun_ids
Shixun.where(id: shixun_ids.uniq)
else
Shixun.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: id })
end
end end
def subjects def subjects
main_site? ? Subject.all : Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id }) if main_site?
Subject.where.not(id: laboratory_subjects.pluck(:subject_id))
elsif sync_subject
laboratory_subject_ids = laboratory_subjects.pluck(:subject_id)
school_subject_ids = Subject.joins("join user_extensions on subjects.user_id=user_extensions.user_id").where(user_extensions: { school_id: school_id }).pluck(:id)
subject_ids = laboratory_subject_ids + school_subject_ids
Subject.where(id: subject_ids.uniq)
else
Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id })
end
end end
def all_courses def all_courses

@ -48,15 +48,9 @@ class SearchService < ApplicationService
end end
{ where: { id: shixun_ids } } { where: { id: shixun_ids } }
when 'subject' then when 'subject' then
if Laboratory.current.main_site? { where: { id: Laboratory.current.subjects.pluck(:id) } }
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{Laboratory.current.id}")
subject_ids = Subject.where.not(id: not_subject_ids).pluck(:id)
else
subject_ids = Laboratory.current.subjects.pluck(:id)
end
{ where: { id: subject_ids } }
when 'course' then when 'course' then
{ where: { laboratory_id: Laboratory.current.id } } { where: { id: Laboratory.current.all_courses } }
else else
{} {}
end end

@ -12,21 +12,12 @@ class SubjectSearchService < ApplicationService
# 全部实训/我的实训 # 全部实训/我的实训
type = params[:type] || "all" type = params[:type] || "all"
if type == "mine" @subjects = laboratory.subjects
@subjects = User.current.subjects.visible.unhidden
else
@subjects = Subject.visible.unhidden
end
# laboratory = Laboratory.find_by_subdomain(subdomain) if type == "mine"
# @subjects = @subjects.where(id: laboratory.subjects) if laboratory @subjects = @subjects.where(id: User.current.subjects).visible.unhidden
## 云上实验室过滤
if laboratory.main_site?
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{laboratory.id}")
@subjects = @subjects.where.not(id: not_subject_ids)
else else
@subjects = @subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: laboratory.id }) @subjects = @subjects.visible.unhidden
end end
Subject.search(keyword, search_options) Subject.search(keyword, search_options)

@ -24,33 +24,7 @@
<% if courses.present? %> <% if courses.present? %>
<% courses.each do |course| %> <% courses.each do |course| %>
<tr class="course-item-<%= course.id %>"> <tr class="course-item-<%= course.id %>">
<td><%= course.id %></td> <%= render 'admins/courses/shared/td', course: course %>
<td class="text-left">
<%= link_to(course.name, "/courses/#{course.id}", target: '_blank') %>
</td>
<td><%= course.course_members_count %></td>
<td><%= get_attachment_count(course, 0) %></td>
<td><%= course.course_homework_count(1) %></td>
<td><%= course.course_homework_count(3) %></td>
<td><%= course.course_homework_count(4) %></td>
<td><%= course.exercises_count %></td>
<td><%= course.evaluate_count %></td>
<td><%= course.is_public == 1 ? "--" : "√" %></td>
<td><%= course.is_end ? "已结束" : "正在进行" %></td>
<td><%= course.school&.name %></td>
<td><%= course.teacher&.real_name %></td>
<td><%= course.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td>
<%= check_box_tag :homepage_show,!course.homepage_show,course.homepage_show,remote:true,data:{id:course.id},class:"course-setting-form" %>
</td>
<td>
<%= check_box_tag :email_notify,!course.email_notify,course.email_notify,remote:true,data:{id:course.id},class:"course-setting-form" %>
</td>
<td class="action-container">
<% if course.is_delete == 0 %>
<%= delete_link '删除', admins_course_path(course, element: ".course-item-#{course.id}"), class: 'delete-course-action' %>
<% end %>
</td>
</tr> </tr>
<% end %> <% end %>
<% else %> <% else %>

@ -0,0 +1,27 @@
<td><%= course.id %></td>
<td class="text-left">
<%= link_to(course.name, "/courses/#{course.id}", target: '_blank') %>
</td>
<td><%= course.course_members_count %></td>
<td><%= get_attachment_count(course, 0) %></td>
<td><%= course.course_homework_count(1) %></td>
<td><%= course.course_homework_count(3) %></td>
<td><%= course.course_homework_count(4) %></td>
<td><%= course.exercises_count %></td>
<td><%= course.evaluate_count %></td>
<td><%= course.is_public == 1 ? "--" : "√" %></td>
<td><%= course.is_end ? "已结束" : "正在进行" %></td>
<td><%= course.school&.name %></td>
<td><%= course.teacher&.real_name %></td>
<td><%= course.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td>
<%= check_box_tag :homepage_show,!course.homepage_show,course.homepage_show,remote:true,data:{id:course.id},class:"course-setting-form" %>
</td>
<td>
<%= check_box_tag :email_notify,!course.email_notify,course.email_notify,remote:true,data:{id:course.id},class:"course-setting-form" %>
</td>
<td class="action-container">
<% if course.is_delete == 0 %>
<%= delete_link '删除', admins_course_path(course, element: ".course-item-#{course.id}"), class: 'delete-course-action' %>
<% end %>
</td>

@ -0,0 +1 @@
$("#course-item-<%= @course.id %>").html("<%= j render partial: "admins/courses/shared/td",locals: {course: @course} %>")

@ -31,7 +31,17 @@
<td><%= laboratory.created_at.strftime('%Y-%m-%d %H:%M') %></td> <td><%= laboratory.created_at.strftime('%Y-%m-%d %H:%M') %></td>
<td> <td>
<% if school.present? && laboratory.id != 1 %> <% if school.present? && laboratory.id != 1 %>
<%= check_box_tag :sync_course,!laboratory.sync_course,laboratory.sync_course,remote:true,data:{id:laboratory.id},class:"laboratory-sync-course" %> <%= check_box_tag :sync_course,!laboratory.sync_course,laboratory.sync_course,remote:true,data:{id:laboratory.id},class:"laboratory-sync-form" %>
<% end %>
</td>
<td>
<% if school.present? && laboratory.id != 1 %>
<%= check_box_tag :sync_subject,!laboratory.sync_subject,laboratory.sync_subject,remote:true,data:{id:laboratory.id},class:"laboratory-sync-form" %>
<% end %>
</td>
<td>
<% if school.present? && laboratory.id != 1 %>
<%= check_box_tag :sync_shixun,!laboratory.sync_shixun,laboratory.sync_shixun,remote:true,data:{id:laboratory.id},class:"laboratory-sync-form" %>
<% end %> <% end %>
</td> </td>
<td class="action-container"> <td class="action-container">

@ -3,10 +3,12 @@
<tr> <tr>
<th width="14%" class="text-left">单位名称</th> <th width="14%" class="text-left">单位名称</th>
<th width="16%" class="text-left">域名</th> <th width="16%" class="text-left">域名</th>
<th width="10%">统计链接</th> <th width="6%">统计链接</th>
<th width="22%">管理员</th> <th width="22%">管理员</th>
<th width="14%"><%= sort_tag('创建时间', name: 'id', path: admins_laboratories_path) %></th> <th width="10%"><%= sort_tag('创建时间', name: 'id', path: admins_laboratories_path) %></th>
<th width="6%" title="同步显示显示主站下该单位的课堂">同步课堂</th> <th width="4%" title="同步显示主站下该单位的课堂">同步课堂</th>
<th width="4%" title="同步显示主站下该单位用户创建的实践课程">同步实践课程</th>
<th width="4%" title="同步显示主站下该单位用户创建的实训">同步实训</th>
<th width="20%">操作</th> <th width="20%">操作</th>
</tr> </tr>
</thead> </thead>

@ -0,0 +1 @@
$(".laboratory-item-<%= @laboratory.id %>").html("<%= j render partial: "admins/laboratories/shared/laboratory_item",locals: {laboratory: @laboratory} %>")

@ -1090,7 +1090,7 @@ Rails.application.routes.draw do
post :drag, on: :collection post :drag, on: :collection
post :replace_image_url, on: :member post :replace_image_url, on: :member
end end
resources :laboratories, only: [:index, :create, :destroy] do resources :laboratories, only: [:index, :create, :destroy, :update] do
member do member do
get :shixuns_for_select get :shixuns_for_select
get :subjects_for_select get :subjects_for_select

@ -0,0 +1,6 @@
class AddSyncShixunSubjectToLaboratory < ActiveRecord::Migration[5.2]
def change
add_column :laboratories, :sync_subject, :boolean, default: 0
add_column :laboratories, :sync_shixun, :boolean, default: 0
end
end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save