diff --git a/1234567 b/1234567 index c7ff2f81d..e9cd9a1c1 100644 --- a/1234567 +++ b/1234567 @@ -1 +1 @@ -{"access_token":"nwsA--Idg9Wk4Kyuybly8XuI8MWx-NrJbPTzZX2ynbGaVHBnXZgJ4DHkwlJK6dGfYOmeMNmRj6PSXEzs1GS6vAy0e_7_6S34-S44wtGK83dv6HCUQ8qh3vAw12QUi39fUMDhCIAFXO","expires_in":7200,"got_token_at":1461723935} \ No newline at end of file +{"access_token":"yFUfEXFu0_Pl_jdojoRv6eA8pmGjyRkRIL1VCB2HZ4kVJhEq6crriyCRCI-_u5QbWgtepiIOvqTHtXpKgzMuaB7Eo7MjlMcXeecqhzTjnvpivK5HUzGhZXBG1dk_BxicJAFlCAARIN","expires_in":7200,"got_token_at":1461934858} \ No newline at end of file diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 6df683948..eeea2d01a 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -27,11 +27,15 @@ class BlogsController < ApplicationController @topics.each do |topic| topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count) + if topic[:infocount] < 0 + topic[:infocount] = 0 + end end @b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] } @topics = sort_by_sticky @topics + @topics = sortby_time_countcommon_hassticky @topics,sort_name else @type = 1 end diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 260c28b16..1d7e94c06 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -77,7 +77,7 @@ class BoardsController < ApplicationController @b_sort = 2 end - sort_name = "updated_at" + sort_name = "updated_on" sort_type = @b_sort == 1 ? "asc" : "desc" @@ -126,9 +126,13 @@ class BoardsController < ApplicationController @type = 2 @topics.each do |topic| topic[:infocount] = get_praise_num(topic) + (topic.parent ? x.parent.children.count : topic.children.count) + if topic[:infocount] < 0 + topic[:infocount] = 0 + end end @b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] } @topics = sort_by_sticky @topics + @topics = sortby_time_countcommon_hassticky @topics,sort_name else @type = 1 end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index d8188ca74..fabacf1ba 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -89,7 +89,7 @@ class HomeworkCommonController < ApplicationController homework_detail_manual.comment_status = 1 end eval_start = homework_detail_manual.evaluation_start - if eval_start <= @homework.end_time && homework_detail_manual.comment_status <= 1 + if eval_start.nil? || (eval_start <= @homework.end_time && homework_detail_manual.comment_status <= 1) homework_detail_manual.evaluation_start = @homework.end_time + 7 homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7 end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index f47471e0f..d35d7ac63 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -79,21 +79,20 @@ class NewsController < ApplicationController @b_sort = 2 end - sort_name = "created_on" + sort_name = "updated_at" sort_type = @b_sort == 1 ? "asc" : "desc" scope = @course ? @course.news.course_visible : News.course_visible news_arr = scope.map{|news| news.id} - @page = params[:page] ? params[:page].to_i + 1 : 0 news_page = 0 #@page *10 @news_count = scope.count @is_new = params[:is_new] @q = params[:subject] if params[:subject].nil? || params[:subject].blank? - scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.#{sort_name} #{sort_type}").offset(news_page).includes(:author,:course).all() + scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on #{sort_type}").offset(news_page).includes(:author,:course).all() #all(:include => [:author, :course], #:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page) else @@ -101,16 +100,26 @@ class NewsController < ApplicationController #.all(:include => [:author, :course],:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC") end + scope_order.each do |topic| + topic[:updated_at] = CourseActivity.where("course_act_type='#{topic.class}' and course_act_id =#{topic.id}").first.updated_at + end + #根据 赞+回复数排序 if @order.to_i == 2 @type = 2 scope_order.each do |topic| topic[:infocount] = get_praise_num(topic) + topic.comments.count + if topic[:infocount] < 0 + topic[:infocount] = 0 + end end @b_sort == 1 ? scope_order = scope_order.sort{|x,y| x[:infocount] <=> y[:infocount] } : scope_order = scope_order.sort{|x,y| y[:infocount] <=> x[:infocount] } scope_order = sort_by_sticky scope_order + scope_order = sortby_time_countcommon_hassticky scope_order,sort_name else @type = 1 + @b_sort == 1 ? scope_order = scope_order.sort{|x,y| x[:updated_at] <=> y[:updated_at] } : scope_order = scope_order.sort{|x,y| y[:updated_at] <=> x[:updated_at] } + scope_order = sort_by_sticky scope_order end @newss = scope_order diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index e7c10f9eb..cc1a1e9c7 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -5,7 +5,7 @@ class StudentWorkController < ApplicationController include ApplicationHelper require 'bigdecimal' require "base64" - before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students] + before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students,:work_canrepeat] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment] before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] @@ -17,41 +17,41 @@ class StudentWorkController < ApplicationController is_test = params[:is_test] == 'true' resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')} - student_work = find_or_save_student_work(is_test) + student_work = find_or_save_student_work(is_test) - unless student_work - resultObj[:status] = 100 - else - if @homework.homework_type == 2 && @homework.homework_detail_programing - result = test_realtime(student_work, params[:src]) - logger.debug result - resultObj[:status] = result["status"] - resultObj[:results] = result["results"] - resultObj[:error_msg] = result["error_msg"] - results = result["results"] - if result["status"].to_i == -2 #编译错误 - results = [result["error_msg"]] - end - student_work_test = student_work.student_work_tests.build(status: result["status"], results: results, - src: params[:src]) - unless student_work.save - resultObj[:status] = 200 + unless student_work + resultObj[:status] = 100 + else + if @homework.homework_type == 2 && @homework.homework_detail_programing + result = test_realtime(student_work, params[:src]) + logger.debug result + resultObj[:status] = result["status"] + resultObj[:results] = result["results"] + resultObj[:error_msg] = result["error_msg"] + results = result["results"] + if result["status"].to_i == -2 #编译错误 + results = [result["error_msg"]] + end + student_work_test = student_work.student_work_tests.build(status: result["status"], results: results, + src: params[:src]) + unless student_work.save + resultObj[:status] = 200 + else + student_work.name = params[:title] + student_work.description = params[:src] + if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") + student_work.late_penalty = @homework.late_penalty else - student_work.name = params[:title] - student_work.description = params[:src] - if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") - student_work.late_penalty = @homework.late_penalty - else - student_work.late_penalty = 0 - end - student_work.save - resultObj[:status] = result["status"].to_i - resultObj[:time] = student_work_test.created_at.to_s(:db) - resultObj[:index] = student_work.student_work_tests.count + student_work.late_penalty = 0 end + student_work.save + resultObj[:status] = result["status"].to_i + resultObj[:time] = student_work_test.created_at.to_s(:db) + resultObj[:index] = student_work.student_work_tests.count end end - + end + render :json => resultObj end @@ -81,6 +81,8 @@ class StudentWorkController < ApplicationController #根据传入的tIndex确定是第几次测试 #之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来 def program_test_ex + tStarttime = Time.now + is_test = params[:is_test] == 'true' resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1,testid:1} #保存每测试一次返回的结果 @@ -92,83 +94,229 @@ class StudentWorkController < ApplicationController resultObj[:status] = 100 else if @homework.homework_type == 2 && @homework.homework_detail_programing - #找到第index个测试的输入输出 - index = params[:tIndex].to_i - resultObj[:tseq] = index - test = @homework.homework_tests[index - 1] + #找到第index个测试的输入输出 + index = params[:tIndex].to_i + resultObj[:tseq] = index + test = @homework.homework_tests[index - 1] - #请求测试 + #请求测试 + begin result = test_realtime_ex(test, params[:src]) + rescue Timeout::Error + tEndtime = Time.now + tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 + logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒" - if result["status"].to_i != -2 - #result["results"].first['output'] = result["results"].first['output'].gsub(" ","□") - #result["results"].first['result'] = result["results"].first['result'].gsub(" ","□") - space_replace_1(result["results"].first['output']) - space_replace_1(result["results"].first['result']) - end + #status 0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时 + CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>-3,:wait_time=>tUsedtime,:student_work_id=>student_work.id) - logger.debug result + end + if result["status"].to_i != -2 + #result["results"].first['output'] = result["results"].first['output'].gsub(" ","□") + #result["results"].first['result'] = result["results"].first['result'].gsub(" ","□") + space_replace_1(result["results"].first['output']) + space_replace_1(result["results"].first['result']) + end - #-1 默认值 0全部正确并结束 2 超时 -2 编译错误 - resultObj[:status] = -1 - resultObj[:results] = result["results"].first #本次测试结果 - resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 + logger.debug result - if result["status"].to_i == -2 #编译错误 - resultObj[:results] = result["error_msg"] - resultObj[:status] = -2 - elsif result["results"][0]["status"].to_i == 2 - resultObj[:status] = 2 - end + #-1 默认值 0全部正确并结束 2 超时 -2 编译错误 + resultObj[:status] = -1 + resultObj[:results] = result["results"].first #本次测试结果 + resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 - unless student_work.save - resultObj[:status] = 200 + #该状态用于存入CodeTests + tmpstatus = -1 + if result["status"].to_i == -2 #编译错误 + resultObj[:results] = result["error_msg"] + resultObj[:status] = -2 + tmpstatus = -2 + elsif result["results"][0]["status"].to_i == 2 + resultObj[:status] = 2 + tmpstatus = 2 + end + + if result["status"] == 0 + tmpstatus = 0 + end + + unless student_work.save + resultObj[:status] = 200 + else + student_work.name = params[:title] + student_work.description = params[:src] + + if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") + student_work.late_penalty = @homework.late_penalty else - student_work.name = params[:title] - student_work.description = params[:src] - - if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") - student_work.late_penalty = @homework.late_penalty - else - student_work.late_penalty = 0 - end - - #每次从数据库取出上次的结果加上本次的结果再存入数据库 - status = result["status"] - if index == 1 - student_work_test = student_work.student_work_tests.build(status: status, - results: [resultObj[:results]],src: params[:src]) - student_work_test.save! - resultObj[:testid] = student_work_test.id - else - #先从数据库取出result - student_work_test = StudentWorkTest.find(params[:testid]) - results = student_work_test.results - results << resultObj[:results] - student_work_test.results = results - student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status) - student_work_test.save! - status = student_work_test.status - resultObj[:testid] = student_work_test.id - end - - #超时或编译错误则直接返回了并存入数据库 - if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size - if status == 0 - resultObj[:status] = 0 - end - student_work.save! - resultObj[:time] = student_work_test.created_at.to_s(:db) - resultObj[:index] = student_work.student_work_tests.count - end - - #渲染返回结果 - render :json => resultObj + student_work.late_penalty = 0 end + + #每次从数据库取出上次的结果加上本次的结果再存入数据库 + if result["status"].to_i != -2 + result["results"].first['user_wait'] = tUsedtime + + if result["results"][0]["status"].to_i == 2 + result["status"] = 2 + end + end + + status = result["status"] + if index == 1 + student_work_test = student_work.student_work_tests.build(status: status, + results: [resultObj[:results]],src: params[:src]) + student_work_test.save! + resultObj[:testid] = student_work_test.id + else + #先从数据库取出result + student_work_test = StudentWorkTest.find(params[:testid]) + results = student_work_test.results + results << resultObj[:results] + student_work_test.results = results + student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status) + student_work_test.save! + status = student_work_test.status + resultObj[:testid] = student_work_test.id + end + + #超时或编译错误则直接返回了并存入数据库 + if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size + if status == 0 + resultObj[:status] = 0 + end + student_work.save! + resultObj[:time] = student_work_test.created_at.to_s(:db) + resultObj[:index] = student_work.student_work_tests.count + end + + #将每次用户等待时间都存起来以便管理界面显示用 + tEndtime = Time.now + tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 + logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒" + + time_used = 0 + if result["status"].to_i != -2 + #至少一毫秒 + time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used'] + end + #0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时 + CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id) + + #渲染返回结果 + render :json => resultObj + end end end end + #找出该作业的所有提交作业 + def find_all_student_work_by_homeid() + all_studentwork = StudentWork.where("homework_common_id = #{@homework.id} and is_test = 0 ") + + all_studentwork + end + + def request_code_repeattest(src) + url = "#{Redmine::Configuration['jplag_server']}api/realtime_test.json" + + factor = [] + src.each do |test| + factor << {work_id: test.id, des: test.description,created_at:test.created_at.to_i} + end + + solutions = { + homeid:@homework.id, + language:@homework.homework_detail_programing.language, + factor: factor + } + uri = URI(url) + body = solutions.to_json + + logger.debug "send body" + logger.debug body + + res = Net::HTTP.new(uri.host, uri.port).start do |client| + request = Net::HTTP::Post.new(uri.path) + request.body = body + request["Content-Type"] = "application/json" + client.request(request) + end + + JSON.parse(res.body) + end + + #点击代码查重按钮 + def work_canrepeat + @homework_id = params[:homework] + @course_id = params[:course_id] + + all_studentwork = find_all_student_work_by_homeid() + + @work_count = all_studentwork.count + end + + #代码查重 status: 0完成 -2不需要查重 -1查重失败不支持该语言 + def code_repeattest + tStarttime = Time.now + logger.debug "code_repeattest start is #{tStarttime}}" + resultObj = {status: -2} + + @homework = HomeworkCommon.find params[:homework] + + all_studentwork = find_all_student_work_by_homeid() + + if all_studentwork == nil + resultObj[:status] = -2 + elsif all_studentwork.count <= 1 + resultObj[:status] = -2 + else + + #@homework.homework_detail_programing.language、id、description + logger.debug "time1 is #{Time.now.usec} " + result = request_code_repeattest(all_studentwork) + logger.debug "time2 is #{Time.now.usec} " + + resultObj[:status] = result['status'].to_i + # resultObj[:results] = result['results'] + + #Time.now, simi_id = simiworkid , simi_value = simivalue + if resultObj[:status] == 0 + @homework.simi_time = Time.now + resultObj[:comparetime] = @homework.simi_time + @homework.update_column('simi_time', @homework.simi_time) + + logger.debug "time3 is #{Time.now.usec} " + result['results'].each do |key,value| + @student_work = StudentWork.where("id =?", key.to_i).first + @student_work.update_column('simi_id', value['simiworkid'].to_i) + @student_work.update_column('simi_value', value['simivalue'].to_i) + # sqlstr = "update student_works set simi_id=#{value['simiworkid']},simi_value=#{value['simivalue']} where id=#{key.to_i} " + # dbh.execute(sqlstr) + end + logger.debug "time4 is #{Time.now.usec} " + end + end + tEndtime = Time.now + logger.debug "code_repeattest end is #{tEndtime}}" + tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000000+(tEndtime.usec - tStarttime.usec) + logger.debug "code_repeattest userd utime is #{tUsedtime}" + render :json => resultObj + end + + #上次代码查重时间 + def last_codecomparetime + resultObj = {status: 0} + @homework = HomeworkCommon.find params[:homework] + + #转换一下 + if @homework.simi_time != nil + resultObj[:comparetime] = Time.parse(@homework.simi_time.to_s).strftime("%Y-%m-%d %H:%M:%S") + else + resultObj[:comparetime] = 0 + end + + render :json => resultObj + end def index # 作业消息状态更新 @@ -504,7 +652,7 @@ class StudentWorkController < ApplicationController if @homework.homework_detail_group.base_on_project == 1 stu_project.project_id = @student_work_project.project_id else @homework.homework_detail_group.base_on_project == 0 - stu_project.project_id = -1 + stu_project.project_id = -1 end stu_project.user_id = members[i].to_i stu_project.is_leader = 0 @@ -791,7 +939,7 @@ class StudentWorkController < ApplicationController if homework_detail_manual.ta_proportion.to_s != params[:ta_proportion].to_s || @homework.teacher_priority.to_s != teacher_priority.to_s || (homework_detail_programing && homework_detail_programing.ta_proportion.to_s != params[:sy_proportion].to_s) homework_detail_manual.ta_proportion = params[:ta_proportion] homework_detail_programing.ta_proportion = params[:sy_proportion] if homework_detail_programing - @homework.teacher_priority = teacher_priority + @homework.update_column('teacher_priority', teacher_priority) homework_detail_manual.save if homework_detail_manual homework_detail_programing.save if homework_detail_programing @@ -801,7 +949,7 @@ class StudentWorkController < ApplicationController student_work.save end end - + @homework.save if params[:student_path] redirect_to student_work_index_url(:homework => @homework.id) @@ -1095,11 +1243,11 @@ class StudentWorkController < ApplicationController student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first if student_work.nil? @homework.student_works.build( - name: params[:title], - description: params[:src], - user_id: User.current.id, - is_test: is_test - ) + name: params[:title], + description: params[:src], + user_id: User.current.id, + is_test: is_test + ) unless @homework.save logger.debug @homework.errors.full_messages else @@ -1120,7 +1268,7 @@ class StudentWorkController < ApplicationController src:src, language:@homework.homework_detail_programing.language, factor: factor - } + } uri = URI(url) body = solutions.to_json res = Net::HTTP.new(uri.host, uri.port).start do |client| @@ -1174,8 +1322,12 @@ class StudentWorkController < ApplicationController final_score = final_ta_score + final_s_score student_work.final_score = format("%.2f",final_score.to_f) end - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end end else #不考虑教师评分 if student_work.teaching_asistant_score.nil? @@ -1189,8 +1341,12 @@ class StudentWorkController < ApplicationController final_score = final_ta_score + final_s_score student_work.final_score = format("%.2f",final_score.to_f) end - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end end elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空 if homework.teacher_priority == 1 #教师优先 @@ -1225,8 +1381,12 @@ class StudentWorkController < ApplicationController final_score = final_sy_score + final_ts_score + final_st_score student_work.final_score = format("%.2f",final_score.to_f) end - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end end else #不考虑教师评分 if student_work.teaching_asistant_score.nil? #教辅未评分 @@ -1256,8 +1416,12 @@ class StudentWorkController < ApplicationController final_score = final_sy_score + final_ts_score + final_st_score student_work.final_score = format("%.2f",final_score.to_f) end - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8e4c57f76..f8bf70933 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -477,8 +477,8 @@ class UsersController < ApplicationController ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:send_id].to_i) if ah.empty? @status = 2 - elsif ah.first.status == 1 - @status = 1 + elsif ah.first.status != 2 + @status = ah.first.status end end if !params[:search].nil? @@ -1208,13 +1208,13 @@ class UsersController < ApplicationController #显示更多用户课程 def user_courses4show @page = params[:page].to_i + 1 - @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5) + @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5) end #显示更多用户项目 def user_projects4show @page = params[:page].to_i + 1 - @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5).offset(@page * 5) + @projects = @user.projects.visible.select("projects.*,(SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5).offset(@page * 5) end def user_course_activities @@ -2948,20 +2948,19 @@ class UsersController < ApplicationController sort_name = "created_at" sort_type = @c_sort == 1 ? "asc" : "desc" - if @user.courses.visible.count > 0 - course_order_ids = "(" + CourseActivity.find_by_sql("SELECT c.course_id, updated_at FROM(SELECT ca.course_id, MAX(ca.updated_at) AS updated_at FROM course_activities ca WHERE ca.course_id IN (" + @user.courses.visible.select('courses.id').map{|c| c.id}.join(',') + ") GROUP BY ca.course_id) AS c ").map {|c| c.course_id}.join(",") + ")" - @courses = Course.where("id in #{course_order_ids}").order("#{sort_name} #{sort_type}") - else - @courses = [] - end + @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a #{sort_type}") #根据 作业+资源数排序 if @order.to_i == 2 @type = 2 @courses.each do |course| course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count) : (course.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(course).count) + if course[:infocount] < 0 + course[:infocount] = 0 + end end @c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]}) + @courses = sortby_time_countcommon_nosticky @courses,sort_name else @type = 1 end @@ -2993,21 +2992,19 @@ class UsersController < ApplicationController sort_name = "created_on" sort_type = @c_sort == 1 ? "asc" : "desc" - if @user.projects.visible.count > 0 - project_order_ids = "(" +ForgeActivity.find_by_sql("SELECT p.project_id, p.created_at FROM (SELECT fa.project_id, MAX(fa.created_at) AS created_at FROM forge_activities fa WHERE fa.project_id IN (" + @user.projects.visible.select('projects.id').map{|p| p.id}.join(',') + ") GROUP BY fa.project_id) AS p ").map {|p| p.project_id}.join(",") + ")" - @projects = Project.where("projects.id in #{project_order_ids}").order("#{sort_name} #{sort_type}") - else - @projects = [] - end + @projects = @user.projects.visible.select("projects.*, (SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a #{sort_type}") #根据 问题+资源数排序 @project.project_score.issue_num @project.project_score.attach_num if @order.to_i == 2 @type = 2 @projects.each do |project| project[:infocount] = project.project_score.issue_num+project.project_score.attach_num + if project[:infocount] < 0 + project[:infocount] = 0 + end end - @c_sort == 1 ? (@projects = @projects.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@projects = @projects.sort{|x,y| y[:infocount] <=> x[:infocount] }) + @projects = sortby_time_countcommon_nosticky @projects,sort_name else @type = 1 end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 464b4fcc6..d2f3ad456 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3065,7 +3065,7 @@ def host_with_protocol return Setting.protocol + "://" + Setting.host_name end -#将有置顶属性的提到数组前面 #infocount 相同的按时间降序排列 +#将有置顶属性的提到数组前面 def sort_by_sticky topics tmpTopics = [] tmpIndex = 0 @@ -3082,10 +3082,120 @@ def sort_by_sticky topics tmpIndex = tmpIndex + 1 end end + return tmpTopics +end - topics = tmpTopics - return topics -enddef strip_html(text,len=0,endss="...") +#按人气排序的时候 相同的人气必须按某种时间顺序排序 有置顶属性 +def sortby_time_countcommon_hassticky topics,sortstr + tmpTopics = [] + tmpTopics = topics + tStart = -1 + tEnd = -1 + + tmpTopics_1 = [] + tmpIndex = 0 + + tmpTopics.each_with_index do |topic,index| + if topic.sticky == 0 + if tStart == -1 + if (index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount]) + tStart = index + end + else + if ((topic[:infocount] == tmpTopics[index-1][:infocount]) && ((index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount]))) + tEnd = index + else + if (topic[:infocount] == tmpTopics[index-1][:infocount]) + tEnd = index + end + if tEnd > tStart + for i in tStart..tEnd + tmpTopics_1[tmpIndex] = tmpTopics[i] + tmpIndex = tmpIndex + 1 + end + + if sortstr == "created_at" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_at].to_i <=> x[:created_at].to_i } + elsif sortstr == "created_on" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_on].to_i <=> x[:created_on].to_i } + elsif sortstr == "updated_at" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_at].to_i <=> x[:updated_at].to_i } + elsif sortstr == "updated_on" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_on].to_i <=> x[:updated_on].to_i } + end + + tmpIndex = 0 + for i in tStart..tEnd + tmpTopics[i] = tmpTopics_1[tmpIndex] + tmpIndex = tmpIndex + 1 + end + end + tStart = -1 + tEnd = -1 + tmpTopics_1 = [] + tmpIndex = 0 + end + end + end + end + return tmpTopics +end + +#按人气排序的时候 相同的人气必须按某种时间顺序排序 无置顶属性 +def sortby_time_countcommon_nosticky topics,sortstr + tmpTopics = [] + tmpTopics = topics + tStart = -1 + tEnd = -1 + + tmpTopics_1 = [] + tmpIndex = 0 + + tmpTopics.each_with_index do |topic,index| + if tStart == -1 + if (index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount]) + tStart = index + end + else + if ((topic[:infocount] == tmpTopics[index-1][:infocount]) && ((index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount]))) + tEnd = index + else + if (topic[:infocount] == tmpTopics[index-1][:infocount]) + tEnd = index + end + if tEnd > tStart + for i in tStart..tEnd + tmpTopics_1[tmpIndex] = tmpTopics[i] + tmpIndex = tmpIndex + 1 + end + + if sortstr == "created_at" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_at].to_i <=> x[:created_at].to_i } + elsif sortstr == "created_on" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_on].to_i <=> x[:created_on].to_i } + elsif sortstr == "updated_at" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_at].to_i <=> x[:updated_at].to_i } + elsif sortstr == "updated_on" + tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_on].to_i <=> x[:updated_on].to_i } + end + + tmpIndex = 0 + for i in tStart..tEnd + tmpTopics[i] = tmpTopics_1[tmpIndex] + tmpIndex = tmpIndex + 1 + end + end + tStart = -1 + tEnd = -1 + tmpTopics_1 = [] + tmpIndex = 0 + end + end + end + return tmpTopics +end + +def strip_html(text,len=0,endss="...") ss = "" if text.length>0 ss=text.gsub(/<\/?.*?>/, '').strip @@ -3098,4 +3208,4 @@ enddef strip_html(text,len=0,endss="...") end end return ss -end \ No newline at end of file +end diff --git a/app/models/comment.rb b/app/models/comment.rb index 341a179ce..8632c243a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -45,7 +45,8 @@ class Comment < ActiveRecord::Base if self.commented.course if self.author_id != self.commented.author_id self.course_messages << CourseMessage.new(:user_id => self.commented.author_id, :course_id => self.commented.course.id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{self.commented.author_id} and shield_type='Course' and shield_id=#{self.commented.course.id}").count == 0 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.commented.author_id} and shield_type='Course' and shield_id=#{self.commented.course.id}").count + if count == 0 content = strip_html self.comments.html_safe, 200 ws.comment_template self.commented.author_id, "course_notice", self.id, "#{l(:label_notice_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index b47008393..dae910d60 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -59,7 +59,8 @@ class HomeworkCommon < ActiveRecord::Base self.course.members.each do |m| # if m.user_id != self.user_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count == 0 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count + if count == 0 ws = WechatService.new ws.homework_template(m.user_id, "homework", self.id, "#{l(:label_new_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59") end @@ -108,7 +109,8 @@ class HomeworkCommon < ActiveRecord::Base #修改作业后发送微信模板消息 def wechat_message self.course.members.each do |member| - if ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count == 0 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count + if count == 0 ws = WechatService.new ws.homework_template(member.user_id, "homework", self.id, "#{l(:label_update_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59") end diff --git a/app/models/issue.rb b/app/models/issue.rb index 6e3dcc57a..79ddcd917 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -162,7 +162,7 @@ class Issue < ActiveRecord::Base end self.project.members.each do |m| count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count - if m.user_id != self.author_id && count != 0 + if m.user_id != self.author_id && count == 0 ws = WechatService.new content = strip_html self.project.name + " 有新缺陷了:" + self.subject.html_safe, 200 ws.message_update_template m.user_id, "issues", self.id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on) diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 675c07b06..10971d46f 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -255,11 +255,14 @@ class JournalsForMessage < ActiveRecord::Base self.course_messages << CourseMessage.new(:user_id => r, :course_id => self.jour.id, :viewed => false) end end - if self.jour_type == 'HomeworkCommon' && ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count == 0 - ws = WechatService.new - #content = truncate(strip_tags(self.notes.to_s), length: 200) - content = strip_html self.notes.html_safe, 200 - ws.comment_template self.jour.user_id, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + if self.jour_type == 'HomeworkCommon' + count = ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count + if count == 0 + ws = WechatService.new + #content = truncate(strip_tags(self.notes.to_s), length: 200) + content = strip_html self.notes.html_safe, 200 + ws.comment_template self.jour.user_id, "homework", self.jour_id, "#{l(:label_homework_comment_template)}", self.user.try(:realname), format_time(self.created_on), content + end end end diff --git a/app/models/message.rb b/app/models/message.rb index 5275c57b9..7bfb9d80e 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -83,7 +83,7 @@ class Message < ActiveRecord::Base # after_create :add_author_as_watcher, :reset_counters!, :add_boards_count after_update :update_messages_board, :update_activity after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score - after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count + after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count, :act_as_system_message #before_save :be_user_score scope :visible, lambda {|*args| @@ -263,8 +263,9 @@ class Message < ActiveRecord::Base if self.parent_id.nil? # 主贴 self.course.members.includes(:user).each do |m| if self.author.allowed_to?(:as_teacher, self.course) && m.user_id != self.author_id # 老师 自己的帖子不给自己发送消息 - self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course.id}").count == 0 + #self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.board.course_id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course.id}").count + if count == 0 content = strip_html self.subject, 200 ws.topic_publish_template m.user_id, "course_discussion", self.id, "#{l(:label_course_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) end @@ -273,8 +274,9 @@ class Message < ActiveRecord::Base else # 回帖 parent_author_id = Message.find(self.parent_id).author_id if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 - self.course_messages << CourseMessage.new(:user_id => parent_author_id, :course_id => self.board.course_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count == 0 + #self.course_messages << CourseMessage.new(:user_id => parent_author_id, :course_id => self.board.course_id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count + if count == 0 content = strip_html self.content.html_safe, 200 ws.comment_template parent_author_id, "course_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end @@ -284,8 +286,9 @@ class Message < ActiveRecord::Base if self.parent_id.nil? # 主贴 self.project.members.includes(:user).each do |m| if m.user_id != self.author_id - self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project.id}").count == 0 + #self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.board.project_id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project.id}").count + if count == 0 content = strip_html self.subject, 200 ws.topic_publish_template m.user_id, "project_discussion", self.id, "#{l(:label_project_topic_template)}", content, self.author.try(:realname), format_time(self.created_on) end @@ -294,8 +297,9 @@ class Message < ActiveRecord::Base else # 回帖 parent_author_id = Message.find(self.parent_id).author_id if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息 - self.forge_messages << ForgeMessage.new(:user_id => parent_author_id, :project_id => self.board.project_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Project' and shield_id=#{self.board.project_id}").count == 0 + #self.forge_messages << ForgeMessage.new(:user_id => parent_author_id, :project_id => self.board.project_id, :viewed => false) + count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Project' and shield_id=#{self.board.project_id}").count + if count == 0 content = strip_html self.content.html_safe, 200 ws.comment_template parent_author_id, "project_discussion", self.parent_id, "#{l(:label_topic_comment_template)}", self.author.try(:realname), format_time(self.created_on), content end diff --git a/app/models/news.rb b/app/models/news.rb index cd16442a0..1a2205f48 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -170,7 +170,8 @@ class News < ActiveRecord::Base self.course.members.each do |m| if m.user_id != self.author_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - if ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count == 0 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count + if count == 0 ws = WechatService.new content = strip_html self.author.try(:realname) + " 发布了通知:" + self.title.html_safe, 200 ws.message_update_template m.user_id, "course_notice", self.id, "#{l(:label_new_notice_template)}", self.author.try(:realname) + " 发布了通知:" + content, format_time(self.created_on) diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 3abd4276a..ddd91df38 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -63,11 +63,17 @@ class StudentWork < ActiveRecord::Base final_score = final_ta_score + final_s_score student_work.final_score = format("%.2f",final_score.to_f) end - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end end else #不考虑教师评分 - if student_work.teaching_asistant_score.nil? + if student_work.student_score.nil? && student_work.teaching_asistant_score.nil? + student_work.final_score = student_work.teacher_score + elsif student_work.teaching_asistant_score.nil? student_work.final_score = student_work.student_score elsif student_work.student_score.nil? student_work.final_score = student_work.teaching_asistant_score @@ -78,8 +84,12 @@ class StudentWork < ActiveRecord::Base final_score = final_ta_score + final_s_score student_work.final_score = format("%.2f",final_score.to_f) end - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end end elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空 if homework.teacher_priority == 1 #教师优先 @@ -114,9 +124,13 @@ class StudentWork < ActiveRecord::Base final_score = final_sy_score + final_ts_score + final_st_score student_work.final_score = format("%.2f",final_score.to_f) end - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score - end + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end + end else #不考虑教师评分 if student_work.teaching_asistant_score.nil? #教辅未评分 if student_work.student_score.nil? @@ -145,8 +159,12 @@ class StudentWork < ActiveRecord::Base final_score = final_sy_score + final_ts_score + final_st_score student_work.final_score = format("%.2f",final_score.to_f) end - score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score - student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + if student_work.final_score + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score + else + student_work.work_score = nil + end end end end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index ee999d98f..1dcd147d4 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -10,23 +10,23 @@ class WechatService data:{ first: { value:first, - color:"#CCCCCC" + color:"#707070" }, keyword1:{ value:key1, - color:"#CCCCCC" + color:"#707070" }, keyword2:{ value:key2, - color:"#CCCCCC" + color:"#707070" }, keyword3:{ value:key3, - color:"#CCCCCC" + color:"#707070" }, remark:{ value:remark, - color:"#CCCCCC" + color:"#707070" } } } @@ -88,19 +88,19 @@ class WechatService data:{ first: { value:first, - color:"#CCCCCC" + color:"#707070" }, keyword1:{ value:key1, - color:"#CCCCCC" + color:"#707070" }, keyword2:{ value:key2, - color:"#CCCCCC" + color:"#707070" }, remark:{ value:remark, - color:"#CCCCCC" + color:"#707070" } } } diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index ea494d0f9..7a1dc636c 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -25,7 +25,7 @@ <%= link_to activity.title.subject.to_s.html_safe, user_blog_blog_comment_path(:user_id=>activity.author_id, :blog_id=>activity.blog.id,:id=>activity), :class=> "list-title fl"%> <% end %> <% if activity.blog.homepage_id and activity.id == activity.blog.homepage_id %> - [已设为首页] + [已设为首页] <% end %> <% if activity.sticky == 1 %> diff --git a/app/views/layouts/_user_courses.html.erb b/app/views/layouts/_user_courses.html.erb index 8db253888..1e0f46926 100644 --- a/app/views/layouts/_user_courses.html.erb +++ b/app/views/layouts/_user_courses.html.erb @@ -84,7 +84,7 @@ <% end%> \ No newline at end of file diff --git a/app/views/organizations/_org_course_homework.html.erb b/app/views/organizations/_org_course_homework.html.erb index 4ac2ebcbf..33e2835dd 100644 --- a/app/views/organizations/_org_course_homework.html.erb +++ b/app/views/organizations/_org_course_homework.html.erb @@ -153,9 +153,9 @@
<% if activity.homework_type != 2 %> <% ids = student_work_scores.empty? ? "(-1)" : '('+student_work_scores.map{|sw|sw.student_work_id}.join(',')+')' %> - <% student_works = activity.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where("student_works.id in #{ids}").order("score desc") %> + <% student_works = activity.student_works.select("student_works.*,student_works.work_score as score").where("student_works.id in #{ids}").order("score desc") %> <% else %> - <% student_works = activity.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("score desc") %> + <% student_works = activity.student_works.select("student_works.*,student_works.work_score as score").order("score desc") %> <% end %> <% student_works.each_with_index do |sw, i| %>
@@ -211,7 +211,7 @@
项目名称:<%=project.name %>
创建者:<%=(User.find project.user_id).show_name %>(组长)
- 更新时间:<%=time_from_now time %> + 更新时间:<%=time_from_now !com_time.nil? && format_time(com_time) > format_time(time) ? com_time : time %>
<% if i == 9 && projects.count > 10 %> @@ -372,4 +372,7 @@ $("#relatePWrap_<%=user_activity_id %>").toggleClass('relatePWrap'); $("#moreProject_<%=user_activity_id %>").show(); }); + $(function(){ + user_card_show_hide(); + }); \ No newline at end of file diff --git a/app/views/organizations/_org_course_message.html.erb b/app/views/organizations/_org_course_message.html.erb index 9a9943e9b..56dafed08 100644 --- a/app/views/organizations/_org_course_message.html.erb +++ b/app/views/organizations/_org_course_message.html.erb @@ -157,3 +157,8 @@ <% end %>
+ diff --git a/app/views/organizations/_org_course_news.html.erb b/app/views/organizations/_org_course_news.html.erb index 7f50b3725..a6183e891 100644 --- a/app/views/organizations/_org_course_news.html.erb +++ b/app/views/organizations/_org_course_news.html.erb @@ -121,3 +121,8 @@ + diff --git a/app/views/organizations/_org_course_poll.html.erb b/app/views/organizations/_org_course_poll.html.erb index 10d1919a2..cb390f7f5 100644 --- a/app/views/organizations/_org_course_poll.html.erb +++ b/app/views/organizations/_org_course_poll.html.erb @@ -56,3 +56,8 @@ <% end %> + diff --git a/app/views/organizations/_org_project_issue.html.erb b/app/views/organizations/_org_project_issue.html.erb index 9b7dbfa8f..98c1e2df3 100644 --- a/app/views/organizations/_org_project_issue.html.erb +++ b/app/views/organizations/_org_project_issue.html.erb @@ -139,3 +139,8 @@ + diff --git a/app/views/organizations/_org_subfield_message.html.erb b/app/views/organizations/_org_subfield_message.html.erb index bf0cc8734..fc6cc6ee0 100644 --- a/app/views/organizations/_org_subfield_message.html.erb +++ b/app/views/organizations/_org_subfield_message.html.erb @@ -159,3 +159,8 @@ + diff --git a/app/views/organizations/_org_subfield_news.html.erb b/app/views/organizations/_org_subfield_news.html.erb index 3d2a316cf..daa81e96c 100644 --- a/app/views/organizations/_org_subfield_news.html.erb +++ b/app/views/organizations/_org_subfield_news.html.erb @@ -143,4 +143,7 @@ diff --git a/app/views/organizations/_project_create.html.erb b/app/views/organizations/_project_create.html.erb index 5003fd0e2..ef59d154e 100644 --- a/app/views/organizations/_project_create.html.erb +++ b/app/views/organizations/_project_create.html.erb @@ -36,4 +36,9 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/organizations/_project_message.html.erb b/app/views/organizations/_project_message.html.erb index a818939d6..26cf3b318 100644 --- a/app/views/organizations/_project_message.html.erb +++ b/app/views/organizations/_project_message.html.erb @@ -133,3 +133,8 @@ + diff --git a/app/views/organizations/_show_org_document.html.erb b/app/views/organizations/_show_org_document.html.erb index fdd6772e7..6012dd0d4 100644 --- a/app/views/organizations/_show_org_document.html.erb +++ b/app/views/organizations/_show_org_document.html.erb @@ -152,4 +152,7 @@ target.eq(2).show(); } } + $(function(){ + user_card_show_hide(); + }); \ No newline at end of file diff --git a/app/views/projects/_project_create.html.erb b/app/views/projects/_project_create.html.erb index ef0c7c4c3..bd118418d 100644 --- a/app/views/projects/_project_create.html.erb +++ b/app/views/projects/_project_create.html.erb @@ -36,4 +36,9 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/projects/_project_news.html.erb b/app/views/projects/_project_news.html.erb index 4ea0e9f17..8756ff26f 100644 --- a/app/views/projects/_project_news.html.erb +++ b/app/views/projects/_project_news.html.erb @@ -120,4 +120,9 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/users/_course_attachment.html.erb b/app/views/users/_course_attachment.html.erb index 6f6cf82f3..63c57f708 100644 --- a/app/views/users/_course_attachment.html.erb +++ b/app/views/users/_course_attachment.html.erb @@ -38,4 +38,9 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/users/_course_create.html.erb b/app/views/users/_course_create.html.erb index dc1e0ee81..6b2234337 100644 --- a/app/views/users/_course_create.html.erb +++ b/app/views/users/_course_create.html.erb @@ -34,4 +34,9 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index 743090a4d..56ceb1ab6 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -158,9 +158,9 @@
<% if activity.homework_type != 2 %> <% ids = student_work_scores.empty? ? "(-1)" : '('+student_work_scores.map{|sw|sw.student_work_id}.join(',')+')' %> - <% student_works = activity.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where("student_works.id in #{ids}").order("score desc") %> + <% student_works = activity.student_works.select("student_works.*,student_works.work_score as score").where("student_works.id in #{ids}").order("score desc") %> <% else %> - <% student_works = activity.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("score desc") %> + <% student_works = activity.student_works.select("student_works.*,student_works.work_score as score").order("score desc") %> <% end %> <% student_works.includes(:user).each_with_index do |sw, i| %>
@@ -226,7 +226,7 @@
项目名称:<%=project.name %>
创建者:<%=(User.find project.user_id).show_name %>(组长)
- 更新时间:<%=time_from_now time %> + 更新时间:<%=time_from_now !com_time.nil? && format_time(com_time) > format_time(time) ? com_time : time %>
<% if i == 9 && projects.count > 10 %> @@ -388,4 +388,7 @@ $("#relatePWrap_<%=user_activity_id %>").toggleClass('relatePWrap'); $("#moreProject_<%=user_activity_id %>").show(); }); + $(function(){ + user_card_show_hide(); + }); diff --git a/app/views/users/_course_journalsformessage.html.erb b/app/views/users/_course_journalsformessage.html.erb index f9a59f024..1d0c4cba5 100644 --- a/app/views/users/_course_journalsformessage.html.erb +++ b/app/views/users/_course_journalsformessage.html.erb @@ -107,4 +107,9 @@
+ diff --git a/app/views/users/_course_message.html.erb b/app/views/users/_course_message.html.erb index 56133d1de..2f790b19b 100644 --- a/app/views/users/_course_message.html.erb +++ b/app/views/users/_course_message.html.erb @@ -2,7 +2,7 @@
<%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id,:host=>Setting.host_user), :alt => "用户头像" %> - <%#= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %>
@@ -174,4 +174,9 @@
<% end %>
-
\ No newline at end of file + + \ No newline at end of file diff --git a/app/views/users/_course_news.html.erb b/app/views/users/_course_news.html.erb index efaa72beb..403a922ed 100644 --- a/app/views/users/_course_news.html.erb +++ b/app/views/users/_course_news.html.erb @@ -146,3 +146,8 @@ + diff --git a/app/views/users/_course_poll.html.erb b/app/views/users/_course_poll.html.erb index 970fb516e..dab970cdf 100644 --- a/app/views/users/_course_poll.html.erb +++ b/app/views/users/_course_poll.html.erb @@ -55,3 +55,8 @@ <% end %> + diff --git a/app/views/users/_project_attachment.html.erb b/app/views/users/_project_attachment.html.erb index b3d904104..795432008 100644 --- a/app/views/users/_project_attachment.html.erb +++ b/app/views/users/_project_attachment.html.erb @@ -38,4 +38,9 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/users/_project_create.html.erb b/app/views/users/_project_create.html.erb index 0e35bca25..83bfe3f04 100644 --- a/app/views/users/_project_create.html.erb +++ b/app/views/users/_project_create.html.erb @@ -36,4 +36,9 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/users/_project_issue.html.erb b/app/views/users/_project_issue.html.erb index 008f08706..daa7c71c2 100644 --- a/app/views/users/_project_issue.html.erb +++ b/app/views/users/_project_issue.html.erb @@ -96,3 +96,8 @@ <%= render :partial => 'users/project_issue_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> + \ No newline at end of file diff --git a/app/views/users/_project_message.html.erb b/app/views/users/_project_message.html.erb index c071f4a13..0a41dbbf5 100644 --- a/app/views/users/_project_message.html.erb +++ b/app/views/users/_project_message.html.erb @@ -167,3 +167,8 @@ <% end %> + diff --git a/app/views/users/_user_blog.html.erb b/app/views/users/_user_blog.html.erb index 841fd9377..74f090344 100644 --- a/app/views/users/_user_blog.html.erb +++ b/app/views/users/_user_blog.html.erb @@ -144,4 +144,7 @@ $("#relatePWrap_<%=user_activity_id %>").toggleClass('relatePWrap'); $("#moreProject_<%=user_activity_id %>").show(); }); + $(function(){ + user_card_show_hide(); + }); diff --git a/app/views/users/_user_homework_detail.html.erb b/app/views/users/_user_homework_detail.html.erb index 43bde1779..861a35ed9 100644 --- a/app/views/users/_user_homework_detail.html.erb +++ b/app/views/users/_user_homework_detail.html.erb @@ -162,9 +162,9 @@
<% if homework_common.homework_type != 2 %> <% ids = student_work_scores.empty? ? "(-1)" : '('+student_work_scores.map{|sw|sw.student_work_id}.join(',')+')' %> - <% student_works = homework_common.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where("student_works.id in #{ids}").order("score desc") %> + <% student_works = homework_common.student_works.select("student_works.*,student_works.work_score as score").where("student_works.id in #{ids}").order("score desc") %> <% else %> - <% student_works = homework_common.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("score desc") %> + <% student_works = homework_common.student_works.select("student_works.*,student_works.work_score as score").order("score desc") %> <% end %> <% student_works.includes(:user).each_with_index do |sw, i| %>
@@ -230,7 +230,7 @@
项目名称:<%=project.name %>
创建者:<%=(User.find project.user_id).show_name %>(组长)
- 更新时间:<%=time_from_now time %> + 更新时间:<%=time_from_now !com_time.nil? && format_time(com_time) > format_time(time) ? com_time : time %>
<% if i == 9 && projects.count > 10 %> @@ -392,4 +392,7 @@ $("#relatePWrap_<%=homework_common.id %>").toggleClass('relatePWrap'); $("#moreProject_<%=homework_common.id %>").show(); }); + $(function(){ + user_card_show_hide(); + }); \ No newline at end of file diff --git a/app/views/users/_user_journalsformessage.html.erb b/app/views/users/_user_journalsformessage.html.erb index dde4f34ce..944477e88 100644 --- a/app/views/users/_user_journalsformessage.html.erb +++ b/app/views/users/_user_journalsformessage.html.erb @@ -149,4 +149,9 @@
- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/users/choose_user_course.js.erb b/app/views/users/choose_user_course.js.erb index 77c8d2522..51af05782 100644 --- a/app/views/users/choose_user_course.js.erb +++ b/app/views/users/choose_user_course.js.erb @@ -2,6 +2,8 @@ alert("您的申请尚未通过审核,暂时不可发送至课程"); <% elsif @status == 2 %> alert("该作业是私有的,请先提交申请并通过审核后再发送"); +<% elsif @status == 3 %> + alert("您的申请已被拒绝,不可发送至课程"); <% else %> <% if params[:is_observe].nil? %> $("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/send_homework_to_course', :locals => {:courses => @course, :user => @user, :send_id => @send_id}) %>'); diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 22515205c..10d0af25b 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2139,7 +2139,7 @@ zh: label_journals_comment_template: 您的留言有新回复了 label_blog_comment_template: 您的博客有新回复了 label_new_blog_template: 有新博客了 - label_new_issue_template: 您有新缺陷了 + label_new_issue_template: 有新缺陷了 label_new_notice_template: 您的课程有新通知了 #edit yk label_code_work_tests: 代码测试列表 diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index f87af796f..f0f8e9c92 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -1,6 +1,7 @@
+
diff --git a/public/assets/wechat/app.html b/public/assets/wechat/app.html index 7caa318b6..63e88490f 100644 --- a/public/assets/wechat/app.html +++ b/public/assets/wechat/app.html @@ -14,11 +14,6 @@
-
-
- 加载中... -
-
diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 7c52bae35..e7be7acbd 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -23,6 +23,32 @@ function description_show_hide(id){ }); } +//名片的显示 +function user_card_show_hide() { + $(".homepagePostPortrait").mouseover(function(){ + $(".userCard").css("display","none"); + onImage = true; + $(this).children(".userCard").css("display","block"); + }); + $(".homepagePostPortrait").mouseout(function(){ + var cur = $(this); + onImage = false; + setTimeout(function(){ + if (onUserCard == false && onImage == false){ + $(cur).children(".userCard").css("display", "none"); + } + }, 500); + }); + $(".userCard").mouseover(function(){ + onUserCard = true; + $(this).css("display","block"); + }); + $(".userCard").mouseout(function(){ + onUserCard = false; + $(this).css("display","none"); + }); +} + function cleanArray (actual){ var newArray = new Array(); for (var i = 0; i< actual.length; i++){ diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index e5444c384..16fa8cf03 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -3,6 +3,7 @@ var apiUrl = '/api/v1/'; var debug = false; //调试标志,如果在本地请置为true if(debug===true){ + //apiUrl = 'http://localhost:3000/api/v1/'; apiUrl = 'https://www.trustie.net/api/v1/'; } @@ -435,6 +436,25 @@ app.directive('textAutoHeight', function($timeout){ } }); +app.directive('loadingSpinner', function ($http) { + return { + restrict: 'A', + replace: true, + template: '
加载中...
', + link: function (scope, element, attrs) { + + scope.$watch('activeCalls', function (newVal, oldVal) { + if (newVal == 0) { + $(element).hide(); + } + else { + $(element).show(); + } + }); + } + }; +}); + app.config(['$routeProvider',"$httpProvider",function ($routeProvider, $httpProvider) { $routeProvider .when('/activities', { @@ -472,22 +492,30 @@ app.config(['$routeProvider',"$httpProvider",function ($routeProvider, $httpProv .otherwise({ redirectTo: '/activities' }); - //$httpProvider.interceptors.push('timestampMarker'); -}]); -//loading -app.factory('timestampMarker', ["$rootScope", function ($rootScope) { - var timestampMarker = { - request: function (config) { - $rootScope.loading = true; - config.requestTimestamp = new Date().getTime(); - return config; - }, - response: function (response) { - // $rootScope.loading = false; - response.config.responseTimestamp = new Date().getTime(); - return response; - } - }; - return timestampMarker; + //监听异步请求 + $httpProvider.interceptors.push(function ($q, $rootScope) { + if ($rootScope.activeCalls == undefined) { + $rootScope.activeCalls = 0; + } + + return { + request: function (config) { + $rootScope.activeCalls += 1; + return config; + }, + requestError: function (rejection) { + $rootScope.activeCalls -= 1; + return rejection; + }, + response: function (response) { + $rootScope.activeCalls -= 1; + return response; + }, + responseError: function (rejection) { + $rootScope.activeCalls -= 1; + return rejection; + } + }; + }); }]); diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index c10f2b9cb..be23fffec 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -1322,7 +1322,7 @@ a.sortdownbtn{ background: url(../images/liststyle.png) 0 -12px no-repeat; width .item_list{ display:block; width:5px; height:5px;-webkit-border-radius: 25px;border-radius:25px; background-color:#adadad; margin:10px 10px 0 0;} .list-file a.list-title{ font-size:14px; font-weight: bold; color:#000;white-space:nowrap; overflow:hidden; text-overflow:ellipsis; display:block; max-width:550px;} a:hover.list-title{ color:#269ac9;} -.c_red{ font-weight:normal; font-size:12px;} +.font_normal{ font-weight:normal; font-size:12px;} .list-file{ padding:10px 0; border-bottom:1px dashed #ddd;} .list-file li{ line-height:1.9;} .list-info span{ margin-left:5px;} diff --git a/public/stylesheets/new_user.css b/public/stylesheets/new_user.css index aa8f5c899..09319ff65 100644 --- a/public/stylesheets/new_user.css +++ b/public/stylesheets/new_user.css @@ -1519,7 +1519,7 @@ a.sortdownbtn{ background: url(../images/liststyle.png) 0 -12px no-repeat; width .item_list{ display:block; width:5px; height:5px;-webkit-border-radius: 25px;border-radius:25px; background-color:#adadad; margin:10px 10px 0 0;} .list-file a.list-title{ font-size:14px; font-weight: bold; color:#000;white-space:nowrap; overflow:hidden; text-overflow:ellipsis; display:block; max-width:550px;} a:hover.list-title{ color:#269ac9;} -.c_red{ font-weight:normal; font-size:12px;} +.font_normal{ font-weight:normal; font-size:12px;} .list-file{ padding:10px 0; border-bottom:1px dashed #ddd;} .list-file li{ line-height:1.9;} .list-info span{ margin-left:5px;} diff --git a/public/stylesheets/project.css b/public/stylesheets/project.css index 713b959f5..aae9ceb7c 100644 --- a/public/stylesheets/project.css +++ b/public/stylesheets/project.css @@ -1220,7 +1220,7 @@ a.sortdownbtn{ background: url(../images/liststyle.png) 0 -12px no-repeat; width .item_list{ display:block; width:5px; height:5px;-webkit-border-radius: 25px;border-radius:25px; background-color:#adadad; margin:10px 10px 0 0;} .list-file a.list-title{ font-size:14px; font-weight: bold; color:#000;white-space:nowrap; overflow:hidden; text-overflow:ellipsis; display:block; max-width:550px;} a:hover.list-title{ color:#269ac9;} -.c_red{ font-weight:normal; font-size:12px;} +.font_normal{ font-weight:normal; font-size:12px;} .list-file{ padding:10px 0; border-bottom:1px dashed #ddd;} .list-file li{ line-height:1.9;} .list-info span{ margin-left:5px;} @@ -1230,4 +1230,5 @@ a.pages-big{ width:50px;} .pages .active{ background-color:#269ac9; color:#fff;} .pages{width:330px; margin:20px auto 10px;} -.red-cir-btn{ background:#e74c3c; padding:1px 5px; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; color:#fff; font-weight:normal;font-size:12px;} \ No newline at end of file +.red-cir-btn{ background:#e74c3c; padding:1px 5px; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; color:#fff; font-weight:normal;font-size:12px;} +.green-cir-btn{ background:#28be6c; padding:1px 5px; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; color:#fff; font-weight:normal;font-size:12px;} \ No newline at end of file diff --git a/public/stylesheets/weui/weixin.css b/public/stylesheets/weui/weixin.css index 22c568a2e..fffa7a214 100644 --- a/public/stylesheets/weui/weixin.css +++ b/public/stylesheets/weui/weixin.css @@ -76,4 +76,4 @@ a.underline {text-decoration:underline;} .loading-bg {position:fixed; width:100%; height:100%; left:0; top:0; z-index:99; background:rgba(206, 206, 206, 0.3); overflow:hidden;} .loading-box {position:absolute; top:50%; background:white; width:160px; height:72px; left:50%; margin-top:-36px; margin-left:-80px; text-align:center;} .loading-box img {margin-top: 3px; text-align: center;} -.loading-box span {display: block; font-size:13px;} +.loading-box span {display: block; font-size:12px;}