Sha256: 36fb6b4086241893a8d7a21efcd8dc37758c092ff617607048ed6088c6c44f32

Contents?: true

Size: 1.57 KB

Versions: 59

Compression:

Stored size: 1.57 KB

Contents

class Marty::McflyGridPanel < Marty::Grid
  def configure(c)
    super

    warped = Marty::Util.warped?

    c.editing  = !warped && c.editing || :none

    [:update, :delete, :create].each do |perm|
      c.permissions[perm] = false if warped
    end

    # default sort all Mcfly grids with id
    c.store_config.merge!({sorters: [{property: :id, direction: 'ASC'}]})
  end

  def get_records(params)
   ts = Mcfly.normalize_infinity(Marty::Util.get_posting_time)
   tb = model.table_name

   model.where("#{tb}.obsoleted_dt >= ? AND #{tb}.created_dt < ?",
                     ts, ts).scoping do
      super
    end
  end

  ######################################################################

  def augment_attribute_config(c)
    super

    # Set mcfly_scope if the attribute is a mcfly association
    if !c[:scope] && model_adapter.association_attr?(c)
      assoc_name, assoc_method = c[:name].split('__')
      begin
        aklass = model.reflect_on_association(assoc_name.to_sym).klass
      rescue
        raise "trouble finding #{assoc_name} assoc class on #{model}"
      end
      c[:scope] = Mcfly.has_mcfly?(aklass) ?
      self.class.mcfly_scope(assoc_method || 'id') :
                  self.class.sorted_scope(assoc_method || 'id')
    end
  end

private
  def self.mcfly_scope(sort_column)
    lambda { |r|
      ts = Mcfly.normalize_infinity(Marty::Util.get_posting_time)
      r.where("obsoleted_dt >= ? AND created_dt < ?", ts, ts).
      order(sort_column.to_sym)
    }
  end

  def self.sorted_scope(sort_column)
    lambda { |r|
      r.order(sort_column.to_sym)
    }
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
marty-1.2.0 app/components/marty/mcfly_grid_panel.rb
marty-1.1.9 app/components/marty/mcfly_grid_panel.rb
marty-1.1.8 app/components/marty/mcfly_grid_panel.rb
marty-1.1.7 app/components/marty/mcfly_grid_panel.rb
marty-1.1.6 app/components/marty/mcfly_grid_panel.rb
marty-1.1.5 app/components/marty/mcfly_grid_panel.rb
marty-1.1.4 app/components/marty/mcfly_grid_panel.rb
marty-1.1.3 app/components/marty/mcfly_grid_panel.rb
marty-1.1.2 app/components/marty/mcfly_grid_panel.rb
marty-1.1.1 app/components/marty/mcfly_grid_panel.rb
marty-1.0.54 app/components/marty/mcfly_grid_panel.rb
marty-1.0.53 app/components/marty/mcfly_grid_panel.rb
marty-1.0.52 app/components/marty/mcfly_grid_panel.rb
marty-1.0.51 app/components/marty/mcfly_grid_panel.rb
marty-1.0.50 app/components/marty/mcfly_grid_panel.rb
marty-1.0.48 app/components/marty/mcfly_grid_panel.rb
marty-1.0.47 app/components/marty/mcfly_grid_panel.rb
marty-1.0.46 app/components/marty/mcfly_grid_panel.rb
marty-1.0.44 app/components/marty/mcfly_grid_panel.rb
marty-1.0.43 app/components/marty/mcfly_grid_panel.rb