diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 92e4d1fb5..ac2a5236b 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -9,6 +9,7 @@ class TagsController < ApplicationController include UsersHelper include BidsHelper include ForumsHelper + include AttachmentsHelper include ActsAsTaggableOn::TagsHelper helper :projects include TagsHelper @@ -48,24 +49,27 @@ class TagsController < ApplicationController unless @selected_tags.include? @tag @selected_tags << @tag end - end + end end - @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num = get_tags_size + @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, + @forum_tags_num, @attachments_tags_num = get_tags_size # 获取搜索结果 @obj,@obj_pages,@results_count,@users_results, @projects_results, @issues_results, @bids_results, - @forums_results = refresh_results(@obj_id,@obj_flag,@selected_tags) + @forums_results, + @attachments_results = refresh_results(@obj_id,@obj_flag,@selected_tags) # 这里是做tag推荐用的, 用来生产推荐的tags unless @obj.nil? @tags = @obj.tag_list - @selected_tags.each do |i| - @tags.delete(i) - end + @tags -= @selected_tags + # @selected_tags.each do |i| + # @tags.delete(i) + # end @related_tags = @tags else return @@ -136,6 +140,7 @@ class TagsController < ApplicationController @taggable_type = numbers_to_object_type(params[:taggable_type]) @obj = get_object(@taggable_id,params[:taggable_type]) + logger.debug "==========================================#{@obj}" @object_flag = params[:taggable_type] # if can_remove_tag?(User.current,@taggable_id,@taggable_type) @@ -166,6 +171,7 @@ private @issues_results = nil @bids_results = nil @forums_results = nil + attachments_results = nil @obj_pages = nil @obj = nil @@ -186,10 +192,13 @@ private when '5' @obj = Forum.find_by_id(obj_id) @obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags)) + when '6' + @obj = Attachment.find_by_id(obj_id) + @obj_pages, attachments_results, @results_count = for_pagination(get_attachments_by_tag(selected_tags)) else @obj = nil end - return @obj,@obj_pages,@results_count,@users_results,@projects_results,@issues_results,@bids_results,@forums_results + return @obj,@obj_pages,@results_count,@users_results,@projects_results,@issues_results,@bids_results,@forums_results, attachments_results end def for_pagination(results) @@ -207,7 +216,9 @@ private @projects_tags_num = Project.tag_counts.size @users_tags_num = User.tag_counts.size @bids_tags_num = Bid.tag_counts.size - return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num + forum_tags_num = Forum.tag_counts.size + attachment_tags_num = Attachment.tag_counts.size + return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num end # 通过数字 来转换出对象的类型 @@ -224,6 +235,10 @@ private return 'Issue' when '4' return 'Bid' + when '5' + return 'Forum' + when '6' + return 'Attachment' else render_error :message => e.message return diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 741ccce10..5fcac2d59 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -628,6 +628,8 @@ class UsersController < ApplicationController @obj = Bid.find_by_id(@obj_id) when '5' then @obj = Forum.find_by_id(@obj_id) + when '6' + @obj = Attachment.find_by_id(@obj_id) else @obj = nil end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 1cbea11ef..7ca9b9669 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -17,9 +17,9 @@ class WelcomeController < ApplicationController caches_action :robots + before_filter :entry_select, :only => [:index] def index - (course() and render :course and return 0) if request.original_url.match(/course\.trustie\.net/) # @news = News.latest User.current # @projects = Project.latest User.current #by young @@ -79,5 +79,12 @@ class WelcomeController < ApplicationController @teacher = User.teacher @student = User.student end + + private + + # 判断网站的入口,是课程 course 则跳过index去渲染 course 方法 + def entry_select + (course() and render :course and return 0) if request.original_url.match(/course\.trustie\.net/) + end end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 421860860..a90807718 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -79,4 +79,10 @@ module AttachmentsHelper end end + # this method is used to get all projects that tagged one tag + # added by william + def get_attachments_by_tag(tag_name) + Attachment.tagged_with(tag_name).order('created_on desc') + end + end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index fa99b57ad..c4ee5273d 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -1,5 +1,5 @@ module TagsHelper - + include StoresHelper # 通过 id和type获取对象 def get_object(obj_id,obj_type) @obj = nil @@ -12,6 +12,10 @@ module TagsHelper @obj = Issue.find_by_id(obj_id) when '4' @obj = Bid.find_by_id(obj_id) + when '6' + @obj = Attachment.find_by_id(obj_id) + else + raise Exception, '[TagsHelper] ===> tag type unknow.' end return @obj end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 144125174..e669428f6 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -28,6 +28,7 @@ class Attachment < ActiveRecord::Base validates_length_of :disk_filename, :maximum => 255 validates_length_of :description, :maximum => 255 validate :validate_max_file_size + acts_as_taggable acts_as_event :title => :filename, :url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}} diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index 7c0cfd965..2b1853094 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -8,6 +8,8 @@ width: 98%; text-align: left; border-collapse: collapse; + line-height: 20px; + font-size: 14px; } #ver-zebra th { @@ -26,6 +28,36 @@ border-left: 1px solid #fff; color: #669; } +#ver-zebra td.description { + background-color: white; + padding: 0px; + margin: 0px auto; +} +div.tags_area { + padding: 2px 10px 10px 10px; + margin: 0px; + margin-bottom: 10px; + border-bottom: 1px dashed #CCCCCC; + overflow: hidden; + position: relative; +} +.tags_gradint { +} +.read-more{ + padding: 5px; + border-top: 4px double #ddd; + background: #fff; + color: #333; +} +.read-more a{ + padding-right: 22px; + background: url() no-repeat 100% 50%; + font-weight: bold; + text-decoration: none; +} +.read-more a:hover{ + color: #000; +} .vzebra-odd { background: #eff2ff; @@ -49,22 +81,34 @@ white-space: nowrap; text-overflow: ellipsis; } - + <%=(@project.project_type == 1) ? t(:label_user_course) : t(:label_project) %>文件共享专区
<%= link_to(l(:label_attachment_new), new_project_file_path(@project), :class => 'icon icon-add') if User.current.allowed_to?(:manage_files, @project) %> + +<% if Rails.env.development? %> +~测试测试~ + +<% end %>
<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %> - +
+ <%= sort_header_tag('filename', :caption => l(:field_filename), :scope =>"col" , :id => "vzebra-adventure")%> @@ -79,14 +123,14 @@ <% next if container.attachments.empty? -%> <% if container.is_a?(Version) -%> - <% end -%> <% container.attachments.each do |file| %> - "> - + "> + @@ -96,9 +140,18 @@ :data => {:confirm => l(:text_are_you_sure)}, :method => :delete) if delete_allowed %> - <% end %> + + + + <% end -%> <% reset_cycle %> - <% end %> + <% end -%> @@ -107,3 +160,46 @@ <% html_title(l(:label_attachment_plural)) -%> + \ No newline at end of file diff --git a/app/views/tags/_show_attachments.html.erb b/app/views/tags/_show_attachments.html.erb new file mode 100644 index 000000000..3484d1351 --- /dev/null +++ b/app/views/tags/_show_attachments.html.erb @@ -0,0 +1,34 @@ +
+<% if attachments_results.size < 0 %> +<% else %> +
+ <% attachments_results.each do |file| %> +

