diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index e83a13ad9..ca37e445c 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,33 @@ 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 + else + @file.is_publish = 1 + end + @file.save + respond_to do |format| + format.js + end + end + def search_project sort = "" @sort = "" 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/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 707e87fd1..7655f1eb4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -34,7 +34,7 @@ class RepositoriesController < ApplicationController before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] - before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked] + before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff] accept_rss_auth :revisions # hidden repositories filter // 隐藏代码过滤器 before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] @@ -521,6 +521,13 @@ update end end + # 每次提交对应的文件差异 + def commit_diff + @commit_diff = $g.commit_diff(@project.gpid, params[:changeset]) + @commit_details = $g.commit(@project.gpid, params[:changeset]) + render :layout => 'base_projects' + end + def diff if params[:format] == 'diff' @diff = @repository.diff(@path, @rev, @rev_to) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index e6ff904f3..7ccb3177c 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -1055,4 +1055,4 @@ class StudentWorkController < ApplicationController end end end -end \ No newline at end of file +end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 507dada24..2c390025e 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,695 +1,695 @@ -# encoding: utf-8 -# This controller was added by william -class TagsController < ApplicationController - layout "base_tags" - - before_filter :require_admin,:only => :show - - include CoursesHelper - include ProjectsHelper - include IssuesHelper - include UsersHelper - include BidsHelper - include ForumsHelper - include AttachmentsHelper - include ContestsHelper - include ActsAsTaggableOn::TagsHelper - include TagsHelper - include FilesHelper - helper :projects - helper :courses - helper :tags - include OpenSourceProjectsHelper - - before_filter :require_admin,:only => [:delete,:show_all] - before_filter :require_login,:only => [:tag_save] - - # $selected_tags = Array.new - # $related_tags = Array.new - NUMBERS = Setting.tags_show_search_results - - # 预设几个可以添加的tag - #@preTags = %w|预设A 预设B 预设C 预设D 预设E 预设F | - - # 接收参数解释: - # params[:q]这是在其他页面点击tag,跳转到该页面后的结果显示 ;params[:selected_tags],这是在过滤页面增删tag进行过滤传过来的参数 - # 最后是2个过滤何种数据,显示结果的控制参数params[:obj_id],params[:object_falg] - # 0代表删除tag 1代表增加tag - def index - - @obj_id = params[:obj_id] - @obj_flag = params[:object_flag] - - @selected_tags = Array.new - @related_tags = nil - - if params[:q] - @selected_tags << params[:q] - else - @do_what = params[:do_what] - @tag = params[:tag] - @selected_tags = params[:current_selected_tags] - @selected_tags = @selected_tags.nil? ? Array.new : @selected_tags - - case @do_what - when '0' then - @selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop - when '1' then - # 判断是否已存在该tag 主要用来处理分页的情况 - unless @selected_tags.include? @tag - @selected_tags << @tag - end - end - end - - @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num,@contests_tags_num, - @forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size - - # 获取搜索结果 - @obj, - @obj_pages, - @results_count, - @users_results, - @projects_results, - @issues_results, - @bids_results, - @forums_results, - @attachments_results, - @contests_results, - @courses_results, - @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags) - - # 这里是做tag推荐用的, 用来生产推荐的tags - unless @obj.nil? - @tags = @obj.tag_list - @tags -= @selected_tags - # @selected_tags.each do |i| - # @tags.delete(i) - # end - @related_tags = @tags - else - return - end - - end - - # 增加已选的tag - def add_tag - @tag = params[:tag] - @show_flag = params[:show_flag] - - $selected_tags << @tag - $related_tags.delete(@tag) - - # 获取搜索结果 - @obj, - @obj_pages, - @results_count, - @users_results, - @projects_results, - @issues_results, - @bids_results, - @forums_results, - @attachments_results, - @contests_results, - @courses_results, - @open_source_projects_results= refresh_results(@obj_id,@show_flag) - end - - # 删除已选tag - def delete_tag - @tag = params[:tag] - @show_flag = params[:show_flag] - - $related_tags << @tag - $selected_tags.delete(@tag) - - # 获取搜索结果 - @obj, - @obj_pages, - @results_count, - @users_results, - @projects_results, - @issues_results, - @bids_results, - @forums_results, - @attachments_results, - @contests_results, - @courses_results, - @open_source_projects_results= refresh_results(@obj_id,@show_flag) - end - - def show_all - @tags = ActsAsTaggableOn::Tag.find(:all) - end - - # 完全从数据库删除tag - # 这种删除方式是针对 印有该 tag所有对象来做删除的 - # 这样是从整个系统数据库中把该tag删除了 - def delete - if params[:q] - @tag = ActsAsTaggableOn::Tag.find_by_id(params[:q]) - @tag.delete - @taggings = ActsAsTaggableOn::Tagging.find_all_by_tag_id(@tag.id) - @taggings.each do |tagging| - tagging.delete - end - end - end - - # 只删除某个对象的该tag - def remove_tag - @obj = nil - @object_flag = nil - - if request.get? - # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 - @tag_name = params[:tag_name] - @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id - @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 - @taggable_type = numbers_to_object_type(params[:taggable_type]) - - @obj = get_object(@taggable_id,params[:taggable_type]) - @object_flag = params[:taggable_type] - - # if can_remove_tag?(User.current,@taggable_id,@taggable_type) - - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) - - unless @taggings.nil? - @taggings.delete - end - - # 是否还有其他记录 引用了 tag_id - @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id) - # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作 - if @tagging.nil? - @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) - @tag.delete unless @tag.nil? - end - # end - end - end - - # 只删除某个对象的该tag - def remove_tag_new - @obj = nil - @object_flag = nil - - if request.get? - # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 - @tag_name = params[:tag_name] - @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id - @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 - @taggable_type = numbers_to_object_type(params[:taggable_type]) - - @obj = get_object(@taggable_id,params[:taggable_type]) - @object_flag = params[:taggable_type] - - # if can_remove_tag?(User.current,@taggable_id,@taggable_type) - - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) - - unless @taggings.nil? - @taggings.delete - end - - # 是否还有其他记录 引用了 tag_id - @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id) - # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作 - if @tagging.nil? - @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) - @tag.delete unless @tag.nil? - end - - if @obj && @object_flag == '6' && @obj.container.kind_of?(Course) - @course = @obj.container - @tag_list = get_course_tag_list @course - @select_tag_name = params[:select_tag_name] - end - - if @obj && @object_flag == '6' && @obj.container.kind_of?(Project) - @project = @obj.container - @tag_list = get_course_tag_list @project - @select_tag_name = params[:select_tag_name] - end - - if @obj && @object_flag == '6' && @obj.container.kind_of?(OrgSubfield) - @org_subfield = @obj.container - @tag_list = get_org_subfield_tag_list @org_subfield - @select_tag_name = params[:select_tag_name] - end - # end - end - end - - #更新某个tag名称 - def update_tag_name - @tag_name = params[:tagName] - @rename_tag_name = params[:renameName] - @taggable_id = params[:taggableId] - @taggable_type = numbers_to_object_type(params[:taggableType]) - @course_id = params[:courseId] - - @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag - @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? - @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? - if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 - if @course_id - course = Course.find @course_id - if course - course.attachments.each do |attachment| - taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) - if taggings - taggings.delete - attachment.tag_list.add(@rename_tag_name.split(",")) - attachment.save - end - end - end - end - else - if(@rename_tag.nil?) #这次命名的是新的tag - - # 是否还有其他记录 引用了 tag_id - @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") - # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 - if @tagging.count == 1 - @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) - @tag.update_attributes({:name=>@rename_tag_name}) - else #如果tagging表中的记录大于1,那么就要新增tag记录 - - unless @obj.nil? - @obj.tag_list.add(@rename_tag_name.split(",")) - @obj.save - end - #删除原来的对应的taggings的记录 - unless @taggings.nil? - @taggings.delete - end - end - else #这是已有的tag - # 更改taggings记录里的tag_id - unless @taggings.nil? - @taggings.update_attributes({:tag_id=>@rename_tag.id}) - end - end - end - - @obj_flag = params[:taggableType] - if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course) - @course = @obj.container - @tag_list = @tag_list = get_course_tag_list @course - elsif @course_id - @course = Course.find(@course_id) - @tag_list = get_course_tag_list @course - - #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 - @flag = params[:flag] || false - sort = "" - @sort = "" - @order = "" - @is_remote = false - @isproject = false - - sort = "#{Attachment.table_name}.created_on desc" - - @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] - - show_attachments @containers - elsif @obj && @obj_flag == '5' - @forum = @obj - end - respond_to do |format| - format.js - end - end - - def update_project_tag_name - @tag_name = params[:tagName] - @rename_tag_name = params[:renameName] - @taggable_id = params[:taggableId] - @taggable_type = numbers_to_object_type(params[:taggableType]) - @project_id = params[:projectId] - - @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag - @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? - @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? - if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 - if @project_id - project = Project.find @project_id - if project - project.attachments.each do |attachment| - taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) - if taggings - taggings.delete - attachment.tag_list.add(@rename_tag_name.split(",")) - attachment.save - end - end - end - end - else - if(@rename_tag.nil?) #这次命名的是新的tag - - # 是否还有其他记录 引用了 tag_id - @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") - # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 - if @tagging.count == 1 - @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) - @tag.update_attributes({:name=>@rename_tag_name}) - else #如果tagging表中的记录大于1,那么就要新增tag记录 - - unless @obj.nil? - @obj.tag_list.add(@rename_tag_name.split(",")) - @obj.save - end - #删除原来的对应的taggings的记录 - unless @taggings.nil? - @taggings.delete - end - end - else #这是已有的tag - # 更改taggings记录里的tag_id - unless @taggings.nil? - @taggings.update_attributes({:tag_id=>@rename_tag.id}) - end - end - end - - @obj_flag = params[:taggableType] - if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project) - @project = @obj.container - @tag_list = @tag_list = get_course_tag_list @project - elsif @project_id - @project = Project.find(@project_id) - @tag_list = get_project_tag_list @project - - #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 - @flag = params[:flag] || false - sort = "" - @sort = "" - @order = "" - @is_remote = false - @isproject = false - - sort = "#{Attachment.table_name}.created_on desc" - - @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] - - show_attachments @containers - elsif @obj && @obj_flag == '5' - @forum = @obj - end - respond_to do |format| - format.js - end - end - - def update_org_subfield_tag_name - @tag_name = params[:tagName] - @rename_tag_name = params[:renameName] - @taggable_id = params[:taggableId] - @taggable_type = numbers_to_object_type(params[:taggableType]) - @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag - @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id - @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? - @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? - if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 - if params[:org_subfield_id] - org_subfield = OrgSubfield.find params[:org_subfield_id] - if org_subfield - org_subfield.attachments.each do |attachment| - taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) - if taggings - taggings.delete - attachment.tag_list.add(@rename_tag_name.split(",")) - attachment.save - end - end - end - end - else - if(@rename_tag.nil?) #这次命名的是新的tag - - # 是否还有其他记录 引用了 tag_id - @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") - # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 - if @tagging.count == 1 - @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) - @tag.update_attributes({:name=>@rename_tag_name}) - else #如果tagging表中的记录大于1,那么就要新增tag记录 - - unless @obj.nil? - @obj.tag_list.add(@rename_tag_name.split(",")) - @obj.save - end - #删除原来的对应的taggings的记录 - unless @taggings.nil? - @taggings.delete - end - end - else #这是已有的tag - # 更改taggings记录里的tag_id - unless @taggings.nil? - @taggings.update_attributes({:tag_id=>@rename_tag.id}) - end - end - end - - @obj_flag = params[:taggableType] - if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield) - @org_subfield = @obj.container - @tag_list = @tag_list = get_org_subfield_tag_list @org_subfield - elsif params[:org_subfield_id] - @org_subfield = OrgSubfield.find(params[:org_subfield_id]) - @tag_list = get_org_subfield_tag_list @org_subfield - - #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 - @flag = params[:flag] || false - sort = "" - @sort = "" - @order = "" - @is_remote = false - @isproject = false - - sort = "#{Attachment.table_name}.created_on desc" - - @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] - - show_attachments @containers - elsif @obj && @obj_flag == '5' - @forum = @obj - end - respond_to do |format| - format.js - end - end - - def show_attachments obj - @attachments = [] - obj.each do |container| - @attachments += container.attachments - end - @all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments) - @limit = 10 - @feedback_count = @all_attachments.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @obj_attachments = paginateHelper @all_attachments,10 - end - - def tag_save - @select_tag_name = params[:tag_for_save][:tag_name] - @tags = params[:tag_for_save][:name] - @obj_id = params[:tag_for_save][:object_id] - @obj_flag = params[:tag_for_save][:object_flag] - - case @obj_flag - when '1' then - @obj = User.find_by_id(@obj_id) - when '2' then - @obj = Project.find_by_id(@obj_id) - when '3' then - @obj = Issue.find_by_id(@obj_id) - when '4' then - @obj = Bid.find_by_id(@obj_id) - when '5' then - @obj = Forum.find_by_id(@obj_id) - when '6' - @obj = Attachment.find_by_id(@obj_id) - when '7' then - @obj = Contest.find_by_id(@obj_id) - when '8' - @obj = OpenSourceProject.find_by_id(@obj_id) - when '9' - @obj = Course.find_by_id(@obj_id) - when '10' - @obj = Attachment.find_by_id(@obj_id) - else - @obj = nil - end - unless @obj.nil? - @obj.tag_list.add(@tags.split(",")) - else - return - end - if @obj.save - logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}" - else - logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}" - end - if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course) - @course = @obj.container - @tag_list = @tag_list = get_course_tag_list @course - end - if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project) - @project = @obj.container - @tag_list = @tag_list = get_project_tag_list @project - end - if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield) - @org_subfield = @obj.container - @tag_list = @tag_list = get_org_subfield_tag_list @org_subfield - end - respond_to do |format| - format.js - format.html - end - end - - private - # 这里用来刷新搜索结果的区域 - # 函数的返回值 前2字段用来处理获取其他tag和分页 ,另外4个返回值为过滤结果 - def refresh_results(obj_id,obj_flag,selected_tags) - @users_results = nil - @projects_results = nil - @issues_results = nil - @bids_results = nil - @contests_results = nil - @forums_results = nil - @attachments_results = nil - @open_source_projects_results = nil - @obj_pages = nil - @obj = nil - @result = nil - @courses_results = nil - - # 这里为了提高系统的响应速度 把搜索结果放到case中去了 - case obj_flag - when '1' then - @obj = User.find_by_id(obj_id) - @obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags)) - when '2' then - @obj = Project.find_by_id(obj_id) - @obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags)) - when '3' then - @obj = Issue.find_by_id(obj_id) - @obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags)) - when '4' then - @obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags)) - @obj = Bid.find_by_id(obj_id) - when '5' - @obj = Forum.find_by_id(obj_id) - @obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags)) - when '6' - @obj = Attachment.find_by_id(obj_id) - - # modifed by Long Jun - # this is used to find the attachments that came from the same project and tagged with the same tag. - #@result = get_attachments_by_project_tag(selected_tags, @obj) - @result = get_attachments_by_tag(selected_tags) - @obj_pages, @attachments_results, @results_count = for_pagination(@result) - when '7' - @obj = Contest.find_by_id(obj_id) - @obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags)) - when '8' - @obj = OpenSourceProject.find_by_id(obj_id) - @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags)) - when '10' - @obj = Attachment.find_by_id(obj_id) - - # modifed by Long Jun - # this is used to find the attachments that came from the same project and tagged with the same tag. - #@result = get_attachments_by_project_tag(selected_tags, @obj) - @result = get_attachments_by_tag(selected_tags) - @obj_pages, @attachments_results, @results_count = for_pagination(@result) - when '9' then - @obj = Course.find_by_id(obj_id) - @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags)) - else - @obj = nil - end - return [@obj, - @obj_pages, - @results_count, - @users_results, - @projects_results, - @issues_results, - @bids_results, - @forums_results, - @attachments_results, - @contests_results, - @courses_results, - @open_source_projects_results] - end - - def for_pagination(results) - @offset, @limit = api_offset_and_limit({:limit => NUMBERS }) # 设置每页显示的个数 - @results_count = results.count - @obj_pages = Paginator.new @results_count, @limit, params['page'] # 3个参数分别是:总数,每页显示数目,第几页 - @offset ||= @obj_pages.offset - results = results.offset(@offset).limit(@limit).all # 这里默认设置为按时间排序 - return @obj_pages,results, @results_count - end - - # 获取有某类对象的tag总数 - def get_tags_size - @issues_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Issue").count - @projects_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Project").count - @users_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"User").count - @bids_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Bid").count - forum_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Forum").count - attachment_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Attachment").count - @open_source_projects_num = ActsAsTaggableOn::Tagging.where(taggable_type:"OpenSourceProject").count - @contests_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Contest").count - return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num, @open_source_projects_num - end - - # 通过数字 来转换出对象的类型 - # 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求 - # 这个函数 重构是可以移动到application_helper中去 - # 当做一个全局的函数使用,有好几个地方使用到了 - def numbers_to_object_type(num) - case num - when '1' - return 'Principal' - when '2' - return 'Project' - when '3' - return 'Issue' - when '4' - return 'Bid' - when '5' - return 'Forum' - when '6' - return 'Attachment' - when '7' - return 'Contest' - when '8' - return 'OpenSourceProject' - when '9' - return 'Course' - when '10' - return 'Attachment' - else - render_error :message => e.message - return - end - end - - - -end +# encoding: utf-8 +# This controller was added by william +class TagsController < ApplicationController + layout "base_tags" + + before_filter :require_admin,:only => :show + + include CoursesHelper + include ProjectsHelper + include IssuesHelper + include UsersHelper + include BidsHelper + include ForumsHelper + include AttachmentsHelper + include ContestsHelper + include ActsAsTaggableOn::TagsHelper + include TagsHelper + include FilesHelper + helper :projects + helper :courses + helper :tags + include OpenSourceProjectsHelper + + before_filter :require_admin,:only => [:delete,:show_all] + before_filter :require_login,:only => [:tag_save] + + # $selected_tags = Array.new + # $related_tags = Array.new + NUMBERS = Setting.tags_show_search_results + + # 预设几个可以添加的tag + #@preTags = %w|预设A 预设B 预设C 预设D 预设E 预设F | + + # 接收参数解释: + # params[:q]这是在其他页面点击tag,跳转到该页面后的结果显示 ;params[:selected_tags],这是在过滤页面增删tag进行过滤传过来的参数 + # 最后是2个过滤何种数据,显示结果的控制参数params[:obj_id],params[:object_falg] + # 0代表删除tag 1代表增加tag + def index + + @obj_id = params[:obj_id] + @obj_flag = params[:object_flag] + + @selected_tags = Array.new + @related_tags = nil + + if params[:q] + @selected_tags << params[:q] + else + @do_what = params[:do_what] + @tag = params[:tag] + @selected_tags = params[:current_selected_tags] + @selected_tags = @selected_tags.nil? ? Array.new : @selected_tags + + case @do_what + when '0' then + @selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop + when '1' then + # 判断是否已存在该tag 主要用来处理分页的情况 + unless @selected_tags.include? @tag + @selected_tags << @tag + end + end + end + + @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num,@contests_tags_num, + @forum_tags_num, @attachments_tags_num, @open_source_projects_num = get_tags_size + + # 获取搜索结果 + @obj, + @obj_pages, + @results_count, + @users_results, + @projects_results, + @issues_results, + @bids_results, + @forums_results, + @attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags) + + # 这里是做tag推荐用的, 用来生产推荐的tags + unless @obj.nil? + @tags = @obj.tag_list + @tags -= @selected_tags + # @selected_tags.each do |i| + # @tags.delete(i) + # end + @related_tags = @tags + else + return + end + + end + + # 增加已选的tag + def add_tag + @tag = params[:tag] + @show_flag = params[:show_flag] + + $selected_tags << @tag + $related_tags.delete(@tag) + + # 获取搜索结果 + @obj, + @obj_pages, + @results_count, + @users_results, + @projects_results, + @issues_results, + @bids_results, + @forums_results, + @attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@show_flag) + end + + # 删除已选tag + def delete_tag + @tag = params[:tag] + @show_flag = params[:show_flag] + + $related_tags << @tag + $selected_tags.delete(@tag) + + # 获取搜索结果 + @obj, + @obj_pages, + @results_count, + @users_results, + @projects_results, + @issues_results, + @bids_results, + @forums_results, + @attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results= refresh_results(@obj_id,@show_flag) + end + + def show_all + @tags = ActsAsTaggableOn::Tag.find(:all) + end + + # 完全从数据库删除tag + # 这种删除方式是针对 印有该 tag所有对象来做删除的 + # 这样是从整个系统数据库中把该tag删除了 + def delete + if params[:q] + @tag = ActsAsTaggableOn::Tag.find_by_id(params[:q]) + @tag.delete + @taggings = ActsAsTaggableOn::Tagging.find_all_by_tag_id(@tag.id) + @taggings.each do |tagging| + tagging.delete + end + end + end + + # 只删除某个对象的该tag + def remove_tag + @obj = nil + @object_flag = nil + + if request.get? + # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 + @tag_name = params[:tag_name] + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id + @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 + @taggable_type = numbers_to_object_type(params[:taggable_type]) + + @obj = get_object(@taggable_id,params[:taggable_type]) + @object_flag = params[:taggable_type] + + # if can_remove_tag?(User.current,@taggable_id,@taggable_type) + + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) + + unless @taggings.nil? + @taggings.delete + end + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id) + # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作 + if @tagging.nil? + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.delete unless @tag.nil? + end + # end + end + end + + # 只删除某个对象的该tag + def remove_tag_new + @obj = nil + @object_flag = nil + + if request.get? + # 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象 + @tag_name = params[:tag_name] + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id + @taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串 + @taggable_type = numbers_to_object_type(params[:taggable_type]) + + @obj = get_object(@taggable_id,params[:taggable_type]) + @object_flag = params[:taggable_type] + + # if can_remove_tag?(User.current,@taggable_id,@taggable_type) + + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) + + unless @taggings.nil? + @taggings.delete + end + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id) + # 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作 + if @tagging.nil? + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.delete unless @tag.nil? + end + + if @obj && @object_flag == '6' && @obj.container.kind_of?(Course) + @course = @obj.container + @tag_list = get_course_tag_list @course + @select_tag_name = params[:select_tag_name] + end + + if @obj && @object_flag == '6' && @obj.container.kind_of?(Project) + @project = @obj.container + @tag_list = get_course_tag_list @project + @select_tag_name = params[:select_tag_name] + end + + if @obj && @object_flag == '6' && @obj.container.kind_of?(OrgSubfield) + @org_subfield = @obj.container + @tag_list = get_org_subfield_tag_list @org_subfield + @select_tag_name = params[:select_tag_name] + end + # end + end + end + + #更新某个tag名称 + def update_tag_name + @tag_name = params[:tagName] + @rename_tag_name = params[:renameName] + @taggable_id = params[:taggableId] + @taggable_type = numbers_to_object_type(params[:taggableType]) + @course_id = params[:courseId] + + @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? + @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? + if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 + if @course_id + course = Course.find @course_id + if course + course.attachments.each do |attachment| + taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) + if taggings + taggings.delete + attachment.tag_list.add(@rename_tag_name.split(",")) + attachment.save + end + end + end + end + else + if(@rename_tag.nil?) #这次命名的是新的tag + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") + # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 + if @tagging.count == 1 + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.update_attributes({:name=>@rename_tag_name}) + else #如果tagging表中的记录大于1,那么就要新增tag记录 + + unless @obj.nil? + @obj.tag_list.add(@rename_tag_name.split(",")) + @obj.save + end + #删除原来的对应的taggings的记录 + unless @taggings.nil? + @taggings.delete + end + end + else #这是已有的tag + # 更改taggings记录里的tag_id + unless @taggings.nil? + @taggings.update_attributes({:tag_id=>@rename_tag.id}) + end + end + end + + @obj_flag = params[:taggableType] + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course) + @course = @obj.container + @tag_list = @tag_list = get_course_tag_list @course + elsif @course_id + @course = Course.find(@course_id) + @tag_list = get_course_tag_list @course + + #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 + @flag = params[:flag] || false + sort = "" + @sort = "" + @order = "" + @is_remote = false + @isproject = false + + sort = "#{Attachment.table_name}.created_on desc" + + @containers = [ Course.includes(:attachments).reorder(sort).find(@course.id)] + + show_attachments @containers + elsif @obj && @obj_flag == '5' + @forum = @obj + end + respond_to do |format| + format.js + end + end + + def update_project_tag_name + @tag_name = params[:tagName] + @rename_tag_name = params[:renameName] + @taggable_id = params[:taggableId] + @taggable_type = numbers_to_object_type(params[:taggableType]) + @project_id = params[:projectId] + + @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? + @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? + if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 + if @project_id + project = Project.find @project_id + if project + project.attachments.each do |attachment| + taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) + if taggings + taggings.delete + attachment.tag_list.add(@rename_tag_name.split(",")) + attachment.save + end + end + end + end + else + if(@rename_tag.nil?) #这次命名的是新的tag + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") + # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 + if @tagging.count == 1 + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.update_attributes({:name=>@rename_tag_name}) + else #如果tagging表中的记录大于1,那么就要新增tag记录 + + unless @obj.nil? + @obj.tag_list.add(@rename_tag_name.split(",")) + @obj.save + end + #删除原来的对应的taggings的记录 + unless @taggings.nil? + @taggings.delete + end + end + else #这是已有的tag + # 更改taggings记录里的tag_id + unless @taggings.nil? + @taggings.update_attributes({:tag_id=>@rename_tag.id}) + end + end + end + + @obj_flag = params[:taggableType] + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project) + @project = @obj.container + @tag_list = @tag_list = get_course_tag_list @project + elsif @project_id + @project = Project.find(@project_id) + @tag_list = get_project_tag_list @project + + #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 + @flag = params[:flag] || false + sort = "" + @sort = "" + @order = "" + @is_remote = false + @isproject = false + + sort = "#{Attachment.table_name}.created_on desc" + + @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] + + show_attachments @containers + elsif @obj && @obj_flag == '5' + @forum = @obj + end + respond_to do |format| + format.js + end + end + + def update_org_subfield_tag_name + @tag_name = params[:tagName] + @rename_tag_name = params[:renameName] + @taggable_id = params[:taggableId] + @taggable_type = numbers_to_object_type(params[:taggableType]) + @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag + @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank? + @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank? + if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。 + if params[:org_subfield_id] + org_subfield = OrgSubfield.find params[:org_subfield_id] + if org_subfield + org_subfield.attachments.each do |attachment| + taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class) + if taggings + taggings.delete + attachment.tag_list.add(@rename_tag_name.split(",")) + attachment.save + end + end + end + end + else + if(@rename_tag.nil?) #这次命名的是新的tag + + # 是否还有其他记录 引用了 tag_id + @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}") + # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字 + if @tagging.count == 1 + @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id) + @tag.update_attributes({:name=>@rename_tag_name}) + else #如果tagging表中的记录大于1,那么就要新增tag记录 + + unless @obj.nil? + @obj.tag_list.add(@rename_tag_name.split(",")) + @obj.save + end + #删除原来的对应的taggings的记录 + unless @taggings.nil? + @taggings.delete + end + end + else #这是已有的tag + # 更改taggings记录里的tag_id + unless @taggings.nil? + @taggings.update_attributes({:tag_id=>@rename_tag.id}) + end + end + end + + @obj_flag = params[:taggableType] + if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield) + @org_subfield = @obj.container + @tag_list = @tag_list = get_org_subfield_tag_list @org_subfield + elsif params[:org_subfield_id] + @org_subfield = OrgSubfield.find(params[:org_subfield_id]) + @tag_list = get_org_subfield_tag_list @org_subfield + + #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。 + @flag = params[:flag] || false + sort = "" + @sort = "" + @order = "" + @is_remote = false + @isproject = false + + sort = "#{Attachment.table_name}.created_on desc" + + @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] + + show_attachments @containers + elsif @obj && @obj_flag == '5' + @forum = @obj + end + respond_to do |format| + format.js + end + end + + def show_attachments obj + @attachments = [] + obj.each do |container| + @attachments += container.attachments + end + @all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments) + @limit = 10 + @feedback_count = @all_attachments.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @obj_attachments = paginateHelper @all_attachments,10 + end + + def tag_save + @select_tag_name = params[:tag_for_save][:tag_name] + @tags = params[:tag_for_save][:name] + @obj_id = params[:tag_for_save][:object_id] + @obj_flag = params[:tag_for_save][:object_flag] + + case @obj_flag + when '1' then + @obj = User.find_by_id(@obj_id) + when '2' then + @obj = Project.find_by_id(@obj_id) + when '3' then + @obj = Issue.find_by_id(@obj_id) + when '4' then + @obj = Bid.find_by_id(@obj_id) + when '5' then + @obj = Forum.find_by_id(@obj_id) + when '6' + @obj = Attachment.find_by_id(@obj_id) + when '7' then + @obj = Contest.find_by_id(@obj_id) + when '8' + @obj = OpenSourceProject.find_by_id(@obj_id) + when '9' + @obj = Course.find_by_id(@obj_id) + when '10' + @obj = Attachment.find_by_id(@obj_id) + else + @obj = nil + end + unless @obj.nil? + @obj.tag_list.add(@tags.split(",")) + else + return + end + if @obj.save + logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}" + else + logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}" + end + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course) + @course = @obj.container + @tag_list = @tag_list = get_course_tag_list @course + end + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project) + @project = @obj.container + @tag_list = @tag_list = get_project_tag_list @project + end + if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield) + @org_subfield = @obj.container + @tag_list = @tag_list = get_org_subfield_tag_list @org_subfield + end + respond_to do |format| + format.js + format.html + end + end + + private + # 这里用来刷新搜索结果的区域 + # 函数的返回值 前2字段用来处理获取其他tag和分页 ,另外4个返回值为过滤结果 + def refresh_results(obj_id,obj_flag,selected_tags) + @users_results = nil + @projects_results = nil + @issues_results = nil + @bids_results = nil + @contests_results = nil + @forums_results = nil + @attachments_results = nil + @open_source_projects_results = nil + @obj_pages = nil + @obj = nil + @result = nil + @courses_results = nil + + # 这里为了提高系统的响应速度 把搜索结果放到case中去了 + case obj_flag + when '1' then + @obj = User.find_by_id(obj_id) + @obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags)) + when '2' then + @obj = Project.find_by_id(obj_id) + @obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags)) + when '3' then + @obj = Issue.find_by_id(obj_id) + @obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags)) + when '4' then + @obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags)) + @obj = Bid.find_by_id(obj_id) + when '5' + @obj = Forum.find_by_id(obj_id) + @obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags)) + when '6' + @obj = Attachment.find_by_id(obj_id) + + # modifed by Long Jun + # this is used to find the attachments that came from the same project and tagged with the same tag. + #@result = get_attachments_by_project_tag(selected_tags, @obj) + @result = get_attachments_by_tag(selected_tags) + @obj_pages, @attachments_results, @results_count = for_pagination(@result) + when '7' + @obj = Contest.find_by_id(obj_id) + @obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags)) + when '8' + @obj = OpenSourceProject.find_by_id(obj_id) + @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags)) + when '10' + @obj = Attachment.find_by_id(obj_id) + + # modifed by Long Jun + # this is used to find the attachments that came from the same project and tagged with the same tag. + #@result = get_attachments_by_project_tag(selected_tags, @obj) + @result = get_attachments_by_tag(selected_tags) + @obj_pages, @attachments_results, @results_count = for_pagination(@result) + when '9' then + @obj = Course.find_by_id(obj_id) + @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags)) + else + @obj = nil + end + return [@obj, + @obj_pages, + @results_count, + @users_results, + @projects_results, + @issues_results, + @bids_results, + @forums_results, + @attachments_results, + @contests_results, + @courses_results, + @open_source_projects_results] + end + + def for_pagination(results) + @offset, @limit = api_offset_and_limit({:limit => NUMBERS }) # 设置每页显示的个数 + @results_count = results.count + @obj_pages = Paginator.new @results_count, @limit, params['page'] # 3个参数分别是:总数,每页显示数目,第几页 + @offset ||= @obj_pages.offset + results = results.offset(@offset).limit(@limit).all # 这里默认设置为按时间排序 + return @obj_pages,results, @results_count + end + + # 获取有某类对象的tag总数 + def get_tags_size + @issues_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Issue").count + @projects_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Project").count + @users_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"User").count + @bids_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Bid").count + forum_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Forum").count + attachment_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Attachment").count + @open_source_projects_num = ActsAsTaggableOn::Tagging.where(taggable_type:"OpenSourceProject").count + @contests_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Contest").count + return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num, @open_source_projects_num + end + + # 通过数字 来转换出对象的类型 + # 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求 + # 这个函数 重构是可以移动到application_helper中去 + # 当做一个全局的函数使用,有好几个地方使用到了 + def numbers_to_object_type(num) + case num + when '1' + return 'Principal' + when '2' + return 'Project' + when '3' + return 'Issue' + when '4' + return 'Bid' + when '5' + return 'Forum' + when '6' + return 'Attachment' + when '7' + return 'Contest' + when '8' + return 'OpenSourceProject' + when '9' + return 'Course' + when '10' + return 'Attachment' + else + render_error :message => e.message + return + end + end + + + +end diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index d66c6a30d..386e5733d 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -134,8 +134,11 @@ class ZipdownController < ApplicationController homework_common.student_works.each do |work| unless work.attachments.empty? out_file = zip_student_work_by_user(work) - bid_homework_path << out_file.file_path - digests << out_file.file_digest + + bid_homework_path << out_file.file_path + digests << out_file.file_digest + + end end homework_id = homework_common.id @@ -172,7 +175,11 @@ class ZipdownController < ApplicationController } end - def zip_student_work_by_user work + def make_zip_name(work) + "#{work.user.show_name}_#{((work.user.user_extensions.nil? || work.user.user_extensions.student_id.nil?) ? "" : work.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}" + end + + def zip_student_work_by_user(work) homeworks_attach_path = [] not_exist_file = [] # 需要将所有homework.attachments遍历加入zip @@ -186,10 +193,23 @@ class ZipdownController < ApplicationController digests << 'not_exist_file' end end - out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){ - zipping("#{work.user.show_name}_#{((work.user.user_extensions.nil? || work.user.user_extensions.student_id.nil?) ? "" : work.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", - homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file) - } + + #单个文件的话,不需要压缩,只改名 + out_file = nil + if homeworks_attach_path.size == 1 + out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){ + des_path = "#{OUTPUT_FOLDER}/#{make_zip_name(work)}_#{File.basename(homeworks_attach_path.first)}" + FileUtils.cp homeworks_attach_path.first, des_path + des_path + } + else + out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){ + zipping("#{make_zip_name(work)}.zip", + homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file) + } + end + out_file + end diff --git a/app/helpers/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/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index ff4aa61fb..36187b460 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -41,6 +41,16 @@ module RepositoriesHelper identifiers.include?(iden) ? false :true end + # 获取diff内容行号 + def diff_line_num content + content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i + end + + # 处理内容 + def diff_content content + content.gsub!(/.*@@ -\d+,\d+ \+\d+,\d+ @@\n/m,'') + end + def format_revision(revision) if revision.respond_to? :format_identifier revision.format_identifier diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 4edfed578..efb67a2ac 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -85,6 +85,11 @@ module UsersHelper 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 diff --git a/app/models/attachment.rb b/app/models/attachment.rb index ea9ad2cc0..588ee144d 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -643,8 +643,8 @@ class Attachment < ActiveRecord::Base def decrease_attchments_count if self.container_type == "Project" && !self.project.project_score.nil? - aatach_count = self.container.project_score.attach_num - 1 - self.container.project_score.update_attribute(:attach_num, aatach_count) + attach_count = self.container.project_score.attach_num - 1 + self.container.project_score.update_attribute(:attach_num, attach_count < 0 ? 0 : attach_count) end end end diff --git a/app/models/issue.rb b/app/models/issue.rb index e1de4cd9e..c82f6f0be 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -184,7 +184,7 @@ class Issue < ActiveRecord::Base def decrease_issues_count unless self.project.project_score.nil? issue_count = self.project.project_score.issue_num - 1 - self.project.project_score.update_attribute(:issue_num, issue_count) + self.project.project_score.update_attribute(:issue_num, issue_count < 0 ? 0 : issue_count) end end diff --git a/app/models/journal.rb b/app/models/journal.rb index b184c82e6..c37b8d2c5 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -219,8 +219,9 @@ class Journal < ActiveRecord::Base # 减少留言数量统计 def decrease_issues_journal_count unless self.issue.project.nil? - project = self.issue.project - project.project_score.update_attribute(:issue_journal_num, project.project_score.issue_journal_num - 1) + journal_count = self.issue.project.project_score.issue_journal_num - 1 + # project = self.issue.project + self.issue.project.project_score.update_attribute(:issue_journal_num, journal_count < 0 ? 0 : journal_count) end end diff --git a/app/models/message.rb b/app/models/message.rb index 675d37790..6381f444f 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -146,10 +146,10 @@ class Message < ActiveRecord::Base # 讨论区 if self.parent_id.nil? count = self.project.project_score.board_num - 1 - self.project.project_score.update_attribute(:board_num, count) + self.project.project_score.update_attribute(:board_num, count < 0 ? 0 : count) else # 回复 count = self.project.project_score.board_message_num - 1 - self.project.project_score.update_attribute(:board_message_num, count) + self.project.project_score.update_attribute(:board_message_num, count < 0 ? 0 : count) end end end diff --git a/app/models/news.rb b/app/models/news.rb index fee5d2801..d0fccae17 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -126,7 +126,7 @@ class News < ActiveRecord::Base def decrease_news_count if self.project && !self.project.project_score.nil? count = self.project.project_score.news_num - 1 - self.project.project_score.update_attribute(:news_num, count) + self.project.project_score.update_attribute(:news_num, count < 0 ? 0 : count) end end diff --git a/app/views/blog_comments/_simple_ke_reply_form.html.erb b/app/views/blog_comments/_simple_ke_reply_form.html.erb index 292587cad..e222d8e56 100644 --- a/app/views/blog_comments/_simple_ke_reply_form.html.erb +++ b/app/views/blog_comments/_simple_ke_reply_form.html.erb @@ -1,16 +1,3 @@ - -
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
diff --git a/app/views/common/_file.html.erb b/app/views/common/_file.html.erb index 97443beea..486c760f1 100644 --- a/app/views/common/_file.html.erb +++ b/app/views/common/_file.html.erb @@ -8,7 +8,7 @@ <%= line_num %> -
<%= line.html_safe %>
+
<%= line.html_safe %>
<% line_num += 1 %> diff --git a/app/views/courses/_user_homework_search_list.html.erb b/app/views/courses/_user_homework_search_list.html.erb index 585d8761a..750e7537c 100644 --- a/app/views/courses/_user_homework_search_list.html.erb +++ b/app/views/courses/_user_homework_search_list.html.erb @@ -2,18 +2,6 @@ <%= import_ke(enable_at: true, prettify: false, init_activity: true) %> <% end %> -
<% homework_commons.each do |homework_common|%> +发布设置 + +<%= 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..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)%>

