diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 68386de44..cec419eba 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -32,18 +32,20 @@ class AdminController < ApplicationController end def projects +=begin @status = params[:status] || 1 - scope = Project.status(@status).order('id asc') + scope = Project.status(@status) scope = scope.like(params[:name]) if params[:name].present? - @projects = scope.where(project_type: Project::ProjectType_project).all - + @projects = scope.where(project_type: Project::ProjectType_project).reorder("created_on desc").all +=end + @projects = Project.like(@name).order('created_on desc') render :action => "projects", :layout => false if request.xhr? end def courses @name = params[:name] - @courses = Course.like(@name) + @courses = Course.like(@name).order('created_at desc') respond_to do |format| format.html end @@ -469,6 +471,23 @@ class AdminController < ApplicationController end end + #最近登录老师列表 + def latest_login_teachers + scope = User.find_by_sql("SELECT * FROM users,user_extensions WHERE users.id = user_extensions.user_id AND user_extensions.identity=0 ORDER BY last_login_on DESC") + if params[:startdate].present? + scope = User.find_by_sql("SELECT * FROM users,user_extensions WHERE users.id = user_extensions.user_id AND user_extensions.identity=0 and last_login_on>= '#{params[:startdate]} 00:00:00' ORDER BY last_login_on DESC") + end + if params[:enddate].present? + scope = User.find_by_sql("SELECT * FROM users,user_extensions WHERE users.id = user_extensions.user_id AND user_extensions.identity=0 and last_login_on <= '#{params[:enddate]} 23:59:59' ORDER BY last_login_on DESC") + end + @teachers = scope + @teachers = paginateHelper @teachers,30 + @page = (params['page'] || 1).to_i - 1 + respond_to do |format| + format.html + end + end + #作业 def homework @homework = HomeworkCommon.order('end_time desc') diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 842433ec6..7a226f50d 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -29,7 +29,7 @@ class BlogsController < ApplicationController def set_homepage @blog = Blog.find(params[:id]) @blog.update_attribute(:homepage_id, params[:article_id]) - redirect_to user_blogs_path(params[:user_id]) + redirect_to user_path(params[:user_id]) end def cancel_homepage diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 36060d41c..be96124c2 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -450,6 +450,93 @@ class CoursesController < ApplicationController #copy avatar copy_avatar(@course, copy_course) + if params[:course_content_type] + params[:course_content_type].each do |type| + case type + when "0" + homeworks = copy_course.homework_commons + homeworks.each do |homework| + new_homework = HomeworkCommon.new + new_homework.name = homework.name + new_homework.user_id = User.current.id + new_homework.description = homework.description + new_homework.publish_time = Date.today + 30 + new_homework.end_time = Date.today + 60 + new_homework.homework_type = homework.homework_type + new_homework.late_penalty = homework.late_penalty + new_homework.course_id = @course.id + new_homework.teacher_priority = homework.teacher_priority + new_homework.anonymous_comment = homework.anonymous_comment + new_homework.quotes = 0 + new_homework.is_open = homework.is_open + homework.attachments.each do |attachment| + att = attachment.copy + att.container_id = nil + att.container_type = nil + att.copy_from = attachment.id + att.save + new_homework.attachments << att + end + homework_detail_manual = homework.homework_detail_manual + homework_detail_programing = homework.homework_detail_programing + homework_detail_group = homework.homework_detail_group + if homework_detail_manual + new_homework.homework_detail_manual = HomeworkDetailManual.new + new_homework_detail_manual = new_homework.homework_detail_manual + new_homework_detail_manual.ta_proportion = homework_detail_manual.ta_proportion + new_homework_detail_manual.comment_status = 0 + new_homework_detail_manual.evaluation_start = Date.today + 67 + new_homework_detail_manual.evaluation_end = Date.today + 74 + new_homework_detail_manual.evaluation_num = homework_detail_manual.evaluation_num + new_homework_detail_manual.absence_penalty = homework_detail_manual.absence_penalty + end + if homework_detail_programing + new_homework.homework_detail_programing = HomeworkDetailPrograming.new + new_homework.homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion + new_homework.homework_detail_programing.language = homework_detail_programing.language + homework.homework_tests.each_with_index do |homework_test| + new_homework.homework_tests << HomeworkTest.new( + input: homework_test.input, + output: homework_test.output + ) + end + end + + if homework_detail_group + new_homework.homework_detail_group = HomeworkDetailGroup.new + new_homework.homework_detail_group.min_num = homework_detail_group.min_num + new_homework.homework_detail_group.max_num = homework_detail_group.max_num + new_homework.homework_detail_group.base_on_project = homework_detail_group.base_on_project + end + if new_homework.save + new_homework_detail_manual.save if new_homework_detail_manual + new_homework.homework_detail_programing.save if new_homework.homework_detail_programing + new_homework.homework_detail_group.save if new_homework.homework_detail_group + end + homework.update_attribute(:quotes, homework.quotes+1) + end + when "1" + attachments = copy_course.attachments + attachments.each do |attachment| + attach_copied_obj = attachment.copy + attach_copied_obj.tag_list.add(attachment.tag_list) # tag关联 + attach_copied_obj.container = @course + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.copy_from = attachment.copy_from.nil? ? attachment.id : attachment.copy_from + attach_copied_obj.is_publish = 0 + attach_copied_obj.publish_time = Date.today + 30 + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + attach_copied_obj.save + update_quotes attach_copied_obj + end + end + end + end + +=begin if params[:checkAll] attachments = copy_course.attachments attachments.each do |attachment| @@ -513,6 +600,7 @@ class CoursesController < ApplicationController end end end +=end end if @course respond_to do |format| diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 16fee2dae..5ad93f8db 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -533,6 +533,7 @@ class FilesController < ApplicationController if attachment.publish_time > Date.today attachment.is_publish = 0 end + attachment.description = params[:description] attachment.save end end @@ -632,16 +633,14 @@ class FilesController < ApplicationController end def update_contributor_score(course, file ) - unless file.author.allowed_to?(:as_teacher, course) - course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first - if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0, :total_score => 5) - else - score = course_contributor_score.resource_num + 5 - total_score = course_contributor_score.total_score + 5 - course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score) - end + course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0, + :news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0, :total_score => 5) + else + score = course_contributor_score.resource_num + 5 + total_score = course_contributor_score.total_score + 5 + course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score) end end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index a891d3354..00b11323b 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -6,8 +6,8 @@ class HomeworkCommonController < ApplicationController 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] - 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] + 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 @@ -261,6 +261,30 @@ class HomeworkCommonController < ApplicationController 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] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2d1f8d771..b650afe1b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -66,6 +66,7 @@ class ProjectsController < ApplicationController helper :words helper :project_score helper :user_score + include UsersHelper ### added by william include ActsAsTaggableOn::TagsHelper @@ -405,11 +406,16 @@ class ProjectsController < ApplicationController end flash.now[:error] = html if !html.to_s.blank? end - scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first - @repository = Repository.factory(scm) - @repository.is_default = @project.repository.nil? - @repository.project = @project - + scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first + @repository = Repository.factory(scm) + @repository.is_default = @project.repository.nil? + @repository.project = @project + unless @project.gpid.nil? + g = Gitlab.client + @gitlab_branches = g.branches(@project.gpid) + @branch_names = g.branches(@project.gpid).map{|b| b.name} + @gitlab_default_branch = g.project(@project.gpid).default_branch + end end # 项目邀请用户加入实现过程 @@ -670,8 +676,7 @@ class ProjectsController < ApplicationController # 更新公开私有时同步gitlab公开私有 unless @project.gpid.nil? g = Gitlab.client - gproject = g.project(@project.gpid) - params[:project][:is_public] ? g.edit_project(gproject.id, 20) : g.edit_project(gproject.id, 0) + params[:project][:is_public] ? g.edit_project(@project.gpid, 20, params[:branch]) : g.edit_project(@project.gpid, 0, params[:branch]) end # end if validate_parent_id && @project.save diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 707e87fd1..f7845d6f1 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -34,7 +34,7 @@ class RepositoriesController < ApplicationController before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] - before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked] + before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff] accept_rss_auth :revisions # hidden repositories filter // 隐藏代码过滤器 before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] @@ -521,6 +521,13 @@ update end end + # 每次提交对应的文件差异 + def commit_diff + @commit_diff = $g.commit_diff(@project.gpid, params[:changeset]) + @commit_details = $g.commit(@project.gpid, params[:changeset]) + render :layout => 'base_projects' + end + def diff if params[:format] == 'diff' @diff = @repository.diff(@path, @rev, @rev_to) @@ -626,9 +633,10 @@ update end (render_404; return false) unless @repository @path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s - @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip + # gitlab端获取默认分支 + gitlab_branchs = $g.project(@project.gpid).default_branch + @project.gpid.nil? ? (@rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip) : (@rev = params[:rev].blank? ? gitlab_branchs : params[:rev].to_s.strip) @rev_to = params[:rev_to] - unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE) if @repository.branches.blank? raise InvalidRevisionParam diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index e6ff904f3..a38d83851 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -6,9 +6,10 @@ class StudentWorkController < ApplicationController require "base64" before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment] - before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work] + before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :set_score_rule, :forbidden_anonymous_comment] + before_filter :is_logged, :only => [:index] ### def program_test @@ -91,101 +92,119 @@ class StudentWorkController < ApplicationController student_in_group = '(' + group_students.map{|user| user.id}.join(',') + ')' end #老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 - if @is_teacher || @homework.homework_detail_manual.nil? || - (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) + if @homework.is_open == 1 @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name @show_all = true - elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - @stundet_works = [] + elsif @homework.is_open == 0 && User.current.member_of_course?(@course) || User.current.admin? + if @is_teacher || @homework.homework_detail_manual.nil? || + (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @show_all = true + elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + @stundet_works = [] + else + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + end else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) end - else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) - end - elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] + elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + my_work = [] + else + my_work = @homework.student_works.where(:id => pro.student_work_id) + end else - my_work = @homework.student_works.where(:id => pro.student_work_id) + my_work = @homework.student_works.where(:user_id => User.current.id) end - else - my_work = @homework.student_works.where(:user_id => User.current.id) - end - @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} - elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] + @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} + elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + my_work = [] + else + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + end else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + end + if my_work.empty? + @stundet_works = [] + else + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @show_all = true end else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) - end - if my_work.empty? @stundet_works = [] - else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name - @show_all = true end else - @stundet_works = [] + render_403 + return end + @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count else - if @is_teacher || @homework.homework_detail_manual.nil? || (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) #老师 || 超级管理员 显示所有列表 + if @homework.is_open == 1 @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name @show_all = true - elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - @stundet_works = [] + elsif @homework.is_open == 0 && User.current.member_of_course?(@course) || User.current.admin? + if @is_teacher || @homework.homework_detail_manual.nil? || (@homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) #老师 || 超级管理员 显示所有列表 + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name + @show_all = true + elsif @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + @stundet_works = [] + else + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + end else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) end - else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) - end - elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] + elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + my_work = [] + else + my_work = @homework.student_works.where(:id => pro.student_work_id) + end else - my_work = @homework.student_works.where(:id => pro.student_work_id) + my_work = @homework.student_works.where(:user_id => User.current.id) end - else - my_work = @homework.student_works.where(:user_id => User.current.id) - end - @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} - elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 - if @homework.homework_type == 3 - pro = @homework.student_work_projects.where(:user_id => User.current.id).first - if pro.nil? - my_work = [] + @stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id} + elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的 + if @homework.homework_type == 3 + pro = @homework.student_work_projects.where(:user_id => User.current.id).first + if pro.nil? + my_work = [] + else + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + end else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id => pro.student_work_id) + my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) + end + if my_work.empty? + @stundet_works = [] + else + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name + @show_all = true end else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id => User.current.id) - end - if my_work.empty? @stundet_works = [] - else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name - @show_all = true end else - @stundet_works = [] + render_403 + return end + @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order} #{@b_sort}"),@name).count end @@ -802,6 +821,10 @@ class StudentWorkController < ApplicationController render_403 unless User.current.allowed_to?(:as_teacher,@course) || User.current.admin? end + def is_logged + redirect_to signin_path unless User.current.logged? + end + #根据条件过滤作业结果 def search_homework_member homeworks,name if name == "" @@ -1055,4 +1078,4 @@ class StudentWorkController < ApplicationController end end end -end \ No newline at end of file +end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 507dada24..2c390025e 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,695 +1,695 @@ -# encoding: utf-8 -# This controller was added by william -class TagsController < ApplicationController - layout "base_tags" - - before_filter :require_admin,:only => :show - - include CoursesHelper - include ProjectsHelper - include IssuesHelper - include UsersHelper - include BidsHelper - include ForumsHelper - include AttachmentsHelper - include ContestsHelper - include ActsAsTaggableOn::TagsHelper - include TagsHelper - include FilesHelper - helper :projects - helper :courses - helper :tags - include OpenSourceProjectsHelper - - before_filter :require_admin,:only => [:delete,:show_all] - before_filter :require_login,:only => [:tag_save] - - # $selected_tags = Array.new - # $related_tags = Array.new - NUMBERS = Setting.tags_show_search_results - - # 预设几个可以添加的tag - #@preTags = %w|预设A 预设B 预设C 预设D 预设E 预设F | - - # 接收参数解释: - # params[:q]这是在其他页面点击tag,跳转到该页面后的结果显示 ;params[:selected_tags],这是在过滤页面增删tag进行过滤传过来的参数 - # 最后是2个过滤何种数据,显示结果的控制参数params[:obj_id],params[:object_falg] - # 0代表删除tag 1代表增加tag - def index - - @obj_id = params[:obj_id] - @obj_flag = params[:object_flag] - - @selected_tags = Array.new - @related_tags = nil - - if params[:q] - @selected_tags << params[:q] - else - @do_what = params[:do_what] - @tag = params[:tag] - @selected_tags = params[:current_selected_tags] - @selected_tags = @selected_tags.nil? ? Array.new : @selected_tags - - case @do_what - when '0' then - @selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop - when '1' then - # 判断是否已存在该tag 主要用来处理分页的情况 - unless @selected_tags.include? @tag - @selected_tags << @tag - end - end - end - - @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num,@contests_tags_num, - @forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size - - # 获取搜索结果 - @obj, - @obj_pages, - @results_count, - @users_results, - @projects_results, - @issues_results, - @bids_results, - @forums_results, - @attachments_results, - @contests_results, - @courses_results, - @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags) - - # 这里是做tag推荐用的, 用来生产推荐的tags - unless @obj.nil? - @tags = @obj.tag_list - @tags -= @selected_tags - # @selected_tags.each do |i| - # @tags.delete(i) - # end - @related_tags = @tags - else - return - end - - end - - # 增加已选的tag - def add_tag - @tag = params[:tag] - @show_flag = params[:show_flag] - - $selected_tags << @tag - $related_tags.delete(@tag) - - # 获取搜索结果 - @obj, - @obj_pages, - @results_count, - @users_results, - @projects_results, - @issues_results, - @bids_results, - @forums_results, - @attachments_results, - @contests_results, - @courses_results, - @open_source_projects_results= refresh_results(@obj_id,@show_flag) - end - - # 删除已选tag - def delete_tag - @tag = params[:tag] - @show_flag = params[:show_flag] - - $related_tags << @tag - $selected_tags.delete(@tag) - - # 获取搜索结果 - @obj, - @obj_pages, - @results_count, - @users_results, - @projects_results, - @issues_results, - @bids_results, - @forums_results, - @attachments_results, - @contests_results, - @courses_results, - @open_source_projects_results= refresh_results(@obj_id,@show_flag) - end - - def show_all - @tags = ActsAsTaggableOn::Tag.find(:all) - end - - # 完全从数据库删除tag - # 这种删除方式是针对 印有该 tag所有对象来做删除的 - # 这样是从整个系统数据库中把该tag删除了 - def delete - if params[:q] - @tag = ActsAsTaggableOn::Tag.find_by_id(params[:q]) - @tag.delete - @taggings = ActsAsTaggableOn::Tagging.find_all_by_tag_id(@tag.id) - @taggings.each do |tagging| - tagging.delete - end - end - end - - # 只删除某个对象的该tag - def remove_tag - @obj = nil - @object_flag = nil - - if request.get? - # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 - @tag_name = params[:tag_name] - @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id - @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 - @taggable_type = numbers_to_object_type(params[:taggable_type]) - - @obj = get_object(@taggable_id,params[:taggable_type]) - @object_flag = params[:taggable_type] - - # if can_remove_tag?(User.current,@taggable_id,@taggable_type) - - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) - - unless @taggings.nil? - @taggings.delete - end - - # 是否还有其他记录 引用了 tag_id - @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id) - # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作 - if @tagging.nil? - @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) - @tag.delete unless @tag.nil? - end - # end - end - end - - # 只删除某个对象的该tag - def remove_tag_new - @obj = nil - @object_flag = nil - - if request.get? - # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 - @tag_name = params[:tag_name] - @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id - @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 - @taggable_type = numbers_to_object_type(params[:taggable_type]) - - @obj = get_object(@taggable_id,params[:taggable_type]) - @object_flag = params[:taggable_type] - - # if can_remove_tag?(User.current,@taggable_id,@taggable_type) - - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) - - unless @taggings.nil? - @taggings.delete - end - - # 是否还有其他记录 引用了 tag_id - @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id) - # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作 - if @tagging.nil? - @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) - @tag.delete unless @tag.nil? - end - - if @obj && @object_flag == '6' && @obj.container.kind_of?(Course) - @course = @obj.container - @tag_list = get_course_tag_list @course - @select_tag_name = params[:select_tag_name] - end - - if @obj && @object_flag == '6' && @obj.container.kind_of?(Project) - @project = @obj.container - @tag_list = get_course_tag_list @project - @select_tag_name = params[:select_tag_name] - end - - if @obj && @object_flag == '6' && @obj.container.kind_of?(OrgSubfield) - @org_subfield = @obj.container - @tag_list = get_org_subfield_tag_list @org_subfield - @select_tag_name = params[:select_tag_name] - end - # end - end - end - - #更新某个tag名称 - def update_tag_name - @tag_name = params[:tagName] - @rename_tag_name = params[:renameName] - @taggable_id = params[:taggableId] - @taggable_type = numbers_to_object_type(params[:taggableType]) - @course_id = params[:courseId] - - @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag - @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? - @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? - if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 - if @course_id - course = Course.find @course_id - if course - course.attachments.each do |attachment| - taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) - if taggings - taggings.delete - attachment.tag_list.add(@rename_tag_name.split(",")) - attachment.save - end - end - end - end - else - if(@rename_tag.nil?) #这次命名的是新的tag - - # 是否还有其他记录 引用了 tag_id - @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") - # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 - if @tagging.count == 1 - @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) - @tag.update_attributes({:name=>@rename_tag_name}) - else #如果tagging表中的记录大于1,那么就要新增tag记录 - - unless @obj.nil? - @obj.tag_list.add(@rename_tag_name.split(",")) - @obj.save - end - #删除原来的对应的taggings的记录 - unless @taggings.nil? - @taggings.delete - end - end - else #这是已有的tag - # 更改taggings记录里的tag_id - unless @taggings.nil? - @taggings.update_attributes({:tag_id=>@rename_tag.id}) - end - end - end - - @obj_flag = params[:taggableType] - if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course) - @course = @obj.container - @tag_list = @tag_list = get_course_tag_list @course - elsif @course_id - @course = Course.find(@course_id) - @tag_list = get_course_tag_list @course - - #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 - @flag = params[:flag] || false - sort = "" - @sort = "" - @order = "" - @is_remote = false - @isproject = false - - sort = "#{Attachment.table_name}.created_on desc" - - @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] - - show_attachments @containers - elsif @obj && @obj_flag == '5' - @forum = @obj - end - respond_to do |format| - format.js - end - end - - def update_project_tag_name - @tag_name = params[:tagName] - @rename_tag_name = params[:renameName] - @taggable_id = params[:taggableId] - @taggable_type = numbers_to_object_type(params[:taggableType]) - @project_id = params[:projectId] - - @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag - @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? - @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? - if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 - if @project_id - project = Project.find @project_id - if project - project.attachments.each do |attachment| - taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) - if taggings - taggings.delete - attachment.tag_list.add(@rename_tag_name.split(",")) - attachment.save - end - end - end - end - else - if(@rename_tag.nil?) #这次命名的是新的tag - - # 是否还有其他记录 引用了 tag_id - @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") - # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 - if @tagging.count == 1 - @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) - @tag.update_attributes({:name=>@rename_tag_name}) - else #如果tagging表中的记录大于1,那么就要新增tag记录 - - unless @obj.nil? - @obj.tag_list.add(@rename_tag_name.split(",")) - @obj.save - end - #删除原来的对应的taggings的记录 - unless @taggings.nil? - @taggings.delete - end - end - else #这是已有的tag - # 更改taggings记录里的tag_id - unless @taggings.nil? - @taggings.update_attributes({:tag_id=>@rename_tag.id}) - end - end - end - - @obj_flag = params[:taggableType] - if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project) - @project = @obj.container - @tag_list = @tag_list = get_course_tag_list @project - elsif @project_id - @project = Project.find(@project_id) - @tag_list = get_project_tag_list @project - - #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 - @flag = params[:flag] || false - sort = "" - @sort = "" - @order = "" - @is_remote = false - @isproject = false - - sort = "#{Attachment.table_name}.created_on desc" - - @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] - - show_attachments @containers - elsif @obj && @obj_flag == '5' - @forum = @obj - end - respond_to do |format| - format.js - end - end - - def update_org_subfield_tag_name - @tag_name = params[:tagName] - @rename_tag_name = params[:renameName] - @taggable_id = params[:taggableId] - @taggable_type = numbers_to_object_type(params[:taggableType]) - @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag - @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? - @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? - if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 - if params[:org_subfield_id] - org_subfield = OrgSubfield.find params[:org_subfield_id] - if org_subfield - org_subfield.attachments.each do |attachment| - taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) - if taggings - taggings.delete - attachment.tag_list.add(@rename_tag_name.split(",")) - attachment.save - end - end - end - end - else - if(@rename_tag.nil?) #这次命名的是新的tag - - # 是否还有其他记录 引用了 tag_id - @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") - # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 - if @tagging.count == 1 - @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) - @tag.update_attributes({:name=>@rename_tag_name}) - else #如果tagging表中的记录大于1,那么就要新增tag记录 - - unless @obj.nil? - @obj.tag_list.add(@rename_tag_name.split(",")) - @obj.save - end - #删除原来的对应的taggings的记录 - unless @taggings.nil? - @taggings.delete - end - end - else #这是已有的tag - # 更改taggings记录里的tag_id - unless @taggings.nil? - @taggings.update_attributes({:tag_id=>@rename_tag.id}) - end - end - end - - @obj_flag = params[:taggableType] - if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield) - @org_subfield = @obj.container - @tag_list = @tag_list = get_org_subfield_tag_list @org_subfield - elsif params[:org_subfield_id] - @org_subfield = OrgSubfield.find(params[:org_subfield_id]) - @tag_list = get_org_subfield_tag_list @org_subfield - - #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 - @flag = params[:flag] || false - sort = "" - @sort = "" - @order = "" - @is_remote = false - @isproject = false - - sort = "#{Attachment.table_name}.created_on desc" - - @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] - - show_attachments @containers - elsif @obj && @obj_flag == '5' - @forum = @obj - end - respond_to do |format| - format.js - end - end - - def show_attachments obj - @attachments = [] - obj.each do |container| - @attachments += container.attachments - end - @all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments) - @limit = 10 - @feedback_count = @all_attachments.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @obj_attachments = paginateHelper @all_attachments,10 - end - - def tag_save - @select_tag_name = params[:tag_for_save][:tag_name] - @tags = params[:tag_for_save][:name] - @obj_id = params[:tag_for_save][:object_id] - @obj_flag = params[:tag_for_save][:object_flag] - - case @obj_flag - when '1' then - @obj = User.find_by_id(@obj_id) - when '2' then - @obj = Project.find_by_id(@obj_id) - when '3' then - @obj = Issue.find_by_id(@obj_id) - when '4' then - @obj = Bid.find_by_id(@obj_id) - when '5' then - @obj = Forum.find_by_id(@obj_id) - when '6' - @obj = Attachment.find_by_id(@obj_id) - when '7' then - @obj = Contest.find_by_id(@obj_id) - when '8' - @obj = OpenSourceProject.find_by_id(@obj_id) - when '9' - @obj = Course.find_by_id(@obj_id) - when '10' - @obj = Attachment.find_by_id(@obj_id) - else - @obj = nil - end - unless @obj.nil? - @obj.tag_list.add(@tags.split(",")) - else - return - end - if @obj.save - logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}" - else - logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}" - end - if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course) - @course = @obj.container - @tag_list = @tag_list = get_course_tag_list @course - end - if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project) - @project = @obj.container - @tag_list = @tag_list = get_project_tag_list @project - end - if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield) - @org_subfield = @obj.container - @tag_list = @tag_list = get_org_subfield_tag_list @org_subfield - end - respond_to do |format| - format.js - format.html - end - end - - private - # 这里用来刷新搜索结果的区域 - # 函数的返回值 前2字段用来处理获取其他tag和分页 ,另外4个返回值为过滤结果 - def refresh_results(obj_id,obj_flag,selected_tags) - @users_results = nil - @projects_results = nil - @issues_results = nil - @bids_results = nil - @contests_results = nil - @forums_results = nil - @attachments_results = nil - @open_source_projects_results = nil - @obj_pages = nil - @obj = nil - @result = nil - @courses_results = nil - - # 这里为了提高系统的响应速度 把搜索结果放到case中去了 - case obj_flag - when '1' then - @obj = User.find_by_id(obj_id) - @obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags)) - when '2' then - @obj = Project.find_by_id(obj_id) - @obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags)) - when '3' then - @obj = Issue.find_by_id(obj_id) - @obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags)) - when '4' then - @obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags)) - @obj = Bid.find_by_id(obj_id) - when '5' - @obj = Forum.find_by_id(obj_id) - @obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags)) - when '6' - @obj = Attachment.find_by_id(obj_id) - - # modifed by Long Jun - # this is used to find the attachments that came from the same project and tagged with the same tag. - #@result = get_attachments_by_project_tag(selected_tags, @obj) - @result = get_attachments_by_tag(selected_tags) - @obj_pages, @attachments_results, @results_count = for_pagination(@result) - when '7' - @obj = Contest.find_by_id(obj_id) - @obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags)) - when '8' - @obj = OpenSourceProject.find_by_id(obj_id) - @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags)) - when '10' - @obj = Attachment.find_by_id(obj_id) - - # modifed by Long Jun - # this is used to find the attachments that came from the same project and tagged with the same tag. - #@result = get_attachments_by_project_tag(selected_tags, @obj) - @result = get_attachments_by_tag(selected_tags) - @obj_pages, @attachments_results, @results_count = for_pagination(@result) - when '9' then - @obj = Course.find_by_id(obj_id) - @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags)) - else - @obj = nil - end - return [@obj, - @obj_pages, - @results_count, - @users_results, - @projects_results, - @issues_results, - @bids_results, - @forums_results, - @attachments_results, - @contests_results, - @courses_results, - @open_source_projects_results] - end - - def for_pagination(results) - @offset, @limit = api_offset_and_limit({:limit => NUMBERS }) # 设置每页显示的个数 - @results_count = results.count - @obj_pages = Paginator.new @results_count, @limit, params['page'] # 3个参数分别是:总数,每页显示数目,第几页 - @offset ||= @obj_pages.offset - results = results.offset(@offset).limit(@limit).all # 这里默认设置为按时间排序 - return @obj_pages,results, @results_count - end - - # 获取有某类对象的tag总数 - def get_tags_size - @issues_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Issue").count - @projects_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Project").count - @users_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"User").count - @bids_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Bid").count - forum_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Forum").count - attachment_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Attachment").count - @open_source_projects_num = ActsAsTaggableOn::Tagging.where(taggable_type:"OpenSourceProject").count - @contests_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Contest").count - return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num, @open_source_projects_num - end - - # 通过数字 来转换出对象的类型 - # 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求 - # 这个函数 重构是可以移动到application_helper中去 - # 当做一个全局的函数使用,有好几个地方使用到了 - def numbers_to_object_type(num) - case num - when '1' - return 'Principal' - when '2' - return 'Project' - when '3' - return 'Issue' - when '4' - return 'Bid' - when '5' - return 'Forum' - when '6' - return 'Attachment' - when '7' - return 'Contest' - when '8' - return 'OpenSourceProject' - when '9' - return 'Course' - when '10' - return 'Attachment' - else - render_error :message => e.message - return - end - end - - - -end +# encoding: utf-8 +# This controller was added by william +class TagsController < ApplicationController + layout "base_tags" + + before_filter :require_admin,:only => :show + + include CoursesHelper + include ProjectsHelper + include IssuesHelper + include UsersHelper + include BidsHelper + include ForumsHelper + include AttachmentsHelper + include ContestsHelper + include ActsAsTaggableOn::TagsHelper + include TagsHelper + include FilesHelper + helper :projects + helper :courses + helper :tags + include OpenSourceProjectsHelper + + before_filter :require_admin,:only => [:delete,:show_all] + before_filter :require_login,:only => [:tag_save] + + # $selected_tags = Array.new + # $related_tags = Array.new + NUMBERS = Setting.tags_show_search_results + + # 预设几个可以添加的tag + #@preTags = %w|预设A 预设B 预设C 预设D 预设E 预设F | + + # 接收参数解释: + # params[:q]这是在其他页面点击tag,跳转到该页面后的结果显示 ;params[:selected_tags],这是在过滤页面增删tag进行过滤传过来的参数 + # 最后是2个过滤何种数据,显示结果的控制参数params[:obj_id],params[:object_falg] + # 0代表删除tag 1代表增加tag + def index + + @obj_id = params[:obj_id] + @obj_flag = params[:object_flag] + + @selected_tags = Array.new + @related_tags = nil + + if params[:q] + @selected_tags << params[:q] + else + @do_what = params[:do_what] + @tag = params[:tag] + @selected_tags = params[:current_selected_tags] + @selected_tags = @selected_tags.nil? ? Array.new : @selected_tags + + case @do_what + when '0' then + @selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop + when '1' then + # 判断是否已存在该tag 主要用来处理分页的情况 + unless @selected_tags.include? @tag + @selected_tags << @tag + end + end + end + + @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num,@contests_tags_num, + @forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size + + # 获取搜索结果 + @obj, + @obj_pages, + @results_count, + @users_results, + @projects_results, + @issues_results, + @bids_results, + @forums_results, + @attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags) + + # 这里是做tag推荐用的, 用来生产推荐的tags + unless @obj.nil? + @tags = @obj.tag_list + @tags -= @selected_tags + # @selected_tags.each do |i| + # @tags.delete(i) + # end + @related_tags = @tags + else + return + end + + end + + # 增加已选的tag + def add_tag + @tag = params[:tag] + @show_flag = params[:show_flag] + + $selected_tags << @tag + $related_tags.delete(@tag) + + # 获取搜索结果 + @obj, + @obj_pages, + @results_count, + @users_results, + @projects_results, + @issues_results, + @bids_results, + @forums_results, + @attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@show_flag) + end + + # 删除已选tag + def delete_tag + @tag = params[:tag] + @show_flag = params[:show_flag] + + $related_tags << @tag + $selected_tags.delete(@tag) + + # 获取搜索结果 + @obj, + @obj_pages, + @results_count, + @users_results, + @projects_results, + @issues_results, + @bids_results, + @forums_results, + @attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@show_flag) + end + + def show_all + @tags = ActsAsTaggableOn::Tag.find(:all) + end + + # 完全从数据库删除tag + # 这种删除方式是针对 印有该 tag所有对象来做删除的 + # 这样是从整个系统数据库中把该tag删除了 + def delete + if params[:q] + @tag = ActsAsTaggableOn::Tag.find_by_id(params[:q]) + @tag.delete + @taggings = ActsAsTaggableOn::Tagging.find_all_by_tag_id(@tag.id) + @taggings.each do |tagging| + tagging.delete + end + end + end + + # 只删除某个对象的该tag + def remove_tag + @obj = nil + @object_flag = nil + + if request.get? + # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 + @tag_name = params[:tag_name] + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id + @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 + @taggable_type = numbers_to_object_type(params[:taggable_type]) + + @obj = get_object(@taggable_id,params[:taggable_type]) + @object_flag = params[:taggable_type] + + # if can_remove_tag?(User.current,@taggable_id,@taggable_type) + + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) + + unless @taggings.nil? + @taggings.delete + end + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id) + # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作 + if @tagging.nil? + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.delete unless @tag.nil? + end + # end + end + end + + # 只删除某个对象的该tag + def remove_tag_new + @obj = nil + @object_flag = nil + + if request.get? + # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 + @tag_name = params[:tag_name] + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id + @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 + @taggable_type = numbers_to_object_type(params[:taggable_type]) + + @obj = get_object(@taggable_id,params[:taggable_type]) + @object_flag = params[:taggable_type] + + # if can_remove_tag?(User.current,@taggable_id,@taggable_type) + + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) + + unless @taggings.nil? + @taggings.delete + end + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id) + # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作 + if @tagging.nil? + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.delete unless @tag.nil? + end + + if @obj && @object_flag == '6' && @obj.container.kind_of?(Course) + @course = @obj.container + @tag_list = get_course_tag_list @course + @select_tag_name = params[:select_tag_name] + end + + if @obj && @object_flag == '6' && @obj.container.kind_of?(Project) + @project = @obj.container + @tag_list = get_course_tag_list @project + @select_tag_name = params[:select_tag_name] + end + + if @obj && @object_flag == '6' && @obj.container.kind_of?(OrgSubfield) + @org_subfield = @obj.container + @tag_list = get_org_subfield_tag_list @org_subfield + @select_tag_name = params[:select_tag_name] + end + # end + end + end + + #更新某个tag名称 + def update_tag_name + @tag_name = params[:tagName] + @rename_tag_name = params[:renameName] + @taggable_id = params[:taggableId] + @taggable_type = numbers_to_object_type(params[:taggableType]) + @course_id = params[:courseId] + + @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? + @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? + if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 + if @course_id + course = Course.find @course_id + if course + course.attachments.each do |attachment| + taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) + if taggings + taggings.delete + attachment.tag_list.add(@rename_tag_name.split(",")) + attachment.save + end + end + end + end + else + if(@rename_tag.nil?) #这次命名的是新的tag + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") + # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 + if @tagging.count == 1 + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.update_attributes({:name=>@rename_tag_name}) + else #如果tagging表中的记录大于1,那么就要新增tag记录 + + unless @obj.nil? + @obj.tag_list.add(@rename_tag_name.split(",")) + @obj.save + end + #删除原来的对应的taggings的记录 + unless @taggings.nil? + @taggings.delete + end + end + else #这是已有的tag + # 更改taggings记录里的tag_id + unless @taggings.nil? + @taggings.update_attributes({:tag_id=>@rename_tag.id}) + end + end + end + + @obj_flag = params[:taggableType] + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course) + @course = @obj.container + @tag_list = @tag_list = get_course_tag_list @course + elsif @course_id + @course = Course.find(@course_id) + @tag_list = get_course_tag_list @course + + #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 + @flag = params[:flag] || false + sort = "" + @sort = "" + @order = "" + @is_remote = false + @isproject = false + + sort = "#{Attachment.table_name}.created_on desc" + + @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] + + show_attachments @containers + elsif @obj && @obj_flag == '5' + @forum = @obj + end + respond_to do |format| + format.js + end + end + + def update_project_tag_name + @tag_name = params[:tagName] + @rename_tag_name = params[:renameName] + @taggable_id = params[:taggableId] + @taggable_type = numbers_to_object_type(params[:taggableType]) + @project_id = params[:projectId] + + @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? + @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? + if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 + if @project_id + project = Project.find @project_id + if project + project.attachments.each do |attachment| + taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) + if taggings + taggings.delete + attachment.tag_list.add(@rename_tag_name.split(",")) + attachment.save + end + end + end + end + else + if(@rename_tag.nil?) #这次命名的是新的tag + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") + # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 + if @tagging.count == 1 + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.update_attributes({:name=>@rename_tag_name}) + else #如果tagging表中的记录大于1,那么就要新增tag记录 + + unless @obj.nil? + @obj.tag_list.add(@rename_tag_name.split(",")) + @obj.save + end + #删除原来的对应的taggings的记录 + unless @taggings.nil? + @taggings.delete + end + end + else #这是已有的tag + # 更改taggings记录里的tag_id + unless @taggings.nil? + @taggings.update_attributes({:tag_id=>@rename_tag.id}) + end + end + end + + @obj_flag = params[:taggableType] + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project) + @project = @obj.container + @tag_list = @tag_list = get_course_tag_list @project + elsif @project_id + @project = Project.find(@project_id) + @tag_list = get_project_tag_list @project + + #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 + @flag = params[:flag] || false + sort = "" + @sort = "" + @order = "" + @is_remote = false + @isproject = false + + sort = "#{Attachment.table_name}.created_on desc" + + @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] + + show_attachments @containers + elsif @obj && @obj_flag == '5' + @forum = @obj + end + respond_to do |format| + format.js + end + end + + def update_org_subfield_tag_name + @tag_name = params[:tagName] + @rename_tag_name = params[:renameName] + @taggable_id = params[:taggableId] + @taggable_type = numbers_to_object_type(params[:taggableType]) + @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? + @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? + if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 + if params[:org_subfield_id] + org_subfield = OrgSubfield.find params[:org_subfield_id] + if org_subfield + org_subfield.attachments.each do |attachment| + taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) + if taggings + taggings.delete + attachment.tag_list.add(@rename_tag_name.split(",")) + attachment.save + end + end + end + end + else + if(@rename_tag.nil?) #这次命名的是新的tag + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") + # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 + if @tagging.count == 1 + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.update_attributes({:name=>@rename_tag_name}) + else #如果tagging表中的记录大于1,那么就要新增tag记录 + + unless @obj.nil? + @obj.tag_list.add(@rename_tag_name.split(",")) + @obj.save + end + #删除原来的对应的taggings的记录 + unless @taggings.nil? + @taggings.delete + end + end + else #这是已有的tag + # 更改taggings记录里的tag_id + unless @taggings.nil? + @taggings.update_attributes({:tag_id=>@rename_tag.id}) + end + end + end + + @obj_flag = params[:taggableType] + if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield) + @org_subfield = @obj.container + @tag_list = @tag_list = get_org_subfield_tag_list @org_subfield + elsif params[:org_subfield_id] + @org_subfield = OrgSubfield.find(params[:org_subfield_id]) + @tag_list = get_org_subfield_tag_list @org_subfield + + #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 + @flag = params[:flag] || false + sort = "" + @sort = "" + @order = "" + @is_remote = false + @isproject = false + + sort = "#{Attachment.table_name}.created_on desc" + + @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] + + show_attachments @containers + elsif @obj && @obj_flag == '5' + @forum = @obj + end + respond_to do |format| + format.js + end + end + + def show_attachments obj + @attachments = [] + obj.each do |container| + @attachments += container.attachments + end + @all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments) + @limit = 10 + @feedback_count = @all_attachments.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @obj_attachments = paginateHelper @all_attachments,10 + end + + def tag_save + @select_tag_name = params[:tag_for_save][:tag_name] + @tags = params[:tag_for_save][:name] + @obj_id = params[:tag_for_save][:object_id] + @obj_flag = params[:tag_for_save][:object_flag] + + case @obj_flag + when '1' then + @obj = User.find_by_id(@obj_id) + when '2' then + @obj = Project.find_by_id(@obj_id) + when '3' then + @obj = Issue.find_by_id(@obj_id) + when '4' then + @obj = Bid.find_by_id(@obj_id) + when '5' then + @obj = Forum.find_by_id(@obj_id) + when '6' + @obj = Attachment.find_by_id(@obj_id) + when '7' then + @obj = Contest.find_by_id(@obj_id) + when '8' + @obj = OpenSourceProject.find_by_id(@obj_id) + when '9' + @obj = Course.find_by_id(@obj_id) + when '10' + @obj = Attachment.find_by_id(@obj_id) + else + @obj = nil + end + unless @obj.nil? + @obj.tag_list.add(@tags.split(",")) + else + return + end + if @obj.save + logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}" + else + logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}" + end + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course) + @course = @obj.container + @tag_list = @tag_list = get_course_tag_list @course + end + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project) + @project = @obj.container + @tag_list = @tag_list = get_project_tag_list @project + end + if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield) + @org_subfield = @obj.container + @tag_list = @tag_list = get_org_subfield_tag_list @org_subfield + end + respond_to do |format| + format.js + format.html + end + end + + private + # 这里用来刷新搜索结果的区域 + # 函数的返回值 前2字段用来处理获取其他tag和分页 ,另外4个返回值为过滤结果 + def refresh_results(obj_id,obj_flag,selected_tags) + @users_results = nil + @projects_results = nil + @issues_results = nil + @bids_results = nil + @contests_results = nil + @forums_results = nil + @attachments_results = nil + @open_source_projects_results = nil + @obj_pages = nil + @obj = nil + @result = nil + @courses_results = nil + + # 这里为了提高系统的响应速度 把搜索结果放到case中去了 + case obj_flag + when '1' then + @obj = User.find_by_id(obj_id) + @obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags)) + when '2' then + @obj = Project.find_by_id(obj_id) + @obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags)) + when '3' then + @obj = Issue.find_by_id(obj_id) + @obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags)) + when '4' then + @obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags)) + @obj = Bid.find_by_id(obj_id) + when '5' + @obj = Forum.find_by_id(obj_id) + @obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags)) + when '6' + @obj = Attachment.find_by_id(obj_id) + + # modifed by Long Jun + # this is used to find the attachments that came from the same project and tagged with the same tag. + #@result = get_attachments_by_project_tag(selected_tags, @obj) + @result = get_attachments_by_tag(selected_tags) + @obj_pages, @attachments_results, @results_count = for_pagination(@result) + when '7' + @obj = Contest.find_by_id(obj_id) + @obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags)) + when '8' + @obj = OpenSourceProject.find_by_id(obj_id) + @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags)) + when '10' + @obj = Attachment.find_by_id(obj_id) + + # modifed by Long Jun + # this is used to find the attachments that came from the same project and tagged with the same tag. + #@result = get_attachments_by_project_tag(selected_tags, @obj) + @result = get_attachments_by_tag(selected_tags) + @obj_pages, @attachments_results, @results_count = for_pagination(@result) + when '9' then + @obj = Course.find_by_id(obj_id) + @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags)) + else + @obj = nil + end + return [@obj, + @obj_pages, + @results_count, + @users_results, + @projects_results, + @issues_results, + @bids_results, + @forums_results, + @attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results] + end + + def for_pagination(results) + @offset, @limit = api_offset_and_limit({:limit => NUMBERS }) # 设置每页显示的个数 + @results_count = results.count + @obj_pages = Paginator.new @results_count, @limit, params['page'] # 3个参数分别是:总数,每页显示数目,第几页 + @offset ||= @obj_pages.offset + results = results.offset(@offset).limit(@limit).all # 这里默认设置为按时间排序 + return @obj_pages,results, @results_count + end + + # 获取有某类对象的tag总数 + def get_tags_size + @issues_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Issue").count + @projects_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Project").count + @users_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"User").count + @bids_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Bid").count + forum_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Forum").count + attachment_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Attachment").count + @open_source_projects_num = ActsAsTaggableOn::Tagging.where(taggable_type:"OpenSourceProject").count + @contests_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Contest").count + return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num, @open_source_projects_num + end + + # 通过数字 来转换出对象的类型 + # 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求 + # 这个函数 重构是可以移动到application_helper中去 + # 当做一个全局的函数使用,有好几个地方使用到了 + def numbers_to_object_type(num) + case num + when '1' + return 'Principal' + when '2' + return 'Project' + when '3' + return 'Issue' + when '4' + return 'Bid' + when '5' + return 'Forum' + when '6' + return 'Attachment' + when '7' + return 'Contest' + when '8' + return 'OpenSourceProject' + when '9' + return 'Course' + when '10' + return 'Attachment' + else + render_error :message => e.message + return + end + end + + + +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a1dc443e0..1d328c1e9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -26,6 +26,7 @@ class UsersController < ApplicationController menu_item :user_information, :only => :info menu_item :user_course, :only => :user_courses menu_item :user_homework, :only => :user_homeworks + menu_item :student_homework, :only => :student_homeworks menu_item :user_project, :only => [:user_projects, :watch_projects] menu_item :requirement_focus, :only => :watch_contests menu_item :user_newfeedback, :only => :user_newfeedback @@ -35,12 +36,12 @@ class UsersController < ApplicationController # before_filter :can_show_course, :only => [:user_courses,:user_homeworks] before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, - :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, + :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, - :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages] + :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -106,7 +107,7 @@ class UsersController < ApplicationController redirect_to signin_url return elsif @user != User.current && !User.current.admin? - return render_403 + return render_403 end # 初始化/更新 点击按钮时间 # 24小时内显示系统消息 @@ -374,32 +375,131 @@ class UsersController < ApplicationController #用户作业列表 def user_homeworks - if User.current == @user - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" - - #判断当前用户在当前课程的身份 - visibleCourse = @user.courses.empty? ? [] : @user.courses.visible - homework_ids = [] - visibleCourse.each do |course| - if User.current.allowed_to?(:as_teacher,course) - homeworks = HomeworkCommon.where("course_id = #{course.id}") - homework_ids << homeworks.pluck(:id) unless homeworks.empty? - else - homeworks = HomeworkCommon.where("course_id = #{course.id} and publish_time <= '#{Date.today}'") - homework_ids << homeworks.pluck(:id) unless homeworks.empty? + @user = User.current + 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(",") + ")" + @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'").order("created_at desc") + elsif params[:type] == "2" #我的题库 + @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("created_at desc") + end + @type = params[:type] + @limit = 15 + @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 + respond_to do |format| + format.js + format.html {render :layout => 'static_base'} + end + end + + def student_homeworks + if User.current == @user + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" + + #判断当前用户在当前课程的身份 + visibleCourse = @user.courses.empty? ? [] : @user.courses.visible + homework_ids = [] + visibleCourse.each do |course| + homeworks = HomeworkCommon.where("course_id = #{course.id} and publish_time <= '#{Date.today}'") + homework_ids << homeworks.pluck(:id) unless homeworks.empty? end + visible_homework_ids = homework_ids.size == 0 ? "(-1)" :"(" + homework_ids.join(",") + ")" + @homework_commons = HomeworkCommon.where("id in #{visible_homework_ids}").order("created_at desc").limit(10).offset(@page * 10) + @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true) + @is_in_course = params[:is_in_course].to_i || 0 + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + else + render_403 end - visible_homework_ids = homework_ids.size == 0 ? "(-1)" :"(" + homework_ids.join(",") + ")" - @homework_commons = HomeworkCommon.where("id in #{visible_homework_ids}").order("created_at desc").limit(10).offset(@page * 10) - @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true) - @is_in_course = params[:is_in_course].to_i || 0 - respond_to do |format| - format.js - format.html {render :layout => 'new_base_user'} - end + end + + def choose_user_course + homework = HomeworkCommon.find params[:homework].to_i + if !params[:search].nil? + search = "%#{params[:search].to_s.strip.downcase}%" + @course = @user.courses.where("#{Course.table_name}.id != #{homework.course_id} and #{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)} else - render_403 + @course = @user.courses.where("#{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)} + end + @search = params[:search] + #这里仅仅是传递需要发送的资源id + @send_id = params[:send_id] + respond_to do |format| + format.js + end + end + + def send_homework_to_course + homework = HomeworkCommon.find params[:send_id].to_i + course_ids = params[:course_ids] + course_ids.each do |course_id| + course = Course.find course_id.to_i + new_homework = HomeworkCommon.new + new_homework.name = homework.name + new_homework.user_id = User.current.id + new_homework.description = homework.description + new_homework.homework_type = homework.homework_type + new_homework.late_penalty = homework.late_penalty + new_homework.course_id = course.id + new_homework.teacher_priority = homework.teacher_priority + new_homework.anonymous_comment = homework.anonymous_comment + new_homework.quotes = 0 + new_homework.is_open = homework.is_open + homework.attachments.each do |attachment| + att = attachment.copy + att.container_id = nil + att.container_type = nil + att.copy_from = attachment.id + att.save + new_homework.attachments << att + end + homework_detail_manual = homework.homework_detail_manual + homework_detail_programing = homework.homework_detail_programing + homework_detail_group = homework.homework_detail_group + if homework_detail_manual + new_homework.homework_detail_manual = HomeworkDetailManual.new + new_homework_detail_manual = new_homework.homework_detail_manual + new_homework_detail_manual.ta_proportion = homework_detail_manual.ta_proportion + new_homework_detail_manual.comment_status = 0 + new_homework_detail_manual.evaluation_num = homework_detail_manual.evaluation_num + new_homework_detail_manual.absence_penalty = homework_detail_manual.absence_penalty + end + if homework_detail_programing + new_homework.homework_detail_programing = HomeworkDetailPrograming.new + new_homework.homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion + new_homework.homework_detail_programing.language = homework_detail_programing.language + homework.homework_tests.each_with_index do |homework_test| + new_homework.homework_tests << HomeworkTest.new( + input: homework_test.input, + output: homework_test.output + ) + end + end + + if homework_detail_group + new_homework.homework_detail_group = HomeworkDetailGroup.new + new_homework.homework_detail_group.min_num = homework_detail_group.min_num + new_homework.homework_detail_group.max_num = homework_detail_group.max_num + new_homework.homework_detail_group.base_on_project = homework_detail_group.base_on_project + end + if new_homework.save + new_homework_detail_manual.save if new_homework_detail_manual + new_homework.homework_detail_programing.save if new_homework.homework_detail_programing + new_homework.homework_detail_group.save if new_homework.homework_detail_group + end + homework.update_attribute(:quotes, homework.quotes+1) + end + @homework = homework + respond_to do |format| + format.js end end @@ -432,13 +532,22 @@ class UsersController < ApplicationController elsif params[:type] == "2" #我的题库 @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}'").order("created_at desc") end + if params[:property] && params[:property] == "1" + @homeworks = @homeworks.where("homework_type = 1").reorder("created_at desc") + elsif params[:property] && params[:property] == "2" + @homeworks = @homeworks.where("homework_type = 2").reorder("created_at desc") + elsif params[:property] && params[:property] == "3" + @homeworks = @homeworks.where("homework_type = 3").reorder("created_at desc") + end @type = params[:type] + @property = params[:property] @limit = 15 @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] respond_to do |format| format.js end @@ -446,6 +555,7 @@ class UsersController < ApplicationController def show_homework_detail @homework = HomeworkCommon.find params[:homework].to_i + @is_import = params[:is_import] respond_to do |format| format.js end @@ -458,10 +568,21 @@ class UsersController < ApplicationController 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(",") + ")" - @homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("created_at desc") + all_homeworks = HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}'") + 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("created_at desc") elsif params[:type] == "2" #课程资源 @homeworks = HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("created_at desc") end + if params[:property] && params[:property] == "1" + @homeworks = @homeworks.where("homework_type = 1").reorder("created_at desc") + elsif params[:property] && params[:property] == "2" + @homeworks = @homeworks.where("homework_type = 2").reorder("created_at desc") + elsif params[:property] && params[:property] == "3" + @homeworks = @homeworks.where("homework_type = 3").reorder("created_at desc") + end @type = params[:type] @limit = 15 @is_remote = true @@ -469,6 +590,7 @@ class UsersController < ApplicationController @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 @offset ||= @hw_pages.offset @homeworks = paginateHelper @homeworks,15 + @is_import = params[:is_import] respond_to do |format| format.js end @@ -532,9 +654,10 @@ class UsersController < ApplicationController if @student_work.nil? @student_work = StudentWork.new end + @course = @homework.course respond_to do |format| format.js - format.html {render :layout => 'new_base_user'} + format.html {render :layout => 'base_courses'} end else render_403 @@ -569,7 +692,7 @@ class UsersController < ApplicationController student_work.save flash[:notice] = l(:notice_successful_create) redirect_to student_work_index_url(:homework => params[:homework]) - else + else render_403 end end @@ -683,19 +806,23 @@ class UsersController < ApplicationController 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} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - @attachments = Attachment.where("(author_id = #{params[:id]} 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(',')}))").order("created_on desc") - elsif params[:type] == "2" #课程资源 - 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(',')})) ").order("created_on desc") - elsif params[:type] == "3" #项目资源 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project'").order("created_on desc") + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + @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 = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") + @attachments = get_attch_resources params[:id] elsif params[:type] == "5" #用户资源 - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal'").order("created_on desc") + @attachments = get_principal_resources params[:id] + elsif params[:type] == "6" # 公共资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) end @type = params[:type] @limit = 7 @@ -728,6 +855,8 @@ class UsersController < ApplicationController @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%')").order("created_on desc") elsif params[:type] == "5" #用户资源 @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like '%#{search}%')").order("created_on desc") + elsif params[:type] == "6" #公共资源 + @attachments = Attachment.where("(is_public =1 and is_publish = 1 and container_id is not null)" + "or (author_id = #{params[:id]} and is_publish = 0)").order("created_on desc") end @type = params[:type] @limit = 7 @@ -768,7 +897,7 @@ class UsersController < ApplicationController def store_selected_resource session[:seleted_resource_ids] = [] if session[:seleted_resource_ids].nil? if params[:save] == 'y' - session[:seleted_resource_ids] << params[:res_id] + session[:seleted_resource_ids] << params[:res_id] else session[:seleted_resource_ids].delete( params[:res_id]) end @@ -1074,12 +1203,12 @@ class UsersController < ApplicationController else blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + - "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) + "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10) end else - # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) + # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10) blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")" @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+ @@ -1402,50 +1531,51 @@ class UsersController < ApplicationController # 上传用户资源 def user_resource_create + 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 = User.find(params[:id]) #@user.save_attachments(params[:attachments],User.current) # Container_type为Principal Attachment.attach_filesex(@user, params[:attachments], params[:attachment_type]) - if(params[:type].blank?|| params[:type] == "1") #全部 - 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 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(',')}))").order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 " + - "and container_type in('Project','OrgSubfield','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(',')}))").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(',')})) ").order("created_on desc") + if(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + if params[:status] == 2 + @attachments = get_course_resources(params[:id], user_course_ids) + elsif params[:status] == "3" + @attachments = get_project_resources(params[:id], user_project_ids) + elsif params[:status] == "4" + @attachments = get_attch_resources params[:id] + elsif params[:status] == "5" + @attachments = get_principal_resources params[:id] 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(',')}))").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'").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' ").order("created_on desc") + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) 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" #附件 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") - 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'").order("created_on desc") + @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) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids) + elsif params[:status] == "4" + @attachments = get_attch_resources_public + elsif params[:status] == "5" + @attachments = get_principal_resources_public else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type ='Principal'").order("created_on desc") + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) end end - @type = params[:type] || 1 + @status = params[:status] + @type = params[:type] @limit = 25 @is_remote = true @atta_count = @attachments.count @@ -1467,46 +1597,46 @@ class UsersController < ApplicationController Attachment.where("author_id = #{User.current.id}").delete(id) end end - - if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部 - 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 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(',')}))").order("created_on 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) + elsif params[:status] == "3" + @attachments = get_project_resources(params[:id], user_project_ids) + elsif params[:status] == "4" + @attachments = get_attch_resources params[:id] + elsif params[:status] == "5" + @attachments = get_principal_resources params[:id] else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 " + - "and container_type in('Project','OrgSubfield','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(',')}))").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(',')})) ").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(',')}))").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'").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' ").order("created_on desc") + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) 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" #附件 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") - end + @attachments = get_attch_resources params[:id] 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'").order("created_on desc") + @attachments = get_principal_resources params[:id] + elsif params[:type] == "6" # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids) + elsif params[:status] == "4" + @attachments = get_attch_resources_public + elsif params[:status] == "5" + @attachments = get_principal_resources_public else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type ='Principal'").order("created_on desc") + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) end end + @status = params[:status] @type = params[:type] @limit = 25 @is_remote = true @@ -1592,6 +1722,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 4 end if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end @save_message = attach_copied_obj.errors.full_messages @@ -1604,10 +1737,11 @@ class UsersController < ApplicationController @flag = false end send_ids.each do |send_id| + quotes = 0 ori = Attachment.find_by_id(send_id) - unless course_ids.nil? course_ids.each do |id| + quotes = 0 next if ori.blank? @exist = false Course.find(id).attachments.each do |att| #如果课程中包含该资源 @@ -1630,6 +1764,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 4 end if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end @save_message = attach_copied_obj.errors.full_messages @@ -1690,6 +1827,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 1 end if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end unless Project.find(project_id).project_score.nil? @@ -1705,10 +1845,11 @@ class UsersController < ApplicationController @flag = false end send_ids.each do |send_id| - + quotes = 0 ori = Attachment.find_by_id(send_id) unless project_ids.nil? project_ids.each do |project_id| + quotes = 0 next if ori.blank? @exist = false Project.find(project_id).attachments.each do |att| #如果课程中包含该资源 @@ -1731,6 +1872,9 @@ class UsersController < ApplicationController attach_copied_obj.attachtype = 1 end if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end unless Project.find(project_id).project_score.nil? @@ -1769,30 +1913,33 @@ class UsersController < ApplicationController end ori = Attachment.find_by_id(send_id) unless subfield_id.nil? - attach_copied_obj = ori.copy - @exist = false - OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源 - if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from - att.created_on = Time.now - att.save - @exist = true - break - end + attach_copied_obj = ori.copy + @exist = false + OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源 + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break end - if @exist == false #如果不存在该资源 - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 - attach_copied_obj.container = OrgSubfield.find(subfield_id) - attach_copied_obj.created_on = Time.now - attach_copied_obj.author_id = User.current.id - attach_copied_obj.is_public = 0 - attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from - if attach_copied_obj.attachtype == nil - attach_copied_obj.attachtype = 1 - end - if attach_copied_obj.save - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) - end + end + if @exist == false #如果不存在该资源 + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = OrgSubfield.find(subfield_id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.is_public = 0 + attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 1 end + if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? + ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + end + end end elsif params[:send_ids].present? send_ids = params[:send_ids].split(" ") @@ -1801,33 +1948,36 @@ class UsersController < ApplicationController @flag = false end send_ids.each do |send_id| - + quotes = 0 ori = Attachment.find_by_id(send_id) unless subfield_id.nil? - next if ori.blank? - @exist = false - OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源 - if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from - att.created_on = Time.now - att.save - @exist = true - break - end - end - next if @exist - attach_copied_obj = ori.copy - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 - attach_copied_obj.container = OrgSubfield.find(subfield_id) - attach_copied_obj.created_on = Time.now - attach_copied_obj.author_id = User.current.id - attach_copied_obj.is_public = 0 - attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from - if attach_copied_obj.attachtype == nil - attach_copied_obj.attachtype = 1 - end - if attach_copied_obj.save - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + next if ori.blank? + @exist = false + OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源 + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break end + end + next if @exist + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = OrgSubfield.find(subfield_id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.is_public = 0 + attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 1 + end + if attach_copied_obj.save + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? + ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + end end end else @@ -1862,8 +2012,8 @@ class UsersController < ApplicationController end news.attachments.each do |attach| course_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, - :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, - :is_public => attach.is_public, :quotes => 0) + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) end end end @@ -1882,8 +2032,8 @@ class UsersController < ApplicationController end news.attachments.each do |attach| message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, - :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, - :is_public => attach.is_public, :quotes => 0) + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) end end end @@ -1899,8 +2049,8 @@ class UsersController < ApplicationController end news.attachments.each do |attach| org_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, - :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, - :is_public => attach.is_public, :quotes => 0) + :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, + :is_public => attach.is_public, :quotes => 0) end OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'News', :org_act_id => org_news.id, :user_id => User.current.id) end @@ -2168,54 +2318,107 @@ class UsersController < ApplicationController end end + # 获取公共资源 + def get_public_resources user_course_ids, user_project_ids + attachments = Attachment.where("(is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','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)" + + "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") + end + + # 获取我的资源 + def get_my_resources author_id, user_course_ids, user_project_ids + 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") + 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") + end + + # 获取公共资源课程 + def get_course_resources_public user_course_ids + attchments = Attachment.where("(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") + 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") + end + + # 获取公共资源的项目资源 + def get_project_resources_public user_project_ids + attchments = Attachment.where("(container_type = 'Project') or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc") + 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") + end + + # 获取公共资源中我上传的附件 + def get_attch_resources_public + attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") + end + + # 获取我的用户类型资源 + def get_principal_resources author_id + attchments = Attachment.where("author_id = #{author_id} and container_type = 'Principal'").order("created_on desc") + end + + # 获取我的用户类型资源 + def get_principal_resources_public + attchments = Attachment.where("container_type = 'Principal'").order("created_on desc") + end + # 资源库 分为全部 课程资源 项目资源 附件 def user_resource - #确定container_type - # @user = User.find(params[:id]) # 别人的资源库是没有权限去看的 if User.current.id.to_i != params[:id].to_i render_403 return end - if(params[:type].blank? || params[:type] == "1") #全部 - 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 is_publish = 1 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)").order("created_on desc") - else - user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 and is_publish = 1 " + - "and container_type in('Project','OrgSubfield','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 is_publish = 1)").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' 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") - 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' and is_publish = 1)"+ - "or (container_type = 'Course' and is_public = 1 and is_publish = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").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'").order("created_on 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) + elsif params[:status] == "3" + @attachments = get_project_resources(params[:id], user_project_ids) + elsif params[:status] == "4" + @attachments = get_attch_resources params[:id] + elsif params[:status] == "5" + @attachments = get_principal_resources params[:id] else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' ").order("created_on desc") + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) 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" #附件 - if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") - else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc") - end + @attachments = get_attch_resources params[:id] 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'").order("created_on desc") + @attachments = get_principal_resources params[:id] + elsif params[:type] == "6" # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids) + elsif params[:status] == "4" + @attachments = get_attch_resources_public + elsif params[:status] == "5" + @attachments = get_principal_resources_public else - @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal'").order("created_on desc") + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) end end + @status = params[:status] @type = params[:type] @limit = 25 @is_remote = true @@ -2226,18 +2429,141 @@ class UsersController < ApplicationController @attachments = paginateHelper @attachments,25 respond_to do |format| format.js - format.html {render :layout => 'new_base_user'} + format.html {render :layout => 'new_base'} + end + end + + # 导入资源 + def import_resources + # 别人的资源库是没有权限去看的 + 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") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + @attachments = get_my_resources(params[:id], user_course_ids, user_project_ids) + elsif params[:type] == "6" # 公共资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) + end + @type = params[:type] + @limit = 10 + @is_remote = true + @atta_count = @attachments.count + @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 + respond_to do |format| + format.js + format.html {render :layout => 'new_base'} + end + end + + def import_resources_search + search = "%#{params[: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") + elsif params[:type] == "6" # 公共资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids) + end + @type = params[:type] + @limit = 10 + @is_remote = true + @atta_count = @attachments.count + @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 + respond_to do |format| + format.js + format.html {render :layout => 'new_base'} + end + end + + # 内容导入到对象中 + def import_into_container + send_ids = params[:checkbox1] + # mul_id为当前课程id、项目id、组织id的多种形态 + mul_id = params[:mul_id] + if params[:mul_type] == "Course" + mul_container = Course.find(mul_id) + elsif params[:mul_type] == "Project" + mul_container = Project.find(mul_id) + elsif params[:mul_type] == "SubfieldFile" + mul_container = OrgSubfield.find(mul_id) + end + unless params[:checkbox1].blank? + send_ids.each do |send_id| + ori = Attachment.find_by_id(send_id) + # 如果该附件已经存课程中,则只更新附件创建时间 + mul_container.attachments.each do |att| + if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + att.created_on = Time.now + att.save + @exist = true + break + end + end + next if @exist + attach_copied_obj = ori.copy + attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + attach_copied_obj.container = mul_container + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.is_public = 0 + attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + attach_copied_obj.save + @save_message = attach_copied_obj.errors.full_messages + end + end + respond_to do |format| + format.html { + if params[:mul_type] == "Course" + redirect_to course_files_url(mul_container) unless mul_container.nil? + elsif params[:mul_type] == "Project" + redirect_to project_files_url(mul_container) unless mul_container.nil? + elsif params[:mul_type] == "SubfieldFile" + redirect_to org_subfield_files_url(mul_container) unless mul_container.nil? + end + } end end # 根据资源关键字进行搜索 def resource_search search = "%#{params[: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 - user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询 - @attachments = Attachment.where("((author_id = #{params[:id]} 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 (filename like :p) ",:p=>search).order("created_on desc") + + @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" + @@ -2273,6 +2599,11 @@ class UsersController < ApplicationController 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") end + elsif params[:type] == "6" #全部资源 + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = Attachment.where("((is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','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)" + + "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") end @type = params[:type] @limit = 25 diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index d66c6a30d..386e5733d 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -134,8 +134,11 @@ class ZipdownController < ApplicationController homework_common.student_works.each do |work| unless work.attachments.empty? out_file = zip_student_work_by_user(work) - bid_homework_path << out_file.file_path - digests << out_file.file_digest + + bid_homework_path << out_file.file_path + digests << out_file.file_digest + + end end homework_id = homework_common.id @@ -172,7 +175,11 @@ class ZipdownController < ApplicationController } end - def zip_student_work_by_user work + def make_zip_name(work) + "#{work.user.show_name}_#{((work.user.user_extensions.nil? || work.user.user_extensions.student_id.nil?) ? "" : work.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}" + end + + def zip_student_work_by_user(work) homeworks_attach_path = [] not_exist_file = [] # 需要将所有homework.attachments遍历加入zip @@ -186,10 +193,23 @@ class ZipdownController < ApplicationController digests << 'not_exist_file' end end - out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){ - zipping("#{work.user.show_name}_#{((work.user.user_extensions.nil? || work.user.user_extensions.student_id.nil?) ? "" : work.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", - homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file) - } + + #单个文件的话,不需要压缩,只改名 + out_file = nil + if homeworks_attach_path.size == 1 + out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){ + des_path = "#{OUTPUT_FOLDER}/#{make_zip_name(work)}_#{File.basename(homeworks_attach_path.first)}" + FileUtils.cp homeworks_attach_path.first, des_path + des_path + } + else + out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){ + zipping("#{make_zip_name(work)}.zip", + homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file) + } + end + out_file + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9d08be378..22890fd9a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -110,11 +110,19 @@ module ApplicationHelper end end - # 更新课程英雄榜得分 - # user传过来必须是学生 + # 更新课程活跃度得分 def course_member_score(course_id,user_id,type) course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first case type + when "HomeworkCommon" + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :homework_journal_num => 1 , :total_score => 1) + else + score = course_contributor_score.homework_journal_num + 1 + total_score = course_contributor_score.total_score + 1 + course_contributor_score.update_attributes(:homework_journal_num => score, :total_score => total_score) + end when "JournalForMessage" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, @@ -151,6 +159,15 @@ module ApplicationHelper total_score = course_contributor_score.total_score + 1 course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score) end + when "News" + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, + :news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) + else + score = course_contributor_score.news_num + 1 + total_score = course_contributor_score.total_score + 1 + course_contributor_score.update_attributes(:news_num => score, :total_score => total_score) + end end end @@ -2512,7 +2529,7 @@ module ApplicationHelper #获取匿评相关连接代码 def homework_anonymous_comment (homework, is_in_course, user_activity_id = -1, course_activity = -1) - if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + if homework.homework_detail_manual.comment_status == 0 ||Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") link = link_to "启动匿评","javascript:void(0)", :class => "postOptionLink", :title => "作业截止日期之前不可以启动匿评" elsif homework.student_works.count >= 2 && homework.homework_detail_manual#作业份数大于2 case homework.homework_detail_manual.comment_status diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 2cdb277be..cbc514df6 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -25,7 +25,7 @@ module CoursesHelper # 获取tag匹配结果ID a_tags = [] # kc = keywords.to_a - Course.visible.where("is_excellent =?", 1).each do |ec| + Course.visible.where("is_excellent =? and is_public =?", 1, 1).each do |ec| if ec.tags.any?{|value| current_course.name.include?(value.to_s)} a_tags << ec.id end @@ -44,7 +44,7 @@ module CoursesHelper excellent_ids = a_courses.flatten.uniq.delete_if{|i| i == current_course.id} limit = 5 - excellent_ids.length.to_i sql = "SELECT distinct c.id FROM course_activities cs, courses c where cs.course_id = c.id - and c.is_excellent =1 and c.id != #{current_course.id} order by cs.updated_at desc;" + and c.is_excellent =1 and c.is_public = 1 and c.id != #{current_course.id} order by cs.updated_at desc;" default_ecourse_ids = Course.find_by_sql(sql).flatten # REDO:时间紧,待优化 default_ids =[] @@ -116,7 +116,7 @@ module CoursesHelper @course.journals_for_messages.where('m_parent_id IS NULL').count end - #当前学期 + #当前学期(2015春季学期) def current_time_and_term course str = "" term = cur_course_term @@ -144,6 +144,22 @@ module CoursesHelper val end + #当前学期(2015春) + def current_time_and_term_short course + str = "" + term = cur_course_term + if (course.time == course.end_time && course.term == course.end_term) || (course.end_term.nil? && course.end_time.nil?) || course.time > Time.now.year + str = course.time.to_s + course.term[0] + elsif course.time == Time.now.year && set_term_value(cur_course_term) <= set_term_value(course.term) + str = course.time.to_s + course.term[0] + elsif course.end_time < Time.now.year || (course.end_time == Time.now.year && set_term_value(cur_course_term) >= set_term_value(course.term)) + str = course.end_time.to_s + course.end_term[0] + else + str = Time.now.year.to_s + cur_course_term[0] + end + str + end + # 返回学生数量,即roles表中定义的Reporter #def studentCount project # searchStudent(project).count @@ -840,7 +856,9 @@ module CoursesHelper end def contributor_course_scor(course_id) - ccs = CourseContributorScore.where("course_id =?", course_id).order("total_score desc") .limit(9) + ccs = CourseContributorScore.find_by_sql("SELECT * FROM `course_contributor_scores` where course_id = #{course_id} order by + (message_num*2 + message_reply_num + news_reply_num + news_num + + resource_num*5 + journal_num + homework_journal_num ) desc limit 9;") end end diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index aba2fb58e..6dadf92b5 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -1,153 +1,178 @@ -# encoding: utf-8 -module ExerciseHelper - - # 单选 - def sigle_selection_standard_answer(params) - size = params.ord - 96 - if size > 0 # 小写字母答案 - answer = params.ord - 96 - else - answer = params.ord - 64 - end - end - - # 多选 - def multiselect_standard_answer(params) - size = params.ord - 96 - answer = [] - if size > 0 # 小写字母答案 - for i in 0..(params.length-1) - answer << (params[i].ord - 96).to_s - end - else - for i in 0..(params.length-1) - answer << (params[i].ord - 64) - end - end - answer = answer.sort - answer.join("") - end - - # - def fill_standart_answer(params, standart_answer) - params.each do |param| - standart_answer.answer_text = param.value - standart_answer.save - end - end - - # 获取多选的得分 - def get_mulscore(question, user) - ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) - arr = [] - ecs.each do |ec| - arr << ec.exercise_choice.choice_position - end - #arr = arr.sort - str = arr.sort.join("") - return str - end - - # 判断用户是否已经提交了问卷 - # status 为0的时候是用户点击试卷。为1表示用户已经提交 - def has_commit_exercise?(exercise_id, user_id) - pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, true) - if pu.empty? - false - else - true - end - end - - # 判断学生是否点击过问卷,点击则为他保存一个记录,记录start_at - def has_click_exercise?(exercise_id, user_id) - pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, false) - if pu.empty? - false - else - true - end - end - - def convert_to_char(str) - result = "" - length = str.length - unless str.nil? - if length === 1 - result += (str.to_i + 64).chr - return result - elsif length > 1 - for i in 0...length - result += (str[i].to_i + 64).chr - end - return result - end - end - return result - end - - def get_current_score exercise - score = 0 - unless exercise.nil? - exercise.exercise_questions.each do |exercise_question| - unless exercise_question.question_score.nil? - score += exercise_question.question_score - end - end - return score - end - return score - end - - def answer_be_selected?(answer,user) - pv = answer.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id} ") - if !pv.nil? && pv.count > 0 - true - else - false - end - end - - #获取未完成的题目 - def get_uncomplete_question exercise,user - all_questions = exercise.exercise_questions - uncomplete_question = [] - all_questions.each do |question| - answers = get_user_answer(question, user) - if answers.empty? - uncomplete_question << question - end - end - uncomplete_question - end - - #获取文本题答案 - def get_anwser_vote_text(question_id,user_id) - pv = ExerciseAnswer.find_by_exercise_question_id_and_user_id(question_id,user_id) - if pv.nil? - '' - else - pv.answer_text - end - end - - # 获取当前学生回答问题的答案 - def get_user_answer(question,user) - user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") - user_answer - end - - # 获取问题的标准答案 - def get_user_standard_answer(question,user) - if question.question_type == 3 - standard_answer =[] - question.exercise_standard_answers.each do |answer| - standard_answer << answer.answer_text - end - else - standard_answer = question.exercise_standard_answers - end - standard_answer - end - +# encoding: utf-8 +module ExerciseHelper + + # 单选 + def sigle_selection_standard_answer(params) + size = params.ord - 96 + if size > 0 # 小写字母答案 + answer = params.ord - 96 + else + answer = params.ord - 64 + end + end + + # 多选 + def multiselect_standard_answer(params) + size = params.ord - 96 + answer = [] + if size > 0 # 小写字母答案 + for i in 0..(params.length-1) + answer << (params[i].ord - 96).to_s + end + else + for i in 0..(params.length-1) + answer << (params[i].ord - 64) + end + end + answer = answer.sort + answer.join("") + end + + # + def fill_standart_answer(params, standart_answer) + params.each do |param| + standart_answer.answer_text = param.value + standart_answer.save + end + end + + # 获取多选的得分 + def get_mulscore(question, user) + ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + arr = [] + ecs.each do |ec| + arr << ec.exercise_choice.choice_position + end + #arr = arr.sort + str = arr.sort.join("") + return str + end + + # 判断用户是否已经提交了问卷 + # status 为0的时候是用户点击试卷。为1表示用户已经提交 + def has_commit_exercise?(exercise_id, user_id) + pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, true) + if pu.empty? + false + else + true + end + end + + # 判断学生是否点击过问卷,点击则为他保存一个记录,记录start_at + def has_click_exercise?(exercise_id, user_id) + pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, false) + if pu.empty? + false + else + true + end + end + + def convert_to_char(str) + result = "" + length = str.length + unless str.nil? + if length === 1 + result += (str.to_i + 64).chr + return result + elsif length > 1 + for i in 0...length + result += (str[i].to_i + 64).chr + end + return result + end + end + return result + end + + def convert_to_chi_num num + result = "" + case num.to_i + when 1 + result = '一' + when 2 + result = '二' + when 3 + result = '三' + when 4 + result = '四' + when 5 + result = '五' + when 6 + result = '六' + when 7 + result = '七' + when 8 + result = '八' + when 9 + result = '九' + end + return result + end + + def get_current_score exercise + score = 0 + unless exercise.nil? + exercise.exercise_questions.each do |exercise_question| + unless exercise_question.question_score.nil? + score += exercise_question.question_score + end + end + return score + end + return score + end + + def answer_be_selected?(answer,user) + pv = answer.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id} ") + if !pv.nil? && pv.count > 0 + true + else + false + end + end + + #获取未完成的题目 + def get_uncomplete_question exercise,user + all_questions = exercise.exercise_questions + uncomplete_question = [] + all_questions.each do |question| + answers = get_user_answer(question, user) + if answers.empty? + uncomplete_question << question + end + end + uncomplete_question + end + + #获取文本题答案 + def get_anwser_vote_text(question_id,user_id) + pv = ExerciseAnswer.find_by_exercise_question_id_and_user_id(question_id,user_id) + if pv.nil? + '' + else + pv.answer_text + end + end + + # 获取当前学生回答问题的答案 + def get_user_answer(question,user) + user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") + user_answer + end + + # 获取问题的标准答案 + def get_user_standard_answer(question,user) + if question.question_type == 3 + standard_answer =[] + question.exercise_standard_answers.each do |answer| + standard_answer << answer.answer_text + end + else + standard_answer = question.exercise_standard_answers + end + standard_answer + end + end \ No newline at end of file diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 412c3f889..4ad3cb49d 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -1,463 +1,463 @@ -# encoding: utf-8 -# -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -module IssuesHelper - include ApplicationHelper - - def issue_list(issues, &block) - ancestors = [] - issues.each do |issue| - while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) - ancestors.pop - end - yield issue, ancestors.size - ancestors << issue unless issue.leaf? - end - end - - # Renders a HTML/CSS tooltip - # - # To use, a trigger div is needed. This is a div with the class of "tooltip" - # that contains this method wrapped in a span with the class of "tip" - # - #
<%= link_to_issue(issue) %> - # <%= render_issue_tooltip(issue) %> - #
- # - def render_issue_tooltip(issue) - @cached_label_status ||= l(:field_status) - @cached_label_start_date ||= l(:field_start_date) - @cached_label_due_date ||= l(:field_due_date) - @cached_label_assigned_to ||= l(:field_assigned_to) - @cached_label_priority ||= l(:field_priority) - @cached_label_project ||= l(:field_project) - - link_to_issue(issue) + "

