Skip to content

Commit

Permalink
DRY up activity partials
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacall committed Dec 10, 2024
1 parent c286957 commit 7063644
Show file tree
Hide file tree
Showing 81 changed files with 205 additions and 458 deletions.
6 changes: 3 additions & 3 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class ActivitiesController < ApplicationController

def index
if request.xhr?
@activities = PublicActivity::Activity.order('created_at desc')
@activities = @resource.activities.order('created_at desc')
respond_to do |format|
format.html { render partial: 'activities/activity_log', locals: { resource: @resource } }
format.html { render partial: 'activities/activity_log', locals: { activities: @activities } }
end
else
@activities = PublicActivity::Activity.order('created_at desc').paginate(page: params[:page], per_page: 50)
@activities = @resource.activities.order('created_at desc').paginate(page: params[:page], per_page: 50)
respond_to do |format|
format.html
end
Expand Down
20 changes: 20 additions & 0 deletions app/helpers/activity_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# The helper for PublicActivity

module ActivityHelper
def activity_owner(activity)
if activity.owner
link_to activity.owner.username, activity.owner
else
t('activity.deleted_owner')
end
end

def activity_resource(activity)
if activity.trackable
title_field = activity.trackable.is_a?(User) ? :name : :title
link_to activity.trackable.send(title_field), activity.trackable
else
t('activity.deleted_trackable')
end
end
end
24 changes: 8 additions & 16 deletions app/views/activities/_activity_log.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
<%# Activity log partial that renders activity log for a resource.
Variables that should be available
- resource - resource whose activity log is being displayed (a material, a content provider, etc...)
%>
<% unless resource.blank? %>
<div class="activity">
<% if resource.activities.blank? %>
<p class="empty">No activities recorded.</p>
<% else %>
<% resource.activities.order(created_at: :desc).each do |activity| %>
<%= render_activity(activity, layout: :activity) %>
<% end %>
<% end %>
</div>
<% end %>
<%# Activity log partial that renders activity log for a resource.%>
<% if activities.blank? %>
<p class="empty"><%= t('activity.empty') %></p>
<% else %>
<% activities.each do |activity| %>
<%= render_activity(activity, layout: :activity, display: "common/#{activity.key.split('.').last}") %>
<% end %>
<% end %>
11 changes: 1 addition & 10 deletions app/views/activities/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@

<%= will_paginate @activities, param_name: 'page', renderer: BootstrapPagination::Rails %>

<% @activities.each do |activity| %>
<div class="activity">
<% if activity.owner -%>
<%= link_to activity.owner[:username], activity.owner %>
<% else -%>
Someone
<% end -%>
<%= render_activity activity %>
</div>
<% end %>
<%= render partial: 'activities/activity_log', locals: { activities: @activities } %>

<%= will_paginate @activities, param_name: 'page', renderer: BootstrapPagination::Rails %>
7 changes: 0 additions & 7 deletions app/views/activities/show.html.erb

This file was deleted.

12 changes: 0 additions & 12 deletions app/views/public_activity/collection/_add_event.html.erb

This file was deleted.

15 changes: 0 additions & 15 deletions app/views/public_activity/collection/_add_item.html.erb

This file was deleted.

12 changes: 0 additions & 12 deletions app/views/public_activity/collection/_add_material.html.erb

This file was deleted.

9 changes: 0 additions & 9 deletions app/views/public_activity/collection/_create.html.erb

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/public_activity/collection/_destroy.html.erb

This file was deleted.