@@ -28,7 +29,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/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index ad5d971ed..b63897951 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -1,18 +1,7 @@ <%= content_for(:header_tags) do %> <%= import_ke(enable_at: true,init_activity: true) %> <% end %> - + +<% domain = Secdomain.where("sub_type=2 and pid=?", @organization.id).first %>
配置
@@ -53,12 +54,12 @@
组织描述:
-
+
组织URL:
http:// - + .trustie.net申请 - <% if @organization.domain.present? and OrgMessage.where("organization_id=? and message_type='ApplySubdomain'", @organization.id).order("updated_at desc").first.content == @organization.domain %> + <% if domain.present? and OrgMessage.where("organization_id=? and message_type='ApplySubdomain'", @organization.id).order("updated_at desc").first.content == domain.subname %> (已批准) <% elsif OrgMessage.where("organization_id=? and message_type='ApplySubdomain'", @organization.id).count > 0 %> (您申请了子域名<%= OrgMessage.where("organization_id=? and message_type='ApplySubdomain'", @organization.id).order("updated_at desc").first.content %>,还未批准) @@ -127,8 +128,8 @@

域名目录(用户自定义url,可选)

- <% if @organization.domain %> - <%= @organization.domain %>.trustie.net/ + <% if domain %> + <%= domain.subname %>.trustie.net/ <% else %> 您还没有子域名,请先在左侧信息栏申请子域名 <% end %> diff --git a/app/views/projects/_project_activities.html.erb b/app/views/projects/_project_activities.html.erb index 062d64096..c036633a5 100644 --- a/app/views/projects/_project_activities.html.erb +++ b/app/views/projects/_project_activities.html.erb @@ -35,18 +35,7 @@ }) }) - + <% unless forge_acts.empty? %> <% forge_acts.each do |activity| -%> --> +
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/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/_user_activities.html.erb b/app/views/users/_user_activities.html.erb index 59d605a09..0e55c246c 100644 --- a/app/views/users/_user_activities.html.erb +++ b/app/views/users/_user_activities.html.erb @@ -38,18 +38,7 @@ }) }) - + <% user_activities.each do |user_activity| if user_activities %>