diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index b878a14ac..e974f26b4 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -572,6 +572,15 @@ class AttachmentsController < ApplicationController end end + #找到文件的所有的历史版本及当前版本 + def attachment_history_download + @attachment = Attachment.find(params[:id]) + @attachment_histories = @attachment.attachment_histories + respond_to do |format| + format.js + end + end + private def find_project @attachment = Attachment.find(params[:id]) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index f06a782bc..24f5fd52c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -902,10 +902,7 @@ class CoursesController < ApplicationController end def feedback - @course.journals_for_messages.each do |messages| - query = messages.course_messages.where("user_id = ?", User.current.id) - query.update_all(:viewed => true); - end + CourseMessage.where("user_id = ? and course_id = ?", User.current, @course.id).update_all(:viewed => true) if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) page = params[:page] diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 9f754a0fc..3532a9e4c 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -1,378 +1,380 @@ -class HomeworkCommonController < ApplicationController - require 'net/http' - require 'json' - require "base64" - layout "base_courses" - - include StudentWorkHelper - before_filter :find_course, :only => [:index,:new,:create] - before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] - before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] - before_filter :member_of_course, :only => [:index] - - def index - @new_homework = HomeworkCommon.new - @new_homework.homework_detail_manual = HomeworkDetailManual.new - @new_homework.course = @course - @page = params[:page] ? params[:page].to_i + 1 : 0 - @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) - if @is_teacher - @homeworks = @course.homework_commons.order("updated_at desc").limit(10).offset(@page * 10) - else - @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("updated_at desc").limit(10).offset(@page * 10) - end - @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) - @is_new = params[:is_new] - - #设置at已读 - @homeworks.each do |homework| - homework.journals_for_messages.each do |j| - User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} - end - end - - respond_to do |format| - format.js - format.html - end - end - - #新建作业,在个人作业列表创建作业 - def new - render_404 - end - - #新建作业,在个人作业列表创建作业 - def create - redirect_to user_homeworks_user_path(User.current.id) - end - - def edit - @user = User.current - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - respond_to do |format| - format.html{render :layout => 'new_base_user'} - end - end - - def update - if params[:homework_common] - @homework.name = params[:homework_common][:name] - @homework.description = params[:homework_common][:description] - if params[:homework_common][:publish_time] == "" - @homework.publish_time = Date.today - else - @homework.publish_time = params[:homework_common][:publish_time] - end - @homework.end_time = params[:homework_common][:end_time] || Time.now - @homework.course_id = params[:course_id] - @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0 - - homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new - if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 - homework_detail_manual.comment_status = 1 - end - homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? @homework.end_time + 7 : params[:evaluation_start] - homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end] - - @homework.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(@homework) - - #编程作业相关属性 - if @homework.homework_type == 2 - @homework.homework_detail_programing ||= HomeworkDetailPrograming.new - @homework_detail_programing = @homework.homework_detail_programing - @homework_detail_programing.language = params[:language_type].to_i - - @homework.homework_tests.delete_all - inputs = params[:program][:input] - if Array === inputs - inputs.each_with_index do |val, i| - @homework.homework_tests << HomeworkTest.new( - input: val, - output: params[:program][:output][i] - ) - end - end - end - - #分组作业 - if @homework.homework_type == 3 - @homework.homework_detail_group ||= HomeworkDetailGroup.new - @homework_detail_group = @homework.homework_detail_group - @homework_detail_group.min_num = params[:min_num].to_i - @homework_detail_group.max_num = params[:max_num].to_i - @homework_detail_group.base_on_project = params[:base_on_project].to_i - end - - if @homework.save - @homework_detail_manual.save if @homework_detail_manual - @homework_detail_programing.save if @homework_detail_programing - @homework_detail_group.save if @homework_detail_group - - if params[:is_in_course] == "1" - redirect_to homework_common_index_path(:course => @course.id) - elsif params[:is_in_course] == "0" - redirect_to user_homeworks_user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" - redirect_to user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" - redirect_to course_path(@course.id) - end - end - end - end - - def destroy - if @homework.destroy - respond_to do |format| - format.html { - if params[:is_in_course] == "1" - redirect_to homework_common_index_path(:course => @course.id) - elsif params[:is_in_course] == "0" - redirect_to user_homeworks_user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" - redirect_to user_path(User.current.id) - elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" - redirect_to course_path(@course.id) - end - } - end - end - end - - #开启匿评 - #statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限 - def start_anonymous_comment - @statue = 4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course) - @statue = 5 and return if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") - if @homework_detail_manual.comment_status == 1 - student_works = @homework.student_works - if student_works && student_works.size >= 2 - if @homework.homework_type == 3 - student_work_projects = @homework.student_work_projects.where("student_work_id is not null") - student_work_projects.each_with_index do |pro_work, pro_index| - n = @homework_detail_manual.evaluation_num - n = n < student_works.size ? n : student_works.size - 1 - work_index = -1 - student_works.each_with_index do |stu_work, stu_index| - if stu_work.id.to_i == pro_work.student_work_id.to_i - work_index = stu_index - end - end - assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) - student_works_evaluation_distributions.save - end - end - else - student_works.each_with_index do |work, index| - user = work.user - n = @homework_detail_manual.evaluation_num - n = n < student_works.size ? n : student_works.size - 1 - assigned_homeworks = get_assigned_homeworks(student_works, n, index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) - student_works_evaluation_distributions.save - end - end - end - @homework_detail_manual.update_column('comment_status', 2) - @homework_detail_manual.update_column('evaluation_start', Date.today) - @statue = 1 - # 匿评开启消息邮件通知 - send_message_anonymous_comment(@homework, m_status = 2) - Mailer.send_mail_anonymous_comment_open(@homework).deliver - else - @statue = 2 - - end - else - @statue = 3 - end - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - end - - #关闭匿评 - def stop_anonymous_comment - @homework_detail_manual.update_column('comment_status', 3) - @homework_detail_manual.update_column('evaluation_end', Date.today) - #计算缺评扣分 - work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" - @homework.student_works.each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 - student_work.save - end - # 匿评关闭消息邮件通知 - send_message_anonymous_comment(@homework, m_status = 3) - Mailer.send_mail_anonymous_comment_close(@homework).deliver - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - respond_to do |format| - format.js - end - end - - # 开启/关闭匿评消息通知 - def send_message_anonymous_comment(homework, m_status ) - # status 标记匿评状态 1为关闭 0为开启 - course = homework.course - course.members.each do |m| - @homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => m_status) - end - end - #提示 - def alert_anonymous_comment - @cur_size = 0 - @totle_size = 0 - if @homework_detail_manual.comment_status == 1 - @totle_size = @course.student.count - @cur_size = @homework.student_works.size - elsif @homework_detail_manual.comment_status == 2 - @homework.student_works.map { |work| @totle_size += work.student_works_evaluation_distributions.count} - @cur_size = 0 - @homework.student_works.map { |work| @cur_size += work.student_works_scores.where(:reviewer_role => 3).count} - end - @percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100) - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - respond_to do |format| - format.js - end - end - - def alert_forbidden_anonymous_comment - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] if params[:is_in_course] - @course_activity = params[:course_activity] if params[:course_Activity] - respond_to do |format| - format.js - end - end - - def open_student_works - if @homework.is_open == 0 - @homework.update_attribute(:is_open, 1) - else - @homework.update_attribute(:is_open, 0) - end - @user_activity_id = params[:user_activity_id] - @is_in_course = params[:is_in_course] if params[:is_in_course] - @course_activity = params[:course_activity] if params[:course_Activity] - end - - def alert_open_student_works - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] if params[:is_in_course] - @course_activity = params[:course_activity] if params[:course_Activity] - respond_to do |format| - format.js - end - end - - def programing_test - test = {language:params[:language],src:Base64.encode64(params[:src]),input:[params[:input]],output:[params[:output]]} - @index = params[:index] - uri = URI('http://192.168.80.21:8080/api/realtime.json') - body = test.to_json - 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 - result = JSON.parse(res.body) - @err_msg = result["compile_error_msg"] - result["results"].each do |re| - @result = re["status"] - end - end - - #启动匿评参数设置 - def start_evaluation_set - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] - @course_activity = params[:course_activity].to_i - end - - #设置匿评参数 - def set_evaluation_attr - if @homework_detail_manual - unless params[:evaluation_start].to_s == @homework_detail_manual.evaluation_start.to_s - @homework_detail_manual.evaluation_start = params[:evaluation_start] - end - - unless @homework_detail_manual.evaluation_end.to_s == params[:evaluation_end].to_s - @homework_detail_manual.evaluation_end = params[:evaluation_end] - end - - @homework_detail_manual.evaluation_num = params[:evaluation_num] - @homework_detail_manual.save - @user_activity_id = params[:user_activity_id].to_i - @is_in_course = params[:is_in_course].to_i - @course_activity = params[:course_activity].to_i - end - end - - #评分设置 - def score_rule_set - if params[:user_activity_id] - @user_activity_id = params[:user_activity_id] - else - @user_activity_id = -1 - end - @is_in_course = params[:is_in_course] - @course_activity = params[:course_activity].to_i - end - - private - #获取课程 - def find_course - @course = Course.find params[:course] - rescue - render_404 - end - #获取作业 - def find_homework - @homework = HomeworkCommon.find params[:id] - @homework_detail_manual = @homework.homework_detail_manual - @homework_detail_programing = @homework.homework_detail_programing - @homework_detail_group = @homework.homework_detail_group - @course = @homework.course - rescue - render_404 - end - #是不是课程的老师 - def teacher_of_course - render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin? - end - - #当前用户是不是课程的成员 - def member_of_course - render_403 unless @course.is_public==1 || User.current.member_of_course?(@course) || User.current.admin? - end - - def get_assigned_homeworks(student_works, n, index) - student_works += student_works - student_works[index + 1 .. index + n] - end -end +class HomeworkCommonController < ApplicationController + require 'net/http' + require 'json' + require "base64" + layout "base_courses" + + include StudentWorkHelper + before_filter :find_course, :only => [:index,:new,:create] + before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] + before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment,:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works] + before_filter :member_of_course, :only => [:index] + + def index + @new_homework = HomeworkCommon.new + @new_homework.homework_detail_manual = HomeworkDetailManual.new + @new_homework.course = @course + @page = params[:page] ? params[:page].to_i + 1 : 0 + @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) + if @is_teacher + @homeworks = @course.homework_commons.order("updated_at desc").limit(10).offset(@page * 10) + else + @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("updated_at desc").limit(10).offset(@page * 10) + end + @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) + @is_new = params[:is_new] + + #设置at已读 + @homeworks.each do |homework| + homework.journals_for_messages.each do |j| + User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!} + end + end + + respond_to do |format| + format.js + format.html + end + end + + #新建作业,在个人作业列表创建作业 + def new + render_404 + end + + #新建作业,在个人作业列表创建作业 + def create + redirect_to user_homeworks_user_path(User.current.id) + end + + def edit + @user = User.current + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.html{render :layout => 'new_base_user'} + end + end + + def update + if params[:homework_common] + @homework.name = params[:homework_common][:name] + @homework.description = params[:homework_common][:description] + if params[:homework_common][:publish_time] == "" + @homework.publish_time = Date.today + else + @homework.publish_time = params[:homework_common][:publish_time] + end + @homework.end_time = params[:homework_common][:end_time] || Time.now + @homework.course_id = params[:course_id] + @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0 + + homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new + if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 + 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 + homework_detail_manual.evaluation_start = @homework.end_time + 7 + homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7 + end + @homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@homework) + + #编程作业相关属性 + if @homework.homework_type == 2 + @homework.homework_detail_programing ||= HomeworkDetailPrograming.new + @homework_detail_programing = @homework.homework_detail_programing + @homework_detail_programing.language = params[:language_type].to_i + + @homework.homework_tests.delete_all + inputs = params[:program][:input] + if Array === inputs + inputs.each_with_index do |val, i| + @homework.homework_tests << HomeworkTest.new( + input: val, + output: params[:program][:output][i] + ) + end + end + end + + #分组作业 + if @homework.homework_type == 3 + @homework.homework_detail_group ||= HomeworkDetailGroup.new + @homework_detail_group = @homework.homework_detail_group + @homework_detail_group.min_num = params[:min_num].to_i + @homework_detail_group.max_num = params[:max_num].to_i + @homework_detail_group.base_on_project = params[:base_on_project].to_i + end + + if @homework.save + @homework_detail_manual.save if @homework_detail_manual + @homework_detail_programing.save if @homework_detail_programing + @homework_detail_group.save if @homework_detail_group + + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => @course.id) + elsif params[:is_in_course] == "0" + redirect_to user_homeworks_user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" + redirect_to user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" + redirect_to course_path(@course.id) + end + end + end + end + + def destroy + if @homework.destroy + respond_to do |format| + format.html { + if params[:is_in_course] == "1" + redirect_to homework_common_index_path(:course => @course.id) + elsif params[:is_in_course] == "0" + redirect_to user_homeworks_user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "0" + redirect_to user_path(User.current.id) + elsif params[:is_in_course] == "-1" && params[:course_activity] == "1" + redirect_to course_path(@course.id) + end + } + end + end + end + + #开启匿评 + #statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限 + def start_anonymous_comment + @statue = 4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course) + @statue = 5 and return if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + if @homework_detail_manual.comment_status == 1 + student_works = @homework.student_works + if student_works && student_works.size >= 2 + if @homework.homework_type == 3 + student_work_projects = @homework.student_work_projects.where("student_work_id is not null") + student_work_projects.each_with_index do |pro_work, pro_index| + n = @homework_detail_manual.evaluation_num + n = n < student_works.size ? n : student_works.size - 1 + work_index = -1 + student_works.each_with_index do |stu_work, stu_index| + if stu_work.id.to_i == pro_work.student_work_id.to_i + work_index = stu_index + end + end + assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + else + student_works.each_with_index do |work, index| + user = work.user + n = @homework_detail_manual.evaluation_num + n = n < student_works.size ? n : student_works.size - 1 + assigned_homeworks = get_assigned_homeworks(student_works, n, index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + end + @homework_detail_manual.update_column('comment_status', 2) + @homework_detail_manual.update_column('evaluation_start', Date.today) + @statue = 1 + # 匿评开启消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 2) + Mailer.send_mail_anonymous_comment_open(@homework).deliver + else + @statue = 2 + + end + else + @statue = 3 + end + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + end + + #关闭匿评 + def stop_anonymous_comment + @homework_detail_manual.update_column('comment_status', 3) + @homework_detail_manual.update_column('evaluation_end', Date.today) + #计算缺评扣分 + work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")" + @homework.student_works.each do |student_work| + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count + student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0 + student_work.save + end + # 匿评关闭消息邮件通知 + send_message_anonymous_comment(@homework, m_status = 3) + Mailer.send_mail_anonymous_comment_close(@homework).deliver + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + + # 开启/关闭匿评消息通知 + def send_message_anonymous_comment(homework, m_status ) + # status 标记匿评状态 1为关闭 0为开启 + course = homework.course + course.members.each do |m| + @homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => m_status) + end + end + #提示 + def alert_anonymous_comment + @cur_size = 0 + @totle_size = 0 + if @homework_detail_manual.comment_status == 1 + @totle_size = @course.student.count + @cur_size = @homework.student_works.size + elsif @homework_detail_manual.comment_status == 2 + @homework.student_works.map { |work| @totle_size += work.student_works_evaluation_distributions.count} + @cur_size = 0 + @homework.student_works.map { |work| @cur_size += work.student_works_scores.where(:reviewer_role => 3).count} + end + @percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100) + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + + def alert_forbidden_anonymous_comment + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + respond_to do |format| + format.js + end + end + + def open_student_works + if @homework.is_open == 0 + @homework.update_attribute(:is_open, 1) + else + @homework.update_attribute(:is_open, 0) + end + @user_activity_id = params[:user_activity_id] + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + end + + def alert_open_student_works + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] if params[:is_in_course] + @course_activity = params[:course_activity] if params[:course_Activity] + respond_to do |format| + format.js + end + end + + def programing_test + test = {language:params[:language],src:Base64.encode64(params[:src]),input:[params[:input]],output:[params[:output]]} + @index = params[:index] + uri = URI('http://192.168.80.21:8080/api/realtime.json') + body = test.to_json + 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 + result = JSON.parse(res.body) + @err_msg = result["compile_error_msg"] + result["results"].each do |re| + @result = re["status"] + end + end + + #启动匿评参数设置 + def start_evaluation_set + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] + @course_activity = params[:course_activity].to_i + end + + #设置匿评参数 + def set_evaluation_attr + if @homework_detail_manual + unless params[:evaluation_start].to_s == @homework_detail_manual.evaluation_start.to_s + @homework_detail_manual.evaluation_start = params[:evaluation_start] + end + + unless @homework_detail_manual.evaluation_end.to_s == params[:evaluation_end].to_s + @homework_detail_manual.evaluation_end = params[:evaluation_end] + end + + @homework_detail_manual.evaluation_num = params[:evaluation_num] + @homework_detail_manual.save + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + end + end + + #评分设置 + def score_rule_set + if params[:user_activity_id] + @user_activity_id = params[:user_activity_id] + else + @user_activity_id = -1 + end + @is_in_course = params[:is_in_course] + @course_activity = params[:course_activity].to_i + end + + private + #获取课程 + def find_course + @course = Course.find params[:course] + rescue + render_404 + end + #获取作业 + def find_homework + @homework = HomeworkCommon.find params[:id] + @homework_detail_manual = @homework.homework_detail_manual + @homework_detail_programing = @homework.homework_detail_programing + @homework_detail_group = @homework.homework_detail_group + @course = @homework.course + rescue + render_404 + end + #是不是课程的老师 + def teacher_of_course + render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + end + + #当前用户是不是课程的成员 + def member_of_course + render_403 unless @course.is_public==1 || User.current.member_of_course?(@course) || User.current.admin? + end + + def get_assigned_homeworks(student_works, n, index) + student_works += student_works + student_works[index + 1 .. index + n] + end +end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index eb78c4c5b..44f0d15f4 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -118,6 +118,9 @@ class IssuesController < ApplicationController end def show + # 打开编辑内容 + @is_edit = true unless params[:edit].nil? + # 当前用户查看指派给他的缺陷消息,则设置消息为已读 query = ForgeMessage.where("forge_message_type =? and user_id =? and forge_message_id =?", "Issue", User.current, @issue).first query.update_attribute(:viewed, true) unless query.nil? @@ -387,6 +390,9 @@ class IssuesController < ApplicationController end def destroy + # 增加删除页面类型,如果是个人主页,则返回该主页,项目动态则返回项目动态页眉 + page_classify = params[:page_classify] unless params[:page_classify].nil? + page_id = params[:page_id] unless params[:page_id].nil? @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f if @hours > 0 case params[:todo] @@ -415,7 +421,11 @@ class IssuesController < ApplicationController end end respond_to do |format| - format.html { redirect_back_or_default _project_issues_path(@project) } + if page_classify + format.html { redirect_back_or_default _project_issues_path(@project, page_classify, page_id) } + else + format.html { redirect_back_or_default _project_issues_path(@project) } + end format.api { render_api_ok } end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1c9a00fa4..33b6e8643 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -110,8 +110,7 @@ class UsersController < ApplicationController elsif @user != User.current && !User.current.admin? return render_403 end - # 初始化/更新 点击按钮时间 - # 24小时内显示系统消息 + # 初始化/更新 点击按钮时间, 24小时内显示系统消息 update_onclick_time # 全部设为已读 if params[:viewed] == "all" @@ -190,17 +189,19 @@ class UsersController < ApplicationController # 消息设置为已读 def update_message_viewed(user) - course_querys = CourseMessage.where("user_id =? and viewed =?", user, 0) - forge_querys = ForgeMessage.where("user_id =? and viewed =?", user, 0) - user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0) - forum_querys = MemoMessage.where("user_id =? and viewed =?", user, 0) - org_querys = OrgMessage.where("user_id=? and viewed=0", user) if User.current.id == @user.id - course_querys.update_all(:viewed => true) - forge_querys.update_all(:viewed => true) - user_querys.update_all(:viewed => true) - forum_querys.update_all(:viewed => true) - org_querys.update_all(:viewed => true) + course_querys = CourseMessage.where("user_id =? and viewed =?", user, 0) + forge_querys = ForgeMessage.where("user_id =? and viewed =?", user, 0) + user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0) + forum_querys = MemoMessage.where("user_id =? and viewed =?", user, 0) + org_querys = OrgMessage.where("user_id=? and viewed=0", user) + at_querys = AtMessage.where("user_id=? and viewed=0", user) + course_querys.update_all(:viewed => true) unless course_querys.nil? + forge_querys.update_all(:viewed => true) unless forge_querys.nil? + user_querys.update_all(:viewed => true) unless user_querys.nil? + forum_querys.update_all(:viewed => true) unless forum_querys.nil? + org_querys.update_all(:viewed => true) unless org_querys.nil? + at_querys.update_all(:viewed => true) unless at_querys.nil? end end @@ -387,12 +388,12 @@ class UsersController < ApplicationController @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("#{@order} #{@b_sort}") end @type = params[:type] - @limit = 15 + @limit = 25 @is_remote = true @hw_count = @homeworks.count @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @offset ||= @hw_pages.offset - @homeworks = paginateHelper @homeworks,15 + @homeworks = paginateHelper @homeworks,25 respond_to do |format| format.js format.html {render :layout => 'static_base'} @@ -546,13 +547,13 @@ class UsersController < ApplicationController end @type = params[:type] @property = params[:property] - @limit = 15 + @is_import = params[:is_import] + @limit = params[:is_import].to_i == 1 ? 15 : 25 @is_remote = true @hw_count = @homeworks.count @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @offset ||= @hw_pages.offset - @homeworks = paginateHelper @homeworks,15 - @is_import = params[:is_import] + @homeworks = paginateHelper @homeworks,@limit respond_to do |format| format.js end @@ -572,6 +573,7 @@ class UsersController < ApplicationController @r_sort = @b_sort == "desc" ? "asc" : "desc" @user = User.current search = params[:name].to_s.strip.downcase + type_ids = params[:property] ? "(" + params[:property] + ")" : "(1, 2, 3)" if(params[:type].blank? || params[:type] == "1") #全部 visible_course = Course.where("is_public = 1 && is_delete = 0") visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" @@ -579,24 +581,40 @@ class UsersController < ApplicationController all_user_ids = all_homeworks.map{|hw| hw.user_id} user_str_ids = search_user_by_name all_user_ids, search user_ids = user_str_ids.empty? ? "(-1)" : "(" + user_str_ids.join(",") + ")" - @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order} #{@b_sort}") + if @order == "course_name" + sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_type in #{type_ids} and course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%' or homework_commons.user_id in #{user_ids}) order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}" + @homeworks = HomeworkCommon.find_by_sql(sql) + elsif @order == "user_name" + @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}") + else + @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order} #{@b_sort}") + end elsif params[:type] == "2" #课程资源 - @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("#{@order} #{@b_sort}") + if @order == "course_name" + sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}" + @homeworks = HomeworkCommon.find_by_sql(sql) + elsif @order == "user_name" + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}") + else + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order} #{@b_sort}") + end end +=begin if params[:property] && params[:property] == "1" - @homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}") + @homeworks = @homeworks.where("homework_type = 1") elsif params[:property] && params[:property] == "2" - @homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}") + @homeworks = @homeworks.where("homework_type = 2") elsif params[:property] && params[:property] == "3" - @homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}") + @homeworks = @homeworks.where("homework_type = 3") end +=end @type = params[:type] - @limit = 15 + @limit = params[:is_import].to_i == 1 ? 15 : 25 @is_remote = true @hw_count = @homeworks.count @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @offset ||= @hw_pages.offset - @homeworks = paginateHelper @homeworks,15 + @homeworks = paginateHelper @homeworks,@limit @is_import = params[:is_import] @property = params[:property] @search = search @@ -823,20 +841,33 @@ class UsersController < ApplicationController user_course_ids = User.current.courses.map { |c| c.id} user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} - if(params[:type].blank? || params[:type] == "1") #全部 + if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) - elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) - elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) - elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] - elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] + if params[:status] == "2" + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(params[:id], @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(params[:id], @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) + end elsif params[:type] == "6" # 公共资源 - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + end end @type = params[:type] @limit = 7 @@ -946,12 +977,7 @@ class UsersController < ApplicationController return end # 自己访问自己的页面才更新消息状态 - if User.current == @user - journals_messages = UserFeedbackMessage.where("user_id =? and journals_for_message_type =? and viewed =?", User.current.id, "JournalsForMessage", 0) - journals_messages.each do |journals_message| - journals_message.update_attributes(:viewed => true) - end - end + UserFeedbackMessage.where("user_id =? and viewed =? and journals_for_message_type =? ", User.current.id, 0, "JournalsForMessage").update_all(:viewed => true) # end @page = params[:page] ? params[:page].to_i + 1 : 0 if params[:type].present? @@ -1553,43 +1579,39 @@ class UsersController < ApplicationController user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} @user = User.find(params[:id]) - #@user.save_attachments(params[:attachments],User.current) - # Container_type为Principal + # 保存文件 attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true) + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + user_course_ids = User.current.courses.map { |c| c.id} + user_project_ids = User.current.projects.map {|p| p.id} + # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == 2 - @attachments = get_course_resources(params[:id], user_course_ids) + if params[:status] == "2" + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources(params[:id], @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources(params[:id], @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) - elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) - elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] - elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids) + @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids) + @attachments = get_project_resources_public(user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources_public + @attachments = get_attch_resources_public(@order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources_public + @attachments = get_principal_resources_public(@order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end end @status = params[:status] @@ -1609,49 +1631,44 @@ class UsersController < ApplicationController # 删除用户资源,分为批量删除 和 单个删除,只能删除自己上传的资源 def user_resource_delete if params[:resource_id].present? - Attachment.where("author_id = #{User.current.id}").delete(params[:resource_id]) + Attachment.where("author_id =? and id =?", User.current.id, params[:resource_id]).first.destroy elsif params[:checkbox1].present? params[:checkbox1].each do |id| - Attachment.where("author_id = #{User.current.id}").delete(id) + Attachment.where("author_id =? and id =?", User.current.id, id).first.destroy end end + @user = User.current + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" user_course_ids = User.current.courses.map { |c| c.id} user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == 2 - @attachments = get_course_resources(params[:id], user_course_ids) + if params[:status] == "2" + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources(params[:id], @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources(params[:id], @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) - elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) - elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] - elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids) + @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids) + @attachments = get_project_resources_public(user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources_public + @attachments = get_attch_resources_public(@order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources_public + @attachments = get_principal_resources_public(@order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end end @status = params[:status] @@ -1674,10 +1691,10 @@ class UsersController < ApplicationController if !params[:search].nil? search = "%#{params[:search].to_s.strip.downcase}%" @course = @user.courses.where(" #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search) - .select { |course| @user.allowed_to?(:as_teacher,course)} + .select { |course| @user.allowed_to?(:as_teacher,course) and course.is_delete == 0 } else @course = @user.courses - .select { |course| @user.allowed_to?(:as_teacher,course)} + .select { |course| @user.allowed_to?(:as_teacher,course) and course.is_delete == 0 } end @search = params[:search] #这里仅仅是传递需要发送的资源id @@ -1695,7 +1712,7 @@ class UsersController < ApplicationController search = "%#{params[:search].to_s.strip.downcase}%" @projects = @user.projects.where(" #{Project.table_name}.id = #{params[:search].to_i } or #{Project.table_name}.name like :p",:p=>search) else - @projects = @user.projects + @projects = @user.projects.visible end @search = params[:search] #这里仅仅是传递需要发送的资源id @@ -2339,59 +2356,125 @@ class UsersController < ApplicationController end # 获取公共资源 - def get_public_resources user_course_ids, user_project_ids - attachments = Attachment.where("(is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("created_on desc") + def get_public_resources user_course_ids, user_project_ids, order, score + attachments = Attachment.where("(is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取公共资源搜索 + def get_public_resources_search user_course_ids, user_project_ids, order, score, search + attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的资源 - def get_my_resources author_id, user_course_ids, user_project_ids + def get_my_resources author_id, user_course_ids, user_project_ids, order, score attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("created_on desc") + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取我的资源查询结果 + def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search) + @attachments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的课程资源 - def get_course_resources author_id, user_course_ids - attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + def get_course_resources author_id, user_course_ids, order, score + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) + and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取我的课程资源中搜索结果 + def get_course_resources_search author_id, user_course_ids, order, score, search + attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) + and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end - # 获取公共资源课程 - def get_course_resources_public user_course_ids - attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("created_on desc") + # 获取公共资源中课程资源 + def get_course_resources_public user_course_ids, order, score + attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取公共资源中课程资源搜索结果 + def get_course_resources_public_search user_course_ids, order, score, search + attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的项目资源 - def get_project_resources author_id, user_project_ids - attchments = Attachment.where("(author_id = #{author_id} and container_type = 'Project') or (container_type = 'Course' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + def get_project_resources author_id, user_project_ids, order, score + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) + and is_publish = 1 and container_id is not null)").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取我的项目资源搜索 + def get_project_resources_search author_id, user_project_ids, order, score, search + attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ + "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) + and is_publish = 1 and container_id is not null)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源的项目资源 - def get_project_resources_public user_project_ids - attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("created_on desc") + def get_project_resources_public user_project_ids, order, score + attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取公共资源的项目资源搜索 + def get_project_resources_public_search user_project_ids, order, score, search + attchments = Attachment.where("(container_type = 'Project' and container_id is not null and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我上传的附件 - def get_attch_resources author_id - attchments = Attachment.where("author_id = #{author_id} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") + def get_attch_resources author_id, order, score + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue', + 'Document','Message','News','StudentWorkScore','HomewCommon'))").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取我上传的附件搜索结果 + def get_attch_resources_search author_id, order, score, search + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue', + 'Document','Message','News','StudentWorkScore','HomewCommon')) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取公共资源中我上传的附件 + def get_attch_resources_public order, score + attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') + and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取公共资源中我上传的附件 - def get_attch_resources_public - attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') and container_id is not null and is_public =1").order("created_on desc") + def get_attch_resources_public_search order, score, search + attchments = Attachment.where("(container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') + and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的用户类型资源 - def get_principal_resources author_id - attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("created_on desc") + def get_principal_resources author_id, order, score + attchments = Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取我的用户类型资源搜索 + def get_principal_resources_search author_id, order, score, search + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 获取我的用户类型资源 - def get_principal_resources_public - attchments = Attachment.where("container_type = 'Principal'and container_id is not null and is_public =1").order("created_on desc") + def get_principal_resources_public order, score + attchments = Attachment.where("container_type = 'Principal'and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + end + + # 获取我的用户类型资源 + def get_principal_resources_public_search order, score, search + attchments = Attachment.where("(container_type = 'Principal'and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") end # 资源库 分为全部 课程资源 项目资源 附件 def user_resource + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" # 别人的资源库是没有权限去看的 if User.current.id.to_i != params[:id].to_i render_403 @@ -2403,37 +2486,29 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 if params[:status] == "2" - @attachments = get_course_resources(params[:id], user_course_ids) + @attachments = get_course_resources(params[:id], user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources(params[:id], user_project_ids) + @attachments = get_project_resources(params[:id], user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources params[:id] + @attachments = get_attch_resources(params[:id], @order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources params[:id] + @attachments = get_principal_resources(params[:id], @order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) end - elsif params[:type] == "2" # 课程资源 - @attachments = get_course_resources(params[:id], user_course_ids) - elsif params[:type] == "3" # 项目资源 - @attachments = get_project_resources(params[:id], user_project_ids) - elsif params[:type] == "4" #附件 - @attachments = get_attch_resources params[:id] - elsif params[:type] == "5" #用户资源 - @attachments = get_principal_resources params[:id] elsif params[:type] == "6" # 公共资源 if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids) + @attachments = get_course_resources_public( user_course_ids, @order, @score) elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids) + @attachments = get_project_resources_public(user_project_ids, @order, @score) elsif params[:status] == "4" - @attachments = get_attch_resources_public + @attachments = get_attch_resources_public(@order, @score) elsif params[:status] == "5" - @attachments = get_principal_resources_public + @attachments = get_principal_resources_public(@order, @score) else # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end end @status = params[:status] @@ -2458,16 +2533,19 @@ class UsersController < ApplicationController render_403 return end + @user = User.find(params[:id]) + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" user_course_ids = User.current.courses.map { |c| c.id} - user_project_ids = User.current.projects.map {|p| p.id} - # user_org_ids = User.current.organizations.map {|o| o.id} + user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score) elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end + @status = params[:status] @type = params[:type] @limit = 10 @is_remote = true @@ -2483,26 +2561,25 @@ class UsersController < ApplicationController end def import_resources_search - search = "%#{params[:search].strip.downcase}%" + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + @user = User.current + @switch_search = params[:name].nil? ? " " : params[:name] + search = "%#{@switch_search.strip.downcase}%" # 别人的资源库是没有权限去看的 if User.current.id.to_i != params[:id].to_i render_403 return end - user_course_ids = User.current.courses.map { |c| c.id} - user_project_ids = User.current.projects.map {|p| p.id} - # user_org_ids = User.current.organizations.map {|o| o.id} if(params[:type].blank? || params[:type] == "1") # 我的资源 # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 user_course_ids = User.current.courses.map { |c| c.id} user_project_ids = User.current.projects.map {|p| p.id} # user_org_ids = User.current.organizations.map {|o| o.id} - @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc") + @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search) elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids) + @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) end @type = params[:type] @limit = 10 @@ -2511,10 +2588,10 @@ class UsersController < ApplicationController @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 @offset ||= @atta_pages.offset #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,10 + @attachments = paginateHelper @attachments, 10 respond_to do |format| format.js - format.html {render :layout => 'new_base'} + # format.html {render :layout => 'new_base'} end end @@ -2572,55 +2649,41 @@ class UsersController < ApplicationController # 根据资源关键字进行搜索 def resource_search - search = "%#{params[:search].strip.downcase}%" - user_course_ids = User.current.courses.map { |c| c.id} + @order, @b_sort = params[:order] || "created_on", params[:sort] || "desc" + @score = @b_sort == "desc" ? "asc" : "desc" + @user = User.current + @switch_search = params[:search].nil? ? " " : params[:search] + search = "%#{@switch_search.strip.downcase}%" + user_course_ids = User.current.courses.map {|c| c.id} user_project_ids = User.current.projects.map {|p| p.id} - # user_org_ids = User.current.organizations.map {|o| o.id} - if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部 - if User.current.id.to_i == params[:id].to_i - - @attachments = Attachment.where("((author_id = #{params[:id]} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" + - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 - @attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type in" + - " ('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon'))"+ - " or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) )" + - " and (filename like :p) ",:p=>search).order("created_on desc") - end - elsif params[:type] == "2" #课程资源 - if User.current.id.to_i == params[:id].to_i - user_course_ids = User.current.courses.map { |c| c.id} - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 - @attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type = 'Course') "+ - "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) )"+ - " and (filename like :p) ",:p=>search).order("created_on desc") - end - elsif params[:type] == "3" #项目资源 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like :p)",:p=>search).order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' and (filename like :p) ",:p=>search).order("created_on desc") - end - elsif params[:type] == "4" #附件 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("created_on desc") + if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部 + if params[:status] == "2" + @attachments = get_course_resources_search(params[:id], user_course_ids, @order, @score, search) + elsif params[:status] == "3" + @attachments = get_project_resources_search(params[:id], user_project_ids, @order, @score, search) + elsif params[:status] == "4" + @attachments = get_attch_resources_search(params[:id], @order, @score, search) + elsif params[:status] == "5" + @attachments = get_principal_resources_search(params[:id], @order, @score, search) else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("created_on desc") + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search) end - elsif params[:type] == "5" #用户资源 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc") + elsif params[:type] == "6" # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public_search(user_course_ids, @order, @score, search) + elsif params[:status] == "3" + @attachments = get_project_resources_public_search(user_project_ids, @order, @score, search) + elsif params[:status] == "4" + @attachments = get_attch_resources_public_search(@order, @score, search) + elsif params[:status] == "5" + @attachments = get_principal_resources_public_search(@order, @score, search) else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc") + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) end - elsif params[:type] == "6" #全部资源 - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)" ,:p => search).order("created_on desc") end + @status = params[:status] @type = params[:type] @limit = 25 @is_remote = true diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 928f99588..42911cc33 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1044,9 +1044,9 @@ module ApplicationHelper elsif @organization title << @organization.name elsif @user - title << @user.login + title << @user.try(:realname) else - title << User.current.login + title << User.current.try(:realname) end if first_page.nil? || first_page.web_title.nil? title << Setting.app_title unless Setting.app_title == title.last diff --git a/app/helpers/routes_helper.rb b/app/helpers/routes_helper.rb index 15c809964..8d08f22da 100644 --- a/app/helpers/routes_helper.rb +++ b/app/helpers/routes_helper.rb @@ -22,10 +22,18 @@ module RoutesHelper # Returns the path to project issues or to the cross-project # issue list if project is nil def _project_issues_path(project, *args) - if project - project_issues_path(project, *args) + if args[0].to_s.include? '_page' + if args[0].to_s == "user_page" + user_activities_path(args[1].to_i) + else + project_path(project) + end else - issues_path(*args) + if project + project_issues_path(project, *args) + else + issues_path(*args) + end end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 44b919121..bdd34d80d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -62,7 +62,7 @@ module UsersHelper when 'Course' result = current_time_and_term_resource content when 'Project' - result = content.name + result = content.name + "(" + content.id.to_s + ")" when 'Issue' result = content.subject when 'Message' diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 1cc0d3b7a..714da9920 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -90,8 +90,8 @@ class Attachment < ActiveRecord::Base @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") before_save :files_to_final_location - after_save :act_as_course_activity - after_create :office_conver, :be_user_score,:act_as_forge_activity,:create_attachment_ealasticsearch_index + after_save :act_as_course_activity,:act_as_forge_activity + after_create :office_conver, :be_user_score,:create_attachment_ealasticsearch_index after_update :office_conver, :be_user_score,:update_attachment_ealasticsearch_index after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count, :down_course_score @@ -606,7 +606,7 @@ class Attachment < ActiveRecord::Base # Author lizanle # Description 上传该项目的文档资料也要保存一份在公共表中 def act_as_forge_activity - if self.container_type == 'Project' + if self.container_type == 'Project' && self.forge_acts.empty? self.forge_acts << ForgeActivity.new(:user_id => self.author_id, :project_id => self.container_id) end diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index 88767ba1f..a02eb750c 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -73,7 +73,8 @@ class CourseActivity < ActiveRecord::Base name = lead_message.subject content = lead_message.content # message的status状态为0为正常,为1表示创建课程时发送的message - message = Message.create(:subject => name, :content => content, :board_id => self.course.boards.first.id, :author_id => self.course.tea_id , :sticky => true, :status => true ) + # author_id 默认为课程使者创建 + message = Message.create(:subject => name, :content => content, :board_id => self.course.boards.first.id, :author_id => 1 , :sticky => true, :status => true ) # 更新的目的是为了排序,因为该条动态的时间可能与课程创建的动态创建时间一直 message.course_acts.first.update_attribute(:updated_at, message.course_acts.first.updated_at + 1) if message.course_acts.first end diff --git a/app/models/user.rb b/app/models/user.rb index 2c7d61b5c..78d823ea7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -116,7 +116,7 @@ class User < Principal has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' has_one :rss_token, :class_name => 'Token', :conditions => "action='feeds'" has_one :blog, :class_name => 'Blog', :foreign_key => "author_id" - has_many :org_document_comments, :dependent =>:destroy + has_many :org_document_comments, :dependent =>:destroy, :foreign_key => "creator_id" has_one :api_token, :class_name => 'Token', :conditions => "action='api'" belongs_to :auth_source has_many :org_members @@ -1067,6 +1067,16 @@ class User < Principal anonymous_user end + # refactor User model find function, + # return anonymous user when can not find user id = user_id + def self.find (*args, &block) + begin + super + rescue + self.anonymous + end + # super + end # Salts all existing unsalted passwords # It changes password storage scheme from SHA1(password) to SHA1(salt + SHA1(password)) # This method is used in the SaltPasswords migration and is to be kept as is diff --git a/app/views/attachments/_attachment_history_download.html.erb b/app/views/attachments/_attachment_history_download.html.erb new file mode 100644 index 000000000..c805960f0 --- /dev/null +++ b/app/views/attachments/_attachment_history_download.html.erb @@ -0,0 +1,30 @@ + +选择版本 +

注:该文件有历史版本,请选择您需要的文件,点击文件名下载。

+

版本及序号

+ +
+ + <%= link_to truncate(@attachment.filename,length: 35, omission: '...'), + download_named_attachment_path(@attachment.id, @attachment.filename), + :title => @attachment.filename+"\n"+@attachment.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis; max-width:300px;",:class => "linkBlue f14 fb link_file_a2 fl" %> + + 版本号:当前 +
+ <% @attachment_histories.each do |history| %> + + <%= link_to truncate(history.filename,length: 35, omission: '...'), + download_history_attachment_path(history.id, history.filename), + :title => history.filename+"\n"+history.description.to_s, + :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis; max-width:300px;",:class => "linkBlue f14 fb link_file_a2 fl" %> + + 版本号:<%= history.version %> +
+ <% end %> +
diff --git a/app/views/attachments/attachment_history_download.js.erb b/app/views/attachments/attachment_history_download.js.erb new file mode 100644 index 000000000..352a2ef93 --- /dev/null +++ b/app/views/attachments/attachment_history_download.js.erb @@ -0,0 +1,7 @@ +$("#ajax-modal").html('<%= escape_javascript( render :partial => 'attachments/attachment_history_download' )%>'); +showModal('ajax-modal', '452px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","40%").css("left","50%"); +$('#ajax-modal').parent().addClass("resourceUploadPopup"); +$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); \ No newline at end of file diff --git a/app/views/blogs/_homepage.html.erb b/app/views/blogs/_homepage.html.erb index 80ae8c9f4..5dbee59d6 100644 --- a/app/views/blogs/_homepage.html.erb +++ b/app/views/blogs/_homepage.html.erb @@ -43,6 +43,8 @@ <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.content} %>
+ +
diff --git a/app/views/boards/_course_new.html.erb b/app/views/boards/_course_new.html.erb index 31cdf41eb..3deb04f6c 100644 --- a/app/views/boards/_course_new.html.erb +++ b/app/views/boards/_course_new.html.erb @@ -1,7 +1,123 @@ <%= content_for(:header_tags) do %> - <%= import_ke(enable_at: true, prettify: false) %> + <%= import_ke(enable_at: true, prettify: false, init_activity: false) %> <% end %> - + <%= error_messages_for 'message' %>
@@ -25,7 +141,7 @@ <%= text_area :quote,:quote,:style => 'display:none' %> <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> - <%= f.kindeditor :content, :editor_id => 'message_content_editor', + <%#= f.kindeditor :content, :editor_id => 'message_content_editor', :owner_id => topic.nil? ? 0: topic.id, :owner_type => OwnerTypeHelper::MESSAGE, :width => '100%', @@ -37,8 +153,11 @@ :maxlength => 5000 }, at_id: topic.id, at_type: topic.class.to_s %> +

+

+

@@ -49,11 +168,11 @@
<%if !edit_mode %> - 确定 + 确定 取消 <% else %> - 确定 + 确定 <%= link_to "取消",board_message_url(topic.board, topic.root, :r => (topic.parent_id && topic.id)), :class => "fr mr10 mt3"%> <% end %> diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 16b4fcd3d..d33b75f82 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -25,11 +25,13 @@ 课程问答区
+
<% if User.current.logged? %> <%= labelled_form_for @message, :url =>{:controller=>'messages',:action => 'new', :board_id => @board.id, :is_board => 'true'}, :html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %> <%= render :partial => 'course_new', :locals => {:f => f, :topic => @message, :edit_mode => false, :course => @board.course} %> <% end %> <% end %> +
<%= render :partial=> 'course_show_detail',:locals =>{:topics => @topics, :page => 0} %>
diff --git a/app/views/files/_org_subfield_list.html.erb b/app/views/files/_org_subfield_list.html.erb index 70214b721..ab547db87 100644 --- a/app/views/files/_org_subfield_list.html.erb +++ b/app/views/files/_org_subfield_list.html.erb @@ -9,9 +9,17 @@
- <%= link_to file.is_public? ? truncate(file.filename, length: 45) : truncate(file.filename,length: 35, omission: '...'), - download_named_attachment_path(file.id, file.filename), - :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkGrey3 f_14 f_l" %> + <%# 如果有历史版本则提供历史版本下载 %> + <% if file.attachment_histories.count == 0 %> + <%= link_to file.is_public? ? truncate(file.filename, length: 45) : truncate(file.filename,length: 35, omission: '...'), + download_named_attachment_path(file.id, file.filename), + :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkGrey3 f_14" %> + <% else %> + <%= link_to truncate(file.filename,length: 35, omission: '...'), attachment_history_download_path(file.id), + :title => file.filename+"\n"+file.description.to_s, + :class => "linkGrey3 f_14", + :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;", :remote=>true %> + <% end %> <%= file_preview_eye(file, class: 'preview') %> <% if file.is_public? == false%> diff --git a/app/views/files/_project_list.html.erb b/app/views/files/_project_list.html.erb index a2a1670d1..2ee726d77 100644 --- a/app/views/files/_project_list.html.erb +++ b/app/views/files/_project_list.html.erb @@ -8,9 +8,17 @@
- <%= link_to truncate(file.filename,length: 35, omission: '...'), - download_named_attachment_path(file.id, file.filename), - :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkGrey3 f_14" %> + <%# 如果有历史版本则提供历史版本下载 %> + <% if file.attachment_histories.count == 0 %> + <%= link_to truncate(file.filename,length: 35, omission: '...'), + download_named_attachment_path(file.id, file.filename), + :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkGrey3 f_14" %> + <% else %> + <%= link_to truncate(file.filename,length: 35, omission: '...'), attachment_history_download_path(file.id), + :title => file.filename+"\n"+file.description.to_s, + :class => "linkGrey3 f_14", + :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;", :remote=>true %> + <% end %> <%= file_preview_eye(file, class: 'preview') %> <% if file.is_public? == false%> diff --git a/app/views/files/_resource_detail.html.erb b/app/views/files/_resource_detail.html.erb index 317bb7dd8..20ffb1e50 100644 --- a/app/views/files/_resource_detail.html.erb +++ b/app/views/files/_resource_detail.html.erb @@ -6,9 +6,17 @@
- <%= link_to truncate(file.filename,length: 35, omission: '...'), - download_named_attachment_path(file.id, file.filename), - :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkGrey3 f_14" %> + <%# 如果有历史版本则提供历史版本下载 %> + <% if file.attachment_histories.count == 0 %> + <%= link_to truncate(file.filename,length: 35, omission: '...'), + download_named_attachment_path(file.id, file.filename), + :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkGrey3 f_14" %> + <% else %> + <%= link_to truncate(file.filename,length: 35, omission: '...'), attachment_history_download_path(file.id), + :title => file.filename+"\n"+file.description.to_s, + :class => "linkGrey3 f_14", + :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;", :remote=>true %> + <% end %> <%= file_preview_eye(file, class: 'preview') %> <% if file.is_public? == false%> @@ -38,31 +46,28 @@ <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %>
-
  • <% if User.current.logged? %> - <% if (is_course_teacher(User.current,@course) || file.author_id == User.current.id) && course_contains_attachment?(@course,file) %> <% if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" %>
      -
    • <%= link_to("发       送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
    • <%= link_to '延期发布',file_hidden_course_file_path(@course,file),:class => "postOptionLink",:remote=>true %>
    • <%= link_to '更新版本',attachments_versions_path(file),:class => "postOptionLink",:remote=>true %>
    • <% if @course.is_public? %>
    • - - <%= link_to (file.is_public? ? "设为私有":"设为公开"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"postOptionLink",:method => :post %> - + + <%= link_to (file.is_public? ? "设为私有":"设为公开"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"postOptionLink",:method => :post %> +
    • <%end%>
    • <%= link_to( '删除资源', attachment_path(file), - :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" && file.destroyable %> + :data => {:confirm => l(:text_are_you_sure)}, + :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" && file.destroyable %>
    - <% end %> <%else%>
      diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index b9d463855..4b82f8665 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -9,6 +9,9 @@ $(function(){ $("#RSide").removeAttr("id"); $("#Container").css("width","1000px"); + if(<%= @is_edit %>) { + issueEditShow(); + } });
      diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 8ab1851e4..315b1d300 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -109,7 +109,7 @@
    diff --git a/app/views/student_work/_programing_work_show.html.erb b/app/views/student_work/_programing_work_show.html.erb index 8e7c58dc3..20d6df9ba 100644 --- a/app/views/student_work/_programing_work_show.html.erb +++ b/app/views/student_work/_programing_work_show.html.erb @@ -25,7 +25,7 @@
  • 编程代码: -
    +
    diff --git a/app/views/student_work/_show.html.erb b/app/views/student_work/_show.html.erb index d66a30718..67c04d71f 100644 --- a/app/views/student_work/_show.html.erb +++ b/app/views/student_work/_show.html.erb @@ -59,8 +59,8 @@
  • 内容: -
    - <%= text_format(work.description) if work.description%> +
    + <%= work.description.html_safe if work.description%>
  • @@ -105,6 +105,9 @@
-->

+

+

@@ -66,7 +73,7 @@ <% end %>
- 确定 + 确定 <%= link_to "取消", student_work_index_path(:homework => @homework), :class => "fr mr10 mt3"%>
@@ -96,23 +103,130 @@ } function popupRegex(){ - if(regexStudentWorkName()&®exStudentWorkDescription()) - { - if($("#group_member_ids").length > 0) { - if(regexStudentWorkMember(parseInt($.trim($("#min_num_member").html())),parseInt($.trim($("#max_num_member").html())))) { - $('#ajax-modal').html("

作品信息完整性校验中,请稍等...

"); - showModal('ajax-modal', '500px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); - $('#ajax-modal').parent().addClass("anonymos"); - } - } else { + if($("#group_member_ids").length > 0) { + if(regexStudentWorkMember(parseInt($.trim($("#min_num_member").html())),parseInt($.trim($("#max_num_member").html())))) { $('#ajax-modal').html("

作品信息完整性校验中,请稍等...

"); showModal('ajax-modal', '500px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); $('#ajax-modal').parent().addClass("anonymos"); } + } else { + $('#ajax-modal').html("

作品信息完整性校验中,请稍等...

"); + showModal('ajax-modal', '500px'); + $('#ajax-modal').siblings().remove(); + $('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); + $('#ajax-modal').parent().addClass("anonymos"); + } + } + + function nh_check_field(params){ + var result=true; + if(!regexStudentWorkName()) { + result=false; + return result; + } + if(params.content!=undefined){ + if(params.content.isEmpty()){ + result=false; + } + if(params.content.html()!=params.textarea.html() || params.issubmit==true){ + params.textarea.html(params.content.html()); + params.content.sync(); + + if(params.content.isEmpty()){ + params.contentmsg.html('作品描述不能为空'); + }else{ + params.contentmsg.html(''); + } + } } + return result; } + function init_homework_form(params){ + params.form.submit(function(){ + params.textarea.html(params.editor.html()); + params.editor.sync(); + var flag = false; + if(params.form.attr('data-remote') != undefined ){ + flag = true + } + var is_checked = nh_check_field({ + issubmit:true, + content:params.editor, + contentmsg:params.contentmsg, + textarea:params.textarea + }); + + if(is_checked){ + if(flag){ + popupRegex(); + return true; + }else{ + $(this)[0].submit(); + $("#ajax-indicator").hide(); + return false; + } + } + return false; + }); + } + function init_homework_editor(params){ + params.textarea.removeAttr('placeholder'); + var editor = params.kindutil.create(params.textarea, { + resizeType : 1,minWidth:"1px",width:"100%",minHeight:"30px",height:"30px", + items : ['code','emoticons','fontname', + 'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|', + 'formatblock', 'fontsize', '|','indent', 'outdent', + '|','imagedirectupload','table', 'media', 'preview',"more" + ], + afterChange:function(){//按键事件 + var edit = this.edit; + var body = edit.doc.body; + //paramsHeight = params.kindutil.removeUnit(this.height); + edit.iframe.height(150); + this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight) + 33, 150)); + }, + afterCreate:function(){ + //init + var edit = this.edit; + var body = edit.doc.body; + edit.iframe[0].scroll = 'no'; + body.style.overflowY = 'hidden'; + //reset height + var edit = this.edit; + var body = edit.doc.body; + edit.html(params.textarea.innerHTML); + //paramsHeight = params.kindutil.removeUnit(this.height); + edit.iframe.height(150); + this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight) , 150)); + elocalStorage(editor2,'student_work_<%=@work.id %>'); + } + }).loadPlugin('paste'); + return editor; + } + KindEditor.ready(function(K){ + $("div[nhname='student_work_form']").each(function(){ + var params = {}; + params.kindutil = K; + params.div_form = $(this); + params.form = $("form",params.div_form); + if(params.form==undefined || params.form.length==0){ + return; + } + params.textarea = $("textarea[nhname='student_work_textarea']",params.div_form); + params.contentmsg = $("#student_work_description_textarea"); + params.submit_btn = $("#new_message_submit_btn"); + if(params.textarea.data('init') == undefined) { + params.editor = init_homework_editor(params); + editor2 = params.editor; + init_homework_form(params); + params.submit_btn.click(function () { + params.form.submit(); + $("#ajax-indicator").hide(); + }); + params.textarea.data('init', 1); + } + }); + }); \ No newline at end of file diff --git a/app/views/student_work/index.html.erb b/app/views/student_work/index.html.erb index 41ec2b61b..8e7d87302 100644 --- a/app/views/student_work/index.html.erb +++ b/app/views/student_work/index.html.erb @@ -172,7 +172,7 @@
<% if @homework.homework_detail_manual && @homework.homework_detail_manual.comment_status < 2 %>
提交截止时间:<%= @homework.end_time %> 23:59
- <% elsif @homework.homework_detail_manual && @homework.homework_detail_manual.comment_status >= 2 %> + <% elsif @homework.homework_detail_manual && @homework.homework_detail_manual.comment_status >= 2 && @homework.anonymous_comment == 0 %>
匿评截止时间:<%= @homework.homework_detail_manual.evaluation_end %> 23:59
<% end %> <% if @homework.homework_detail_manual.comment_status == 0 %> diff --git a/app/views/student_work/new.html.erb b/app/views/student_work/new.html.erb index 5d2b134a8..c43482299 100644 --- a/app/views/student_work/new.html.erb +++ b/app/views/student_work/new.html.erb @@ -1,4 +1,9 @@ +<% content_for :header_tags do %> + <%= import_ke(enable_at: true, prettify: false, init_activity: false) %> + <%= javascript_include_tag 'homework','baiduTemplate' %> +<% end %> +
@@ -110,7 +225,7 @@
-
+
<%= form_for(@student_work, :html => { :multipart => true }, :url => {:controller => 'student_work', @@ -127,18 +242,21 @@ <%=hidden_field_tag 'group_member_ids', params[:group_member_ids], :value=>User.current.id %> <% end %>
- <%= f.text_field "name", :required => true, :size => 60, :class => "InputBox W700", :maxlength => 200, :placeholder => "请输入作品名称", :onkeyup => "regexStudentWorkName();" %> + <%= f.text_field "name", :required => true, :size => 60, :class => "InputBox W700", :maxlength => 200, :placeholder => "请输入作品名称",:value=>"#{@homework.name}的作品提交", :onkeyup => "regexStudentWorkName();" %>

- <%= f.text_area "description", :class => "InputBox W700 H150", :placeholder => "请输入作品描述", :onkeyup => "regexStudentWorkDescription();"%> - -->

+

+

@@ -167,9 +285,9 @@
-->
- 提交 + 提交 - <%= link_to "取消", delete_work_student_work_index_path(:homework =>@homework.id), :class => "fr mr10 mt3"%> + <%= link_to "取消", delete_work_student_work_index_path(:homework =>@homework.id),:id => 'new_message_cancel_btn', :class => "fr mr10 mt3"%>
<% end%> diff --git a/app/views/student_work/show.js.erb b/app/views/student_work/show.js.erb index c89180b16..135da3c0d 100644 --- a/app/views/student_work/show.js.erb +++ b/app/views/student_work/show.js.erb @@ -1,36 +1,36 @@ -if($("#about_hwork_<%= @work.id%>").children().length > 0){ - $("#about_hwork_<%= @work.id%>").html(""); -} -else{ - <% if @homework.homework_type == 2%> - $("#about_hwork_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'programing_work_show',:locals => {:work =>@work,:score =>@score,:student_work_scores => @student_work_scores}) %>"); - - var program_name = "text/x-csrc"; - var language = <%= @homework.language %>; - if (language == 1) { - program_name = 'text/x-csrc'; - } else if(language==2){ - program_name = 'text/x-c++src'; - }else if(language==3){ - program_name = 'text/x-cython'; - } else if(language==4){ - program_name = 'text/x-java'; - } - - var editor = CodeMirror(document.getElementById("work-code_<%= @work.id%>"), { - mode: {name: program_name, - version: 2, - singleLineStringErrors: false}, - lineNumbers: true, - indentUnit: 2, - matchBrackets: true, - readOnly: true, - value: $("#work-src").text() - } - ); - - <% else%> - $("#about_hwork_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'show',:locals => {:work =>@work,:score =>@score,:student_work_scores => @student_work_scores}) %>"); - <% end%> - $('#score_<%= @work.id%>').peSlider({range: 'min'}); +if($("#about_hwork_<%= @work.id%>").children().length > 0){ + $("#about_hwork_<%= @work.id%>").html(""); +} +else{ + <% if @homework.homework_type == 2%> + $("#about_hwork_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'programing_work_show',:locals => {:work =>@work,:score =>@score,:student_work_scores => @student_work_scores}) %>"); + + var program_name = "text/x-csrc"; + var language = <%= @homework.language %>; + if (language == 1) { + program_name = 'text/x-csrc'; + } else if(language==2){ + program_name = 'text/x-c++src'; + }else if(language==3){ + program_name = 'text/x-cython'; + } else if(language==4){ + program_name = 'text/x-java'; + } + + var editor = CodeMirror(document.getElementById("work-code_<%= @work.id%>"), { + mode: {name: program_name, + version: 2, + singleLineStringErrors: false}, + lineNumbers: true, + indentUnit: 2, + matchBrackets: true, + readOnly: true, + value: $("#work-src_<%= @work.id%>").text() + } + ); + + <% else%> + $("#about_hwork_<%= @work.id%>").html("<%= escape_javascript(render :partial => 'show',:locals => {:work =>@work,:score =>@score,:student_work_scores => @student_work_scores}) %>"); + <% end%> + $('#score_<%= @work.id%>').peSlider({range: 'min'}); } \ No newline at end of file diff --git a/app/views/users/_course_message.html.erb b/app/views/users/_course_message.html.erb index df084357a..7477eaabd 100644 --- a/app/views/users/_course_message.html.erb +++ b/app/views/users/_course_message.html.erb @@ -1,23 +1,15 @@
- <% if activity.status == 1 %> - <%= image_tag("/images/trustie_logo1.png", width: "50px", height: "50px") %> - <% else %> - <%= 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} %> - <% end %> + <%= 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} %>
- <% if activity.status == 1 %> - 确实团队 + <% if activity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> <% else %> - <% if activity.try(:author).try(:realname) == ' ' %> - <%= link_to activity.try(:author), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> - <% end %> + <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> <% end %> TO <%= link_to activity.course.name.to_s+" | 课程问答区", course_boards_path(activity.course,:host=> Setting.host_course), :class => "newsBlue ml15 mr5"%> diff --git a/app/views/users/_homework_detail_information.html.erb b/app/views/users/_homework_detail_information.html.erb index 07328e696..1829fa61c 100644 --- a/app/views/users/_homework_detail_information.html.erb +++ b/app/views/users/_homework_detail_information.html.erb @@ -1,7 +1,17 @@
题目信息
<% if homework.nil? %> - 请先在左侧选择作业 + 本题库遵循创作共用许可证

+ +教师给学生出题本质上是一种创作行为,题目的作者通常为此付出大量时间和精力。好的题目不仅能加深学生对知识点的理解,还能激发学生兴趣,提升学习效率。为此,本网站的题库许可证基于创作共用许可证( Creative Commons License )建立,其核心条款包括:

+ +1. 署名:必须提到原作者。

+ +2. 非商业用途:不得用于盈利性目的。

+ +3. 相同方式共享:允许修改原作品,但必须使用相同的许可证发布。

+ +对此许可证的支持或反对,请在网站中留言,我们不断完善,谢谢!
<% else %>
标题:<%=homework.name %>
来源:<%=homework.course.name %>
diff --git a/app/views/users/_homework_repository_detail.html.erb b/app/views/users/_homework_repository_detail.html.erb index 7cf74e11e..efbf24955 100644 --- a/app/views/users/_homework_repository_detail.html.erb +++ b/app/views/users/_homework_repository_detail.html.erb @@ -2,7 +2,18 @@
题目信息
<% if homework.nil? %> - 请先在左侧选择作业 + 本题库遵循创作共用许可证
+ +教师给学生出题本质上是一种创作行为,题目的作者通常为此付出大量时间和精力。好的题目不仅能加深学生对知识点的理解,还能激发学生兴趣,提升学习效率。为此,本网站的题库许可证基于创作共用许可证( Creative Commons License )建立,其核心条款包括:

+ +1. 署名:必须提到原作者。

+ +2. 非商业用途:不得用于盈利性目的。

+ +3. 相同方式共享:允许修改原作品,但必须使用相同的许可证发布。

+ +对此许可证的支持或反对,请在网站中留言,我们不断完善,谢谢! +
<% else %>
标题:<%=homework.name %>
来源:<%=homework.course.name %>
diff --git a/app/views/users/_homework_repository_list.html.erb b/app/views/users/_homework_repository_list.html.erb index 67a8f47b4..56259d6b8 100644 --- a/app/views/users/_homework_repository_list.html.erb +++ b/app/views/users/_homework_repository_list.html.erb @@ -1,18 +1,33 @@
    -
  • 来源
  • -
  • 类别
  • -
  • 贡献者
  • +
  • + <%= link_to "来源",user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "course_name", :sort => @r_sort),:class => "fl ml30",:remote => true%> + <% if @order == "course_name"%> + <%= link_to "", user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "course_name", :sort => @r_sort),:class => "#{@r_sort == 'desc' ? 'st_up' : 'st_down'} mt12 fl" ,:remote => true%> + <% end%> +
  • +
  • + <%= link_to "类别",user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "homework_type", :sort => @r_sort),:class => "fl ml10",:remote => true%> + <% if @order == "homework_type"%> + <%= link_to "", user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "homework_type", :sort => @r_sort),:class => "#{@r_sort == 'desc' ? 'st_up' : 'st_down'} mt12 fl" ,:remote => true%> + <% end%> +
  • +
  • + <%= link_to "贡献者",user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "user_name", :sort => @r_sort),:class => "fl ml20",:remote => true%> + <% if @order == "user_name"%> + <%= link_to "", user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "user_name", :sort => @r_sort),:class => "#{@r_sort == 'desc' ? 'st_up' : 'st_down'} mt12 fl" ,:remote => true%> + <% end%> +
  • - <%= link_to "引用数",user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "quotes", :sort => @r_sort),:class => "fl",:remote => true%> + <%= link_to "引用数",user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "quotes", :sort => @r_sort),:class => "fl ml5",:remote => true%> <% if @order == "quotes"%> - <%= link_to "", user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "quotes", :sort => @r_sort),:class => "#{@r_sort == 'desc' ? 'st_up' : 'st_down'} mt12" ,:remote => true%> + <%= link_to "", user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "quotes", :sort => @r_sort),:class => "#{@r_sort == 'desc' ? 'st_up' : 'st_down'} mt12 fl" ,:remote => true%> <% end%>
  • <%= link_to "发布时间",user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "created_at", :sort => @r_sort),:class => "fl",:remote => true%> <% if @order == "created_at"%> - <%= link_to "", user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "created_at", :sort => @r_sort),:class => "#{@r_sort == 'desc' ? 'st_up' : 'st_down'} mt12" ,:remote => true%> + <%= link_to "", user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "created_at", :sort => @r_sort),:class => "#{@r_sort == 'desc' ? 'st_up' : 'st_down'} mt12 fl" ,:remote => true%> <% end%>
