diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3283595e5..8d2c3579a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -30,14 +30,14 @@ class CoursesController < ApplicationController :informs, :update_informs, :online_learning, :update_task_position, :tasks_list, :join_excellent_course, :export_couser_info, :export_member_act_score, :new_informs, :delete_informs, :change_member_role, :course_groups, :join_course_group, :statistics, - :work_score, :act_score, :calculate_all_shixun_scores] + :work_score, :act_score, :calculate_all_shixun_scores, :move_to_category] before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course, :search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list] before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate, :transfer_to_course_group, :delete_from_course, :export_member_scores_excel, :search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher, :export_couser_info, :export_member_act_score, - :update_informs, :new_informs, :delete_informs, :switch_to_student] + :update_informs, :new_informs, :delete_informs, :switch_to_student, :move_to_category] before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin, :set_course_group, :create_group_by_importing_file, :update_task_position, :tasks_list] @@ -118,6 +118,21 @@ class CoursesController < ApplicationController render_ok end + # 视频移动到目录 + def move_to_category + tip_exception("请选择要移动的目录") if params[:new_category_id].blank? + + category = @course.course_second_categories.find_by(id: params[:new_category_id]) + if params[:new_category_id].to_i == 0 || category.present? + videos = @course.course_videos.where(id: params[:video_ids]) + + videos.update_all(course_second_category_id: params[:new_category_id]) + normal_status(0, "操作成功") + else + normal_status(-1, "目录不存在") + end + end + def visits_plus_one new_visits = @course.visits + 1 @course.update_visits(new_visits) @@ -1259,7 +1274,7 @@ class CoursesController < ApplicationController @is_teacher = @user_course_identity < Course::ASSISTANT_PROFESSOR @course_modules = @course.course_modules.where(hidden: 0) @hidden_modules = @course.course_modules.where(hidden: 1) - @second_category_type = ["shixun_homework", "graduation", "attachment", "board", "course_group"] + @second_category_type = ["shixun_homework", "graduation", "attachment", "board", "course_group", "video"] end def board_list diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index ab460596a..cb0d9bc35 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -6,7 +6,7 @@ class HomeworkCommonsController < ApplicationController before_action :require_login, :check_auth, except: [:index, :choose_category] before_action :find_course, only: [:index, :create, :new, :shixuns, :subjects, :create_shixun_homework, :publish_homework, - :end_homework, :set_public, :choose_category, :move_to_category, :choose_category, + :end_homework, :set_public, :move_to_category, :choose_category, :create_subject_homework, :multi_destroy, :add_to_homework_bank] before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :show_comment, :settings, :works_list, :update_settings, diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 0e79f11de..e9d6e4b06 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -87,16 +87,18 @@ module CoursesHelper # 子目录对应的url def category_url category, course case category.category_type - when "shixun_homework" - "/courses/#{course.id}/shixun_homework/#{category.id}" - when "graduation" - if category.name == "毕设选题" - "/courses/#{course.id}/graduation_topics/#{category.course_module_id}" - else - "/courses/#{course.id}/graduation_tasks/#{category.course_module_id}" - end - when "attachment" - "/courses/#{course.id}/file/#{category.id}" + when "shixun_homework" + "/courses/#{course.id}/shixun_homework/#{category.id}" + when "graduation" + if category.name == "毕设选题" + "/courses/#{course.id}/graduation_topics/#{category.course_module_id}" + else + "/courses/#{course.id}/graduation_tasks/#{category.course_module_id}" + end + when "attachment" + "/courses/#{course.id}/file/#{category.id}" + when "video" + "/courses/#{course.id}/course_videos/#{category.id}" end end @@ -113,6 +115,8 @@ module CoursesHelper end when "attachment" get_attachment_count(course, category.id) + when "video" + get_video_count(course, category.id) end end @@ -237,6 +241,11 @@ module CoursesHelper category_id.to_i == 0 ? course.attachments.size : course.attachments.where(course_second_category_id: category_id).size end + # 获取课堂的视频数 + def get_video_count(course, category_id) + category_id.to_i == 0 ? course.course_videos.size : course.course_videos.where(course_second_category_id: category_id).size + end + # 获取课堂的作业数 def get_homework_commons_count(course, type, category_id) category_id == 0 ? HomeworkCommon.where(course_id: course.id, homework_type: type).size : diff --git a/config/routes.rb b/config/routes.rb index 2bbdd6c3c..1f9d4cfc4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -524,6 +524,7 @@ Rails.application.routes.draw do get 'statistics' get 'course_videos' delete 'delete_course_video' + post :move_to_category post :inform_up post :inform_down get :calculate_all_shixun_scores diff --git a/db/migrate/20200309015735_add_course_second_category_id_to_course_videos.rb b/db/migrate/20200309015735_add_course_second_category_id_to_course_videos.rb new file mode 100644 index 000000000..cdc2dcd20 --- /dev/null +++ b/db/migrate/20200309015735_add_course_second_category_id_to_course_videos.rb @@ -0,0 +1,5 @@ +class AddCourseSecondCategoryIdToCourseVideos < ActiveRecord::Migration[5.2] + def change + add_column :course_videos, :course_second_category_id, :integer, index: true, default: 0 + end +end