Files
codeocean/app/views/application/_breadcrumbs_and_title.html.slim
Sebastian Serth 9a9efd5caa Lint Slim files and fix offenses
The fixing was partially done manually and partially automatically.
2024-04-18 08:31:24 +02:00

52 lines
3.0 KiB
Plaintext

- model = controller_path.classify.constantize rescue nil # rubocop:disable Style/RescueModifier
- if model
- object = model.find_by(id: params[:id])
- if (parent_model = model.try(:parent_resource))
- parent_route_key = parent_model.model_name.singular_route_key
- if params["#{parent_route_key}_id"].present?
- parent_object = object.try(parent_route_key) || parent_model.find_by(id: params["#{parent_route_key}_id"])
- parent_element = link_to_if(current_user && policy(parent_object).show?, parent_object, {controller: parent_model.model_name.route_key, action: :show, id: parent_object.id})
- parent_root_element = link_to_if(current_user && policy(parent_model).index?, parent_model.model_name.human(count: 2), {controller: parent_model.model_name.route_key, action: :index})
- root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), send(:"#{parent_route_key}_#{model.model_name.route_key}_path", parent_object))
- if object
- current_element = link_to_if(current_user && policy(object).show?, object, send(:"#{parent_route_key}_#{model.model_name.singular}_path", parent_object, object))
- else
- root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), {controller: model.model_name.route_key, action: :index})
- if object
- current_element = link_to_if(current_user && policy(object).show?, object, {controller: model.model_name.route_key, action: :show, id: object.id})
- else
- root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), {controller: model.model_name.route_key, action: :index})
- if object
- current_element = link_to_if(current_user && policy(object).show?, object, {controller: model.model_name.route_key, action: :show, id: object.id})
- if I18n.exists?("shared.#{params[:action]}")
- active_action = t("shared.#{params[:action]}", model: model&.model_name&.human)
- else
- active_action = t("#{controller_name}.index.#{params[:action]}", model: model&.model_name&.human)
- else
- active_action = t("breadcrumbs.#{controller_name}.#{params[:action]}")
- title = application_name.to_s
- title = "#{active_action} - #{title}" unless %w[index show].include? params[:action]
- content_for :breadcrumbs do
.container.mb-4
ul.breadcrumb.bg-body-secondary.px-3.py-2
- if defined?(parent_root_element) && parent_root_element.present?
li.breadcrumb-item.small
= parent_root_element
li.breadcrumb-item.small
= parent_element
- title = "#{parent_object} - #{title}"
- if root_element.present?
li.breadcrumb-item.small
= root_element
- if current_element.present?
li.breadcrumb-item.small
= current_element
- title = "#{object} - #{title}"
- else
- title = "#{model.model_name.human(count: 2)} - #{title}"
li.breadcrumb-item.active.small
= active_action
- content_for :title, title