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(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 %> | @@ -96,9 +140,18 @@ :data => {:confirm => l(:text_are_you_sure)}, :method => :delete) if delete_allowed %>|||||||
+ | + + +
+
+ <%= 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) %>
+
+
+ |
+