Skip to content

Commit

Permalink
add new filter option and delete view patch
Browse files Browse the repository at this point in the history
Global changes for issue range plugin.  Delete view patch for
compatibility with new redmine versions.
  • Loading branch information
sharpyfox committed Jun 7, 2012
1 parent fbfe21e commit 0f37b52
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 128 deletions.
53 changes: 0 additions & 53 deletions app/views/queries/_filters.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
en:
# query selectors strings
label_issue_list: Issue list
field_id: Issue_id

1 change: 0 additions & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
ru:
label_issue_list: Список задач
field_id: Номер задачи
14 changes: 7 additions & 7 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

unless Redmine::Plugin.registered_plugins.keys.include?(:redmine_issue_query_operators)
Redmine::Plugin.register :redmine_issue_query_operators do
name 'Issue query operators plugin'
author 'Nikita Vasiliev'
author_url 'mailto:sharpyfox@gmail.com'
description 'Issue query operators plugin for Redmine'
version '0.0.1'
requires_redmine :version_or_higher => '1.3.0'
name 'Issue query operators plugin'
author 'Nikita Vasiliev'
author_url 'mailto:sharpyfox@gmail.com'
description 'Redmine plugin which add filter by issues id'
version '0.0.2'
requires_redmine :version_or_higher => '1.3.0'
end
end

Dispatcher.to_prepare :redmine_issue_query_operators do
require_dependency 'query'
require_dependency 'query'

unless Query.included_modules.include? IssueQuery::Patches::QueryModelPatch
Query.send(:include, IssueQuery::Patches::QueryModelPatch)
Expand Down
110 changes: 44 additions & 66 deletions lib/issue_query_patch.rb
Original file line number Diff line number Diff line change
@@ -1,69 +1,47 @@
module IssueQuery
module Patches
module QueryModelPatch
def self.included(base) # :nodoc:
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
module IssueQuery
module Patches
module QueryModelPatch
def self.included(base) # :nodoc:
base.extend(ClassMethods)
base.send(:include, InstanceMethods)

base.class_eval do
alias_method_chain :sql_for_field, :issue_range
alias_method_chain :available_filters, :issue_range

class << self
alias_method_chain :operators_by_filter_type, :issue_range
alias_method_chain :operators, :issue_range
end
end
end

module ClassMethods
def operators_with_issue_range
o=operators_without_issue_range
if o[":"].blank?
o[":"]=:label_issue_list
end
o # return
end

def operators_by_filter_type_with_issue_range
o = operators_by_filter_type_without_issue_range
#unless o[:list_issue].include?(":")
o[:list_issue] = ":"
#end
o # return
end
end
base.class_eval do
alias_method_chain :available_filters, :issue_range
end
end

module InstanceMethods
def available_filters_with_issue_range
f = available_filters_without_issue_range
f["id"] = { :type => :list_issue, :order => 15 }
f # return
end

def get_issue_range_from_string(issue_str)
format_issue = issue_str.to_s.gsub(/\s+/, '')
issue_str.split(",") # return
end

def sql_for_field_with_issue_range(field, operator, value, db_table, db_field, is_custom_filter=false)
sql=case operator
when ":"
case type_for(field)
when :list_issue
value = get_issue_range_from_string(value.first.strip)
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
else
# IN an empty set
sql = "1=0"
module ClassMethods
#dummy
end
else
sql_for_field_without_issue_range(field, operator, value, db_table, db_field, is_custom_filter)
end
sql
end
end
end

end
end

module InstanceMethods
def available_filters_with_issue_range
f = available_filters_without_issue_range
f["id"] = { :type => :text, :order => 15 }
f # return
end

def get_issue_range_from_string(issue_str)
format_issue = issue_str.to_s.gsub(/\s+/, '')
issue_str.split(",") # return
end

def sql_for_id_field(field, operator, value)
case operator
when ":", "~"
value = get_issue_range_from_string(value.first.strip)
sql = "#{Issue.table_name}.id IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
when "!~"
value = get_issue_range_from_string(value.first.strip)
sql = "#{Issue.table_name}.id NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
else
# IN an empty set
sql = "1=0"
end

sql #return
end
end
end #module QueryModelPatch
end #module Patches
end

0 comments on commit 0f37b52

Please sign in to comment.