diff --git a/app/assets/javascripts/admins/carousels/index.js b/app/assets/javascripts/admins/carousels/index.js index 0f279f17e..fe665a35f 100644 --- a/app/assets/javascripts/admins/carousels/index.js +++ b/app/assets/javascripts/admins/carousels/index.js @@ -1,5 +1,7 @@ $(document).on('turbolinks:load', function() { if ($('body.admins-carousels-index-page').length > 0) { + var laboratoryId = $('#carousels-container').data('laboratoryId'); + // ------------ 保存链接 ----------- $('.carousels-card').on('click', '.save-data-btn', function(){ var $link = $(this); @@ -13,7 +15,7 @@ $(document).on('turbolinks:load', function() { $link.attr('disabled', true); $.ajax({ - url: '/admins/carousels/' + id, + url: '/admins/laboratories/' + laboratoryId + '/carousels/' + id, method: 'PATCH', dataType: 'json', data: { link: link, name: name }, @@ -34,7 +36,7 @@ $(document).on('turbolinks:load', function() { $checkbox.attr('disabled', true); $.ajax({ - url: '/admins/carousels/' + id, + url: '/admins/laboratories/' + laboratoryId + '/carousels/' + id, method: 'PATCH', dataType: 'json', data: { status: checked }, @@ -60,7 +62,7 @@ $(document).on('turbolinks:load', function() { var insertId = $(sibling).data('id') || ''; $.ajax({ - url: '/admins/carousels/drag', + url: '/admins/laboratories/' + laboratoryId + '/carousels/drag', method: 'POST', dataType: 'json', data: { move_id: moveId, after_id: insertId }, diff --git a/app/assets/stylesheets/admins/common.scss b/app/assets/stylesheets/admins/common.scss index adad72997..aabe6085c 100644 --- a/app/assets/stylesheets/admins/common.scss +++ b/app/assets/stylesheets/admins/common.scss @@ -48,9 +48,15 @@ } .action-container { - .action { + & > .action { padding: 0 3px; } + + .more-action-dropdown { + .dropdown-item { + font-size: 14px; + } + } } /* 分页 */ diff --git a/app/controllers/admins/carousels_controller.rb b/app/controllers/admins/carousels_controller.rb index cd693d2fd..ad6af7649 100644 --- a/app/controllers/admins/carousels_controller.rb +++ b/app/controllers/admins/carousels_controller.rb @@ -1,15 +1,17 @@ class Admins::CarouselsController < Admins::BaseController before_action :convert_file!, only: [:create] + helper_method :current_laboratory + def index - @images = PortalImage.order(position: :asc) + @images = current_laboratory.portal_images.order(position: :asc) end def create - position = PortalImage.count + 1 + position = current_laboratory.portal_images.count + 1 ActiveRecord::Base.transaction do - image = PortalImage.create!(create_params.merge(position: position)) + image = current_laboratory.portal_images.create!(create_params.merge(position: position)) file_path = Util::FileManage.disk_filename('PortalImage', image.id) File.delete(file_path) if File.exist?(file_path) # 删除之前的文件 @@ -17,7 +19,7 @@ class Admins::CarouselsController < Admins::BaseController end flash[:success] = '保存成功' - redirect_to admins_carousels_path + redirect_to admins_laboratory_carousels_path(current_laboratory) end def update @@ -29,7 +31,7 @@ class Admins::CarouselsController < Admins::BaseController ActiveRecord::Base.transaction do current_image.destroy! # 前移 - PortalImage.where('position > ?', current_image.position) + current_laboratory.portal_images.where('position > ?', current_image.position) .update_all('position = position - 1') file_path = Util::FileManage.disk_filename('PortalImage', current_image.id) @@ -39,10 +41,10 @@ class Admins::CarouselsController < Admins::BaseController end def drag - move = PortalImage.find_by(id: params[:move_id]) - after = PortalImage.find_by(id: params[:after_id]) + move = current_laboratory.portal_images.find_by(id: params[:move_id]) + after = current_laboratory.portal_images.find_by(id: params[:after_id]) - Admins::DragPortalImageService.call(move, after) + Admins::DragPortalImageService.call(current_laboratory, move, after) render_ok rescue Admins::DragPortalImageService::Error => e render_error(e.message) @@ -50,8 +52,12 @@ class Admins::CarouselsController < Admins::BaseController private + def current_laboratory + @_current_laboratory ||= Laboratory.find(params[:laboratory_id]) + end + def current_image - @_current_image ||= PortalImage.find(params[:id]) + @_current_image ||= current_laboratory.portal_images.find(params[:id]) end def create_params diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb index 34dac7350..77159fdaf 100644 --- a/app/controllers/competitions/competitions_controller.rb +++ b/app/controllers/competitions/competitions_controller.rb @@ -1,5 +1,6 @@ class Competitions::CompetitionsController < Competitions::BaseController skip_before_action :require_login + before_action :allow_visit, except: [:index] def index # 已上架 或者 即将上架 @@ -24,10 +25,10 @@ class Competitions::CompetitionsController < Competitions::BaseController end def show - unless current_competition.published? || admin_or_business? - render_forbidden - return - end + end + + def common_header + end private @@ -35,4 +36,11 @@ class Competitions::CompetitionsController < Competitions::BaseController def current_competition @_current_competition ||= Competition.find_by!(identifier: params[:id]) end + + def allow_visit + unless current_competition.published? || admin_or_business? + render_forbidden + return + end + end end \ No newline at end of file diff --git a/app/controllers/concerns/laboratory_helper.rb b/app/controllers/concerns/laboratory_helper.rb index fbb18b36d..08a75fd79 100644 --- a/app/controllers/concerns/laboratory_helper.rb +++ b/app/controllers/concerns/laboratory_helper.rb @@ -2,6 +2,7 @@ module LaboratoryHelper extend ActiveSupport::Concern included do + helper_method :current_laboratory helper_method :default_setting end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0b3e35519..a1bd16e94 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -583,6 +583,8 @@ class CoursesController < ApplicationController # 学生身份的处理 student_member = course_members.where(role: %i[STUDENT]).take + + # 不存在则创建学生身份 if params[:roles].include?("STUDENT") && student_member.blank? correspond_teacher_exist = CourseMember.exists?(user_id: params[:user_id], is_active: 1, course_id: @course.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]) new_student = CourseMember.new(user_id: params[:user_id], course_id: @course.id, role: 4) @@ -597,6 +599,9 @@ class CoursesController < ApplicationController student_member.destroy! CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [params[:user_id]]) # CourseDeleteStudentNotifyJob.perform_later(@course.id, [params[:user_id]], current_user.id) + elsif params[:roles].include?("STUDENT") && student_member.present? && !params[:roles].include?("PROFESSOR") && !params[:roles].include?("ASSISTANT_PROFESSOR") + # 学生身份存在且学生没有教师身份时更新is_active + student_member.update_attributes!(is_active: 1) end normal_status(0, "修改成功") diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 2ed82f1b5..72d6118bf 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -2,10 +2,10 @@ class HomeController < ApplicationController def index # banner图 - images = PortalImage.where(status: true).order("position asc") + images = current_laboratory.portal_images.only_online.order(position: :asc) @images_url = [] images.each do |image| - @images_url << {path: image.link, image_url: Util::FileManage.disk_file_url('PortalImage', image.id)} + @images_url << {path: image.link, image_url: Util::FileManage.source_disk_file_url(image)} end # 目录分级 diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 0e2628c3e..869ba27f6 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,5 +1,5 @@ class MainController < ApplicationController def index - render file: 'public/react/build/index.html', :layout => false + render file: 'public/react/build/index', formats: [:html] end end \ No newline at end of file diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index e13f754be..9a62e6b1d 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,14 +115,27 @@ module ExercisesHelper if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率 + end + # if ex.question_type != Exercise::MULTIPLE + # ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 + # percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率 + # else + # multiple_score = 0 + # user_ids.each do |user_id| + # ex_answer_score = ex_answers.select{|answer| answer.user_id == user_id}&.first&.score.to_f + # multiple_score += ex_answer_score + # end + # percent = (ex_total_score == 0.0 ? 0.0 : (multiple_score / ex_total_score.to_f).round(3) * 100) #正确率 + # end + question_answer_infos = [] if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 ex_choices = ex.exercise_choices standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 - # right_users_count = 0 - # 该问题的正确率 + right_users_count = 0 + #该问题的正确率 if ex.question_type == Exercise::MULTIPLE #多选题 right_user_ids = user_ids standard_answer.each do |choice_position| @@ -130,10 +143,13 @@ module ExercisesHelper right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id) end right_users_count = right_user_ids.size + # right_users_scores = right_users_count * ex&.question_score.to_f else #单选题和判断题 standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first&.id right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size + # right_users_scores = right_users_count * ex&.question_score.to_f end + # percent = (ex_total_score == 0.0 ? 0.0 : (right_users_scores / ex_total_score.to_f).round(3) * 100) #正确率 percent = commit_user_ids > 0 ? (right_users_count / commit_user_ids.to_f).round(3)*100 : 0.0 @@ -159,6 +175,7 @@ module ExercisesHelper null_stand_choice = null_standard_answer.pluck(:exercise_choice_id) #一个exercise_choice_id可能对应多个answer_text null_stand_text = null_standard_answer.pluck(:answer_text) standard_answer_count = 0 + each_null_score = null_stand_choice.size > 0 ? (ex&.question_score.to_f / null_stand_choice.uniq.size).round(3) : 0.0 all_user_count = 0 null_stand_choice.each_with_index do |s,index| user_count = 0 @@ -181,7 +198,10 @@ module ExercisesHelper all_user_count += user_count standard_answer_count += 1 end - percent = commit_user_ids > 0 ? (all_user_count / commit_user_ids.to_f).round(3)*100 : 0.0 + answer_user_score = all_user_count * each_null_score + percent = (ex_total_score == 0.0 ? 0.0 : (answer_user_score / ex_total_score.to_f).round(3) * 100) #正确率 + + # percent = commit_user_ids > 0 ? (all_user_count / commit_user_ids.to_f).round(3)*100 : 0.0 user_wrong_count = (effictive_users_count - all_user_count ) diff --git a/app/libs/hot_search_keyword.rb b/app/libs/hot_search_keyword.rb index e222bf3a7..f026142cb 100644 --- a/app/libs/hot_search_keyword.rb +++ b/app/libs/hot_search_keyword.rb @@ -1,3 +1,4 @@ +# 基于Redis实现热门搜索关键字 class HotSearchKeyword class << self def add(keyword) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index fc2dd3ea4..def3b6b0d 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -37,6 +37,7 @@ class HomeworkCommon < ApplicationRecord validates :name, length: { maximum: 60 } validates :description, length: { maximum: 15000 } + validates :explanation, length: { maximum: 5000 } validates :reference_answer, length: { maximum: 15000 } # after_update :update_activity diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index f319ace80..00f5adabf 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -6,6 +6,8 @@ class Laboratory < ApplicationRecord has_one :laboratory_setting, dependent: :destroy + has_many :portal_images, dependent: :destroy + validates :identifier, uniqueness: { case_sensitive: false }, allow_nil: true def site diff --git a/app/models/portal_image.rb b/app/models/portal_image.rb index a3fd71bb5..b07214c77 100644 --- a/app/models/portal_image.rb +++ b/app/models/portal_image.rb @@ -1,4 +1,8 @@ class PortalImage < ApplicationRecord + belongs_to :laboratory + + scope :only_online, -> { where(status: true) } + def online? status? end diff --git a/app/services/admins/drag_portal_image_service.rb b/app/services/admins/drag_portal_image_service.rb index 9f8adea38..5555c08b2 100644 --- a/app/services/admins/drag_portal_image_service.rb +++ b/app/services/admins/drag_portal_image_service.rb @@ -1,9 +1,10 @@ class Admins::DragPortalImageService < ApplicationService Error = Class.new(StandardError) - attr_reader :move, :after + attr_reader :laboratory, :move, :after - def initialize(move, after) + def initialize(laboratory, move, after) + @laboratory = laboratory @move = move @after = after # 移动后下一个位置的元素 end @@ -11,7 +12,7 @@ class Admins::DragPortalImageService < ApplicationService def call return if move.position + 1 == after&.position # 未移动 - images = PortalImage.all + images = laboratory.portal_images ActiveRecord::Base.transaction do if after.blank? || move.id == after.id # 移动至末尾 @@ -31,5 +32,4 @@ class Admins::DragPortalImageService < ApplicationService end end end - end \ No newline at end of file diff --git a/app/views/admins/carousels/index.html.erb b/app/views/admins/carousels/index.html.erb index 89c224784..299d1dcfd 100644 --- a/app/views/admins/carousels/index.html.erb +++ b/app/views/admins/carousels/index.html.erb @@ -1,5 +1,6 @@ <% define_admin_breadcrumbs do + add_admin_breadcrumb('云上实验室', admins_laboratories_path) add_admin_breadcrumb('轮播图') end %> @@ -9,7 +10,7 @@ 首页轮播图(拖动排序) <%= javascript_void_link '添加', class: 'btn btn-primary btn-sm add-btn', data: { toggle: 'modal', target: '.admin-add-carousel-modal' } %> -