".html_safe + - "#{@cached_label_project}: #{link_to_project(issue.project)}
".html_safe + - "#{@cached_label_status}: #{h(issue.status.name)}
".html_safe + - "#{@cached_label_start_date}: #{format_date(issue.start_date)}
".html_safe + - "#{@cached_label_due_date}: #{format_date(issue.due_date)}
".html_safe + - "#{@cached_label_assigned_to}: #{h(issue.assigned_to)}
".html_safe + - "#{@cached_label_priority}: #{h(issue.priority.name)}".html_safe - end - - def issue_heading(issue) - #h("#{issue.tracker} ##{issue.id}") - # h("#{issue.tracker} #{issue.source_from}") - s = '' - s << link_to(@issue.project.name, project_issues_path(@issue.project), :class => "pro_page_top") - s << " > " - s << link_to("#" + @issue.project_index, project_issues_path(@issue.project), :class => "pro_page_top") - s.html_safe - end - - #获取跟踪类型及样式 - def get_issue_type(value) - issuetype = [] - if value == "缺陷" || value == 1 - issuetype << "issues fl" - issuetype << "缺陷" - elsif value == "任务" || value == 4 - issuetype << "duty fl" - issuetype << "任务" - elsif value == "支持" || value == 3 - issuetype << "support fl" - issuetype << "支持" - elsif value == "功能" || value == 2 - issuetype << "function fl" - issuetype << "功能" - else - issuetype << "weekly fl" - issuetype << "周报" - end - end - - # 获取优先级样式 value值1 2 低 - def get_issue_priority(value) - issuetype = [] - if value == "紧急" || value == 4 - issuetype << "red_btn_cir ml10" - issuetype << "紧急" - elsif value == "正常" || value == 2 - issuetype << "green_btn_cir ml10" - issuetype << "正常" - elsif value == "高" || value == 3 - issuetype << "orange_btn_cir ml10" - issuetype << "高" - elsif value == "低" || value == 1 - issuetype << "bgreen_btn_cir ml10" - issuetype << "低" - else - issuetype << "red_btn_cir ml10" - issuetype << "立刻" - end - end - - def principals_options_for_isuue_list(project) - if User.current.member_of?(project) - project.members.order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["<< #{l(:label_me)} >>", User.current.id]).unshift(["指派给", 0]) - else - project.members.order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["指派给", 0]) - end - end - - def render_issue_subject_with_tree(issue) - s = '' - ancestors = issue.root? ? [] : issue.ancestors.visible.all - ancestors.each do |ancestor| - s << '
' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) - end - s << '
' - subject = h(issue.subject) - if issue.is_private? - subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject - end - s << content_tag('h3', subject) - s << '
' * (ancestors.size + 1) - s.html_safe - end - - def render_descendants_tree(issue) - s = '
' - issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| - css = "issue issue-#{child.id} hascontextmenu" - css << " idnt idnt-#{level}" if level > 0 - s << content_tag('tr', - content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + - content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') + - content_tag('td', h(child.status)) + - content_tag('td', link_to_user(child.assigned_to)) + - content_tag('td', progress_bar(child.done_ratio, :width => '80px')), - :class => css) - end - s << '
' - s.html_safe - end - - # Returns a link for adding a new subtask to the given issue - def link_to_new_subtask(issue) - attrs = { - :tracker_id => issue.tracker, - :parent_issue_id => issue - } - link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) - end - - class IssueFieldsRows - include ActionView::Helpers::TagHelper - - def initialize - @left = [] - @right = [] - end - - def left(*args) - args.any? ? @left << cells(*args) : @left - end - - def right(*args) - args.any? ? @right << cells(*args) : @right - end - - def size - @left.size > @right.size ? @left.size : @right.size - end - - def to_html - html = ''.html_safe - blank = content_tag('th', '') + content_tag('td', '') - size.times do |i| - left = @left[i] || blank - right = @right[i] || blank - html << content_tag('tr', left + right) - end - html - end - - def cells(label, text, options={}) - content_tag('th', "#{label}:", options) + content_tag('td', text, options) - end - end - - def issue_fields_rows - r = IssueFieldsRows.new - yield r - r.to_html - end - - def render_custom_fields_rows(issue) - return if issue.custom_field_values.empty? - ordered_values = [] - half = (issue.custom_field_values.size / 2.0).ceil - half.times do |i| - ordered_values << issue.custom_field_values[i] - ordered_values << issue.custom_field_values[i + half] - end - s = "\n" - n = 0 - ordered_values.compact.each do |value| - s << "\n\n" if n > 0 && (n % 2) == 0 - s << "\t#{ h(value.custom_field.name) }:#{ simple_format_without_paragraph(h(show_value(value))) }\n" - n += 1 - end - s << "\n" - s.html_safe - end - - def issues_destroy_confirmation_message(issues) - issues = [issues] unless issues.is_a?(Array) - message = l(:text_issues_destroy_confirmation) - descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} - if descendant_count > 0 - issues.each do |issue| - next if issue.root? - issues.each do |other_issue| - descendant_count -= 1 if issue.is_descendant_of?(other_issue) - end - end - if descendant_count > 0 - message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) - end - end - message - end - - def sidebar_queries - unless @sidebar_queries - @sidebar_queries = IssueQuery.visible.all( - :order => "#{Query.table_name}.name ASC", - # Project specific queries and global queries - :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) - ) - end - @sidebar_queries - end - - def query_links(title, queries) - # links to #index on issues/show - url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params - - content_tag('h3', h(title)) + - queries.collect {|query| - css = 'query' - css << ' selected' if query == @query - link_to(h(query.name), url_params.merge(:query_id => query), :class => css) - }.join('
').html_safe - end - - def render_sidebar_queries - out = ''.html_safe - queries = sidebar_queries.select {|q| !q.is_public?} - out << query_links(l(:label_my_queries), queries) if queries.any? - queries = sidebar_queries.select {|q| q.is_public?} - out << query_links(l(:label_query_plural), queries) if queries.any? - out - end - - # Returns the textual representation of a journal details - # as an array of strings - def details_to_strings(details, no_html=false, options={}) - options[:only_path] = (options[:only_path] == false ? false : true) - options[:token] = options[:token] if options[:token] - strings = [] - values_by_field = {} - details.each do |detail| - - if detail.property == 'cf' - field_id = detail.prop_key - field = CustomField.find_by_id(field_id) - if field && field.multiple? - values_by_field[field_id] ||= {:added => [], :deleted => []} - if detail.old_value - values_by_field[field_id][:deleted] << detail.old_value - end - if detail.value - values_by_field[field_id][:added] << detail.value - end - next - end - end - strings << show_detail(detail, no_html, options) - - end - values_by_field.each do |field_id, changes| - detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) - if changes[:added].any? - detail.value = changes[:added] - strings << show_detail(detail, no_html, options) - elsif changes[:deleted].any? - detail.old_value = changes[:deleted] - strings << show_detail(detail, no_html, options) - end - end - strings - end - - # Returns the textual representation of a single journal detail - def show_detail(detail, no_html=false, options={}) - multiple = false - case detail.property - when 'attr' - field = detail.prop_key.to_s.gsub(/\_id$/, "") - label = l(("field_" + field).to_sym) - case detail.prop_key - when 'due_date', 'start_date' - value = format_date(detail.value.to_date) if detail.value - old_value = format_date(detail.old_value.to_date) if detail.old_value - - when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', - 'priority_id', 'category_id', 'fixed_version_id' - value = find_name_by_reflection(field, detail.value) - old_value = find_name_by_reflection(field, detail.old_value) - - when 'estimated_hours' - value = "%0.02f" % detail.value.to_f unless detail.value.blank? - old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? - - when 'parent_id' - label = l(:field_parent_issue) - value = "##{detail.value}" unless detail.value.blank? - old_value = "##{detail.old_value}" unless detail.old_value.blank? - - when 'is_private' - value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? - old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? - end - when 'cf' - custom_field = CustomField.find_by_id(detail.prop_key) - if custom_field - multiple = custom_field.multiple? - label = custom_field.name - value = format_value(detail.value, custom_field.field_format) if detail.value - old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value - end - when 'attachment' - label = l(:label_attachment) - end - call_hook(:helper_issues_show_detail_after_setting, - {:detail => detail, :label => label, :value => value, :old_value => old_value }) - - label ||= detail.prop_key - value ||= detail.value - old_value ||= detail.old_value - - unless no_html - label = content_tag('strong', label) - old_value = content_tag("i", h(old_value)) if detail.old_value - old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? - if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) - # Link to the attachment if it has not been removed - if options[:token].nil? - value = atta.filename - else - value = atta.filename - end - # 放大镜搜索功能 - # if options[:only_path] != false && atta.is_text? - # value += link_to( - # image_tag('magnifier.png'), - # :controller => 'attachments', :action => 'show', - # :id => atta, :filename => atta.filename - # ) - # end - else - value = content_tag("i", h(value)) if value - end - end - # 缺陷更新结果在消息中显示样式 - if no_html == "message" - label = content_tag(:span, label, :class => "issue_update_message") - old_value = content_tag("span", h(old_value)) if detail.old_value - old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? - if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) - # Link to the attachment if it has not been removed - if options[:token].nil? - value = atta.filename - else - value = atta.filename - end - else - value = content_tag(:span, h(value), :class => "issue_update_message_value") if value - end - end - - if detail.property == 'attr' && detail.prop_key == 'description' - s = l(:text_journal_changed_no_detail, :label => label) - unless no_html - diff_link = link_to l(:label_diff), - {:controller => 'journals', :action => 'diff', :id => detail.journal_id, - :detail_id => detail.id, :only_path => options[:only_path]}, - :title => l(:label_view_diff) - s << " (#{ diff_link })" - end - s.html_safe - elsif detail.value.present? - case detail.property - when 'attr', 'cf' - if detail.old_value.present? - l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe - elsif multiple - l(:text_journal_added, :label => label, :value => value).html_safe - else - l(:text_journal_set_to, :label => label, :value => value).html_safe - end - when 'attachment' - l(:text_journal_added, :label => label, :value => value).html_safe - end - else - l(:text_journal_deleted, :label => label, :old => old_value).html_safe - end - end - - # Find the name of an associated record stored in the field attribute - def find_name_by_reflection(field, id) - unless id.present? - return nil - end - association = Issue.reflect_on_association(field.to_sym) - if association - record = association.class_name.constantize.find_by_id(id) - if record - record.name.force_encoding('UTF-8') if record.name.respond_to?(:force_encoding) - return record.name - end - end - end - - # Renders issue children recursively - def render_api_issue_children(issue, api) - return if issue.leaf? - api.array :children do - issue.children.each do |child| - api.issue(:id => child.id) do - api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? - api.subject child.subject - render_api_issue_children(child, api) - end - end - end - end - - # this method is used to get all projects that tagged one tag - # added by william - def get_issues_by_tag(tag_name) - Issue.tagged_with(tag_name).order('updated_on desc') - end - -end +# encoding: utf-8 +# +# Redmine - project management software +# Copyright (C) 2006-2013 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module IssuesHelper + include ApplicationHelper + + def issue_list(issues, &block) + ancestors = [] + issues.each do |issue| + while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) + ancestors.pop + end + yield issue, ancestors.size + ancestors << issue unless issue.leaf? + end + end + + # Renders a HTML/CSS tooltip + # + # To use, a trigger div is needed. This is a div with the class of "tooltip" + # that contains this method wrapped in a span with the class of "tip" + # + #
<%= link_to_issue(issue) %> + # <%= render_issue_tooltip(issue) %> + #
+ # + def render_issue_tooltip(issue) + @cached_label_status ||= l(:field_status) + @cached_label_start_date ||= l(:field_start_date) + @cached_label_due_date ||= l(:field_due_date) + @cached_label_assigned_to ||= l(:field_assigned_to) + @cached_label_priority ||= l(:field_priority) + @cached_label_project ||= l(:field_project) + + link_to_issue(issue) + "

