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
|