Sha256: fcae96a859e2f10ca5db2f6f129cdb4b7fe2a30ba4ee289ec38e4e70363a1d8f

Contents?: true

Size: 1.96 KB

Versions: 28

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

class Avo::Views::ResourceShowComponent < Avo::ResourceComponent
  include Avo::ApplicationHelper

  attr_reader :display_breadcrumbs

  prop :resource
  prop :reflection
  prop :parent_resource
  prop :parent_record
  prop :resource_panel, reader: :public
  prop :actions, default: [].freeze, reader: :public

  def after_initialize
    @view = Avo::ViewInquirer.new("show")
    @display_breadcrumbs = @reflection.blank?
  end

  def title
    if @reflection.present?
      return field.name if has_one_field?

      reflection_resource.name
    else
      @resource.default_panel_name
    end
  end

  def back_path
    # The `return_to` param takes precedence over anything else.
    return params[:return_to] if params[:return_to].present?

    if via_resource?
      helpers.resource_path(resource: association_resource, resource_id: params[:via_record_id])
    else
      helpers.resources_path(resource: @resource, **keep_referrer_params)
    end
  end

  def edit_path
    args = if via_resource?
      {
        via_resource_class: params[:via_resource_class],
        via_record_id: params[:via_record_id]
      }
    elsif @parent_resource.present?
      {
        via_resource_class: @parent_resource.class,
        via_record_id: @parent_record.to_param
      }
    else
      {}
    end

    # Pass the return_to param to the edit path so the chain of navigation is kept.
    args[:return_to] = params[:return_to] if params[:return_to].present?

    helpers.edit_resource_path(record: @resource.record, resource: @resource, **args)
  end

  def controls
    @resource.render_show_controls
  end

  def view_for(field)
    @view
  end

  private

  # In development and test environments we should show the invalid field errors
  def should_display_invalid_fields_errors?
    (Rails.env.development? || Rails.env.test?) && @resource.invalid_fields.present?
  end

  def has_one_field?
    field.present? and field.instance_of? Avo::Fields::HasOneField
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
avo-3.18.1.tw4 app/components/avo/views/resource_show_component.rb
avo-3.18.1 app/components/avo/views/resource_show_component.rb
avo-3.18.0.tw4 app/components/avo/views/resource_show_component.rb
avo-3.18.0 app/components/avo/views/resource_show_component.rb
avo-3.17.9.beta2 app/components/avo/views/resource_show_component.rb
avo-3.17.9.beta1 app/components/avo/views/resource_show_component.rb
avo-3.17.9.tw4 app/components/avo/views/resource_show_component.rb
avo-3.17.9 app/components/avo/views/resource_show_component.rb
avo-3.17.8.tw4 app/components/avo/views/resource_show_component.rb
avo-3.17.8 app/components/avo/views/resource_show_component.rb
avo-3.17.7 app/components/avo/views/resource_show_component.rb
avo-3.17.6.tw4 app/components/avo/views/resource_show_component.rb
avo-3.17.6 app/components/avo/views/resource_show_component.rb
avo-3.17.5 app/components/avo/views/resource_show_component.rb
avo-3.17.4 app/components/avo/views/resource_show_component.rb
avo-3.17.3 app/components/avo/views/resource_show_component.rb
avo-3.17.5.tw4 app/components/avo/views/resource_show_component.rb
avo-3.17.4.tw4 app/components/avo/views/resource_show_component.rb
avo-3.17.3.tw4 app/components/avo/views/resource_show_component.rb
avo-3.17.2.tw4 app/components/avo/views/resource_show_component.rb