From a6d474f167602ef728711ca08d75c7dce205e186 Mon Sep 17 00:00:00 2001 From: basyura Date: Sun, 22 Jul 2012 16:30:43 +0900 Subject: [PATCH 1/2] for rails3 --- app/controllers/vote_controller.rb | 32 ++++++++++++++++++++++++++++++ config/routes.rb | 7 +++++++ lib/issue_vote_patch.rb | 4 ++-- lib/issues_vote_hook.rb | 6 +++--- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 app/controllers/vote_controller.rb create mode 100644 config/routes.rb diff --git a/app/controllers/vote_controller.rb b/app/controllers/vote_controller.rb new file mode 100644 index 0000000..5e3d77e --- /dev/null +++ b/app/controllers/vote_controller.rb @@ -0,0 +1,32 @@ +require 'redmine' + +class VoteController < IssuesController + + skip_before_filter :authorize, :only => [:up,:down] + + def up + vote(:up) + end + + def down + vote(:down) + end + + private + def vote(type) + find_issue + authorize + @issue.vote(type) + @issue.save + # TODO + reset_invocation_response + redirect_to :controller => 'issues', :action => 'show', :id => @issue + end + + def reset_invocation_response + self.instance_variable_set(:@_response_body, nil) + response.instance_variable_set( + :@header, + Rack::Utils::HeaderHash.new("cookie" => [], 'Content-Type' => 'text/html')) + end +end diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..49e775a --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,7 @@ +# Plugin's routes +# See: http://guides.rubyonrails.org/routing.html + +RedmineApp::Application.routes.draw do + post '/vote/up', :to => 'vote#up' + post '/vote/down', :to => 'vote#down' +end diff --git a/lib/issue_vote_patch.rb b/lib/issue_vote_patch.rb index dcd58f0..7c49ddb 100644 --- a/lib/issue_vote_patch.rb +++ b/lib/issue_vote_patch.rb @@ -1,6 +1,6 @@ -require 'vote' +require File.join(File.dirname(__FILE__), '../app/models/vote') require 'acts_as_voteable' Issue.class_eval do acts_as_voteable -end \ No newline at end of file +end diff --git a/lib/issues_vote_hook.rb b/lib/issues_vote_hook.rb index cb7701c..023db34 100644 --- a/lib/issues_vote_hook.rb +++ b/lib/issues_vote_hook.rb @@ -6,9 +6,9 @@ class IssuesVoteHook < Redmine::Hook::ViewListener <%= content_tag('span', vv, :class => (vv > 0? 'votes-positive': ( vv < 0 ? 'votes-negative' : ''))) %> <% @project = @issue.project %> <% if authorize_for('issues', 'vote') && !@issue.voted_by_user? %> - <%= link_to("", {:controller => 'issues', :action => 'vote', :id => @issue, :vote => :up}, :class => 'icon icon-vote-up') %> - <%= link_to("", {:controller => 'issues', :action => 'vote', :id => @issue, :vote => :down}, :class => 'icon icon-vote-down') %> + <%= link_to("", { :controller => 'vote', :action => 'up', :id => @issue }, :class => 'icon icon-vote-up' , :method => 'post', :confirm => 'up?') %> + <%= link_to("", { :controller => 'vote', :action => 'down', :id => @issue }, :class => 'icon icon-vote-down', :method => 'post', :confirm => 'down?') %> <% end %> END -end \ No newline at end of file +end From bcdbe3769b168f79de18ced507b52f3b65dc1e34 Mon Sep 17 00:00:00 2001 From: basyura Date: Sun, 22 Jul 2012 16:35:05 +0900 Subject: [PATCH 2/2] improved readme --- README.rdoc | 3 ++- app/controllers/issues_controller.rb | 15 --------------- 2 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 app/controllers/issues_controller.rb diff --git a/README.rdoc b/README.rdoc index b664efb..4a3b98a 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,3 +1,4 @@ = vote -Description goes here +vote plugin for redmine which powered by rails3. + diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb deleted file mode 100644 index 1705c25..0000000 --- a/app/controllers/issues_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'redmine' -require_dependency 'issues_controller' - -class IssuesController < ApplicationController - skip_before_filter :authorize, :only => [:vote] - #before_filter :find_issue, :only => [:vote] #[:show, :edit, :reply] - #before_filter :authorize, :only => [:vote] #:except => [:index, :changes, :gantt, :calendar, :preview, :update_form, :context_menu] - def vote - find_issue - authorize - @issue.vote(params[:vote] == "up" ? :up : :down) - @issue.save - redirect_to :controller => 'issues', :action => 'show', :id => @issue - end -end \ No newline at end of file