Module: RailsAdmin::MainHelper
- Included in:
- MainController
- Defined in:
- app/helpers/rails_admin/main_helper.rb
Instance Method Summary collapse
- #filterable_fields ⇒ Object
- #get_column_sets(properties) ⇒ Object
- #get_indicator(percent) ⇒ Object
- #ordered_filter_options ⇒ Object
- #ordered_filters ⇒ Object
- #rails_admin_form_for(*args, &block) ⇒ Object
Instance Method Details
#filterable_fields ⇒ Object
39 40 41 |
# File 'app/helpers/rails_admin/main_helper.rb', line 39 def filterable_fields @filterable_fields ||= @model_config.list.fields.select(&:filterable?) end |
#get_column_sets(properties) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/rails_admin/main_helper.rb', line 20 def get_column_sets(properties) sets = [] property_index = 0 set_index = 0 while property_index < properties.length current_set_width = 0 loop do sets[set_index] ||= [] sets[set_index] << properties[property_index] current_set_width += (properties[property_index].column_width || 120) property_index += 1 break if current_set_width >= RailsAdmin::Config.total_columns_width || property_index >= properties.length end set_index += 1 end sets end |
#get_indicator(percent) ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/helpers/rails_admin/main_helper.rb', line 12 def get_indicator(percent) return '' if percent < 0 # none return 'info' if percent < 34 # < 1/100 of max return 'success' if percent < 67 # < 1/10 of max return 'warning' if percent < 84 # < 1/3 of max 'danger' # > 1/3 of max end |
#ordered_filter_options ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/rails_admin/main_helper.rb', line 59 def @ordered_filter_options ||= ordered_filters.map do |duplet| = {index: duplet[0]} filter_for_field = duplet[1] filter_name = filter_for_field.keys.first filter_hash = filter_for_field.values.first unless (field = filterable_fields.find { |f| f.name == filter_name.to_sym }) raise "#{filter_name} is not currently filterable; filterable fields are #{filterable_fields.map(&:name).join(', ')}" end case field.type when :enum [:select_options] = (field.with(object: @abstract_model.model.new).enum, filter_hash['v']) when :date, :datetime, :time [:datetimepicker_format] = field.parser.to_momentjs end [:label] = field.label [:name] = field.name [:type] = field.type [:value] = filter_hash['v'] [:label] = field.label [:operator] = filter_hash['o'] || field.default_filter_operator [:required] = field.required end if ordered_filters end |
#ordered_filters ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/rails_admin/main_helper.rb', line 43 def ordered_filters return @ordered_filters if @ordered_filters.present? @index = 0 @ordered_filters = (params[:f].try(:permit!).try(:to_h) || @model_config.list.filters).inject({}) do |memo, filter| field_name = filter.is_a?(Array) ? filter.first : filter (filter.is_a?(Array) ? filter.last : {(@index += 1) => {'v' => ''}}).each do |index, filter_hash| if filter_hash['disabled'].blank? memo[index] = {field_name => filter_hash} else params[:f].delete(field_name) end end memo end.to_a.sort_by(&:first) end |
#rails_admin_form_for(*args, &block) ⇒ Object
5 6 7 8 9 10 |
# File 'app/helpers/rails_admin/main_helper.rb', line 5 def rails_admin_form_for(*args, &block) = args..reverse_merge(builder: RailsAdmin::FormBuilder) ([:html] ||= {})[:novalidate] ||= !RailsAdmin::Config.browser_validations form_for(*(args << ), &block) << after_nested_form_callbacks end |