From 46217fb85dbd565c29ee329071d8bb09c4885d44 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 13 Jan 2016 10:02:43 +0800 Subject: [PATCH 01/31] =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=88=86=E6=94=AF?= =?UTF-8?q?=E5=90=8E=E6=96=B0=E5=87=BA=E7=8E=B0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/tags_controller.rb | 1390 ++++++++--------- app/views/tags/update_project_tag_name.js.erb | 20 +- app/views/users/search_user_course.js.erb | 40 +- app/views/users/search_user_org.js.erb | 16 +- app/views/users/search_user_project.js.erb | 34 +- 5 files changed, 750 insertions(+), 750 deletions(-) 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/views/tags/update_project_tag_name.js.erb b/app/views/tags/update_project_tag_name.js.erb index c1d181e35..1dc5d58fa 100644 --- a/app/views/tags/update_project_tag_name.js.erb +++ b/app/views/tags/update_project_tag_name.js.erb @@ -1,11 +1,11 @@ -<% if @obj %> -$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); -$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_list', - :locals => {:obj => @obj,:object_flag => @obj_flag,:select_tag_name => @select_tag_name}) %>'); -$("#tags_name_<%=@obj.id%>").val(""); -$("#add_tag_<%=@obj.id%>").hide(); -<% else %> -$("#course_list").html("<%= escape_javascript(render :partial => 'files/project_list', - :locals => {project: @project,all_attachments: @all_attachments,sort:@sort,order:@order,project_attachments:@obj_attachments}) %>"); -<% end %> +<% if @obj %> +$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); +$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_list', + :locals => {:obj => @obj,:object_flag => @obj_flag,:select_tag_name => @select_tag_name}) %>'); +$("#tags_name_<%=@obj.id%>").val(""); +$("#add_tag_<%=@obj.id%>").hide(); +<% else %> +$("#course_list").html("<%= escape_javascript(render :partial => 'files/project_list', + :locals => {project: @project,all_attachments: @all_attachments,sort:@sort,order:@order,project_attachments:@obj_attachments}) %>"); +<% end %> $("#files_tag_project").html("<%= escape_javascript(render :partial => "files/tag_yun_project", :locals => {:tag_list => @tag_list,:project => @project,:tag_name => @select_tag_name}) %>"); \ No newline at end of file diff --git a/app/views/users/search_user_course.js.erb b/app/views/users/search_user_course.js.erb index d0ac40ed0..ba9dabb51 100644 --- a/app/views/users/search_user_course.js.erb +++ b/app/views/users/search_user_course.js.erb @@ -1,20 +1,20 @@ -//var screenWidth = $(window).width(); -//var screenHeight = $(window).height(); //当前浏览器窗口的 宽高 -//var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度 -//var objLeft = (screenWidth - 2)/2.5 ; //2 可以根据需要修改 -//var objTop = (screenHeight - 100)/2 + scrolltop; //100可以根据需要修改 -//var popupHeight = $(".resourceSharePopup").outerHeight(true); -//$(".resourceSharePopup").css("marginTop",-popupHeight/2); -// -//$("#upload_box").css('left','').css('top',''); -//$("#upload_box").html('<%#= escape_javascript( render :partial => "resource_share_popup" ,:locals => {:courses=>@course,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); -//$("#upload_box").css('display','block'); -$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_popup' ,:locals => {:courses=>@course,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); -showModal('ajax-modal', '452px'); -$('#ajax-modal').siblings().remove(); -$('#ajax-modal').before(""); -$('#ajax-modal').parent().css("top","415px").css("left","1045px"); -$('#ajax-modal').parent().addClass("popbox").addClass("resourceUploadPopup"); -$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); -var val = $("#search_course_input").val(); -$("#search_course_input").val("").focus().val(val); +//var screenWidth = $(window).width(); +//var screenHeight = $(window).height(); //当前浏览器窗口的 宽高 +//var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度 +//var objLeft = (screenWidth - 2)/2.5 ; //2 可以根据需要修改 +//var objTop = (screenHeight - 100)/2 + scrolltop; //100可以根据需要修改 +//var popupHeight = $(".resourceSharePopup").outerHeight(true); +//$(".resourceSharePopup").css("marginTop",-popupHeight/2); +// +//$("#upload_box").css('left','').css('top',''); +//$("#upload_box").html('<%#= escape_javascript( render :partial => "resource_share_popup" ,:locals => {:courses=>@course,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +//$("#upload_box").css('display','block'); +$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_popup' ,:locals => {:courses=>@course,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +showModal('ajax-modal', '452px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","415px").css("left","1045px"); +$('#ajax-modal').parent().addClass("popbox").addClass("resourceUploadPopup"); +$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); +var val = $("#search_course_input").val(); +$("#search_course_input").val("").focus().val(val); diff --git a/app/views/users/search_user_org.js.erb b/app/views/users/search_user_org.js.erb index db099fe72..e9faaf5be 100644 --- a/app/views/users/search_user_org.js.erb +++ b/app/views/users/search_user_org.js.erb @@ -1,9 +1,9 @@ -$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_for_orgs' ,:locals => {:orgs=>@orgs,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); -showModal('ajax-modal', '452px'); -$('#ajax-modal').siblings().remove(); -$('#ajax-modal').before(""); -$('#ajax-modal').parent().css("top","415px").css("left","1045px"); -$('#ajax-modal').parent().addClass("popbox").addClass("shareDP"); -$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); -var val = $("#search_org_input").val(); +$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_for_orgs' ,:locals => {:orgs=>@orgs,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +showModal('ajax-modal', '452px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","415px").css("left","1045px"); +$('#ajax-modal').parent().addClass("popbox").addClass("shareDP"); +$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); +var val = $("#search_org_input").val(); $("#search_org_input").val("").focus().val(val); \ No newline at end of file diff --git a/app/views/users/search_user_project.js.erb b/app/views/users/search_user_project.js.erb index 0632ebb98..569cd8d34 100644 --- a/app/views/users/search_user_project.js.erb +++ b/app/views/users/search_user_project.js.erb @@ -1,17 +1,17 @@ - -//var popupHeight = $(".resourceSharePopup").outerHeight(true); -//$(".resourceSharePopup").css("marginTop",-popupHeight/2); -// -//$("#upload_box").css('left','').css('top',''); -//$("#upload_box").html('<%#= escape_javascript( render :partial => "resource_share_for_project_popup" ,:locals => {:projects=>@projects,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); -//$("#upload_box").css('display','block'); -$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_for_project_popup' ,:locals => {:projects=>@projects,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); -showModal('ajax-modal', '452px'); -$('#ajax-modal').siblings().remove(); -$('#ajax-modal').before(""); -$('#ajax-modal').parent().css("top","415px").css("left","1045px"); -$('#ajax-modal').parent().addClass("resourceUploadPopup").addClass("popbox") -$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); -//$("#search_project_input").focus(); -var val = $("#search_project_input").val(); -$("#search_project_input").val("").focus().val(val); + +//var popupHeight = $(".resourceSharePopup").outerHeight(true); +//$(".resourceSharePopup").css("marginTop",-popupHeight/2); +// +//$("#upload_box").css('left','').css('top',''); +//$("#upload_box").html('<%#= escape_javascript( render :partial => "resource_share_for_project_popup" ,:locals => {:projects=>@projects,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +//$("#upload_box").css('display','block'); +$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_for_project_popup' ,:locals => {:projects=>@projects,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +showModal('ajax-modal', '452px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","415px").css("left","1045px"); +$('#ajax-modal').parent().addClass("resourceUploadPopup").addClass("popbox") +$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px"); +//$("#search_project_input").focus(); +var val = $("#search_project_input").val(); +$("#search_project_input").val("").focus().val(val); From 6a83a9b55cbd03d64ddbf542c87aef557ee94d42 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 25 Jan 2016 15:43:37 +0800 Subject: [PATCH 02/31] =?UTF-8?q?=E9=97=AE=E9=A2=98=E8=B7=9F=E8=B8=AA?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/users_helper.rb | 1216 ++++++++--------- .../users/_project_issue_detail.html.erb | 228 ++-- db/schema.rb | 4 +- 3 files changed, 725 insertions(+), 723 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 43ef7cefc..e23d21691 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,608 +1,608 @@ -# 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 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 => " f16 fb c_dblue " - 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 - 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 - 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 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 + 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 + 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 diff --git a/app/views/users/_project_issue_detail.html.erb b/app/views/users/_project_issue_detail.html.erb index e46761bd1..a6614399d 100644 --- a/app/views/users/_project_issue_detail.html.erb +++ b/app/views/users/_project_issue_detail.html.erb @@ -1,115 +1,115 @@ - -
-
-
    - <%#= labelled_fields_for :issue, @issue do |f| %> - <%#= f.select :status_id, ([["新增",1],["正在解决",2],["已解决",3],["反馈",4],["关闭",5],["拒绝",6]].unshift(["状态",0])), - {:include_blank => false, :selected => @status_id ? @status_id : 0 }, - {:onchange=>"remote_function('#issue_query_form_#{activity.id}');",:id=>"status_id",:name=>"status_id",:class=>"w70 undis issueEdit"} %> - <%# end %> - <%= form_tag({:controller => 'issues', :action => 'update', :issue_id => activity.id, :issue_detail => true, :type => "status"},:remote=>'true', :method => :put, :id=>"issue_query_form_#{activity.id}", :class => 'query_form') do %> -
  • -

     状态  : 

    -

    <%= activity.status.name %>

    - <%= select( :issue,:status, [["新增",1],["正在解决",2],["已解决",3],["反馈",4],["关闭",5],["拒绝",6]].unshift(["状态",0]), - {:include_blank => false, :selected => @status_id ? @status_id : 0 }, - {:onchange=>"remote_function('#issue_query_form_#{activity.id}');",:id=>"status_id",:name=>"status_id",:class=>"w70 undis issueEdit"} - ) - %> -
  • - <% end %> -
    - <%= form_tag({:controller => 'issues', :action => 'update', :issue_id => activity.id, :issue_detail => true, :type => "assigned"},:remote=>'true', :method => :put, :id=>"issue_query_assign_form_#{activity.id}", :class => 'query_form') do %> -
  • -

     指派  : 

    - - <%= link_to activity.try(:assigned_to), user_path(activity.assigned_to_id), :class => "linkBlue hidden", :style => "max-width:50px; display:inline-block;" %> - - <%= select( :issue, :user_id, principals_options_for_isuue_list(activity.project), - { :include_blank => false,:selected => @assign_to_id ? @assign_to_id : 0}, - {:onchange=>"remote_function('#issue_query_assign_form_#{activity.id}');", :id =>"assigned_to_id", :name => "assigned_to_id",:class=>"w70 undis issueEdit"}) %> -
  • - <% end %> -
    -
