From 46217fb85dbd565c29ee329071d8bb09c4885d44 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 13 Jan 2016 10:02:43 +0800 Subject: [PATCH 01/22] =?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/22] =?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/22] =?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/22] =?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 a2e60944be2fd3e8fcd9e9e1f6fc6316164c9406 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 23 Feb 2016 11:04:19 +0800 Subject: [PATCH 05/22] =?UTF-8?q?=E5=B7=B2=E5=8F=91=E5=B8=83=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E7=9A=84=E5=BB=B6=E6=9C=9F=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 27 +++++++- app/helpers/courses_helper.rb | 2 +- app/views/files/_course_list.html.erb | 80 +---------------------- app/views/files/_hidden_file.html.erb | 54 +++++++++++++++ app/views/files/_resource_detail.html.erb | 77 ++++++++++++++++++++++ app/views/files/_upload_course_files.erb | 2 +- app/views/files/file_hidden.js.erb | 6 ++ app/views/files/republish_file.js.erb | 2 + config/routes.rb | 3 + 9 files changed, 173 insertions(+), 80 deletions(-) create mode 100644 app/views/files/_hidden_file.html.erb create mode 100644 app/views/files/_resource_detail.html.erb create mode 100644 app/views/files/file_hidden.js.erb create mode 100644 app/views/files/republish_file.js.erb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index e83a13ad9..b18612243 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -26,7 +26,7 @@ class FilesController < ApplicationController before_filter :authorize, :except => [:create,:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project, :search_tag_attachment,:subfield_upload_file,:search_org_subfield_tag_attachment, :search_tag_attachment,:quote_resource_show_org_subfield,:find_org_subfield_attache, - :search_files_in_subfield,:upload_files_menu] + :search_files_in_subfield,:upload_files_menu,:file_hidden,:republish_file] helper :sort include SortHelper @@ -96,6 +96,31 @@ class FilesController < ApplicationController end end + def file_hidden + @file = Attachment.find params[:id] + @course = Course.find params[:course_id] + respond_to do |format| + format.js + end + end + + def republish_file + @file = Attachment.find params[:id] + @course = Course.find params[:course_id] + if params[:publish_time] + unless params[:publish_time] == "" + @file.publish_time = params[:publish_time] + end + end + if @file.publish_time > Date.today + @file.is_publish = 0 + end + @file.save + respond_to do |format| + format.js + end + end + def search_project sort = "" @sort = "" diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 6d0066fbc..2cdb277be 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -746,7 +746,7 @@ module CoursesHelper return[] unless course result = [] course.attachments.each do |attachment| - if attachment.is_public? ||User.current.allowed_to?(:as_teacher,Course.find(attachment.container_id))|| (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin? + if attachment.is_public? ||User.current == attachment.author ||User.current.allowed_to?(:as_teacher,Course.find(attachment.container_id))|| (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin? result << attachment end end diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index d7aade6c2..7724bb861 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -1,82 +1,8 @@ - -<% delete_allowed = User.current.allowed_to?(:manage_files, course) %> <% curse_attachments.each do |file| %> <% if file.is_public? || User.current.member_of_course?(course) || User.current.admin? %> -
-
-
- <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %> -
-
-
- <%= link_to truncate(file.filename,length: 35, omission: '...'), - download_named_attachment_path(file.id, file.filename), - :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkBlue f_14 f_b" %> - <%= file_preview_eye(file, class: 'preview') %> - - <% if file.is_public? == false%> - 私有 - <%end %> - - <% if file.is_publish == 0 %> - <%=file.publish_time %>  0点发布 - <% end %> -
-
- 上传时间:<%= format_time(file.created_on)%> - <% if file.tag_list.length > 0%> - 上传类型:<%= file.tag_list[0] %> - <% end %> -

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

-

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

-
-
-
- - <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> - <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> -
-
- -
    -
  • - <% if User.current.logged? %> - - <% if (is_course_teacher(User.current,@course) || file.author_id == User.current.id) && course_contains_attachment?(@course,file) %> - <% if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" %> -
      - -
    • <%= link_to("发       送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
    • -
    • <%= link_to '更新版本',attachments_versions_path(file),:class => "postOptionLink",:remote=>true %>
    • - <% if @course.is_public? %> -
    • - - <%= link_to (file.is_public? ? "设为私有":"设为公开"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"postOptionLink",:method => :post %> - -
    • - <%end%> -
    • - <%= link_to( '删除资源', attachment_path(file), - :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" && file.destroyable %> -
    • -
    - - <% end %> - <%else%> -
      -
    • <%= link_to("发  送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
    • -
    - <% end %> - <% end %> -
  • -
- -
-
-
-
-
-
+
+ <%=render :partial=>'files/resource_detail',:locals => {:file => file} %> +
<% else %>
<%= file.filename %>是私有资源
<% end %> diff --git a/app/views/files/_hidden_file.html.erb b/app/views/files/_hidden_file.html.erb new file mode 100644 index 000000000..eb0f366a3 --- /dev/null +++ b/app/views/files/_hidden_file.html.erb @@ -0,0 +1,54 @@ +发布设置 + +<%= form_tag(republish_file_course_file_path(@course,@file), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %> +
+ +
+ + <%#= calendar_for('attachment_publish_time')%> +
+ +
+
+ +
+ + +
+<% end %> +
+ \ No newline at end of file diff --git a/app/views/files/_resource_detail.html.erb b/app/views/files/_resource_detail.html.erb new file mode 100644 index 000000000..fd0a165aa --- /dev/null +++ b/app/views/files/_resource_detail.html.erb @@ -0,0 +1,77 @@ +<% delete_allowed = User.current.allowed_to?(:manage_files, @course) %> +
+
+
+ <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %> +
+
+
+ <%= link_to truncate(file.filename,length: 35, omission: '...'), + download_named_attachment_path(file.id, file.filename), + :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkBlue f_14 f_b" %> + <%= file_preview_eye(file, class: 'preview') %> + + <% if file.is_public? == false%> + 私有 + <%end %> + + <% if file.is_publish == 0 %> + <%=file.publish_time %>  0点发布 + <% end %> +
+
+ 上传时间:<%= format_time(file.created_on)%> + <% if file.tag_list.length > 0%> + 上传类型:<%= file.tag_list[0] %> + <% end %> +

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

+

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

+
+
+
+ + <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> + <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> +
+
+ +
    +
  • + <% if User.current.logged? %> + + <% if (is_course_teacher(User.current,@course) || file.author_id == User.current.id) && course_contains_attachment?(@course,file) %> + <% if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" %> +
      + +
    • <%= link_to("发       送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
    • +
    • <%= link_to '延期发布',file_hidden_course_file_path(@course,file),:class => "postOptionLink",:remote=>true %>
    • +
    • <%= link_to '更新版本',attachments_versions_path(file),:class => "postOptionLink",:remote=>true %>
    • + <% if @course.is_public? %> +
    • + + <%= link_to (file.is_public? ? "设为私有":"设为公开"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"postOptionLink",:method => :post %> + +
    • + <%end%> +
    • + <%= link_to( '删除资源', attachment_path(file), + :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" && file.destroyable %> +
    • +
    + + <% end %> + <%else%> +
      +
    • <%= link_to("发  送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
    • +
    + <% end %> + <% end %> +
  • +
+ +
+
+
+
+
+
\ No newline at end of file diff --git a/app/views/files/_upload_course_files.erb b/app/views/files/_upload_course_files.erb index 2e53f05d2..1b8b140a5 100644 --- a/app/views/files/_upload_course_files.erb +++ b/app/views/files/_upload_course_files.erb @@ -28,7 +28,7 @@ <%#= calendar_for('attachment_publish_time')%>
- +
<% end %> diff --git a/app/views/files/file_hidden.js.erb b/app/views/files/file_hidden.js.erb new file mode 100644 index 000000000..b95ab5104 --- /dev/null +++ b/app/views/files/file_hidden.js.erb @@ -0,0 +1,6 @@ +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'files/hidden_file',:locals => {:course => @course,:course_attachment_type => 1}) %>'); +showModal('ajax-modal', '311px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); +$('#ajax-modal').parent().addClass("popbox_polls"); \ No newline at end of file diff --git a/app/views/files/republish_file.js.erb b/app/views/files/republish_file.js.erb new file mode 100644 index 000000000..e85e5eb50 --- /dev/null +++ b/app/views/files/republish_file.js.erb @@ -0,0 +1,2 @@ +hideModal(); +$("#resource_detail_<%=@file.id %>").html("<%= escape_javascript(render :partial=>'files/resource_detail',:locals => {:file => @file}) %>") \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7060e4eb6..095470139 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -695,6 +695,7 @@ RedmineApp::Application.routes.draw do end member do match "quote_resource_show", :via => [:get] + get "file_hidden" end end @@ -1015,6 +1016,8 @@ RedmineApp::Application.routes.draw do end member do match "quote_resource_show", :via => [:get] + get "file_hidden" + post "republish_file" end end resources :memberships, :shallow => true, :controller => 'members', :only => [:index, :show, :new, :create, :update, :destroy] do From b6bf78a5df895e00e08f5e1ebebe8f0f0b9b04b8 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 23 Feb 2016 11:35:07 +0800 Subject: [PATCH 06/22] =?UTF-8?q?=E5=BD=93=E5=A4=A9=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=9A=84=E8=B5=84=E6=BA=90=E6=98=BE=E7=A4=BA=E6=9C=AA=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E3=80=81=E6=97=A5=E6=9C=9F=E9=80=89=E6=8B=A9=E5=99=A8?= =?UTF-8?q?=E7=94=A8=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 2 ++ app/views/files/_hidden_file.html.erb | 1 + app/views/files/_upload_course_files.erb | 1 + 3 files changed, 4 insertions(+) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index b18612243..ca37e445c 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -114,6 +114,8 @@ class FilesController < ApplicationController end if @file.publish_time > Date.today @file.is_publish = 0 + else + @file.is_publish = 1 end @file.save respond_to do |format| diff --git a/app/views/files/_hidden_file.html.erb b/app/views/files/_hidden_file.html.erb index eb0f366a3..8e359c605 100644 --- a/app/views/files/_hidden_file.html.erb +++ b/app/views/files/_hidden_file.html.erb @@ -1,3 +1,4 @@ + 发布设置 <%= form_tag(republish_file_course_file_path(@course,@file), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %> diff --git a/app/views/files/_upload_course_files.erb b/app/views/files/_upload_course_files.erb index 1b8b140a5..de43977cd 100644 --- a/app/views/files/_upload_course_files.erb +++ b/app/views/files/_upload_course_files.erb @@ -1,3 +1,4 @@ +

<%= l(:label_upload_files)%>

From c91ef44570f7941f759a82bfbdb3d87dab1f67ac Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Tue, 23 Feb 2016 12:52:04 +0800 Subject: [PATCH 07/22] =?UTF-8?q?=E7=BB=84=E7=BB=87=E5=AD=90=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=EF=BC=9A=E6=89=80=E6=9C=89=E5=AD=90=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=88=B0secdomains=E8=A1=A8=EF=BC=8C?= =?UTF-8?q?=E5=B0=86=E7=BB=84=E7=BB=87=E8=A1=A8=E4=B8=AD=E7=9A=84=E5=AD=90?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E8=BF=81=E7=A7=BB=E5=88=B0secdomains?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=EF=BC=8C=E5=B9=B6=E4=BF=AE=E6=94=B9=E7=9B=B8?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/org_subfields_controller.rb | 3 ++- app/controllers/organizations_controller.rb | 9 +++++++-- app/views/organizations/_subfield_list.html.erb | 2 +- app/views/organizations/setting.html.erb | 11 ++++++----- app/views/users/user_organizations.html.erb | 5 ----- .../20160223021012_add_index_to_secdomain.rb | 5 +++++ .../20160223021227_move_domain_to_secdomain.rb | 14 ++++++++++++++ ...60223031843_remove_domain_from_organizations.rb | 8 ++++++++ db/schema.rb | 9 +++++++-- 9 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20160223021012_add_index_to_secdomain.rb create mode 100644 db/migrate/20160223021227_move_domain_to_secdomain.rb create mode 100644 db/migrate/20160223031843_remove_domain_from_organizations.rb diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index bae0232a5..2a4bcf9c8 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -30,7 +30,8 @@ class OrgSubfieldsController < ApplicationController if params[:id] @organization = Organization.find(params[:id]) else - @organization = Organization.where("domain=?",request.subdomain).first + domain = Secdomain.where("subname=?", request.subdomain).first + @organization = Organization.find(domain.pid) end @org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+ "subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+ diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 6e2da311f..f225e7f50 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -139,7 +139,7 @@ class OrganizationsController < ApplicationController end def check_uniq_domain - @is_exist = (Organization.where("domain=?", params[:org_domain]).count > 0) + @is_exist = (Secdomain.where("subname=?",params[:org_domain]).count > 0) end def find_organization @@ -322,7 +322,12 @@ class OrganizationsController < ApplicationController def agree_apply_subdomain @organization = Organization.find(params[:organization_id]) OrgMessage.find(params[:act_id]).update_attribute(:viewed, 1) - @organization.update_attribute(:domain, params[:org_domain]) + if Secdomain.where("pid=? and sub_type=2",@organization.id).count > 0 + domain = Secdomain.where("pid=? and sub_type=2",params[:organization_id]).first + Secdomain.update(domain.id, :subname => params[:org_domain]) + else + Secdomain.create(:sub_type => 2, :pid => params[:organization_id], :subname => params[:org_domain]) + end if OrgMessage.where("message_type='AgreeApplySubdomain' and organization_id=#{@organization.id} and content=?",params[:org_domain]).count == 0 OrgMessage.create(:user_id => params[:user_id], :organization_id => @organization.id, :message_type => 'AgreeApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:org_domain]) end diff --git a/app/views/organizations/_subfield_list.html.erb b/app/views/organizations/_subfield_list.html.erb index b49436d4e..eed0dabf6 100644 --- a/app/views/organizations/_subfield_list.html.erb +++ b/app/views/organizations/_subfield_list.html.erb @@ -28,7 +28,7 @@
  • 新增
  • <%= field.field_type == "Post" ? "帖子" : "资源" %>
  • <% else %> - - + + <% end %> <% else %> diff --git a/app/views/news/_course_news_detail.html.erb b/app/views/news/_course_news_detail.html.erb index 61db84134..bd3215fb3 100644 --- a/app/views/news/_course_news_detail.html.erb +++ b/app/views/news/_course_news_detail.html.erb @@ -3,18 +3,6 @@ <%= javascript_include_tag "create_kindeditor" %> <% end %> - <% if newss%> <% newss.each do |news| %> - + <% unless forge_acts.empty? %> <% forge_acts.each do |activity| -%> - + <% user_activities.each do |user_activity| if user_activities %> --> +
    Commit + <%= @commit_details.id %>
    +
  • + <%= 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 21/22] =?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 22/22] =?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;}