Merge branches 'PCqiandao' and 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into PCqiandao

PCqiandao
杨树明 5 years ago
commit 300579e7e9

@ -18,11 +18,23 @@ class FilesController < ApplicationController
sort_type = params[:sort_type] || 'created_on' # created_on时间排序 downloads下载次数排序; quotes: 引用次数排序 sort_type = params[:sort_type] || 'created_on' # created_on时间排序 downloads下载次数排序; quotes: 引用次数排序
@course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id @course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id
@user = current_user @user = current_user
@attachments = @course_second_category_id.to_i == 0 ? @course.attachments.includes(:course_second_category) : @course.attachments.by_course_second_category_id(@course_second_category_id) get_category(@course, @course_second_category_id)
# 主目录显示所有资源,一级目录显示一级和所属二级目录的资源,二级目录只显示该目录下的资源
if @course_second_category_id.to_i == 0
@attachments = @course.attachments.includes(:course_second_category)
else
if @parent_category_id == 0
category_ids = [@category_id] + @category.children.pluck(:id)
@attachments = @course.attachments.where(course_second_category_id: category_ids)
else
@attachments = @course.attachments.by_course_second_category_id(@course_second_category_id)
end
end
@attachments = @attachments.includes(author: [:user_extension, :course_members]) @attachments = @attachments.includes(author: [:user_extension, :course_members])
.ordered(sort: sort.to_i, sort_type: sort_type.strip) .ordered(sort: sort.to_i, sort_type: sort_type.strip)
get_category(@course, @course_second_category_id)
@total_count = @attachments.size @total_count = @attachments.size
@unlink_count = @attachments.no_link.size @unlink_count = @attachments.no_link.size
@ -354,9 +366,10 @@ class FilesController < ApplicationController
@category_id = category.try(:id) @category_id = category.try(:id)
@category_name = category.try(:module_name) @category_name = category.try(:module_name)
else else
category = CourseSecondCategory.find category_id @category = CourseSecondCategory.find category_id
@category_id = category.try(:id) @category_id = category.try(:id)
@category_name = category.try(:name) @category_name = category.try(:name)
@parent_category_id = category&.parent_id.to_i
end end
end end

@ -3,8 +3,11 @@ json.course_modules do
json.array! @course_modules do |course_module| json.array! @course_modules do |course_module|
json.id course_module.id json.id course_module.id
json.module_name course_module.module_name json.module_name course_module.module_name
json.course_second_categories do json.course_second_categories course_module.first_categories do |category|
json.array! course_module.course_second_categories, :id, :name json.(category, :id, :name)
json.course_third_categories category.children do |child|
json.(child, :id, :name)
end
end end
end end
end end

@ -7,6 +7,7 @@ json.data do
json.unpublish_count @unpublish_count json.unpublish_count @unpublish_count
json.unlink_count @unlink_count json.unlink_count @unlink_count
json.course_is_public @course.is_public? json.course_is_public @course.is_public?
json.parent_category_id @parent_category_id
json.files do json.files do
json.array! @attachments do |attachment| json.array! @attachments do |attachment|
json.is_history_file attachment.attachment_histories.count > 0 #是否有历史文件 json.is_history_file attachment.attachment_histories.count > 0 #是否有历史文件
@ -16,7 +17,7 @@ json.data do
end end
# json.partial! "files/course_groups", attachment_group_settings: attachment.attachment_group_settings # json.partial! "files/course_groups", attachment_group_settings: attachment.attachment_group_settings
json.category_id attachment.course_second_category_id json.category_id attachment.course_second_category_id
if @course_second_category_id.to_i == 0 unless @parent_category_id.present? && @parent_category_id != 0
json.category_name attachment.course_second_category&.name json.category_name attachment.course_second_category&.name
end end
end end

