Class: WorkActivity::MetadataChanges
- Defined in:
- app/models/work_activity.rb
Constant Summary
Constants inherited from Renderer
Renderer::DATE_FORMAT, Renderer::DATE_TIME_FORMAT, Renderer::SORTABLE_DATE_TIME_FORMAT, Renderer::UNKNOWN_USER
Instance Method Summary collapse
-
#body_html ⇒ Object
Returns the message formatted to display metadata changes that were logged as an activity.
- #change_value_html(value) ⇒ Object
Methods inherited from Renderer
#created_by_user_html, #created_sortable_html, #created_updated_html, #initialize, #title_html, #to_html
Constructor Details
This class inherits a constructor from WorkActivity::Renderer
Instance Method Details
#body_html ⇒ Object
Returns the message formatted to display metadata changes that were logged as an activity
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'app/models/work_activity.rb', line 184 def body_html = JSON.parse(@work_activity.) # Messages should consistently be Arrays of Hashes, but this might require a migration from legacy field records = if .is_a?(Array) else Array.wrap() end elements = .map do || markup = if .is_a?(Hash) .keys.map do |field| mapped = [field].map { |value| change_value_html(value) } "<details class='message-html'><summary class='show-changes'>#{field&.titleize}</summary>#{mapped.join}</details>" end else # For handling cases where WorkActivity#message only contains Strings, or Arrays of Strings [ "<details class='message-html'><summary class='show-changes'></summary>#{}</details>" ] end markup.join end elements.flatten.join end |
#change_value_html(value) ⇒ Object
212 213 214 215 216 217 218 |
# File 'app/models/work_activity.rb', line 212 def change_value_html(value) if value["action"] == "changed" DiffTools::SimpleDiff.new(value["from"], value["to"]).to_html else "old change" end end |