From a07cc733eccb6b8f7eb18e4420a1c82b352d7c49 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 27 Sep 2019 09:53:40 +0800 Subject: [PATCH 1/2] ecs: api modify --- .../ecs/course_targets/with_achievement_methods.json.jbuilder | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 app/views/ecs/course_targets/with_achievement_methods.json.jbuilder diff --git a/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder b/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder new file mode 100644 index 000000000..689504ec3 --- /dev/null +++ b/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder @@ -0,0 +1,2 @@ + +json.course_targets @course_targets, partial: 'ecs/course_targets/shared/ec_course_target_with_achievement_methods', as: :ec_course_target From 40363b4d975045679173418ac15dae919314c1af Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 27 Sep 2019 10:08:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=87=91=E8=AF=BE=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E5=92=8C=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=9A=84=E7=AB=A0=E8=8A=82=E5=88=97=E8=A1=A8=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 3 +- app/controllers/exercises_controller.rb | 138 +++++++++--------- app/controllers/stages_controller.rb | 3 +- app/helpers/stages_helper.rb | 4 +- .../courses/online_learning.json.jbuilder | 2 +- app/views/stages/_stage.json.jbuilder | 2 +- app/views/stages/index.json.jbuilder | 2 +- 7 files changed, 77 insertions(+), 77 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 812a139dc..0e093460f 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -269,8 +269,9 @@ class CoursesController < ApplicationController def online_learning @subject = @course.subject - @stages = @course.course_stages + @stages = @course.course_stages.includes(:shixuns) @user = current_user + @myshixuns = @user.myshixuns.where(shixun_id: @course.course_stage_shixuns.pluck(:shixun_id)) @start_learning = @user_course_identity == Course::STUDENT && @course.learning?(current_user.id) end diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 3be35345e..28b5d84ef 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -25,85 +25,83 @@ class ExercisesController < ApplicationController include ExercisesHelper def index - ActiveRecord::Base.transaction do - begin - # 按发布时间或创建时间排序 - @exercises_all = @course.exercises - member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷 - @current_user_ = current_user - - # 课堂的学生人数 - @course_all_members = @course.students #当前课堂的全部学生 - @current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生 - - # exercises的不同用户群体的显示 - if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教 - @is_teacher_or = 1 - @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) - elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的 - @is_teacher_or = 2 - @member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0 - if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) - @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] - else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 - # 已发布 当前用户班级分组的 试卷id - not_exercise_ids = @course.exercise_group_settings.exercise_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:exercise_id) - @exercises = member_show_exercises.where.not(id: not_exercise_ids) - end - else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 - @is_teacher_or = 0 - @exercises = member_show_exercises.unified_setting + begin + # 按发布时间或创建时间排序 + @exercises_all = @course.exercises + member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷 + @current_user_ = current_user + + # 课堂的学生人数 + @course_all_members = @course.students #当前课堂的全部学生 + @current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生 + + # exercises的不同用户群体的显示 + if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教 + @is_teacher_or = 1 + @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) + elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的 + @is_teacher_or = 2 + @member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0 + if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) + @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] + else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 + # 已发布 当前用户班级分组的 试卷id + not_exercise_ids = @course.exercise_group_settings.exercise_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:exercise_id) + @exercises = member_show_exercises.where.not(id: not_exercise_ids) end + else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 + @is_teacher_or = 0 + @exercises = member_show_exercises.unified_setting + end - if @exercises.size > 0 - if params[:type].present? - choose_type = params[:type].to_i - ex_setting_ids = [] - if @is_teacher_or != 2 - @exercises = @exercises.where("exercise_status = #{choose_type}") - else - case choose_type - when 1 - ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_not_published.pluck(:exercise_id) - when 2 - ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}") - .where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id) - when 3 - ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_ended.pluck(:exercise_id) - end - unified_setting_ids = @exercises.unified_setting.where("exercise_status = #{choose_type}").pluck(:id) - ex_ids = (ex_setting_ids + unified_setting_ids).uniq - @exercises = @exercises.where(id: ex_ids) + if @exercises.size > 0 + if params[:type].present? + choose_type = params[:type].to_i + ex_setting_ids = [] + if @is_teacher_or != 2 + @exercises = @exercises.where("exercise_status = #{choose_type}") + else + case choose_type + when 1 + ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_not_published.pluck(:exercise_id) + when 2 + ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}") + .where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id) + when 3 + ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_ended.pluck(:exercise_id) end + unified_setting_ids = @exercises.unified_setting.where("exercise_status = #{choose_type}").pluck(:id) + ex_ids = (ex_setting_ids + unified_setting_ids).uniq + @exercises = @exercises.where(id: ex_ids) end + end - if params[:search].present? - search_type = params[:search].to_s.strip - @exercises = @exercises.exercise_search(search_type) - end - - @exercises_select_count = @exercises.size # 全部页面,需返回 - @exercises = @exercises.distinct.order( "IF(ISNULL(publish_time),0,1), publish_time DESC,created_at DESC") #出现错误 - - # 分页 - @page = params[:page] || 1 - @limit = params[:limit] || 15 - @exercises = @exercises.page(@page).per(@limit) - @exercises = @exercises&.includes(:published_settings) - else - @exercises = [] + if params[:search].present? + search_type = params[:search].to_s.strip + @exercises = @exercises.exercise_search(search_type) end - @course_all_members_count = @course_all_members.size #当前课堂的学生数 - @exercises_count = @exercises_all.size # 全部页面,需返回 - @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数 - @exercises_published_counts = @exercises_count - @exercises_unpublish_counts # 已发布的试卷数,包含已截止的 + @exercises_select_count = @exercises.size # 全部页面,需返回 + @exercises = @exercises.distinct.order( "IF(ISNULL(publish_time),0,1), publish_time DESC,created_at DESC") #出现错误 - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback + # 分页 + @page = params[:page] || 1 + @limit = params[:limit] || 15 + @exercises = @exercises.page(@page).per(@limit) + @exercises = @exercises&.includes(:published_settings) + else + @exercises = [] end + + @course_all_members_count = @course_all_members.size #当前课堂的学生数 + @exercises_count = @exercises_all.size # 全部页面,需返回 + @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数 + @exercises_published_counts = @exercises_count - @exercises_unpublish_counts # 已发布的试卷数,包含已截止的 + + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback end end diff --git a/app/controllers/stages_controller.rb b/app/controllers/stages_controller.rb index b0b072f83..0abd3c362 100644 --- a/app/controllers/stages_controller.rb +++ b/app/controllers/stages_controller.rb @@ -6,7 +6,8 @@ class StagesController < ApplicationController def index @user = current_user - @stages = @subject.stages + @stages = @subject.stages.includes(:shixuns) + @myshixuns = @user.myshixuns.where(shixun_id: @subject.stage_shixuns.pluck(:shixun_id)) end def create diff --git a/app/helpers/stages_helper.rb b/app/helpers/stages_helper.rb index e0df514e3..93c466c46 100644 --- a/app/helpers/stages_helper.rb +++ b/app/helpers/stages_helper.rb @@ -1,8 +1,8 @@ module StagesHelper # 章节实训的通关情况 - def stage_myshixun_status shixun, user - myshixun = Myshixun.where(user_id: user.id, shixun_id: shixun.id).take + def stage_myshixun_status myshixun + # myshixun = Myshixun.where(user_id: user.id, shixun_id: shixun.id).take myshixun.try(:status) == 1 ? 1 : 0 end diff --git a/app/views/courses/online_learning.json.jbuilder b/app/views/courses/online_learning.json.jbuilder index b48cd9e23..95b44238c 100644 --- a/app/views/courses/online_learning.json.jbuilder +++ b/app/views/courses/online_learning.json.jbuilder @@ -1,5 +1,5 @@ json.stages @stages do |stage| - json.partial! 'stages/stage', locals: {stage: stage, user:@user, subject:@subject} + json.partial! 'stages/stage', locals: {stage: stage, user: @user, subject: @subject, myshixuns: @myshixuns} end # json.description @subject&.description diff --git a/app/views/stages/_stage.json.jbuilder b/app/views/stages/_stage.json.jbuilder index db00ad844..e5d2be82d 100644 --- a/app/views/stages/_stage.json.jbuilder +++ b/app/views/stages/_stage.json.jbuilder @@ -15,7 +15,7 @@ json.shixuns_list do json.shixun_name shixun.name json.shixun_hidden shixun.hidden json.identifier shixun.identifier - json.complete_status stage_myshixun_status(shixun, user) + json.complete_status stage_myshixun_status(myshixuns.select{|ms| ms.shixun_id == shixun.id}.first) json.shixun_status stage_shixun_status(subject.status, shixun.status, shixun.hidden) end end \ No newline at end of file diff --git a/app/views/stages/index.json.jbuilder b/app/views/stages/index.json.jbuilder index d186088c4..b7c61d9cf 100644 --- a/app/views/stages/index.json.jbuilder +++ b/app/views/stages/index.json.jbuilder @@ -1,3 +1,3 @@ json.stages @stages do |stage| - json.partial! 'stage', locals: {stage: stage, user:@user, subject:@subject} + json.partial! 'stage', locals: {stage: stage, user: @user, subject: @subject, myshixuns: @myshixuns} end \ No newline at end of file