@ -1,5 +1,26 @@
import React, { useRef, useEffect, useCallback } from 'react' import React, { useRef, useEffect, useCallback } from 'react'
Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
get: function () {
return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2)
}
})
function compareNumbers(a, b) {
return a - b;
}
function getTotalEffectTime(pos) {
pos.sort(compareNumbers)
let sum = 0
for (let i = 0; i < pos.length - 1; i++) {
let v = pos[i + 1] - pos[i]
if (v < 21) {
sum += v
}
}
return sum
}
const regex = /(android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini)/i const regex = /(android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini)/i
// https://www.showdoc.cc/educoder?page_id=4029884447803706 // https://www.showdoc.cc/educoder?page_id=4029884447803706
export default ({ src, videoId, logWatchHistory, courseId = null }) => { export default ({ src, videoId, logWatchHistory, courseId = null }) => {
@ -12,22 +33,21 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => {
const device = deviceMatch ? deviceMatch[0] : 'pc' const device = deviceMatch ? deviceMatch[0] : 'pc'
let totalDuration = 0 let totalDuration = 0
let totalTimePlayed = 0
let sumTimePlayed = 0 let sumTimePlayed = 0
let lastUpdatedTime = 0 let lastUpdatedTime = 0
let lastEffectUpdatedTime = 0
let logId = null let logId = null
let initLog = false let initLog = false
let timeTick = 20 // 20s let timeTick = 20 // 20s
let logCount = 1 let logCount = 1
let isLoging = false let isLoging = false
let isSeeking = false let isSeeking = false
let pos = []//
const log = useCallback((callback) => { const log = useCallback((callback) => {
let params = {} let params = {}
if (logId) { if (logId) {
params['log_id'] = logId params['log_id'] = logId
params['watch_duration'] = totalTimePlayed // params['watch_duration'] = getTotalEffectTime(pos) //
params['total_duration'] = sumTimePlayed // params['total_duration'] = sumTimePlayed //
} else { } else {
if (courseId) { if (courseId) {
@ -82,6 +102,7 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => {
useEffect(() => { useEffect(() => {
function onPlay() { function onPlay() {
pos.push(el.current.currentTime)
if (!initLog) { if (!initLog) {
initLog = true initLog = true
log() log()
@ -92,13 +113,12 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => {
log(() => { log(() => {
logId = null logId = null
logCount = 1 logCount = 1
totalTimePlayed = 0
lastUpdatedTime = 0 lastUpdatedTime = 0
sumTimePlayed = 0 sumTimePlayed = 0
initLog = false initLog = false
isLoging = false isLoging = false
lastEffectUpdatedTime = 0
isSeeking = false isSeeking = false
pos = []
}) })
} }
@ -106,31 +126,31 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => {
if (!isSeeking) { if (!isSeeking) {
let newTime = el.current.currentTime let newTime = el.current.currentTime
let timeDiff = newTime - lastUpdatedTime let timeDiff = newTime - lastUpdatedTime
let effectTimeDiff = newTime - lastEffectUpdatedTime //currenttime update before Seeking & Seeked fired
if (effectTimeDiff > 0) { if (Math.abs(timeDiff) < 0.5) {
totalTimePlayed += effectTimeDiff
lastEffectUpdatedTime = newTime
}
sumTimePlayed += Math.abs(timeDiff) sumTimePlayed += Math.abs(timeDiff)
lastUpdatedTime = newTime lastUpdatedTime = newTime
if (!isLoging) { if (!isLoging) {
if (sumTimePlayed - logCount * timeTick >= 0) { if (sumTimePlayed - logCount * timeTick >= 0) {
logCount++ logCount++
pos.push(lastUpdatedTime)
log() log()
} }
} }
} }
}
} }
function onSeeking() { function onSeeking() {
isSeeking = true isSeeking = true
lastUpdatedTime = el.current.currentTime
lastEffectUpdatedTime = el.current.currentTime
} }
function onSeeked() { function onSeeked() {
if (el.current.playing) {
pos.push(el.current.currentTime, lastUpdatedTime)
}
lastUpdatedTime = el.current.currentTime
isSeeking = false isSeeking = false
} }

@ -178,23 +178,23 @@
white-space: nowrap; white-space: nowrap;
} }
.icon-bianji_Hover,.icon-xiayi_Hover,.icon-shangyi_Hover,.icon-shanchu_Hover{ /* .icon-bianji_Hover,.icon-xiayi_Hover,.icon-shangyi_Hover,.icon-shanchu_Hover{
color:#BBBBBB !important; color: rgb(80, 145, 255) !important;
} } */
.icon-bianji_Hover:hover{ .icon-bianji_Hover{
color: rgb(80, 145, 255) !important; color: rgb(80, 145, 255) !important;
} }
.icon-xiayi_Hover:hover{ .icon-xiayi_Hover{
color: rgb(51, 189, 140) !important; color: rgb(51, 189, 140) !important;
} }
.icon-shangyi_Hover:hover{ .icon-shangyi_Hover{
color: rgb(51, 189, 140) !important; color: rgb(51, 189, 140) !important;
} }
.icon-shanchu_Hover:hover{ .icon-shanchu_Hover{
color:rgb(255, 85, 85) !important; color:rgb(255, 85, 85) !important;
} }
.ysliconfont{ .ysliconfont{

Loading…
Cancel
Save