Sha256: bef1405c054dce6110b2b23457afc822ef00eea0f5970ebb0b4870f21b5471e1

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

require_dependency "audit_rails/application_controller"

module AuditRails
  class AuditsController < ApplicationController
    before_filter :apply_filter, except: [:create]

    def index
      find_all_audits

      if params[:commit] == "Download Filtered Report"
        send_data(@audits.to_xls(:columns => [:user_name, :action, :description, :created_at], 
                  :headers => ['User name', 'Action', 'Details', 'When?']), filename: 'audits.xls') and return
      end
    end

    def create
      add_to_audit("visit-site", "xyz", "Fake User")
      render :nothing => true, :status => 200, :content_type => 'text/html'
    end

    def analytics
      @analysis_by_user_name  = AuditRails::Audit.in_range(@range_begin, @range_end).analysis_by_user_name
      @analysis_by_page_views = AuditRails::Audit.in_range(@range_begin, @range_end).analysis_by_page_views
      @analysis_per_user_by_page_views  = AuditRails::Audit.in_range(@range_begin, @range_end).analysis_per_user_by_page_views

      @total = AuditRails::Audit.in_range(@range_begin, @range_end).count
      @no_audits = AuditRails::Audit.count == 0

      if params[:commit] == "Download Filtered Report"
        find_all_audits
        send_data(@audits.to_xls(:columns => [:user_name, :action, :description, :created_at], 
                  :headers => ['User name', 'Action', 'Details', 'When?']), filename: 'audits.xls') and return
      end
    end

    private

    def apply_filter
      @range_begin = params[:analytics] ? params[:analytics][:range_begin] : nil
      @range_end   = params[:analytics] ? params[:analytics][:range_end] : nil
    end

    def find_all_audits
      @audits = AuditRails::Audit.reverse_chronological.in_range(@range_begin, @range_end)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
audit_rails-2.0.1 app/controllers/audit_rails/audits_controller.rb