diff --git a/app/views/users/_import_resource_info.html.erb b/app/views/users/_import_resource_info.html.erb index bc1152ce4..4ea56ad9f 100644 --- a/app/views/users/_import_resource_info.html.erb +++ b/app/views/users/_import_resource_info.html.erb @@ -26,11 +26,14 @@ 公共资源 我的资源 <% end %> - <%#= form_tag( url_for(:controller => 'users', :action => 'import_resources_search', :id => User.current.id, :type => 1), - :remote => true , :method => 'get', :id => 'resource_search_form') do %> + + - <%#= hidden_field_tag(:type,type.nil? ? 1 : type) %> - <%# end %> + + +
@@ -42,25 +45,10 @@
  • 上传者
  • 上传时间
  • - <%= form_tag( url_for({:controller => 'users', :action => 'import_into_container', - :mul_id => params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id], - :mul_type => params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"}), - :method => 'post', :id => 'resource_import_container_form') do %> - <% @attachments.each do |attach| %> -
      - -
    • <%= get_resource_type(attach.container_type)%>
    • - -
    • <%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %>
    • -
    • <%= format_date(attach.created_on) %>
    • -
    - <% end %> - <% end %> +
    + <%= render :partial => 'users/user_import_resource_list',:locals => {:project_id => params[:project_id], :subfield_file_id => params[:subfield_file_id], :course_id => params[:course_id]} %> +
    +
    diff --git a/app/views/users/_project_issue.html.erb b/app/views/users/_project_issue.html.erb index 1ce03da17..5d472497d 100644 --- a/app/views/users/_project_issue.html.erb +++ b/app/views/users/_project_issue.html.erb @@ -13,6 +13,29 @@ <% end %> TO <%= link_to activity.project.name.to_s+" | 项目问题", project_issues_path(activity.project), :class => "newsBlue ml15"%>
    +
    +
      +
    • +
        +
      • + <%= link_to l(:button_edit), issue_path(activity.id, :edit => 'true'), :class => 'postOptionLink', :accesskey => accesskey(:edit) if activity.editable? && User.current.allowed_to?(:edit_issues, activity.project) %> +
      • +
      • + <% if !defined?(project_id) && !defined?(user_id) %> + <%= link_to l(:button_delete), issue_path(activity.id), :data => {:confirm => issues_destroy_confirmation_message(activity)}, :method => :delete, :class => 'postOptionLink' if User.current.allowed_to?(:delete_issues, activity.project) %> + <% elsif defined?(project_id) %> + <%= link_to l(:button_delete), issue_path(activity.id, :page_classify => "project_page", :page_id => project_id), :data => {:confirm => issues_destroy_confirmation_message(activity)}, :method => :delete, :class => 'postOptionLink' if User.current.allowed_to?(:delete_issues, activity.project) %> + <% elsif defined?(user_id) %> + <%= link_to l(:button_delete), issue_path(activity.id, :page_classify => "user_page", :page_id => user_id), :data => {:confirm => issues_destroy_confirmation_message(activity)}, :method => :delete, :class => 'postOptionLink' if User.current.allowed_to?(:delete_issues, activity.project) %> + <% end %> +
      • +
      • + <%= link_to l(:button_copy), project_copy_issue_path(activity.project, activity), :class => 'postOptionLink' if User.current.allowed_to?(:add_issues, activity.project) %> +
      • +
      +
    • +
    +
    <% case activity.tracker_id %> <% when 1%> @@ -51,6 +74,10 @@
    <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> + + + +
    <%# 局部刷新:修改xissue属性 %> <% if User.current.member_of?(activity.project) %> <% unless params[:action] == "index" %> @@ -59,10 +86,7 @@
    <% end %> <% end %> -
    - - -
    +
    <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %>
    diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index f679f9c8c..a545038f1 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -16,7 +16,7 @@
  • <%= attach.quotes.nil? ? 0 : attach.quotes %>
  • <%= attach.downloads %>
  • <%= attach.author_id %>
  • -
  • <%= number_to_human_size(attach.filesize) %>
  • +
  • <%= (number_to_human_size(attach.filesize)).gsub("ytes", "") %>
  • <%= get_resource_type(attach.container_type)%>
  • diff --git a/app/views/users/_show_user_homeworks.html.erb b/app/views/users/_show_user_homeworks.html.erb index b9bbf6934..7e9df7f4d 100644 --- a/app/views/users/_show_user_homeworks.html.erb +++ b/app/views/users/_show_user_homeworks.html.erb @@ -30,7 +30,7 @@ 取消
    -
      +
        <%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true%>
    diff --git a/app/views/users/_user_activities.html.erb b/app/views/users/_user_activities.html.erb index 0e55c246c..01711ace3 100644 --- a/app/views/users/_user_activities.html.erb +++ b/app/views/users/_user_activities.html.erb @@ -89,7 +89,7 @@ <% if act %> <% case user_activity.act_type.to_s %> <% when 'Issue' %> - <%= render :partial => 'project_issue', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> + <%= render :partial => 'project_issue', :locals => {:activity => act,:user_activity_id =>user_activity.id, :user_id => user_id} %> <% when 'Message' %> <%= render :partial => 'project_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %> <% when 'ProjectCreateInfo'%> diff --git a/app/views/users/_user_at_message.html.erb b/app/views/users/_user_at_message.html.erb index d8649cabe..089171c3d 100644 --- a/app/views/users/_user_at_message.html.erb +++ b/app/views/users/_user_at_message.html.erb @@ -8,15 +8,15 @@ <% if ma.at_message_type == "Message" && !ma.at_message.course.nil? %> <%= link_to ma.subject.html_safe, course_boards_path(ma.at_message.course, :parent_id => ma.at_message.parent_id ? ma.at_message.parent_id : ma.at_message.id, :topic_id => ma.at_message.id), - :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %> + :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}" %> + + <% elsif ma.at_message_type == "Message" && !ma.at_message.project.nil? %> <%= link_to ma.subject.html_safe, project_boards_path(ma.at_message.project, :parent_id => ma.at_message.parent_id ? ma.at_message.parent_id : ma.at_message.id, :topic_id => ma.at_message.id), - :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %> + :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}" %> + + <% else %> <%= link_to ma.subject.html_safe, ma.url, :class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}", :onmouseover =>"message_titile_show($(this),event)", :onmouseout => "message_titile_hide($(this))" %> <% end %> diff --git a/app/views/users/_user_homework_form.html.erb b/app/views/users/_user_homework_form.html.erb index 8b72ec781..f23d01d3c 100644 --- a/app/views/users/_user_homework_form.html.erb +++ b/app/views/users/_user_homework_form.html.erb @@ -16,7 +16,6 @@ $("#GroupPopupBox a.group_save_btn").click(); <% end %> }); - var homework_description_editor; function checked_val() { if ($("#anonymous_comment").is(":checked")) { $("#anonymous_comment").val(1); @@ -106,7 +105,7 @@ //paramsHeight = params.kindutil.removeUnit(this.height); edit.iframe.height(150); this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight) , 150)); - + elocalStorage(homework_description_editor,'homework_<%=User.current.id %>'); } }).loadPlugin('paste'); return editor; @@ -150,7 +149,7 @@
    - <%= link_to("导入作业", user_import_homeworks_user_path(User.current.id,:select_course => defined?(select_course)),:class => "BlueCirBtn fl mr10",:remote => true,:title=>"导入自己发布过的作业,或者共享题库中的作业") unless edit_mode%> + <%= link_to("从题库选用", user_import_homeworks_user_path(User.current.id,:select_course => defined?(select_course)),:class => "BlueCirBtn fl mr10",:remote => true,:title=>"导入自己发布过的作业,或者共享题库中的作业") unless edit_mode%> <% unless edit_mode %> <% end %> @@ -159,7 +158,7 @@ <% end %>
    - <% if homework.homework_detail_manual.comment_status.to_i < 3 %> + <% if homework.homework_detail_manual.comment_status.to_i < 2 %> <%= calendar_for('homework_end_time')%> <% end %>
    @@ -199,6 +198,8 @@ <%= select_tag :course_id, options_for_select(get_as_teacher_courses(User.current), homework.course_id), {:class => "InputBox w709",:value => "请选择发布作业的课程"} %>

    +

    +

    diff --git a/app/views/users/_user_import_resource_list.html.erb b/app/views/users/_user_import_resource_list.html.erb new file mode 100644 index 000000000..af4f951e0 --- /dev/null +++ b/app/views/users/_user_import_resource_list.html.erb @@ -0,0 +1,19 @@ +<%= form_tag( url_for({:controller => 'users', :action => 'import_into_container', + :mul_id => project_id.nil? ? (course_id.nil? ? subfield_file_id : course_id) : project_id, + :mul_type => project_id.nil? ? (course_id.nil? ? "SubfieldFile" : "Course") : "Project"}), + :method => 'post', :id => 'resource_import_container_form') do %> + <% @attachments.each do |attach| %> +
      + +
    • <%= get_resource_type(attach.container_type)%>
    • + +
    • <%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %>
    • +
    • <%= format_date(attach.created_on) %>
    • +
    + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/users/_user_import_resource_search.html.erb b/app/views/users/_user_import_resource_search.html.erb new file mode 100644 index 000000000..b048675dd --- /dev/null +++ b/app/views/users/_user_import_resource_search.html.erb @@ -0,0 +1,29 @@ + + \ No newline at end of file diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index bb9fc1174..3b035179b 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -5,9 +5,10 @@
  • <%=link_to ma.course_message.author, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher" %>">发布了通知:
  • <%= link_to ma.course_message.title, {:controller => 'news', :action => 'show', :id => ma.course_message.id }, - :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %>
  • + :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}" %> + + +