Sha256: 19c9f7f6b6667f290e328323eef13532175f013b6f8ed8e92fcebe4656e077a9

Contents?: true

Size: 1.95 KB

Versions: 14

Compression:

Stored size: 1.95 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, *args, interaction:, **kwargs)
          set_interaction interaction

          kwargs[:route_options] ||= build_route_options name
          kwargs.reverse_merge! action_options
          super(name, *args, **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

14 entries across 14 versions & 1 rubygems

Version Path
plutonium-0.15.0.pre.rc3 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.0.pre.rc2 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.15.0.pre.rc1 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.14.1 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.14.0 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.13.3 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.13.2 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.13.1 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.13.0 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.12.14 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.12.13 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.12.12 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.12.11 lib/plutonium/core/actions/interactive_action.rb
plutonium-0.12.10 lib/plutonium/core/actions/interactive_action.rb