# frozen_string_literal: true module Tramway::RecordsHelper # FIXME: replace to module def current_model_record_path(*args, **options) record_path args, options.merge(model: params[:model]) end def edit_current_model_record_path(*args, **options) edit_record_path args, options.merge(model: params[:model]) end def new_current_model_record_path(*args, **options) new_record_path args, options.merge(model: params[:model]) end def current_model_records_path(*args, **options) records_path args, options.merge(model: params[:model]) end def public_path(record) record.public_path || try("#{record.class.name.underscore.gsub('/', '_')}_path", record) end def model_class params[:model].constantize end def decorator_class(model_name = nil) "#{model_name || model_class}Decorator".constantize end def to_path(constant) constant.name.underscore.gsub '/', '_' end def search_tab_title(count) "#{t('helpers.scope.found')} / #{count}" end def searchable_model?(model_class) model_class.methods.include? :full_text_search end def build_options_for_select(name, collection) selected_value = params[:list_filters].present? ? params[:list_filters][name] : nil options_for_select(collection, selected_value) end def 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 def collection_human_name(model_name:, collection_name:) if t("default.collections.#{collection_name}").include?(' { association.options[:as] => object.id, association.type => object.class.model_name } } end def options_for_isomorphic_link(object, association, as) { association.options[:class_name].underscore => { as || object.model.class.name.underscore.gsub('/', '_') => object.id } } end def there_any_filters?(model_class) decorator_class(model_class).list_filters&.any? end end