Class: RailsAdmin::History

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/rails_admin/extensions/history/history.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.create_history_item(message, object, abstract_model, user) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/rails_admin/extensions/history/history.rb', line 14

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

.history_for_model(abstract_model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20)) ⇒ Object



23
24
25
26
27
28
# File 'lib/rails_admin/extensions/history/history.rb', line 23

def self.history_for_model(abstract_model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
  history = where(:table => abstract_model.to_s)
  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

.history_for_object(abstract_model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20)) ⇒ Object



30
31
32
33
34
35
# File 'lib/rails_admin/extensions/history/history.rb', line 30

def self.history_for_object(abstract_model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
  history = where(:table => abstract_model.to_s, :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

.latestObject



10
11
12
# File 'lib/rails_admin/extensions/history/history.rb', line 10

def self.latest
  self.limit(100)
end