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
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/models/work_activity.rb', line 158 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
186 187 188 189 190 191 192 |
# File 'app/models/work_activity.rb', line 186 def change_value_html(value) if value["action"] == "changed" DiffTools::SimpleDiff.new(value["from"], value["to"]).to_html else "old change" end end |