8 changes: 0 additions & 8 deletions app/views/public_activity/collection/_update.html.erb

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions app/views/public_activity/common/_add_data.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.data_suggestion_add') %> <b><%= activity.parameters[:name] %></b>
<%= t('activity.target_html', resource: activity_resource(activity)) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
6 changes: 6 additions & 0 deletions app/views/public_activity/common/_add_event.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.add') %> <%= Event.model_name.human.downcase %> <%= link_to activity.parameters[:event_title],
event_path(activity.parameters[:event_id]) %>
<%= t('activity.target_html', resource: activity_resource(activity)) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
8 changes: 8 additions & 0 deletions app/views/public_activity/common/_add_item.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<% type = activity.parameters[:resource_type].constantize %>
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.add') %> <%= type.model_name.human.downcase %> <%= link_to activity.parameters[:resource_title],
polymorphic_path(type.model_name.singular.to_sym,
id: activity.parameters[:resource_id]) %>
<%= t('activity.target_html', resource: activity_resource(activity)) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
6 changes: 6 additions & 0 deletions app/views/public_activity/common/_add_material.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.add') %> <%= Material.model_name.human.downcase %> <%= link_to activity.parameters[:material_title],
material_path(activity.parameters[:material_id]) %>
<%= t('activity.target_html', resource: activity_resource(activity)) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
5 changes: 5 additions & 0 deletions app/views/public_activity/common/_add_term.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.term_suggestion_add', field: activity.parameters[:field].try(:singularize)) %> <b><%= activity.parameters[:name] %></b>
<%= t('activity.target_html', resource: activity_resource(activity)) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
6 changes: 6 additions & 0 deletions app/views/public_activity/common/_add_to_collection.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% return unless activity.parameters.present? %>
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.add') %> <%= activity_resource(activity) %>
<%= t('activity.target_html', resource: link_to(activity.parameters[:collection_title], collection_path(activity.parameters[:collection_id]))) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
6 changes: 6 additions & 0 deletions app/views/public_activity/common/_add_to_topic.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% return unless activity.parameters.present? %>
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.add') %> <%= activity_resource(activity) %>
<%= t('activity.target_html', resource: link_to(activity.parameters[:topic_title], learning_path_topic_path(activity.parameters[:topic_id]))) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
6 changes: 6 additions & 0 deletions app/views/public_activity/common/_add_topic.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.add_topic_html',
resource: activity_resource(activity),
topic: link_to(activity.parameters[:topic_title], learning_path_topic_path(activity.parameters[:topic_id]))) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.approval_status_change_html',
source: activity_resource(activity),
status: source_approval_badge(activity.parameters[:new])) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
7 changes: 7 additions & 0 deletions app/views/public_activity/common/_change_role.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.change_role_html',
user: activity_resource(activity),
old: Role.find_by_id(activity.parameters[:old])&.title || activity.parameters[:old],
new: Role.find_by_id(activity.parameters[:new])&.title || activity.parameters[:new]) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
4 changes: 4 additions & 0 deletions app/views/public_activity/common/_create.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<i class="fa fa-plus-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.create') %> <%= activity_resource(activity) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
4 changes: 4 additions & 0 deletions app/views/public_activity/common/_destroy.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<i class="fa fa-trash-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.destroy') %> <%= activity_resource(activity) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<i class="fa fa-pencil-square-o"></i>

<% if activity.owner %>
<%= link_to activity.owner.username, activity.owner %>
<% end %>

modified the workflow diagram at <%= activity.created_at -%>.
<%= activity_owner(activity) %>
<%= t('activity.actions.workflows.modify_diagram') %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
<ul>
<% [:added_nodes, :removed_nodes, :modified_nodes].each do |key| %>
<% if activity.parameters[key].any? %>
<li>
<%= key.to_s.sub('_nodes','').capitalize %> <%= pluralize(activity.parameters[key].count, 'node') %>:
<%= t("activity.actions.workflows.#{key}") %> <%= pluralize(activity.parameters[key].count, t('activity.actions.workflows.node')) %>:
<%= activity.parameters[key].map { |n| "'#{n['data']['name']}'" }.join(', ') %>
</li>
<% end %>
Expand Down
8 changes: 0 additions & 8 deletions app/views/public_activity/common/_parameter_change.html.erb

This file was deleted.

5 changes: 5 additions & 0 deletions app/views/public_activity/common/_reject_data.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<i class="fa fa-trash-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.data_suggestion_reject') %> <b><%= activity.parameters[:name] %></b>
<%= t('activity.target_html', resource: activity_resource(activity)) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
5 changes: 5 additions & 0 deletions app/views/public_activity/common/_reject_term.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<i class="fa fa-trash-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.term_suggestion_reject', field: activity.parameters[:field].try(:singularize)) %> <b><%= activity.parameters[:name] %></b>
<%= t('activity.target_html', resource: activity_resource(activity)) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
4 changes: 4 additions & 0 deletions app/views/public_activity/common/_report.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.report') %> <%= activity_resource(activity) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
4 changes: 4 additions & 0 deletions app/views/public_activity/common/_update.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<i class="fa fa-pencil-square-o"></i>
<%= activity_owner(activity) %>
<%= t('activity.actions.update') %> <%= activity_resource(activity) %>
<%= t('activity.timestamp', time: activity.created_at) -%>.
18 changes: 18 additions & 0 deletions app/views/public_activity/common/_update_parameter.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% parameters = activity.parameters %>
<% return if parameters.empty? %>
<% return if activity.trackable.is_a?(Event) &&
Event::SENSITIVE_FIELDS.include?(parameters[:attr].to_sym) &&
!policy(activity.trackable).edit_report? %>

<div class="sub-activity">
<% if parameters[:association_name] -%>
<%= t('activity.actions.association_change_html',
parameter: parameters[:attr].humanize,
name: parameters[:association_name],
value: parameters[:new_val]) %>
<% else %>
<%= t('activity.actions.parameter_change_html',
parameter: parameters[:attr].humanize,
value: parameters[:new_val]) %>
<% end %>
</div>
8 changes: 0 additions & 8 deletions app/views/public_activity/content_provider/_create.html.erb

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/public_activity/content_provider/_destroy.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/public_activity/content_provider/_update.html.erb

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions app/views/public_activity/event/_add_data.html.erb

This file was deleted.

8 changes: 0 additions & 8 deletions app/views/public_activity/event/_add_term.html.erb

This file was deleted.

12 changes: 0 additions & 12 deletions app/views/public_activity/event/_add_to_collection.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/public_activity/event/_create.html.erb

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/public_activity/event/_destroy.html.erb

This file was deleted.

Loading

0 comments on commit 7063644

Please sign in to comment.