Skip to content

Commit

Permalink
initiate
Browse files Browse the repository at this point in the history
  • Loading branch information
Strnadj committed Jan 26, 2014
1 parent 12decec commit 0d3d481
Show file tree
Hide file tree
Showing 20 changed files with 519 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gemspec
150 changes: 150 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
PATH
remote: .
specs:
active_admin_event_log (0.0.1)
activeadmin (~> 0.6.0)

GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.16)
actionpack (= 3.2.16)
mail (~> 2.5.4)
actionpack (3.2.16)
activemodel (= 3.2.16)
activesupport (= 3.2.16)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
activeadmin (0.6.1)
arbre (~> 1.0)
bourbon (>= 1.0.0, < 4)
devise (>= 1.5.4, < 4)
formtastic (~> 2.0)
inherited_resources (~> 1.3)
jquery-rails (>= 1.0.0, < 3)
kaminari (~> 0.13)
meta_search (~> 1.0)
rails (>= 3.0.0, < 4)
sass (~> 3.1)
activemodel (3.2.16)
activesupport (= 3.2.16)
builder (~> 3.0.0)
activerecord (3.2.16)
activemodel (= 3.2.16)
activesupport (= 3.2.16)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.16)
activemodel (= 3.2.16)
activesupport (= 3.2.16)
activesupport (3.2.16)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
arbre (1.0.1)
activesupport (>= 3.0.0)
arel (3.0.3)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
bourbon (3.1.8)
sass (>= 3.2.0)
thor
builder (3.0.4)
devise (3.2.2)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
thread_safe (~> 0.1)
warden (~> 1.2.3)
erubis (2.7.0)
formtastic (2.2.1)
actionpack (>= 3.0)
has_scope (0.6.0.rc)
actionpack (>= 3.2, < 5)
activesupport (>= 3.2, < 5)
hike (1.2.3)
i18n (0.6.9)
inherited_resources (1.4.1)
has_scope (~> 0.6.0.rc)
responders (~> 1.0.0.rc)
journey (1.0.4)
jquery-rails (2.2.2)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
kaminari (0.15.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
meta_search (1.1.3)
actionpack (~> 3.1)
activerecord (~> 3.1)
activesupport (~> 3.1)
polyamorous (~> 0.5.0)
mime-types (1.25.1)
minitest (5.2.2)
multi_json (1.8.4)
orm_adapter (0.5.0)
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.16)
actionmailer (= 3.2.16)
actionpack (= 3.2.16)
activerecord (= 3.2.16)
activeresource (= 3.2.16)
activesupport (= 3.2.16)
bundler (~> 1.0)
railties (= 3.2.16)
railties (3.2.16)
actionpack (= 3.2.16)
activesupport (= 3.2.16)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.1.1)
rdoc (3.12.2)
json (~> 1.4)
responders (1.0.0)
railties (>= 3.2, < 5)
sass (3.2.14)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.8)
thor (0.18.1)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.38)
warden (1.2.3)
rack (>= 1.0)

PLATFORMS
ruby

DEPENDENCIES
active_admin_event_log!
bundler (>= 1.0.0)
minitest
rake
sqlite3
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
active_admin_event_log
======================
# Active Admin Event logger for Active Admin 0.6.0 (maybe 0.6.1)

## Info
Active Admin event log

## Installation guide

1. Add gem to gemfile

```ruby
gem 'active_admin_event_log', :git =>
"https://github.com:netbrick/active_admin_event_log.git"
```

2. Run rails generator for create event log migration and create
active_admin template (offcourse you'll be able to modify active admin event log
resource after that)

```ruby
rails generate active_admin_event_log:install
```

3. Run migrations

```ruby
rake db:migrate
```

4. Add your translations (you can inspire in config/locales/en.yml)

```ruby
en:
activerecord:
models:
active_admin_event_log/active_admin_event:
one: "Event log"
zero: "Event log"
other: "Events log"
attributes:
active_admin_event_log/active_admin_event:
created_at: "Created at"
author: "Source user"
etc...
```