-
    - <%= form_tag({:controller => 'issues', :action => 'update', :issue_id => activity.id, :issue_detail => true, :type => "prior"},:remote=>'true', :method => :put, :id=>"issue_query_prior_form_#{activity.id}", :class => 'query_form') do %> -
  • -

     优先级  : 

    - <%= activity.priority.name %> - <%= select( :issue,:prior, [["低",1],["正常",2],["高",3],["紧急",4],["立刻",5]].unshift(["优先级",0]), - {:include_blank => false,:selected=>@priority_id ? @priority_id : 0}, - {:onchange=>"remote_function('#issue_query_prior_form_#{activity.id}');",:id=>"priority_id",:name=>"priority_id",:class=>"w70 undis issueEdit"}) %> -
  • - <% end %> -
    - <%= form_tag({:controller => 'issues', :action => 'update', :issue_id => activity.id, :issue_detail => true, :type => "ratio"},:remote=>'true', :method => :put, :id=>"issue_query_done_form_#{activity.id}", :class => 'query_form') do %> -
  • -

     完成度  : 

    - <%= activity.done_ratio %>% - <%= select( :issue,:done_ratio, ((0..10).to_a.collect { |r| ["#{r*10} %", r*10] }), - {:include_blank => false, :selected => @done_ratio ? @done_ratio : 0}, - {:onchange=>"remote_function('#issue_query_done_form_#{activity.id}');",:id=>"done_ratio",:name=>"done_ratio",:class=>"w70 undis issueEdit"}) %> - <% end %> -
  • - -
    -
