Sha256: 6755cab8e1390adb71ac61166439ce6abec1ab4ca4579b88e92dc212619c6575

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

module Carnival
  class QueryFormCreator

    def self.create presenter, params
      query_form = Carnival::QueryForm.new(params)

      if query_form.sort_column.nil?
        query_form.sort_column = presenter.default_sortable_field.sort_name.to_sym
      end

      if query_form.sort_direction.nil?
        query_form.sort_direction = presenter.default_sort_direction
      end

      if query_form.scope.nil?
        scope = presenter.default_scope
        query_form.scope = scope.name if scope.present?
      end

      date_filter_field = presenter.date_filter_field
      if date_filter_field.present?
        query_form.date_period_label = date_filter_field.default_date_filter if query_form.date_period_label.nil?
        query_form.date_period_from = date_filter_field.date_filter_periods[query_form.date_period_label].first if query_form.date_period_from.nil?
        query_form.date_period_to = date_filter_field.date_filter_periods[query_form.date_period_label].last if query_form.date_period_to.nil?
      end

      query_form
    end


  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
carnival-0.3.2 app/services/carnival/query_form_creator.rb
carnival-0.3.1 app/services/carnival/query_form_creator.rb
carnival-0.3.0 app/services/carnival/query_form_creator.rb
carnival-0.2.8 app/services/carnival/query_form_creator.rb
carnival-0.2.7 app/services/carnival/query_form_creator.rb
carnival-0.2.6 app/services/carnival/query_form_creator.rb