From b7e9442800ea2f4f931fca5e7b8556507189fbb5 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 16 Apr 2015 14:01:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E3=80=81=E5=88=A0=E9=99=A4TA?= =?UTF-8?q?G=E4=BA=91=E6=97=B6TAG=E4=BA=91=E5=88=97=E8=A1=A8=E5=88=B7?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/tags_controller.rb | 17 +++++++++++++++++ app/helpers/application_helper.rb | 9 +++++++++ app/helpers/files_helper.rb | 8 -------- app/views/files/_course_list.html.erb | 8 ++------ app/views/files/_tag_yun.html.erb | 5 +++++ app/views/tags/remove_tag_new.js.erb | 2 ++ app/views/tags/tag_save.js.erb | 12 +++++++----- 7 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 app/views/files/_tag_yun.html.erb diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index e26901320..d4399e464 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -220,6 +220,15 @@ class TagsController < ApplicationController @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 + all_attachments = @course.attachments.select{|attachment| attachment.is_public? || + (attachment.container_type == "Course" && User.current.member_of_course?(@course))|| + attachment.author_id == User.current.id + } + @tag_list = attachment_tag_list all_attachments + end # end end end @@ -263,6 +272,14 @@ class TagsController < ApplicationController else logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}" end + if @obj && @obj_flag == '6' && @obj.container.kind_of?(Course) + @course = @obj.container + all_attachments = @course.attachments.select{|attachment| attachment.is_public? || + (attachment.container_type == "Course" && User.current.member_of_course?(@course))|| + attachment.author_id == User.current.id + } + @tag_list = attachment_tag_list all_attachments + end respond_to do |format| format.js format.html diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 095d0ada5..5782d4bc8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2097,4 +2097,13 @@ module ApplicationHelper request.env["HTTP_USER_AGENT"] =~ /MSIE 8.0/ end + + #获取指定资源列表的TAG的集合以及每个TAG的数量,降序排序 + def attachment_tag_list attachments + tag_list = Hash.new + attachments.each do |attachment| + attachment.tag_list.map{|tag| tag_list.has_key?(tag) ? tag_list[tag] = tag_list[tag] + 1 : tag_list[tag] = 1} + end + tag_list.sort {|a,b| b[1]<=>a[1]} + end end diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 0be59c0da..d69f13a29 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -120,14 +120,6 @@ module FilesHelper result end - def attachment_tag_list attachments - tag_list = Hash.new - attachments.each do |attachment| - attachment.tag_list.map{|tag| tag_list.has_key?(tag) ? tag_list[tag] = tag_list[tag] + 1 : tag_list[tag] = 1} - end - tag_list.sort {|a,b| b[1]<=>a[1]} - end - def get_attachments_by_tag attachments,tag attachments.each do |attachment| attachment.tag_list.include?(tag) diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 5bbb8757d..c726d63e7 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -15,12 +15,8 @@
-
- <% unless @tag_list.nil?%> - <% @tag_list.each do |k,v|%> - <%= k%>(<%= v%> - <% end%> - <% end%> +
+ <%= render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => course}%>
diff --git a/app/views/files/_tag_yun.html.erb b/app/views/files/_tag_yun.html.erb new file mode 100644 index 000000000..f78ea6cdf --- /dev/null +++ b/app/views/files/_tag_yun.html.erb @@ -0,0 +1,5 @@ +<% unless tag_list.nil?%> + <% tag_list.each do |k,v|%> + <%= k%>(<%= v%> + <% end%> +<% end%> \ 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 01edf3e1c..35361fc7d 100644 --- a/app/views/tags/remove_tag_new.js.erb +++ b/app/views/tags/remove_tag_new.js.erb @@ -3,6 +3,8 @@ $("#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}) %>'); + +$("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course}) %>"); <% end %> <% if @object_flag == "10"%> $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); diff --git a/app/views/tags/tag_save.js.erb b/app/views/tags/tag_save.js.erb index c7dbec65d..31ee40a42 100644 --- a/app/views/tags/tag_save.js.erb +++ b/app/views/tags/tag_save.js.erb @@ -5,11 +5,13 @@ $('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_n //$('#put-tag-form-issue').hide(); $('#name-issue').val(""); <% elsif @obj_flag == '6'%> -$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); -$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/course_attachment_tag_name', - :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); -$("#tags_name_<%=@obj.id%>").val(""); -$("#add_tag_<%=@obj.id%>").hide(); + $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); + $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/course_attachment_tag_name', + :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); + $("#tags_name_<%=@obj.id%>").val(""); + $("#add_tag_<%=@obj.id%>").hide(); + + $("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course}) %>"); <% elsif @obj_flag == '9'%> $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/new_tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');