+

+ <%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package", :style => "color: #666666;") %>
<%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %>
<%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %> <%= format_time(file.created_on) %> <%= number_to_human_size(file.filesize) %> <%= file.downloads %>
+
+ <%= render :partial => 'tags/tag', :locals => {:obj => file, :object_flag => "6"}%> +
+
+ +
+ + + + + +
+
+ <%= l(:label_attachment) %>:  <%= file.filename %> + + <%= link_to_attachment file, {:download => true, :text => image_tag("/images/button/dl.png", width: "70px", alt: l(:button_download), :class => 'download_icon')}%> + +
+ <%= l(:field_description) %>:  <%= file.description %> +
所属分类:<%=result_come_from file%>
+ + 下载:<%= file.downloads%>| + 大小:<%= number_to_human_size(file.filesize) %>| + 共享者:<%= link_to file.author, user_path(file.author), target: "_blank" unless file.author.blank? %>| + 上传时间:<%= format_time(file.created_on) %> + +
+
+

+
+ <% end %> +<% end %> + diff --git a/app/views/tags/_tag.html.erb b/app/views/tags/_tag.html.erb index 6370e8dee..b2cd77054 100644 --- a/app/views/tags/_tag.html.erb +++ b/app/views/tags/_tag.html.erb @@ -1,5 +1,12 @@
- + <%#begin + 1 代表是user类型 + 2 代表是project类型 + 3 代表是issue类型 + 4 代表是bid类型 + 5 代表是forum类型 + 6 代表是Attachment类型 + #end%> <% if object_flag == '3' %> <%= image_tag("/images/sidebar/tags.png") %> @@ -23,7 +30,27 @@ <% end %>
- + <% elsif object_flag == '6' %> + <%= image_tag("/images/sidebar/tags.png") %> + + <%= link_to (image_tag "/images/sidebar/add.png"), 'javascript:void(0);', :class => "tags_icona", :onclick=>"$('#put-tag-form-#{obj.class}-#{obj.id}').toggle(); readmore(this);" if User.current.logged? %> + <%#= toggle_link (image_tag "/images/sidebar/add.png"), "put-tag-form-#{obj.class}-#{obj.id}", {:focus => "put-tag-form-#{obj.class}-#{obj.id} #name"} if User.current.logged? %> + +    +
+ <%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %> +
+ <% else %> <%= image_tag("/images/sidebar/tags.png") %> diff --git a/app/views/tags/_tag_name.html.erb b/app/views/tags/_tag_name.html.erb index 220f886e0..d1291ee78 100644 --- a/app/views/tags/_tag_name.html.erb +++ b/app/views/tags/_tag_name.html.erb @@ -70,6 +70,15 @@ :taggable_id => obj.id,:taggable_type => object_flag %> <% end %> + <% when '6'%> + <% if ( User.current.logged? && + User.current.admin? + # && (@project && User.current.member_of?(@project)) + ) + %> + <%= link_to 'x',:controller => "tags",:action => "remove_tag",:remote => true,:tag_name => tag, + :taggable_id => obj.id,:taggable_type => object_flag %> + <% end %> <% end %> diff --git a/app/views/tags/_tag_search_results.html.erb b/app/views/tags/_tag_search_results.html.erb index b46ad7da6..c67ece520 100644 --- a/app/views/tags/_tag_search_results.html.erb +++ b/app/views/tags/_tag_search_results.html.erb @@ -16,6 +16,9 @@ <% when show_flag == '5'%> <%= l(:label_forum)%>(<%= @results_count %>) <%= render :partial => "show_forums",:locals => {:forums_results => forums_results}%> + <% when show_flag == '6'%> + <%= l(:label_attachment)%>(<%= @results_count %>) + <%= render :partial => "show_attachments",:locals => {:attachments_results => attachments_results}%> <% else %> <%= l(:label_tags_all_objects)%> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index 0cee8e981..17ac58184 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -21,12 +21,14 @@ <%= l(:label_issue_plural) %>(<%= @issues_tags_num %>) | <%= l(:label_project_plural) %>(<%= @projects_tags_num %>) | <%= l(:label_user_plural) %>(<%= @users_tags_num %>) | - <%= l(:label_tags_call)%>(<%= @bids_tags_num %>) + <%= l(:label_tags_call)%>(<%= @bids_tags_num %>) | + <%= l(:field_filename)%>(<%= @attachments_tags_num %>)
+ <%# 求工厂模式重构 %> <%= render :partial => "tag_search_results",:locals => {:issues_results => @issues_results, :projects_results => @projects_results,:users_results => @users_results , - :bids_results=>@bids_results,:forums_results => @forums_results, :show_flag => @obj_flag}%> + :bids_results=>@bids_results,:forums_results => @forums_results, :attachments_results => @attachments_results, :show_flag => @obj_flag}%>
diff --git a/app/views/tags/remove_tag.js.erb b/app/views/tags/remove_tag.js.erb index f74cb355d..dbad80f96 100644 --- a/app/views/tags/remove_tag.js.erb +++ b/app/views/tags/remove_tag.js.erb @@ -2,7 +2,10 @@ <% if @object_flag == '3'%> $('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @object_flag}) %>'); - +<% elsif @object_flag == '6'%> + $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); + $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_name', + :locals => {:obj => @obj,:non_list_all => false, :object_flag => @object_flag}) %>'); <% else %> $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @object_flag}) %>'); diff --git a/app/views/users/tag_save.js.erb b/app/views/users/tag_save.js.erb index 4dbdc4203..a7ae11768 100644 --- a/app/views/users/tag_save.js.erb +++ b/app/views/users/tag_save.js.erb @@ -4,7 +4,12 @@ $('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_n :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); $('#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/tag_name', + :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); + //$("#put-tag-form-<%=@obj.class%>-<%=@obj.id%>").hide(); + $("#put-tag-form-<%=@obj.class%>-<%=@obj.id%> #name").val(""); <% else %> $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name', diff --git a/public/images/sidebar/minus.png b/public/images/sidebar/minus.png index 0e4076157..3a4c8330f 100644 Binary files a/public/images/sidebar/minus.png and b/public/images/sidebar/minus.png differ diff --git a/public/stylesheets/nyan.css b/public/stylesheets/nyan.css index bc032ebc8..08e001eb2 100644 --- a/public/stylesheets/nyan.css +++ b/public/stylesheets/nyan.css @@ -336,7 +336,7 @@ div.actions input[type="text"]{ border-top: 2px double #C6F3F9; /*border-radius: 10px;*/ } -.comments img { +.memo-content img, .comments img { overflow:hidden; /*width: 100%;*/ max-width: 500px;