Class: Redmine::FieldFormat::RecordList

Inherits:
List
  • Object
show all
Defined in:
lib/redmine/field_format.rb

Overview

Since:

  • 2.5.0

Direct Known Subclasses

EnumerationFormat, UserFormat, VersionFormat

Instance Method Summary collapse

Methods inherited from List

#bulk_edit_tag, #edit_tag, #query_filter_options

Methods inherited from Base

#after_save_custom_value, #before_custom_field_save, #bulk_edit_tag, #cast_custom_value, #cast_value, #edit_tag, field_attributes, #formatted_custom_value, #formatted_value, #label, #name, #possible_values_options, #query_filter_options, #set_custom_field_value, #validate_custom_field, #validate_single_value, #value_from_keyword

Methods included from Helpers::URL

#uri_with_safe_scheme?

Methods included from I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Instance Method Details

#cast_single_value(custom_field, value, customized = nil) ⇒ Object



718
719
720
# File 'lib/redmine/field_format.rb', line 718

def cast_single_value(custom_field, value, customized=nil)
  target_class.find_by_id(value.to_i) if value.present?
end

#group_statement(custom_field) ⇒ Object



755
756
757
# File 'lib/redmine/field_format.rb', line 755

def group_statement(custom_field)
  "COALESCE(#{join_alias custom_field}.value, '')"
end

#join_for_order_statement(custom_field) ⇒ Object



759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# File 'lib/redmine/field_format.rb', line 759

def join_for_order_statement(custom_field)
  alias_name = join_alias(custom_field)

  "LEFT OUTER JOIN #{CustomValue.table_name} #{alias_name}" +
    " ON #{alias_name}.customized_type = '#{custom_field.class.customized_class.base_class.name}'" +
    " AND #{alias_name}.customized_id = #{custom_field.class.customized_class.table_name}.id" +
    " AND #{alias_name}.custom_field_id = #{custom_field.id}" +
    " AND (#{custom_field.visibility_by_project_condition})" +
    " AND #{alias_name}.value <> ''" +
    " AND #{alias_name}.id = (SELECT max(#{alias_name}_2.id) FROM #{CustomValue.table_name} #{alias_name}_2" +
      " WHERE #{alias_name}_2.customized_type = #{alias_name}.customized_type" +
      " AND #{alias_name}_2.customized_id = #{alias_name}.customized_id" +
      " AND #{alias_name}_2.custom_field_id = #{alias_name}.custom_field_id)" +
    " LEFT OUTER JOIN #{target_class.table_name} #{value_join_alias custom_field}" +
    " ON CAST(CASE #{alias_name}.value WHEN '' THEN '0' ELSE #{alias_name}.value END AS decimal(30,0)) = #{value_join_alias custom_field}.id"
end

#order_statement(custom_field) ⇒ Object



749
750
751
752
753
# File 'lib/redmine/field_format.rb', line 749

def order_statement(custom_field)
  if target_class.respond_to?(:fields_for_order_statement)
    target_class.fields_for_order_statement(value_join_alias(custom_field))
  end
end

#possible_custom_value_options(custom_value) ⇒ Object



730
731
732
733
734
735
736
737
# File 'lib/redmine/field_format.rb', line 730

def possible_custom_value_options(custom_value)
  options = possible_values_options(custom_value.custom_field, custom_value.customized)
  missing = [custom_value.value_was].flatten.reject(&:blank?) - options.map(&:last)
  if missing.any?
    options += target_class.where(:id => missing.map(&:to_i)).map {|o| [o.to_s, o.id.to_s]}
  end
  options
end

#reset_target_classObject

Since:

  • 2.6.0



726
727
728
# File 'lib/redmine/field_format.rb', line 726

def reset_target_class
  @target_class = nil
end

#target_classObject



722
723
724
# File 'lib/redmine/field_format.rb', line 722

def target_class
  @target_class ||= self.class.name[/^(.*::)?(.+)Format$/, 2].constantize rescue nil
end

#validate_custom_value(custom_value) ⇒ Object

Since:

  • 3.4.7



739
740
741
742
743
744
745
746
747
# File 'lib/redmine/field_format.rb', line 739

def validate_custom_value(custom_value)
  values = Array.wrap(custom_value.value).reject {|value| value.to_s == ''}
  invalid_values = values - possible_custom_value_options(custom_value).map(&:last)
  if invalid_values.any?
    [::I18n.t('activerecord.errors.messages.inclusion')]
  else
    []
  end
end