From af157a9c63350ffd25865266f681bb9af778dfc4 Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Tue, 15 Dec 2015 17:30:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E8=B5=84=E6=BA=90=E6=A0=8F?= =?UTF-8?q?=E7=9B=AE=E5=A2=9E=E5=8A=A0=E6=A0=87=E7=AD=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 56 ++++++++++++++++--- app/controllers/tags_controller.rb | 6 ++ app/helpers/application_helper.rb | 9 +++ app/views/files/_org_subfield_list.html.erb | 6 +- app/views/files/_subfield_files.html.erb | 16 +++--- app/views/files/_subfield_tags.html.erb | 43 ++++++++++++++ .../files/_upload_subfield_file.html.erb | 24 ++++---- .../search_org_subfield_tag_attachment.js.erb | 2 + app/views/tags/remove_tag_new.js.erb | 6 +- config/routes.rb | 2 +- 10 files changed, 137 insertions(+), 33 deletions(-) create mode 100644 app/views/files/_subfield_tags.html.erb create mode 100644 app/views/files/search_org_subfield_tag_attachment.js.erb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 8597ad3b7..51dabebb4 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -395,6 +395,7 @@ class FilesController < ApplicationController @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] @organization = Organization.find(@containers.first.organization_id) show_attachments @containers + @tag_list = attachment_tag_list @all_attachments render :layout => 'base_org' # @subfield = params[:org_subfield_id] end @@ -523,14 +524,29 @@ class FilesController < ApplicationController end elsif @org_subfield @addTag=false - # if params[:in_org_subfield_toolbar] - # @in_org_subfield_toolbar = params[:in_org_subfield_toolbar] - # end attachments = Attachment.attach_filesex(@org_subfield, params[:attachments], params[:org_subfield_attachment_type]) - # if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') - # Mailer.run.attachments_added(attachments[:files]) - # end + if params[:org_subfield_attachment_type] && params[:org_subfield_attachment_type].is_a?(Array) + params[:org_subfield_attachment_type].each do |type| + tag_name = get_tag_name_by_type_number 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[:org_subfield_attachment_type] && params[:org_subfield_attachment_type] != "5" + tag_name = get_tag_name_by_type_number params[:org_subfield_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' @@ -542,7 +558,7 @@ class FilesController < ApplicationController @containers = [OrgSubfield.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@org_subfield.id)] show_attachments @containers - + @tag_list = attachment_tag_list @all_attachments @attachtype = 0 @contenttype = 0 @@ -733,6 +749,32 @@ class FilesController < ApplicationController end end + #搜索资源栏目的指定TAG的资源列表 + def search_org_subfield_tag_attachment + @q,@tag_name,@order = params[:q],params[:tag_name] + @is_remote = true + if params[:sort] + order_by = params[:sort].split(":") + @sort = order_by[0] + if order_by.count > 1 + @order = order_by[1] + end + sort = "#{@sort} #{@order}" + end + + q = "%#{@q.strip}%" + @result = find_org_subfield_attache q,@org_subfield,sort + @result = visable_attachemnts @result + @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank? + @searched_attach = paginateHelper @result,10 + @tag_list = get_org_subfield_tag_list @org_subfield + + respond_to do |format| + format.js + # format.html + end + end + def subfield_upload_file @org_subfield = OrgSubfield.find(params[:org_subfield_id]) end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index cb61177f5..82adc1fff 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -227,6 +227,12 @@ class TagsController < ApplicationController @tag_list = get_course_tag_list @course @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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8f4679c67..9a622316a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2376,6 +2376,15 @@ module ApplicationHelper 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))|| + attachment.author_id == User.current.id + } + tag_list = attachment_tag_list all_attachments + tag_list + end + #获取匿评相关连接代码 def homework_anonymous_comment (homework, is_in_course, user_activity_id = -1, course_activity = -1) if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") diff --git a/app/views/files/_org_subfield_list.html.erb b/app/views/files/_org_subfield_list.html.erb index e11e020c2..750aed9ae 100644 --- a/app/views/files/_org_subfield_list.html.erb +++ b/app/views/files/_org_subfield_list.html.erb @@ -14,9 +14,9 @@

