-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ismail Akbudak
committed
Jun 22, 2016
1 parent
4739ee0
commit 1872c56
Showing
18 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
require 'application_responder' | ||
|
||
class Hq::ApplicationController < ActionController::Base | ||
|
||
before_filter :set_audit_user | ||
before_action :authenticate_admin! | ||
|
||
self.responder = ApplicationResponder | ||
respond_to :html, :json | ||
|
||
private | ||
|
||
def set_audit_user | ||
# Set audit current user | ||
Audited.current_user_method = :current_admin | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Hq::AuditsController < Hq::ApplicationController | ||
|
||
add_breadcrumb I18n.t('activerecord.models.audits'), :hq_audits_path | ||
|
||
def index | ||
@search = Audit.includes(:user).reorder('id DESC').search(params[:q]) | ||
@audits = @search.result(distinct: true).paginate(page: params[:page]) | ||
@auditable_types = Audited::Adapters::ActiveRecord::Audit.select('auditable_type').group('auditable_type').reorder('') | ||
end | ||
|
||
def show | ||
@audit = Audit.find(params[:id]) | ||
add_breadcrumb @audit.id, hq_audit_path(id: @audit) | ||
end | ||
|
||
end |
11 changes: 11 additions & 0 deletions
11
templates/app/controllers/user/user_application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
require 'application_responder' | ||
|
||
class User::UserApplicationController < ActionController::Base | ||
|
||
# layout 'user/application' | ||
layout 'application' | ||
before_filter :set_audit_user | ||
before_action :authenticate_user! | ||
|
||
self.responder = ApplicationResponder | ||
respond_to :html, :json | ||
|
||
private | ||
|
||
def set_audit_user | ||
# Set audit current user | ||
Audited.current_user_method = :current_user | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Audit < Audited::Adapters::ActiveRecord::Audit | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
class City < ActiveRecord::Base | ||
|
||
# Helpers | ||
audited | ||
|
||
# Relations | ||
belongs_to :country | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.table-header.row | ||
.col-lg-2 | ||
- if params[:q].present? | ||
= link_to hq_audits_path, class: 'btn btn-info' do | ||
= t('view.all') | ||
%span.badge= Audit.count | ||
.col-lg-10 | ||
.pull-right | ||
= search_form_for @search, builder: SimpleForm::FormBuilder, html: {class: 'form-inline'}, url: hq_audits_path do |f| | ||
.form-group | ||
= f.label :user_type, label: t('activerecord.attributes.audits.user_type') | ||
= f.input_field :user_type_eq, label: false, class: 'form-control', placeholder: t('activerecord.attributes.audits.user'), collection: get_audit_users, include_blank: t('view.select') | ||
|
||
- if params[:q].present? and params[:q][:user_type_eq].present? | ||
- type = params[:q][:user_type_eq] | ||
- if type == 'Admin' | ||
= f.label :user, label: t('activerecord.attributes.audits.user') | ||
= f.input :user_id_eq, label: false, class: 'form-control chosen-select', placeholder: t('activerecord.attributes.audits.user'), collection: get_admins, include_blank: t('view.select') | ||
- elsif type == 'User' | ||
= f.label :user, label: t('activerecord.attributes.audits.user') | ||
= f.input_field :user_id_eq, label: false, class: 'form-control chosen-select', placeholder: t('activerecord.attributes.audits.user'), collection: get_users, include_blank: t('view.select') | ||
|
||
= f.label :auditable_type, label: t('activerecord.attributes.audits.auditable_type') | ||
= f.input_field :auditable_type_eq, label: false, class: 'form-control chosen-select', placeholder: t('activerecord.attributes.audits.auditable_type'), collection: @auditable_types.map{|a| [t("activerecord.models.#{a.auditable_type.try(:underscore)}"), a.auditable_type]}, include_blank: t('view.select') | ||
|
||
= f.label :user, label: t('activerecord.attributes.audits.auditable_id') | ||
= f.input_field :auditable_id_eq, label: false, class: 'form-control', placeholder: t('activerecord.attributes.audits.auditable_id') | ||
|
||
= f.label :user, label: t('activerecord.attributes.audits.action') | ||
= f.input_field :action_eq, label: false, class: 'form-control', placeholder: t('activerecord.attributes.audits.action'), collection: %w(create update destroy).map{|a| [t("actions.#{a}"), a]}, include_blank: t('view.select') | ||
= button_tag( class: 'btn btn-success btn-group') do | ||
%i.fa.fa-search |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.panel-heading | ||
%i.fa.fa-list | ||
= t('activerecord.models.audits') | ||
.panel-tools | ||
.btn-group | ||
%a.btn{href: hq_audits_path, data: {toggle: 'toolbar-tooltip'}, title: t('view.reload')} | ||
%i.icon-refresh | ||
.badge= @audits.total_entries | ||
.panel-body.filters | ||
= render 'filters' | ||
.table-responsive | ||
%table.table | ||
%thead | ||
%tr | ||
%th= sort_link(@search, :id, t('activerecord.attributes.audits.id')) | ||
%th= sort_link(@search, :user_type, t('activerecord.attributes.audits.user_type')) | ||
%th= sort_link(@search, :user_id, t('activerecord.attributes.audits.user')) | ||
%th= sort_link(@search, :auditable_type, t('activerecord.attributes.audits.auditable_type')) | ||
%th= sort_link(@search, :auditable_id, t('activerecord.attributes.audits.auditable_id')) | ||
%th= sort_link(@search, :auditable_id, t('activerecord.attributes.audits.created_at')) | ||
%th= sort_link(@search, :action, t('activerecord.attributes.audits.action')) | ||
%th.actions | ||
= t('view.actions') | ||
%tbody | ||
- @audits.each do |audit| | ||
%tr | ||
%td= audit.id | ||
%td | ||
= t("activerecord.models.#{audit.try(:user_type).try(:downcase)}") if audit.try(:user_type).present? | ||
%td= "#{audit.try(:user).try(:full_name)} - #{audit.try(:user).try(:email)}" | ||
%td= t("activerecord.models.#{audit.try(:auditable_type).try(:underscore)}") if audit.try(:auditable_type).present? | ||
%td= audit.auditable_id | ||
%td= l audit.created_at | ||
%td= t("actions.#{audit.action}") | ||
%td.actions | ||
= link_to(hq_audit_path(id: audit), class: 'btn btn-success btn-xs', 'data-toggle' => 'tooltip', title: t('tooltips.zoom')) do | ||
%i.fa.fa-eye |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.panel.panel-default.grid | ||
= render 'list' | ||
.panel-footer | ||
.pagination.pagination-sm | ||
= will_paginate @audits, renderer: BootstrapPagination::Rails, bootstrap: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- @audit.audited_changes.keys.each do |key| | ||
%p | ||
%strong | ||
= t("activerecord.attributes.#{@audit.try(:auditable_type).try(:underscore)}.#{key}") if @audit.try(:auditable_type).present? | ||
= @audit.audited_changes[key] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters