Sha256: 7849965a12376fb4560984b85ef68e434f05e965cd1fb64da42d894fe3ed5742

Contents?: true

Size: 1.94 KB

Versions: 30

Compression:

Stored size: 1.94 KB

Contents

module Plutonium
  module Core
    module Actions
      class InteractiveAction < Plutonium::Core::Action
        include Plutonium::Core::Definers::FieldInputDefiner

        Context = Data.define :resource_class

        attr_reader :interaction, :inline, :inputs

        def initialize(name, *, interaction:, **kwargs)
          set_interaction interaction

          kwargs[:route_options] ||= build_route_options name
          kwargs.reverse_merge! action_options
          super(name, *, **kwargs)
        end

        def confirmation
          super || (inline ? "#{label}?" : nil)
        end

        private

        def resource_class = interaction

        def action_options
          {
            # TODO: move these into config
            collection_action: [:interactive_resource_collection_action,
              :interactive_resource_recordless_action].include?(action_type),
            collection_record_action: action_type == :interactive_resource_record_action,
            record_action: action_type == :interactive_resource_record_action,
            bulk_action: action_type == :interactive_resource_collection_action
          }
        end

        def set_interaction(interaction)
          @interaction = interaction
          @inputs = defined_field_inputs_for(*(interaction.filters.keys - [:resource, :resources]))
          @inline = @inputs.blank? unless inline == false
        end

        def build_route_options(name)
          method = inline ? :post : :get
          action = action_type
          options = {interactive_action: name}

          RouteOptions.new action:, method:, options:
        end

        def action_type
          if interaction.filters.key? :resource
            :interactive_resource_record_action
          elsif interaction.filters.key? :resources
            :interactive_resource_collection_action
          else
            :interactive_resource_recordless_action
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
plutonium-0.16.5 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.16.4 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.16.3 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.16.1 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.16.0 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.24 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.23 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.22 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.21 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.20 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.19 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.18 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.17 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.16 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.15 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.14 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.13 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.12 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.11 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.10 lib/plutonium/core/actions/interactive_action.rb