Class: ErpApp::Desktop::AuditLogViewer::BaseController

Inherits:
BaseController show all
Defined in:
app/controllers/erp_app/desktop/audit_log_viewer/base_controller.rb

Instance Method Summary collapse

Instance Method Details

#audit_log_typesObject



47
48
49
50
# File 'app/controllers/erp_app/desktop/audit_log_viewer/base_controller.rb', line 47

def audit_log_types
  audit_log_types= AuditLogType.all
  render :json => {:audit_log_types => audit_log_types.collect{|type| type.to_hash(:only => [:id, :description, :internal_identifier])}}
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/erp_app/desktop/audit_log_viewer/base_controller.rb', line 6

def index
  start_date = params[:start_date].to_time
  end_date = params[:end_date].to_time
  audit_log_type_id = params[:audit_log_type_id]

  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
  sort = sort_hash[:property] || 'id'
  dir  = sort_hash[:direction] || 'DESC'
  limit = params[:limit] || 15
  start = params[:start] || 0

  if start_date.blank? and end_date.blank? and audit_log_type_id.blank?
    audit_log_entries = AuditLog.order("#{sort} #{dir}").offset(start).limit(limit).all
    total_count = AuditLog.count
  else
    audit_logs = AuditLog.arel_table

    arel_query = AuditLog.where(:created_at => start_date..(end_date + 1.day))
    arel_query = arel_query.where(audit_logs[:audit_log_type_id].eq(audit_log_type_id)) if audit_log_type_id

    audit_log_entries = arel_query.order("#{sort} #{dir}").offset(start).limit(limit).all

    total_count = arel_query.count
  end

  render :json => {:total_count => total_count,
                   :audit_log_entries => audit_log_entries.collect{
                       |audit_log| audit_log.to_hash(:only => [:id, :description, :created_at],
                         :additional_values => {:party_description => audit_log.party.description,
                                                :audit_log_type => audit_log.audit_log_type.description})}}
end

#itemsObject



38
39
40
41
42
43
44
# File 'app/controllers/erp_app/desktop/audit_log_viewer/base_controller.rb', line 38

def items
  render :json => {:total_count => AuditLog.find(params[:audit_log_id]).items.count,
                   :audit_log_items => AuditLog.find(params[:audit_log_id]).items.collect{
                       |audit_log_item| audit_log_item.to_hash(:only => [:id, :description, :created_at, :audit_log_id],
                                                     :additional_values => {:value => audit_log_item.audit_log_item_value,
                                                                            :audit_log_item_type => audit_log_item.type.description})}}
end