- - - +
+ <%= render :partial => "files/subfield_tags", :locals => {:tag_list => @tag_list,:org_subfield => @org_subfield,:tag_name => @tag_name}%> +
diff --git a/app/views/files/_subfield_files.html.erb b/app/views/files/_subfield_files.html.erb index 2a552dc43..09f74d3cd 100644 --- a/app/views/files/_subfield_files.html.erb +++ b/app/views/files/_subfield_files.html.erb @@ -15,9 +15,9 @@ { switch(obj) { - case 1: - $('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 1}) %>'); - break; +// case 1: +// $('#ajax-modal').html('<%#= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 1}) %>'); +// break; case 2: $('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 2}) %>'); break; @@ -27,9 +27,9 @@ case 4: $('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 4}) %>'); break; - case 6: - $('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 6}) %>'); - break; +// case 6: +// $('#ajax-modal').html('<%#= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 6}) %>'); +// break; default: $('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_subfield_file',:locals => {:org_subfield => @org_subfield,:org_subfield_attachment_type => 5}) %>'); } @@ -77,11 +77,11 @@

上传: - 课件 |  + 软件 |  媒体 |  代码 |  - 论文 |  + 其他

<%# end %> diff --git a/app/views/files/_subfield_tags.html.erb b/app/views/files/_subfield_tags.html.erb new file mode 100644 index 000000000..1a2c896fc --- /dev/null +++ b/app/views/files/_subfield_tags.html.erb @@ -0,0 +1,43 @@ +<% if org_subfield && tag_list && tag_list.empty? == false%> + + 全部 +<% end %> +<% unless tag_list.nil?%> + <% tag_list.each do |k,v|%> + <% if tag_name && tag_name == k%> + + <%= k%>(<%= v%>) + <% else%> + + <%= k%>(<%= v%>) + <% end%> + <% end%> +<% end%> + + \ No newline at end of file diff --git a/app/views/files/_upload_subfield_file.html.erb b/app/views/files/_upload_subfield_file.html.erb index 567309f9c..7137e14e7 100644 --- a/app/views/files/_upload_subfield_file.html.erb +++ b/app/views/files/_upload_subfield_file.html.erb @@ -7,19 +7,17 @@ <%= form_tag(org_subfield_files_path(org_subfield, :in_org => params[:in_org]), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %> - - - - - - - - - - - - - + <% if params[:in_org] %> +
+ 软件 |  + 媒体 |  + 代码 |  + 其他 +
+ <% else %> + + <% end %> + <%= render :partial => 'files/attachement_list'%>
<%= l(:button_cancel)%> diff --git a/app/views/files/search_org_subfield_tag_attachment.js.erb b/app/views/files/search_org_subfield_tag_attachment.js.erb new file mode 100644 index 000000000..deed2d5d3 --- /dev/null +++ b/app/views/files/search_org_subfield_tag_attachment.js.erb @@ -0,0 +1,2 @@ +$("#org_subfield_list").html("<%= escape_javascript(render :partial => 'org_subfield_list', + :locals => {org_subfield: @org_subfield,all_attachments: @result,sort:@sort,order:@order,org_subfield_attachments:@searched_attach})%>"); \ No newline at end of file diff --git a/app/views/tags/remove_tag_new.js.erb b/app/views/tags/remove_tag_new.js.erb index 9a43dd9b4..879155aa7 100644 --- a/app/views/tags/remove_tag_new.js.erb +++ b/app/views/tags/remove_tag_new.js.erb @@ -3,8 +3,12 @@ $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_list', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @object_flag,:select_tag_name => @select_tag_name}) %>'); +<% if @org_subfield %> + $("#files_tag").html("<%= escape_javascript(render :partial => "files/subfield_tags", :locals => {:tag_list => @tag_list,:org_subfield => @org_subfield,:tag_name => @tag_name})%>"); +<% else %> + $("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course,:tag_name => @select_tag_name}) %>"); +<% end %> -$("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course,:tag_name => @select_tag_name}) %>"); <% end %> <% if @object_flag == "10"%> $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); diff --git a/config/routes.rb b/config/routes.rb index 05507d024..28a3fec70 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,7 +77,7 @@ RedmineApp::Application.routes.draw do match "getattachtype", :via => [:get, :post] match "search_files_in_subfield",:via => [:post,:get] match "searchone4reload",:via => [:post,:get] - match "search_tag_attachment", :via => [:post,:get] + match "search_org_subfield_tag_attachment", :via => [:post,:get] match "subfield_upload_file", :via => :post end member do