Sha256: 8034ed8957b8d495804cf6e6f47de6caacfc8de7168be4ce3a67043151d3e965

Contents?: true

Size: 1.49 KB

Versions: 18

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

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

  def initialize(resource: nil, reflection: nil, parent_resource: nil, parent_record: nil, resource_panel: nil, actions: [])
    @resource = resource
    @reflection = reflection
    @resource_panel = resource_panel
    @actions = actions
    @parent_record = parent_record
    @parent_resource = parent_resource
    @view = Avo::ViewInquirer.new("show")
  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
    if via_resource?
      helpers.resource_path(record: association_resource.model_class, resource: association_resource, resource_id: params[:via_record_id])
    else
      helpers.resources_path(resource: @resource)
    end
  end

  def edit_path
    args = {}

    if via_resource?
      args = {
        via_resource_class: params[:via_resource_class],
        via_record_id: params[:via_record_id]
      }
    end

    helpers.edit_resource_path(record: @resource.record, resource: @resource, **args)
  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

18 entries across 18 versions & 1 rubygems

Version Path
avo-3.0.1.beta23 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta20 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta21 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta17 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta22 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta18 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta19 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta24 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta15 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta16 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta14 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta12 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta13 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta10 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta11 app/components/avo/views/resource_show_component.rb
avo-3.0.0.pre19 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta8 app/components/avo/views/resource_show_component.rb
avo-3.0.1.beta9 app/components/avo/views/resource_show_component.rb