Module: RailsAdmin::MainHelper
- Included in:
- MainController
- Defined in:
- app/helpers/rails_admin/main_helper.rb
Instance Method Summary collapse
- #filterable_fields ⇒ 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
21 22 23 |
# File 'app/helpers/rails_admin/main_helper.rb', line 21 def filterable_fields @filterable_fields ||= @model_config.list.fields.select(&:filterable?) end |
#get_indicator(percent) ⇒ Object
12 13 14 15 16 17 18 19 |
# 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/rails_admin/main_helper.rb', line 42 def if ordered_filters @ordered_filter_options ||= ordered_filters.map do |duplet| 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 }&.with({view: self})) raise "#{filter_name} is not currently filterable; filterable fields are #{filterable_fields.map(&:name).join(', ')}" end field..merge( index: duplet[0], operator: filter_hash['o'] || field.default_filter_operator, value: filter_hash['v'], ) end end end |
#ordered_filters ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/rails_admin/main_helper.rb', line 25 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 |