5. Add event log to actions! I didn't find yet automatic way for log actions
and batch actions

## Result
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'bundler'
require 'rake/testtask'
Bundler::GemHelper.install_tasks

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
end

task :default => :test
27 changes: 27 additions & 0 deletions active_admin_event_log.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/active_admin_event_log/version', __FILE__)

Gem::Specification.new do |s|
s.name = 'active_admin_event_log'
s.version = ActiveAdminEventLog::VERSION
s.platform = Gem::Platform::RUBY
s.authors = %w("Jan Strnádek")
s.email = %w([email protected])
s.homepage = 'https://github.com/netbrick/active_admin_event_log'
s.summary = 'Active Admin event logger'
s.description = 'Active Admin event logger'

s.required_rubygems_version = '>= 1.3.6'

# Gems
s.add_dependency 'activeadmin', '~> 0.6.0'

s.add_development_dependency 'bundler', '>= 1.0.0'
s.add_development_dependency 'minitest'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rake'

s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map { |f| f =~ /^bin\/(.*)/ ? $1 : nil }.compact
s.require_path = 'lib'
end
15 changes: 15 additions & 0 deletions config/locales/cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cs:
activerecord:
models:
active_admin_event_log/active_admin_event:
one: "Log události"
zero: "Log události"
other: "Log událostí"
attributes:
active_admin_event_log/active_admin_event:
created_at: "Vytvořeno"
resource: "Objekt"
resource_type: "Typ objektu"
author: "Zdroj"
params: "Změny"
action: "Akce"
15 changes: 15 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
en:
activerecord:
models:
active_admin_event_log/active_admin_event:
one: "Event log"
zero: "Event log"
other: "Events log"
attributes:
active_admin_event_log/active_admin_event:
created_at: "Created at"
resource: "Resource"
resource_type: "Resource type"
author: "Author"
params: "Changes"
action: "Action"
16 changes: 16 additions & 0 deletions lib/active_admin_event_log.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Require
require 'inherited_resources'
require 'active_admin'
require 'active_admin_event_log/default_callbacks'
require 'active_admin_event_log/dirty_resource'

# Require active admin
module ActiveAdminEventLog
# Load active admin event at point, when Kaminari and Rails are ready!
autoload :ActiveAdminEvent, 'active_admin_event_log/active_admin_event'
end

# Event - only found option yet ;-(
ActiveAdmin.before_load do |app|
ActiveAdmin::ResourceDSL.send(:include, ActiveAdminEventLog::DefaultCallbacks)
end
22 changes: 22 additions & 0 deletions lib/active_admin_event_log/active_admin_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module ActiveAdminEventLog
class ActiveAdminEvent < ActiveRecord::Base
# Belongs to!
belongs_to :resource, :polymorphic => true
belongs_to :author, :polymorphic => true

# Attributes
attr_accessible :resource, :resource_id, :resource_type, :action, :params, :author

# Serialize params
serialize :params

# Get table name
def self.table_name
@table_name ||= ActiveRecord::Migrator.proper_table_name("active_admin_events")
end

def display_name
I18n.t("activerecord.models.active_admin_event_log/active_admin_event", :count => 1)
end
end
end
30 changes: 30 additions & 0 deletions lib/active_admin_event_log/default_callbacks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Add methods!
module ActiveAdminEventLog
module DefaultCallbacks
def self.included(base)
base.class_eval do
def set_log_callbacks
[ :update, :destroy, :create ].each do |action|
@config.controller.send("before_#{action}") do |resource|
# Prepare changed values
changed_data = ActiveAdminEventLog::DirtyResource.new(resource, params).hash_report

# Create event log
ActiveAdminEventLog::ActiveAdminEvent.create!(
:author => current_active_admin_user,
:resource => resource,
:action => action,
:params => changed_data
)
end
end
end

def initialize(config)
@config = config
set_log_callbacks
end
end
end
end
end
Loading

0 comments on commit 0d3d481

Please sign in to comment.