summaryrefslogtreecommitdiff
path: root/app/helpers/node_actions_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/node_actions_helper.rb')
-rw-r--r--app/helpers/node_actions_helper.rb87
1 files changed, 86 insertions, 1 deletions
diff --git a/app/helpers/node_actions_helper.rb b/app/helpers/node_actions_helper.rb
index 019a9cf7..672dda36 100644
--- a/app/helpers/node_actions_helper.rb
+++ b/app/helpers/node_actions_helper.rb
@@ -23,7 +23,10 @@ module NodeActionsHelper
23 "user_deactivate" => "user-off", 23 "user_deactivate" => "user-off",
24 "user_reactivate" => "user-check", 24 "user_reactivate" => "user-check",
25 "redaktion_grant" => "users-plus", 25 "redaktion_grant" => "users-plus",
26 "redaktion_revoke" => "users-minus" 26 "redaktion_revoke" => "users-minus",
27 "event_create" => "calendar-plus",
28 "event_update" => "calendar-event",
29 "event_destroy" => "calendar-x"
27 }.freeze 30 }.freeze
28 31
29 def verb_icon action 32 def verb_icon action
@@ -57,6 +60,7 @@ module NodeActionsHelper
57 def action_details? action 60 def action_details? action
58 m = action.metadata 61 m = action.metadata
59 return true if m["translation_diff"].present? 62 return true if m["translation_diff"].present?
63 return true if m["changes"].present? || m["description_changed"]
60 return true if m["title"].is_a?(Hash) && m.dig("title", "from") != m.dig("title", "to") 64 return true if m["title"].is_a?(Hash) && m.dig("title", "from") != m.dig("title", "to")
61 %w[author tags template_changed assets assets_changed assets_reordered 65 %w[author tags template_changed assets assets_changed assets_reordered
62 abstract_changed body_changed].any? { |key| m[key].present? } 66 abstract_changed body_changed].any? { |key| m[key].present? }
@@ -92,6 +96,59 @@ module NodeActionsHelper
92 items 96 items
93 end 97 end
94 98
99 def event_changes_list action
100 m = action.metadata
101 c = m["changes"] || {}
102 items = []
103
104 if c["title"]
105 items << t("node_actions.detail_title",
106 :from => c.dig("title", "from"), :to => c.dig("title", "to"))
107 end
108
109 if %w[rrule start_time end_time].any? { |field| c.key?(field) }
110 items << t("node_actions.detail_event_schedule",
111 :from => event_schedule_side(m, c, "from"),
112 :to => event_schedule_side(m, c, "to"))
113 end
114
115 if c["allday"]
116 items << t("node_actions.detail_event_allday",
117 :from => t("admin.common.#{c.dig("allday", "from") ? "yes" : "no"}"),
118 :to => t("admin.common.#{c.dig("allday", "to") ? "yes" : "no"}"))
119 end
120
121 %w[location url].each do |field|
122 next unless c[field]
123 items << t("node_actions.detail_event_#{field}",
124 :from => c.dig(field, "from").presence || t("node_actions.event_none"),
125 :to => c.dig(field, "to").presence || t("node_actions.event_none"))
126 end
127
128 if c["tags"]
129 items << t("node_actions.detail_tags",
130 :from => Array(c.dig("tags", "from")).join(", "),
131 :to => Array(c.dig("tags", "to")).join(", "))
132 end
133
134 if c["node_path"]
135 items << t("node_actions.detail_event_moved",
136 :from => c.dig("node_path", "from") || t("node_actions.event_none"),
137 :to => c.dig("node_path", "to") || t("node_actions.event_none"))
138 end
139
140 items << t("node_actions.detail_event_description") if m["description_changed"]
141 items << t("node_actions.detail_event_coordinates") if c["latitude"] || c["longitude"]
142 items
143 end
144
145 def event_schedule_side metadata, changes, side
146 attributes = %w[rrule start_time end_time].each_with_object({}) do |field, acc|
147 acc[field.to_sym] = changes.key?(field) ? changes.dig(field, side) : metadata[field]
148 end
149 event_schedule_text(Event.new(attributes)).presence || t("node_actions.event_none")
150 end
151
95 def translation_changes diff 152 def translation_changes diff
96 case diff["status"] 153 case diff["status"]
97 when "added" then [t("node_actions.locale_added", :title => diff.dig("title", "to"))] 154 when "added" then [t("node_actions.locale_added", :title => diff.dig("title", "to"))]
@@ -188,6 +245,12 @@ module NodeActionsHelper
188 participant ? link_to(name, edit_user_path(participant)) : name 245 participant ? link_to(name, edit_user_path(participant)) : name
189 end 246 end
190 247
248 def event_ref action
249 event = action.action_participants.detect { |p| p.subject_type == "Event" }&.subject
250 name = h(action.metadata["event_title"].presence || t("node_actions.unknown_event"))
251 event ? link_to(name, edit_event_path(event)) : name
252 end
253
191 def summarize_publish action 254 def summarize_publish action
192 if action.metadata["via"] == "revision" 255 if action.metadata["via"] == "revision"
193 t("node_actions.publish_rollback", 256 t("node_actions.publish_rollback",
@@ -301,4 +364,26 @@ module NodeActionsHelper
301 t("node_actions.user_create", :actor => actor_ref(action), 364 t("node_actions.user_create", :actor => actor_ref(action),
302 :target => user_participant_ref(action)).html_safe 365 :target => user_participant_ref(action)).html_safe
303 end 366 end
367
368 def summarize_event_create action
369 event_sentence(action, "event_create")
370 end
371
372 def summarize_event_update action
373 event_sentence(action, "event_update")
374 end
375
376 def summarize_event_destroy action
377 event_sentence(action, "event_destroy")
378 end
379
380 def event_sentence action, key
381 if action.node
382 t("node_actions.#{key}_on", :actor => actor_ref(action),
383 :event => event_ref(action), :subject => subject_ref(action)).html_safe
384 else
385 t("node_actions.#{key}", :actor => actor_ref(action),
386 :event => event_ref(action)).html_safe
387 end
388 end
304end 389end