Skip to content

Commit

Permalink
Merge pull request #1073 from ElixirTeSS/activities-refactor
Browse files Browse the repository at this point in the history
Activities refactor
  • Loading branch information
fbacall authored Jan 6, 2025
2 parents 5bb5b1f + 0ed9f0b commit 1cd7517
Show file tree
Hide file tree
Showing 91 changed files with 351 additions and 476 deletions.
13 changes: 9 additions & 4 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
class ActivitiesController < ApplicationController

before_action :set_resource, only: [:index]
before_action :set_breadcrumbs
before_action :set_breadcrumbs, only: [:index]

MODELS = %w[content_provider material collection event node workflow source learning_path learning_path_topic].freeze

def show
raise ActionController::RoutingError.new("") unless current_user&.is_admin?
@activity = PublicActivity::Activity.find(params[:id])
end

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
2 changes: 1 addition & 1 deletion app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def item_class
return Material if TeSS::Config.feature['materials']
end

raise ActiveRecord::AccessDenied
raise ActionController::RoutingError.new('Unrecognized type')
end

# Delete the reviewed but unselected items (if they exist)
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/concerns/topic_curation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def add_data
#puts "RESOURCE: #{resource.inspect}"
authorize resource, :update?

log_params = {data_field: params[:data_field],
data_value: params[:data_value]}
log_params = { data_field: params[:data_field],
data_value: resource.edit_suggestion.data_fields[params[:data_field]] }

resource.edit_suggestion.accept_data(params[:data_field])
resource.create_activity :add_data,
Expand All @@ -68,8 +68,8 @@ def reject_data
resource = instance_variable_get("@#{controller_name.singularize}")
authorize resource, :update?

log_params = {data_field: params[:data_field],
data_value: params[:data_value]}
log_params = { data_field: params[:data_field],
data_value: resource.edit_suggestion.data_fields[params[:data_field]] }

resource.edit_suggestion.reject_data(params[:data_field])
resource.create_activity :reject_data,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/resolution_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def parse_identifier
if matches
@identifier = matches
else
raise ActionController:RoutingError
raise ActionController::RoutingError.new('Unrecognized identifier')
end
end
end
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 %>
8 changes: 2 additions & 6 deletions app/views/activities/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<%#= render_activities(@activities, layout: :activity) %>
<h1>Activity</h1>

<% @resource.activities.each do |activity| %>
<div class="activity">
<%= render_activity(activity) %>
</div>
<% end %>
<%= render_activity(@activity, layout: :activity, display: "common/#{@activity.key.split('.').last}") %>
2 changes: 1 addition & 1 deletion app/views/layouts/_activity.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% content = yield %>
<% unless content.strip.blank? %>
<% unless content&.strip.blank? %>
<div class="activity">
<%= content %>
</div>
Expand Down
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') %> <em><%= activity.parameters[:data_field] %></em>: <strong><%= activity.parameters[:data_value] %></strong>
<%= 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') %> <em><%= activity.parameters[:data_field] %></em>: <strong><%= activity.parameters[:data_value] %></strong>
<%= 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.

Loading

0 comments on commit 1cd7517

Please sign in to comment.