From 2079c8736272288d513c8add8821d1df029096e4 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 27 Sep 2013 14:58:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0tag=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/tags_controller.rb | 69 +++++++++++-- app/helpers/bids_helper.rb | 1 - app/helpers/projects_helper.rb | 12 ++- app/helpers/tags_helper.rb | 43 ++++++++ app/helpers/users_helper.rb | 1 + app/views/account/register.html.erb | 5 +- app/views/bids/_list_projects.html.erb | 15 ++- app/views/bids/_project_list.html.erb | 69 ------------- app/views/bids/set_reward.js.erb | 11 ++- app/views/tags/_tag_name.html.erb | 97 +++++++++++++------ app/views/users/tag_save.js.erb | 6 +- config/locales/zh.yml | 5 +- config/routes.rb | 1 + db/schema.rb | 11 +-- .../lib/acts_as_taggable_on/tags_helper.rb | 1 + public/javascripts/application.js | 1 + public/stylesheets/application.css | 1 + 17 files changed, 227 insertions(+), 122 deletions(-) create mode 100644 app/helpers/tags_helper.rb diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index e99d2500c..2b9c9a320 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -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] @@ -83,7 +86,7 @@ class TagsController < ApplicationController @bids_results = refresh_results(@obj_id,@show_flag) end - # 删除已选tag + # 删除已选tag def delete_tag @tag = params[:tag] @show_flag = params[:show_flag] @@ -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]) @@ -112,8 +116,41 @@ class TagsController < ApplicationController @taggings.each do |tagging| tagging.delete end - 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 diff --git a/app/helpers/bids_helper.rb b/app/helpers/bids_helper.rb index e777330c6..6176b0f20 100644 --- a/app/helpers/bids_helper.rb +++ b/app/helpers/bids_helper.rb @@ -2,7 +2,6 @@ # fq module BidsHelper - def render_notes(bid, journal, options={}) content = '' removable = User.current == journal.user || User.current == bid.author diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 1b8340721..661d5c627 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -127,7 +127,7 @@ module ProjectsHelper l("label_version_sharing_#{sharing}") end - # this method is used to get all projects that tagged one tag + # 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') @@ -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 diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb new file mode 100644 index 000000000..fa99b57ad --- /dev/null +++ b/app/helpers/tags_helper.rb @@ -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 \ No newline at end of file diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index c813714d3..88e918256 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -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), ''], diff --git a/app/views/account/register.html.erb b/app/views/account/register.html.erb index ce666940e..f65a891fb 100644 --- a/app/views/account/register.html.erb +++ b/app/views/account/register.html.erb @@ -216,9 +216,8 @@

<%= l(:label_identity) %> * - <%= select_tag 'identity', " - - ".html_safe %>

+ <%= select_tag 'identity', " " + .html_safe %>

diff --git a/app/views/bids/_list_projects.html.erb b/app/views/bids/_list_projects.html.erb index 8974abeaa..7216b60e1 100644 --- a/app/views/bids/_list_projects.html.erb +++ b/app/views/bids/_list_projects.html.erb @@ -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 %> @@ -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,"" + .html_safe %> + + <%= f.submit "提交",:class=>"submit" %> <% end %> diff --git a/app/views/bids/_project_list.html.erb b/app/views/bids/_project_list.html.erb index 23e1b4f24..889a0b0da 100644 --- a/app/views/bids/_project_list.html.erb +++ b/app/views/bids/_project_list.html.erb @@ -1,8 +1,6 @@ <%= render_flash_messages %> - - <% if @bid.deadline > Date.today %>
<%= l(:label_gender) %>
@@ -18,73 +16,6 @@ <% end %>
- -<% @bidding_project.each do |b_project|%> - - - - -
- - - - - - -
-
- <%= link_to image_tag(url_to_avatar(b_project.project), :class => 'avatar3'), :class => "avatar" %> -
- - - - - - - - - - - -
<%= link_to(b_project.project.name, project_path(b_project.project)) %><%= l(:label_jion_bidding_homework)%>
<%= b_project.project.description %>
<%=format_time(b_project.created_at) %>
-
- - - - - - - -
<%= l(:label_bidding_user_homework) %> : <%= link_to(b_project.user.name, user_path(b_project.user)) %>
<%= l(:label_bidding_reason_homewrok) %> : <%= b_project.description %>
-
<% end %> - - - - <% else %> - - - - <% if User.current.logged? %> - - <% end %> - -
<%= l(:label_bidding_project) %>(<%= @bidding_project.count%>) -
- <%= toggle_link l(:button_bidding), 'put-bid-form' %> -
- - <% else %> - -

