小改怡情 大改伤身 强改灰飞烟灭

This commit is contained in:
yanxd 2014-03-01 10:14:01 +08:00
parent dd4fb1f5b0
commit 21e55492fa
16 changed files with 238 additions and 24 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}}

View File

@ -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;
}
</style>
</style>
<span class="borad-title"><%=(@project.project_type == 1) ? t(:label_user_course) : t(:label_project) %>文件共享专区</span>
<div class="content-title-top">
<%= 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? %>
<a href="#" class = 'icon' onclick="modalWin();">~测试测试~</a>
<script type="text/javascript">
function modalWin () {
$('#ajax-modal').html('<h3 class="title">~测试测试~</h3><p>导入勾选文件xxx test</p>');
showModal('ajax-modal', '400px');
}
</script>
<% end %>
</div>
<% delete_allowed = User.current.allowed_to?(:manage_files, @project) %>
<table class="list files" id="ver-zebra" style="line-height: 20px; font-size: 14px;">
<table class="list files" id="ver-zebra" >
<colgroup>
<col class="vzebra-odd" />
<col class="vzebra-even" />
<col class="vzebra-odd" />
<col class="vzebra-even" />
<col class="vzebra-odd" />
</colgroup>
<thead><tr>
<%= 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) -%>
<tr>
<th colspan="6" align="left" style="line-height: 30px; font-size: 14px; ">
<th colspan="5" align="left" style="line-height: 30px; font-size: 14px; ">
<%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package", :style => "color: #666666;") %>
</th>
</tr>
<% end -%>
<% container.attachments.each do |file| %>
<tr class="file <%= cycle("odd", "even") %>">
<td class="filename" style="font-size: 13px; max-width: 240px; "><%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %></td>
<tr class="file <%= cycle("odd", "odd") %>">
<td class="filename" style="font-size: 13px; width: 240px; "><%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %></td>
<td class="created_on"><%= format_time(file.created_on) %></td>
<td class="filesize"><%= number_to_human_size(file.filesize) %></td>
<td class="downloads"><%= file.downloads %></td>
@ -96,9 +140,18 @@
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete) if delete_allowed %>
</td>
</tr>
<% end %>
<tr>
<td class='description' colspan="5">
<div class="tags_area">
<%= render :partial => 'tags/tag', :locals => {:obj => file, :object_flag => "6"}%>
<div class="tags_gradint"></div>
</div>
<div class="read-more hidden"><a href="javascript:void(0);" onclick="readmore(this);"> 更多 </a></div>
</td>
</tr>
<% end -%>
<% reset_cycle %>
<% end %>
<% end -%>
<!-- %= h downloadAll(@containers) % -->
<!-- %= link_to "download all file", (downloadAll(@containers)) % -->
@ -107,3 +160,46 @@
<% html_title(l(:label_attachment_plural)) -%>
<script type='text/javascript';>
var slideHeight = 29;
function readmore (aNode) {
// console.log(aNode)
// var $td_tags_area = $(aNode).parent().parent();
var $td_tags_area = $(aNode).parent().parent().parent().parent();
var $tags_area = $td_tags_area.find('.tags_area')
var $tags_gradint = $td_tags_area.find('.tags_gradint')
var $read_more = $td_tags_area.find('.read-more')
var $read_more_a = $td_tags_area.find('.read-more a')
var $tags = $td_tags_area.find('#tags')
var $icona = $td_tags_area.find('.tags_icona')
var slideHeight = 20; //px
var defHeight = $tags.height();
var curHeight = $tags_area.height();
if (curHeight == slideHeight) {
$tags_area.animate({
height: defHeight
}, 'normal');
$read_more_a.html('隐藏');
$icona.html('<%=image_tag "/images/sidebar/minus.png"%>')
$tags_gradint.fadeOut();
}else{
$tags_area.animate({
height: slideHeight
}, 'normal');
$read_more_a.html('更多');
$icona.html('<%=image_tag "/images/sidebar/add.png"%>')
$tags_gradint.fadeIn();
};
}
$(function () {
var slideHeight = 20; //px
var defHeight = $('.tags_area').height();
if (defHeight >= slideHeight) {
$('.tags_area').css('height', slideHeight +'px');
};
});
</script>

View File

