rlog_items 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rlog_items/active_record_logger.rb +1 -1
- data/lib/rlog_items/version.rb +1 -1
- data/lib/rlog_items/view_helpers.rb +119 -0
- data/lib/rlog_items.rb +14 -7
- metadata +2 -1
data/lib/rlog_items/version.rb
CHANGED
@@ -0,0 +1,119 @@
|
|
1
|
+
module RlogItems
|
2
|
+
|
3
|
+
module ViewHelpers
|
4
|
+
|
5
|
+
def rlog_item_user rlog_item
|
6
|
+
if rlog_item.user
|
7
|
+
target_type = t("activerecord.models.#{rlog_item.user.target_type.underscore}")
|
8
|
+
username = rlog_item.user.target.to_s
|
9
|
+
target_info = "#{target_type} #{username}"
|
10
|
+
capture_haml do
|
11
|
+
haml_tag "div" do
|
12
|
+
if rlog_item.user.target_type.downcase == "admin"
|
13
|
+
target_url = "rcoi"
|
14
|
+
elsif rlog_item.user.target_type.downcase == "rcoi"
|
15
|
+
target_url = "rcoi"
|
16
|
+
else
|
17
|
+
target_url = rlog_item.user.target #TODO SHIT
|
18
|
+
end
|
19
|
+
haml_concat link_to(target_info, url_for(target_url))
|
20
|
+
end
|
21
|
+
haml_tag "div", rlog_item.ip if rlog_item.ip && current_user.has_role?("admin")
|
22
|
+
end
|
23
|
+
else
|
24
|
+
target_info = "#{t("messages.user_id")}: #{rlog_item.user_id}"
|
25
|
+
capture_haml do
|
26
|
+
haml_tag "div" do
|
27
|
+
haml_tag "span.username", target_info
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def rlog_item_object rlog_item
|
34
|
+
model = rlog_item.record_type.camelize.constantize
|
35
|
+
id = rlog_item.record_id
|
36
|
+
object = model.unscoped.find_by_id id
|
37
|
+
|
38
|
+
return capture_haml do
|
39
|
+
haml_tag "div", t("messages.object_not_found")
|
40
|
+
end if object.nil?
|
41
|
+
|
42
|
+
if object.hidden
|
43
|
+
record_type = t("activerecord.models.#{rlog_item.record_type.underscore}")
|
44
|
+
record_id = rlog_item.record_id
|
45
|
+
capture_haml do
|
46
|
+
haml_tag "div", t("messages.object_with_target_deleted", :target => object)
|
47
|
+
haml_tag "div", t("messages.record_type", :record_type => record_type)
|
48
|
+
haml_tag "div", t("messages.record_id", :record_id => record_id)
|
49
|
+
end
|
50
|
+
else
|
51
|
+
capture_haml do
|
52
|
+
haml_concat link_to object.to_s, url_for(object)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def value_conversion key, value, object
|
58
|
+
begin
|
59
|
+
is_scan = object.record.send(key.to_sym).is_a? ScanUploader
|
60
|
+
rescue
|
61
|
+
is_scan = false
|
62
|
+
end
|
63
|
+
begin
|
64
|
+
is_date = object.record.send(key.to_sym).is_a? ActiveSupport::TimeWithZone
|
65
|
+
rescue
|
66
|
+
is_date = false
|
67
|
+
end
|
68
|
+
|
69
|
+
if !!value==value
|
70
|
+
bool_to_word(value)
|
71
|
+
elsif key =~ /^.*(_id|_code)$/
|
72
|
+
full_string, model_name, foreign_key = key.match(/(^.*)_(id|code)$/).to_a
|
73
|
+
begin
|
74
|
+
model = model_name.camelize.constantize
|
75
|
+
model.where(foreign_key => value).first.to_s
|
76
|
+
rescue
|
77
|
+
return value
|
78
|
+
end
|
79
|
+
elsif is_scan
|
80
|
+
unless value.blank?
|
81
|
+
capture_haml do
|
82
|
+
haml_concat link_to t("messages.download"), value.to_s
|
83
|
+
end
|
84
|
+
end
|
85
|
+
elsif is_date
|
86
|
+
l(value, :format => :short)
|
87
|
+
elsif key == "hidden" && !value.blank?
|
88
|
+
code = value.split(":").first
|
89
|
+
if DestroyReason::SYSTEM_CODE.include?(code.to_sym)
|
90
|
+
case
|
91
|
+
when code == "recursive"
|
92
|
+
recoursive, object_id, object_type = value.split(":")
|
93
|
+
object_type_name = t("activerecord.models.#{object_type.underscore}")
|
94
|
+
target = object_type.constantize.unscoped.find_by_id object_id
|
95
|
+
reason = t("messages.deleted_by_recursive", :target => target, :object_id => object_id, :object_type => object_type_name)
|
96
|
+
else
|
97
|
+
reason = t("messages.deleted_by_#{code}").to_s
|
98
|
+
end
|
99
|
+
else
|
100
|
+
reason = DestroyReason.find_by_code(code).try(:name)
|
101
|
+
end
|
102
|
+
value = t("messages.removed_due_to", :reason => reason)
|
103
|
+
value
|
104
|
+
elsif key == "hidden" && value.blank?
|
105
|
+
t("messages.record_was_recovered")
|
106
|
+
elsif value.nil?
|
107
|
+
t("messages.nil_value")
|
108
|
+
else
|
109
|
+
value
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def changed_field_name key, model_name
|
114
|
+
t("activerecord.attributes.#{model_name}.#{key}")
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
data/lib/rlog_items.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
require "rails"
|
2
2
|
require "rlog_items/version"
|
3
|
-
require "rlog_items/
|
3
|
+
require "rlog_items/active_record_logger"
|
4
|
+
require "rlog_items/view_helpers"
|
4
5
|
|
5
6
|
module RlogItems
|
6
|
-
#def self.config
|
7
|
-
# yield self
|
8
|
-
#end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
class Railtie < Rails::Railtie
|
9
|
+
initializer "rlog_items.active_record_logger" do
|
10
|
+
ActiveRecord::Base.send :include, ActiveRecordLogger
|
11
|
+
ActiveRecord::Base.class_eval { cattr_accessor :current_user }
|
12
|
+
ActiveRecord::Base.class_eval { cattr_accessor :current_request }
|
13
|
+
end
|
14
|
+
|
15
|
+
initializer "rlog_items.view_helpers" do
|
16
|
+
ActionView::Base.send :include, ViewHelpers
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
13
20
|
|
14
21
|
class Engine < Rails::Engine
|
15
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rlog_items
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/rlog_items.rb
|
28
28
|
- lib/rlog_items/active_record_logger.rb
|
29
29
|
- lib/rlog_items/version.rb
|
30
|
+
- lib/rlog_items/view_helpers.rb
|
30
31
|
- rlog_items.gemspec
|
31
32
|
homepage: http://mystand.ru/
|
32
33
|
licenses:
|