This commit is contained in:
sw 2014-10-28 17:29:21 +08:00
commit d2740c8a3a
19 changed files with 89 additions and 61 deletions

View File

@ -38,24 +38,41 @@ class TagsController < ApplicationController
@obj_id = params[:obj_id]
@obj_flag = params[:object_flag]
@selected_tags = Array.new
@selected_tags = Array.new
@selected_tag_ids = Array.new
@selected_tag_objs = Array.new
@related_tags = nil
if params[:q]
@selected_tags << params[:q]
@related_tag_ids = Array.new
@related_tag_objs = Array.new
if params[:q]
@tag = ActsAsTaggableOn::Tag.find(params[:q])
@selected_tags << @tag.name
@selected_tag_ids << @tag.id.to_s
@selected_tag_objs << @tag
else
@do_what = params[:do_what]
@tag = params[:tag]
@selected_tags = params[:current_selected_tags]
@selected_tags = @selected_tags.nil? ? Array.new : @selected_tags
@tag = ActsAsTaggableOn::Tag.find(params[:tag])
#@selected_tags = params[:current_selected_tags]
@selected_tag_ids = params[:current_selected_tags]
@selected_tag_ids = @selected_tag_ids.nil? ? Array.new : @selected_tag_ids
@selected_tag_ids.each do |t|
ta = ActsAsTaggableOn::Tag.find(t)
@selected_tags << ta.name
@selected_tag_objs << ta
end
#@selected_tags = @selected_tags.nil? ? Array.new : @selected_tags
case @do_what
when '0' then
@selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop
@selected_tags.delete @tag.name #数组中删除有多方式 可以改用shift,pop
@selected_tag_ids.delete @tag.id.to_s
@selected_tag_objs.delete @tag
when '1' then
# 判断是否已存在该tag 主要用来处理分页的情况
unless @selected_tags.include? @tag
@selected_tags << @tag
unless @selected_tags.include? @tag.name
@selected_tags << @tag.name
@selected_tag_ids << @tag.id.to_s
@selected_tag_objs << @tag
end
end
end
@ -75,7 +92,7 @@ class TagsController < ApplicationController
@attachments_results,
@contests_results,
@courses_results,
@open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags)
@open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags,@selected_tag_ids)
# 这里是做tag推荐用的 用来生产推荐的tags
unless @obj.nil?
@ -85,6 +102,13 @@ class TagsController < ApplicationController
# @tags.delete(i)
# end
@related_tags = @tags
@tag_objs = @obj.tags
@tag_objs.each do |t|
unless @selected_tags.include?(t.name)
@related_tag_ids << t.id.to_s
@related_tag_objs << t
end
end
else
return
end
@ -162,8 +186,8 @@ class TagsController < ApplicationController
if request.get?
# 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象
@tag_name = params[:tag_name]
@tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id
@tag_id = params[:tag_name]
@tag_name = (ActsAsTaggableOn::Tag.find(@tag_id)).name
@taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串
@taggable_type = numbers_to_object_type(params[:taggable_type])
@ -192,7 +216,7 @@ class TagsController < ApplicationController
private
# 这里用来刷新搜索结果的区域
# 函数的返回值 前2字段用来处理获取其他tag和分页 另外4个返回值为过滤结果
def refresh_results(obj_id,obj_flag,selected_tags)
def refresh_results(obj_id,obj_flag,selected_tags,selected_tag_ids = nil)
@users_results = nil
@projects_results = nil
@issues_results = nil
@ -210,36 +234,36 @@ class TagsController < ApplicationController
case obj_flag
when '1' then
@obj = User.find_by_id(obj_id)
@obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags))
@obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags,selected_tag_ids))
when '2' then
@obj = Project.find_by_id(obj_id)
@obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags))
@obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags,selected_tag_ids))
when '3' then
@obj = Issue.find_by_id(obj_id)
@obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags))
@obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags,selected_tag_ids))
when '4' then
@obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags))
@obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags,selected_tag_ids))
@obj = Bid.find_by_id(obj_id)
when '5'
@obj = Forum.find_by_id(obj_id)
@obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags))
@obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags,selected_tag_ids))
when '6'
@obj = Attachment.find_by_id(obj_id)
# modifed by Long Jun
# this is used to find the attachments that came from the same project and tagged with the same tag.
#@result = get_attachments_by_project_tag(selected_tags, @obj)
@result = get_attachments_by_tag(selected_tags)
@result = get_attachments_by_tag(selected_tags,selected_tag_ids)
@obj_pages, @attachments_results, @results_count = for_pagination(@result)
when '7'
@obj = Contest.find_by_id(obj_id)
@obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags))
@obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags,selected_tag_ids))
when '8'
@obj = OpenSourceProject.find_by_id(obj_id)
@obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags))
@obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags,selected_tag_ids))
when '9' then
@obj = Course.find_by_id(obj_id)
@obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags))
@obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags,selected_tag_ids))
else
@obj = nil
end

