增加tag删除。
This commit is contained in:
parent
61e4021625
commit
2079c87362
|
@ -3,12 +3,15 @@ class TagsController < ApplicationController
|
|||
layout "base_tags"
|
||||
|
||||
before_filter :require_admin,:only => :show
|
||||
|
||||
include ProjectsHelper
|
||||
include IssuesHelper
|
||||
include UsersHelper
|
||||
include BidsHelper
|
||||
include ActsAsTaggableOn::TagsHelper
|
||||
helper :projects
|
||||
include TagsHelper
|
||||
helper :tags
|
||||
|
||||
before_filter :require_admin,:only => [:delete,:show_all]
|
||||
|
||||
|
@ -96,14 +99,15 @@ class TagsController < ApplicationController
|
|||
@projects_results,
|
||||
@issues_results,
|
||||
@bids_results = refresh_results(@obj_id,@show_flag)
|
||||
|
||||
end
|
||||
|
||||
def show_all
|
||||
@tags = ActsAsTaggableOn::Tag.find(:all)
|
||||
end
|
||||
|
||||
#完全从数据库删除tag
|
||||
# 完全从数据库删除tag
|
||||
# 这种删除方式是针对 印有该 tag所有对象来做删除的
|
||||
# 这样是从整个系统数据库中把该tag删除了
|
||||
def delete
|
||||
if params[:q]
|
||||
@tag = ActsAsTaggableOn::Tag.find_by_id(params[:q])
|
||||
|
@ -113,7 +117,40 @@ class TagsController < ApplicationController
|
|||
tagging.delete
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 只删除某个对象的该tag
|
||||
def remove_tag
|
||||
@obj = nil
|
||||
@object_flag = nil
|
||||
|
||||
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
|
||||
@taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串
|
||||
@taggable_type = numbers_to_object_type(params[:taggable_type])
|
||||
|
||||
@obj = get_object(@taggable_id,params[:taggable_type])
|
||||
@object_flag = params[:taggable_type]
|
||||
|
||||
# if can_remove_tag?(User.current,@taggable_id,@taggable_type)
|
||||
|
||||
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type)
|
||||
|
||||
unless @taggings.nil?
|
||||
@taggings.delete
|
||||
end
|
||||
|
||||
# 是否还有其他记录 引用了 tag_id
|
||||
@tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id)
|
||||
# 如果taggings表中记录已经不存在 ,那么检查tags表 作删除动作
|
||||
if @tagging.nil?
|
||||
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
|
||||
@tag.delete unless @tag.nil?
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -156,7 +193,7 @@ private
|
|||
return @obj_pages,results, @results_count
|
||||
end
|
||||
|
||||
#获取有某类对象的tag总数
|
||||
# 获取有某类对象的tag总数
|
||||
def get_tags_size
|
||||
@issues_tags_num = Issue.tag_counts.size
|
||||
@projects_tags_num = Project.tag_counts.size
|
||||
|
@ -165,4 +202,24 @@ private
|
|||
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num
|
||||
end
|
||||
|
||||
# 通过数字 来转换出对象的类型
|
||||
# 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求
|
||||
# 这个函数 重构是可以移动到application_helper中去
|
||||
# 当做一个全局的函数使用,有好几个地方使用到了
|
||||
def numbers_to_object_type(num)
|
||||
case num
|
||||
when '1'
|
||||
return 'Principal'
|
||||
when '2'
|
||||
return 'Project'
|
||||
when '3'
|
||||
return 'Issue'
|
||||
when '4'
|
||||
return 'Bid'
|
||||
else
|
||||
render_error :message => e.message
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
# fq
|
||||
module BidsHelper
|
||||
|
||||
|
||||
def render_notes(bid, journal, options={})
|
||||
content = ''
|
||||
removable = User.current == journal.user || User.current == bid.author
|
||||
|
|
|
@ -146,4 +146,14 @@ module ProjectsHelper
|
|||
type << option2
|
||||
end
|
||||
|
||||
# 用来判断用户是否是项目的管理员
|
||||
# added by william
|
||||
def is_manager?(user_id,project_id)
|
||||
@result = false
|
||||
@user_id = ProjectInfo.find_by_project_id(project_id)
|
||||
if @user_id == user.id
|
||||
@result = true
|
||||
end
|
||||
return @result
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
module TagsHelper
|
||||
|
||||
# 通过 id和type获取对象
|
||||
def get_object(obj_id,obj_type)
|
||||
@obj = nil
|
||||
case obj_type
|
||||
when '1'
|
||||
@obj = User.find_by_id(obj_id)
|
||||
when '2'
|
||||
@obj = Project.find_by_id(obj_id)
|
||||
when '3'
|
||||
@obj = Issue.find_by_id(obj_id)
|
||||
when '4'
|
||||
@obj = Bid.find_by_id(obj_id)
|
||||
end
|
||||
return @obj
|
||||
end
|
||||
|
||||
# 判断登录用户是否可以对用户、项目、需求、问题中tag进行删除动作
|
||||
# 这里关于项目可以使用User.memeber_of?来做判断,这样可以提高该函数效率,但对满足需求有偏差
|
||||
# 返回值为true 或 false
|
||||
def can_remove_tag(user,obj_id,obj_type)
|
||||
@result = false
|
||||
case obj_type
|
||||
when '1' # 对用户 是否是本人
|
||||
@obj = User.find_by_id(obj_id)
|
||||
if user == @obj
|
||||
@result = true
|
||||
end
|
||||
when '2'
|
||||
@result = is_manager?(user.id,obj_id)
|
||||
when '3'
|
||||
@project_id = Issue.find_by_id(obj_id)
|
||||
@result = is_manager?(user.id,@project_id)
|
||||
when '4'
|
||||
if user.id == obj_id
|
||||
@result = true
|
||||
end
|
||||
end
|
||||
return @result
|
||||
end
|
||||
|
||||
end
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
include AvatarHelper
|
||||
module UsersHelper
|
||||
|
||||
def users_status_options_for_select(selected)
|
||||
user_count_by_status = User.count(:group => 'status').to_hash
|
||||
options_for_select([[l(:label_all), ''],
|
||||
|
|
|
@ -216,9 +216,8 @@
|
|||
|
||||
<p><table><tr><td class="info" align="right" style="width: 90px"><strong><%= l(:label_identity) %><span class="required"> *</span></strong></td>
|
||||
<td class="info" style="width: 10px">
|
||||
<%= select_tag 'identity', "<option value = '0'>#{l(:label_teacher)}</option>
|
||||
<option value = '1'>#{l(:label_student)}</option>
|
||||
<option value = '2'>#{l(:label_other)}</option>".html_safe %></td></tr></table></p>
|
||||
<%= select_tag 'identity', "<option value = '0'>#{l(:label_teacher)}</option> <option value = '1'>#{l(:label_student)}</option> <option value = '2'>#{l(:label_other)}</option>"
|
||||
.html_safe %></td></tr></table></p>
|
||||
|
||||
|
||||
<p><table><tr><td class="info" align="right" style="width: 90px"><strong><%= l(:label_gender) %></strong></td>
|
||||
|
|
|
@ -23,7 +23,14 @@
|
|||
<% if get_prize(b_project).nil? or get_prize(b_project) == "" %>
|
||||
未评奖
|
||||
<% else %>
|
||||
<%= get_prize(b_project) %>
|
||||
<% case get_prize(b_project) %>
|
||||
<% when '0' %>
|
||||
一等奖
|
||||
<% when '1' %>
|
||||
二等奖
|
||||
<% when '2' %>
|
||||
入围奖
|
||||
<%end%>
|
||||
<% end %>
|
||||
</span></strong>
|
||||
</td>
|
||||
|
@ -52,7 +59,11 @@
|
|||
|
||||
<%= form_for "set_reward",:remote=>true,:url=>set_reward_path do |f| %>
|
||||
<%= f.text_field :b_id,:style => "display:none",:value => b_project.id,:size=>"0" %>
|
||||
<%= f.text_field :reward,:size=>"10",:require=>true,:maxlength => 10,:minlength=>1 %>
|
||||
|
||||
<%= f.select :reward,"<option value = '0'>#{l(:label_first_reward)}</option> <option value = '1'>#{l(:label_second_reward)}</option> <option value = '2'>#{l(:label_comfort_reward)}</option>"
|
||||
.html_safe %>
|
||||
|
||||
|
||||
<%= f.submit "提交",:class=>"submit" %>
|
||||
|
||||
<% end %>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
<!-- fq -->
|
||||
<%= render_flash_messages %>
|
||||
|
||||
<!-- 当需求结束时 隐藏我要参加按钮 -->
|
||||
|
||||
<% if @bid.deadline > Date.today %>
|
||||
|
||||
<table width="1000px" border="0" style="padding-left: 15px">
|
||||
|
@ -18,73 +16,6 @@
|
|||
</td>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<% @bidding_project.each do |b_project|%>
|
||||
<table width="90%" border="0" align='center'>
|
||||
<tr>
|
||||
<td>
|
||||
<table width="660px" border="0" align='center'>
|
||||
<tr>
|
||||
<td width="50px" valign="top" colspan="2" align="middle">
|
||||
<div style="width: 50px; height: 50px;">
|
||||
<%= link_to image_tag(url_to_avatar(b_project.project), :class => 'avatar3'), :class => "avatar" %>
|
||||
</div></td>
|
||||
<td width="60%" valign="top">
|
||||
<table width="100%" valign="top">
|
||||
<tr>
|
||||
<td colspan="2" valign="top"><strong><%= link_to(b_project.project.name, project_path(b_project.project)) %></strong><a class="font_lighter"><%= l(:label_jion_bidding_homework)%></a></td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td valign="top"><%= b_project.project.description %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"><a class="font_lighter"><%=format_time(b_project.created_at) %></a></td>
|
||||
</tr>
|
||||
</table></td>
|
||||
<td width="30%">
|
||||
<div class="bid-user-message" style="border-left: 1px solid rgb(225, 225, 225); margin-left: 20px; padding-left: 20px;">
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td><%= l(:label_bidding_user_homework) %> : <%= link_to(b_project.user.name, user_path(b_project.user)) %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style=" word-wrap: break-word; word-break: break-all"><%= l(:label_bidding_reason_homewrok) %> : <%= b_project.description %></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div></td>
|
||||
</tr>
|
||||
</table></td>
|
||||
</tr>
|
||||
</table>
|
||||
<% end %>
|
||||
|
||||
|
||||
|
||||
<% else %>
|
||||
<table width="1000px" border="0" style="padding-left: 15px">
|
||||
<td class="font_lighter" style="font-size: 15px;"><%= l(:label_bidding_project) %>(<%= @bidding_project.count%>)</td>
|
||||
|
||||
<% if User.current.logged? %>
|
||||
<td>
|
||||
<div class='icon icon-add'>
|
||||
<%= toggle_link l(:button_bidding), 'put-bid-form' %>
|
||||
</div></td>
|
||||
<% end %>
|
||||
|
||||
</table>
|
||||
|
||||
<% else %>
|
||||
|
||||
<div id='bid-over' class="font_lighter" style="font-size: 18px;" align="center">
|
||||
<%= l(:label_bid_end)%>
|
||||
<div class="user_underline"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<% end %>
|
||||
|
||||
|
||||
<!-- 应标项目列表 -->
|
||||
<%= render :partial=> "list_projects",:locals => {:bidding_project => @bidding_project,:bid => @bid }%>
|
||||
|
||||
|
|
|
@ -3,7 +3,16 @@ $('#reward_result_<%= @biding_project_id %>').html('<%= j(
|
|||
if get_prize(@b_p).nil? or get_prize(@b_p) == ""
|
||||
puts '未评奖'
|
||||
else
|
||||
get_prize(@b_p)
|
||||
case get_prize(@b_p)
|
||||
when '0'
|
||||
'一等奖'
|
||||
when '1'
|
||||
'二等奖'
|
||||
when '2'
|
||||
'入围奖'
|
||||
else
|
||||
'未评奖'
|
||||
end
|
||||
end
|
||||
|
||||
)
|
||||
|
|
|
@ -1,41 +1,84 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
// $(this).ready(function(){
|
||||
// $('.tag_show').hover(function() {
|
||||
// $(this).children("span").show();
|
||||
// }, function() {
|
||||
// $(this).children("span").hide();
|
||||
// });
|
||||
})
|
||||
</script>
|
||||
<!-- 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求-->
|
||||
<% @tags = obj.reload.tag_list %>
|
||||
|
||||
<% if non_list_all and (@tags.size > 0) %>
|
||||
<!-- 这里是显示的非主页的tag 所以当tag数量较多时 不必全部显示 用“更多”代替 -->
|
||||
<% if @tags.size > Setting.show_tags_length.to_i then %>
|
||||
<% i = 0 %>
|
||||
<% if @tags.size > Setting.show_tags_length.to_i then %>
|
||||
<% i = 0 %>
|
||||
|
||||
<% until i>Setting.show_tags_length.to_i do %>
|
||||
<div id="tag">
|
||||
<% until i>Setting.show_tags_length.to_i do %>
|
||||
<div id="tag">
|
||||
<%= link_to @tags[i], :controller => "tags",:action => "index",:q => @tags[i],:object_flag => object_flag,:obj_id => obj.id %>
|
||||
</div>
|
||||
<% i += 1%>
|
||||
<% end %>
|
||||
</div>
|
||||
<% i += 1%>
|
||||
<% end %>
|
||||
|
||||
<%= link_to l(:label_more_tags),:action => "show",:id => obj.id %>
|
||||
<%= link_to l(:label_more_tags),:action => "show",:id => obj.id %>
|
||||
|
||||
<% else %>
|
||||
<% else %>
|
||||
|
||||
<% @tags.each do |tag| %>
|
||||
<div id="tag">
|
||||
<% @tags.each do |tag| %>
|
||||
<div id="tag">
|
||||
<%= link_to tag,:controller => "tags",:action => "index",:q=>tag,:object_flag => object_flag,:obj_id => obj.id %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% else %>
|
||||
<!-- 用来显示三大对象的主页中的tag 故是全部显示 -->
|
||||
<% if @tags.size > 0 %>
|
||||
<% @tags.each do |tag| %>
|
||||
<div id="tag">
|
||||
<%= link_to tag,:controller => "tags",:action => "index",:q=>tag ,:object_flag => object_flag,:obj_id => obj.id %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div style="color:#919294;"><%= l(:label_tags_no) %></div>
|
||||
<% if @tags.size > 0 %>
|
||||
<% @tags.each do |tag| %>
|
||||
<div id="tag">
|
||||
<span class="tag_show"> <%= link_to tag,:controller => "tags",:action => "index",:q=>tag ,:object_flag => object_flag,:obj_id => obj.id %>
|
||||
<!-- 对用户主页 是本人 ,对项目,需求,问题是管理员 -->
|
||||
<% case object_flag %>
|
||||
<% when '1'%>
|
||||
|
||||
<% if User.current.eql?(obj) %>
|
||||
<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 %>
|
||||
|
||||
<% when '2' %>
|
||||
|
||||
<% if (ProjectInfo.find_by_project_id(obj.id)).user_id == User.current.id %>
|
||||
<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 %>
|
||||
|
||||
<% when '3' %>
|
||||
|
||||
<% if (ProjectInfo.find_by_project_id(obj.project_id)).user_id == User.current.id %>
|
||||
<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 %>
|
||||
|
||||
<% when '4'%>
|
||||
<% if obj.author_id == User.current.id %>
|
||||
|
||||
<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>
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div style="color:#919294;">
|
||||
<%= l(:label_tags_no) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
|
@ -1,14 +1,16 @@
|
|||
|
||||
|
||||
<% if @obj_flag == '3'%>
|
||||
|
||||
$('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_name',
|
||||
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');
|
||||
$('#put-tag-form-issue').hide();
|
||||
$('#name-issue').val("");
|
||||
|
||||
<% else %>
|
||||
|
||||
$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name',
|
||||
:locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>');
|
||||
$('#put-tag-form').hide();
|
||||
$('#name').val("");
|
||||
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -1515,7 +1515,8 @@ zh:
|
|||
label_course_homework_new: 发布作业
|
||||
label_course_data: 资料
|
||||
label_homework_statistics: 作业统计
|
||||
# added by william
|
||||
|
||||
# added by william 无english版本
|
||||
label_bidding_results: 应标结果
|
||||
label_bid_end: 该需求已经结束!
|
||||
label_special_reward: 特等奖
|
||||
|
@ -1523,4 +1524,4 @@ zh:
|
|||
label_second_reward: 二等奖
|
||||
label_third_reward: 三等奖
|
||||
label_excellence_reward: 优秀奖
|
||||
label_comfort_reward: 入围
|
||||
label_comfort_reward: 入围奖
|
||||
|
|
|
@ -475,6 +475,7 @@ RedmineApp::Application.routes.draw do
|
|||
match 'parise_tread/praise_plus',:to => 'parise_tread#praise_plus',:as=>"praise"
|
||||
match 'parise_tread/tread_plus',:to => 'parise_tread#tread_plus',:as=>"tread"
|
||||
match 'tags/delete',:to=>'tags#delete'
|
||||
match 'tags/remove_tag',:to=>'tags#remove_tag',:as=>"remove_tag"
|
||||
|
||||
match 'words/add_brief_introdution', :controller => 'words', :action => 'add_brief_introdution'
|
||||
end
|
||||
|
|
11
db/schema.rb
11
db/schema.rb
|
@ -11,11 +11,8 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
<<<<<<< .mine
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130922123849) do
|
||||
=======
|
||||
ActiveRecord::Schema.define(:version => 20130918004629) do
|
||||
>>>>>>> .theirs
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -73,11 +70,9 @@ ActiveRecord::Schema.define(:version => 20130918004629) do
|
|||
t.string "description"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
<<<<<<< .mine
|
||||
|
||||
t.string "reward"
|
||||
=======
|
||||
t.integer "reward"
|
||||
>>>>>>> .theirs
|
||||
|
||||
end
|
||||
|
||||
create_table "bids", :force => true do |t|
|
||||
|
|
|
@ -11,5 +11,6 @@ module ActsAsTaggableOn
|
|||
yield tag, classes[index.nan? ? 0 : index.round]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -593,3 +593,4 @@ function blockEventPropagation(event) {
|
|||
$(document).ready(setupAjaxIndicator);
|
||||
$(document).ready(hideOnLoad);
|
||||
$(document).ready(addFormObserversForDoubleSubmit);
|
||||
|
||||
|
|
|
@ -330,6 +330,7 @@ ul.tool li{list-style-type:none;
|
|||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
}
|
||||
|
||||
.tool{
|
||||
|
|
Loading…
Reference in New Issue