Class: WorkActivity::FileChanges
- 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 file changes that were logged as an activity.
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 file changes that were logged as an activity
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'app/models/work_activity.rb', line 197 def body_html changes = JSON.parse(@work_activity.) if changes.is_a?(Hash) changes = [changes] end files_added = changes.select { |v| v["action"] == "added" } files_deleted = changes.select { |v| v["action"] == "removed" } files_replaced = changes.select { |v| v["action"] == "replaced" } changes_html = [] unless files_added.empty? label = "Files Added: " label += files_added.length.to_s changes_html << "<tr><td>#{label}</td></tr>" end unless files_deleted.empty? label = "Files Deleted: " label += files_deleted.length.to_s changes_html << "<tr><td>#{label}</td></tr>" end unless files_replaced.empty? label = "Files Replaced: " label += files_replaced.length.to_s changes_html << "<tr><td>#{label}</td></tr>" end "<table>#{changes_html.join}</table>" end |