View File

@ -75,8 +75,8 @@ module AttachmentsHelper
# 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')
def get_attachments_by_tag(tag_name,selected_tag_ids = nil)
Attachment.tagged_with(tag_name,{},selected_tag_ids).order('created_on desc')
end
# this method is used to get all attachments that from one project and tagged one tag

View File

@ -35,8 +35,8 @@ module BidsHelper
# this method is used to get all projects that tagged one tag
# added by william
def get_bids_by_tag(tag_name)
Bid.tagged_with(tag_name).order('updated_on desc')
def get_bids_by_tag(tag_name,selected_tag_ids = nil)
Bid.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc')
end
#added by huang

View File

@ -35,8 +35,8 @@ module ContestsHelper
# this method is used to get all projects that tagged one tag
# added by william
def get_contests_by_tag(tag_name)
Contest.tagged_with(tag_name).order('updated_on desc')
def get_contests_by_tag(tag_name,selected_tag_ids = nil)
Contest.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc')
end
#added by huang

View File

@ -449,8 +449,8 @@ module CoursesHelper
return homework_users
end
def get_courses_by_tag(tag_name)
Course.tagged_with(tag_name).order('updated_at desc')
def get_courses_by_tag(tag_name,selected_tag_ids = nil)
Course.tagged_with(tag_name,{},selected_tag_ids).order('updated_at desc')
end
#课程实践年份下拉框

View File

@ -22,7 +22,7 @@ module ForumsHelper
# this method is used to get all projects that tagged one tag
# added by william
def get_forums_by_tag(tag_name)
Forum.tagged_with(tag_name).order('updated_at desc')
def get_forums_by_tag(tag_name,selected_tag_ids = nil)
Forum.tagged_with(tag_name,{},selected_tag_ids).order('updated_at desc')
end
end

View File

@ -382,8 +382,8 @@ module IssuesHelper
# this method is used to get all projects that tagged one tag
# added by william
def get_issues_by_tag(tag_name)
Issue.tagged_with(tag_name).order('updated_on desc')
def get_issues_by_tag(tag_name,selected_tag_ids = nil)
Issue.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc')
end
end

View File

@ -31,8 +31,8 @@ module OpenSourceProjectsHelper
s = content_tag('div', s, :class => 'user_tags')
end
def get_open_source_projects_by_tag(tag_name)
OpenSourceProject.tagged_with(tag_name).order('created_at desc')
def get_open_source_projects_by_tag(tag_name,selected_tag_ids = nil)
OpenSourceProject.tagged_with(tag_name,{},selected_tag_ids).order('created_at desc')
end
def show_origin(url)

View File

@ -232,8 +232,8 @@ module ProjectsHelper
# this method is used to get all projects that tagged one tag
# added by william
def get_projects_by_tag(tag_name)
Project.tagged_with(tag_name).order('updated_on desc')
def get_projects_by_tag(tag_name,selected_tag_ids = nil)
Project.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc')
end
# added by fq

View File

@ -57,8 +57,8 @@ module UsersHelper
# this method is used to get all projects that tagged one tag
# added by william
def get_users_by_tag(tag_name)
User.tagged_with(tag_name).order('updated_on desc')
def get_users_by_tag(tag_name,selected_tag_ids = nil)
User.tagged_with(tag_name,{},selected_tag_ids).order('updated_on desc')
end
# added by fq

View File

@ -8,7 +8,7 @@
<% if params[:project_type] == "1" %>
<table width="940px">
<tr>
<td class="info_font" style="width: 220px; color: #15bccf""><%= l(:label_course_practice) %></td>
<td class="info_font" style="width: 220px; color: #15bccf"><%= l(:label_course_practice) %></td>
<td class="location-list"><strong><%= l(:label_user_location) %> :</strong></td>
<td rowspan="2">
<% if User.current.logged?%>
@ -33,7 +33,7 @@
<% else %>
<table width="940px">
<tr>
<td class="info_font" style="width: 220px; color: #15bccf""><%= l(:label_project_deposit) %></td>
<td class="info_font" style="width: 220px; color: #15bccf"><%= l(:label_project_deposit) %></td>
<td class="location-list"><strong><%= l(:label_user_location) %> :</strong></td>
<td rowspan="2">
<% if User.current.logged? %>

View File

