diff --git a/app/controllers/attendances_controller.rb b/app/controllers/attendances_controller.rb index c8287f413..936bef188 100644 --- a/app/controllers/attendances_controller.rb +++ b/app/controllers/attendances_controller.rb @@ -2,6 +2,7 @@ class AttendancesController < ApplicationController before_action :require_login before_action :find_course, only: [:index, :statistics] + before_action :find_attendance, except: [:index, :statistics] before_action :user_course_identity def index @@ -66,9 +67,53 @@ class AttendancesController < ApplicationController @avg_leave_rate = data[:avg_leave_rate] end + def edit + @groups = @course.course_groups.where(id: @attendance.course_attendance_groups.pluck(:course_group_id)) + end + + def update + tip_exception(403, "") unless @user_course_identity < Course::PROFESSOR || @attendance.user_id == current_user.id + a_end_time = "#{@attendance.attendance_date} #{@attendance.end_time}".to_time + new_end_time = "#{params[:attendance_date]} #{params[:end_time]}".to_time + @attendance.update!(update_params) + + # 如果历史签到变为了正在签到,将未创建的学生签到数据补上 + if a_end_time < Time.current && new_end_time > Time.current + create_absence_student_data + end + render_ok + end + private def find_attendance @attendance = CourseAttendance.find params[:id] @course = @attendance.course end + + def update_params + params.permit(:name, :mode, :attendance_date, :start_time, :end_time) + end + + def create_absence_student_data + group_ids = @attendance.course_attendance_groups.pluck(:course_group_id) + if group_ids.include?(0) + students = @course.students + else + students = @course.students.where(course_group_id: group_ids) + end + + none_users = students.where.not(user_id: @attendance.course_member_attendances.pluck(:user_id)) + + attrs = %i[course_attendance_id user_id course_member_id course_id course_group_id created_at updated_at] + + same_attrs = {course_attendance_id: attendance.id, course_id: course.id} + + CourseMemberAttendance.bulk_insert(*attrs) do |worker| + + none_users.each do |student| + next if @attendance.course_member_attendances.exists?(user_id: student.user_id) + worker.add same_attrs.merge(user_id: student.user_id, course_member_id: student.id, course_group_id: student.course_group_id) + end + end + end end \ No newline at end of file diff --git a/app/controllers/course_videos_controller.rb b/app/controllers/course_videos_controller.rb index fe01c6226..3a0b09b4e 100644 --- a/app/controllers/course_videos_controller.rb +++ b/app/controllers/course_videos_controller.rb @@ -25,7 +25,7 @@ class CourseVideosController < ApplicationController course_video = CourseVideo.find(@video.id) @watch_course_videos = course_video.watch_course_videos.joins(" - JOIN watch_video_histories ON watch_video_histories.watch_course_video_id = watch_course_videos.id + JOIN watch_video_histories ON watch_video_histories.watch_course_video_id = watch_course_videos.id AND watch_video_histories.end_at IS NOT NULL JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4 ").group("watch_video_histories.watch_course_video_id").where("watch_course_videos.end_at IS NOT NULL").select("watch_course_videos.id") @@ -35,7 +35,7 @@ class CourseVideosController < ApplicationController @watch_course_videos = @watch_course_videos.where("course_members.course_group_id = ?", params[:group_id]) end - @watch_course_videos = @watch_course_videos.select("count(watch_video_histories.id) AS freq, watch_course_videos.*") + @watch_course_videos = @watch_course_videos.select("count(watch_course_videos.course_video_id) AS freq, watch_course_videos.*") if params[:order].present? key = params[:order].split("-") diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index f6868cfa2..4fc8d1350 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1491,10 +1491,11 @@ class CoursesController < ApplicationController @videos = CourseVideo.joins(" JOIN videos ON course_videos.course_id = #{@course.id} AND videos.id = course_videos.video_id LEFT JOIN ( - SELECT watch_course_videos.course_video_id, SUM(watch_course_videos.total_duration) AS time, COUNT(watch_course_videos.course_video_id) AS num + SELECT watch_course_videos.course_video_id, SUM(watch_course_videos.total_duration) AS time, COUNT(watch_video_histories.watch_course_video_id) AS num FROM watch_course_videos JOIN course_videos ON course_videos.id = watch_course_videos.course_video_id AND watch_course_videos.end_at IS NOT NULL JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4 + JOIN watch_video_histories ON watch_course_videos.id = watch_video_histories.watch_course_video_id AND watch_video_histories.end_at IS NOT NULL WHERE course_videos.course_id = #{@course.id} GROUP BY watch_course_videos.course_video_id ) AS hisotries ON hisotries.course_video_id = course_videos.id").select("course_videos.id") @@ -1521,16 +1522,19 @@ class CoursesController < ApplicationController JOIN videos ON course_videos.course_id = #{@course.id} AND videos.id = course_videos.video_id JOIN watch_course_videos ON course_videos.id = watch_course_videos.course_video_id AND watch_course_videos.user_id = #{current_user.id} JOIN ( - SELECT watch_course_videos.course_video_id, COUNT(watch_course_videos.course_video_id) AS num + SELECT watch_course_videos.course_video_id, COUNT(watch_video_histories.watch_course_video_id) AS num FROM watch_course_videos JOIN course_videos ON course_videos.id = watch_course_videos.course_video_id JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4 + JOIN watch_video_histories ON watch_course_videos.id = watch_video_histories.watch_course_video_id AND watch_video_histories.end_at IS NOT NULL WHERE course_videos.course_id = #{@course.id} AND watch_course_videos.user_id = #{current_user.id} AND watch_course_videos.end_at IS NOT NULL GROUP BY watch_course_videos.course_video_id ) AS hisotries ON hisotries.course_video_id = course_videos.id").select("course_videos.id") @count = @videos.count + @videos = @videos.includes(video: :user) + if params[:order].present? key = params[:order].split("-") if ["freq", 'total_duration'].include?(key.first) && ["desc", "asc"].include?(key.last) @@ -1538,24 +1542,32 @@ class CoursesController < ApplicationController end end - @videos = @videos.select("course_videos.id, watch_course_videos.start_at, watch_course_videos.total_duration, watch_course_videos.end_at, watch_course_videos.is_finished, videos.title, IFNULL(hisotries.num,0) AS freq") + @videos = @videos.select("course_videos.id, course_videos.video_id, watch_course_videos.start_at, watch_course_videos.total_duration, watch_course_videos.end_at, watch_course_videos.is_finished, videos.title, IFNULL(hisotries.num,0) AS freq") @videos = paginate @videos end # 课堂视频的统计总览 def watch_statics - course_videos = @course.course_videos.joins(:watch_course_videos).joins(" - JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4 - ").where("watch_course_videos.end_at IS NOT NULL") - @total_duration = course_videos.sum(:total_duration).round(0) - @frequencies = course_videos.joins("JOIN watch_video_histories ON watch_course_videos.id = watch_video_histories.watch_course_video_id").count(:id) - @people_num = course_videos.count(:id) + course_videos = @course.course_videos.joins(:watch_course_videos).joins("JOIN course_members ON course_members.user_id = watch_course_videos.user_id AND course_members.course_id = #{@course.id} AND role = 4").where("watch_course_videos.end_at IS NOT NULL") + + if params[:all].present? + return normal_status(403, "你没有权限操作") unless current_user.teacher_of_course?(@course) + @total_duration = course_videos.sum(:total_duration).round(0) + @frequencies = course_videos.joins("JOIN watch_video_histories ON watch_course_videos.id = watch_video_histories.watch_course_video_id AND watch_video_histories.end_at IS NOT NULL").count(:id) + @num = course_videos.count(:id) + + else + course_videos = course_videos.where("course_members.user_id = #{current_user.id}") + @total_duration = course_videos.sum(:total_duration).round(0) + @frequencies = course_videos.joins("JOIN watch_video_histories ON watch_course_videos.id = watch_video_histories.watch_course_video_id AND watch_video_histories.end_at IS NOT NULL").count(:id) + @num = course_videos.count(:id) + end render json: { total_duration: @total_duration, - freq: @frequencies, - people_num: @people_num, - begin_at: '2020-03-13 24:00' + freq: @frequencies, + num: @num, + begin_at: '2020-03-13 24:00' } end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 8e6356201..74f7c074a 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -32,8 +32,7 @@ class FilesController < ApplicationController end end - @attachments = @attachments.includes(author: [:user_extension, :course_members]) - .ordered(sort: sort.to_i, sort_type: sort_type.strip) + @attachments = @attachments.ordered(sort: sort.to_i, sort_type: sort_type.strip) @total_count = @attachments.size @unlink_count = @attachments.no_link.size @@ -59,7 +58,8 @@ class FilesController < ApplicationController @attachments = @attachments.no_link end - @attachments = @attachments.page(@page).per(@page_size) + @attachments = @attachments.includes(:course_second_category, author: [:user_extension, :course_members]) + .page(@page).per(@page_size) end def bulk_publish diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 6c9de071d..8770a6519 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -477,6 +477,8 @@ class StudentWorksController < ApplicationController @user_evaluate_count = 0 end + @view_tpi = ((@user_course_identity < Course::STUDENT && current_user.is_certification_teacher) || current_user.admin_or_business?) && @work.myshixun.present? + # 图形效率图的数据 @echart_data = student_efficiency(@homework, @work) if @work.myshixun end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 001883fb6..dc8b44d1e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -28,6 +28,7 @@ class Attachment < ApplicationRecord scope :no_link, -> {where(link: nil)} validates_length_of :description, maximum: 100, message: "不能超过100个字符" + validates :link, format: { with: CustomRegexp::URL, message: "必须为网址超链接" }, allow_blank: true DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) diff --git a/app/views/attendances/edit.json.jbuilder b/app/views/attendances/edit.json.jbuilder new file mode 100644 index 000000000..77d2b09f3 --- /dev/null +++ b/app/views/attendances/edit.json.jbuilder @@ -0,0 +1,4 @@ +json.(@attendance, :name, :mode, :attendance_date, :start_time, :end_time) +json.groups @groups do |group| + json.(group, :id, :name) +end \ No newline at end of file diff --git a/app/views/courses/attahcment_category_list.json.jbuilder b/app/views/courses/attahcment_category_list.json.jbuilder index af83890a9..dae54264a 100644 --- a/app/views/courses/attahcment_category_list.json.jbuilder +++ b/app/views/courses/attahcment_category_list.json.jbuilder @@ -2,7 +2,7 @@ json.has_course_groups @has_course_groups json.course_modules do json.array! @course_modules do |course_module| json.value course_module.id - json.title course_module.module_name + json.title course_module.module_name.to_s + "(根目录)" json.children course_module.first_categories do |category| json.title category.name json.value category.id diff --git a/app/views/courses/own_watch_histories.json.jbuilder b/app/views/courses/own_watch_histories.json.jbuilder index cc3b31eae..c3b8b8ffa 100644 --- a/app/views/courses/own_watch_histories.json.jbuilder +++ b/app/views/courses/own_watch_histories.json.jbuilder @@ -1,7 +1,7 @@ json.data do json.array! @videos.each do |d| json.title d.title - json.user_name @current_user&.real_name + json.user_name d.video.user&.real_name json.is_finished d.is_finished ? true : false json.total_duration d.total_duration.round(0) json.freq d['freq'] diff --git a/app/views/files/index.json.jbuilder b/app/views/files/index.json.jbuilder index 07430cd7b..f1b3f26d0 100644 --- a/app/views/files/index.json.jbuilder +++ b/app/views/files/index.json.jbuilder @@ -17,7 +17,7 @@ json.data do end # json.partial! "files/course_groups", attachment_group_settings: attachment.attachment_group_settings json.category_id attachment.course_second_category_id - unless @parent_category_id.present? && @parent_category_id != 0 + if (@parent_category_id.blank? || @parent_category_id != 0) && attachment.course_second_category&.parent_id.to_i != 0 json.category_name attachment.course_second_category&.name end end diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index bd618c2d4..adf0a2ea5 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -87,4 +87,6 @@ if @shixun end end +json.view_tpi @view_tpi + diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index 4c5c808ac..eac113ee0 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -64,6 +64,7 @@ zh-CN: description: '章节描述' attachment: description: '资源描述' + link: '链接' message: subject: '标题' message_detail: diff --git a/public/images/qiandao/studentbz1.png b/public/images/qiandao/studentbz1.png new file mode 100755 index 000000000..fa66f35db Binary files /dev/null and b/public/images/qiandao/studentbz1.png differ diff --git a/public/images/qiandao/studentbz2.png b/public/images/qiandao/studentbz2.png new file mode 100755 index 000000000..bf694e9c6 Binary files /dev/null and b/public/images/qiandao/studentbz2.png differ diff --git a/public/images/qiandao/studentbz3.png b/public/images/qiandao/studentbz3.png new file mode 100755 index 000000000..984f61862 Binary files /dev/null and b/public/images/qiandao/studentbz3.png differ diff --git a/public/react/public/css/demo_index.html b/public/react/public/css/demo_index.html index 7a6d6b5e8..8b88a36ec 100644 --- a/public/react/public/css/demo_index.html +++ b/public/react/public/css/demo_index.html @@ -30,6 +30,12 @@