diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index c5ad7a94c..3ed71746d 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1117,7 +1117,7 @@ class HomeworkCommonsController < ApplicationController def choose_category @main_catrgory = @course.course_modules.where(module_type: "shixun_homework") - @homework_category = @main_catrgory.take.course_second_categories + @homework_category = @main_catrgory.take.course_second_categories.includes(:homework_commons) end # 实训作业移动到目录 diff --git a/app/models/course_second_category.rb b/app/models/course_second_category.rb index 963367e0b..84b47e27f 100644 --- a/app/models/course_second_category.rb +++ b/app/models/course_second_category.rb @@ -12,4 +12,13 @@ class CourseSecondCategory < ApplicationRecord category_type == "graduation" && name == "毕设任务" ? "graduation_tasks" : category_type ) end + + def homework_publish_count + homework_commons.select{|homework| homework.publish_time.present? && homework.publish_time <= Time.now}.size + end + + def homework_unpublish_count + homework_commons.select{|homework| homework.publish_time.nil? || homework.publish_time > Time.now}.size + end + end diff --git a/app/views/homework_commons/_second_category.json.jbuilder b/app/views/homework_commons/_second_category.json.jbuilder index b584abecc..c6dfa76a0 100644 --- a/app/views/homework_commons/_second_category.json.jbuilder +++ b/app/views/homework_commons/_second_category.json.jbuilder @@ -5,4 +5,7 @@ end json.homework_category homework_category do |category| json.category_id category.id json.category_name category.name + json.publish_count category.homework_publish_count + json.unpublish_count category.homework_unpublish_count + json.all_count category.homework_commons.size end \ No newline at end of file