Advertisement
Guest User

Untitled

a guest
Oct 14th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.50 KB | None | 0 0
  1. require_dependency 'query'
  2.  
  3. module QueryVotePatch
  4.   def can_vote?(context = {})
  5.     context[:project].module_enabled?('issue_voting') and User.current.allowed_to?(:view_votes, context[:project])
  6.   end
  7.  
  8.   def self.included(base) # :nodoc:
  9.     base.extend(ClassMethods)
  10.  
  11. #    base.send(:include, InstanceMethods)
  12.    
  13.     # Same as typing in the class
  14.     base.class_eval do
  15.       unloadable # Send unloadable so it will not be unloaded in development
  16. #      if can_vote?
  17. #      if Project.current.module_enabled?('issue_voting') and User.current._to?(:view_votes, Project.current)
  18.         base.add_available_column(QueryColumn.new(:votes_value, :sortable => "#{Issue.table_name}.votes_value"))
  19. #      end
  20.  
  21. #      alias_method :available_filters_before_question, :available_filters
  22. #      alias_method :available_filters, :question_available_filters
  23.  
  24. #      alias_method :sql_for_field_before_question, :sql_for_field
  25. #      alias_method :sql_for_field, :question_sql_for_field
  26.  
  27.     end
  28.  
  29.   end
  30.  
  31.   module ClassMethods
  32.     unless Query.respond_to?(:available_columns=)
  33.       # Setter for +available_columns+ that isn't provided by the core.
  34.       def available_columns=(v)
  35.         self.available_columns = (v)
  36.       end
  37.     end
  38.    
  39.     unless Query.respond_to?(:add_available_column)
  40.       # Method to add a column to the +available_columns+ that isn't provided by the core.
  41.       def add_available_column(column)
  42.         self.available_columns << (column)
  43.       end
  44.     end
  45.  
  46.   end  
  47. end
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement