From b4561fa68d0c0db9ce090a8839ae6142a3806985 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 22 Sep 2015 16:19:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=20=E4=B8=8A=E6=96=B9=E7=9A=84tag=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E7=9A=84=E8=AF=9D=EF=BC=8C=E6=89=80=E6=9C=89=E7=9A=84=E5=90=AB?= =?UTF-8?q?=E6=9C=89=E8=AF=A5tag=E7=9A=84=E8=B5=84=E6=BA=90=E7=9A=84?= =?UTF-8?q?=E9=82=A3=E4=B8=AA=E6=A0=87=E7=AD=BE=E9=A1=B5=E8=A6=81=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/tags_controller.rb | 93 ++++++++++++++++++++------- app/helpers/tags_helper.rb | 22 +++++++ app/views/files/_course_list.html.erb | 12 ++-- app/views/files/_tag_yun.html.erb | 2 +- app/views/files/index.html.erb | 15 ++--- app/views/tags/update_tag_name.js.erb | 18 ++++-- public/stylesheets/courses.css | 2 +- 7 files changed, 118 insertions(+), 46 deletions(-) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index e0cb8af8e..7dc647911 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -15,6 +15,7 @@ class TagsController < ApplicationController include ContestsHelper include ActsAsTaggableOn::TagsHelper include TagsHelper + include FilesHelper helper :projects helper :courses helper :tags @@ -236,47 +237,89 @@ class TagsController < ApplicationController @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) - @obj = get_object(@taggable_id,params[:taggableType]) - 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 = 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存在。 + #看重命名后的tag是否存在。如果存在的话,只需要更改taggings里边的id即可 + if @rename_tag + @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) @taggings.update_attributes({:tag_id=>@rename_tag.id}) + else #如果不存在,那么就直接更新该tag名称为新的名称 + (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).update_attributes(:name=>@rename_tag_name) + 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 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] diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 284ee8c43..2e8b98a2d 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -1,5 +1,6 @@ module TagsHelper include StoresHelper + include CoursesHelper # 通过 id和type获取对象 def get_object(obj_id,obj_type) @obj = nil @@ -62,6 +63,27 @@ module TagsHelper end +#判断课程course中是否包含课件attachment,course中引用了attachment也算作包含 +def course_contains_attachment? course,attachment + course.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 + user.courses.each do |course| + if !course_contains_attachment?(course,file) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course) + return true + end + end + result +end + # 判断用户是否是贴吧的管理员 # add by chenmin def is_forum_manager?(user_id,forum_id) diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 353d19dab..e31eea960 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -3,13 +3,13 @@

共有 <%= all_attachments.count%> 个资源

<% if order == "asc" %> - 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /  - <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> /  - <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 + 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /  + <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> /  + <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 <% else %> - 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /  - <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>  /  - <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 + 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /  + <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>  /  + <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序 <% end %>

diff --git a/app/views/files/_tag_yun.html.erb b/app/views/files/_tag_yun.html.erb index 9db34ece4..d4bdc57dc 100644 --- a/app/views/files/_tag_yun.html.erb +++ b/app/views/files/_tag_yun.html.erb @@ -3,7 +3,7 @@ <% if tag_name && tag_name == k%> <%= k%>×<%= v%> <% else%> - <%= k%>×<%= v%> + <%= k%>×<%= v%> <% end%> <% end%> <% end%> \ No newline at end of file diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index ded576f12..5d3e60671 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -229,6 +229,9 @@ var ele; //当前双击的链接 var tagId; //标签的id var taggableType; //被标签的类型 + //这里renameTag有两种情况,一种是改变某个资源的tag名称。如果其他资源也有这个tag。则新增一个改变后的tag名 + //第二种是改变某个tag名称。其他所有的资源如果拥有这个tag。那么对应的tag名也要改掉。 + //目前这两种依据 的来源就是 是否 传了参数 id。如果有id。就指定了资源id,就是第一种情况。如果没有id。就是第二种情况 function rename_tag(domEle,name,id,type){ if(domEle.children().get(0) != undefined ){ //已经是编辑框的情况下不要动 return; @@ -256,14 +259,10 @@ }else{ //否则就要更新tag名称了 if(confirm("是否将标签改为 "+ $("#renameTagName").val().trim())){ - $.post( - '<%= update_tag_name_path %>', - {"taggableId":tagId,"taggableType":taggableType,"tagName":tagName,"renameName":$("#renameTagName").val().trim()} -// function(data){ -// ele.parent().css("border",""); -// ele.parent().html(tagNameHtml); -// } - ) + $.post( + '<%= update_tag_name_path %>', + {"taggableId": tagId, "taggableType": taggableType, "tagName": tagName, "renameName": $("#renameTagName").val().trim(),"courseId":<%= @course.id%>} + ) }else{ ele.parent().css("border",""); ele.parent().html(tagNameHtml); diff --git a/app/views/tags/update_tag_name.js.erb b/app/views/tags/update_tag_name.js.erb index b72b0c33f..276c050b8 100644 --- a/app/views/tags/update_tag_name.js.erb +++ b/app/views/tags/update_tag_name.js.erb @@ -14,18 +14,26 @@ $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_project $('#tags_name2').val(""); <% elsif @obj_flag == '6'%> <%if @course%> -$("#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}) %>'); + <% 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/course_list', + :locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments}) %>"); + <% end %> $("#files_tag").html("<%= escape_javascript(render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => @course,:tag_name => @select_tag_name}) %>"); <%else%> $("#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}) %>'); -<%end%> - $("#tags_name_<%=@obj.id%>").val(""); $("#add_tag_<%=@obj.id%>").hide(); +<%end%> + + <% 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}) %>'); diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index d810c4891..789fba426 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -551,7 +551,7 @@ a.wzan_visited{background:url(../images/new_project/public_icon.png) 0px -503px .vi_zan{color:#28be6c;} .newwork_btn a{background:#64bdd9;color:#fff;font-size:14px; font-weight:normal; padding:2px 10px; display:block; text-align:center; float:right;} .newwork_btn a:hover{ background:#329cbd;} -.files_tag{ width:670px; height:22px; overflow:hidden; margin-bottom:10px;} +.files_tag{ width:670px; min-height:22px;margin-bottom:10px;}/* overflow:hidden; */ a.files_tag_icon{ background:#e2f3f9; color:#54aeca; border:1px solid #bbe2ef; padding:1px 10px; float:left; margin-right:10px;margin-bottom:10px; } a.files_tag_select{ background:#64bdd9; color:#fff; border:1px solid #64bdd9; padding:1px 10px; float:left; margin-right:10px;margin-bottom:10px;}