Sha256: d57ed057c9bef56f0d7e7a4947289a8f241e547571624d67c9b6e21c0e4325a6

Contents?: true

Size: 1.43 KB

Versions: 10

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

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

  def initialize(resource: nil, reflection: nil, parent_model: nil, resource_panel: nil, actions: [])
    @resource = resource
    @reflection = reflection
    @resource_panel = resource_panel
    @actions = actions
    @view = :show

    split_panel_fields
  end

  def title
    if @reflection.present?
      return field.name if has_one_field?
      reflection_resource.name
    else
      @resource.panels.first[:name]
    end
  end

  def back_path
    if via_resource?
      helpers.resource_path(model: params[:via_resource_class].safe_constantize, resource: relation_resource, resource_id: params[:via_resource_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_resource_id: params[:via_resource_id]
      }
    end

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

  private

  # In development and test environments we shoudl 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.class == Avo::Fields::HasOneField
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
avo-2.9.2.pre1 app/components/avo/views/resource_show_component.rb
avo-2.9.1.pre7 app/components/avo/views/resource_show_component.rb
avo-2.9.1.pre6 app/components/avo/views/resource_show_component.rb
avo-2.9.1.pre5 app/components/avo/views/resource_show_component.rb
avo-2.9.1.pre4 app/components/avo/views/resource_show_component.rb
avo-2.9.1.pre3 app/components/avo/views/resource_show_component.rb
avo-2.9.1.pre2 app/components/avo/views/resource_show_component.rb
avo-2.9.1.pre1 app/components/avo/views/resource_show_component.rb
avo-2.9.0 app/components/avo/views/resource_show_component.rb
avo-2.8.0 app/components/avo/views/resource_show_component.rb