Sha256: 6d71cd6eb1954d0f6e9c55780c15141593b41046d21ffafc24527e1d8fa964b3

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

class RailsAdmin::History < ActiveRecord::Base
  self.table_name = :rails_admin_histories

  IGNORED_ATTRS = Set[:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on]

  attr_accessible :message, :item, :table, :username

  default_scope order('id DESC')

  def self.latest
    self.limit(100)
  end

  def self.create_history_item(message, object, abstract_model, user)
    create(
       :message => [message].flatten.join(', '),
       :item => object.id,
       :table => abstract_model.model.to_s,
       :username => user.try(:email)
     )
  end

  def self.history_for_model(model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
    history = where(:table => model.pretty_name)
    history = history.where("message LIKE ? OR username LIKE ?", "%#{query}%", "%#{query}%") if query
    history = history.order(sort_reverse == "true" ? "#{sort} DESC" : sort) if sort
    all ? history : history.send(Kaminari.config.page_method_name, page.presence || "1").per(per_page)
  end

  def self.history_for_object(model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
    history = where(:table => model.pretty_name, :item => object.id)
    history = history.where("message LIKE ? OR username LIKE ?", "%#{query}%", "%#{query}%") if query
    history = history.order(sort_reverse == "true" ? "#{sort} DESC" : sort) if sort
    all ? history : history.send(Kaminari.config.page_method_name, page.presence || "1").per(per_page)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_admin-0.3.0 lib/rails_admin/extensions/history/history.rb