Sha256: d712844199548e0db87d188118e40dfbb5c8a052793939a508d07d4908d77258

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

class Marty::PivotGrid < Netzke::Base
  module Services
    # Implementation for the "server_read" endpoint
    def read(params = {})
      {}.tap do |res|
        records = get_records(params)
        res[:data] = records.map{|r| data_adapter.record_to_array(r, final_columns(:with_meta => true))}
      end
    end

    # Returns an array of records.
    def get_records(params)
      params[:query] = normalize_query(params[:query]) if params[:query].present?
      if config[:enable_pagination]
        params[:limit] = config[:rows_per_page]
      else
        params.delete(:limit)
      end
      params[:scope] = config[:scope] # note, params[:scope] becomes ActiveSupport::HashWithIndifferentAccess

      data_adapter.get_records(params, final_columns)
    end

    def count_records(params)
      params[:scope] = config[:scope] # note, params[:scope] becomes ActiveSupport::HashWithIndifferentAccess

      data_adapter.count_records(params, final_columns)
    end

    # Override this method to react on each operation that caused changing of data
    def on_data_changed
    end

    protected

    def normalize_query(or_query)
      or_query.each do |and_query|
        and_query.each do |q|
          column_config = final_columns_hash[q[:attr].to_sym] || {}
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
marty-0.5.15 app/components/marty/pivot_grid/services.rb
marty-0.5.14 app/components/marty/pivot_grid/services.rb
marty-0.5.13 app/components/marty/pivot_grid/services.rb
marty-0.5.12 app/components/marty/pivot_grid/services.rb