-
    -
  • -

     开始  : 

    -

    <%= format_date(activity.start_date) %>

    -
  • -
    -
  • -

     周期  : 

    - <%= l_hours(activity.estimated_hours) %>
  • -
    -
-
    -
  • -

     计划完成  : 

    - <%= format_date(activity.due_date)? format_date(activity.due_date) : "--" %>
  • -
    -
  • -

     目标版本  : 

    - <%= (activity.fixed_version ? link_to_user_version(activity.fixed_version) : "--") %>
  • -
    -
- + +
+
+
    + <%#= labelled_fields_for :issue, @issue do |f| %> + <%#= f.select :status_id, ([["新增",1],["正在解决",2],["已解决",3],["反馈",4],["关闭",5],["拒绝",6]].unshift(["状态",0])), + {:include_blank => false, :selected => @status_id ? @status_id : 0 }, + {:onchange=>"remote_function('#issue_query_form_#{activity.id}');",:id=>"status_id",:name=>"status_id",:class=>"w70 undis issueEdit"} %> + <%# end %> + <%= form_tag({:controller => 'issues', :action => 'update', :issue_id => activity.id, :issue_detail => true, :type => "status"},:remote=>'true', :method => :put, :id=>"issue_query_form_#{activity.id}", :class => 'query_form') do %> +
  • +

     状态  : 

    +

    <%= activity.status.name %>

    + <%= select( :issue,:status, [["新增",1],["正在解决",2],["已解决",3],["反馈",4],["关闭",5],["拒绝",6]].unshift(["状态",0]), + {:include_blank => false, :selected => @status_id ? @status_id : 0 }, + {:onchange=>"remote_function('#issue_query_form_#{activity.id}');",:id=>"status_id",:name=>"status_id",:class=>"w70 undis issueEdit",:style=>"white-space:nowrap; overflow:hidden;"} + ) + %> +
  • + <% end %> +
    + <%= form_tag({:controller => 'issues', :action => 'update', :issue_id => activity.id, :issue_detail => true, :type => "assigned"},:remote=>'true', :method => :put, :id=>"issue_query_assign_form_#{activity.id}", :class => 'query_form') do %> +
  • +

     指派  : 

    + + <%= link_to activity.try(:assigned_to), user_path(activity.assigned_to_id), :class => "linkBlue hidden", :style => "max-width:50px; display:inline-block;" %> + + <%= select( :issue, :user_id, principals_options_for_isuue_list(activity.project), + { :include_blank => false,:selected => @assign_to_id ? @assign_to_id : 0}, + {:onchange=>"remote_function('#issue_query_assign_form_#{activity.id}');", :id =>"assigned_to_id", :name => "assigned_to_id",:class=>"w70 undis issueEdit"}) %> +
  • + <% end %> +
    +
+
    + <%= form_tag({:controller => 'issues', :action => 'update', :issue_id => activity.id, :issue_detail => true, :type => "prior"},:remote=>'true', :method => :put, :id=>"issue_query_prior_form_#{activity.id}", :class => 'query_form') do %> +
  • +

     优先级  : 

    + <%= activity.priority.name %> + <%= select( :issue,:prior, [["低",1],["正常",2],["高",3],["紧急",4],["立刻",5]].unshift(["优先级",0]), + {:include_blank => false,:selected=>@priority_id ? @priority_id : 0}, + {:onchange=>"remote_function('#issue_query_prior_form_#{activity.id}');",:id=>"priority_id",:name=>"priority_id",:class=>"w70 undis issueEdit"}) %> +
  • + <% end %> +
    + <%= form_tag({:controller => 'issues', :action => 'update', :issue_id => activity.id, :issue_detail => true, :type => "ratio"},:remote=>'true', :method => :put, :id=>"issue_query_done_form_#{activity.id}", :class => 'query_form') do %> +
  • +

     完成度  : 

    + <%= activity.done_ratio %>% + <%= select( :issue,:done_ratio, ((0..10).to_a.collect { |r| ["#{r*10} %", r*10] }), + {:include_blank => false, :selected => @done_ratio ? @done_ratio : 0}, + {:onchange=>"remote_function('#issue_query_done_form_#{activity.id}');",:id=>"done_ratio",:name=>"done_ratio",:class=>"w70 undis issueEdit"}) %> + <% end %> +
  • + +
    +
+
    +
  • +

     开始  : 

    +

    <%= format_date(activity.start_date) %>

    +
  • +
    +
  • +

     周期  : 

    + <%= l_hours(activity.estimated_hours) %>
  • +
    +
+
    +
  • +

     计划完成  : 

    + <%= format_date(activity.due_date)? format_date(activity.due_date) : "--" %>
  • +
    +
  • +

     目标版本  : 

    + <%= (activity.fixed_version ? link_to_user_version(activity.fixed_version) : "--") %>
  • +
    +
