What is the intented way for custom operators and custom operators_by_filter_type

Added by Angelinsky7 Angelinsky7 over 1 year ago

i would like to know what is the correct way of adding a custom operator and operator filter to a field in redmine.
i understand that you can add operator this way :

def initialize_available_filters_with_myplugin
 if operators["sbl"].blank?

  operators_by_filter_type[:list_my_plugin_optional] = operators_by_filter_type[:list_optional] + ["sbl","sl"]

 add_available_filter 'my_field_plugin_id', :type => :list_my_plugin_optional, :values => my_other_fields.sort.collect{|s| [s.name, s.id.to_s]}
alias_method :initialize_available_filters_without_myplugin, :initialize_available_filters
alias_method :initialize_available_filters, :initialize_available_filters_with_myplugin

and extending the sql_for_field like this

def sql_for_field_with_myplugin(field, operator, value, db_table, db_field, is_custom_filter=false)
          logger.error "before: #{field}, #{operator}, #{value}, #{db_table}, #{db_field}, #{is_custom_filter}" 

          sql=case operator
            when "sbl" 
              # generate sql here
            when "sl" 
              # generate sql here
              sql_for_field_without_scrum(field, operator, value, db_table, db_field, is_custom_filter)
        alias_method :sql_for_field_without_myplugin, :sql_for_field
        alias_method :sql_for_field, :sql_for_field_with_myplugin

and everything is working fine IF is don't create a new operators_by_filter_type (like here) but extends an existing one (like 'list_optional')
because of those line in application.js (in buildFilterRow line 156 and toggleOperator line 266)

switch (filterOptions['type']) {
  case "list":
  case "list_optional":
  case "list_status":
  case "list_subprojects":
  ... follow a long list of type without any way to extend it


switch (operator.val()) {
    case "!*":
    case "*":
    case "t":
    case "ld":
    case "w":
    case "lw":
    case "l2w":
    case "m":
    case "lm":
    case "y":
    case "o":
    case "c":
    case "*o":
    case "!o":
      enableValues(field, []);
    ... follow a long list of operator without any way to extend it

my new type of filter obviously don't exist and my new type of filter neither.
How could i add them to the list and how could i make my new filter and filter operator work correctly (without patching by hand the application.js file)

Thanks to anyone that could help me !!!