Sha256: 5dd7a62b71f034b6b2735ff9e9b0fb58ac19b9e08e537e3804fc3a1e8a4bed08

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Renalware
  module Events
    module Lists
      # Form object to help us build and parse the appropriate filters for the
      # events_lists controller
      class Form
        delegate_missing_to :@handler

        def initialize(named_filter:, params: {})
          @handler = create_filter_specific_object_to_handle_all_requests(named_filter, params)
        end

        def create_filter_specific_object_to_handle_all_requests(named_filter, params)
          handler_klass = "#{self.class.name}::#{named_filter.to_s.classify}Events"
          handler_klass.constantize.new(params)
        end

        class AllEvents
          include ActiveModel::Model
          include Virtus::Model

          attribute :s, String # sort order, not really part of the form
          attribute :event_type_id_eq, Integer
          attribute :created_by_id_eq, Integer
          attribute :created_at_gteq, Date
          attribute :created_at_lteq, Date

          def event_type_options
            Events::Type.order(:name).pluck(:name, :id)
          end

          def created_by_options
            User.excluding_system_user.ordered
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
renalware-core-2.0.130 app/models/renalware/events/lists/form.rb
renalware-core-2.0.129 app/models/renalware/events/lists/form.rb
renalware-core-2.0.128 app/models/renalware/events/lists/form.rb
renalware-core-2.0.127 app/models/renalware/events/lists/form.rb
renalware-core-2.0.126 app/models/renalware/events/lists/form.rb