".html_safe + + "#{@cached_label_project}: #{link_to_project(issue.project)}
".html_safe + + "#{@cached_label_status}: #{h(issue.status.name)}
".html_safe + + "#{@cached_label_start_date}: #{format_date(issue.start_date)}
".html_safe + + "#{@cached_label_due_date}: #{format_date(issue.due_date)}
".html_safe + + "#{@cached_label_assigned_to}: #{h(issue.assigned_to)}
".html_safe + + "#{@cached_label_priority}: #{h(issue.priority.name)}".html_safe + end + + def issue_heading(issue) + #h("#{issue.tracker} ##{issue.id}") + # h("#{issue.tracker} #{issue.source_from}") + s = '' + s << link_to(@issue.project.name, project_issues_path(@issue.project), :class => "pro_page_top") + s << " > " + s << link_to("#" + @issue.project_index, project_issues_path(@issue.project), :class => "pro_page_top") + s.html_safe + end + + #获取跟踪类型及样式 + def get_issue_type(value) + issuetype = [] + if value == "缺陷" || value == 1 + issuetype << "issues fl" + issuetype << "缺陷" + elsif value == "任务" || value == 4 + issuetype << "duty fl" + issuetype << "任务" + elsif value == "支持" || value == 3 + issuetype << "support fl" + issuetype << "支持" + elsif value == "功能" || value == 2 + issuetype << "issues-function fl" + issuetype << "功能" + else + issuetype << "weekly fl" + issuetype << "周报" + end + end + + # 获取优先级样式 value值1 2 低 + def get_issue_priority(value) + issuetype = [] + if value == "紧急" || value == 4 + issuetype << "red_btn_cir ml10" + issuetype << "紧急" + elsif value == "正常" || value == 2 + issuetype << "green_btn_cir ml10" + issuetype << "正常" + elsif value == "高" || value == 3 + issuetype << "orange_btn_cir ml10" + issuetype << "高" + elsif value == "低" || value == 1 + issuetype << "bgreen_btn_cir ml10" + issuetype << "低" + else + issuetype << "red_btn_cir ml10" + issuetype << "立刻" + end + end + + def principals_options_for_isuue_list(project) + if User.current.member_of?(project) + project.members.order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["<< #{l(:label_me)} >>", User.current.id]).unshift(["指派给", 0]) + else + project.members.order("lower(users.login)").map{|c| [c.name, c.user_id]}.unshift(["指派给", 0]) + end + end + + def render_issue_subject_with_tree(issue) + s = '' + ancestors = issue.root? ? [] : issue.ancestors.visible.all + ancestors.each do |ancestor| + s << '
' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) + end + s << '
' + subject = h(issue.subject) + if issue.is_private? + subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject + end + s << content_tag('h3', subject) + s << '
' * (ancestors.size + 1) + s.html_safe + end + + def render_descendants_tree(issue) + s = '
' + issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| + css = "issue issue-#{child.id} hascontextmenu" + css << " idnt idnt-#{level}" if level > 0 + s << content_tag('tr', + content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + + content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') + + content_tag('td', h(child.status)) + + content_tag('td', link_to_user(child.assigned_to)) + + content_tag('td', progress_bar(child.done_ratio, :width => '80px')), + :class => css) + end + s << '
' + s.html_safe + end + + # Returns a link for adding a new subtask to the given issue + def link_to_new_subtask(issue) + attrs = { + :tracker_id => issue.tracker, + :parent_issue_id => issue + } + link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) + end + + class IssueFieldsRows + include ActionView::Helpers::TagHelper + + def initialize + @left = [] + @right = [] + end + + def left(*args) + args.any? ? @left << cells(*args) : @left + end + + def right(*args) + args.any? ? @right << cells(*args) : @right + end + + def size + @left.size > @right.size ? @left.size : @right.size + end + + def to_html + html = ''.html_safe + blank = content_tag('th', '') + content_tag('td', '') + size.times do |i| + left = @left[i] || blank + right = @right[i] || blank + html << content_tag('tr', left + right) + end + html + end + + def cells(label, text, options={}) + content_tag('th', "#{label}:", options) + content_tag('td', text, options) + end + end + + def issue_fields_rows + r = IssueFieldsRows.new + yield r + r.to_html + end + + def render_custom_fields_rows(issue) + return if issue.custom_field_values.empty? + ordered_values = [] + half = (issue.custom_field_values.size / 2.0).ceil + half.times do |i| + ordered_values << issue.custom_field_values[i] + ordered_values << issue.custom_field_values[i + half] + end + s = "\n" + n = 0 + ordered_values.compact.each do |value| + s << "\n\n" if n > 0 && (n % 2) == 0 + s << "\t#{ h(value.custom_field.name) }:#{ simple_format_without_paragraph(h(show_value(value))) }\n" + n += 1 + end + s << "\n" + s.html_safe + end + + def issues_destroy_confirmation_message(issues) + issues = [issues] unless issues.is_a?(Array) + message = l(:text_issues_destroy_confirmation) + descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} + if descendant_count > 0 + issues.each do |issue| + next if issue.root? + issues.each do |other_issue| + descendant_count -= 1 if issue.is_descendant_of?(other_issue) + end + end + if descendant_count > 0 + message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) + end + end + message + end + + def sidebar_queries + unless @sidebar_queries + @sidebar_queries = IssueQuery.visible.all( + :order => "#{Query.table_name}.name ASC", + # Project specific queries and global queries + :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) + ) + end + @sidebar_queries + end + + def query_links(title, queries) + # links to #index on issues/show + url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params + + content_tag('h3', h(title)) + + queries.collect {|query| + css = 'query' + css << ' selected' if query == @query + link_to(h(query.name), url_params.merge(:query_id => query), :class => css) + }.join('
').html_safe + end + + def render_sidebar_queries + out = ''.html_safe + queries = sidebar_queries.select {|q| !q.is_public?} + out << query_links(l(:label_my_queries), queries) if queries.any? + queries = sidebar_queries.select {|q| q.is_public?} + out << query_links(l(:label_query_plural), queries) if queries.any? + out + end + + # Returns the textual representation of a journal details + # as an array of strings + def details_to_strings(details, no_html=false, options={}) + options[:only_path] = (options[:only_path] == false ? false : true) + options[:token] = options[:token] if options[:token] + strings = [] + values_by_field = {} + details.each do |detail| + + if detail.property == 'cf' + field_id = detail.prop_key + field = CustomField.find_by_id(field_id) + if field && field.multiple? + values_by_field[field_id] ||= {:added => [], :deleted => []} + if detail.old_value + values_by_field[field_id][:deleted] << detail.old_value + end + if detail.value + values_by_field[field_id][:added] << detail.value + end + next + end + end + strings << show_detail(detail, no_html, options) + + end + values_by_field.each do |field_id, changes| + detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) + if changes[:added].any? + detail.value = changes[:added] + strings << show_detail(detail, no_html, options) + elsif changes[:deleted].any? + detail.old_value = changes[:deleted] + strings << show_detail(detail, no_html, options) + end + end + strings + end + + # Returns the textual representation of a single journal detail + def show_detail(detail, no_html=false, options={}) + multiple = false + case detail.property + when 'attr' + field = detail.prop_key.to_s.gsub(/\_id$/, "") + label = l(("field_" + field).to_sym) + case detail.prop_key + when 'due_date', 'start_date' + value = format_date(detail.value.to_date) if detail.value + old_value = format_date(detail.old_value.to_date) if detail.old_value + + when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', + 'priority_id', 'category_id', 'fixed_version_id' + value = find_name_by_reflection(field, detail.value) + old_value = find_name_by_reflection(field, detail.old_value) + + when 'estimated_hours' + value = "%0.02f" % detail.value.to_f unless detail.value.blank? + old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? + + when 'parent_id' + label = l(:field_parent_issue) + value = "##{detail.value}" unless detail.value.blank? + old_value = "##{detail.old_value}" unless detail.old_value.blank? + + when 'is_private' + value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? + old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? + end + when 'cf' + custom_field = CustomField.find_by_id(detail.prop_key) + if custom_field + multiple = custom_field.multiple? + label = custom_field.name + value = format_value(detail.value, custom_field.field_format) if detail.value + old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value + end + when 'attachment' + label = l(:label_attachment) + end + call_hook(:helper_issues_show_detail_after_setting, + {:detail => detail, :label => label, :value => value, :old_value => old_value }) + + label ||= detail.prop_key + value ||= detail.value + old_value ||= detail.old_value + + unless no_html + label = content_tag('strong', label) + old_value = content_tag("i", h(old_value)) if detail.old_value + old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? + if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) + # Link to the attachment if it has not been removed + if options[:token].nil? + value = atta.filename + else + value = atta.filename + end + # 放大镜搜索功能 + # if options[:only_path] != false && atta.is_text? + # value += link_to( + # image_tag('magnifier.png'), + # :controller => 'attachments', :action => 'show', + # :id => atta, :filename => atta.filename + # ) + # end + else + value = content_tag("i", h(value)) if value + end + end + # 缺陷更新结果在消息中显示样式 + if no_html == "message" + label = content_tag(:span, label, :class => "issue_update_message") + old_value = content_tag("span", h(old_value)) if detail.old_value + old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? + if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) + # Link to the attachment if it has not been removed + if options[:token].nil? + value = atta.filename + else + value = atta.filename + end + else + value = content_tag(:span, h(value), :class => "issue_update_message_value") if value + end + end + + if detail.property == 'attr' && detail.prop_key == 'description' + s = l(:text_journal_changed_no_detail, :label => label) + unless no_html + diff_link = link_to l(:label_diff), + {:controller => 'journals', :action => 'diff', :id => detail.journal_id, + :detail_id => detail.id, :only_path => options[:only_path]}, + :title => l(:label_view_diff) + s << " (#{ diff_link })" + end + s.html_safe + elsif detail.value.present? + case detail.property + when 'attr', 'cf' + if detail.old_value.present? + l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe + elsif multiple + l(:text_journal_added, :label => label, :value => value).html_safe + else + l(:text_journal_set_to, :label => label, :value => value).html_safe + end + when 'attachment' + l(:text_journal_added, :label => label, :value => value).html_safe + end + else + l(:text_journal_deleted, :label => label, :old => old_value).html_safe + end + end + + # Find the name of an associated record stored in the field attribute + def find_name_by_reflection(field, id) + unless id.present? + return nil + end + association = Issue.reflect_on_association(field.to_sym) + if association + record = association.class_name.constantize.find_by_id(id) + if record + record.name.force_encoding('UTF-8') if record.name.respond_to?(:force_encoding) + return record.name + end + end + end + + # Renders issue children recursively + def render_api_issue_children(issue, api) + return if issue.leaf? + api.array :children do + issue.children.each do |child| + api.issue(:id => child.id) do + api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? + api.subject child.subject + render_api_issue_children(child, api) + end + end + end + end + + # this method is used to get all projects that tagged one tag + # added by william + def get_issues_by_tag(tag_name) + Issue.tagged_with(tag_name).order('updated_on desc') + end + +end diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index ff4aa61fb..36187b460 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -41,6 +41,16 @@ module RepositoriesHelper identifiers.include?(iden) ? false :true end + # 获取diff内容行号 + def diff_line_num content + content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i + end + + # 处理内容 + def diff_content content + content.gsub!(/.*@@ -\d+,\d+ \+\d+,\d+ @@\n/m,'') + end + def format_revision(revision) if revision.respond_to? :format_identifier revision.format_identifier diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 4edfed578..44b919121 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,604 +1,676 @@ -# encoding: utf-8 -# -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - - -include AvatarHelper -module UsersHelper - def users_status_options_for_select(selected) - user_count_by_status = User.count(:group => 'status').to_hash - options_for_select([[l(:label_all), ''], - ["#{l(:status_active)} (#{user_count_by_status[1].to_i})", '1'], - ["#{l(:status_registered)} (#{user_count_by_status[2].to_i})", '2'], - ["#{l(:status_locked)} (#{user_count_by_status[3].to_i})", '3']], selected.to_s) - end - - def get_resource_type type - case type - when 'Course' - '课程资源' - when 'Project' - '项目资源' - when 'Issue' - '缺陷附件' - when 'Message' - '讨论区附件' - when 'Document' - '文档附件' - when 'News' - '通知附件' - when 'HomewCommon' - '作业附件' - when 'StudentWorkScore' - '批改附件' - when 'Principal' - '用户资源' - when 'OrgSubfield' - '组织资源' - end - end - - def title_for_message type - case type - when nil - '消息' - when 'unviewed' - '未读消息' - when 'apply' - '用户申请' - when 'system_messages' - '系统消息' - when 'homework' - '作业消息' - when 'course_message' - '课程讨论' - when 'course_news' - '课程通知' - when 'poll' - '课程问卷' - when 'issue' - '项目任务' - when 'forge_message' - '项目讨论' - when 'forge_news' - '项目新闻' - when 'forum' - '贴吧帖子' - when 'user_feedback' - '用户留言' - end - end - - # 统计未读消息数 - def unviewed_message(user) - course_count = CourseMessage.where("user_id =? and viewed =?", user, 0).count - forge_count = ForgeMessage.where("user_id =? and viewed =?", user, 0).count - org_count = OrgMessage.where("user_id =? and viewed =?", user, 0).count - user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count - user_memo_count = MemoMessage.where("user_id =? and viewed =?", user, 0).count - at_count = user.at_messages.where(viewed: false).count - messages_count = course_count + forge_count + user_feedback_count + user_memo_count + at_count + org_count - end - - def user_mail_notification_options(user) - user.valid_notification_options.collect {|o| [l(o.last), o.first]} - end - - def change_status_link(user) - url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil} - - if user.locked? - link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock' - elsif user.registered? - link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock' - elsif user != User.current - link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'icon icon-lock' - end - end - - def user_settings_tabs - tabs = [{:name => 'general', :partial => 'users/general', :label => :label_general}, - {:name => 'memberships', :partial => 'users/memberships', :label => :label_project_plural} - ] - if Group.all.any? - tabs.insert 1, {:name => 'groups', :partial => 'users/groups', :label => :label_group_plural} - end - tabs - end - - # this method is used to get all projects that tagged one tag - # added by william - def get_users_by_tag(tag_name) - User.tagged_with(tag_name).order('updated_on desc') - end - - # added by fq - # - - # TODO: 待删 - # def show_activity(state) - # content = ''.html_safe - # case state - # when 0 - # s = content_tag('span', l(:label_user_all_activity), :class => "current-page") - # content << content_tag('li', s) - # content << content_tag('li', link_to(l(:label_user_activity_myself), {:controller => 'users', :action => 'show', :type => 1})) - # content << content_tag('li', link_to(l(:label_user_all_respond), {:controller => 'users', :action => 'show', :type => 2})) - # when 1 - # s = content_tag('span', l(:label_user_activity_myself), :class => "current-page") - # content << content_tag('li', link_to(l(:label_user_all_activity), {:controller => 'users', :action => 'show'})) - # content << content_tag('li', s, :class => "current-page") - # content << content_tag('li', link_to(l(:label_user_all_respond), {:controller => 'users', :action => 'show', :type => 2})) - # when 2 - # s = content_tag('span', l(:label_user_all_respond), :class => "current-page") - # content << content_tag('li', link_to(l(:label_user_all_activity), {:controller => 'users', :action => 'show'})) - # content << content_tag('li', link_to(l(:label_user_activity_myself), {:controller => 'users', :action => 'show', :type => 1})) - # content << content_tag('li', s, :class => "current-page") - # end - # content_tag('div', content, :class => "pagination") - # end - - #TODO: 待删 - def watch_projects(state) - content = ''.html_safe - case state - when 0 - s = content_tag('span', l(:label_project_take), :class => "current-page") - content << content_tag('li', s) - content << content_tag('li', link_to(l(:label_has_watched_project), {:controller => 'users', :action => 'watch_projects', :type => 1})) - when 1 - s = content_tag('span', l(:label_has_watched_project), :class => "current-page") - content << content_tag('li', link_to(l(:label_project_take), {:controller => 'users', :action => 'user_projects'})) - content << content_tag('li', s, :class => "current-page") - end - content_tag('div', content, :class => "pagination") - end - - def user_course(state) - content = ''.html_safe - if @user != User.current - if @user.user_extensions.identity == 0 - case state - when 0 - s = content_tag('span', '他执教的课程', :class => "current-page") - content << content_tag('li', s) - content << content_tag('li', link_to('他发布的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) - content_tag('div', content, :class => "pagination") - when 1 - s = content_tag('span', '他发布的作业', :class => "current-page") - content << content_tag('li', link_to('他执教的课程', {:controller => 'users', :action => 'user_courses'})) - content << content_tag('li', s, :class => "current-page") - content_tag('div', content, :class => "pagination") - end - else - case state - when 0 - s = content_tag('span', '他的课程', :class => "current-page") - content << content_tag('li', s) - content << content_tag('li', link_to('他的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) - content_tag('div', content, :class => "pagination") - when 1 - s = content_tag('span', '他的作业', :class => "current-page") - content << content_tag('li', link_to('他的课程', {:controller => 'users', :action => 'user_courses', :type => 0})) - content << content_tag('li', s, :class => "current-page") - content_tag('div', content, :class => "pagination") - end - end - else - if @user.user_extensions.identity == 0 - case state - when 0 - s = content_tag('span', l(:label_teaching_course), :class => "current-page") - content << content_tag('li', s) - content << content_tag('li', link_to(l(:label_release_homework), {:controller => 'users', :action => 'user_courses', :type => 1})) - content_tag('div', content, :class => "pagination") - when 1 - s = content_tag('span', l(:label_release_homework), :class => "current-page") - content << content_tag('li', link_to(l(:label_teaching_course), {:controller => 'users', :action => 'user_courses'})) - content << content_tag('li', s, :class => "current-page") - content_tag('div', content, :class => "pagination") - end - else - case state - when 0 - s = content_tag('span', l(:label_my_course), :class => "current-page") - content << content_tag('li', s) - content << content_tag('li', link_to('我的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) - content_tag('div', content, :class => "pagination") - when 1 - s = content_tag('span', '我的作业', :class => "current-page") - content << content_tag('li', link_to(l(:label_my_course), {:controller => 'users', :action => 'user_courses', :type => 0})) - content << content_tag('li', s, :class => "current-page") - content_tag('div', content, :class => "pagination") - end - end - end - end - - # added by huang - def sort_user(state, project_type) - content = ''.html_safe - case state - when 0 - content << content_tag('li', link_to(l(:label_sort_by_active), users_path(params.merge({:user_sort_type => '1', :project_type => project_type}) ))) - content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(params.merge({:user_sort_type => '2', :project_type => project_type}) ))) - content << content_tag('li', link_to(l(:label_sort_by_time), users_path(params.merge({:user_sort_type => '0', :project_type => project_type}) ), :class=>"selected") ) - when 1 - content << content_tag('li', link_to(l(:label_sort_by_active), users_path(params.merge({:user_sort_type => '1', :project_type => project_type}) ), :class=>"selected") ) - content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(params.merge({:user_sort_type => '2', :project_type => project_type}) ))) - content << content_tag('li', link_to(l(:label_sort_by_time), users_path(params.merge({:user_sort_type => '0', :project_type => project_type}) ))) - when 2 - content << content_tag('li', link_to(l(:label_sort_by_active), users_path(params.merge({:user_sort_type => '1', :project_type => project_type}) ))) - content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(params.merge({:user_sort_type => '2', :project_type => project_type}) ), :class=>"selected") ) - content << content_tag('li', link_to(l(:label_sort_by_time), users_path(params.merge({:user_sort_type => '0', :project_type => project_type}) ))) - end - content = content_tag('ul', content) - content_tag('div', content, :class => "tabs") - end - - def sort_user_enterprise(state, project_type) - content = ''.html_safe - case state - when 0 - content << content_tag('li', link_to(l(:label_sort_by_active), users_path(:user_sort_type => '1', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(:user_sort_type => '2', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_time), users_path(:user_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected") - when 1 - content << content_tag('li', link_to(l(:label_sort_by_active), users_path(:user_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(:user_sort_type => '2', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_time), users_path(:user_sort_type => '0', :project_type => project_type))) - when 2 - content << content_tag('li', link_to(l(:label_sort_by_active), users_path(:user_sort_type => '1', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(:user_sort_type => '2', :project_type => project_type), :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_time), users_path(:user_sort_type => '0', :project_type => project_type))) - end - content = content_tag('ul', content) - content_tag('div', content, :class => "tabs_enterprise") - end - - def gender_avatar_uri user - img_uri = '/images/sidebar/female.png' - return img_uri if user.user_extensions.blank? - person_gender = user.user_extensions.gender - img_uri = (person_gender == 1) ? '/images/sidebar/female.png' : '/images/sidebar/male.png' - end - - include CoursesHelper - def is_watching?(user) - login_user = User.current# 登录者 - - courses = user.projects.where('project_type=1') - return true if ((login_user == user) or login_user.admin?) - courses.each do |course| - return true if login_user.member_of?(course) - end - ## 下面的代码只判断是否是老师或者助教,上面是成员都可以看到 - # people_ids = [] - # user.projects.where('project_type=1').each do |project| - # tmp = searchTeacherAndAssistant(project) - # people_ids += (members_to_user_ids(tmp)) unless tmp.nil? - # end - # people_ids.include?(login_user.id) or (login_user == user) or login_user.admin? - - false - end - - # base user上面的navbar显示内容 - def show_item_on_navbar params - displayed_item = %w|index| - displayed_item.include?(params['action']) - end - # base user上面searchBar显示 - def show_search_bar params - displayed_flag = %w|index| - !displayed_flag.include?(params['action']) - end - - #获取指定用户的未过期的课程列表 - def user_courses_list user - result = [] - user.coursememberships.map(&:course).each do |course| - if !course_endTime_timeout?(course) - result << course - end - end - return result - end - - #获取用户参与的公开的课程列表 - def user_public_course_list user - membership = user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current)) - membership.sort! {|older, newer| newer.created_on <=> older.created_on } - memberships = [] - membership.collect { |e| - memberships.push(e) - } - ## 判断课程是否过期 [需封装] - memberships_doing = [] - memberships_done = [] - memberships.map { |e| - if course_endTime_timeout?(e.course) - memberships_done.push e - else - memberships_doing.push e - end - } - end - - #获取用户留言相关的连接 - def user_jour_feed_back_url active - if active.act_type == "JournalsForMessage" - jour = JournalsForMessage.find active.act_id - if jour - case jour.jour_type - when "Principal" - link_to(l(:label_goto), user_newfeedback_user_path(jour.jour_id)) - when "Project" - link_to(l(:label_goto), project_feedback_path(jour.jour_id)) - when "Bid" - link_to(l(:label_goto), course_for_bid_path(jour.jour_id)) - when "Course" - link_to(l(:label_goto), course_feedback_path(jour.jour_id)) - when "Contest" - link_to(l(:label_goto), show_contest_contest_path(jour.jour_id)) - when "Softapplication" - link_to(l(:label_goto), softapplication_path(jour.jour_id)) - when "HomeworkAttach" - link_to(l(:label_goto), course_for_bid_path(jour.jour_id)) - end - end - end - end - - def get_watcher_users(obj) - count = User.watched_by(obj.id).count - if count == 0 - return [0,[]] - end - list = User.watched_by(obj.id).order("#{Watcher.table_name}.id desc").limit(10).all - return [count,list]; - end - - def get_fans_users(obj) - count = obj.watcher_users.count - if count == 0 - return [0,[]] - end - list = obj.watcher_users.order("#{Watcher.table_name}.id desc").limit(10).all - return [count,list]; - end - - def get_visitor_users(obj) - query = Visitor.where("master_id=?",obj.id) - count = query.count - if count == 0 - return [0,[]] - end - list = query.order("updated_on desc").limit(10).all - return [count,list] - end - - def get_create_course_count(user) - user.courses.visible.where("tea_id = ?",user.id).count - end - - #获取加入课程数 - def get_join_course_count(user) - user.courses.visible.count - get_create_course_count(user) - end - - #发布作业数 - def get_homework_commons_count(user) - HomeworkCommon.where("user_id = ?",user.id).count - end - - #资源数 - def get_projectandcourse_attachment_count(user) - Attachment.where("author_id = ? and container_type in ('Project','Course')",user.id).count - end - - #创建项目数 - def get_create_project_count(user) - user.projects.visible.where("projects.user_id=#{user.id}").count - end - - #加入项目数 - def get_join_project_count(user) - user.projects.visible.count - get_create_project_count(user) - end - - #创建缺陷数 - def get_create_issue_count(user) - Issue.where("author_id = ?",user.id).count - end - - #解决缺陷数 - def get_resolve_issue_count(user) - Issue.where("assigned_to_id = ? and status_id=3",user.id).count - end - - #参与匿评数 - def get_anonymous_evaluation_count(user) - StudentWorksScore.where("user_id = ? and reviewer_role=3",user.id).count - end - - def query_activities(query) - list = query.limit(13).all - result = [] - for item in list - container = get_activity_container(item) - result << { :item=>item,:e=>container } - end - result - end - - def get_activity_container activity - return activity.activity_container - end - - def get_activity_act_showname_htmlclear(activity) - str = get_activity_act_showname(activity) - str = str.gsub(/<.*>/,'') - str = str.gsub(/\r/,'') - str = str.gsub(/\n/,'') - str = str.lstrip.rstrip - if str == '' - str = 'RE:' - end - return str.html_safe - end - - # journal.details 记录每个动作的新旧值 - def get_issue_des_update(journal) - no_html = "message" - arr = details_to_strings(journal.details, no_html) - unless journal.notes.blank? - arr << journal.notes - end - str = '' - arr.each { |item| str = str+item } - return str - end - - def get_activity_act_showname(activity) - case activity.act_type - when "HomeworkCommon" - return activity.act.name - when "Issue" - return activity.act.subject - when "Journal" - arr = details_to_strings(activity.act.details,true) - arr << activity.act.notes - str = '' - arr.each { |item| str = str+item } - return str - when "JournalsForMessage" - return activity.act.notes - when "Message" - return activity.act.subject - when "News" - return activity.act.title - when "Poll" - return activity.act.polls_name - when "Contest" - return '' - when "Contestnotification" - return '' - when "Principal" - return '' - else - return activity.act_type - end - end - - def get_activity_act_createtime(activity) - case activity.act_type - when "HomeworkCommon" - return activity.act.created_at - when "Poll" - return activity.act.created_at - else - return activity.act.created_on - end - end - - def get_activity_container_url e - if !e.visible? - return "javascript:;" - end - - if e.class.to_s == 'Course' - return url_for(:controller => 'courses', :action=>"show", :id=>e.id, :host=>Setting.host_course) - end - return url_for(:controller => 'projects', :action=>"show", :id=>e.id, :host=>Setting.host_name) - end - - def get_activity_url(activity,e) - if !e.visible? - return "javascript:;" - end - - case activity.act_type - # when "Contest" - # when "Contestnotification" - # when "Principal" - when "HomeworkCommon" - return homework_common_index_path( :course=>e.id ) - when "Issue" - return issue_path(activity.act.id) - when "Journal" - return issue_path( activity.act.journalized_id ) - when "JournalsForMessage" - return e.class.to_s == 'Course' ? course_feedback_path(e) : project_feedback_path(e) - when "Message" - return e.class.to_s == 'Course' ? course_boards_path(e) : project_boards_path(e) - when "News" - return news_path(activity.act) - #return e.class.to_s == 'Course' ? course_news_index_path(e) : project_news_index_path(e) - when "Poll" - return poll_index_path( :polls_group_id=>activity.act.polls_group_id, :polls_type=>e.class.to_s ) - else - return 'javascript:;' - end - end - - def get_activity_opt(activity,e) - case activity.act_type - when "HomeworkCommon" - return '创建了作业' - when "News" - return e.class.to_s == 'Course' ? '发布了通知' : '添加了新闻' - when "Issue" - return '发表了问题' - when "Journal" - return '更新了问题' - when "JournalsForMessage" - return e.class.to_s == 'Course' ? '发表了留言' : '提交了反馈' - #return ( activity.act.reply_id == nil || activity.act.reply_id == 0 ) ? '' : '' - when "Message" - return ( activity.act.parent_id == nil || activity.act.parent_id == '' ) ? '发布了帖子' : '回复了帖子' - when "Poll" - return '创建了问卷' - else - return '有了新动态' - end - end - - #获取指定用户作为老师的课程 - def get_as_teacher_courses user - type = [] - option = [] - option << "请选择发布作业的课程" - option << -1 - type << option - user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").select{|c| user.allowed_to?(:as_teacher,c)}.each do |course| - option = [] - option << course.name+"("+course.time.to_s+course.term+")" - option << course.id - type << option - end - type - end - -end +# encoding: utf-8 +# +# Redmine - project management software +# Copyright (C) 2006-2013 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + + +include AvatarHelper +module UsersHelper + def users_status_options_for_select(selected) + user_count_by_status = User.count(:group => 'status').to_hash + options_for_select([[l(:label_all), ''], + ["#{l(:status_active)} (#{user_count_by_status[1].to_i})", '1'], + ["#{l(:status_registered)} (#{user_count_by_status[2].to_i})", '2'], + ["#{l(:status_locked)} (#{user_count_by_status[3].to_i})", '3']], selected.to_s) + end + + def get_resource_type type + case type + when 'Course' + '课程资源' + when 'Project' + '项目资源' + when 'Issue' + '缺陷附件' + when 'Message' + '讨论区附件' + when 'Document' + '文档附件' + when 'News' + '通知附件' + when 'HomewCommon' + '作业附件' + when 'StudentWorkScore' + '批改附件' + when 'Principal' + '用户资源' + when 'OrgSubfield' + '组织资源' + end + end + + def get_resource_origin attach + type = attach.container_type + content = attach.container + unless content.nil? + case type + when 'Course' + result = current_time_and_term_resource content + when 'Project' + result = content.name + when 'Issue' + result = content.subject + when 'Message' + result = content.subject + when 'News' + result = content.title + when 'HomewCommon' + result = content.name + when 'StudentWorkScore' + result = content.name + when 'Principal' + result = content.name + when 'OrgSubfield' + result = content.name + end + end + end + + def current_time_and_term_resource course + str = "" + term = cur_course_term_resource + name = course.name + if (course.time == course.end_time && course.term == course.end_term) || (course.end_term.nil? && course.end_time.nil?) || course.time > Time.now.year + str = name + "(" + course.time.to_s + course.term.to_s + ")" + elsif course.time == Time.now.year && set_term_value(cur_course_term) <= set_term_value(course.term) + str = name + "(" + course.time.to_s + course.term.to_s + ")" + elsif course.end_time < Time.now.year || (course.end_time == Time.now.year && set_term_value(cur_course_term) >= set_term_value(course.term)) + str = name + "(" + course.end_time.to_s + course.end_term.to_s + ")" + else + str = name + "(" + Time.now.year.to_s + cur_course_term_resource.to_s + ")" + end + str + end + + def cur_course_term_resource + month = Time.now.month + if month >= 9 || month < 2 + term = "秋" + elsif (month >= 7 && Time.now.day >= 15) || month == 8 + term = "夏" + else + term = "春" + end + term + end + + def title_for_message type + case type + when nil + '消息' + when 'unviewed' + '未读消息' + when 'apply' + '用户申请' + when 'system_messages' + '系统消息' + when 'homework' + '作业消息' + when 'course_message' + '课程讨论' + when 'course_news' + '课程通知' + when 'poll' + '课程问卷' + when 'issue' + '项目任务' + when 'forge_message' + '项目讨论' + when 'forge_news' + '项目新闻' + when 'forum' + '贴吧帖子' + when 'user_feedback' + '用户留言' + end + end + + def link_to_user_version(version, options = {}) + return '' unless version && version.is_a?(Version) + link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, :class => "linkBlue" + end + + # 统计未读消息数 + def unviewed_message(user) + course_count = CourseMessage.where("user_id =? and viewed =?", user, 0).count + forge_count = ForgeMessage.where("user_id =? and viewed =?", user, 0).count + org_count = OrgMessage.where("user_id =? and viewed =?", user, 0).count + user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count + user_memo_count = MemoMessage.where("user_id =? and viewed =?", user, 0).count + at_count = user.at_messages.where(viewed: false).count + messages_count = course_count + forge_count + user_feedback_count + user_memo_count + at_count + org_count + end + + def user_mail_notification_options(user) + user.valid_notification_options.collect {|o| [l(o.last), o.first]} + end + + def change_status_link(user) + url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil} + + if user.locked? + link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock' + elsif user.registered? + link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock' + elsif user != User.current + link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'icon icon-lock' + end + end + + def user_settings_tabs + tabs = [{:name => 'general', :partial => 'users/general', :label => :label_general}, + {:name => 'memberships', :partial => 'users/memberships', :label => :label_project_plural} + ] + if Group.all.any? + tabs.insert 1, {:name => 'groups', :partial => 'users/groups', :label => :label_group_plural} + end + tabs + end + + # this method is used to get all projects that tagged one tag + # added by william + def get_users_by_tag(tag_name) + User.tagged_with(tag_name).order('updated_on desc') + end + + # added by fq + # + + # TODO: 待删 + # def show_activity(state) + # content = ''.html_safe + # case state + # when 0 + # s = content_tag('span', l(:label_user_all_activity), :class => "current-page") + # content << content_tag('li', s) + # content << content_tag('li', link_to(l(:label_user_activity_myself), {:controller => 'users', :action => 'show', :type => 1})) + # content << content_tag('li', link_to(l(:label_user_all_respond), {:controller => 'users', :action => 'show', :type => 2})) + # when 1 + # s = content_tag('span', l(:label_user_activity_myself), :class => "current-page") + # content << content_tag('li', link_to(l(:label_user_all_activity), {:controller => 'users', :action => 'show'})) + # content << content_tag('li', s, :class => "current-page") + # content << content_tag('li', link_to(l(:label_user_all_respond), {:controller => 'users', :action => 'show', :type => 2})) + # when 2 + # s = content_tag('span', l(:label_user_all_respond), :class => "current-page") + # content << content_tag('li', link_to(l(:label_user_all_activity), {:controller => 'users', :action => 'show'})) + # content << content_tag('li', link_to(l(:label_user_activity_myself), {:controller => 'users', :action => 'show', :type => 1})) + # content << content_tag('li', s, :class => "current-page") + # end + # content_tag('div', content, :class => "pagination") + # end + + #TODO: 待删 + def watch_projects(state) + content = ''.html_safe + case state + when 0 + s = content_tag('span', l(:label_project_take), :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to(l(:label_has_watched_project), {:controller => 'users', :action => 'watch_projects', :type => 1})) + when 1 + s = content_tag('span', l(:label_has_watched_project), :class => "current-page") + content << content_tag('li', link_to(l(:label_project_take), {:controller => 'users', :action => 'user_projects'})) + content << content_tag('li', s, :class => "current-page") + end + content_tag('div', content, :class => "pagination") + end + + def user_course(state) + content = ''.html_safe + if @user != User.current + if @user.user_extensions.identity == 0 + case state + when 0 + s = content_tag('span', '他执教的课程', :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to('他发布的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) + content_tag('div', content, :class => "pagination") + when 1 + s = content_tag('span', '他发布的作业', :class => "current-page") + content << content_tag('li', link_to('他执教的课程', {:controller => 'users', :action => 'user_courses'})) + content << content_tag('li', s, :class => "current-page") + content_tag('div', content, :class => "pagination") + end + else + case state + when 0 + s = content_tag('span', '他的课程', :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to('他的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) + content_tag('div', content, :class => "pagination") + when 1 + s = content_tag('span', '他的作业', :class => "current-page") + content << content_tag('li', link_to('他的课程', {:controller => 'users', :action => 'user_courses', :type => 0})) + content << content_tag('li', s, :class => "current-page") + content_tag('div', content, :class => "pagination") + end + end + else + if @user.user_extensions.identity == 0 + case state + when 0 + s = content_tag('span', l(:label_teaching_course), :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to(l(:label_release_homework), {:controller => 'users', :action => 'user_courses', :type => 1})) + content_tag('div', content, :class => "pagination") + when 1 + s = content_tag('span', l(:label_release_homework), :class => "current-page") + content << content_tag('li', link_to(l(:label_teaching_course), {:controller => 'users', :action => 'user_courses'})) + content << content_tag('li', s, :class => "current-page") + content_tag('div', content, :class => "pagination") + end + else + case state + when 0 + s = content_tag('span', l(:label_my_course), :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to('我的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) + content_tag('div', content, :class => "pagination") + when 1 + s = content_tag('span', '我的作业', :class => "current-page") + content << content_tag('li', link_to(l(:label_my_course), {:controller => 'users', :action => 'user_courses', :type => 0})) + content << content_tag('li', s, :class => "current-page") + content_tag('div', content, :class => "pagination") + end + end + end + end + + # added by huang + def sort_user(state, project_type) + content = ''.html_safe + case state + when 0 + content << content_tag('li', link_to(l(:label_sort_by_active), users_path(params.merge({:user_sort_type => '1', :project_type => project_type}) ))) + content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(params.merge({:user_sort_type => '2', :project_type => project_type}) ))) + content << content_tag('li', link_to(l(:label_sort_by_time), users_path(params.merge({:user_sort_type => '0', :project_type => project_type}) ), :class=>"selected") ) + when 1 + content << content_tag('li', link_to(l(:label_sort_by_active), users_path(params.merge({:user_sort_type => '1', :project_type => project_type}) ), :class=>"selected") ) + content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(params.merge({:user_sort_type => '2', :project_type => project_type}) ))) + content << content_tag('li', link_to(l(:label_sort_by_time), users_path(params.merge({:user_sort_type => '0', :project_type => project_type}) ))) + when 2 + content << content_tag('li', link_to(l(:label_sort_by_active), users_path(params.merge({:user_sort_type => '1', :project_type => project_type}) ))) + content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(params.merge({:user_sort_type => '2', :project_type => project_type}) ), :class=>"selected") ) + content << content_tag('li', link_to(l(:label_sort_by_time), users_path(params.merge({:user_sort_type => '0', :project_type => project_type}) ))) + end + content = content_tag('ul', content) + content_tag('div', content, :class => "tabs") + end + + def sort_user_enterprise(state, project_type) + content = ''.html_safe + case state + when 0 + content << content_tag('li', link_to(l(:label_sort_by_active), users_path(:user_sort_type => '1', :project_type => project_type))) + content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(:user_sort_type => '2', :project_type => project_type))) + content << content_tag('li', link_to(l(:label_sort_by_time), users_path(:user_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected") + when 1 + content << content_tag('li', link_to(l(:label_sort_by_active), users_path(:user_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(:user_sort_type => '2', :project_type => project_type))) + content << content_tag('li', link_to(l(:label_sort_by_time), users_path(:user_sort_type => '0', :project_type => project_type))) + when 2 + content << content_tag('li', link_to(l(:label_sort_by_active), users_path(:user_sort_type => '1', :project_type => project_type))) + content << content_tag('li', link_to(l(:label_sort_by_influence), users_path(:user_sort_type => '2', :project_type => project_type), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_time), users_path(:user_sort_type => '0', :project_type => project_type))) + end + content = content_tag('ul', content) + content_tag('div', content, :class => "tabs_enterprise") + end + + def gender_avatar_uri user + img_uri = '/images/sidebar/female.png' + return img_uri if user.user_extensions.blank? + person_gender = user.user_extensions.gender + img_uri = (person_gender == 1) ? '/images/sidebar/female.png' : '/images/sidebar/male.png' + end + + include CoursesHelper + def is_watching?(user) + login_user = User.current# 登录者 + + courses = user.projects.where('project_type=1') + return true if ((login_user == user) or login_user.admin?) + courses.each do |course| + return true if login_user.member_of?(course) + end + ## 下面的代码只判断是否是老师或者助教,上面是成员都可以看到 + # people_ids = [] + # user.projects.where('project_type=1').each do |project| + # tmp = searchTeacherAndAssistant(project) + # people_ids += (members_to_user_ids(tmp)) unless tmp.nil? + # end + # people_ids.include?(login_user.id) or (login_user == user) or login_user.admin? + + false + end + + # base user上面的navbar显示内容 + def show_item_on_navbar params + displayed_item = %w|index| + displayed_item.include?(params['action']) + end + # base user上面searchBar显示 + def show_search_bar params + displayed_flag = %w|index| + !displayed_flag.include?(params['action']) + end + + #获取指定用户的未过期的课程列表 + def user_courses_list user + result = [] + user.coursememberships.map(&:course).each do |course| + if !course_endTime_timeout?(course) + result << course + end + end + return result + end + + #获取用户参与的公开的课程列表 + def user_public_course_list user + membership = user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current)) + membership.sort! {|older, newer| newer.created_on <=> older.created_on } + memberships = [] + membership.collect { |e| + memberships.push(e) + } + ## 判断课程是否过期 [需封装] + memberships_doing = [] + memberships_done = [] + memberships.map { |e| + if course_endTime_timeout?(e.course) + memberships_done.push e + else + memberships_doing.push e + end + } + end + + #获取用户留言相关的连接 + def user_jour_feed_back_url active + if active.act_type == "JournalsForMessage" + jour = JournalsForMessage.find active.act_id + if jour + case jour.jour_type + when "Principal" + link_to(l(:label_goto), user_newfeedback_user_path(jour.jour_id)) + when "Project" + link_to(l(:label_goto), project_feedback_path(jour.jour_id)) + when "Bid" + link_to(l(:label_goto), course_for_bid_path(jour.jour_id)) + when "Course" + link_to(l(:label_goto), course_feedback_path(jour.jour_id)) + when "Contest" + link_to(l(:label_goto), show_contest_contest_path(jour.jour_id)) + when "Softapplication" + link_to(l(:label_goto), softapplication_path(jour.jour_id)) + when "HomeworkAttach" + link_to(l(:label_goto), course_for_bid_path(jour.jour_id)) + end + end + end + end + + def get_watcher_users(obj) + count = User.watched_by(obj.id).count + if count == 0 + return [0,[]] + end + list = User.watched_by(obj.id).order("#{Watcher.table_name}.id desc").limit(10).all + return [count,list]; + end + + def get_fans_users(obj) + count = obj.watcher_users.count + if count == 0 + return [0,[]] + end + list = obj.watcher_users.order("#{Watcher.table_name}.id desc").limit(10).all + return [count,list]; + end + + def get_visitor_users(obj) + query = Visitor.where("master_id=?",obj.id) + count = query.count + if count == 0 + return [0,[]] + end + list = query.order("updated_on desc").limit(10).all + return [count,list] + end + + def get_create_course_count(user) + user.courses.visible.where("tea_id = ?",user.id).count + end + + #获取加入课程数 + def get_join_course_count(user) + user.courses.visible.count - get_create_course_count(user) + end + + #发布作业数 + def get_homework_commons_count(user) + HomeworkCommon.where("user_id = ?",user.id).count + end + + #资源数 + def get_projectandcourse_attachment_count(user) + Attachment.where("author_id = ? and container_type in ('Project','Course')",user.id).count + end + + #创建项目数 + def get_create_project_count(user) + user.projects.visible.where("projects.user_id=#{user.id}").count + end + + #加入项目数 + def get_join_project_count(user) + user.projects.visible.count - get_create_project_count(user) + end + + #创建缺陷数 + def get_create_issue_count(user) + Issue.where("author_id = ?",user.id).count + end + + #解决缺陷数 + def get_resolve_issue_count(user) + Issue.where("assigned_to_id = ? and status_id=3",user.id).count + end + + #参与匿评数 + def get_anonymous_evaluation_count(user) + StudentWorksScore.where("user_id = ? and reviewer_role=3",user.id).count + end + + def query_activities(query) + list = query.limit(13).all + result = [] + for item in list + container = get_activity_container(item) + result << { :item=>item,:e=>container } + end + result + end + + def get_activity_container activity + return activity.activity_container + end + + def get_activity_act_showname_htmlclear(activity) + str = get_activity_act_showname(activity) + str = str.gsub(/<.*>/,'') + str = str.gsub(/\r/,'') + str = str.gsub(/\n/,'') + str = str.lstrip.rstrip + if str == '' + str = 'RE:' + end + return str.html_safe + end + + # journal.details 记录每个动作的新旧值 + def get_issue_des_update(journal) + no_html = "message" + arr = details_to_strings(journal.details, no_html) + unless journal.notes.blank? + arr << journal.notes + end + str = '' + arr.each { |item| str = str+item } + return str + end + + def get_activity_act_showname(activity) + case activity.act_type + when "HomeworkCommon" + return activity.act.name + when "Issue" + return activity.act.subject + when "Journal" + arr = details_to_strings(activity.act.details,true) + arr << activity.act.notes + str = '' + arr.each { |item| str = str+item } + return str + when "JournalsForMessage" + return activity.act.notes + when "Message" + return activity.act.subject + when "News" + return activity.act.title + when "Poll" + return activity.act.polls_name + when "Contest" + return '' + when "Contestnotification" + return '' + when "Principal" + return '' + else + return activity.act_type + end + end + + def get_activity_act_createtime(activity) + case activity.act_type + when "HomeworkCommon" + return activity.act.created_at + when "Poll" + return activity.act.created_at + else + return activity.act.created_on + end + end + + def get_activity_container_url e + if !e.visible? + return "javascript:;" + end + + if e.class.to_s == 'Course' + return url_for(:controller => 'courses', :action=>"show", :id=>e.id, :host=>Setting.host_course) + end + return url_for(:controller => 'projects', :action=>"show", :id=>e.id, :host=>Setting.host_name) + end + + def get_activity_url(activity,e) + if !e.visible? + return "javascript:;" + end + + case activity.act_type + # when "Contest" + # when "Contestnotification" + # when "Principal" + when "HomeworkCommon" + return homework_common_index_path( :course=>e.id ) + when "Issue" + return issue_path(activity.act.id) + when "Journal" + return issue_path( activity.act.journalized_id ) + when "JournalsForMessage" + return e.class.to_s == 'Course' ? course_feedback_path(e) : project_feedback_path(e) + when "Message" + return e.class.to_s == 'Course' ? course_boards_path(e) : project_boards_path(e) + when "News" + return news_path(activity.act) + #return e.class.to_s == 'Course' ? course_news_index_path(e) : project_news_index_path(e) + when "Poll" + return poll_index_path( :polls_group_id=>activity.act.polls_group_id, :polls_type=>e.class.to_s ) + else + return 'javascript:;' + end + end + + def get_activity_opt(activity,e) + case activity.act_type + when "HomeworkCommon" + return '创建了作业' + when "News" + return e.class.to_s == 'Course' ? '发布了通知' : '添加了新闻' + when "Issue" + return '发表了问题' + when "Journal" + return '更新了问题' + when "JournalsForMessage" + return e.class.to_s == 'Course' ? '发表了留言' : '提交了反馈' + #return ( activity.act.reply_id == nil || activity.act.reply_id == 0 ) ? '' : '' + when "Message" + return ( activity.act.parent_id == nil || activity.act.parent_id == '' ) ? '发布了帖子' : '回复了帖子' + when "Poll" + return '创建了问卷' + else + return '有了新动态' + end + end + + #获取指定用户作为老师的课程 + def get_as_teacher_courses user + type = [] + option = [] + option << "请选择发布作业的课程" + option << -1 + type << option + user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").select{|c| user.allowed_to?(:as_teacher,c)}.each do |course| + option = [] + option << course.name+"("+course.time.to_s+course.term+")" + option << course.id + type << option + end + type + end + + #根据姓名搜索用户 + def search_user_by_name user_ids, name + result_ids = [] + user_ids.each do |user_id| + user = User.find user_id + username = user.lastname.to_s.downcase + user.firstname.to_s.downcase + if username.include?(name) + result_ids << user_id + end + end + result_ids + end +end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 9fb6112b8..82f648ad9 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -88,7 +88,8 @@ class Attachment < ActiveRecord::Base cattr_accessor :thumbnails_storage_path @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") - before_save :files_to_final_location,:act_as_course_activity + 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_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 @@ -606,8 +607,14 @@ class Attachment < ActiveRecord::Base #课程动态公共表记录 def act_as_course_activity - if self.container_type == "Course" && self.course_acts.empty? - self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.container_id) + if self.container_type == "Course" + if self.is_publish == 0 + self.course_acts.destroy_all + else + if self.is_publish == 1 && self.course_acts.empty? + self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.container_id) + end + end end end @@ -644,8 +651,8 @@ class Attachment < ActiveRecord::Base def decrease_attchments_count if self.container_type == "Project" && !self.project.project_score.nil? - aatach_count = self.container.project_score.attach_num - 1 - self.container.project_score.update_attribute(:attach_num, aatach_count) + attach_count = self.container.project_score.attach_num - 1 + self.container.project_score.update_attribute(:attach_num, attach_count < 0 ? 0 : attach_count) end end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 69753d81c..4d7af1d73 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -82,9 +82,7 @@ class Comment < ActiveRecord::Base # 课程成员得分(英雄榜) def act_as_student_score if self.commented.course - unless self.author.allowed_to?(:as_teacher, self.commented.course) - course_member_score(self.commented.course.id, self.author_id, "NewReply") - end + course_member_score(self.commented.course.id, self.author_id, "NewReply") end end diff --git a/app/models/course_contributor_score.rb b/app/models/course_contributor_score.rb index f2b05458f..4f3b3e187 100644 --- a/app/models/course_contributor_score.rb +++ b/app/models/course_contributor_score.rb @@ -1,5 +1,6 @@ class CourseContributorScore < ActiveRecord::Base - attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num, :resource_num, :user_id, :total_score + attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num, + :resource_num, :user_id, :total_score, :homework_journal_num, :news_num belongs_to :course belongs_to :user end diff --git a/app/models/issue.rb b/app/models/issue.rb index e1de4cd9e..c82f6f0be 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -184,7 +184,7 @@ class Issue < ActiveRecord::Base def decrease_issues_count unless self.project.project_score.nil? issue_count = self.project.project_score.issue_num - 1 - self.project.project_score.update_attribute(:issue_num, issue_count) + self.project.project_score.update_attribute(:issue_num, issue_count < 0 ? 0 : issue_count) end end diff --git a/app/models/journal.rb b/app/models/journal.rb index b184c82e6..c37b8d2c5 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -219,8 +219,9 @@ class Journal < ActiveRecord::Base # 减少留言数量统计 def decrease_issues_journal_count unless self.issue.project.nil? - project = self.issue.project - project.project_score.update_attribute(:issue_journal_num, project.project_score.issue_journal_num - 1) + journal_count = self.issue.project.project_score.issue_journal_num - 1 + # project = self.issue.project + self.issue.project.project_score.update_attribute(:issue_journal_num, journal_count < 0 ? 0 : journal_count) end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index cdcf9d19e..7990979e4 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -283,10 +283,12 @@ class JournalsForMessage < ActiveRecord::Base end end - # 课程成员得分(英雄榜) + # 课程成员得分(活跃度) def act_as_student_score - if !self.user.allowed_to?(:as_teacher, self.jour) && self.jour_type == "Course" + if self.jour_type == "Course" course_member_score(self.jour_id, self.user_id, "JournalForMessage") + elsif self.jour_type == "HomeworkCommon" + course_member_score(self.jour.course_id, self.user_id, "HomeworkCommon") end end diff --git a/app/models/message.rb b/app/models/message.rb index cc9968309..44f2d2c80 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -148,10 +148,10 @@ class Message < ActiveRecord::Base # 讨论区 if self.parent_id.nil? count = self.project.project_score.board_num - 1 - self.project.project_score.update_attribute(:board_num, count) + self.project.project_score.update_attribute(:board_num, count < 0 ? 0 : count) else # 回复 count = self.project.project_score.board_message_num - 1 - self.project.project_score.update_attribute(:board_message_num, count) + self.project.project_score.update_attribute(:board_message_num, count < 0 ? 0 : count) end end end @@ -341,17 +341,15 @@ class Message < ActiveRecord::Base delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE end - # 课程成员得分(英雄榜) + # 课程成员得分(活跃度) def act_as_student_score if self.course - unless self.author.allowed_to?(:as_teacher, self.course) - if self.parent_id.nil? - # 发帖 - course_member_score(self.course.id, self.author_id, "Message") - else - # 回帖 - course_member_score(self.course.id, self.author_id, "MessageReply") - end + if self.parent_id.nil? + # 发帖 + course_member_score(self.course.id, self.author_id, "Message") + else + # 回帖 + course_member_score(self.course.id, self.author_id, "MessageReply") end end end diff --git a/app/models/news.rb b/app/models/news.rb index f859beb0c..028b6d737 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -59,7 +59,7 @@ class News < ActiveRecord::Base :author_key => :author_id acts_as_watchable - after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count + after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score after_update :update_activity after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities @@ -129,7 +129,7 @@ class News < ActiveRecord::Base def decrease_news_count if self.project && !self.project.project_score.nil? count = self.project.project_score.news_num - 1 - self.project.project_score.update_attribute(:news_num, count) + self.project.project_score.update_attribute(:news_num, count < 0 ? 0 : count) end end @@ -195,4 +195,10 @@ class News < ActiveRecord::Base OrgActivity.where("container_type='OrgSubfield' and org_act_type='News' and org_act_id=?", self.id).destroy_all end + def act_as_student_score + if self.course + course_member_score(self.course.id, self.author_id, "News") + end + end + end \ No newline at end of file diff --git a/app/views/admin/_tab_users.erb b/app/views/admin/_tab_users.erb new file mode 100644 index 000000000..2cda0c61c --- /dev/null +++ b/app/views/admin/_tab_users.erb @@ -0,0 +1,7 @@ +
+
    +
  • <%= link_to '用户', {:action => 'latest_login_users'}, class: "#{current_page?(latest_login_users_path)? 'selected' : nil }" %>
  • +
  • <%= link_to '老师', {:action => 'latest_login_teachers'}, class: "#{current_page?(latest_login_teachers_path)? 'selected' : nil }" %>
  • + +