+
\ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 7e6291806..5ef8d4514 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 => 20160122083507) do +ActiveRecord::Schema.define(:version => 20160122094829) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1217,6 +1217,7 @@ ActiveRecord::Schema.define(:version => 20160122083507) do create_table "org_members", :force => true do |t| t.integer "user_id" t.integer "organization_id" + t.string "role" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end @@ -1372,6 +1373,7 @@ ActiveRecord::Schema.define(:version => 20160122083507) do t.integer "board_message_num", :default => 0 t.integer "board_num", :default => 0 t.integer "attach_num", :default => 0 + t.datetime "commit_time" end create_table "project_statuses", :force => true do |t| From 82e4fe16105ae10b5e2d44d0c783130993fdb25a Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 29 Jan 2016 16:33:33 +0800 Subject: [PATCH 03/31] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 5ef8d4514..29a9329a3 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 => 20160122094829) do +ActiveRecord::Schema.define(:version => 20160122143138) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false From fa70e8a714ddf427b64abfd275105cb49548e5b1 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 29 Jan 2016 16:51:46 +0800 Subject: [PATCH 04/31] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 72dd0a741..d60d63e5a 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -81,7 +81,7 @@ class IssuesController < ApplicationController @priority_id = params[:priority_id] @status_id = params[:status_id] @subject = params[:subject] - @done_ratio = parmas[:done_ratio] + @done_ratio = params[:done_ratio] @issue_count = @query.issue_count @issue_pages = Paginator.new @issue_count, @limit, params['page'] params[:page] = (params[:page] || 1).to_i + 1 #页码需要加1 From e6d4d7d0cbcb1624a14932bc63b4c425fae86acf Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 2 Feb 2016 17:16:50 +0800 Subject: [PATCH 05/31] =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E6=A1=86=E7=9A=84?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=A2=9E=E9=AB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/org_document_comments/_new.html.erb | 23 +++++++++++-------- app/views/org_document_comments/edit.html.erb | 2 +- app/views/org_document_comments/new.html.erb | 2 +- public/javascripts/des_kindEditor.js | 8 ++++++- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/views/org_document_comments/_new.html.erb b/app/views/org_document_comments/_new.html.erb index 3d8e8bc23..9d3fe2de8 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 b17ae0e75..71ab98764 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 30e397422..ba06e8589 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/public/javascripts/des_kindEditor.js b/public/javascripts/des_kindEditor.js index 1b952672a..f09568faa 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()); @@ -133,4 +135,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 From 44f192e5a65772099219f0c27633347d30fdea2d Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 23 Feb 2016 13:02:37 +0800 Subject: [PATCH 06/31] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=80=BB=E6=95=B0=E4=B8=BA=E8=B4=9F=E6=95=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index ea9ad2cc0..0bbbd9a54 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -643,8 +643,13 @@ 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 + if attach_count < 0 + self.container.project_score.update_attribute(:attach_num, 0) + else + self.container.project_score.update_attribute(:attach_num, attach_count) + end + end end end From 90208e166f5ba09146c00c2d9477f1bfe894de44 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 23 Feb 2016 13:24:20 +0800 Subject: [PATCH 07/31] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E5=B0=8F=E4=BA=8E0=E6=83=85=E5=86=B5=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 7 +------ app/models/issue.rb | 2 +- app/models/journal.rb | 5 +++-- app/models/message.rb | 4 ++-- app/models/news.rb | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 0bbbd9a54..588ee144d 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -644,12 +644,7 @@ class Attachment < ActiveRecord::Base def decrease_attchments_count if self.container_type == "Project" && !self.project.project_score.nil? attach_count = self.container.project_score.attach_num - 1 - if attach_count < 0 - self.container.project_score.update_attribute(:attach_num, 0) - else - self.container.project_score.update_attribute(:attach_num, attach_count) - end - + self.container.project_score.update_attribute(:attach_num, attach_count < 0 ? 0 : attach_count) end end 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/message.rb b/app/models/message.rb index 675d37790..6381f444f 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -146,10 +146,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 diff --git a/app/models/news.rb b/app/models/news.rb index fee5d2801..d0fccae17 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -126,7 +126,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 From 40fb140b6d52c7bb662ce283afbc0ac8f5c692f9 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 23 Feb 2016 15:09:15 +0800 Subject: [PATCH 08/31] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E8=AE=B0=E5=BD=95diff=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 6 ++++++ app/views/repositories/_revisions.html.erb | 2 +- config/routes.rb | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 707e87fd1..95e9acc80 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -521,6 +521,12 @@ update end end + # 没次提交对应的文件差异 + def commit_diff + + end + + def diff if params[:format] == 'diff' @diff = @repository.diff(@path, @rev, @rev_to) diff --git a/app/views/repositories/_revisions.html.erb b/app/views/repositories/_revisions.html.erb index 4d6e39f88..6de04b1d2 100644 --- a/app/views/repositories/_revisions.html.erb +++ b/app/views/repositories/_revisions.html.erb @@ -40,7 +40,7 @@ <%= 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 => 'revision', :id => repository.project, :repository_id => repository.identifier_param, :rev => rev %>
diff --git a/config/routes.rb b/config/routes.rb index 7060e4eb6..310fe29dd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -831,7 +831,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\.\-_]+/ } @@ -850,15 +850,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 From e4bf35a1b824891869ae71b15a4e2ce8aa434d9a Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 23 Feb 2016 15:22:44 +0800 Subject: [PATCH 09/31] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E7=95=99=E8=A8=80?= =?UTF-8?q?=E7=9A=84=E5=9B=9E=E5=A4=8D=E4=B8=8D=E8=83=BD=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/words_controller.rb | 7 ++++++- app/views/users/_user_journalsformessage.html.erb | 2 +- app/views/words/create_reply.js.erb | 4 ++-- app/views/words/destroy.js.erb | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 351be4e64..d1aa67483 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -74,9 +74,10 @@ class WordsController < ApplicationController # render 'test/index' # } format.js { + #@reply_type = params[:reply_type] @user_activity_id = params[:user_activity_id] @activity = JournalsForMessage.find(parent_id) - @is_activity = params[:is_activity] + @is_activity = params[:is_activity] if params[:is_activity] } end @@ -98,6 +99,10 @@ class WordsController < ApplicationController @user_activity_id = params[:user_activity_id] if params[:user_activity_id] @is_activity = params[:is_activity].to_i if params[:is_activity] @activity = @journal_destroyed.parent if @journal_destroyed.parent + unless @activity + redirect_to feedback_path(@user) + return + end elsif @journal_destroyed.jour_type == 'HomeworkCommon' @homework = HomeworkCommon.find @journal_destroyed.jour_id if params[:user_activity_id] diff --git a/app/views/users/_user_journalsformessage.html.erb b/app/views/users/_user_journalsformessage.html.erb index 4b2fcb486..f49a65262 100644 --- a/app/views/users/_user_journalsformessage.html.erb +++ b/app/views/users/_user_journalsformessage.html.erb @@ -47,7 +47,7 @@
  • <%= link_to(l(:label_bid_respond_delete), {:controller => 'words', :action => 'destroy', :object_id => activity, :user_id => activity.user,:user_activity_id => user_activity_id,:is_activity=>is_activity}, - :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', + :confirm => l(:text_are_you_sure), :method => 'delete', :class => "postOptionLink", :title => l(:button_delete)) %>
  • diff --git a/app/views/words/create_reply.js.erb b/app/views/words/create_reply.js.erb index a5c572049..ded05887f 100644 --- a/app/views/words/create_reply.js.erb +++ b/app/views/words/create_reply.js.erb @@ -1,11 +1,11 @@ <% if @save_succ %> <% if @user_activity_id %> - <% if @reply_type == 'user' %> + <% if @is_activity %> $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/user_journalsformessage', :locals => {:activity => @activity,:user_activity_id =>@user_activity_id,:is_activity=>@is_activity}) %>"); <% else %> $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_journalsformessage', :locals => {:activity => @activity,:user_activity_id =>@user_activity_id}) %>"); <% end %> - #init_activity_KindEditor_data('<%= @user_activity_id%>', "", "87%", "UserActivity"); + //init_activity_KindEditor_data('<%#= @user_activity_id%>', "", "87%", "UserActivity"); sd_create_editor_from_data('<%= @user_activity_id%>', "", "100%", "UserActivity"); <% else %> <% if !@jfm.nil? && @jfm.jour_type == 'Principal' %> diff --git a/app/views/words/destroy.js.erb b/app/views/words/destroy.js.erb index 819936f9f..a2d606e76 100644 --- a/app/views/words/destroy.js.erb +++ b/app/views/words/destroy.js.erb @@ -4,7 +4,8 @@ <% if @is_user%> <% if @activity %> $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/user_journalsformessage', :locals => {:activity => @activity,:user_activity_id =>@user_activity_id,:is_activity=>@is_activity}) %>"); - init_activity_KindEditor_data('<%= @user_activity_id%>', "", "87%", "UserActivity"); + //init_activity_KindEditor_data('<%#= @user_activity_id%>', "", "87%", "UserActivity"); + sd_create_editor_from_data('<%= @user_activity_id%>', "", "100%", "UserActivity"); <% else %> $("#user_activity_<%= @user_activity_id%>").hide(); <% end %> From 87f5f9c380b57052c00fc989eb9258b5accdea4b Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 23 Feb 2016 15:26:34 +0800 Subject: [PATCH 10/31] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E5=9B=BE=E7=89=87=E6=8E=92=E7=89=88=EF=BC=8C?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=85=B3=E8=81=94=E7=BB=84=E7=BB=87=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/courses/settings/_join_org.html.erb | 4 ++-- app/views/layouts/new_base_user.html.erb | 1 + public/stylesheets/org.css | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/courses/settings/_join_org.html.erb b/app/views/courses/settings/_join_org.html.erb index fff0f807c..f7b4d7551 100644 --- a/app/views/courses/settings/_join_org.html.erb +++ b/app/views/courses/settings/_join_org.html.erb @@ -15,8 +15,8 @@
      - 关联 - 取消 + 关联 + 取消 <% end %>
      diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index 7c4b4fad4..731162920 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -272,6 +272,7 @@

      预览

      <%= image_tag(url_to_avatar(@user), :style=>"width:96px;height:96px;",:class=>"mb5 mt10",:nhname=>'avatar_image') %> +
      96px*96px
      <%= image_tag(url_to_avatar(@user), :style=>"width:48px;height:48px;",:class=>"mb5",:nhname=>'avatar_image') %> diff --git a/public/stylesheets/org.css b/public/stylesheets/org.css index 06c8022c6..aa2d0be18 100644 --- a/public/stylesheets/org.css +++ b/public/stylesheets/org.css @@ -40,6 +40,8 @@ a.org_member_btn{ padding:1px 5px; background:#15bccf; color:#fff;} .searchOrg {height:24px; width:200px; color:#9b9b9b; border:1px solid #15bccf;} a.cancelBtn {padding:3px 5px; background-color:#D9D9D9; color:#656565;} a.cancelBtn:hover {background-color:#717171; color:#ffffff;} +a.org-cancel-btn {padding:3px 5px; background-color:#D9D9D9; color:#656565;} +a.org-cancel-btn:hover {background-color:#717171; color:#ffffff;} .relatedList ul li {border-bottom:1px solid #e4e4e4; width:320px; height:22px; vertical-align:middle; line-height:22px;} .relatedListName {width:240px; text-align:left; max-width:240px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis;} .relatedListOption {width:80px; text-align:center;} From c6d203d18676ae3a77afdcd4efb1e9f0acd25d0d Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 23 Feb 2016 15:51:33 +0800 Subject: [PATCH 11/31] =?UTF-8?q?=E4=BD=8E=E7=89=88=E6=9C=AC=E7=9A=84?= =?UTF-8?q?=E8=B0=B7=E6=AD=8C=E6=B5=8F=E8=A7=88=E5=99=A8=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BE=E7=A8=8B=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/courses_service.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index ef0c2eb16..2c8387349 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -252,6 +252,7 @@ class CoursesService def edit_course(params,course,current_user) course.send(:safe_attributes=, params[:course], current_user) #course.safe_attributes = params[:course] + course.password = params[:course][:password] course.time = params[:time] course.term = params[:term] course.end_time = params[:end_time] From c83562bfd7d2fdb4d5f275b2632ec7d570f16137 Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Tue, 23 Feb 2016 16:32:16 +0800 Subject: [PATCH 12/31] =?UTF-8?q?=E7=BB=84=E7=BB=87=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=EF=BC=9A=E5=A6=82=E5=9B=BE=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=95=B0=E7=BB=9F=E8=AE=A1=E5=BA=94=E8=AF=A5=E6=98=AF=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E8=BF=87=E6=BB=A4=E6=9D=A1=E4=BB=B6=E4=B8=8B=E5=90=84?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=95=B0=E7=9A=84=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/files/search_org_subfield_tag_attachment.js.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/files/search_org_subfield_tag_attachment.js.erb b/app/views/files/search_org_subfield_tag_attachment.js.erb index deed2d5d3..fe4aed937 100644 --- a/app/views/files/search_org_subfield_tag_attachment.js.erb +++ b/app/views/files/search_org_subfield_tag_attachment.js.erb @@ -1,2 +1,3 @@ $("#org_subfield_list").html("<%= escape_javascript(render :partial => 'org_subfield_list', - :locals => {org_subfield: @org_subfield,all_attachments: @result,sort:@sort,order:@order,org_subfield_attachments:@searched_attach})%>"); \ No newline at end of file + :locals => {org_subfield: @org_subfield,all_attachments: @result,sort:@sort,order:@order,org_subfield_attachments:@searched_attach})%>"); +$("#attachment_count").html("<%= @result.count %>"); \ No newline at end of file From 2a26fd4e75c42f93cdc8b661a4e2660aaf2d77b8 Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Tue, 23 Feb 2016 16:48:31 +0800 Subject: [PATCH 13/31] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E5=AD=90=E5=9F=9F=E5=90=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/base_org.html.erb | 6 +++--- app/views/organizations/_org_left_subfield_list.html.erb | 4 ++-- db/migrate/20160223021012_add_index_to_secdomain.rb | 5 ----- 3 files changed, 5 insertions(+), 10 deletions(-) delete mode 100644 db/migrate/20160223021012_add_index_to_secdomain.rb diff --git a/app/views/layouts/base_org.html.erb b/app/views/layouts/base_org.html.erb index 6062d760b..f810dd1d6 100644 --- a/app/views/layouts/base_org.html.erb +++ b/app/views/layouts/base_org.html.erb @@ -46,12 +46,12 @@ <% else %> - - + + <% 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/public/stylesheets/public.css b/public/stylesheets/public.css index 80c219350..7112bd3f3 100644 --- a/public/stylesheets/public.css +++ b/public/stylesheets/public.css @@ -113,6 +113,7 @@ h4{ font-size:14px; color:#3b3b3b;} .mt0 {margin-top:0px !important;} .mt3{ margin-top:3px;} .mt5{ margin-top:5px;} +.mt6{ margin-top:6px;} .mt8{ margin-top:8px;} .mt10{ margin-top:10px !important;} .mt20{margin-top: 20px;} From aef2dd8d1a83b82cc48f5a55073799a5fc92a767 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 25 Feb 2016 11:06:10 +0800 Subject: [PATCH 24/31] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E4=BF=AE=E8=AE=A2=E5=A5=BD=EF=BC=8C=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E7=9A=84=E6=96=87=E4=BB=B6=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=AF=B9=E5=BA=94=E5=86=85=E5=AE=B9=20=E9=AB=98?= =?UTF-8?q?=E4=BA=AE=E6=98=BE=E7=A4=BA=E5=86=85=E5=AE=B9=20=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E4=BF=AE=E8=AE=A2=E5=AF=B9=E6=AF=94=20=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 9 +-- app/helpers/repositories_helper.rb | 10 ++++ app/views/common/_file.html.erb | 2 +- .../repositories/_commit_details.html.erb | 15 +++++ .../repositories/_dir_list_content.html.erb | 8 +-- app/views/repositories/_revisions.html.erb | 18 +----- app/views/repositories/changes.html.erb | 2 +- app/views/repositories/commit_diff.html.erb | 55 ++++++++++++++++++ public/images/vlicon/file.png | Bin 0 -> 1167 bytes public/stylesheets/project.css | 19 +++++- 10 files changed, 110 insertions(+), 28 deletions(-) create mode 100644 app/views/repositories/_commit_details.html.erb create mode 100644 app/views/repositories/commit_diff.html.erb create mode 100644 public/images/vlicon/file.png diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 95e9acc80..7655f1eb4 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,12 +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) 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/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/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/_revisions.html.erb b/app/views/repositories/_revisions.html.erb index 6de04b1d2..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)) %>
        - <%= link_to truncate(changeset.short_id.to_s, :length => 20), :controller => 'repositories', :action => 'revision', :id => repository.project, :repository_id => repository.identifier_param, :rev => rev %> + <%= 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..c0308fea3 --- /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/public/images/vlicon/file.png b/public/images/vlicon/file.png new file mode 100644 index 0000000000000000000000000000000000000000..bbfa6078d3d01782244c2c3eab309b009087e03a GIT binary patch literal 1167 zcmaJ>TWHi+7>*WQZP$mY*miU=#D`UIlF3}snb@($$&8)VlrkN#g34r)(>8RH6O&UX z?SpuuC{9tq^;*j=K8aFA6x3QPC>6Do)d!JXx-TLq6sn-m2i@*T?bLnPF(f$`zVG}0 z|NI~4Xj9{sCFP!Sf*_V88^jbIm*Q{vqJ{Xs|BU_%9%@j$1vSG~l$R|)2rA41GO5dL zAO&Q#YtIuM;3vl z?FDMWf;u@8eQDN?s2Dcw#AD%;{yY`-NLqZ z8s66u#JsYkD5RY~v!AD@>&rsKva(-^io%E26Mg$%jP2@U_FTE8Wd4}08oHg+h#&r9 z&yu5C%tO`v_fI*OtF8>)eaTdfAD*lqd+Mdn4Htyt2V^Z*`S5CB_|c1PuecMFp-cXr zIJ@-d;D%#65A-a^eDXYhFqHe7>KT~0-FW@kCTe9v@a>zz_{HZngEiGRexJYN%-F7d zW0{rOp-Y5=i&K&#~k#&;| literal 0 HcmV?d00001 diff --git a/public/stylesheets/project.css b/public/stylesheets/project.css index 2ca1d56d8..1a231b8a0 100644 --- a/public/stylesheets/project.css +++ b/public/stylesheets/project.css @@ -896,9 +896,9 @@ a:hover.Reply_pic{border:1px solid #64bdd9;} /*end*/ /***** Diff *****/ .diff_out { background: #fcc; } -.diff_out span { background: #faa; } +/*.diff_out span { background: #faa; }*/ .diff_in { background: #cfc; } -.diff_in span { background: #afa; } +/*.diff_in span { background: #afa; }*/ .text-diff { padding: 1em; @@ -1169,3 +1169,18 @@ div.disable_link {background-color: #c1c1c1 !important;} .proInfoBox2{ border:1px solid #dddddd; height:45px; padding:10px 0; background-color:#f1f1f1;} .proInfoBox2 ul li{ height:24px; position:relative;} .maxwidth150{max-width: 150px;} + +/*版本库diff*/ +.showing-changes-info {width:650px; padding:10px; background-color:#ffffff; line-height:2;} +.showing-changes-project {width:650px; padding:10px; border-top:1px solid #dce0e6; border-bottom:1px solid #dce0e6; background-color:#f1f1f1;} +.showing-changes-row {width:650px; padding:10px; border-bottom:1px solid #dce0e6; background-color:#f1f1f1;} +#changed-files-detail {display:none;} +#changed-files-detail li {list-style-type:disc; margin-left:15px;} +.showing-changes-detail {width:670px; border-bottom:1px solid #dce0e6; background-color:#f1f1f1;} +.changes-detail-chart {width:100%; overflow:auto; border-collapse:collapse; margin:0px; padding:0px; background-color:#f1f1f1;} +.diff-line-number {width:35px; min-width:35px; max-width:50px; border-right:1px solid #c1c1c1; padding:0px 5px; text-align:right; background-color:#f1f1f1;} +.code-line-old {background-color:#ffecec;} +.number-line-old {background-color:#ffdddd; border-color:#f1c0c0;} +.code-line-new {background-color:#eaffea;} +.number-line-new {background-color:#dbffdb; border-color:#c1e9c1;} +.branch-label {padding-right: 5px; border-radius:2px; color:#888888; display:inline-block; background-color:#f8fafc;} \ No newline at end of file From 8b839caa48dfa146c3275c937bfd6056d54a1c37 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 25 Feb 2016 11:12:24 +0800 Subject: [PATCH 25/31] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/base_projects.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index 657873f8b..33c792aaf 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 %> From 100b002a1ffbd18017e687a49488bd65573a19ca Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 25 Feb 2016 15:48:49 +0800 Subject: [PATCH 26/31] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=94=B9=E5=8A=A8?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=A1=B5=E9=9D=A2=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/commit_diff.html.erb | 2 +- db/schema.rb | 8 +++++--- public/stylesheets/project.css | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/views/repositories/commit_diff.html.erb b/app/views/repositories/commit_diff.html.erb index c0308fea3..5ebeec09a 100644 --- a/app/views/repositories/commit_diff.html.erb +++ b/app/views/repositories/commit_diff.html.erb @@ -30,7 +30,7 @@
      - +
      <% line_num = diff_line_num(cd.diff) %> <% diff_content = diff_content(cd.diff) %> diff --git a/db/schema.rb b/db/schema.rb index c22b79790..c7fa64537 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 => 20160220100507) do +ActiveRecord::Schema.define(:version => 20160223073859) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -99,6 +99,8 @@ ActiveRecord::Schema.define(:version => 20160220100507) do t.integer "quotes" t.integer "version" t.integer "attachment_id" + t.integer "is_publish", :default => 1 + t.date "publish_time" end create_table "attachments", :force => true do |t| @@ -118,6 +120,8 @@ ActiveRecord::Schema.define(:version => 20160220100507) do t.integer "is_public", :default => 1 t.integer "copy_from" t.integer "quotes" + t.integer "is_publish", :default => 1 + t.date "publish_time" end add_index "attachments", ["author_id"], :name => "index_attachments_on_author_id" @@ -1265,7 +1269,6 @@ ActiveRecord::Schema.define(:version => 20160220100507) 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 @@ -1373,7 +1376,6 @@ ActiveRecord::Schema.define(:version => 20160220100507) do t.integer "changeset_num", :default => 0 t.integer "board_message_num", :default => 0 t.integer "board_num", :default => 0 - t.integer "act_num", :default => 0 t.integer "attach_num", :default => 0 t.datetime "commit_time" end diff --git a/public/stylesheets/project.css b/public/stylesheets/project.css index 1a231b8a0..3feeed844 100644 --- a/public/stylesheets/project.css +++ b/public/stylesheets/project.css @@ -1171,7 +1171,7 @@ div.disable_link {background-color: #c1c1c1 !important;} .maxwidth150{max-width: 150px;} /*版本库diff*/ -.showing-changes-info {width:650px; padding:10px; background-color:#ffffff; line-height:2;} +.showing-changes-info {width:650px; padding:10px; padding-top: 0px; background-color:#ffffff; line-height:2;} .showing-changes-project {width:650px; padding:10px; border-top:1px solid #dce0e6; border-bottom:1px solid #dce0e6; background-color:#f1f1f1;} .showing-changes-row {width:650px; padding:10px; border-bottom:1px solid #dce0e6; background-color:#f1f1f1;} #changed-files-detail {display:none;} From c93b4d109ad963db2555bed43bde140cd9a114eb Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 25 Feb 2016 16:18:24 +0800 Subject: [PATCH 27/31] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AD=90=E8=8F=9C=E5=8D=95=EF=BC=9A=E5=85=AC?= =?UTF-8?q?=E5=BC=80=E4=BD=9C=E5=93=81/=E5=8F=96=E6=B6=88=E5=85=AC?= =?UTF-8?q?=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 28 ++- app/controllers/student_work_controller.rb | 191 ++++++++++-------- .../_alert_open_student_works.html.erb | 23 +++ .../alert_open_student_works.js.erb | 6 + .../homework_common/open_student_works.js.erb | 7 + .../_org_course_homework.html.erb | 9 + .../student_work/_student_work_list.html.erb | 9 +- app/views/users/_course_homework.html.erb | 9 + .../users/_user_homework_detail.html.erb | 9 + config/routes.rb | 2 + ...25024759_add_is_open_to_homewrok_common.rb | 5 + db/schema.rb | 15 +- 12 files changed, 220 insertions(+), 93 deletions(-) create mode 100644 app/views/homework_common/_alert_open_student_works.html.erb create mode 100644 app/views/homework_common/alert_open_student_works.js.erb create mode 100644 app/views/homework_common/open_student_works.js.erb create mode 100644 db/migrate/20160225024759_add_is_open_to_homewrok_common.rb 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/student_work_controller.rb b/app/controllers/student_work_controller.rb index 7ccb3177c..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 = [] - 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(: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 = [] - else - my_work = @homework.student_works.where(:id => pro.student_work_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 = [] - 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(:user_id => User.current.id) - end - if my_work.empty? - @stundet_works = [] - else + 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 - end - else - @stundet_works = [] - 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?) #老师 || 超级管理员 显示所有列表 - @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? + 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(: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 = [] + else + my_work = @homework.student_works.where(:id => pro.student_work_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 = [] + 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(:user_id => User.current.id) + end + if my_work.empty? @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) + @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 = @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 = [] - else - my_work = @homework.student_works.where(:id => pro.student_work_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 = [] - 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(: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").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count + else + 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.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(: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 = [] + else + my_work = @homework.student_works.where(:id => pro.student_work_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 = [] + 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(: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 = [] + end + else + 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 == "" 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/organizations/_org_course_homework.html.erb b/app/views/organizations/_org_course_homework.html.erb index b5e3c6958..40db2335f 100644 --- a/app/views/organizations/_org_course_homework.html.erb +++ b/app/views/organizations/_org_course_homework.html.erb @@ -240,6 +240,15 @@ <%= 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 %> + <% 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 %> 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/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index d508fe1af..e1d9ca0e0 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -239,6 +239,15 @@ <%= 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 %> + <% 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 %> diff --git a/app/views/users/_user_homework_detail.html.erb b/app/views/users/_user_homework_detail.html.erb index 01673d164..c2989ee14 100644 --- a/app/views/users/_user_homework_detail.html.erb +++ b/app/views/users/_user_homework_detail.html.erb @@ -243,6 +243,15 @@ <%= link_to("禁用匿评", alert_forbidden_anonymous_comment_homework_common_path(homework_common,:is_in_course => is_in_course),:class => "postOptionLink", :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 %> diff --git a/config/routes.rb b/config/routes.rb index 095470139..562fb8157 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' 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/schema.rb b/db/schema.rb index ef1a1b538..99804e63f 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 => 20160224074034) do +ActiveRecord::Schema.define(:version => 20160225024759) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -99,8 +99,6 @@ ActiveRecord::Schema.define(:version => 20160224074034) do t.integer "quotes" t.integer "version" t.integer "attachment_id" - t.integer "is_publish", :default => 1 - t.date "publish_time" end create_table "attachments", :force => true do |t| @@ -751,6 +749,14 @@ ActiveRecord::Schema.define(:version => 20160224074034) 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 +794,7 @@ ActiveRecord::Schema.define(:version => 20160224074034) 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,6 +1276,7 @@ ActiveRecord::Schema.define(:version => 20160224074034) 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 @@ -1376,6 +1384,7 @@ ActiveRecord::Schema.define(:version => 20160224074034) do t.integer "changeset_num", :default => 0 t.integer "board_message_num", :default => 0 t.integer "board_num", :default => 0 + t.integer "act_num", :default => 0 t.integer "attach_num", :default => 0 t.datetime "commit_time" end From 09c8e57f1c677614c83e7ebcd920491951e6a625 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 26 Feb 2016 10:41:14 +0800 Subject: [PATCH 28/31] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E6=97=B6=E5=8F=AF=E5=A4=8D=E5=88=B6=E8=B5=84=E6=BA=90=E5=92=8C?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 88 +++++++++++++++++++++++++ app/models/attachment.rb | 13 +++- app/views/courses/_copy_course.html.erb | 18 +++-- 3 files changed, 111 insertions(+), 8 deletions(-) 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/models/attachment.rb b/app/models/attachment.rb index c8aa33760..faeab1f30 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 diff --git a/app/views/courses/_copy_course.html.erb b/app/views/courses/_copy_course.html.erb index c7547adcd..0cd8804d9 100644 --- a/app/views/courses/_copy_course.html.erb +++ b/app/views/courses/_copy_course.html.erb @@ -93,15 +93,23 @@
    • - +
      • + + 作业
      • + 复制到新课中的作业将在1个月后发布、2个月后提交截止,请您调整作业的发布时间、截止时间等时间节点。 +
        +
      • + +
      • + 复制到新课的资源将在1个月后发布,请您调整资源的发布时间,否则学生可能看不到资源。
      -
        +
        <% end %> From e8234092ec3a2239d9c70d9f39ffadee36eebae3 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 26 Feb 2016 11:16:12 +0800 Subject: [PATCH 29/31] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=AD=A6=E6=9C=9F?= =?UTF-8?q?=E5=BC=B9=E6=A1=86=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/courses/_copy_course.html.erb | 17 ++++++++--------- app/views/courses/copy_course.js.erb | 2 +- db/schema.rb | 4 ++-- public/stylesheets/public.css | 1 + 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/views/courses/_copy_course.html.erb b/app/views/courses/_copy_course.html.erb index 0cd8804d9..68184d352 100644 --- a/app/views/courses/_copy_course.html.erb +++ b/app/views/courses/_copy_course.html.erb @@ -92,22 +92,21 @@ (选中后课外用户可见该课程,否则仅对课内成员可见)
        -
      • +
      • -
          -
        • -