# frozen_string_literal: true module Tramway::Admin module 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 get_collection(_model_class) decorator_class.collections 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 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 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 } else new_record_path model: association.class_name, redirect: current_model_record_path(object), association.options[:class_name].underscore => { object.model.class.name.underscore => object.id } end end end end