Modified: branches/event_logging/app/helpers/application_helper.rb (1861 => 1862)
--- branches/event_logging/app/helpers/application_helper.rb 2008-10-15 09:53:22 UTC (rev 1861)
+++ branches/event_logging/app/helpers/application_helper.rb 2008-10-15 12:08:40 UTC (rev 1862)
@@ -1462,12 +1462,14 @@
case loggable_type.to_s
when "Workflow", "Blob", "Pack"
+ # TODO: check that the event is still valid
case action
when "create", "update"
rtn << [timestamp, "#{name(log_entry.culprit_id)} #{action}d the #{contributable(log_entry.activity_loggable_id, loggable_type)} #{model_visible_name(loggable_type.to_s)}."]
end
when "Membership"
+ # TODO: check that the event is still valid
if action == "accept"
# this membership record contains ID of the relevant user, but was that the user who
# accepted the membership or the "network" (i.e. the network admin - currently networks have only 1 admin)
@@ -1482,13 +1484,19 @@
end
when "Friendship"
+ # TODO: check that the event is still valid
if action == "accept"
rtn << [timestamp, "#{name(log_entry.culprit_id)} and #{name(log_entry.referenced_id)} became friends."]
end
when "Network"
if action == "create"
- rtn << [timestamp, "#{name(log_entry.culprit_id)} created the #{title(log_entry.referenced_id)} Group."]
+ begin
+ network = Network.find(log_entry.activity_loggable_id)
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} created the #{link_to(h(network.title), group_path(network))} Group."]
+ rescue ActiveRecord::RecordNotFound
+ # do nothing, but don't display the news entry for missing group
+ end
end
when "GroupAnnouncement"
@@ -1508,8 +1516,7 @@
when "create", "update"
begin
rating = Rating.find(log_entry.activity_loggable_id)
- object = eval("#{log_entry.referenced_type}.find(#{log_entry.referenced_id})")
- object_path = eval("#{model_visible_name(log_entry.referenced_type.to_s).downcase}_path(#{log_entry.referenced_id})")
+ object, object_path = evaluate_object_instance_and_path(log_entry.referenced_type, log_entry.referenced_id)
rtn << [timestamp, "#{name(log_entry.culprit_id)} rated #{link_to object.title, object_path} #{model_visible_name(log_entry.referenced_type.to_s)} #{rating.rating} out of 5"]
rescue ActiveRecord::RecordNotFound
@@ -1521,29 +1528,69 @@
when "Bookmark"
+ if action == "create"
+ begin
+ # information from the actual bookmark instance is not used directly, however if that was removed -
+ # RecordNotFound exception will be thrown and the news item won't appear
+ bookmark = Bookmark.find(log_entry.activity_loggable_id)
+ object, object_path = evaluate_object_instance_and_path(log_entry.referenced_type, log_entry.referenced_id)
+
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} added #{link_to object.title, object_path} #{model_visible_name(log_entry.referenced_type.to_s)} to #{link_to "favourites", user_path(log_entry.culprit_id) + "/favourites"}"]
+ rescue ActiveRecord::RecordNotFound
+ # do nothing, but don't display the news entry for missing bookmark / object
+ end
+ end
when "Comment"
+ if action == "create"
+ begin
+ comment = Comment.find(log_entry.activity_loggable_id)
+ object, object_path = evaluate_object_instance_and_path(log_entry.referenced_type, log_entry.referenced_id)
+
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} #{link_to "commented", object_path + "#comment_" + comment.id.to_s} on #{link_to object.title, object_path} #{model_visible_name(log_entry.referenced_type.to_s)}"]
+ rescue ActiveRecord::RecordNotFound
+ # do nothing, but don't display the news entry for missing comment / object
+ end
+ end
when "Review"
+ if action == "create"
+ begin
+ # TODO
+ rescue ActiveRecord::RecordNotFound
+ # do nothing, but don't display the news entry for missing review / object
+ end
+ end
when "Creditation"
+ if action == "create"
+ begin
+ # TODO
+ rescue ActiveRecord::RecordNotFound
+ # do nothing, but don't display the news entry for missing creditation / object
+ end
+ end
-
when "Attribution"
+ if action == "create"
+ begin
+ # TODO
+ rescue ActiveRecord::RecordNotFound
+ # do nothing, but don't display the news entry for missing creditation / object
+ end
+ end
-
when "Tagging"
if action == "create"
begin
tagging = Tagging.find(log_entry.activity_loggable_id)
tag = Tag.find(tagging.tag_id)
- object = eval("#{log_entry.referenced_type}.find(#{log_entry.referenced_id})")
- object_path = eval("#{model_visible_name(log_entry.referenced_type.to_s).downcase}_path(#{log_entry.referenced_id})")
+ object, object_path = evaluate_object_instance_and_path(log_entry.referenced_type, log_entry.referenced_id)
- rtn << [timestamp, "#{name(log_entry.culprit_id)} tagged #{link_to object.title, object_path} #{model_visible_name(log_entry.referenced_type.to_s)} with #{link_to tag.name, tag_path(tag.id)}."]
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} tagged #{link_to object.title, object_path} #{model_visible_name(log_entry.referenced_type.to_s)} with \"#{link_to tag.name, tag_path(tag.id)}.\""]
rescue ActiveRecord::RecordNotFound
# do nothing, but don't display the news entry for missing tagging / tag / object
end
@@ -1565,7 +1612,15 @@
return rtn[0]
end
+
+ def evaluate_object_instance_and_path(model_name, id)
+ # evaluates the instance object and link to the page of it in the UI
+ instance = eval("#{model_name}.find(#{id})")
+ path = eval("#{model_visible_name(model_name).downcase}_path(#{id})")
+ return [instance, path]
+ end
+
######################################################
def contributor_news(contributor, before, after, depth, restrict_contributor)