@ -5,14 +5,14 @@
<% i += 1 %>
<li>
<%= link_to image_tag("/images/sidebar/add.png"),:action => "index",
:current_selected_tags => selected_tags,:tag => rt,:do_what => "1",
:current_selected_tags => selected_tags,:tag => rt.id,:do_what => "1",
:obj_id => obj_id,:object_flag => obj_flag %>
<span id="tag">
<%= rt %>
<%= rt.name %>
</span>
<% break if i >= 10 %>
<!-- 这里用例计数某类对象的所有该tag总数 -->
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => rt }%>
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => rt,:selected_tag_ids => related_tag_ids }%>
</li>
<% end %>
</ul>

View File

@ -3,10 +3,10 @@
<% for sg in selected_tags %>
<li>
<%= link_to image_tag("/images/sidebar/minus.png"),:action => "index",
:current_selected_tags => selected_tags ,:tag => sg,:do_what => "0",
:current_selected_tags => selected_tags ,:tag => sg.id,:do_what => "0",
:obj_id => obj_id,:object_flag => obj_flag %>
<span id="tag"><%= sg %> </span>
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => sg }%>
<span id="tag"><%= sg.name %> </span>
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => obj_flag,:sg => sg ,:selected_tag_ids => @selected_tag_ids}%>
</li>
<% end %>
</ul>

View File

@ -1,14 +1,14 @@
<% case show_flag%>
<% when '1' then %>
(<%= User.tagged_with("#{sg}").size %>)
(<%= User.tagged_with("#{sg.name}",{},selected_tag_ids).size %>)
<%when '2' then %>
(<%= Project.tagged_with(sg).size %>)
(<%= Project.tagged_with(sg.name,{},selected_tag_ids).size %>)
<% when '3' then %>
(<%= Issue.tagged_with("#{sg}").size %>)
(<%= Issue.tagged_with("#{sg.name}",{},selected_tag_ids).size %>)
<% when '4' then %>
(<%= Bid.tagged_with("#{sg}").size %>)
(<%= Bid.tagged_with("#{sg.name}",{},selected_tag_ids).size %>)
<% when '5' then %>
(<%= Forum.tagged_with("#{sg}").size %>)
(<%= Forum.tagged_with("#{sg.name}",{},selected_tag_ids).size %>)
<% when '6' then %>
(<%= Attachment.tagged_with("#{sg}").size %>)
(<%= Attachment.tagged_with("#{sg.name}",{},selected_tag_ids).size %>)
<% end %>

View File

@ -8,7 +8,7 @@
// })
</script>
<!-- 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求 9代表课程-->
<% @tags = obj.reload.tag_list %>
<% @tags = obj.reload.tags %>
<% if non_list_all and (@tags.size > 0) %>
<!-- 这里是显示的非主页的tag 所以当tag数量较多时 不必全部显示 用“更多”代替 -->

View File

@ -3,13 +3,13 @@
<h3><strong><%= l(:label_tags_selected) %></strong></h3>
<div id="selected_tags">
<%= render :partial => "selected_tags",:locals => {
:selected_tags => @selected_tags,:obj_flag => @obj_flag,:obj_id => @obj_id }%>
:selected_tags => @selected_tag_objs,:obj_flag => @obj_flag,:obj_id => @obj_id }%>
</div>
<h3><strong><%= l(:label_tags_related) %></strong></h3>
<div id="related_tags">
<%= render :partial => "related_tags",:locals => {:related_tags => @related_tags,
:selected_tags => @selected_tags,:obj_flag => @obj_flag,:obj_id => @obj_id }%>
<%= render :partial => "related_tags",:locals => {:related_tags => @related_tag_objs,
:selected_tags => @selected_tag_ids,:related_tag_ids => @related_tag_ids,:obj_flag => @obj_flag,:obj_id => @obj_id }%>
</div>
</div>
<% end %>

View File

@ -15,11 +15,12 @@
<% if User.current == @user %>
<% (membership.roles).each do |role| %>
<% unless (role == Role.find(9) || role == Role.find(3)) %>
<%= join_in_course(membership.course, User.current) %>&nbsp;&nbsp;&nbsp;&nbsp;
<%= join_in_course(membership.course, User.current) %>
<% end %>
<% end %>
<% else %>
<% end %>
&nbsp;&nbsp;&nbsp;&nbsp;
<%= l(:label_x_base_courses_member, :count => membership.course.members.count) %>
(<%= "#{membership.course.members.count}" %>)&nbsp;&nbsp;
<%= l(:label_homework) %>

View File

@ -1840,4 +1840,6 @@ en:
label_my_school: My school
label_all_schol: All school
label_select_province: Please select the provinces
label_search_conditions_not_null: The search conditions can not be empty
label_search_conditions_not_null: The search conditions can not be empty
lable_school_list: List of schools
button_delete_file: delete

View File

@ -22,6 +22,7 @@ body
{
font-size: 13px;
line-height: 1.6em;
word-wrap: break-word;
}
blockquote