- <%= l(:label_bid_end)%> -
-
- - -<% end %> - - - <%= render :partial=> "list_projects",:locals => {:bidding_project => @bidding_project,:bid => @bid }%> diff --git a/app/views/bids/set_reward.js.erb b/app/views/bids/set_reward.js.erb index 85989c0fb..1e469eb37 100644 --- a/app/views/bids/set_reward.js.erb +++ b/app/views/bids/set_reward.js.erb @@ -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 ) diff --git a/app/views/tags/_tag_name.html.erb b/app/views/tags/_tag_name.html.erb index 49a81da2a..552246da1 100644 --- a/app/views/tags/_tag_name.html.erb +++ b/app/views/tags/_tag_name.html.erb @@ -1,41 +1,84 @@ - + <% @tags = obj.reload.tag_list %> <% if non_list_all and (@tags.size > 0) %> - <% 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 %> -
- <%= link_to @tags[i], :controller => "tags",:action => "index",:q => @tags[i],:object_flag => object_flag,:obj_id => obj.id %> -
- <% i += 1%> - <% end %> +<% until i>Setting.show_tags_length.to_i do %> +
+ <%= link_to @tags[i], :controller => "tags",:action => "index",:q => @tags[i],:object_flag => object_flag,:obj_id => obj.id %> +
+<% 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| %> -
- <%= link_to tag,:controller => "tags",:action => "index",:q=>tag,:object_flag => object_flag,:obj_id => obj.id %> -
- <% end %> +<% @tags.each do |tag| %> +
+ <%= link_to tag,:controller => "tags",:action => "index",:q=>tag,:object_flag => object_flag,:obj_id => obj.id %> +
+<% end %> - <% end %> +<% end %> <% else %> - <% if @tags.size > 0 %> - <% @tags.each do |tag| %> -
- <%= link_to tag,:controller => "tags",:action => "index",:q=>tag ,:object_flag => object_flag,:obj_id => obj.id %> -
- <% end %> - <% else %> -
<%= l(:label_tags_no) %>
- <% end %> - +<% if @tags.size > 0 %> +<% @tags.each do |tag| %> +
+ <%= 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) %> + <%= link_to 'x',:controller => "tags",:action => "remove_tag",:remote => true,:tag_name => tag, + :taggable_id => obj.id,:taggable_type => object_flag %> + <% end %> + + <% when '2' %> + + <% if (ProjectInfo.find_by_project_id(obj.id)).user_id == User.current.id %> + <%= link_to 'x',:controller => "tags",:action => "remove_tag",:remote => true,:tag_name => tag, + :taggable_id => obj.id,:taggable_type => object_flag %> + <% end %> + + <% when '3' %> + + <% if (ProjectInfo.find_by_project_id(obj.project_id)).user_id == User.current.id %> + <%= link_to 'x',:controller => "tags",:action => "remove_tag",:remote => true,:tag_name => tag, + :taggable_id => obj.id,:taggable_type => object_flag %> + <% end %> + + <% when '4'%> + <% if obj.author_id == User.current.id %> + + <%= link_to 'x',:controller => "tags",:action => "remove_tag",:remote => true,:tag_name => tag, + :taggable_id => obj.id,:taggable_type => object_flag %> + + <% end %> + <% end %> + + +
+<% end %> +<% else %> +
+ <%= l(:label_tags_no) %> +
+<% end %> + <% end %> \ No newline at end of file diff --git a/app/views/users/tag_save.js.erb b/app/views/users/tag_save.js.erb index 6b13f6b41..4dbdc4203 100644 --- a/app/views/users/tag_save.js.erb +++ b/app/views/users/tag_save.js.erb @@ -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 %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 54670a057..2522b0bc7 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -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: 入围奖 diff --git a/config/routes.rb b/config/routes.rb index d3b5c1b43..946d788dc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index ec75c62f4..ad15a092d 100644 --- a/db/schema.rb +++ b/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| diff --git a/lib/plugins/acts-as-taggable-on/lib/acts_as_taggable_on/tags_helper.rb b/lib/plugins/acts-as-taggable-on/lib/acts_as_taggable_on/tags_helper.rb index fbbfd0690..29701ba2f 100644 --- a/lib/plugins/acts-as-taggable-on/lib/acts_as_taggable_on/tags_helper.rb +++ b/lib/plugins/acts-as-taggable-on/lib/acts_as_taggable_on/tags_helper.rb @@ -11,5 +11,6 @@ module ActsAsTaggableOn yield tag, classes[index.nan? ? 0 : index.round] end end + end end \ No newline at end of file diff --git a/public/javascripts/application.js b/public/javascripts/application.js index e843b3ba5..fea17ee12 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -593,3 +593,4 @@ function blockEventPropagation(event) { $(document).ready(setupAjaxIndicator); $(document).ready(hideOnLoad); $(document).ready(addFormObserversForDoubleSubmit); + diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 699bca8e5..65c5a78cc 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -330,6 +330,7 @@ ul.tool li{list-style-type:none; padding-top: 5px; padding-bottom: 5px; padding-left: 12px; + padding-right: 12px; } .tool{