diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 5cbf1ab2f..59b0f6f03 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -99,6 +99,7 @@ class FilesController < ApplicationController @sort = "" @order = "" @is_remote = true + @q = params[:name].strip if params[:sort] order_by = params[:sort].split(":") @sort = order_by[0] @@ -107,24 +108,25 @@ class FilesController < ApplicationController end sort = "#{@sort} #{@order}" end + # show_attachments [@course] begin q = "%#{params[:name].strip}%" #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? if params[:insite] if q == "%%" - @result = [] - @searched_attach = paginateHelper @result,10 + @project_attachment_result = [] + @searched_attach = paginateHelper @project_attachment_result, 10 else - @result = find_public_attache q,sort - @result = visable_attachemnts_insite @result,@project - @searched_attach = paginateHelper @result,10 + @project_attachment_result = find_public_attache q,sort + @project_attachment_result = visable_attachemnts_insite @project_attachment_result, @project + @searched_attach = paginateHelper @project_attachment_result, 10 end else - @result = find_project_attache q,@project,sort - @result = visable_attachemnts @result - @searched_attach = paginateHelper @result,10 + @project_attachment_result = find_project_attache q, @project,sort + @project_attachment_result = visable_attachemnts @project_attachment_result + @searched_attach = paginateHelper @project_attachment_result,10 + @tag_list = get_project_tag_list @project end - #rescue Exception => e # #render 'stores' # redirect_to search_course_files_url @@ -200,23 +202,10 @@ class FilesController < ApplicationController if sort == "" sort = "created_on DESC" end - ids = "" - len = 0 - count = project.versions.count - project.versions.each do |version| - len = len + 1 - if len != count - ids += version.id.to_s + ',' - else - ids += version.id.to_s - end - end - if ids.blank? - resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ", like: "%#{keywords}%"). - reorder(sort) + if keywords != "%%" + resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort) else - resultSet = Attachment.where("((attachments.container_type = 'Project' And attachments.container_id = '#{project.id}') OR (container_type = 'Version' AND container_id IN (#{ids}))) AND filename LIKE :like ", like: "%#{keywords}%"). - reorder(sort) + resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' "). reorder(sort) end end @@ -239,11 +228,9 @@ class FilesController < ApplicationController @is_remote = false if params[:project_id] @container_type = 0 - if params[:sort] params[:sort].split(",").each do |sort_type| order_by = sort_type.split(":") - case order_by[0] when "filename" attribute = "filename" @@ -281,25 +268,19 @@ class FilesController < ApplicationController else sort = "#{Attachment.table_name}.created_on desc" end + # @containers = [ Project.includes(:attachments).find(@project.id)] + # @containers += @project.versions.includes(:attachments).all - @containers = [ Project.includes(:attachments).find(@project.id)] - @containers += @project.versions.includes(:attachments).all - - ids = [] - @containers.each do |c| - ids += c.attachments.pluck(:id) - end - @containers = [Struct.new(:attachments).new(Attachment.where('id in (?)',ids).reorder(sort))] + @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)] show_attachments @containers - respond_to do |format| - format.html - format.js - end + @tag_list = attachment_tag_list @all_attachments + + render :layout => 'base_projects' elsif params[:course_id] @container_type = 1 - + @page = params[:page] ? params[:page].to_i + 1 : 2 if params[:sort] params[:sort].split(",").each do |sort_type| order_by = sort_type.split(":") @@ -440,16 +421,35 @@ class FilesController < ApplicationController if @project @addTag=false if params[:in_project_toolbar] - @in_project_toolbar = params[:in_project_toolbar] + @in_project_toolbar = params[:in_project_toolbar] end - container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) - attachments = Attachment.attach_filesex(container, params[:attachments], params[:attachment_type]) - render_attachment_warning_if_needed(container) - + # 发送邮件 + attachments = Attachment.attach_filesex(@project, params[:attachments], params[:attachment_type]) if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.run.attachments_added(attachments[:files]) end - + # end + if params[:project_attachment_type] && params[:project_attachment_type].is_a?(Array) + params[:project_attachment_type].each do |type| + tag_name = get_project_tag_name_by_type_nmuber type + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end + end + else + if params[:project_attachment_type] && params[:project_attachment_type] != "6" + tag_name = get_project_tag_name_by_type_nmuber params[:project_attachment_type] + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end + end + end # TODO: 临时用 nyan sort_init 'created_on', 'desc' sort_update 'created_on' => "#{Attachment.table_name}.created_on", @@ -457,14 +457,11 @@ class FilesController < ApplicationController 'size' => "#{Attachment.table_name}.filesize", 'downloads' => "#{Attachment.table_name}.downloads" - @containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun - @containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort - + @containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] show_attachments @containers - + @tag_list = attachment_tag_list @all_attachments @attachtype = 0 @contenttype = 0 - respond_to do |format| format.js format.html { @@ -592,6 +589,25 @@ class FilesController < ApplicationController end end + def get_project_tag_name_by_type_nmuber type + case type + when "1" + tag_name = "软件版本" + when "2" + tag_name = "文档" + when "3" + tag_name = "代码" + when "4" + tag_name = "媒体" + when "5" + tag_name = "论文" + when "6" + tag_name = "其它" + else + tag_name = "" + end + end + def get_tag_name_by_type_number type case type when "1" @@ -743,21 +759,33 @@ class FilesController < ApplicationController end q = "%#{@q.strip}%" - @result = find_course_attache q,@course,sort + if @project + @result = find_project_attache q, @project,sort + else + @result = find_course_attache q,@course,sort + end @result = visable_attachemnts @result if params[:other] - @result = @result.select{|attachment| - !attachment.tag_list.include?('课件') && - !attachment.tag_list.include?('软件') && - !attachment.tag_list.include?('媒体') && - !attachment.tag_list.include?('代码') && - !attachment.tag_list.include?('论文') } + if @project + @result = @result.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') } + else + @result = @result.select{|attachment| + !attachment.tag_list.include?('课件') && + !attachment.tag_list.include?('软件') && + !attachment.tag_list.include?('媒体') && + !attachment.tag_list.include?('代码') && + !attachment.tag_list.include?('论文') } + end else @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank? end @searched_attach = paginateHelper @result,10 - @tag_list = get_course_tag_list @course - + if @project + @tag_list = get_project_tag_list @project + @result_search_project = @result + else + @tag_list = get_course_tag_list @course + end respond_to do |format| format.js # format.html diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index c3f926867..91a0bc902 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -137,6 +137,7 @@ class IssuesController < ApplicationController end end # end + @jour_reply = Journal.new @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all @journals.each_with_index {|j,i| j.indice = i+1} @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) @@ -153,6 +154,7 @@ class IssuesController < ApplicationController @project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq + @journal = Journal.new(:journalized => @issue) respond_to do |format| format.html { @@ -401,6 +403,7 @@ class IssuesController < ApplicationController jour.user_id = User.current.id jour.notes = params[:notes] jour.journalized = @issue + jour.save_attachments(params[:attachments]) jour.save user_activity = UserActivity.where("act_type='Issue' and act_id =#{@issue.id}").first user_activity.updated_at = jour.created_on diff --git a/app/controllers/system_messages_controller.rb b/app/controllers/system_messages_controller.rb index 684378e8a..df17ca3e2 100644 --- a/app/controllers/system_messages_controller.rb +++ b/app/controllers/system_messages_controller.rb @@ -1,4 +1,5 @@ class SystemMessagesController < ApplicationController + # before_filter :message_author, :only => [:show] # # def message_author @@ -41,6 +42,7 @@ class SystemMessagesController < ApplicationController @system_messages.description = params[:system_message][:description] @system_messages.subject = params[:system_message][:subject] @system_messages.user_id = User.current.id + # @system_messages.save_attachments(params[:attachments]) respond_to do |format| if @system_messages.save format.html {redirect_to user_system_messages_path(User.current)} diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index d40bc7c7c..507dada24 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -228,6 +228,12 @@ class TagsController < ApplicationController @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 @@ -320,6 +326,88 @@ class TagsController < ApplicationController 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] @@ -458,6 +546,10 @@ class TagsController < ApplicationController @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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d28837858..fdd2fe419 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -55,6 +55,7 @@ class UsersController < ApplicationController before_filter :recorded_visitor, :only => [:show,:user_fanslist,:user_watchlist,:user_visitorlist] helper :sort + helper :attachments include SortHelper helper :custom_fields include CustomFieldsHelper @@ -63,6 +64,7 @@ class UsersController < ApplicationController include GitlabHelper include UserScoreHelper + include PollHelper helper :user_score helper :journals diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 55a017019..ea3690b78 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -48,6 +48,7 @@ module ApplicationHelper end end end + # 获取组织成员中文名字 def get_org_member_role_name member case member.roles[0].name @@ -2432,6 +2433,16 @@ module ApplicationHelper tag_list end + # 获取项目资源的Tag云 + def get_project_tag_list project + all_attachments = project.attachments.select{|attachment| attachment.is_public? || + (attachment.container_type == "Project" && User.current.member_of?(project))|| + attachment.author_id == User.current.id + } + tag_list = attachment_tag_list all_attachments + tag_list + end + def get_org_subfield_tag_list org_subfield all_attachments = org_subfield.attachments.select{|attachment| attachment.is_public? || (attachment.container_type == "OrgSubfield" && User.current.member_of_org?(org_subfield.organization))|| diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index be24629af..3dc2c66af 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -96,6 +96,7 @@ module AttachmentsHelper end false end + #判断项目project中是否包含课件attachment,project中引用了attachment也算作包含 def project_contains_attachment? project,attachment project.attachments.each do |att| diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 2e8b98a2d..8847f4163 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -73,6 +73,16 @@ def course_contains_attachment? course,attachment false end +#判断项目project中是否包含课件attachment,project中引用了attachment也算作包含 +def project_contains_attachment? project,attachment + project.attachments.each do |att| + if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from + return true + end + end + false +end + #判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期 def has_course? user,file result = false diff --git a/app/models/attachment.rb b/app/models/attachment.rb index c8fe0811e..d90b0368e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -618,7 +618,7 @@ class Attachment < ActiveRecord::Base end end def update_attachment_ealasticsearch_index - if self.is_public == 1 && ( (self.container_type == 'Project' && Project.find(self.container_id).is_public == 1) || + if self.is_public == 1 && ( ((self.container_type == 'Project' or self.container_type == 'Version') && Project.find(self.container_id).is_public == 1) || ( self.container_type == 'Course' && Course.find(self.container_id).is_public == 1) || self.container_type == 'Principal') begin diff --git a/app/models/journal.rb b/app/models/journal.rb index a66c4327a..e1464a703 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -31,9 +31,8 @@ class Journal < ActiveRecord::Base #has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy 评论不应该算入 # 被ForgeMessage虚拟关联 has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy - has_many :at_messages, as: :at_message, dependent: :destroy - + acts_as_attachable attr_accessor :indice acts_as_event :title =>Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.project_index}#{status}: #{o.issue.subject}" }, @@ -46,8 +45,8 @@ class Journal < ActiveRecord::Base acts_as_activity_provider :type => 'issues', :author_key => :user_id, :find_options => {:include => [{:issue => :project}, :details, :user], - :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + - " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} + :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + + "(#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} before_create :split_private_notes diff --git a/app/models/system_message.rb b/app/models/system_message.rb index a05610da7..65623c104 100644 --- a/app/models/system_message.rb +++ b/app/models/system_message.rb @@ -7,6 +7,7 @@ class SystemMessage < ActiveRecord::Base validates_length_of :description, maximum: 10000 has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy + acts_as_attachable # 系统消息放置总消息列表 after_create :add_system_message diff --git a/app/views/admin/messages.html.erb b/app/views/admin/messages.html.erb index e4d053d49..040dd0fe8 100644 --- a/app/views/admin/messages.html.erb +++ b/app/views/admin/messages.html.erb @@ -19,6 +19,7 @@