Sha256: 54c7d1075a486bff34b7ecdfe436435d2c63d7919688414d3ce739d619ac3014

Contents?: true

Size: 1.04 KB

Versions: 61

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

class Avo::Views::ResourceNewComponent < ViewComponent::Base
  include Avo::ResourcesHelper
  include Avo::ApplicationHelper

  def initialize(
    resource: nil,
    model: nil
  )
    @resource = resource
    @model = model
  end

  def back_path
    if via_resource?
      helpers.resource_path(model: params[:via_relation_class].safe_constantize, resource: relation_resource, resource_id: params[:via_resource_id])
    else
      helpers.resources_path(resource: @resource)
    end
  end

  # The create button is dependent on the new? policy method.
  # The create? should be called only when the user clicks the Save button so the developers gets access to the params from the form.
  def can_see_the_save_button?
    @resource.authorization.authorize_action :new, raise_exception: false
  end

  private

  def via_resource?
    params[:via_relation_class].present? && params[:via_resource_id].present?
  end

  def relation_resource
    ::Avo::App.get_resource_by_model_name params[:via_relation_class].safe_constantize
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
avo-1.25.2 app/components/avo/views/resource_new_component.rb
avo-2.7.1.pre.1 app/components/avo/views/resource_new_component.rb
avo-2.7.0 app/components/avo/views/resource_new_component.rb
avo-2.6.1.pre.2 app/components/avo/views/resource_new_component.rb
avo-2.6.1.pre.1 app/components/avo/views/resource_new_component.rb
avo-2.6.0 app/components/avo/views/resource_new_component.rb
avo-2.5.2.pre.7 app/components/avo/views/resource_new_component.rb
avo-2.5.2.pre.6 app/components/avo/views/resource_new_component.rb
avo-2.5.2.pre.5 app/components/avo/views/resource_new_component.rb
avo-2.5.2.pre.4 app/components/avo/views/resource_new_component.rb
avo-2.5.2.pre.3 app/components/avo/views/resource_new_component.rb
avo-2.5.2.pre.2 app/components/avo/views/resource_new_component.rb
avo-2.5.2.pre.1 app/components/avo/views/resource_new_component.rb
avo-2.5.1 app/components/avo/views/resource_new_component.rb
avo-2.5.0 app/components/avo/views/resource_new_component.rb
avo-2.4.1 app/components/avo/views/resource_new_component.rb
avo-2.4.0 app/components/avo/views/resource_new_component.rb
avo-2.3.1.pre.6 app/components/avo/views/resource_new_component.rb
avo-2.3.1.pre.5 app/components/avo/views/resource_new_component.rb
avo-2.3.1.pre.4 app/components/avo/views/resource_new_component.rb