Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please add these features to ur fork #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

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]
before_filter :authorize, :except => [ :vote ]

unloadable

def vote
find_issue
authorize
Expand Down
24 changes: 24 additions & 0 deletions app/views/issues/_vote_issue.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<tr><td><b>
<% if authorize_for('issues', 'view_votes') || authorize_for('issues', 'view_voter') || (authorize_for('issues', 'vote') && [email protected]_by_user?) %>
<%= l :label_votes %>:</b></td><td>
<% end %>
<% if authorize_for('issues', 'view_votes') %>
<% vv = @issue.votes_value.to_i %>
<%= content_tag('span', vv, :class => (vv > 0 ? 'votes-positive': ( vv < 0 ? 'votes-negative' : ''))) %>
<% end %>
<% @project = @issue.project %>
<% if authorize_for('issues', 'vote') && [email protected]_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') %>
<% end %>
<% if authorize_for('issues', 'view_voter') %>
<% unless @issue.votes.empty? %>
<%= link_to_function( l(:label_viewvoter), 'Effect.toggle("voter_list", "blind");') %>
<% end %>
<div id="voter_list" style="display:none">
<% @issue.votes.sort_by{|v| v.user.name}.each do |vote| -%>
<%= content_tag('span', vote.user.name, :class => (vote.vote ? 'votes-positive' : 'votes-negative')) %><br />
<% end -%>
</div>
<% end %>
</td></tr>
8 changes: 4 additions & 4 deletions assets/stylesheets/stylesheet.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.icon-vote-up { background-image: url(../images/arrow_090.png); text-decoration: none !important; }
.icon-vote-down { background-image: url(../images/arrow_270.png); text-decoration: none !important; }
span.votes-positive { color: green; font-weight: bold }
span.votes-negative { color: red; font-weight: bold }
.icon-vote-up { background-image: url(../images/arrow_090.png); text-decoration: none !important; }
.icon-vote-down { background-image: url(../images/arrow_270.png); text-decoration: none !important; }
span.votes-positive { color: green; font-weight: bold }
span.votes-negative { color: red; font-weight: bold }
10 changes: 10 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
de:
button_vote_up: hoch
button_vote_down: runter
label_votes: Abstimmung
field_votes_value: Abstimmung
permission_vote_issue : für ein Ticket abstimmen
permission_view_votes : Stimmenzahl ansehen
permission_view_voter : Liste der Abstimmenden ansehen
project_module_issue_voting : Ticketabstimmung
label_viewvoter: Liste der Abstimmenden
7 changes: 6 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ en:
button_vote_up: up
button_vote_down: down
label_votes: Votes
field_votes_value: Votes
field_votes_value: Votes
permission_vote_issue : vote issue
permission_view_votes : view votes
permission_view_voter : view voter list
project_module_issue_voting : issue voting
label_viewvoter: view voter
10 changes: 6 additions & 4 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
Redmine::Plugin.register :redmine_vote do
name 'Redmine Vote plugin'
author 'Andrew Chaika'
description 'This is a plugin for Redmine'
version '0.0.2'
project_module :issue_tracking do
permission :issues_vote, {:issues => :vote}, :require => :loggedin
description 'Issue Vote Plugin'
version '0.0.3'
project_module :issue_voting do
permission :vote_issue, {:issues => :vote}, :require => :loggedin
permission :view_votes, {:issues => :view_votes}, :require => :loggedin
permission :view_voter, {:issues => :view_voter}, :require => :loggedin
end
end

Expand Down
6 changes: 5 additions & 1 deletion lib/acts_as_voteable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ def find_votes_cast_by_user(user=User.current)
# This module contains instance methods
module InstanceMethods
def vote( vote=:up, user=User.current )
# comment next line to enable user to vote many times
return if voted_by_user? user
Vote.create( :voteable => self, :vote => vote == :up, :user => user )
self.votes_value += vote == :up ? 1:-1;
# uncomment next line to enable user to vote many times
# self.votes_value += (vote == :up ? 1:-1)
# comment next line to enable user to vote many times
self.votes_value += vote == :up ? 1:-1;
end
def votes_for
self.votes.select{|v| v.vote}.size
Expand Down
29 changes: 10 additions & 19 deletions lib/issues_vote_hook.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
# Provides a link to the issue age graph on the issue index page
class IssuesVoteHook < Redmine::Hook::ViewListener
render_on :view_issues_show_details_bottom, :inline => <<-END
<tr><td><b><%= l :label_votes %>:</b></td><td>
<% vv = @issue.votes_value %>
<%= content_tag('span', vv, :class => (vv > 0? 'votes-positive': ( vv < 0 ? 'votes-negative' : ''))) %>
<% @project = @issue.project %>
<% if authorize_for('issues', 'vote') && [email protected]_by_user? %>
<%= link_to('&nbsp;', {:controller => 'issues', :action => 'vote', :id => @issue, :vote => :up}, :class => 'icon icon-vote-up') %>
<%= link_to('&nbsp;', {:controller => 'issues', :action => 'vote', :id => @issue, :vote => :down}, :class => 'icon icon-vote-down') %>
<% end %>
<% unless @issue.votes.empty? %>(<%= link_to_function('View', 'Effect.toggle("voter_list", "blind");') %>)<% end %>
<div id="voter_list" style="display:none">
<% @issue.votes.sort_by{|v| v.user.name}.each do |vote| -%>
<%= content_tag('span', vote.user.name, :class => (vote.vote ? 'votes-positive' : 'votes-negative')) %><br />
<% end -%>
</div>
</td></tr>
END
end
render_on :view_issues_show_details_bottom, :partial => "vote_issue", :if => :can_vote?

private

def can_vote?(context = {})
context[:project].module_enabled?('issue_voting') and User.current.allowed_to?(:vote_issue, context[:project])
end

end

49 changes: 44 additions & 5 deletions lib/query_vote_patch.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
require_dependency 'query'

module QueryVotePatch
def self.included(base)
base.class_eval <<-END
@@available_columns += [QueryColumn.new(:votes_value, :sortable => "#{Issue.table_name}.votes_value")]
END
def can_vote?(context = {})
context[:project].module_enabled?('issue_voting') and User.current.allowed_to?(:view_votes, context[:project])
end
end

def self.included(base) # :nodoc:
base.extend(ClassMethods)

# base.send(:include, InstanceMethods)

# Same as typing in the class
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
# if can_vote?
# if Project.current.module_enabled?('issue_voting') and User.current._to?(:view_votes, Project.current)
base.add_available_column(QueryColumn.new(:votes_value, :sortable => "#{Issue.table_name}.votes_value"))
# end

# alias_method :available_filters_before_question, :available_filters
# alias_method :available_filters, :question_available_filters

# alias_method :sql_for_field_before_question, :sql_for_field
# alias_method :sql_for_field, :question_sql_for_field

end

end

module ClassMethods
unless Query.respond_to?(:available_columns=)
# Setter for +available_columns+ that isn't provided by the core.
def available_columns=(v)
self.available_columns = (v)
end
end

unless Query.respond_to?(:add_available_column)
# Method to add a column to the +available_columns+ that isn't provided by the core.
def add_available_column(column)
self.available_columns << (column)
end
end

end
end