From 0f37b5280a546f8cfb761ae62faf64f25d049ce0 Mon Sep 17 00:00:00 2001 From: Vasiliev Nikita Date: Thu, 7 Jun 2012 20:49:23 +0400 Subject: [PATCH] add new filter option and delete view patch Global changes for issue range plugin. Delete view patch for compatibility with new redmine versions. --- app/views/queries/_filters.html.erb | 53 -------------- config/locales/en.yml | 1 - config/locales/ru.yml | 1 - init.rb | 14 ++-- lib/issue_query_patch.rb | 110 +++++++++++----------------- 5 files changed, 51 insertions(+), 128 deletions(-) delete mode 100644 app/views/queries/_filters.html.erb diff --git a/app/views/queries/_filters.html.erb b/app/views/queries/_filters.html.erb deleted file mode 100644 index 3096c4c..0000000 --- a/app/views/queries/_filters.html.erb +++ /dev/null @@ -1,53 +0,0 @@ - - - - - -
- -<% query.available_filters.sort{|a,b| a[1][:order]<=>b[1][:order]}.each do |filter| %> - <% field = filter[0] - options = filter[1] %> - id="tr_<%= field %>" class="filter"> - - - - -<% end %> -
- <%= check_box_tag 'f[]', field, query.has_filter?(field), :onclick => "toggle_filter('#{field}');", :id => "cb_#{field}" %> - - - <%= label_tag "operators_#{field}", l(:description_filter), :class => "hidden-for-sighted" %> - <%= select_tag "op[#{field}]", options_for_select(operators_for_select(options[:type]), - query.operator_for(field)), :id => "operators_#{field}", - :onchange => "toggle_operator('#{field}');" %> - - - -
-
-<%= label_tag('add_filter_select', l(:label_filter_add)) %> -<%= select_tag 'add_filter_select', options_for_select([["",""]] + query.available_filters.sort{|a,b| a[1][:order]<=>b[1][:order]}.collect{|field| [ field[1][:name] || l(("field_"+field[0].to_s.gsub(/_id$/, "")).to_sym), field[0]] unless query.has_filter?(field[0])}.compact), - :onchange => "add_filter();", - :name => nil %> -
-<%= hidden_field_tag 'f[]', '' %> -<%= javascript_tag 'Event.observe(window,"load",apply_filters_observer);' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index c4af4e5..06eb319 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,4 @@ en: # query selectors strings - label_issue_list: Issue list field_id: Issue_id diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 228a023..fe3a9e6 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -1,3 +1,2 @@ ru: - label_issue_list: Список задач field_id: Номер задачи \ No newline at end of file diff --git a/init.rb b/init.rb index 8c4058e..ea35d12 100644 --- a/init.rb +++ b/init.rb @@ -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) diff --git a/lib/issue_query_patch.rb b/lib/issue_query_patch.rb index c04d6b1..51e4ac1 100644 --- a/lib/issue_query_patch.rb +++ b/lib/issue_query_patch.rb @@ -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 \ No newline at end of file