+
\ No newline at end of file diff --git a/app/views/admin/latest_login_teachers.html.erb b/app/views/admin/latest_login_teachers.html.erb new file mode 100644 index 000000000..05f20ba8d --- /dev/null +++ b/app/views/admin/latest_login_teachers.html.erb @@ -0,0 +1,84 @@ +<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', :media => 'all' %> +

+ <%=l(:label_latest_login_user_list)%> +

+<%= render 'tab_users' %> + +

+ 最近登录老师列表 +

+<%= form_tag({}, :method => :get) do %> +
+ + <%= l(:label_filter_plural) %> + + + <%= text_field_tag 'startdate', params[:startdate], :size => 15, :onchange=>"$('#ui-datepicker-div').hide()", :style=>"float:left"%> + <%= calendar_for('startdate')%>    + + <%= text_field_tag 'enddate', params[:enddate], :size => 15, :onchange =>"$('#ui-datepicker-div').hide()", :style=>"float:left"%> + <%= calendar_for('enddate')%>   + <%= submit_tag l(:button_apply), :class => "small", :name => nil %> + <%= link_to l(:button_clear), {:controller => 'admin', :action => 'latest_login_teachers'}, :class => 'icon icon-reload' %> +
+<% end %> +  +
+ + + + + + + + + + + + + <% @count=@page * 30 %> + <% for teacher in @teachers do %> + + <% @count +=1 %> + + + + + + + + <% end %> + +
+ 序号 + + 登录时间 + + 用户id + + 用户姓名 + + 用户登录名 + + 用户身份 +
+ <%=@count %> + + <%=format_time(teacher.last_login_on) %> + + <%=teacher.user_id %> + <%= teacher.login%><% else %><%=teacher.try(:realname) %><% end %>'> + <% if teacher.try(:realname) == ' '%> + <%= link_to(teacher.login, user_path(teacher.user_id)) %> + <% else %> + <%= link_to(teacher.try(:realname), user_path(teacher.user_id)) %> + <% end %> + + <%=link_to(teacher.login, user_path(teacher.user_id)) %> + + 老师 +
+
+ diff --git a/app/views/admin/latest_login_users.html.erb b/app/views/admin/latest_login_users.html.erb index 594f554b4..17680a8c8 100644 --- a/app/views/admin/latest_login_users.html.erb +++ b/app/views/admin/latest_login_users.html.erb @@ -2,7 +2,10 @@

