diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 5acc14055..6d6b6f42e 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -125,8 +125,7 @@ class FilesController < ApplicationController @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_course_tag_list @project + @tag_list = get_project_tag_list @project end #rescue Exception => e # #render 'stores' @@ -229,7 +228,6 @@ 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(":") @@ -272,21 +270,13 @@ class FilesController < ApplicationController sort = "#{Attachment.table_name}.created_on desc" end - @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 @@ -429,16 +419,37 @@ class FilesController < ApplicationController #modify by nwb if @project @addTag=false - if params[:in_project_toolbar] - @in_project_toolbar = params[:in_project_toolbar] + if params[:in_course_toolbar] + @in_course_toolbar = params[:in_course_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' @@ -447,10 +458,10 @@ 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 @@ -582,6 +593,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" diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a3f8ac9f6..ea3690b78 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2433,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/views/files/_upload_project_files.erb b/app/views/files/_upload_project_files.erb new file mode 100644 index 000000000..4a85a5c65 --- /dev/null +++ b/app/views/files/_upload_project_files.erb @@ -0,0 +1,43 @@ + +
+
+

<%= l(:label_upload_files)%>

+
+ <%= error_messages_for 'attachment' %> + + + <%= form_tag(project_files_path(project), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %> + + +
+ 软件版本 |  + 文档 |  + 代码 |  + 媒体 |  + 论文 |  + 其他 +
+
+
+ <%= render :partial => 'files/new_style_attachment_list',:locals => {:container => project} %> +
+
+ + <%= l(:button_cancel)%> + + <%= submit_tag '确定',:onclick=>'submit_resource();',:onfocus=>'this.blur()',:id=>'submit_resource',:class=>'sendSourceText fr' %> + <% end %> +
+ +
+ <% content_for :header_tags do %> + <%= javascript_include_tag 'attachments' %> + <% end %> +
+ + \ No newline at end of file diff --git a/app/views/files/create.js.erb b/app/views/files/create.js.erb index c3399d9da..18c2b83d8 100644 --- a/app/views/files/create.js.erb +++ b/app/views/files/create.js.erb @@ -27,9 +27,9 @@ $('#upload_file_div').slideToggle('slow'); window.location.href = '<%= project_files_path(@project)%>' <%else%> - $("#resource_list").html('<%= j(render partial: "project_file_new" ,locals: {project: @project}) %>'); - $("#project_files_count_info").html("<%= @all_attachments.count%>"); - $("#project_files_count_nav").html("(<%= @all_attachments.count%>)") + $("#resource_list").html('<%= j(render partial:"project_file", locals: {project: @project}) %>'); + $("#project_files_count_info").html("<%= @all_attachments.count %>"); + $("#project_files_count_nav").html("(<%= @all_attachments.count %>)") // 添加文件上传成功提示 <% unless params[:attachments].nil? %> var div = $('
文件上传成功!
'); @@ -37,7 +37,7 @@ $('#upload_file_div').slideToggle('slow'); setTimeout( function(){div.remove();},3000) <% end %> <% end %> - <%elsif @course%> + <%elsif @course%> hideModal(); <%if @in_course_toolbar %> window.location.href='<%= course_files_path(@course)%>' diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index d6506e010..a3bc00c38 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -238,7 +238,7 @@ function project_files_upload() { - $('#ajax-modal').html('<%= escape_javascript(render :partial => 'projects/upload_project_files_on_navbar',:locals => {:container => @project}) %>'); + $('#ajax-modal').html('<%= escape_javascript(render :partial => 'files/upload_project_files',:locals => {:project => @project, :project_attachment_type => 1}) %>'); showModal('ajax-modal', '513px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before("");