Project

General

Profile

Actions

Defect #41880

closed

Plugin activity icons broken after switching to SVG icons

Added by Stefan Rinkes about 1 month ago. Updated 25 days ago.

Status:
Closed
Priority:
Normal
Category:
Plugin API
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

When a plugin is registered as ActivityProvider, their activities can't get an icon.
I already created the config/icon_source.yml and for the "menu :admin_menu" it works, thanks to #41715.
But no luck for the plugin activities.

In _activities.html.erb it gets the event and passes its type to get the icon, but it misses the info that the icon must be searched in the plugin assets.

  <%= activity_event_type_icon e.event_type %>

Is it not possible anymore or am I holding it wrong?


Files

activity_test.zip (6.59 KB) activity_test.zip Stefan Rinkes, 2024-12-02 10:27
clipboard-202412100153-xh5so.png (102 KB) clipboard-202412100153-xh5so.png Marius BĂLTEANU, 2024-12-10 00:53
0001-WIP.patch (2.63 KB) 0001-WIP.patch Marius BĂLTEANU, 2024-12-10 00:55
Actions #1

Updated by Marius BĂLTEANU about 1 month ago

  • Assignee set to Marius BĂLTEANU
  • Target version set to 6.0.2
Actions #2

Updated by Marius BĂLTEANU about 1 month ago

  • Status changed from New to Confirmed

Is your plugin open source to run a test?

Actions #3

Updated by Stefan Rinkes about 1 month ago

I compacted it in a minimal sample.
This should give you an activity entry in your first project.

The SVG-URL is for example: href="/assets/icons-xxxxx.svg#icon--test-activity"

But should be something like: href="/assets/plugin_assets/activity_test/icons-xxxxx.svg#icon--test-activity"

Actions #4

Updated by Marius BĂLTEANU about 1 month ago

Thanks! I will take a look these days.

Actions #5

Updated by Marius BĂLTEANU 27 days ago

I'm not sure which is the best solution that can be delivered in a patch version, any ideea is welcome!

Actions #6

Updated by Marius BĂLTEANU 27 days ago

Attached is one way to fix this:

Actions #7

Updated by Marius BĂLTEANU 27 days ago

  • File deleted (0001-WIP.patch)
Actions #9

Updated by Marius BĂLTEANU 26 days ago

  • Status changed from Confirmed to Resolved
  • Resolution set to Fixed

I've committed the fix.

Actions #10

Updated by Marius BĂLTEANU 26 days ago

  • Subject changed from Plugin Activity Icons broken with switch to SVGs to Plugin activity icons broken after switching to SVG icons
Actions #11

Updated by Marius BĂLTEANU 26 days ago

  • Status changed from Resolved to Closed
Actions #12

Updated by Stefan Rinkes 26 days ago

Marius BĂLTEANU wrote in #note-9:

I've committed the fix.

Awesome! Thanks :)

Actions #13

Updated by Stefan Rinkes 25 days ago

After trying it I don't think this is probably fixed.

I still see two issues:
  1. Looks to me you can now only have one plugin which registers as an ActivityProvider. Icons only work for one loaded plugin.
  1. We have a class which inherites from Journal, which acts_as_activity_provider for issues. So
    e.activity_provider_options.keys[0]
    ends up as 'issues' and not the wanted key.
Actions #14

Updated by Stefan Rinkes 25 days ago

I came up with this diff, so plugins can register like this for their classes:

Redmine::Activity.map do |activity|
  activity.register :test_activities, class_name: %w(TestActivity), plugin: :activity_test
end

Also works for multiple plugins with ActivityProviders.

---
 app/views/activities/_activities.html.erb |  2 +-
 lib/redmine/activity.rb                   | 15 +++++++++------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/app/views/activities/_activities.html.erb b/app/views/activities/_activities.html.erb
index 21ec1fb28..f2d8e22bd 100644
--- a/app/views/activities/_activities.html.erb
+++ b/app/views/activities/_activities.html.erb
@@ -4,7 +4,7 @@
 <dl>
 <% sort_activity_events(events_by_day[day]).each do |e, in_group| -%>
   <dt class="<%= e.event_type %> icon icon-<%= e.event_type %> <%= "grouped" if in_group %> <%= User.current.logged? && e.respond_to?(:event_author) && User.current == e.event_author ? 'me' : nil %>">
-  <%= activity_event_type_icon e.event_type, plugin: Redmine::Activity.plugin_name(e.activity_provider_options.keys[0]) %>
+  <%= activity_event_type_icon e.event_type, plugin: Redmine::Activity.plugin_name(e.class) %>
   <%= avatar(e.event_author) if e.respond_to?(:event_author) %>
   <span class="time"><%= format_time(e.event_datetime, false) %></span>
   <%= content_tag('span', e.project, :class => 'project') if @project.nil? || @project != e.project %>
diff --git a/lib/redmine/activity.rb b/lib/redmine/activity.rb
index 826b81c9e..3189f4fb1 100644
--- a/lib/redmine/activity.rb
+++ b/lib/redmine/activity.rb
@@ -19,11 +19,11 @@

 module Redmine
   module Activity
-    mattr_accessor :available_event_types, :default_event_types, :plugins_event_types, :providers
+    mattr_accessor :available_event_types, :default_event_types, :plugins_event_classes, :providers

     @@available_event_types = []
     @@default_event_types = []
-    @@plugins_event_types = {}
+    @@plugins_event_classes = {}
     @@providers = Hash.new {|h, k| h[k]=[]}

     class << self
@@ -41,19 +41,22 @@ module Redmine

         @@available_event_types << event_type unless @@available_event_types.include?(event_type)
         @@default_event_types << event_type unless options[:default] == false
-        @@plugins_event_types = { event_type => options[:plugin].to_s } unless options[:plugin].nil?
+        if options[:plugin]
+          providers.each do | provider |
+            @@plugins_event_classes[provider] = options[:plugin].to_s
+          end
+        end
         @@providers[event_type] += providers
       end

       def delete(event_type)
         @@available_event_types.delete event_type
         @@default_event_types.delete event_type
-        @@plugins_event_types.delete(event_type)
         @@providers.delete(event_type)
       end

-      def plugin_name(event_type)
-        @@plugins_event_types[event_type]
+      def plugin_name(class_name)
+        @@plugins_event_classes[class_name.to_s]
       end
     end
   end
-- 
2.43.0

Actions

Also available in: Atom PDF