<%=l(:label_latest_login_user_list)%>

- +<%= render 'tab_users' %> +

+ <%=l(:label_latest_login_user_list)%> +

<%= form_tag({}, :method => :get) do %>
diff --git a/app/views/admin/projects.html.erb b/app/views/admin/projects.html.erb index 3f6ee36f0..d12e85856 100644 --- a/app/views/admin/projects.html.erb +++ b/app/views/admin/projects.html.erb @@ -45,8 +45,8 @@ - <% project_tree(@projects) do |project, level| %> - <%= project.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>"> + <% @projects.each do |project| %> + "> <%= project.id %> diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index de3b038e6..16b4fcd3d 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -22,7 +22,7 @@
- 课程讨论区 + 课程问答区
<% if User.current.logged? %> diff --git a/app/views/common/_file.html.erb b/app/views/common/_file.html.erb index 97443beea..486c760f1 100644 --- a/app/views/common/_file.html.erb +++ b/app/views/common/_file.html.erb @@ -8,7 +8,7 @@ <%= line_num %> -
<%= line.html_safe %>
+
<%= line.html_safe %>
<% line_num += 1 %> diff --git a/app/views/courses/_copy_course.html.erb b/app/views/courses/_copy_course.html.erb index c7547adcd..402e00cf6 100644 --- a/app/views/courses/_copy_course.html.erb +++ b/app/views/courses/_copy_course.html.erb @@ -1,4 +1,11 @@ - -
-
- - - -
-
-
    -
  • - - 分 -
  • -
    -
    - <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> -
  • - - - - -
  • -
    - <% end %> -
    -
    -
-
- -
-
- +<%= form_for("",:url => update_exercise_question_exercise_index_path(:exercise_question => exercise_question.id),:remote => true) do |f|%> + + + +
+
+ + + +
+
+
    +
  • + + 分 +
  • +
    +
    + <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> +
  • + + + + +
  • +
    + <% end %> +
    +
    +
+
+ +
+
+ <% end%> \ No newline at end of file diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb index f0bef74bf..ec099cb09 100644 --- a/app/views/exercise/_exercise_form.html.erb +++ b/app/views/exercise/_exercise_form.html.erb @@ -162,15 +162,38 @@ //单选题 function add_single_answer(doc) { - doc.parent().after("
  • " + + var li = doc.parent().after("
  • " + ""+ "
  • "); + var select_items =$("label[name='select_items']",li.parent()); + for(var i=0; i:   "); + } } function add_candidate_answer(doc) { - doc.parent().after("
  • " + + doc.parent().after("
  • " + ""+ "
  • "); + var select_items =$("label[name='candiate_items']",doc.parent().parent()); + for(var i=0; i:   "); + } + } + function revert_to_chinese_num(num){ + var s_num = ""; + switch (num) { + case 1: s_num = '一'; break; + case 2: s_num = '二'; break; + case 3: s_num = '三'; break; + case 4: s_num = '四'; break; + case 5: s_num = '五'; break; + case 6: s_num = '六'; break; + case 7: s_num = '七'; break; + case 8: s_num = '八'; break; + case 9: s_num = '九'; break; + } + return s_num; } function remove_single_answer(doc) { @@ -180,7 +203,16 @@ } else { + var parent = doc.parent().parent(); doc.parent().remove(); + var select_items =$("label[name='select_items']",parent); + var candiate_items =$("label[name='candiate_items']",parent); + for(var i=0; i:   "); + } + for(var i=0; i:   "); + } } } diff --git a/app/views/exercise/_new_MC.html.erb b/app/views/exercise/_new_MC.html.erb index 0d7350570..6fd6c201e 100644 --- a/app/views/exercise/_new_MC.html.erb +++ b/app/views/exercise/_new_MC.html.erb @@ -18,28 +18,28 @@
  • - +
  • - +
  • - +
  • - + diff --git a/app/views/exercise/_new_MCQ.html.erb b/app/views/exercise/_new_MCQ.html.erb index 3ea198d8f..a24835fc1 100644 --- a/app/views/exercise/_new_MCQ.html.erb +++ b/app/views/exercise/_new_MCQ.html.erb @@ -18,28 +18,28 @@
  • - +
  • - +
  • - +
  • - + diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index 061b053fd..6180dac8e 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -1,50 +1,50 @@ -<%= form_for(ExerciseQuestion.new, - :html => { :multipart => true }, - :url=>create_exercise_question_exercise_path(exercise.id), - :remote=>true ) do |f| %> -
    -
    - - - -
    -
    -
      -
    • - <% score = exercise.exercise_questions.where("question_type=3").last.nil? ? "": exercise.exercise_questions.where("question_type=3").last.question_score %> - - 分 -
    • -
      -
      -
    • - - - - -
    • -
      -
    • - - - - -
    • -
      -
    • - - - - -
    • -
      -
      -
    -
    - -
    -
    +<%= form_for(ExerciseQuestion.new, + :html => { :multipart => true }, + :url=>create_exercise_question_exercise_path(exercise.id), + :remote=>true ) do |f| %> +
    +
    + + + +
    +
    +
      +
    • + <% score = exercise.exercise_questions.where("question_type=3").last.nil? ? "": exercise.exercise_questions.where("question_type=3").last.question_score %> + + 分 +
    • +
      +
      +
    • + + + + +
    • +
      +
    • + + + + +
    • +
      +
    • + + + + +
    • +
      +
      +
    +
    + +
    +
    <% end %> \ No newline at end of file diff --git a/app/views/exercise/_show_MC.html.erb b/app/views/exercise/_show_MC.html.erb index d052bd6da..eef7546e5 100644 --- a/app/views/exercise/_show_MC.html.erb +++ b/app/views/exercise/_show_MC.html.erb @@ -55,28 +55,28 @@ '分'+ '
  • '+ '
  • '+ - ''+ + ''+ ''+ ''+ ''+ '
  • '+ '
    '+ '
  • '+ - ''+ + ''+ ''+ ''+ ''+ '
  • '+ '
    '+ '
  • '+ - ''+ + ''+ ''+ ''+ ''+ '
  • '+ '
    '+ '
  • '+ - ''+ + ''+ ''+ ''+ ''+ diff --git a/app/views/exercise/_show_MCQ.html.erb b/app/views/exercise/_show_MCQ.html.erb index a477303d7..9e66f17f9 100644 --- a/app/views/exercise/_show_MCQ.html.erb +++ b/app/views/exercise/_show_MCQ.html.erb @@ -54,28 +54,28 @@ '分'+ '
  • '+ '
  • '+ - ''+ + ''+ ''+ ''+ ''+ '
  • '+ '
    '+ '
  • '+ - ''+ + ''+ ''+ ''+ ''+ '
  • '+ '
    '+ '
  • '+ - ''+ + ''+ ''+ ''+ ''+ '
  • '+ '
    '+ '
  • '+ - ''+ + ''+ ''+ ''+ ''+ diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index 86203b8bb..90f604da1 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -9,7 +9,7 @@
    <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> - 候选答案:<%= exercise_choice.answer_text%>
    + 候选答案<%= convert_to_chi_num(index+1) %>:<%= exercise_choice.answer_text%>
    <% end %>
  • @@ -42,22 +42,22 @@ '分'+ '
    '+ '
  • '+ - ''+ - ''+ + ''+ + ''+ ''+ ''+ '
  • '+ '
    '+ '
  • '+ - ''+ - ''+ + ''+ + ''+ ''+ ''+ '
  • '+ '
    '+ '
  • '+ - ''+ - ''+ + ''+ + ''+ ''+ ''+ '
  • '+ diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb index cf91b7814..b548092cf 100644 --- a/app/views/files/_course_file.html.erb +++ b/app/views/files/_course_file.html.erb @@ -91,9 +91,10 @@ <%= form_tag( search_course_files_path(@course), method: 'get',:class => "re_search",:remote=>true) do %> <%= text_field_tag 'name', params[:name], name: "name", :class => 'researchBox fl',:style=>"padding: 0px"%> <%= submit_tag "课内搜索", :class => "blueBtn mr5 fl",:name => "incourse",:id => "incourse" %> - <%= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %> + <%#= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %> <% if is_course_teacher(User.current,@course) || (@course.publish_resource==1 && User.current.member_of_course?(@course) ) %> - + + <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %> <% end %> <% end %> diff --git a/app/views/files/_import_files.html.erb b/app/views/files/_import_files.html.erb new file mode 100644 index 000000000..36fa96a0b --- /dev/null +++ b/app/views/files/_import_files.html.erb @@ -0,0 +1,138 @@ +<%#= render :partial => 'users/user_resource_info' %> +
    选用资源库中的资源
    +
    公共资源 我的资源 + +
    +
    +
      + +
    • 类别
    • +
    • 大小
    • +
    • 上传者
    • +
    • 上传时间
    • +
    +
      + +
    • 课程资源
    • +
    • 123.0KB
    • +
    • 尹刚
    • +
    • 2016-01-21
    • +
    +
      + +
    • 项目资源
    • +
    • 123.0KB
    • +
    • 尹刚
    • +
    • 2016-01-21
    • +
    +
      + +
    • 附件
    • +
    • 123.0KB
    • +
    • 尹刚
    • +
    • 2016-01-21
    • +
    +
      + +
    • 课程资源
    • +
    • 123.0KB
    • +
    • 尹刚
    • +
    • 2016-01-21
    • +
    +
      + +
    • 课程资源
    • +
    • 123.0KB
    • +
    • 尹刚
    • +
    • 2016-01-21
    • +
    +
      + +
    • 课程资源
    • +
    • 123.0KB
    • +
    • 尹刚
    • +
    • 2016-01-21
    • +
    +
      + +
    • 课程资源
    • +
    • 123.0KB
    • +
    • 尹刚
    • +
    • 2016-01-21
    • +
    +
      + +
    • 课程资源
    • +
    • 123.0KB
    • +
    • 尹刚
    • +
    • 2016-01-21
    • +
    +
      + +
    • 课程资源
    • +
    • 123.0KB
    • +
    • 尹刚
    • +
    • 2016-01-21
    • +
    +
      + +
    • 课程资源
    • +
    • 123.0KB
    • +
    • 尹刚
    • +
    • 2016-01-21
    • +
    +
    + + +
    + + + + + + + +
    +
    +
    +
    diff --git a/app/views/files/_org_subfield_list.html.erb b/app/views/files/_org_subfield_list.html.erb index 866cf6fd8..38ff40ed3 100644 --- a/app/views/files/_org_subfield_list.html.erb +++ b/app/views/files/_org_subfield_list.html.erb @@ -1,78 +1,78 @@ -<% delete_allowed = User.current.admin? %> - -<% org_subfield_attachments.each do |file| %> -
    -
    -
    - <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %> -
    -
    -
    - <%= 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 => "c_dblue f_14 f_b f_l" %> - <%= file_preview_eye(file, class: 'preview') %> - - <% if file.is_public? == false%> - 私有 - <%end %> - -
    -
    -
    - 上传时间:<%= format_date(file.created_on)%> - <% if file.tag_list.length > 0%> - 上传类型:<%= file.tag_list[0] %> - <% end %> -

    文件大小:<%= number_to_human_size(file.filesize) %>

    -

    下载<%= file.downloads%>  |  引用<%= file.quotes.nil? ? 0:file.quotes %>

    -
    -
    -
    - <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6"} %> - <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6"} %> -
    -
    -
      -
    • - <% if User.current.logged? %> - <% if (delete_allowed || User.current.id == file.author_id) && file.container_id == org_subfield.id && file.container_type == "OrgSubfield" %> -
        -
      • <%= link_to("发       送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
      • -
      • <%= link_to '更新版本',attachments_versions_path(file),:class => "postOptionLink",:remote=>true %>
      • -
      • - - <%= 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( '删除资源', 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 == org_subfield.id && file.container_type == "OrgSubfield" && file.destroyable %> -
      • -
      - <%else%> -
        -
      • <%= link_to("发  送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
      • -
      - <% end %> - <% end %> -
    • -
    - -
    -
    -
    -
    - -
    -<% end %> - -<% if org_subfield_attachments.count == 10 %> - <% if params[:action] == 'search_files_in_subfield' %> - <%=link_to "点击展开更多", search_files_in_subfield_org_subfield_files_path(:org_subfield_id => org_subfield.id,:page => @page.to_i + 1, :name => params[:name],:insite => params[:insite]),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> - <% else %> - - <%=link_to "点击展开更多", org_subfield_files_path(:org_subfield_id => org_subfield.id, :page => @page.nil? ? 2 :(@page.to_i + 1)), :id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> - <%end%> -<% end%> - +<% delete_allowed = User.current.admin? %> + +<% org_subfield_attachments.each do |file| %> +
    +
    +
    + <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %> +
    +
    +
    + <%= 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 f_l" %> + <%= file_preview_eye(file, class: 'preview') %> + + <% if file.is_public? == false%> + 私有 + <%end %> + +
    +
    +
    + 上传时间:<%= format_date(file.created_on)%> + <% if file.tag_list.length > 0%> + 上传类型:<%= file.tag_list[0] %> + <% end %> +

    文件大小:<%= number_to_human_size(file.filesize) %>

    +

    下载<%= file.downloads%>  |  引用<%= file.quotes.nil? ? 0:file.quotes %>

    +
    +
    +
    + <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6"} %> + <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6"} %> +
    +
    +
      +
    • + <% if User.current.logged? %> + <% if (delete_allowed || User.current.id == file.author_id) && file.container_id == org_subfield.id && file.container_type == "OrgSubfield" %> +
        +
      • <%= link_to("发       送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
      • +
      • <%= link_to '更新版本',attachments_versions_path(file),:class => "postOptionLink",:remote=>true %>
      • +
      • + + <%= 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( '删除资源', 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 == org_subfield.id && file.container_type == "OrgSubfield" && file.destroyable %> +
      • +
      + <%else%> +
        +
      • <%= link_to("发  送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
      • +
      + <% end %> + <% end %> +
    • +
    + +
    +
    +
    +
    + +
    +<% end %> + +<% if org_subfield_attachments.count == 10 %> + <% if params[:action] == 'search_files_in_subfield' %> + <%=link_to "点击展开更多", search_files_in_subfield_org_subfield_files_path(:org_subfield_id => org_subfield.id,:page => @page.to_i + 1, :name => params[:name],:insite => params[:insite]),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> + <% else %> + + <%=link_to "点击展开更多", org_subfield_files_path(:org_subfield_id => org_subfield.id, :page => @page.nil? ? 2 :(@page.to_i + 1)), :id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> + <%end%> +<% end%> + diff --git a/app/views/files/_project_file.html.erb b/app/views/files/_project_file.html.erb index e8f4f023b..98b9ad514 100644 --- a/app/views/files/_project_file.html.erb +++ b/app/views/files/_project_file.html.erb @@ -62,10 +62,12 @@ <%= form_tag( search_project_project_files_path(@project), method: 'get',:class => "re_search",:remote=>true) do %> <%= text_field_tag 'name', params[:name], name: "name", :class => 're_schbox',:style=>"padding: 0px"%> <%= submit_tag "项目内搜索", :class => "re_schbtn b_lblue",:name => "incourse",:id => "incourse", :onmouseover => "presscss('incourse')",:onmouseout =>"buttoncss()", :style =>"width:72px;" %> - <%= submit_tag "全站搜索", :class => "re_schbtn b_lblue",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %> + <%#= submit_tag "全站搜索", :class => "re_schbtn b_lblue",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %> <% if User.current.member_of?(@project) %> + <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :project_id => @project.id), :class => "blue-btn fr mr5", :remote => true) %> + <% end %> <% end %>
    diff --git a/app/views/files/_project_list.html.erb b/app/views/files/_project_list.html.erb index 391430126..a2a1670d1 100644 --- a/app/views/files/_project_list.html.erb +++ b/app/views/files/_project_list.html.erb @@ -1,61 +1,61 @@ -<% delete_allowed = User.current.allowed_to?(:manage_files, project) %> -<% project_attachments.each do |file| %> - <% if file.is_public? || User.current.member_of?(project) || User.current.admin? %> -
    -
    -
    - <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %> -
    -
    -
    - <%= 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 => "linkBlue f_14 f_b" %> - <%= file_preview_eye(file, class: 'preview') %> - - <% if file.is_public? == false%> - 私有 - <%end %> - -
    -
    - 上传时间:<%= format_time(file.created_on)%> - <% if file.tag_list.length > 0%> - 上传类型:<%= file.tag_list[0] %> - <% end %> -

    文件大小:<%= number_to_human_size(file.filesize) %>

    -

    下载<%= file.downloads%>  |  引用<%= file.quotes.nil? ? 0:file.quotes %>

    -
    -
    -
    - - <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> - <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> -
    -
    - <%= render :partial => 'files/tool_settings', :locals => {:project => @project, :delete_allowed => delete_allowed, :file => file} %> -
    -
    -
    -
    -
    -
    - <% else %> -
    <%= file.filename %>是私有资源
    - <% end %> -<% end %> - -<% if project_attachments.count == 10%> - <% if params[:action] == 'search_project' %> - - - - <%=link_to "点击展开更多", search_project_project_files_path({:project_id => project.id, :page => @obj_pages.nil? ? @feedback_pages.page + 1 : @obj_pages.page + 1}.merge(params)),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> - <%else%> - - <%=link_to "点击展开更多", project_files_path(:project_id => project.id,:page => @page),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> - <%end%> -<% end%> - - - +<% delete_allowed = User.current.allowed_to?(:manage_files, project) %> +<% project_attachments.each do |file| %> + <% if file.is_public? || User.current.member_of?(project) || User.current.admin? %> +
    +
    +
    + <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %> +
    +
    +
    + <%= 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" %> + <%= file_preview_eye(file, class: 'preview') %> + + <% if file.is_public? == false%> + 私有 + <%end %> + +
    +
    + 上传时间:<%= format_time(file.created_on)%> + <% if file.tag_list.length > 0%> + 上传类型:<%= file.tag_list[0] %> + <% end %> +

    文件大小:<%= number_to_human_size(file.filesize) %>

    +

    下载<%= file.downloads%>  |  引用<%= file.quotes.nil? ? 0:file.quotes %>

    +
    +
    +
    + + <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> + <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> +
    +
    + <%= render :partial => 'files/tool_settings', :locals => {:project => @project, :delete_allowed => delete_allowed, :file => file} %> +
    +
    +
    +
    +
    +
    + <% else %> +
    <%= file.filename %>是私有资源
    + <% end %> +<% end %> + +<% if project_attachments.count == 10%> + <% if params[:action] == 'search_project' %> + + + + <%=link_to "点击展开更多", search_project_project_files_path({:project_id => project.id, :page => @obj_pages.nil? ? @feedback_pages.page + 1 : @obj_pages.page + 1}.merge(params)),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> + <%else%> + + <%=link_to "点击展开更多", project_files_path(:project_id => project.id,:page => @page),:id => "show_more_attachments",:remote => "true",:class => "loadMore mt10 f_grey" %> + <%end%> +<% end%> + + + diff --git a/app/views/files/_resource_detail.html.erb b/app/views/files/_resource_detail.html.erb index fd0a165aa..317bb7dd8 100644 --- a/app/views/files/_resource_detail.html.erb +++ b/app/views/files/_resource_detail.html.erb @@ -1,77 +1,81 @@ -<% delete_allowed = User.current.allowed_to?(:manage_files, @course) %> -
    -
    -
    - <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %> -
    -
    -
    - <%= 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 => "linkBlue f_14 f_b" %> - <%= file_preview_eye(file, class: 'preview') %> - - <% if file.is_public? == false%> - 私有 - <%end %> - - <% if file.is_publish == 0 %> - <%=file.publish_time %>  0点发布 - <% end %> -
    -
    - 上传时间:<%= format_time(file.created_on)%> - <% if file.tag_list.length > 0%> - 上传类型:<%= file.tag_list[0] %> - <% end %> -

    文件大小:<%= number_to_human_size(file.filesize) %>

    -

    下载<%= file.downloads%>  |  引用<%= file.quotes.nil? ? 0:file.quotes %>

    -
    -
    -
    - - <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> - <%= 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 %> - -
      • - <%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 %> -
      • -
      - - <% end %> - <%else%> -
        -
      • <%= link_to("发  送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
      • -
      - <% end %> - <% end %> -
    • -
    - -
    -
    -
    -
    -
    +<% delete_allowed = User.current.allowed_to?(:manage_files, @course) %> +
    +
    +
    + <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %> +
    +
    +
    + <%= 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" %> + <%= file_preview_eye(file, class: 'preview') %> + + <% if file.is_public? == false%> + 私有 + <%end %> + + <% if file.is_publish == 0 %> + <%=file.publish_time %>  0点发布 + <% end %> +
    +
    + 上传时间:<%= format_time(file.created_on)%> + <% if file.tag_list.length > 0%> + 上传类型:<%= file.tag_list[0] %> + <% end %> +

    文件大小:<%= number_to_human_size(file.filesize) %>

    +

    下载<%= file.downloads%>  |  引用<%= file.quotes.nil? ? 0:file.quotes %>

    +
    + <% unless file.description.blank? %> +
    +
    资源描述:<%= file.description %>
    + <% end %> +
    +
    + + <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> + <%= 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 %> + +
      • + <%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 %> +
      • +
      + + <% end %> + <%else%> +
        +
      • <%= link_to("发  送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
      • +
      + <% end %> + <% end %> +
    • +
    + +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/files/_subfield_files.html.erb b/app/views/files/_subfield_files.html.erb index 1de0e8dc2..6531aa96b 100644 --- a/app/views/files/_subfield_files.html.erb +++ b/app/views/files/_subfield_files.html.erb @@ -1,85 +1,86 @@ -<%= stylesheet_link_tag 'courses'%> - - -
    -
    -
    <%= org_subfield.name %>
    - -
    -
    -
    - <%= form_tag( search_files_in_subfield_org_subfield_files_path(@org_subfield), method: 'get',:class => "re_search",:remote=>true) do %> - <%= text_field_tag 'name', params[:name], name: "name", :class => 'researchBox fl',:style=>"padding: 0px"%> - <%= submit_tag "栏目内搜索", :class => "blueBtn mr5 fl",:style => 'width:72px;',:name => "inorg_subfield",:id => "inorg_subfield", :onmouseover => "presscss('inorg_subfield')",:onmouseout =>"buttoncss()" %> - <%= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %> - - <%#= link_to "上传资源",subfield_upload_file_org_subfield_files_path(@org_subfield.id, :in_org => 1),:method => "post",:class=>"blueBtn fr mr5",:remote => true %> - <% end %> -
    -
    - -
    -
    -
    - <%= render :partial => "files/subfield_tags", :locals => {:tag_list => @tag_list,:org_subfield => @org_subfield,:tag_name => @tag_name}%> -
    -
    -

    共有 <%= @all_attachments.count %> 个资源

    -

    - <% if @order == "asc" %> - 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> /  - <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %> /  - <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"quotes"} %> 排序 - <% else %> - 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> /  - <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %>  /  - <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"quotes"} %> 排序 - <% end %> -

    -
    -
    -
    -
    -
    - <%= render :partial => 'files/org_subfield_list',:locals => {org_subfield: @org_subfield,all_attachments: @all_attachments,sort:@sort,order:@order,org_subfield_attachments:@obj_attachments} %> -
    - -
    -<%# html_title(l(:label_attachment_plural)) -%> - + +
    +
    +
    <%= org_subfield.name %>
    + +
    +
    +
    + <%= form_tag( search_files_in_subfield_org_subfield_files_path(@org_subfield), method: 'get',:class => "re_search",:remote=>true) do %> + <%= text_field_tag 'name', params[:name], name: "name", :class => 'researchBox fl',:style=>"padding: 0px"%> + <%= submit_tag "栏目内搜索", :class => "blueBtn mr5 fl",:style => 'width:72px;',:name => "inorg_subfield",:id => "inorg_subfield", :onmouseover => "presscss('inorg_subfield')",:onmouseout =>"buttoncss()" %> + <%#= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %> + + <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :subfield_file_id => @org_subfield.id), :class => "blue-btn fr mr5", :remote => true) %> + <%#= link_to "上传资源",subfield_upload_file_org_subfield_files_path(@org_subfield.id, :in_org => 1),:method => "post",:class=>"blueBtn fr mr5",:remote => true %> + <% end %> +
    +
    + +
    +
    +
    + <%= render :partial => "files/subfield_tags", :locals => {:tag_list => @tag_list,:org_subfield => @org_subfield,:tag_name => @tag_name}%> +
    +
    +

    共有 <%= @all_attachments.count %> 个资源

    +

    + <% if @order == "asc" %> + 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> /  + <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %> /  + <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"quotes"} %> 排序 + <% else %> + 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> /  + <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %>  /  + <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"quotes"} %> 排序 + <% end %> +

    +
    +
    +
    +
    +
    + <%= render :partial => 'files/org_subfield_list',:locals => {org_subfield: @org_subfield,all_attachments: @all_attachments,sort:@sort,order:@order,org_subfield_attachments:@obj_attachments} %> +
    + +
    +<%# html_title(l(:label_attachment_plural)) -%> + \ No newline at end of file diff --git a/app/views/files/_upload_course_files.erb b/app/views/files/_upload_course_files.erb index de43977cd..133b8b4d6 100644 --- a/app/views/files/_upload_course_files.erb +++ b/app/views/files/_upload_course_files.erb @@ -1,84 +1,92 @@ - -
    -
    -

    <%= l(:label_upload_files)%>

    -
    - <%= error_messages_for 'attachment' %> - - - <%= form_tag(course_files_path(course), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %> - - -
    - 课件 |  - 软件 |  - 媒体 |  - 代码 |  - 论文 |  - 其他 -
    -
    -
    - <%= render :partial => 'files/new_style_attachment_list',:locals => {:container => course} %> -
    -
    - <% if User.current.allowed_to?(:as_teacher,course) %> -
    - -
    - - <%#= calendar_for('attachment_publish_time')%> -
    - -
    -
    - <% end %> - <%= l(:button_cancel)%> - <%= l(:button_confirm)%> - <%#= submit_tag '确定',:onclick=>'submit_course_resource();',:onfocus=>'this.blur()',:id=>'submit_resource',:class=>'sendSourceText fr' %> - <% end %> -
    - -
    - <% content_for :header_tags do %> - <%= javascript_include_tag 'attachments' %> - <% end %> -
    - - +
    +
    +

    <%= l(:label_upload_files)%>

    +
    + <%= error_messages_for 'attachment' %> + + + <%= form_tag(course_files_path(course), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %> + + +
    + 课件 |  + 软件 |  + 媒体 |  + 代码 |  + 论文 |  + 其他 +
    +
    +
    + <%= render :partial => 'files/new_style_attachment_list',:locals => {:container => course} %> +
    +
    +
    + +
    + +
    +
    +
    + + <% if User.current.allowed_to?(:as_teacher,course) %> +
    + +
    + + <%#= calendar_for('attachment_publish_time')%> +
    + +
    +
    + <% end %> + <%= l(:button_cancel)%> + <%= l(:button_confirm)%> + <%#= submit_tag '确定',:onclick=>'submit_course_resource();',:onfocus=>'this.blur()',:id=>'submit_resource',:class=>'sendSourceText fr' %> + <% end %> +
    + +
    + <% content_for :header_tags do %> + <%= javascript_include_tag 'attachments' %> + <% end %> +
    + + \ No newline at end of file diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index d4d12232e..528265c26 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -1,480 +1,479 @@ - - <% if @container_type == 0 %> -
    - <%= render :partial => 'project_file', locals: {project: @project} %> -
    - <% elsif @container_type == 1 %> -
    - <%= render :partial => 'course_file', locals: {course: @course} %> -
    - <% elsif @container_type == 2 %> -
    - <%= render :partial => 'files/subfield_files', locals: {org_subfield: @org_subfield} %> -
    - <% end %> - - - - - - + + <% if @container_type == 0 %> +
    + <%= render :partial => 'project_file', locals: {project: @project} %> +
    + <% elsif @container_type == 1 %> +
    + <%= render :partial => 'course_file', locals: {course: @course} %> +
    + <% elsif @container_type == 2 %> +
    + <%= render :partial => 'files/subfield_files', locals: {org_subfield: @org_subfield} %> +
    + <% end %> + + + + + diff --git a/app/views/homework_common/_alert_open_student_works.html.erb b/app/views/homework_common/_alert_open_student_works.html.erb new file mode 100644 index 000000000..ef8fe3d08 --- /dev/null +++ b/app/views/homework_common/_alert_open_student_works.html.erb @@ -0,0 +1,23 @@ +
    +
    + <% if @homework.is_open == 0 %> +

    公开作品

    +

    + 本次作业的所有作品将对Trustie平台所有注册用户开放,请问是否确定公开作品? +

    + <% else %> +

    取消公开作品

    +

    + 您将取消“公开作品”的功能,本次作业的作品将不对Trustie平台其他未加入本课程的用户开放,请问是否确定? +

    + <% end %> + +
    +
    \ No newline at end of file diff --git a/app/views/homework_common/alert_open_student_works.js.erb b/app/views/homework_common/alert_open_student_works.js.erb new file mode 100644 index 000000000..591d34028 --- /dev/null +++ b/app/views/homework_common/alert_open_student_works.js.erb @@ -0,0 +1,6 @@ +$("#ajax-modal").html("<%=escape_javascript(render :partial => 'alert_open_student_works') %>"); +showModal('ajax-modal', '500px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before("" + + ""); +$('#ajax-modal').parent().css("top","30%").css("left","30%").css("position","fixed").css("border","3px solid #269ac9"); \ No newline at end of file diff --git a/app/views/homework_common/open_student_works.js.erb b/app/views/homework_common/open_student_works.js.erb new file mode 100644 index 000000000..e171e65d1 --- /dev/null +++ b/app/views/homework_common/open_student_works.js.erb @@ -0,0 +1,7 @@ +<% if @user_activity_id.to_i == -1 %> +$("#homework_common_<%= @homework.id %>").replaceWith("<%= escape_javascript(render :partial => "users/user_homework_detail",:locals => {:homework_common => @homework, :is_in_course => @is_in_course})%>"); +sd_create_editor_from_data(<%= @homework.id%>,"","100%", "<%=@homework.class.to_s%>"); +<% else %> +$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_homework', :locals => {:activity => @homework,:user_activity_id =>@user_activity_id,:course_activity=>@course_activity}) %>"); +sd_create_editor_from_data(<%= @user_activity_id%>,"","100%", "UserActivity"); +<% end %> \ No newline at end of file diff --git a/app/views/issues/_detail.html.erb b/app/views/issues/_detail.html.erb index 00aa341fe..92021f728 100644 --- a/app/views/issues/_detail.html.erb +++ b/app/views/issues/_detail.html.erb @@ -8,7 +8,7 @@ <% when 1%> <% when 2%> - + <% when 3%> <% when 4%> diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 2fa627c73..20239262f 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -1,136 +1,142 @@ - - - + + + diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 138616fda..14ed8a93b 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -1,8 +1,13 @@ <%# course_model %> <% course_file_num = visable_attachemnts_incourse(@course).count%> <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> +<% if User.current.admin? || User.current.allowed_to?(:as_teacher,@course) %> + <% homework_num = @course.homework_commons.count %> +<% else %> + <% homework_num = @course.homework_commons.where("publish_time <= '#{Date.today}'").count %> +<% end %> - + @@ -74,7 +79,7 @@ <% unless show_nav?(@course.homework_commons.count) %> <div class="subNav"> <%= link_to l(:label_homework), homework_common_index_path(:course => @course.id), :class => "f14 c_blue02"%> - <%= link_to "(#{@course.homework_commons.count})", homework_common_index_path(:course => @course.id), :class => "subnav_num c_orange"%> + <%= link_to "(#{homework_num})", homework_common_index_path(:course => @course.id), :class => "subnav_num c_orange"%> <%= link_to( "", homework_common_index_path(:course => @course.id,:is_new => 1), :class => 'courseMenuSetting', :title =>"#{l(:label_course_homework_new)}") if is_teacher %> </div> <% end %> @@ -99,7 +104,7 @@ <div class="subNav"> <%= link_to l(:label_course_board), course_boards_path(@course), :class => "f14 c_blue02" %> <%= link_to "(#{@course.boards.first ? (@course.boards.first.topics.count + Message.where("board_id =? and parent_id is not ?", @course.boards.first.id, nil).count) : 0})", course_boards_path(@course), :class => "subnav_num c_orange" %> - <%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'courseMenuSetting', :title =>"#{l(:label_message_new)}") if User.current.member_of_course?(@course) && @course.boards.first %> + <%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'courseMenuSetting', :title =>"#{l(:label_message_new)}") %> </div> <% end %> <% unless show_nav?(course_feedback_count) %> @@ -137,29 +142,60 @@ <div class="cl"></div> <% unless contributor_course_scor(@course.id).count == 0 %> <ul class="rankList"> - <h4>课程活跃度</h4> + <h4>课程活跃度 + <a class="contributor_course" onmouseover ="message_titile_show2($(this),event)" onmouseout ="message_titile_hide2($(this))">积分规则</a> + </h4> + <div style="display: none;padding: 5px;" class="numIntro color_888"> + <div class="contributor_course_innor">积分规则</div> + 资源发布:资源数 x 5 </br> + 问答发布:发帖数 x 2 </br> + 通知发布:通知数 x 1 </br> + 问答回复:回复数 x 1 </br> + 作业留言:留言数 x 1 </br> + 通知留言:留言数 x 1 </br> + 课程留言:留言数 x 1 </br> + 总得分为以上得分之和 + </div> + <% contributor_course_scor(@course.id).each do |contributor_score| %> - <% unless contributor_score.total_score ==0 %> + <% total_score = contributor_score.resource_num.to_i * 5 + contributor_score.message_num.to_i * 2 + + contributor_score.message_reply_num.to_i * 1 + contributor_score.journal_num.to_i * 1 + + + contributor_score.homework_journal_num.to_i * 1 + contributor_score.news_reply_num.to_i * 1 + + contributor_score.news_num.to_i * 1 %> + <% unless total_score ==0 %> <li> <a href="javascript:void:(0);"><%=link_to image_tag(url_to_avatar(contributor_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(contributor_score.user) %></a> <p><a href="javascript:void:(0);"><%=link_to contributor_score.user.show_name, user_path(contributor_score.user), :title => contributor_score.user.show_name %></a></p> <p><span class="c_green" style="cursor:pointer"> - <a onmouseover ="message_titile_show($(this),event)" onmouseout ="message_titile_hide($(this))" class="c_green"><%= contributor_score.total_score.to_i %></a></span></p> - <div style="display: none" class="numIntro"> - <% unless contributor_score.resource_num == 0 %> - 课程资源:<%= contributor_score.resource_num %><br /> - <% end %> - <% unless contributor_score.message_num == 0 %> - 课程讨论:<%= contributor_score.message_num %><br /> - <% end %> - <% unless contributor_score.message_reply_num == 0 %> - 评论回复:<%= contributor_score.message_reply_num %><br /> - <% end %> - <% unless contributor_score.journal_num == 0 %> - 课程留言:<%= contributor_score.journal_num %><br /> - <% end %> - <% unless contributor_score.news_reply_num == 0 %> - 课程通知:<%= contributor_score.news_reply_num %><br /> - <% end %> + <a onmouseover ="message_titile_show($(this),event)" onmouseout ="message_titile_hide($(this))" class="c_green"> + <%=total_score %></a></span></p> + <div style="display: none" class="numIntro color_888"> + <div class="contributor_course_calculate">积分计算</div> + <%# unless contributor_score.resource_num.to_i == 0 %> + <div style="padding-left: 2px;padding-bottom: 2px;padding-right: 2px"> + 资源发布数 x 5 = <%= contributor_score.resource_num.to_i %> x 5 = <%= contributor_score.resource_num.to_i * 5 %></br> + <%# end %> + <%# unless contributor_score.message_num.to_i == 0 %> + 问答发布数 x 2 = <%= contributor_score.message_num.to_i %> x 2 = <%= contributor_score.message_num.to_i * 2 %></br> + 通知发布数 x 1 = <%= contributor_score.news_num.to_i %> x 1 = <%= contributor_score.news_num.to_i %></br> + <%# end %> + <%# unless contributor_score.message_reply_num.to_i == 0 %> + 问答回帖数 x 1 = <%= contributor_score.message_reply_num.to_i %> x 1 = <%= contributor_score.message_reply_num.to_i %></br> + 作业留言数 x 1 = <%= contributor_score.homework_journal_num.to_i %> x 1 = <%= contributor_score.homework_journal_num.to_i %></br> + 通知留言数 x 1 = <%= contributor_score.news_reply_num.to_i %> x 1 = <%= contributor_score.news_reply_num.to_i %></br> + <%# end %> + <%# unless contributor_score.journal_num.to_i == 0 %> + 课程留言数 x 1 = <%= contributor_score.journal_num.to_i %> x 1 = <%= contributor_score.journal_num.to_i %></br> + <%# end %> + <%# unless contributor_score.homework_journal_num.to_i == 0 %> + + <%# end %> + <%# unless contributor_score.news_reply_num.to_i == 0 %> + + + <%# end %> + 总得分:<%=total_score %> + </div> + </div> </li> <% end %> @@ -171,12 +207,17 @@ <% hero_homework_scores = hero_homework_score(@course, "desc") %> <% unless hero_homework_scores.map(&:score).detect{|s| s.to_i != 0}.nil? %> <ul class="rankList"> - <h4>课程英雄榜</h4> + <h4><span>课程英雄榜</span> + <a class="contributor_course" onmouseover ="message_titile_show2($(this),event)" onmouseout ="message_titile_hide2($(this))">积分规则</a></h4> + <div style="display: none" class="numIntro color_888"> + <div class="hero_course_innor">积分规则</div> + 英雄榜的得分是每个同学作业的得分总和 + </div> <% hero_homework_scores.each do |student_score| %> <% if student_score.score.to_i != 0 %> <li> <a href="javascript:void:(0);"><%=link_to image_tag(url_to_avatar(student_score.user), :width => "35", :height => "35", :class=> "rankPortrait"),user_path(student_score.user) %></a> <p><a href="javascript:void:(0);"><%=link_to student_score.user.show_name, user_path(student_score.user), :title => student_score.user.show_name %></a></p> - <p><span class="c_red" style="cursor:pointer" title="作业总分:<%= student_score.score %>"><%= student_score.score.to_i %></span></p> + <p><span class="c_red" style="cursor:pointer" ><%= student_score.score<0 ? 0 : student_score.score.to_i %></span></p> </li> <% end %> <% end %> @@ -295,6 +336,16 @@ obj.parent().parent().next("div").hide(); } + function message_titile_show2(obj,e) + { + obj.parent().next("div").show(); + obj.parent().next("div").css("top",e.pageY).css("left",e.pageX).css("position","absolute"); + } + function message_titile_hide2(obj) + { + obj.parent().next("div").hide(); + } + $("#expand_tools_expand").click(function(){ $("#navContentCourse").toggle(); }); diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index 657873f8b..c30d1b4ed 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -12,7 +12,7 @@ <%= favicon %> <%= javascript_heads %> <%= heads_for_theme %> - <%= stylesheet_link_tag 'header','public', 'pleft', 'project','prettify','jquery/jquery-ui-1.9.2','repository','share' %> + <%= stylesheet_link_tag 'header','scm','public', 'pleft', 'project','prettify','jquery/jquery-ui-1.9.2','repository','share' %> <%= javascript_include_tag 'cookie','project', 'header','prettify','select_list_move','attachments' %> <%= call_hook :view_layouts_base_html_head %> @@ -66,7 +66,7 @@ <!-- 项目得分 --> <div class="cl"></div> <div> - <%= link_to l(:label_project_name)+"#{@project.name}", project_path(@project.id), :class=>"pr_info_name fl c_dark fb break_word" %> + <%= link_to "#{@project.name}", project_path(@project.id), :class=>"pr_info_name fl c_dark fb break_word" %> <% if @project.is_public? %> <span class="img_private"><%= l(:label_public)%></span> <% else %> diff --git a/app/views/layouts/static_base.html.erb b/app/views/layouts/static_base.html.erb index f73d1bc61..096b1699b 100644 --- a/app/views/layouts/static_base.html.erb +++ b/app/views/layouts/static_base.html.erb @@ -1,53 +1,56 @@ -<!DOCTYPE html> -<html lang="<%= current_language %>"> -<head> - <meta charset="utf-8" /> - <title><%=h html_title %> - - - <%= csrf_meta_tag %> - <%= favicon %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', 'nyan','prettify', :media => 'all' %> - <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> - <%= javascript_heads %> - <%= javascript_include_tag "jquery.leanModal.min",'prettify' %> - <%= javascript_include_tag 'seems_rateable/jRating', 'seems_rateable/rateable'%> - <%= heads_for_theme %> - <%= call_hook :view_layouts_base_html_head %> - - <%= yield :header_tags -%> - <%= stylesheet_link_tag 'base','header', :media => 'all'%> - - - - - - -
    - -
    -
    - <%= yield %> -
    -
    -
    -<%= render :partial => 'layouts/footer' %> -
    - -<%= call_hook :view_layouts_base_body_bottom %> - - + + + + + <%=h html_title %> + + + <%= csrf_meta_tag %> + <%= favicon %> + <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', 'nyan','prettify', :media => 'all' %> + <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> + <%= javascript_heads %> + <%= javascript_include_tag "jquery.leanModal.min",'prettify' %> + <%= javascript_include_tag 'seems_rateable/jRating', 'seems_rateable/rateable'%> + <%= heads_for_theme %> + <%= call_hook :view_layouts_base_html_head %> + + <%= yield :header_tags -%> + <%= stylesheet_link_tag 'base','header', :media => 'all'%> + + + + + + +
    + +
    +
    + <%= yield %> +
    +
    +
    +<%= render :partial => 'layouts/footer' %> +
    + + +<%= call_hook :view_layouts_base_body_bottom %> + + diff --git a/app/views/org_document_comments/_new.html.erb b/app/views/org_document_comments/_new.html.erb index 3d8e8bc23..9e77d3fa8 100644 --- a/app/views/org_document_comments/_new.html.erb +++ b/app/views/org_document_comments/_new.html.erb @@ -1,8 +1,12 @@ <%= content_for(:header_tags) do %> <%= import_ke(enable_at: false, prettify: false, init_activity: false) %> + <%= javascript_include_tag "des_kindEditor" %> <% end %> -<%= form_tag organization_org_document_comments_path(:organization_id => @organization.id), :id => 'new_org_document_form' do |f| %> -
    +
    + <%= form_tag organization_org_document_comments_path(:organization_id => @organization.id), :id => 'new_org_document_form' do |f| %>
    @@ -41,10 +45,10 @@
    + <% end %>
    -<% end %> \ No newline at end of file diff --git a/app/views/org_document_comments/edit.html.erb b/app/views/org_document_comments/edit.html.erb index a6681d047..ed7413850 100644 --- a/app/views/org_document_comments/edit.html.erb +++ b/app/views/org_document_comments/edit.html.erb @@ -31,7 +31,7 @@
    -
    +
    <%#= kindeditor_tag 'org_document_comment[content]','', :editor_id => 'org_document_description_editor', :height => "150px" %> diff --git a/app/views/org_document_comments/new.html.erb b/app/views/org_document_comments/new.html.erb index c95cfe805..2a261bd5f 100644 --- a/app/views/org_document_comments/new.html.erb +++ b/app/views/org_document_comments/new.html.erb @@ -39,7 +39,7 @@
    -
    +
    <%#= kindeditor_tag 'org_document_comment[content]','', :editor_id => 'org_document_description_editor', :height => "150px" %> diff --git a/app/views/org_subfields/_show_details.html.erb b/app/views/org_subfields/_show_details.html.erb index 3a605f75d..f7f5d0748 100644 --- a/app/views/org_subfields/_show_details.html.erb +++ b/app/views/org_subfields/_show_details.html.erb @@ -42,7 +42,7 @@ }); <% if act.container_type == 'Organization' %> - <% if act.org_act_type == 'OrgDocumentComment' && act.org_act_id != @organization.home_id %> + <% if act.org_act_type == 'OrgDocumentComment' %> <%= render :partial => 'organizations/show_org_document', :locals => {:document => act.org_act, :act => act, :flag => 2, :org_subfield_id => params[:org_subfield_id]} %> <% end %> <% end %> diff --git a/app/views/organizations/_org_course_homework.html.erb b/app/views/organizations/_org_course_homework.html.erb index b5e3c6958..51cede682 100644 --- a/app/views/organizations/_org_course_homework.html.erb +++ b/app/views/organizations/_org_course_homework.html.erb @@ -1,352 +1,370 @@ -<% is_teacher = User.current.allowed_to?(:as_teacher,activity.course) %> -
    -
    -
    - <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user_id), :alt => "用户头像" %> - <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.user} %> -
    -
    -
    - <% if activity.try(:user).try(:realname) == ' ' %> - <%= link_to activity.try(:user), user_path(activity.user_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> - <% else %> - <%= link_to activity.try(:user).try(:realname), user_path(activity.user_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> - <% end %> TO - <%= link_to activity.course.name.to_s+" | 课程作业", homework_common_index_path(:course => activity.course.id, :host=> Setting.host_course), :class => "newsBlue ml15"%> -
    - - <% if activity.homework_detail_manual%> - <% if activity.homework_detail_manual.comment_status == 1%> - <% if activity.anonymous_comment == 0%> - 未开启匿评 - <% else %> - 匿评已禁用 - <% end %> - <% if Time.parse(activity.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")%> - 作品提交中 - <% elsif Time.parse(activity.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") %> - 作品补交中 - <% end %> - <% elsif activity.homework_detail_manual.comment_status == 2%> - <% if activity.anonymous_comment == 0%> - 匿评中 - <% else %> - 匿评已禁用 - <% end %> - 教师评阅中 - <% elsif activity.homework_detail_manual.comment_status == 3%> - <% if activity.anonymous_comment == 0%> - 匿评已结束 - <% else %> - 匿评已禁用 - <% end %> - 教师评阅中 - <% end%> - <% end%> -
    - <% if activity.homework_type == 3 && activity.homework_detail_group.base_on_project == 1%> - 系统提示:该作业要求各组长<%=link_to "创建项目", new_project_path(:host=>Setting.host_name),:class=>"c_red",:title=>"新建项目",:style=>"text-decoration:underline;"%>,组成员加入项目,然后由组长关联项目。谢谢配合! - <% elsif activity.homework_type == 3 && activity.homework_detail_group.base_on_project == 0%> - 系统提示:该作业要求各组长提交作品,提交作品时请添加组成员。谢谢配合! - <% end %> -
    - <% if activity.homework_type == 3 && !is_teacher && activity.homework_detail_group.base_on_project == 1 && User.current.member_of_course?(activity.course)%> - <% projects = cur_user_projects_for_homework activity %> - <% works = cur_user_works_for_homework activity %> - <% if works.nil? && projects.nil? %> -
    - <%=link_to "关联项目",new_student_work_project_student_work_index_path(:homework => activity.id,:is_in_course=>-1,:user_activity_id=>user_activity_id,:course_activity=>course_activity),remote: true,:class=> 'c_blue', :title=> '请各组长关联作业项目' %> - <%#= relate_project(activity,is_teacher,-1,user_activity_id,course_activity) %> -
    - <% elsif works.nil? %> -
    - <%=link_to "取消关联",cancel_relate_project_student_work_index_path(:homework => activity.id,:is_in_course=>-1,:user_activity_id=>user_activity_id,:course_activity=>course_activity), :confirm => "您确定要取消关联吗?", remote: true,:class => "c_blue", :title=> '取消关联项目' %> -
    - <% end %> - <% end %> -
    - <% is_teacher = User.current.allowed_to?(:as_teacher,activity.course) %> - <%= user_for_homework_common activity,is_teacher %> -
    - - <% if activity.homework_type == 2 && is_teacher%> -
    - <%= link_to "模拟答题", new_user_commit_homework_users_path(homework_id: activity.id, is_test: true), class: 'c_blue test-program-btn', title: '教师可以通过模拟答题设置作业的标准答案' %> -
    - <% end %> - <% if activity.homework_type == 2%> -
    - 语言: - <%= activity.language_name%> -
    - <% end %> - <% if activity.homework_type == 3 && activity.homework_detail_group%> -
    - 分组人数:<%=activity.homework_detail_group.min_num %>-<%=activity.homework_detail_group.max_num %> 人 -
    - <% end %> - <% if activity.homework_detail_manual && activity.homework_detail_manual.comment_status < 2 %> -
    提交截止时间:<%= activity.end_time.to_s %> 23:59
    - <% elsif activity.homework_detail_manual && activity.homework_detail_manual.comment_status >= 2 %> -
    匿评截止时间:<%= activity.homework_detail_manual.evaluation_end.to_s %> 23:59
    - <% end %> -
    - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> - -
    - - -
    -
    - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
    -
    -
    - 迟交扣分:<%= activity.late_penalty%>分 -
    - <% if activity.anonymous_comment == 0%> -
    - 匿评开启时间:<%= activity.homework_detail_manual.evaluation_start%> 00:00 -
    - <% end %> -
    -
    -
    -
    - 缺评扣分:<%= activity.homework_detail_manual.absence_penalty%>分/作品 -
    - <% if activity.anonymous_comment == 0%> -
    - 匿评关闭时间:<%= activity.homework_detail_manual.evaluation_end%> 23:59 -
    - <% end %> -
    -
    - <% if activity.student_works.count != 0 %> - <% sw = activity.student_works.reorder("created_at desc").first %> -
    - # <%=time_from_now sw.created_at %><%= link_to sw.user.show_name, user_activities_path(sw.user_id), :class => "newsBlue ml5 mr5"%>提交了作品 -
    - <% end %> -
    - <% if activity.student_works.count != 0 %> - <% sw_id = "("+activity.student_works.map{|sw| sw.id}.join(",")+")" %> - <% student_work_scores = StudentWorksScore.find_by_sql("select max(created_at) as created_at, student_work_id, user_id from student_works_scores where student_work_id in #{sw_id} group by student_work_id order by max(created_at) desc") %> - <%# student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id}").reorder("created_at desc") %> - <% unless student_work_scores.empty? %> - <% last_score = student_work_scores.first %> -
    -

    # <%=time_from_now last_score.created_at %> - <%= link_to last_score.user.show_name, user_activities_path(last_score.user_id), :class => "newsBlue ml5 mr5"%>评阅了作品,优秀排行: -

    - <% ids = '('+student_work_scores.map{|sw|sw.student_work_id}.join(',')+')' %> - <% student_works = activity.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where("student_works.id in #{ids}").order("score desc") %> - <% student_works.each_with_index do |sw, i| %> -
    - <%= link_to image_tag(url_to_avatar(User.find sw.user_id), :width => "40", :height => "40"), student_work_index_path(:homework => activity.id), :alt => "学生头像" %> - - - <% score = sw.respond_to?("score") ? sw.score : (sw.final_score || 0) - sw.absence_penalty - sw.late_penalty %> -

    分数:<%=format("%.1f",score<0 ? 0 : score) %>分

    -
    - <% if i == 4 %> - <% break %> - <% end %> - <% end %> - <% if student_works.count > 5 %> - <%= link_to "更多>>", student_work_index_path(:homework => activity.id),:class=>'linkGrey2 fl ml50',:style=>'margin-top:60px;'%> - <% end %> -
    -
    - <% end %> - <% end %> -
    - <% if activity.homework_type == 3 && activity.homework_detail_group.base_on_project == 1 %> - <% projects = activity.student_work_projects.where("is_leader = 1") %> - <% unless projects.empty? %> - <% sort_projects = project_sort_update projects %> -
    -
    - # <%=time_from_now sort_projects.first.updated_at %><%= link_to User.find(sort_projects.first.user_id).show_name, user_activities_path(sort_projects.first.user_id), :class => "newsBlue ml5 mr5"%>更新了项目,最近更新: -
    -
    - <% sort_projects.each_with_index do |pro, i| %> - <% project = Project.find pro.project_id %> - - -
    - <% if project.is_public || User.current.member_of?(project) || User.current.admin? %> - <%= link_to image_tag(url_to_avatar(project),:width=>"40",:height => "40",:class => "borderRadius"),project_path(project.id,:host=>Setting.host_name),:id=>"project_img_"+project.id.to_s+"_"+activity.id.to_s,:alt =>"项目头像" %> - <% else %> - <%= image_tag(url_to_avatar(project),:width=>"40",:height => "40",:class => "borderRadius",:id=>"project_img_"+project.id.to_s+"_"+activity.id.to_s,:alt =>"项目头像") %> - <% end %> - <% com_time = project.project_score.commit_time %> - <% time=project.updated_on %> - <% time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %> -

    <%=(User.find project.user_id).show_name %>(组长)

    -

    <%=time_from_now !com_time.nil? && format_time(com_time) > format_time(time) ? com_time : time %>  <%= project.project_score.changeset_num %>提交

    -
    - 项目名称:<%=project.name %>
    - 创建者:<%=(User.find project.user_id).show_name %>(组长)
    - 更新时间:<%=time_from_now time %> -
    -
    - <% if i == 9 && projects.count > 10 %> - 更多>> - <% end %> - <% if i > 9 && i == (projects.count - 1) %> - 收回<< - <% end %> - <% end %> -
    - <% end %> - <% end %> -
    - <% if is_teacher%> - <% comment_status = activity.homework_detail_manual.comment_status %> -
    -
      -
    • -
        -
      • - <%= link_to l(:button_edit),edit_homework_common_path(activity,:is_in_course => -1,:course_activity=>course_activity), :class => "postOptionLink"%> -
      • -
      • - <%= link_to(l(:label_bid_respond_delete), homework_common_path(activity,:is_in_course => -1,:course_activity=>course_activity),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "postOptionLink") %> -
      • -
      • - <%= link_to("评分设置", score_rule_set_homework_common_path(activity,:user_activity_id => user_activity_id, :is_in_course => 0),:class => "postOptionLink", :remote => true) %> -
      • - <% if activity.anonymous_comment == 0 %> -
      • - <%= link_to("匿评设置", start_evaluation_set_homework_common_path(activity),:class => "postOptionLink", :remote => true) if activity.homework_detail_manual.comment_status == 1%> -
      • -
      • - <%= homework_anonymous_comment activity,-1,user_activity_id,course_activity %> -
      • - <% end %> - <% if activity.anonymous_comment == 0 && (comment_status == 0 || comment_status == 1)%> -
      • - <%= link_to("禁用匿评", alert_forbidden_anonymous_comment_homework_common_path(activity,:user_activity_id => user_activity_id,:course_activity=>course_activity),:class => "postOptionLink", :remote => true)%> -
      • - <% end %> -
      -
    • -
    -
    - <% end%> -
    -
    -
    - - <% count=activity.journals_for_messages.count %> -
    -
    -
    回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.user == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
    -
    - <%if count>3 %> - - <% end %> -
    - - <% replies_all_i = 0 %> - <% if count > 0 %> -
    -
      - <% activity.journals_for_messages.reorder("created_on desc").each do |comment| %> - - <% replies_all_i = replies_all_i + 1 %> -
    • -
      - <%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %> -
      -
      -
      - <% if comment.try(:user).try(:realname) == ' ' %> - <%= link_to comment.try(:user), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to comment.try(:user).try(:realname), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(comment.created_on) %> - - <% if comment.user == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> - <% end %> - - -
      -
      - <%= comment.notes.html_safe %>
      -
      -
      -
    • - <% end %> -
    -
    - <% end %> - -
    -
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
    -
    -
    - <%= form_for('new_form',:url => {:controller => 'words', :action => 'leave_homework_message', :id => activity.id},:method => "post", :remote => true) do |f|%> - <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %> - <%= hidden_field_tag 'course_activity',params[:course_activity],:value =>course_activity %> -
    - - -
    -

    - <% end%> -
    -
    -
    -
    -
    -
    -
    - + +
    + <% if project.is_public || User.current.member_of?(project) || User.current.admin? %> + <%= link_to image_tag(url_to_avatar(project),:width=>"40",:height => "40",:class => "borderRadius"),project_path(project.id,:host=>Setting.host_name),:id=>"project_img_"+project.id.to_s+"_"+activity.id.to_s,:alt =>"项目头像" %> + <% else %> + <%= image_tag(url_to_avatar(project),:width=>"40",:height => "40",:class => "borderRadius",:id=>"project_img_"+project.id.to_s+"_"+activity.id.to_s,:alt =>"项目头像") %> + <% end %> + <% com_time = project.project_score.commit_time %> + <% time=project.updated_on %> + <% time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %> +

    <%=(User.find project.user_id).show_name %>(组长)

    +

    <%=time_from_now !com_time.nil? && format_time(com_time) > format_time(time) ? com_time : time %>  <%= project.project_score.changeset_num %>提交

    +
    + 项目名称:<%=project.name %>
    + 创建者:<%=(User.find project.user_id).show_name %>(组长)
    + 更新时间:<%=time_from_now time %> +
    +
    + <% if i == 9 && projects.count > 10 %> + 更多>> + <% end %> + <% if i > 9 && i == (projects.count - 1) %> + 收回<< + <% end %> + <% end %> +
    + <% end %> + <% end %> +
    + <% if is_teacher%> + <% comment_status = activity.homework_detail_manual.comment_status %> +
    +
      +
    • +
        +
      • + <%= link_to l(:button_edit),edit_homework_common_path(activity,:is_in_course => -1,:course_activity=>course_activity), :class => "postOptionLink"%> +
      • +
      • + <%= link_to(l(:label_bid_respond_delete), homework_common_path(activity,:is_in_course => -1,:course_activity=>course_activity),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "postOptionLink") %> +
      • +
      • + <%= link_to("评分设置", score_rule_set_homework_common_path(activity,:user_activity_id => user_activity_id, :is_in_course => 0),:class => "postOptionLink", :remote => true) %> +
      • + <% if activity.anonymous_comment == 0 %> +
      • + <%= link_to("匿评设置", start_evaluation_set_homework_common_path(activity),:class => "postOptionLink", :remote => true) if activity.homework_detail_manual.comment_status == 1%> +
      • +
      • + <%= homework_anonymous_comment activity,-1,user_activity_id,course_activity %> +
      • + <% end %> + <% if activity.anonymous_comment == 0 && (comment_status == 0 || comment_status == 1)%> +
      • + <%= link_to("禁用匿评", alert_forbidden_anonymous_comment_homework_common_path(activity,:user_activity_id => user_activity_id,:course_activity=>course_activity),:class => "postOptionLink", + :title => "匿评是同学之间的双盲互评过程:每个同学将评阅系统分配给他/她的若干个作品",:remote => true)%> +
      • + <% end %> + <% if (activity.anonymous_comment == 1 && activity.is_open == 0) || (activity.anonymous_comment == 0 && comment_status == 3 && activity.is_open == 0) %> +
      • + <%= link_to("公开作品", alert_open_student_works_homework_common_path(activity,:user_activity_id => user_activity_id, :is_in_course => -1,:course_activity=>course_activity),:class => "postOptionLink", :remote => true)%> +
      • + <% elsif activity.is_open == 1 %> +
      • + <%= link_to("取消公开", alert_open_student_works_homework_common_path(activity,:user_activity_id => user_activity_id, :is_in_course => -1,:course_activity=>course_activity),:class => "postOptionLink", :remote => true)%> +
      • + <% end %> +
      +
    • +
    +
    + <% end%> +
    +
    +
    + + <% count=activity.journals_for_messages.count %> +
    +
    +
    回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.user == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
    +
    + <%if count>3 %> + + <% end %> +
    + + <% replies_all_i = 0 %> + <% if count > 0 %> +
    +
      + <% activity.journals_for_messages.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
    • +
      + <%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %> +
      +
      +
      + <% if comment.try(:user).try(:realname) == ' ' %> + <%= link_to comment.try(:user), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:user).try(:realname), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> + + <% if comment.user == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + <% end %> + + +
      +
      + <%= comment.notes.html_safe %>
      +
      +
      +
    • + <% end %> +
    +
    + <% end %> + +
    +
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
    +
    +
    + <%= form_for('new_form',:url => {:controller => 'words', :action => 'leave_homework_message', :id => activity.id},:method => "post", :remote => true) do |f|%> + <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %> + <%= hidden_field_tag 'course_activity',params[:course_activity],:value =>course_activity %> +
    + + +
    +

    + <% end%> +
    +
    +
    +
    +
    +
    +
    + \ No newline at end of file diff --git a/app/views/organizations/_org_course_message.html.erb b/app/views/organizations/_org_course_message.html.erb index 4f13e1b4f..7eee53d02 100644 --- a/app/views/organizations/_org_course_message.html.erb +++ b/app/views/organizations/_org_course_message.html.erb @@ -1,159 +1,159 @@ -
    -
    -
    - <%= 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.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 %> - TO - <%= link_to activity.course.name.to_s+" | 课程讨论区", course_boards_path(activity.course,:host=> Setting.host_course), :class => "newsBlue ml15 mr5"%> -
    - - <% if activity.sticky == 1%> - 置顶 - <% end%> - <% if activity.locked%> -        - <% end%> -
    -
    - 发帖时间:<%= format_time(activity.created_on) %> -
    -
    - 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> -
    -
    - <% if activity.parent_id.nil? %> - <% content = activity.content%> - <% else %> - <% content = activity.parent.content%> - <% end %> - <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> - -
    - - -
    -
    - <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> -
    - -
    -
    -
    - <% count=0 %> - <% if activity.parent %> - <% count=activity.parent.children.count%> - <% else %> - <% count=activity.children.count%> - <% end %> -
    -
    -
    回复 - <%= count>0 ? "(#{count})" : "" %> - - <% if activity.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> - <% end %> - -
    -
    <%#=format_date(activity.updated_on)%>
    - <%if count > 3 %> - - <% end %> -
    - - <% activity= activity.parent ? activity.parent : activity%> - <% replies_all_i = 0 %> - <% if count > 0 %> -
    -
      - <% activity.children.reorder("created_on desc").each do |reply|%> - - <% replies_all_i=replies_all_i+1 %> -
    • -
      - <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id,:host=>Setting.host_user), :alt => "用户头像" %> -
      -
      -
      - <% if reply.try(:author).try(:realname) == ' ' %> - <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(reply.created_on) %> - - <% if reply.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> - <% end %> - -
      -
      - <%= reply.content.html_safe %> -
      -
      -
      -
    • - <% end %> -
    -
    - <% end %> - - <% if !activity.locked? && authorize_for_course('messages', 'reply') %> -
    -
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
    -
    -
    - <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => 'true'},:method => "post", :remote => true) do |f|%> - - -
    - - -
    -

    - <% end%> -
    -
    -
    -
    -
    -
    - <% 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.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 %> + TO + <%= link_to activity.course.name.to_s+" | 课程问答区", course_boards_path(activity.course,:host=> Setting.host_course), :class => "newsBlue ml15 mr5"%> +
    + + <% if activity.sticky == 1%> + 置顶 + <% end%> + <% if activity.locked%> +        + <% end%> +
    +
    + 发帖时间:<%= format_time(activity.created_on) %> +
    +
    + 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> +
    +
    + <% if activity.parent_id.nil? %> + <% content = activity.content%> + <% else %> + <% content = activity.parent.content%> + <% end %> + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> + +
    + + +
    +
    + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
    + +
    +
    +
    + <% count=0 %> + <% if activity.parent %> + <% count=activity.parent.children.count%> + <% else %> + <% count=activity.children.count%> + <% end %> +
    +
    +
    回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
    +
    <%#=format_date(activity.updated_on)%>
    + <%if count > 3 %> + + <% end %> +
    + + <% activity= activity.parent ? activity.parent : activity%> + <% replies_all_i = 0 %> + <% if count > 0 %> +
    +
      + <% activity.children.reorder("created_on desc").each do |reply|%> + + <% replies_all_i=replies_all_i+1 %> +
    • +
      + <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id,:host=>Setting.host_user), :alt => "用户头像" %> +
      +
      +
      + <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(reply.created_on) %> + + <% if reply.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> + <% end %> + +
      +
      + <%= reply.content.html_safe %> +
      +
      +
      +
    • + <% end %> +
    +
    + <% end %> + + <% if !activity.locked? && authorize_for_course('messages', 'reply') %> +
    +
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
    +
    +
    + <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => 'true'},:method => "post", :remote => true) do |f|%> + + +
    + + +
    +

    + <% end%> +
    +
    +
    +
    +
    +
    + <% end %> +
    +
    diff --git a/app/views/projects/member.html.erb b/app/views/projects/member.html.erb index e6760d3b3..eb2dcacbc 100644 --- a/app/views/projects/member.html.erb +++ b/app/views/projects/member.html.erb @@ -1,8 +1,13 @@ -
    -

    <%= @subPage_title %>

    -
    -
    - <%= error_messages_for 'member' %> - <%= render :partial => @render_file, :locals => {:members => @members} %> -
    - +
    +

    <%= @subPage_title%>

    + <% if is_project_manager?(User.current, @project) %> + + <%=link_to "成员管理", :controller => 'projects', :action => 'settings', :id => @project.id, :tab => 'members' %> + + <% end %> +
    +
    + <%= error_messages_for 'member' %> + <%= render :partial => @render_file, :locals => {:members => @members} %> +
    + diff --git a/app/views/projects/settings.html.erb b/app/views/projects/settings.html.erb index 76258b9e9..fc9beae35 100644 --- a/app/views/projects/settings.html.erb +++ b/app/views/projects/settings.html.erb @@ -1,126 +1,126 @@ - - -
    -

    配置

    -
    - - - + + +
    +

    配置

    +
    + + + diff --git a/app/views/projects/settings/_new_edit.html.erb b/app/views/projects/settings/_new_edit.html.erb index 1d204a52b..eef87bc9b 100644 --- a/app/views/projects/settings/_new_edit.html.erb +++ b/app/views/projects/settings/_new_edit.html.erb @@ -18,6 +18,13 @@
    + <% if !@project.gpid.nil? && !@gitlab_branches.blank? %> +
  • + + <%= select_tag :branch, options_for_select(["#{@gitlab_default_branch}"]+ @branch_names, @rev), :id => 'branch' %> +
  • + <% end %> +
  • > diff --git a/app/views/projects/settings/_new_repositories.html.erb b/app/views/projects/settings/_new_repositories.html.erb index 43535153d..07b2896eb 100644 --- a/app/views/projects/settings/_new_repositories.html.erb +++ b/app/views/projects/settings/_new_repositories.html.erb @@ -46,9 +46,9 @@ *<%=l(:label_repository_name)%>: <%= f.text_field :identifier, :disabled =>@repository.nil? || @repository.identifier_frozen? ? true:false,:label=>"", :no_label => true %> - <% unless @repository.identifier_frozen? %> + <%# unless @repository.identifier_frozen? %> <%=l(:text_length_between,:min=>1,:max=>254)< - <% end %> + <%# end %>
  • diff --git a/app/views/repositories/_commit_details.html.erb b/app/views/repositories/_commit_details.html.erb new file mode 100644 index 000000000..ef8faecd7 --- /dev/null +++ b/app/views/repositories/_commit_details.html.erb @@ -0,0 +1,15 @@ +
    + <% if !user_commit_rep(changeset.author_email).nil? %> + + <%= image_tag(url_to_avatar(user_commit_rep(changeset.author_email)), :width => "20", :height => "20", :class => "fl portraitRadius mt2 ml4 mr5") %> + <%= link_to user_commit_rep(changeset.author_email), user_path(user_commit_rep(changeset.author_email)), :length => 30 %>提交于 +
    +   +
    + <% else %> + <%= changeset.author_email %>提交于 +
    +   +
    + <% end %> +
    \ No newline at end of file diff --git a/app/views/repositories/_dir_list_content.html.erb b/app/views/repositories/_dir_list_content.html.erb index 81706c25e..dda0cddbd 100644 --- a/app/views/repositories/_dir_list_content.html.erb +++ b/app/views/repositories/_dir_list_content.html.erb @@ -24,10 +24,10 @@ <% if @repository.report_last_commit %> -<%= link_to_revision(entry.changeset, @repository) if entry.changeset %> -<%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %> -<%= entry.author %> -<%=h truncate(entry.changeset.comments, :length => 50) if entry.changeset %> + <%= link_to_revision(entry.changeset, @repository) if entry.changeset %> + <%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %> + <%= entry.author %> + <%=h truncate(entry.changeset.comments, :length => 50) if entry.changeset %> <% end %> <% end %> diff --git a/app/views/repositories/_navigation.html.erb b/app/views/repositories/_navigation.html.erb index c3e154f17..d99df5ed1 100644 --- a/app/views/repositories/_navigation.html.erb +++ b/app/views/repositories/_navigation.html.erb @@ -18,7 +18,7 @@ <% if !@repository.branches.nil? && @repository.branches.length > 0 -%> <%= l(:label_branch) %>: - <%= select_tag :branch, options_for_select([''] + @repository.branches, @rev), :id => 'branch' %> + <%= select_tag :branch, options_for_select(@repository.branches, @rev), :id => 'branch' %> <% end -%> <% if !@repository.tags.nil? && @repository.tags.length > 0 -%> diff --git a/app/views/repositories/_revisions.html.erb b/app/views/repositories/_revisions.html.erb index 4d6e39f88..a27789dc1 100644 --- a/app/views/repositories/_revisions.html.erb +++ b/app/views/repositories/_revisions.html.erb @@ -20,27 +20,13 @@
    • -
      - <% if !user_commit_rep(changeset.author_email).nil? %> - - <%= image_tag(url_to_avatar(user_commit_rep(changeset.author_email)), :width => "20", :height => "20", :class => "fl portraitRadius mt2 ml4 mr5") %> - <%= link_to user_commit_rep(changeset.author_email), user_path(user_commit_rep(changeset.author_email)), :length => 30 %>提交于 -
      -   -
      - <% else %> - <%= changeset.author_email %>提交于 -
      -   -
      - <% end %> -
      + <%= render :partial => 'commit_details', :locals => {:changeset => changeset} %>
      <%= textilizable(truncate_at_line_break(changeset.message)) %>
      - <%= h truncate(changeset.short_id.to_s, :length => 20) %> + <%= link_to truncate(changeset.short_id.to_s, :length => 20), {:controller => 'repositories', :action => 'commit_diff', :id => project.id, :changeset => changeset.id} %>
      diff --git a/app/views/repositories/changes.html.erb b/app/views/repositories/changes.html.erb index 3780df172..726d5d19d 100644 --- a/app/views/repositories/changes.html.erb +++ b/app/views/repositories/changes.html.erb @@ -15,7 +15,7 @@
      - <%= render(:partial => 'revisions', :locals => {:project => @project, :path => @path ,:revisions => @commits, :entry => @entry ,:commits_pages =>@commits_pages , :commits_count => @commits_count}) unless @commits.empty? %> + <%= render(:partial => 'revisions', :locals => {:project => @project, :path => @path , :revisions => @commits, :entry => @entry , :commits_pages => @commits_pages , :commits_count => @commits_count}) unless @commits.empty? %>
      <% content_for :header_tags do %> diff --git a/app/views/repositories/commit_diff.html.erb b/app/views/repositories/commit_diff.html.erb new file mode 100644 index 000000000..5ebeec09a --- /dev/null +++ b/app/views/repositories/commit_diff.html.erb @@ -0,0 +1,55 @@ +
      +

      <%= render :partial => 'breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %>

      +
      + + + + + + + +
    • + <%= render :partial => 'commit_details', :locals => {:changeset => @commit_details} %> +
    • +
    +
    <%= @commit_details.message %>
    + + + + + + + + +<% @commit_diff.each do |cd| %> + +
    + + + <% line_num = diff_line_num(cd.diff) %> + <% diff_content = diff_content(cd.diff) %> + <% syntax_highlight_lines(cd.new_path, Redmine::CodesetUtil.to_utf8_by_setting(diff_content)).each do |line| %> + + + <% if line[0,1] == "-" %> + + <% elsif line[0,1] == "+" %> + + <% else%> + + <% end %> + + <% line_num += 1 %> + <% end %> + +
    + <%= line_num %> +
    <%= line.html_safe %>
    <%= line.html_safe %>
    <%= line.html_safe %>
    +
    +<% end %> \ No newline at end of file diff --git a/app/views/student_work/_student_work_list.html.erb b/app/views/student_work/_student_work_list.html.erb index df89f31eb..1eea8f1c2 100644 --- a/app/views/student_work/_student_work_list.html.erb +++ b/app/views/student_work/_student_work_list.html.erb @@ -4,15 +4,16 @@ (<%= @student_work_count%>人已交) - <% if !@is_teacher && @stundet_works.empty?%> + <% my_work = @homework.student_works.where("user_id = #{User.current.id}").first %> + <% if !@is_teacher && my_work.nil? && User.current.member_of_course?(@course) %> 您尚未提交作品 - <% elsif !@is_teacher &&Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") && !@stundet_works.empty?%> + <% elsif !@is_teacher && my_work &&Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") && !@stundet_works.empty?%> 您已提交且不可再修改,因为截止日期已过 - <% elsif !@is_teacher &&Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.parse(Time.now.to_s).strftime("%Y-%m-%d") && !@stundet_works.empty?%> + <% elsif !@is_teacher && my_work &&Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.parse(Time.now.to_s).strftime("%Y-%m-%d") && !@stundet_works.empty?%> 您已提交,您还可以修改 <% end %> - <%if @is_teacher || @homework.homework_detail_manual.comment_status == 3%> + <%if @is_teacher || @homework.homework_detail_manual.comment_status == 3 || @homework.is_open == 1%>
    diff --git a/app/views/student_work/edit.html.erb b/app/views/student_work/edit.html.erb index f72faaac2..56636a48e 100644 --- a/app/views/student_work/edit.html.erb +++ b/app/views/student_work/edit.html.erb @@ -41,12 +41,12 @@ <%=hidden_field_tag 'group_member_ids', params[:group_member_ids], :value=>str %> <% end %>
    - +

    - + - <% replies_all_i=replies_all_i+1 %> -
  • -
    - <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id,:host=>Setting.host_user), :alt => "用户头像" %> -
    -
    -
    - <% if reply.try(:author).try(:realname) == ' ' %> - <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% else %> - <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> - <% end %> - <%= format_time(reply.created_on) %> - - <% if reply.author == User.current %> - - <% else %> - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> - <% end %> - - -
    -
    - <%= reply.content.html_safe %> -
    -
    -
    -
  • - <% end %> - -
    - <% end %> - - <% if !activity.locked? && authorize_for_course('messages', 'reply') %> -
    -
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
    -
    -
    - <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => is_board,is_course=>is_course},:method => "post", :remote => true) do |f|%> - - -
    - - -
    -

    - <% end%> -
    -
    -
    -
    -
    -
    - <% end %> -
    -
    - +
    +
    +
    + <% 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 %> +
    +
    +
    + <% if activity.status == 1 %> + 确实团队 + <% 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 %> + <% end %> + TO + <%= link_to activity.course.name.to_s+" | 课程问答区", course_boards_path(activity.course,:host=> Setting.host_course), :class => "newsBlue ml15 mr5"%> +
    + + <% if activity.sticky == 1%> + 置顶 + <% end%> + <% if activity.locked%> +        + <% end%> +
    +
    + 发帖时间:<%= format_time(activity.created_on) %> +
    +
    + 更新时间:<%= format_time(CourseActivity.where("course_act_type='#{activity.class}' and course_act_id =#{activity.id}").first.updated_at) %> +
    +
    + <% if activity.parent_id.nil? %> + <% content = activity.content%> + <% else %> + <% content = activity.parent.content%> + <% end %> + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %> + <% if activity.status == 1 %> + <%= activity.created_on.year %> + + <%= activity.created_on.month %> + + <%= activity.created_on.day %> + + <% end %> +
    + + +
    +
    + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
    + + + +
    +
    +
    + <% count=0 %> + <% if activity.parent %> + <% count=activity.parent.children.count%> + <% else %> + <% count=activity.children.count%> + <% end %> +
    +
    +
    回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
    +
    <%#=format_date(activity.updated_on)%>
    + <%if count > 3 %> + + <% end %> +
    + + <% activity= activity.parent ? activity.parent : activity%> + <% replies_all_i = 0 %> + <% if count > 0 %> +
    +
      + <% activity.children.reorder("created_on desc").each do |reply|%> + + <% replies_all_i=replies_all_i+1 %> +
    • +
      + <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id,:host=>Setting.host_user), :alt => "用户头像" %> +
      +
      +
      + <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(reply.created_on) %> + + <% if reply.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> + <% end %> + + +
      +
      + <%= reply.content.html_safe %> +
      +
      +
      +
    • + <% end %> +
    +
    + <% end %> + + <% if !activity.locked? && authorize_for_course('messages', 'reply') %> +
    +
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
    +
    +
    + <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => is_board,is_course=>is_course},:method => "post", :remote => true) do |f|%> + + +
    + + +
    +

    + <% end%> +
    +
    +
    +
    +
    +
    + <% end %> +
    +
    + diff --git a/app/views/users/_homework_detail_information.html.erb b/app/views/users/_homework_detail_information.html.erb index d650cd084..07328e696 100644 --- a/app/views/users/_homework_detail_information.html.erb +++ b/app/views/users/_homework_detail_information.html.erb @@ -1,31 +1,31 @@ -
    题目信息
    -
    - <% if homework.nil? %> - 请先在左侧选择作业 - <% else %> -
    标题:<%=homework.name %>
    - 来源:<%=homework.course.name %>
    - <% if homework.homework_type == 2 && homework.homework_detail_programing %> - 编程语言:<%=homework.language_name %>
    - <% end %> - 贡献者:<%=homework.user.show_name %> - <% if homework.user.user_extensions.occupation && homework.user.user_extensions.occupation!="" %> - ,<%=homework.user.user_extensions.occupation%> - <% end %> -
    - 描述如下: -
    -
    - <%=homework.description.html_safe %> -
    - <% if homework.homework_type == 2 %> -
    - 测试集:<%=homework.homework_tests.count %>组 -
    - <% elsif homework.homework_type ==3 && homework.homework_detail_group %> -
    - 分组人数:<%=homework.homework_detail_group.min_num %> - <%=homework.homework_detail_group.max_num %>人 -
    - <% end %> - <% end %> +
    题目信息
    +
    + <% if homework.nil? %> + 请先在左侧选择作业 + <% else %> +
    标题:<%=homework.name %>
    + 来源:<%=homework.course.name %>
    + <% if homework.homework_type == 2 && homework.homework_detail_programing %> + 编程语言:<%=homework.language_name %>
    + <% end %> + 贡献者:<%=homework.user.show_name %> + <% if homework.user.user_extensions.occupation && homework.user.user_extensions.occupation!="" %> + ,<%=homework.user.user_extensions.occupation%> + <% end %> +
    + 描述如下: +
    +
    + <%=homework.description.html_safe %> +
    + <% if homework.homework_type == 2 %> +
    + 测试集:<%=homework.homework_tests.count %>组 +
    + <% elsif homework.homework_type ==3 && homework.homework_detail_group %> +
    + 分组人数:<%=homework.homework_detail_group.min_num %> - <%=homework.homework_detail_group.max_num %>人 +
    + <% end %> + <% end %>
    \ No newline at end of file diff --git a/app/views/users/_homework_post_notice.html.erb b/app/views/users/_homework_post_notice.html.erb new file mode 100644 index 000000000..d67fa44ae --- /dev/null +++ b/app/views/users/_homework_post_notice.html.erb @@ -0,0 +1,12 @@ +
    +
    +

    + 题目已发送到目标课程的作业列表,但需要您设置发布和截止时间,以激活相应作业,谢谢! +

    + +
    +
    \ No newline at end of file diff --git a/app/views/users/_homework_repository.html.erb b/app/views/users/_homework_repository.html.erb new file mode 100644 index 000000000..a30e21a3f --- /dev/null +++ b/app/views/users/_homework_repository.html.erb @@ -0,0 +1,39 @@ + + +
    + <% homeworks.each do |homework| %> +
      + + +
    • + <% case homework.homework_type %> + <% when 1 %> + 普通 + <% when 2 %> + 编程 + <% when 3 %> + 分组 + <% end %> +
    • + +
    • <%= homework.quotes %>
    • +
    • <%=format_date homework.publish_time %>
    • +
    + <% end %> +
    \ No newline at end of file diff --git a/app/views/users/_homework_repository_detail.html.erb b/app/views/users/_homework_repository_detail.html.erb new file mode 100644 index 000000000..7cf74e11e --- /dev/null +++ b/app/views/users/_homework_repository_detail.html.erb @@ -0,0 +1,33 @@ +
    +
    题目信息
    +
    + <% if homework.nil? %> + 请先在左侧选择作业 + <% else %> +
    标题:<%=homework.name %>
    + 来源:<%=homework.course.name %>
    + <% if homework.homework_type == 2 && homework.homework_detail_programing %> + 编程语言:<%=homework.language_name %>
    + <% end %> + 贡献者:<%=homework.user.show_name %> + <% if homework.user.user_extensions.occupation && homework.user.user_extensions.occupation!="" %> + ,<%=homework.user.user_extensions.occupation%> + <% end %> +
    + 描述如下: +
    +
    + <%=homework.description.html_safe %> +
    + <% if homework.homework_type == 2 %> +
    + 测试集:<%=homework.homework_tests.count %>组 +
    + <% elsif homework.homework_type ==3 && homework.homework_detail_group %> +
    + 分组人数:<%=homework.homework_detail_group.min_num %> - <%=homework.homework_detail_group.max_num %>人 +
    + <% end %> + <% end %> +
    +
    \ No newline at end of file diff --git a/app/views/users/_homework_repository_search.html.erb b/app/views/users/_homework_repository_search.html.erb new file mode 100644 index 000000000..dfbaacd05 --- /dev/null +++ b/app/views/users/_homework_repository_search.html.erb @@ -0,0 +1,29 @@ + + \ No newline at end of file diff --git a/app/views/users/_homework_search_input.html.erb b/app/views/users/_homework_search_input.html.erb index ba85f0d09..31d7602d4 100644 --- a/app/views/users/_homework_search_input.html.erb +++ b/app/views/users/_homework_search_input.html.erb @@ -1,29 +1,29 @@ - - \ No newline at end of file diff --git a/app/views/users/_import_resource_info.html.erb b/app/views/users/_import_resource_info.html.erb new file mode 100644 index 000000000..bc1152ce4 --- /dev/null +++ b/app/views/users/_import_resource_info.html.erb @@ -0,0 +1,75 @@ + +
    选用资源库中的资源
    +
    + <% if !params[:course_id].nil? %> + 公共资源 + 我的资源 + <% elsif !params[:project_id].nil? %> + 公共资源 + 我的资源 + <% elsif !params[:subfield_file_id].nil? %> + 公共资源 + 我的资源 + <% 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 %> + +
    + +
    +
      + +
    • 类别
    • +
    • 大小
    • +
    • 上传者
    • +
    • 上传时间
    • +
    + <%= 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 %> +
    + + + + +
    +
      + <%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %> +
    +
    +
    +
    diff --git a/app/views/users/_project_issue.html.erb b/app/views/users/_project_issue.html.erb index c5d93e0a5..1ce03da17 100644 --- a/app/views/users/_project_issue.html.erb +++ b/app/views/users/_project_issue.html.erb @@ -18,7 +18,7 @@ <% when 1%> <% when 2%> - + <% when 3%> <% when 4%> diff --git a/app/views/users/_resource_search_form.html.erb b/app/views/users/_resource_search_form.html.erb index c629f9f32..9e42f9c96 100644 --- a/app/views/users/_resource_search_form.html.erb +++ b/app/views/users/_resource_search_form.html.erb @@ -1,7 +1,7 @@ -<%= form_tag( url_for(:controller => 'users',:action => 'resource_search',:id=>user.id), - :remote=>true ,:method => 'get',:class=>'resourcesSearchloadBox',:id=>'resource_search_form') do %> - - <%= hidden_field_tag(:type,type.nil? ? 1 : type) %> - <%= submit_tag '',:class=>'homepageSearchIcon',:onfocus=>'this.blur();',:style=>'border-style:none' %> - +<%= form_tag( url_for(:controller => 'users', :action => 'resource_search', :id => user.id), + :remote => true , :method => 'get', :class => 'resourcesSearchloadBox mt10', :id => 'resource_search_form') do %> + + <%= hidden_field_tag(:type,type.nil? ? 1 : type) %> + <%= submit_tag '', :class => 'homepageSearchIcon', :onfocus => 'this.blur();', :style => 'border-style:none' %> + <% end %> \ No newline at end of file diff --git a/app/views/users/_resources_list.html.erb b/app/views/users/_resources_list.html.erb index a0a1377f1..f679f9c8c 100644 --- a/app/views/users/_resources_list.html.erb +++ b/app/views/users/_resources_list.html.erb @@ -1,27 +1,374 @@ - -<% if attachments.nil? || attachments.empty? %> - - - -<% else %> - <% attachments.each do |attach| %> -
      -
    • - -
    • -
    • - - <%= link_to truncate(attach.filename,:length=>30), download_named_attachment_path(attach.id, attach.filename), - :title => attach.filename,:class=>'resourcesBlack'%> -
    • -
    • <%= number_to_human_size(attach.filesize) %>
    • -
    • <%= 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 %>
    • -
    • <%= attach.author_id %>
    • -
    • <%= format_date(attach.created_on) %>
    • -
    • <%= attach.id %>
    • -
    -
      - - <% end %> -<% end %> +<% if attachments.nil? || attachments.empty? %> + + + +<% else %> + <% attachments.each do |attach| %> +
        +
      • + + +
      • + +
      • <%= format_date(attach.created_on) %>
      • +
      • <%= attach.quotes.nil? ? 0 : attach.quotes %>
      • +
      • <%= attach.downloads %>
      • +
      • <%= attach.author_id %>
      • +
      • <%= number_to_human_size(attach.filesize) %>
      • + +
      • <%= get_resource_type(attach.container_type)%>
      • + +
      • <%= attach.id %>
      • +
      +
      + <% end %> +<% end %> + + diff --git a/app/views/users/_send_homework_to_course.html.erb b/app/views/users/_send_homework_to_course.html.erb new file mode 100644 index 000000000..b19fbd1a8 --- /dev/null +++ b/app/views/users/_send_homework_to_course.html.erb @@ -0,0 +1,79 @@ +
      +
      +
      发送到
      +
      +
      + +
      + + +
      + <%= form_tag send_homework_to_course_user_path(user),:remote=>true,:id=>'choose_course_list_form' %> +
      + <%= hidden_field_tag(:send_id, send_id) %> +
      + <% if !courses.empty? %> + <% courses.each do |course| %> +
        +
      • + +
      • +
      • <%= truncate(course.name,:lendght=>25) + '['+current_time_and_term(course) + ']'%>
      • +
      + <% end %> +
      +
      +
      + +
      +
      + 确定 +
      +
      + 取消 +
      +
      +
      + <% end %> +
      + \ No newline at end of file diff --git a/app/views/users/_show_user_homework_form.html.erb b/app/views/users/_show_user_homework_form.html.erb index 004c8fec4..be9a5bf13 100644 --- a/app/views/users/_show_user_homework_form.html.erb +++ b/app/views/users/_show_user_homework_form.html.erb @@ -1,12 +1,13 @@ <% homeworks.each do |homework| %> -
        -
      + <% end %> + <% end %> +
      + <% if is_teacher%> + <% comment_status = homework_common.homework_detail_manual.comment_status%> +
      +
        +
      • +
          +
        • + <%= link_to l(:button_edit),edit_homework_common_path(homework_common,:is_in_course => is_in_course,:course_activity=>-1), :class => "postOptionLink"%> +
        • +
        • + <%= link_to(l(:label_bid_respond_delete), homework_common_path(homework_common,:is_in_course => is_in_course,:course_activity=>-1),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "postOptionLink") %> +
        • +
        • + <%= link_to("评分设置", score_rule_set_homework_common_path(homework_common, :is_in_course => is_in_course,:course_activity=>-1),:class => "postOptionLink", :remote => true) %> +
        • + <% if homework_common.anonymous_comment == 0 &&(comment_status == 0 || comment_status == 1)%> +
        • + <%= link_to("匿评设置", start_evaluation_set_homework_common_path(homework_common, :is_in_course => is_in_course,:course_activity=>-1),:class => "postOptionLink", :remote => true)%> +
        • + <% end %> + <% if homework_common.anonymous_comment == 0%> +
        • + <%= homework_anonymous_comment(homework_common, is_in_course) %> +
        • + <% end %> + <% if homework_common.anonymous_comment == 0 && (comment_status == 0 || comment_status == 1)%> +
        • + <%= link_to("禁用匿评", alert_forbidden_anonymous_comment_homework_common_path(homework_common,:is_in_course => is_in_course),:class => "postOptionLink", + :title => "匿评是同学之间的双盲互评过程:每个同学将评阅系统分配给他/她的若干个作品", :remote => true)%> +
        • + <% end %> + <% if (homework_common.anonymous_comment == 1 && homework_common.is_open == 0) || (homework_common.anonymous_comment == 0 && comment_status == 3 && homework_common.is_open == 0) %> +
        • + <%= link_to("公开作品", alert_open_student_works_homework_common_path(homework_common, :is_in_course => is_in_course,:course_activity=> -1),:class => "postOptionLink", :remote => true)%> +
        • + <% elsif homework_common.is_open == 1 %> +
        • + <%= link_to("取消公开", alert_open_student_works_homework_common_path(homework_common, :is_in_course => is_in_course,:course_activity=> -1),:class => "postOptionLink", :remote => true)%> +
        • + <% end %> +
        +
      • +
      +
      + <% end%> +
      +
      +
      + + <% count=homework_common.journals_for_messages.count %> +
      +
      +
      回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if homework_common.user == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>homework_common, :user_activity_id=>homework_common.id,:type=>"activity"}%> + <% end %> + +
      +
      + <%if count>3 %> + + <% end %> +
      + + <% replies_all_i = 0 %> + <% if count > 0 %> +
      +
        + <% homework_common.journals_for_messages.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
      • +
        + <%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %> +
        +
        +
        + <% if comment.try(:user).try(:realname) == ' ' %> + <%= link_to comment.try(:user), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:user).try(:realname), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> + <% if comment.user == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + <% end %> + + +
        +
        + <%= comment.notes.html_safe %>
        +
        +
        +
      • + <% end %> +
      +
      + <% end %> + +
      +
      <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
      +
      +
      + <%= form_for('new_form',:url => {:controller => 'words', :action => 'leave_homework_message', :id => homework_common.id},:method => "post", :remote => true) do |f|%> + <%= hidden_field_tag 'homework_common_id',params[:homework_common_id],:value =>homework_common.id %> + <%= hidden_field_tag 'is_in_course',params[:is_in_course],:value =>is_in_course %> +
      + + +
      +

      + <% end%> +
      +
      +
      +
      +
      +
      +
      + \ No newline at end of file diff --git a/app/views/users/_user_homework_form.html.erb b/app/views/users/_user_homework_form.html.erb index 0d542882a..8b72ec781 100644 --- a/app/views/users/_user_homework_form.html.erb +++ b/app/views/users/_user_homework_form.html.erb @@ -1,268 +1,270 @@ -<% content_for :header_tags do %> - <%= import_ke(enable_at: true, prettify: false, init_activity: false) %> - - <%= javascript_include_tag 'homework','baiduTemplate' %> - -<% end %> - -
      - -
      - -

      -
      -
      - -
      - <%= 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 %> - <% if edit_mode %> - - <% end %> -
      - - <% if homework.homework_detail_manual.comment_status.to_i < 3 %> - <%= calendar_for('homework_end_time')%> - <% end %> -
      - <% if edit_mode %> - - <% end %> -
      - - <% if homework.homework_detail_manual.comment_status.to_i == 0 %> - <%= calendar_for('homework_publish_time')%> - <% end %> -
      - <% if !edit_mode || edit_mode && homework.homework_detail_manual.comment_status < 2 %> -
      - - 禁用匿评 -
      - <% end %> -
      -
      -

      -
      -
      -
      - <% if edit_mode %> - - <%#= f.kindeditor :description, :editor_id => 'homework_description_editor', :height => "150px", :owner_id => homework.id, :owner_type => OwnerTypeHelper::HOMEWORKCOMMON, at_id: homework.id, at_type: homework.class.to_s %> - <% else %> - <%= hidden_field_tag :asset_id, params[:asset_id], :required => false, :style => 'display:none' %> - - <%#= f.kindeditor :description, :editor_id => 'homework_description_editor', :height => "150px",at_id: homework.id, at_type: homework.class.to_s %> - <% end %> -
      -
      - -
      - <%= select_tag :course_id, options_for_select(get_as_teacher_courses(User.current), homework.course_id), {:class => "InputBox w709",:value => "请选择发布作业的课程"} %> -
      -

      -
      - -
      - - <%= render :partial => 'users/user_homework_attachment', :locals => {:container => homework, :has_program=>!(edit_mode && homework.homework_type != 2), :has_group=>(!(edit_mode && homework.homework_type != 3))&& homework.student_works.empty?,:show_member => true} %> -
      - -
      - <% if edit_mode %> - 确定 - - <%#= link_to "取消",user_homeworks_user_path(User.current.id),:class => "fr mr10 mt3"%> - 取消 - <% else %> - 发送 - - 取消 - <% end %> -
      -
      - - - -
      -
      -
      - - - - - - - - - - - -<% unless edit_mode %> - +<% content_for :header_tags do %> + <%= import_ke(enable_at: true, prettify: false, init_activity: false) %> + + <%= javascript_include_tag 'homework','baiduTemplate' %> + +<% end %> + +
      + +
      + +

      +
      +
      + +
      + <%= 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 %> + <% if edit_mode %> + + <% end %> +
      + + <% if homework.homework_detail_manual.comment_status.to_i < 3 %> + <%= calendar_for('homework_end_time')%> + <% end %> +
      + <% if edit_mode %> + + <% end %> +
      + + <% if homework.homework_detail_manual.comment_status.to_i == 0 %> + <%= calendar_for('homework_publish_time')%> + <% end %> +
      + <% if !edit_mode || edit_mode && homework.homework_detail_manual.comment_status < 2 %> +
      + + 禁用匿评 +
      + <% end %> +
      +
      +

      +
      +
      +
      + <% if edit_mode %> + + <%#= f.kindeditor :description, :editor_id => 'homework_description_editor', :height => "150px", :owner_id => homework.id, :owner_type => OwnerTypeHelper::HOMEWORKCOMMON, at_id: homework.id, at_type: homework.class.to_s %> + <% else %> + <%= hidden_field_tag :asset_id, params[:asset_id], :required => false, :style => 'display:none' %> + + <%#= f.kindeditor :description, :editor_id => 'homework_description_editor', :height => "150px",at_id: homework.id, at_type: homework.class.to_s %> + <% end %> +
      +
      + +
      + <%= select_tag :course_id, options_for_select(get_as_teacher_courses(User.current), homework.course_id), {:class => "InputBox w709",:value => "请选择发布作业的课程"} %> +
      +

      +
      + +
      + + <%= render :partial => 'users/user_homework_attachment', :locals => {:container => homework, :has_program=>!(edit_mode && homework.homework_type != 2), :has_group=>(!(edit_mode && homework.homework_type != 3))&& homework.student_works.empty?,:show_member => true} %> +
      + +
      + <% if edit_mode %> + 确定 + + <%#= link_to "取消",user_homeworks_user_path(User.current.id),:class => "fr mr10 mt3"%> + 取消 + <% else %> + 发送 + + 取消 + <% end %> +
      +
      + + + +
      +
      +
      + + + + + + + + + + + +<% unless edit_mode %> + <% end %> \ No newline at end of file diff --git a/app/views/users/_user_homework_list.html.erb b/app/views/users/_user_homework_list.html.erb index 34e975762..e42c5d8b2 100644 --- a/app/views/users/_user_homework_list.html.erb +++ b/app/views/users/_user_homework_list.html.erb @@ -1,40 +1,40 @@ -<%= content_for(:header_tags) do %> - <%= import_ke(enable_at: true, prettify: false, init_activity: true) %> -<% end %> - -
      -<% homework_commons.each do |homework_common|%> - - <%= render :partial => 'users/user_homework_detail', :locals => {:homework_common => homework_common,:is_in_course => is_in_course} %> -<% end%> -<% if homework_commons.count == 10%> - <% if is_in_course == 1%> - - <%= link_to "点击展开更多",homework_common_index_path(:course => course_id,:page => page,:is_in_course => is_in_course),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%> - <% else%> - - <%= link_to "点击展开更多",user_homeworks_user_path(User.current.id,:page => page,:is_in_course => is_in_course),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%> - <% end%> -<% end%> -
      +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: true, prettify: false, init_activity: true) %> +<% end %> + +
      +<% homework_commons.each do |homework_common|%> + + <%= render :partial => 'users/user_homework_detail', :locals => {:homework_common => homework_common,:is_in_course => is_in_course} %> +<% end%> +<% if homework_commons.count == 10%> + <% if is_in_course == 1%> + + <%= link_to "点击展开更多",homework_common_index_path(:course => course_id,:page => page,:is_in_course => is_in_course),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%> + <% else%> + + <%= link_to "点击展开更多",student_homeworks_user_path(User.current.id,:page => page,:is_in_course => is_in_course),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%> + <% end%> +<% end%> +
      diff --git a/app/views/users/_user_homeworks_old.html.erb b/app/views/users/_user_homeworks_old.html.erb new file mode 100644 index 000000000..59ec24ad3 --- /dev/null +++ b/app/views/users/_user_homeworks_old.html.erb @@ -0,0 +1,47 @@ + +
      +
      作业
      +
      +
      + +<% if @is_teacher%> + +
      + <% homework = HomeworkCommon.new %> + <% homework.homework_detail_manual = HomeworkDetailManual.new%> + <%= labelled_form_for homework,:url => user_new_homework_users_path,:method => "post" do |f| %> +
      + <%= render :partial => 'users/user_homework_form', :locals => { :homework => homework,:f => f,:edit_mode => false } %> +
      + <% end%> +
      +<% end%> + +<%= render :partial => 'users/user_homework_list', :locals => {:homework_commons => @homework_commons,:page => 0,:is_in_course => 0} %> diff --git a/app/views/users/_user_programing_attr.html.erb b/app/views/users/_user_programing_attr.html.erb index 71816689b..8657e5542 100644 --- a/app/views/users/_user_programing_attr.html.erb +++ b/app/views/users/_user_programing_attr.html.erb @@ -7,10 +7,11 @@ <%= options_for_select({"C语言"=>1, "C++"=>2, "Python"=>3, "Java"=>4}, (edit_mode && homework.is_program_homework?) ? homework.language : 1) %>
      -
      +
      <% if edit_mode && homework.is_program_homework? %> <% homework.homework_tests.each_with_index do |test, index| %>
      + @@ -22,6 +23,7 @@ <% end %> <% else %>
      + diff --git a/app/views/users/_user_resource_info.html.erb b/app/views/users/_user_resource_info.html.erb new file mode 100644 index 000000000..cafbf457f --- /dev/null +++ b/app/views/users/_user_resource_info.html.erb @@ -0,0 +1,60 @@ +
      + +
      + <%= render :partial => 'users/resource_search_form',:locals => {:user => @user, :type => @type} %> +
      +
      为您找到<%= @atta_count %>个资源
      +
      +
      +
        +
      • +
      • 资源名称
      • +
      • 上传时间
      • +
      • 引用数
      • +
      • 下载数
      • +
      • 大小
      • +
      • 上传者
      • +
      • 类别
      • +
      • 来源
      • +
      +
      +
      +
      + <%= render :partial => 'users/resources_list' , :locals => { :attachments => @attachments} %> +
      +
      + + +
      +
      + +
      + 全选 删除
      +
      +
      +
      + 发送至 +
      +
      选择 0 个资源
      +
      + +
      +
      +
        + <%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %> +
      +
      + +
      + + + + \ No newline at end of file diff --git a/app/views/users/choose_user_course.js.erb b/app/views/users/choose_user_course.js.erb new file mode 100644 index 000000000..508004816 --- /dev/null +++ b/app/views/users/choose_user_course.js.erb @@ -0,0 +1,7 @@ +$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/send_homework_to_course', :locals => {:courses => @course, :user => @user, :send_id => @send_id}) %>'); +showModal('ajax-modal', '452px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","50%").css("left","50%"); +$('#ajax-modal').parent().addClass("popbox").addClass("resourceUploadPopup"); +$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); \ No newline at end of file diff --git a/app/views/users/import_into_container.js.erb b/app/views/users/import_into_container.js.erb new file mode 100644 index 000000000..2a1ea3599 --- /dev/null +++ b/app/views/users/import_into_container.js.erb @@ -0,0 +1,3 @@ +<% if @flag == true%> +alert("发送成功") +<% end %> \ No newline at end of file diff --git a/app/views/users/import_resources.js.erb b/app/views/users/import_resources.js.erb new file mode 100644 index 000000000..6244e8e64 --- /dev/null +++ b/app/views/users/import_resources.js.erb @@ -0,0 +1,18 @@ +<% if params[:project_id] %> +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :project_id => params[:project_id]} ) %>'); +<% elsif params[:course_id] %> +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :course_id => params[:course_id]} ) %>'); +<% elsif params[:subfield_file_id] %> +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :subfield_file_id => params[:subfield_file_id]} ) %>'); +<% end %> +showModal('ajax-modal', '615px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +<% if params[:project_id] %> +$('#ajax-modal').parent().css("top","10%").css("left","34%").css("border","3px solid #269ac9"); +<% else %> +$('#ajax-modal').parent().css("top","20%").css("left","42%").css("border","3px solid #269ac9"); +<% end %> +$('#ajax-modal').parent().addClass("popbox_polls"); + + diff --git a/app/views/users/import_resources_search.js.erb b/app/views/users/import_resources_search.js.erb new file mode 100644 index 000000000..549cf6329 --- /dev/null +++ b/app/views/users/import_resources_search.js.erb @@ -0,0 +1,25 @@ +//$("#resources_list").html('<%#= escape_javascript( render :partial => 'users/import_resource_info' ,:locals=>{ :attachments => @attachments, :type => @type})%>'); +//$("#pages").html('<%#= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); +//$("#res_all_count").html(<%#= @atta_count%>); +//$("#res_count").html(0); +//$("#checkboxAll").attr('checked',false); + + +<% if params[:project_id] %> +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :project_id => params[:project_id]} ) %>'); +<% elsif params[:course_id] %> +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :course_id => params[:course_id]} ) %>'); +<% elsif params[:subfield_file_id] %> +$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => 1, :subfield_file_id => params[:subfield_file_id]} ) %>'); +<% end %> +showModal('ajax-modal', '615px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +<% if params[:project_id] %> +$('#ajax-modal').parent().css("top","10%").css("left","34%").css("border","3px solid #269ac9"); +<% else %> +$('#ajax-modal').parent().css("top","20%").css("left","42%").css("border","3px solid #269ac9"); +<% end %> +$('#ajax-modal').parent().addClass("popbox_polls"); + + diff --git a/app/views/users/new_user_commit_homework.html.erb b/app/views/users/new_user_commit_homework.html.erb index eed789a29..02bfc9203 100644 --- a/app/views/users/new_user_commit_homework.html.erb +++ b/app/views/users/new_user_commit_homework.html.erb @@ -4,7 +4,12 @@ <%= stylesheet_link_tag "/assets/codemirror/codemirror" %> <% end %> - + -
      +
      @@ -91,7 +96,9 @@
      测试代码 - <% unless @is_test %> + <% if @is_test %> + <%=link_to '返 回',course_path(@course),:class=>'fr mt6' %> + <% else @is_test %> 提交代码 <% end %>
      diff --git a/app/views/users/send_homework_to_course.js.erb b/app/views/users/send_homework_to_course.js.erb new file mode 100644 index 000000000..b06d8e434 --- /dev/null +++ b/app/views/users/send_homework_to_course.js.erb @@ -0,0 +1,9 @@ +$("#subject_count_homework_<%=@homework.id %>").html(<%= @homework.quotes %>); +$("#ajax-modal").html("<%=escape_javascript(render :partial => 'homework_post_notice') %>"); +showModal('ajax-modal', '500px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before("" + + ""); +$('#ajax-modal').parent().css("top","50%").css("left","50%"); +$('#ajax-modal').parent().addClass("popbox").addClass("resourceUploadPopup"); +$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); \ No newline at end of file diff --git a/app/views/users/show_homework_detail.js.erb b/app/views/users/show_homework_detail.js.erb index 12be1b786..a5dd82453 100644 --- a/app/views/users/show_homework_detail.js.erb +++ b/app/views/users/show_homework_detail.js.erb @@ -1 +1,5 @@ -$("#homework_detail_information").html("<%=escape_javascript(render :partial => 'users/homework_detail_information', :locals => {:homework=>@homework}) %>") \ No newline at end of file +<% if @is_import.to_i == 1 %> + $("#homework_detail_information").html("<%=escape_javascript(render :partial => 'users/homework_detail_information', :locals => {:homework=>@homework}) %>"); +<% else %> + $("#homework_repository_detail").html("<%=escape_javascript(render :partial => 'users/homework_repository_detail', :locals => {:homework=>@homework}) %>"); +<% end %> \ No newline at end of file diff --git a/app/views/users/student_homeworks.html.erb b/app/views/users/student_homeworks.html.erb new file mode 100644 index 000000000..59ec24ad3 --- /dev/null +++ b/app/views/users/student_homeworks.html.erb @@ -0,0 +1,47 @@ + +
      +
      作业
      +
      +
      + +<% if @is_teacher%> + +
      + <% homework = HomeworkCommon.new %> + <% homework.homework_detail_manual = HomeworkDetailManual.new%> + <%= labelled_form_for homework,:url => user_new_homework_users_path,:method => "post" do |f| %> +
      + <%= render :partial => 'users/user_homework_form', :locals => { :homework => homework,:f => f,:edit_mode => false } %> +
      + <% end%> +
      +<% end%> + +<%= render :partial => 'users/user_homework_list', :locals => {:homework_commons => @homework_commons,:page => 0,:is_in_course => 0} %> diff --git a/app/views/users/student_homeworks.js.erb b/app/views/users/student_homeworks.js.erb new file mode 100644 index 000000000..c34be666c --- /dev/null +++ b/app/views/users/student_homeworks.js.erb @@ -0,0 +1 @@ +$("#user_show_more_homework").replaceWith("<%= escape_javascript( render :partial => 'users/user_homework_list',:locals => {:homework_commons => @homework_commons, :page => @page,:is_in_course => 0} )%>"); \ No newline at end of file diff --git a/app/views/users/user_homework_type.js.erb b/app/views/users/user_homework_type.js.erb index 691fdc72b..701cf45fa 100644 --- a/app/views/users/user_homework_type.js.erb +++ b/app/views/users/user_homework_type.js.erb @@ -1,4 +1,15 @@ -$("#homework_list_form_show").html('<%= escape_javascript(render :partial => 'users/show_user_homework_form', :locals => {:homeworks => @homeworks})%>'); -$("#homewrok_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); -$("#homework_detail_information").html("<%=escape_javascript(render :partial => 'users/homework_detail_information', :locals => {:homework=>nil}) %>"); -$("#homework_search_input").html("<%=escape_javascript(render :partial=>'homework_search_input', :locals=>{:type=>@type}) %>"); \ No newline at end of file +<% if @is_import.to_i == 1 %> +$("#homework_list_form_show").html('<%= escape_javascript(render :partial => 'users/show_user_homework_form', :locals => {:homeworks => @homeworks})%>'); +$("#homewrok_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); +$("#homework_detail_information").html("<%=escape_javascript(render :partial => 'users/homework_detail_information', :locals => {:homework=>nil}) %>"); +$("#homework_search_input").html("<%=escape_javascript(render :partial=>'homework_search_input', :locals=>{:type=>@type,:is_import=>@is_import}) %>"); +<% else %> +$("#homework_repository").html('<%= escape_javascript(render :partial => 'users/homework_repository', :locals => {:homeworks => @homeworks})%>'); +$("#homework_pository_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); +$("#homework_repository_detail").html("<%=escape_javascript(render :partial => 'users/homework_repository_detail', :locals => {:homework=>nil}) %>"); +$("#homework_search_input").html("<%=escape_javascript(render :partial=>'homework_repository_search', :locals=>{:type=>@type,:is_import=>@is_import,:property=>@property}) %>"); +$("#homework_type_all").attr('href','<%= user_homework_type_user_path(@user,:type => @type,:is_import => 0,:property => 0) %>'); +$("#homework_type_nor").attr('href','<%= user_homework_type_user_path(@user,:type => @type,:is_import => 0,:property => 1) %>'); +$("#homework_type_pro").attr('href','<%= user_homework_type_user_path(@user,:type => @type,:is_import => 0,:property => 2) %>'); +$("#homework_type_gro").attr('href','<%= user_homework_type_user_path(@user,:type => @type,:is_import => 0,:property => 3) %>'); +<% end %> diff --git a/app/views/users/user_homeworks.html.erb b/app/views/users/user_homeworks.html.erb index d0adb291f..4e928ca78 100644 --- a/app/views/users/user_homeworks.html.erb +++ b/app/views/users/user_homeworks.html.erb @@ -1,47 +1,97 @@ - -
      -
      作业
      -
      -
      - -<% if @is_teacher%> - -
      - <% homework = HomeworkCommon.new %> - <% homework.homework_detail_manual = HomeworkDetailManual.new%> - <%= labelled_form_for homework,:url => user_new_homework_users_path,:method => "post" do |f| %> -
      - <%= render :partial => 'users/user_homework_form', :locals => { :homework => homework,:f => f,:edit_mode => false } %> -
      - <% end%> -
      -<% end%> - -<%= render :partial => 'users/user_homework_list', :locals => {:homework_commons => @homework_commons,:page => 0,:is_in_course => 0} %> +<%= stylesheet_link_tag 'pleft','header','new_user','repository','org', 'public' %> + + +
      +
      +
      + +
      +
      + <%=render :partial=>'homework_repository_search', :locals=>{:type => @type,:is_import => 0,:property => @property} %> +
      + +
      +
      +
        + +
      • 来源
      • +
      • 类别
      • +
      • 贡献者
      • +
      • 引用数
      • +
      • 发布时间
      • +
      +
      + <%=render :partial => 'homework_repository', :locals => {:homeworks => @homeworks} %> +
      +
      +
      + <%=render :partial => 'homework_repository_detail', :locals => {:homework => nil} %> +
      +
      +
      +
        + <%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true%> +
      +
      +
      + 发送至 +
      + +
      +
      +
      +
      \ No newline at end of file diff --git a/app/views/users/user_homeworks.js.erb b/app/views/users/user_homeworks.js.erb index cc1bc051a..a24b3d018 100644 --- a/app/views/users/user_homeworks.js.erb +++ b/app/views/users/user_homeworks.js.erb @@ -1,2 +1,3 @@ -$("#user_show_more_homework").replaceWith("<%= escape_javascript( render :partial => 'users/user_homework_list',:locals => {:homework_commons => @homework_commons, :page => @page,:is_in_course => 0} )%>"); - +$("#homework_repository").html('<%= escape_javascript(render :partial => 'users/homework_repository', :locals => {:homeworks => @homeworks})%>'); +$("#homework_pository_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); +$("#homework_repository_detail").html("<%=escape_javascript(render :partial => 'users/homework_repository_detail', :locals => {:homework=>nil}) %>"); diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb index 5abadfb29..f45eb11c2 100644 --- a/app/views/users/user_resource.html.erb +++ b/app/views/users/user_resource.html.erb @@ -1,4 +1,3 @@ - <%= javascript_include_tag 'bootstrap'%> <%= stylesheet_link_tag 'project' %> <%= stylesheet_link_tag 'leftside' %> @@ -12,18 +11,22 @@ function remote_get_resources(user_id,type){ } + $(document).ready(function(){ + $(".resource-switch").click(function(){ + $(".resource-switch").children().removeClass("resource-tab-active"); + $(this).children().addClass("resource-tab-active"); + }); + }); function remote_search(){ $("#resource_search_form").submit(); } - function show_upload(){ - $("#ajax-modal").html('<%= escape_javascript( render :partial => 'upload_resource' ,:locals => {:user=>@user})%>'); - showModal('ajax-modal', '452px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before(""); - $('#ajax-modal').parent().css("top","50%").css("left","50%"); - $('#ajax-modal').parent().addClass("resourceUploadPopup"); - $('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); + function show_public_resource(){ + $("#resource_remote").html('<%= escape_javascript( render :partial => 'user_resource_info' ,:locals => { :tpye => 6}) %>'); + } + + function show_public_resource(){ + $("#resource_remote").html('<%= escape_javascript( render :partial => 'user_resource_info' ,:locals => { :tpye => 1}) %>'); } function closeModal() @@ -56,429 +59,51 @@ } } -
      -
      资源库
      -
        -
      • -
          -
        • - <%= link_to '全部' ,user_resource_user_path(:id=>@user.id,:type=>1),:remote=>true,:method => 'get',:class=>'resourcesTypeAll resourcesGrey' %> -
        • -
        • - <%= link_to '课程资源' ,user_resource_user_path(:id=>@user.id,:type=>2),:remote=>true,:method => 'get',:class=>'homepagePostTypeAssignment postTypeGrey' %> -
        • -
        • - <%= link_to '项目资源' ,user_resource_user_path(:id=>@user.id,:type=>3),:remote=>true,:method => 'get',:class=>'homepagePostTypeQuiz postTypeGrey' %> -
        • -
        • - <%= link_to '用户资源' ,user_resource_user_path(:id=>@user.id,:type=>5),:remote=>true,:method => 'get',:class=>'resourcesTypeUser resourcesGrey' %> -
        • -
        • - <%= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4),:remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %> -
        • -
        -
      • -
      -
      - -
      -
      - -
      - <%= render :partial => 'resource_search_form',:locals => {:user=>@user,:type=>@type} %> -
      -
      为您找到<%= @atta_count%>个资源
      -
      -
      -
        -
      • -
      • 资源名称
      • -
      • 大小
      • -
      • 类别
      • -
      • 上传者
      • -
      • 上传时间
      • -
      -
      -
      -
      - - <%= render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments} %> - -
      -
      -
      - -
      - 全选 - 删除 -
      -
      选择 0 个资源
      -
      - 发送 -
      -
      -
      -
      +
      +
        +
      • + 公共资源 +
      • +
      • + 我的资源 +
      • +
      •  
      • +
      • +
          +
        • +
            +
          • + 全部 +
          • +
          • + 课程资源 + <%#= link_to '课程资源' ,user_resource_user_path(:id => @user.id, :type => 2), id="resource_type_course", :remote => true, :method => 'get', :class=> 'homepagePostTypeAssignment postTypeGrey' %> +
          • +
          • + 项目资源 + <%#= link_to '项目资源' ,user_resource_user_path(:id => @user.id, :type => 3), id="resource_type_project", :remote => true, :method => 'get', :class => 'homepagePostTypeQuiz postTypeGrey' %> +
          • +
          • + 用户资源 + <%#= link_to '用户资源' ,user_resource_user_path(:id=>@user.id,:type=>5), id="resource_type_user", :remote=>true,:method => 'get', :class=>'resourcesTypeUser resourcesGrey' %> +
          • +
          • + 附件 + <%#= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4), id="resource_type_file", :remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %> +
          • +
          +
        • +
        +
      • +
        +
      -
      -
        - <%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true%> -
      +
      + <%= render :partial => 'user_resource_info' %>
      -
      - - - - - - diff --git a/app/views/users/user_resource.js.erb b/app/views/users/user_resource.js.erb index bb195d4bf..4ba186579 100644 --- a/app/views/users/user_resource.js.erb +++ b/app/views/users/user_resource.js.erb @@ -1,6 +1,15 @@ -$("#search_div").html('<%= escape_javascript( render :partial => 'resource_search_form',:locals => {:user=>@user,:type=>@type} ) %>'); -$("#resources_list").html('<%= escape_javascript( render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments})%>'); -$("#pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); -$("#res_count").html(0); -$("#checkboxAll").attr('checked',false); -$("#res_all_count").html(<%= @atta_count%>); \ No newline at end of file +$("#search_div").html('<%= escape_javascript( render :partial => 'resource_search_form', :locals => {:user => @user, :type => @type} ) %>'); +$("#resources_list").html('<%= escape_javascript( render :partial => 'resources_list' , :locals => { :attachments => @attachments}) %>'); +$("#pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); +$("#res_count").html(0); +$("#checkboxAll").attr('checked',false); +$("#res_all_count").html(<%= @atta_count %>); + +$("#public_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '6', :status => @status) %>'); +$("#my_resource_list").attr('href','<%= user_resource_user_path(@user, :type => '1', :status => @status) %>'); + +$("#resource_type_all").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 1) %>'); +$("#resource_type_course").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 2) %>'); +$("#resource_type_project").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 3) %>'); +$("#resource_type_user").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 5) %>'); +$("#resource_type_file").attr('href','<%= user_resource_user_path(@user,:type => @type, :status => 4) %>'); diff --git a/app/views/users/user_search_homeworks.js.erb b/app/views/users/user_search_homeworks.js.erb index c8e3aab3e..34d73b823 100644 --- a/app/views/users/user_search_homeworks.js.erb +++ b/app/views/users/user_search_homeworks.js.erb @@ -1,3 +1,9 @@ -$("#homework_list_form_show").html('<%= escape_javascript(render :partial => 'users/show_user_homework_form', :locals => {:homeworks => @homeworks})%>'); -$("#homewrok_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); -$("#homework_detail_information").html("<%=escape_javascript(render :partial => 'users/homework_detail_information', :locals => {:homework=>nil}) %>"); \ No newline at end of file +<% if @is_import.to_i == 1 %> +$("#homework_list_form_show").html('<%= escape_javascript(render :partial => 'users/show_user_homework_form', :locals => {:homeworks => @homeworks})%>'); +$("#homewrok_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); +$("#homework_detail_information").html("<%=escape_javascript(render :partial => 'users/homework_detail_information', :locals => {:homework=>nil}) %>"); +<% else %> +$("#homework_repository").html('<%= escape_javascript(render :partial => 'users/homework_repository', :locals => {:homeworks => @homeworks})%>'); +$("#homework_pository_ref_pages").html('<%= pagination_links_full @hw_pages, @hw_count, :per_page_links => false, :remote => @is_remote, :flag => true %>'); +$("#homework_repository_detail").html("<%=escape_javascript(render :partial => 'users/homework_repository_detail', :locals => {:homework=>nil}) %>"); +<% end %> \ No newline at end of file diff --git a/config/locales/courses/zh.yml b/config/locales/courses/zh.yml index 19b979d97..b59538bc9 100644 --- a/config/locales/courses/zh.yml +++ b/config/locales/courses/zh.yml @@ -15,7 +15,7 @@ zh: label_course_new: 新建课程 label_course_name: 课程名称 - label_homework: 课程作业 + label_homework: 作业 label_course_news: 课程通知 label_course_mail_news_reply: 课程通知回复 label_main_teacher: 主讲教师 diff --git a/config/locales/zh.yml b/config/locales/zh.yml index e9d3ed813..114e67370 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -614,7 +614,7 @@ zh: label_homework_info: 提交情况 #huang label_course_news_description: '课程必须是高校正式开设的课程,或是围绕特定主题定期发布课程资料的公共开放课程;
      如果您想创建一个协作研究空间,请您前往“我的项目”页面创建项目,谢谢!' - label_course_board: 讨论区 + label_course_board: 问答区 label_version: 版本 label_version_new: 新建版本 @@ -1731,7 +1731,7 @@ zh: label_newbie_faq: '新手指引 & 问答' label_hot_project: '热门项目' label_borad_project: 项目讨论区 - label_borad_course: 课程讨论区 + label_borad_course: 课程问答区 label_borad_org_subfield: 资源栏目讨论区 view_borad_course: 课程讨论 label_memo_create_succ: 发布成功 diff --git a/config/routes.rb b/config/routes.rb index 095470139..dd02bf4af 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -238,6 +238,8 @@ RedmineApp::Application.routes.draw do get 'stop_anonymous_comment' get 'alert_anonymous_comment' get 'alert_forbidden_anonymous_comment' + get 'alert_open_student_works' + get 'open_student_works' get 'start_evaluation_set' get 'score_rule_set' post 'set_evaluation_attr' @@ -503,8 +505,10 @@ RedmineApp::Application.routes.draw do match 'user_feedback4show', :to => 'users#user_feedback4show', :via => :get match 'user_visitorlist', :to => 'users#user_visitorlist', :via => :get match 'user_homeworks', :to => 'users#user_homeworks', :via => :get + match 'student_homeworks', :to => 'users#student_homeworks', :via => :get get 'user_import_homeworks' get 'user_search_homeworks' + get 'choose_user_course' get 'user_import_resource' match 'watch_projects', :to => 'users#watch_projects', :via => :get # @@ -533,10 +537,14 @@ RedmineApp::Application.routes.draw do match 'user_act_issue_assign_to', :to => 'users#user_act_issue_assign_to', :via => [:get, :post] get 'edit_brief_introduction' get "user_resource" + get "import_resources" + get "import_resources_search" + post "import_into_container" get "resource_search" post "user_resource_create" post "user_resource_delete" get "search_user_course" + post "send_homework_to_course" post "add_exist_file_to_course" post "add_exist_file_to_project" post 'add_exist_file_to_org' @@ -832,7 +840,7 @@ RedmineApp::Application.routes.draw do :controller => 'repositories', :format => false, :constraints => { - :action => /(browse|show|entry|raw|annotate|diff)/, + :action => /(browse|show|entry|raw|annotate|diff|commit_diff)/, :rev => /[a-z0-9\.\-_]+/ } @@ -851,15 +859,15 @@ RedmineApp::Application.routes.draw do :controller => 'repositories', :format => false, :constraints => { - :action => /(browse|show|entry|raw|annotate|diff)/, + :action => /(browse|show|entry|raw|annotate|diff|commit_diff)/, :rev => /[a-z0-9\.\-_]+/ } get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))', :controller => 'repositories', - :action => /(browse|show|entry|raw|changes|annotate|diff)/ + :action => /(browse|show|entry|raw|changes|annotate|diff|commit_diff)/ get 'projects/:id/repository/:action(/*path(.:ext))', :controller => 'repositories', - :action => /(browse|show|entry|raw|changes|annotate|diff)/ + :action => /(browse|show|entry|raw|changes|annotate|diff|commit_diff)/ get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil get 'projects/:id/repository', :to => 'repositories#show', :path => nil @@ -952,7 +960,8 @@ RedmineApp::Application.routes.draw do match 'admin/project_messages', as: :project_messages match'admin/course_messages', as: :course_messages get 'admin/notices' - get 'admin/latest_login_users' + match 'admin/latest_login_users', as: :latest_login_users + match 'admin/latest_login_teachers', as: :latest_login_teachers get 'admin/homework' resources :auth_sources do diff --git a/db/migrate/20160224074034_update_one_student_score.rb b/db/migrate/20160224074034_update_one_student_score.rb new file mode 100644 index 000000000..6e1930652 --- /dev/null +++ b/db/migrate/20160224074034_update_one_student_score.rb @@ -0,0 +1,38 @@ +class UpdateOneStudentScore < ActiveRecord::Migration + def up + student_work_score = StudentWorksScore.where("user_id = 11688 AND student_work_id = 34414").first + student_work_score.score = 100 + student_work_score.save + student_works = StudentWork.where("user_id = 6456") + student_works.each do |work| + unless work.student_works_scores.empty? + if work.student_works_scores.where(:reviewer_role => 2).empty? + work.teaching_asistant_score = nil + else + work.teaching_asistant_score = work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f + end + if work.student_works_scores.where(:reviewer_role => 3).empty? + work.student_score = nil + else + work.student_score = work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f + end + end + if work.teaching_asistant_score.nil? + work.final_score = work.student_score + elsif work.student_score.nil? + work.final_score = work.teaching_asistant_score + else + homework = HomeworkCommon.find work.homework_common_id + ta_proportion = homework.homework_detail_manual.ta_proportion + final_ta_score = BigDecimal.new("#{work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}") + final_s_score = BigDecimal.new("#{work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}")) + final_score = final_ta_score + final_s_score + work.final_score = format("%.2f",final_score.to_f) + end + work.save + end + end + + def down + end +end diff --git a/db/migrate/20160225024759_add_is_open_to_homewrok_common.rb b/db/migrate/20160225024759_add_is_open_to_homewrok_common.rb new file mode 100644 index 000000000..760205e26 --- /dev/null +++ b/db/migrate/20160225024759_add_is_open_to_homewrok_common.rb @@ -0,0 +1,5 @@ +class AddIsOpenToHomewrokCommon < ActiveRecord::Migration + def change + add_column :homework_commons, :is_open, :integer, :default => 0 + end +end diff --git a/db/migrate/20160303103231_add_homework_journal_to_course_contributor_scores.rb b/db/migrate/20160303103231_add_homework_journal_to_course_contributor_scores.rb new file mode 100644 index 000000000..e3d4310e6 --- /dev/null +++ b/db/migrate/20160303103231_add_homework_journal_to_course_contributor_scores.rb @@ -0,0 +1,5 @@ +class AddHomeworkJournalToCourseContributorScores < ActiveRecord::Migration + def change + add_column :course_contributor_scores, :homework_journal_num, :integer, :default => 0 + end +end diff --git a/db/migrate/20160304154005_add_news_num_to_course_contributor_scores.rb b/db/migrate/20160304154005_add_news_num_to_course_contributor_scores.rb new file mode 100644 index 000000000..4cb1679f5 --- /dev/null +++ b/db/migrate/20160304154005_add_news_num_to_course_contributor_scores.rb @@ -0,0 +1,5 @@ +class AddNewsNumToCourseContributorScores < ActiveRecord::Migration + def change + add_column :course_contributor_scores, :news_num, :integer , :default => 0 + end +end diff --git a/db/migrate/20160304234903_uodapte_contributor_course.rb b/db/migrate/20160304234903_uodapte_contributor_course.rb new file mode 100644 index 000000000..e0f86550d --- /dev/null +++ b/db/migrate/20160304234903_uodapte_contributor_course.rb @@ -0,0 +1,51 @@ +class UodapteContributorCourse < ActiveRecord::Migration + def up + Course.all.each do |course| + if course.course_activities.count > 1 + course.members.each do |s| + puts course.id + puts course.name + puts s.user_id + # board_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?",s.student_id, course.id, "Message").count * 2 + # 发帖数 + board_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is null;").count + # 回帖数 + message_reply_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is not null").count * 1 + # 新闻回复 + common_reply_count = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{s.user_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count * 1 + # 通知 + common_count = News.find_by_sql("select n.* from news n where n.author_id = #{s.user_id} and n.course_id = #{course.id} ").count * 1 + # attachment_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "Attachment").count * 5 + # 附件数 + attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{s.user_id} and container_type ='Course'").count + # 课程留言数 + journal_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.user_id, course.id, "Course").count * 1 + # 作业留言 + journal_homework_count = JournalsForMessage.find_by_sql("SELECT jfm.* FROM `journals_for_messages` jfm, homework_commons hc where hc.id = jfm.jour_id and hc.course_id =#{course.id} and jfm.user_id =#{s.user_id} and jfm.jour_type ='HomeworkCommon';").count * 1 + # journal_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "JournalsForMessage").count * 1 + # journal_reply_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and status =?", s.student_id, course.id, "Course",1).count * 1 + total = board_count + message_reply_count + common_reply_count + attachment_count + journal_count + course_contributor = CourseContributorScore.where("course_id =? and user_id =?", course.id, s.user_id).first + if course_contributor.nil? + CourseContributorScore.create(:course_id => course.id, :user_id => s.user_id, :message_num => board_count, :message_reply_num => message_reply_count, + :news_reply_num => common_reply_count, :news_num => common_count, :resource_num => attachment_count, :journal_num => journal_count, + :homework_journal_num => journal_homework_count, :journal_reply_num => 0, :total_score => total) + else + course_contributor.message_num = board_count + course_contributor.message_reply_num = message_reply_count + course_contributor.news_reply_num = common_reply_count + course_contributor.news_num = common_count + course_contributor.resource_num = attachment_count + course_contributor.journal_num = journal_count + course_contributor.homework_journal_num = journal_homework_count + course_contributor.save + end + + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index db33479a5..a7ffc23b1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160223073859) do +ActiveRecord::Schema.define(:version => 20160304234903) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -432,9 +432,11 @@ ActiveRecord::Schema.define(:version => 20160223073859) do t.integer "resource_num" t.integer "journal_num" t.integer "journal_reply_num" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "total_score" + t.integer "homework_journal_num", :default => 0 + t.integer "news_num", :default => 0 end create_table "course_groups", :force => true do |t| @@ -751,6 +753,14 @@ ActiveRecord::Schema.define(:version => 20160223073859) do t.integer "locked" end + create_table "forwards", :force => true do |t| + t.integer "from_id" + t.string "from_type" + t.integer "to_id" + t.string "to_type" + t.datetime "created_at" + end + create_table "groups_users", :id => false, :force => true do |t| t.integer "group_id", :null => false t.integer "user_id", :null => false @@ -788,6 +798,7 @@ ActiveRecord::Schema.define(:version => 20160223073859) do t.integer "teacher_priority", :default => 1 t.integer "anonymous_comment", :default => 0 t.integer "quotes", :default => 0 + t.integer "is_open", :default => 0 end add_index "homework_commons", ["course_id", "id"], :name => "index_homework_commons_on_course_id_and_id" @@ -1269,7 +1280,6 @@ ActiveRecord::Schema.define(:version => 20160223073859) do t.text "description" t.integer "creator_id" t.integer "home_id" - t.string "domain" t.boolean "is_public" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false diff --git a/lib/gitlab-cli/lib/gitlab/client/projects.rb b/lib/gitlab-cli/lib/gitlab/client/projects.rb index 8d91edd06..2cc96c4d1 100644 --- a/lib/gitlab-cli/lib/gitlab/client/projects.rb +++ b/lib/gitlab-cli/lib/gitlab/client/projects.rb @@ -85,8 +85,8 @@ class Gitlab::Client # public (optional) - if true same as setting visibility_level = 20 # visibility_level (optional) - def edit_project(id, visibility_level) - put("/projects/#{id}", :body => {:visibility_level => visibility_level}) + def edit_project(id, visibility_level, default_branch) + put("/projects/#{id}", :body => {:visibility_level => visibility_level, :default_branch => default_branch}) end # Deletes a project. diff --git a/public/images/vlicon/file.png b/public/images/vlicon/file.png new file mode 100644 index 000000000..bbfa6078d Binary files /dev/null and b/public/images/vlicon/file.png differ diff --git a/public/javascripts/des_kindEditor.js b/public/javascripts/des_kindEditor.js index 206448044..f8aff0be7 100644 --- a/public/javascripts/des_kindEditor.js +++ b/public/javascripts/des_kindEditor.js @@ -90,7 +90,9 @@ function init_form(params){ } function nh_reset_form(params){ params.form[0].reset(); - params.texttitle.empty(); + $("#document_title").val(""); + $('#org_document_editor').hide(); + $('#doc_title_hint').hide(); params.textarea.empty(); if(params.editor != undefined){ params.editor.html(params.textarea.html()); @@ -134,4 +136,8 @@ function init_des_data(){ } }); }); + + div_form = $("div[nhname='new_topic_form']"); + $(".ke-edit", div_form).css("height","150px"); + $(".ke-edit-iframe",div_form).css("height","150px"); } \ No newline at end of file diff --git a/public/javascripts/homework.js b/public/javascripts/homework.js index f652d0ce8..337c5a9a0 100644 --- a/public/javascripts/homework.js +++ b/public/javascripts/homework.js @@ -151,7 +151,7 @@ $(function(){ modal: true, autoOpen: false, dialogClass: 'BluePopupBox', - minWidth: 753 + minWidth: 771 }); $('#BluePopupBox').parent().resizable("disable"); $('#BluePopupBox').parent().removeClass("ui-state-disabled"); @@ -243,6 +243,10 @@ $(function(){ $(this).parent('.mt10').after(html); var inputs = document.getElementsByName("program[input][]"); var outputs = document.getElementsByName("program[output][]"); + var inputs_labels = document.getElementsByName("inputs_label"); + for(var j= 0; j