card-mod-history 0.13.4 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/card/act.rb +6 -7
- data/lib/card/action/changes.rb +114 -0
- data/lib/card/action.rb +6 -106
- data/locales/de.yml +2 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a64000335eb221dbc674b8417dd0bdc263de9b261dc818807e0d047473b0622b
|
4
|
+
data.tar.gz: 465d80814f678f513eda03f88d08e1ac58320d1f132d7743c66e4b30dccc9501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c887d9f69ba8bc9a8c2d5d763e140e38b8e1cbb3fa6412413429742e2a851c57f4978f73fa8fdcd2c10d9f68675b2b7bf8eb427b4acfeab6f7bdc417bc9e8689
|
7
|
+
data.tar.gz: e4c7b7455a6b91d76e345764d9e9aea30f4f3c9148c69975fd28c0d12ea427921dfc6fced5d3fca45ec39930f7c4f6b32bbfc2be2777fd65e7338c26ff5492ca
|
data/lib/card/act.rb
CHANGED
@@ -72,16 +72,15 @@ class Card
|
|
72
72
|
Card.fetch actor_id
|
73
73
|
end
|
74
74
|
|
75
|
+
# sometimes Object#card_id interferes with default ActiveRecord attribute def
|
76
|
+
def card_id
|
77
|
+
_read_attribute "card_id"
|
78
|
+
end
|
79
|
+
|
75
80
|
# the act's primary card
|
76
81
|
# @return [Card]
|
77
82
|
def card
|
78
|
-
Card.fetch card_id, look_in_trash: true
|
79
|
-
|
80
|
-
# FIXME: if the following is necessary, we need to document why.
|
81
|
-
# generally it's a very bad idea to have type-specific code here.
|
82
|
-
|
83
|
-
# return res unless res&.type_id&.in?([Card::FileID, Card::ImageID])
|
84
|
-
# res.include_set_modules
|
83
|
+
Card.fetch card_id, look_in_trash: true
|
85
84
|
end
|
86
85
|
|
87
86
|
# list of all actions that are part of the act
|
@@ -0,0 +1,114 @@
|
|
1
|
+
class Card
|
2
|
+
class Action
|
3
|
+
# methods for relating Card::Action to Card::Change
|
4
|
+
module Changes
|
5
|
+
# value set by action's {Change} to given field
|
6
|
+
# @see #interpret_field #interpret_field for field param
|
7
|
+
# @see #interpret_value #interpret_value for return values
|
8
|
+
def value field
|
9
|
+
return unless (change = change field)
|
10
|
+
|
11
|
+
interpret_value field, change.value
|
12
|
+
end
|
13
|
+
|
14
|
+
# value of field set by most recent {Change} before this one
|
15
|
+
# @see #interpret_field #interpret_field for field param
|
16
|
+
# @see #interpret_field #interpret_field for field param
|
17
|
+
def previous_value field
|
18
|
+
return if action_type == :create
|
19
|
+
return unless (previous_change = previous_change field)
|
20
|
+
|
21
|
+
interpret_value field, previous_change.value
|
22
|
+
end
|
23
|
+
|
24
|
+
# action's {Change} object for given field
|
25
|
+
# @see #interpret_field #interpret_field for field param
|
26
|
+
# @return [Change]
|
27
|
+
def change field
|
28
|
+
changes[interpret_field field]
|
29
|
+
end
|
30
|
+
|
31
|
+
# most recent change to given field before this one
|
32
|
+
# @see #interpret_field #interpret_field for field param
|
33
|
+
# @return [Change]
|
34
|
+
def previous_change field
|
35
|
+
return nil if action_type == :create
|
36
|
+
|
37
|
+
field = interpret_field field
|
38
|
+
if @previous_changes&.key?(field)
|
39
|
+
@previous_changes[field]
|
40
|
+
else
|
41
|
+
@previous_changes ||= {}
|
42
|
+
@previous_changes[field] = card.last_change_on field, before: self
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def all_changes
|
47
|
+
self.class.cache.fetch("#{id}-changes") do
|
48
|
+
# using card_changes causes caching problem
|
49
|
+
Card::Change.where(card_action_id: id).to_a
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# all action {Change changes} in hash form. { field1: Change1 }
|
54
|
+
# @return [Hash]
|
55
|
+
def changes
|
56
|
+
@changes ||=
|
57
|
+
if sole?
|
58
|
+
current_changes
|
59
|
+
else
|
60
|
+
all_changes.each_with_object({}) do |change, hash|
|
61
|
+
hash[change.field.to_sym] = change
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# all changed values in hash form. { field1: new_value }
|
67
|
+
def changed_values
|
68
|
+
@changed_values ||= changes.transform_values(&:value)
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [Hash]
|
72
|
+
def current_changes
|
73
|
+
return {} unless card
|
74
|
+
|
75
|
+
@current_changes ||=
|
76
|
+
Card::Change::TRACKED_FIELDS.each_with_object({}) do |field, hash|
|
77
|
+
hash[field.to_sym] = Card::Change.new field: field,
|
78
|
+
value: card.send(field),
|
79
|
+
card_action_id: id
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
# translate field into fieldname as referred to in database
|
86
|
+
# @see Change::TRACKED_FIELDS
|
87
|
+
# @param field [Symbol] can be :type_id, :cardtype, :db_content, :content,
|
88
|
+
# :name, :trash
|
89
|
+
# @return [Symbol]
|
90
|
+
def interpret_field field
|
91
|
+
case field
|
92
|
+
when :content then :db_content
|
93
|
+
when :cardtype then :type_id
|
94
|
+
else field.to_sym
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# value in form prescribed for specific field name
|
99
|
+
# @param value [value of {Change}]
|
100
|
+
# @return [Integer] for :type_id
|
101
|
+
# @return [String] for :name, :db_content, :content, :cardtype
|
102
|
+
# @return [True/False] for :trash
|
103
|
+
def interpret_value field, value
|
104
|
+
case field.to_sym
|
105
|
+
when :type_id
|
106
|
+
value&.to_i
|
107
|
+
when :cardtype
|
108
|
+
Card.fetch_name(value&.to_i)
|
109
|
+
else value
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/card/action.rb
CHANGED
@@ -22,6 +22,7 @@ class Card
|
|
22
22
|
#
|
23
23
|
class Action < Cardio::Record
|
24
24
|
include Differ
|
25
|
+
include Changes
|
25
26
|
extend Admin
|
26
27
|
|
27
28
|
belongs_to :act, foreign_key: :card_act_id, inverse_of: :ar_actions
|
@@ -67,6 +68,11 @@ class Card
|
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
71
|
+
# sometimes Object#card_id interferes with default ActiveRecord attribute def
|
72
|
+
def card_id
|
73
|
+
_read_attribute "card_id"
|
74
|
+
end
|
75
|
+
|
70
76
|
# each action is associated with on and only one card
|
71
77
|
# @return [Card]
|
72
78
|
def card
|
@@ -114,112 +120,6 @@ class Card
|
|
114
120
|
Card::Action.where("id < ? AND card_id = ?", id, card_id).last
|
115
121
|
end
|
116
122
|
|
117
|
-
# value set by action's {Change} to given field
|
118
|
-
# @see #interpret_field #interpret_field for field param
|
119
|
-
# @see #interpret_value #interpret_value for return values
|
120
|
-
def value field
|
121
|
-
return unless (change = change field)
|
122
|
-
|
123
|
-
interpret_value field, change.value
|
124
|
-
end
|
125
|
-
|
126
|
-
# value of field set by most recent {Change} before this one
|
127
|
-
# @see #interpret_field #interpret_field for field param
|
128
|
-
# @see #interpret_field #interpret_field for field param
|
129
|
-
def previous_value field
|
130
|
-
return if action_type == :create
|
131
|
-
return unless (previous_change = previous_change field)
|
132
|
-
|
133
|
-
interpret_value field, previous_change.value
|
134
|
-
end
|
135
|
-
|
136
|
-
# action's {Change} object for given field
|
137
|
-
# @see #interpret_field #interpret_field for field param
|
138
|
-
# @return [Change]
|
139
|
-
def change field
|
140
|
-
changes[interpret_field field]
|
141
|
-
end
|
142
|
-
|
143
|
-
# most recent change to given field before this one
|
144
|
-
# @see #interpret_field #interpret_field for field param
|
145
|
-
# @return [Change]
|
146
|
-
def previous_change field
|
147
|
-
return nil if action_type == :create
|
148
|
-
|
149
|
-
field = interpret_field field
|
150
|
-
if @previous_changes&.key?(field)
|
151
|
-
@previous_changes[field]
|
152
|
-
else
|
153
|
-
@previous_changes ||= {}
|
154
|
-
@previous_changes[field] = card.last_change_on field, before: self
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def all_changes
|
159
|
-
self.class.cache.fetch("#{id}-changes") do
|
160
|
-
# using card_changes causes caching problem
|
161
|
-
Card::Change.where(card_action_id: id).to_a
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
# all action {Change changes} in hash form. { field1: Change1 }
|
166
|
-
# @return [Hash]
|
167
|
-
def changes
|
168
|
-
@changes ||=
|
169
|
-
if sole?
|
170
|
-
current_changes
|
171
|
-
else
|
172
|
-
all_changes.each_with_object({}) do |change, hash|
|
173
|
-
hash[change.field.to_sym] = change
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
# all changed values in hash form. { field1: new_value }
|
179
|
-
def changed_values
|
180
|
-
@changed_values ||= changes.transform_values(&:value)
|
181
|
-
end
|
182
|
-
|
183
|
-
# @return [Hash]
|
184
|
-
def current_changes
|
185
|
-
return {} unless card
|
186
|
-
|
187
|
-
@current_changes ||=
|
188
|
-
Card::Change::TRACKED_FIELDS.each_with_object({}) do |field, hash|
|
189
|
-
hash[field.to_sym] = Card::Change.new field: field,
|
190
|
-
value: card.send(field),
|
191
|
-
card_action_id: id
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
# translate field into fieldname as referred to in database
|
196
|
-
# @see Change::TRACKED_FIELDS
|
197
|
-
# @param field [Symbol] can be :type_id, :cardtype, :db_content, :content,
|
198
|
-
# :name, :trash
|
199
|
-
# @return [Symbol]
|
200
|
-
def interpret_field field
|
201
|
-
case field
|
202
|
-
when :content then :db_content
|
203
|
-
when :cardtype then :type_id
|
204
|
-
else field.to_sym
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
# value in form prescribed for specific field name
|
209
|
-
# @param value [value of {Change}]
|
210
|
-
# @return [Integer] for :type_id
|
211
|
-
# @return [String] for :name, :db_content, :content, :cardtype
|
212
|
-
# @return [True/False] for :trash
|
213
|
-
def interpret_value field, value
|
214
|
-
case field.to_sym
|
215
|
-
when :type_id
|
216
|
-
value&.to_i
|
217
|
-
when :cardtype
|
218
|
-
Card.fetch_name(value&.to_i)
|
219
|
-
else value
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
123
|
def sole?
|
224
124
|
all_changes.empty? &&
|
225
125
|
(action_type == :create || Card::Action.where(card_id: card_id).count == 1)
|
data/locales/de.yml
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card-mod-history
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan McCutchen
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-12-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: card
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: 1.104.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - '='
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 1.
|
28
|
+
version: 1.104.0
|
29
29
|
description: ''
|
30
30
|
email:
|
31
31
|
- info@decko.org
|
@@ -41,8 +41,10 @@ files:
|
|
41
41
|
- lib/card/action.rb
|
42
42
|
- lib/card/action/action_renderer.rb
|
43
43
|
- lib/card/action/admin.rb
|
44
|
+
- lib/card/action/changes.rb
|
44
45
|
- lib/card/action/differ.rb
|
45
46
|
- lib/card/change.rb
|
47
|
+
- locales/de.yml
|
46
48
|
- locales/en.yml
|
47
49
|
- set/all/history.rb
|
48
50
|
- set/all/history/act_listing.rb
|
@@ -79,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
81
|
- !ruby/object:Gem::Version
|
80
82
|
version: '0'
|
81
83
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
84
|
+
rubygems_version: 3.2.15
|
83
85
|
signing_key:
|
84
86
|
specification_version: 4
|
85
87
|
summary: Revision histories in acts, actions, and changes
|