@ -0,0 +1,34 @@
<div id="issues">
<% if attachments_results.size < 0 %>
<% else %>
<hr />
<% attachments_results.each do |file| %>
<p class="font_description2">
<table border=0 cellSpacing=0 cellPadding=0>
<tbody>
<tr>
<td class="r1">
<div class="cb">
<strong><%= l(:label_attachment) %>:&nbsp;&nbsp;<%= file.filename %></strong>
<span style="margin-left: 4px;">
<%= link_to_attachment file, {:download => true, :text => image_tag("/images/button/dl.png", width: "70px", alt: l(:button_download), :class => 'download_icon')}%>
</span>
</div>
<strong><%= l(:field_description) %></strong>:&nbsp;&nbsp;<%= file.description %>
<div class="c9 gray-color"> 所属分类:<%=result_come_from file%> </div>
<span class="gray blue-color">
下载:<%= file.downloads%>|
大小:<%= number_to_human_size(file.filesize) %>|
共享者:<a class="gray" ><%= link_to file.author, user_path(file.author), target: "_blank" unless file.author.blank? %></a>|
上传时间:<%= format_time(file.created_on) %>
</span>
<div style="display: none"></div>
</td>
</tr>
</tbody>
</table>
</p>
<div class="line_under"></div>
<% end %>
<% end %>
</div>

View File

@ -1,5 +1,12 @@
<div id="tags">
<!-- 1代表是user类型 2代表是project类型 3代表是issue类型 4代表的是bid类型 5代表的是forum类型 -->
<%#begin
1 代表是user类型
2 代表是project类型
3 代表是issue类型
4 代表是bid类型
5 代表是forum类型
6 代表是Attachment类型
#end%>
<!-- 3 代表的是issue 当是issue是 处理方式与前2个对象不同 -->
<% if object_flag == '3' %>
<span><%= image_tag("/images/sidebar/tags.png") %></span>
@ -23,7 +30,27 @@
<% end %>
</div>
<% elsif object_flag == '6' %>
<span><%= image_tag("/images/sidebar/tags.png") %></span>
<span>
<%= 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? %>
</span>
&nbsp;&nbsp;
<div id="tags_show-<%=obj.class%>-<%=obj.id%>" style="display:inline; ">
<%= render :partial => "tags/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
</div>
<div id="put-tag-form-<%=obj.class%>-<%=obj.id%>" style="display: none">
<%= form_for "tag_for_save",:remote=>true,:url=>tag_path,
:update => "tags_show",
:complete => "$(\"#put-tag-form-#{obj.class}-#{obj.id}\").hide();" do |f| %>
<%= f.text_field :name ,:id => "name",:size=>"28",:require=>true,:maxlength => Setting.tags_max_length,:minlength=>Setting.tags_min_length %>
<%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%>
<%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%>
<%= f.submit l(:button_project_tags_add),:class => "small" %>
<%#= link_to_function l(:button_cancel), "$(\"#put-tag-form-#{obj.class}-#{obj.id}\").hide();"%>
<% end %>
</div>
<% else %>
<span><%= image_tag("/images/sidebar/tags.png") %></span>

View File

@ -70,6 +70,15 @@
:taggable_id => obj.id,:taggable_type => object_flag %> </span>
<% end %>
<% when '6'%>
<% if ( User.current.logged? &&
User.current.admin?
# && (@project && User.current.member_of?(@project))
)
%>
<span class='del'> <%= link_to 'x',:controller => "tags",:action => "remove_tag",:remote => true,:tag_name => tag,
:taggable_id => obj.id,:taggable_type => object_flag %> </span>
<% end %>
<% end %>
</span>

View File

@ -16,6 +16,9 @@
<% when show_flag == '5'%>
<strong><%= l(:label_forum)%>(<%= @results_count %>)</strong>
<%= render :partial => "show_forums",:locals => {:forums_results => forums_results}%>
<% when show_flag == '6'%>
<strong><%= l(:label_attachment)%>(<%= @results_count %>)</strong>
<%= render :partial => "show_attachments",:locals => {:attachments_results => attachments_results}%>
<% else %>
<strong><%= l(:label_tags_all_objects)%></strong>
<!-- 这里为显示搜有过滤结果预留了默认设置 -->

View File

@ -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 %>)
</div>
<div id="show_results">
<%# 求工厂模式重构 %>
<%= 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}%>
</div>
</div>

View File

@ -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}) %>');

View File

@ -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',

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -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;