Module: Tramway::Admin::RecordsHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/tramway/admin/records_helper.rb
Instance Method Summary collapse
- #active_tab(tab, index) ⇒ Object
- #admin_index_path_of_model(model_class, tab, filter) ⇒ Object
- #build_options_for_select(name, collection) ⇒ Object
- #collection_human_name(model_name:, collection_name:) ⇒ Object
-
#current_model_record_path(*args, **options) ⇒ Object
FIXME: replace to module.
- #current_model_records_path(*args, **options) ⇒ Object
- #decorator_class(model_name = nil) ⇒ Object
- #edit_current_model_record_path(*args, **options) ⇒ Object
- #get_collection ⇒ Object
- #is_there_any_filters?(model_class) ⇒ Boolean
- #model_class ⇒ Object
- #new_associated_record_path(object:, association:, as:) ⇒ Object
- #new_current_model_record_path(*args, **options) ⇒ Object
- #public_path(record) ⇒ Object
- #search_tab_title(count) ⇒ Object
- #searchable_model?(model_class) ⇒ Boolean
- #tab_title(model_class, tab, count, _state_method = :state) ⇒ Object
- #to_path(constant) ⇒ Object
Instance Method Details
#active_tab(tab, index) ⇒ Object
77 78 79 80 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 77 def active_tab(tab, index) return :active if params[:scope].nil? && index == 0 return :active if params[:search].nil? && params[:scope].to_s == tab.to_s end |
#admin_index_path_of_model(model_class, tab, filter) ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 55 def admin_index_path_of_model(model_class, tab, filter) if tab records_path model: model_class, filter: filter, scope: tab else records_path model: model_class, filter: filter end end |
#build_options_for_select(name, collection) ⇒ Object
50 51 52 53 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 50 def (name, collection) selected_value = params[:list_filters].present? ? params[:list_filters][name] : nil (collection, selected_value) end |
#collection_human_name(model_name:, collection_name:) ⇒ Object
63 64 65 66 67 68 69 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 63 def collection_human_name(model_name:, collection_name:) if t("default.collections.#{collection_name}").include?('<span') t("collections.#{model_name}.#{collection_name}").pluralize(:ru) else t("default.collections.#{collection_name}") end end |
#current_model_record_path(*args, **options) ⇒ Object
FIXME: replace to module
6 7 8 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 6 def current_model_record_path(*args, **) record_path args, .merge(model: params[:model]) end |
#current_model_records_path(*args, **options) ⇒ Object
18 19 20 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 18 def current_model_records_path(*args, **) records_path args, .merge(model: params[:model]) end |
#decorator_class(model_name = nil) ⇒ Object
30 31 32 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 30 def decorator_class(model_name = nil) "#{model_name || model_class}Decorator".constantize end |
#edit_current_model_record_path(*args, **options) ⇒ Object
10 11 12 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 10 def edit_current_model_record_path(*args, **) edit_record_path args, .merge(model: params[:model]) end |
#get_collection ⇒ Object
34 35 36 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 34 def get_collection decorator_class.collections end |
#is_there_any_filters?(model_class) ⇒ Boolean
103 104 105 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 103 def is_there_any_filters?(model_class) decorator_class(model_class).list_filters&.any? end |
#model_class ⇒ Object
26 27 28 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 26 def model_class params[:model].constantize end |
#new_associated_record_path(object:, association:, as:) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 82 def new_associated_record_path(object:, association:, as:) unless association.[:class_name].present? raise "You should set `class_name` for #{association.name} association" end if association.[:as].present? # polymorphic? conditiion new_record_path model: association.class_name, redirect: current_model_record_path(object.model), association.[:class_name].underscore => { association.[:as] => object.id, association.type => object.class.model_name } else new_record_path model: association.class_name, redirect: current_model_record_path(object.model), association.[:class_name].underscore => { as || object.model.class.name.underscore => object.id } end end |
#new_current_model_record_path(*args, **options) ⇒ Object
14 15 16 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 14 def new_current_model_record_path(*args, **) new_record_path args, .merge(model: params[:model]) end |
#public_path(record) ⇒ Object
22 23 24 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 22 def public_path(record) record.public_path || try("#{record.class.name.underscore.gsub('/', '_')}_path", record) end |
#search_tab_title(count) ⇒ Object
42 43 44 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 42 def search_tab_title(count) "#{t('helpers.scope.found')} / #{count}" end |
#searchable_model?(model_class) ⇒ Boolean
46 47 48 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 46 def searchable_model?(model_class) model_class.methods.include? :full_text_search end |
#tab_title(model_class, tab, count, _state_method = :state) ⇒ Object
71 72 73 74 75 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 71 def tab_title(model_class, tab, count, _state_method = :state) model = model_class.name.underscore name = collection_human_name model_name: model, collection_name: tab "#{name} / #{count}" end |
#to_path(constant) ⇒ Object
38 39 40 |
# File 'app/helpers/tramway/admin/records_helper.rb', line 38 def to_path(constant) constant.name.underscore.gsub '/', '_' end |