myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [1923] branches/event_logging/app/helpers/applica


From: noreply
Subject: [myexperiment-hackers] [1923] branches/event_logging/app/helpers/application_helper.rb: News generation.
Date: Wed, 5 Nov 2008 08:56:16 -0500 (EST)

Revision
1923
Author
alekses6
Date
2008-11-05 08:56:16 -0500 (Wed, 05 Nov 2008)

Log Message

News generation. Added events about workflow versions - creates and updates. 

Duplicates check is also added so identical "events" at the same timestamp will not be shown.

Modified Paths

Diff

Modified: branches/event_logging/app/helpers/application_helper.rb (1922 => 1923)


--- branches/event_logging/app/helpers/application_helper.rb	2008-11-04 15:41:33 UTC (rev 1922)
+++ branches/event_logging/app/helpers/application_helper.rb	2008-11-05 13:56:16 UTC (rev 1923)
@@ -1554,7 +1554,11 @@
     }
     events.delete([])
     
-    # produce news from event list 
+    # produce news from event list;
+    # if enough events are available in the "events" array, this method will
+    # always produce "limit" number of news entries - considering authorization and possible
+    # event duplication, it will 'top-up' news entry collection until it finally has "limit" events;
+    # (and it will interpret ALL events in "events" array if "limit" is set to NIL
     rtn = []
     news_item = nil # contributor_news_from_log!() will return NIL if event is not to be added to the feed for the current user
     events.each do |e|
@@ -1563,7 +1567,26 @@
       
       # no need to interpret more events than is required by the method call;
       # -> therefore, stop once the desired number is reached
-      break if (rtn.length == limit)
+      # --> but still need to check if there are no duplicates, if this is the case,
+      # --> more iterations will be needed to 'top-up' the resulting set of news entries 
+      if (limit && rtn.length == limit)
+        
+        # first element in each item is the timestamp - these should be the same up
+        # to seconds & second element in each item is the "event" itself - these should be
+        # identical; if these two conditions are met - events are the same and one of these
+        # needs to be discarded
+        (limit-1).downto(1) do |i|
+          t_cur = rtn[i][0]
+          t_prev = rtn[i-1][0]
+          
+          if rtn[i][1] == rtn[i-1][1] && (t_cur.year == t_prev.year && t_cur.month == t_prev.month && 
+             t_cur.day == t_prev.day && t_cur.hour == t_prev.hour && t_cur.min == t_prev.min) 
+            rtn.delete_at(i)
+          end
+        end
+        
+        break if rtn.length == limit
+      end
     end
     
     return rtn
@@ -1604,10 +1627,47 @@
     
     
     case loggable_type.to_s
-      when "Workflow", "Blob", "Pack"
+      when "Workflow::Version"
         case action
           when "create", "update"
             begin
+              # check if the workflow version can still be found;
+              # (can skip check on the workflow itself, because versions can't exist without "parent" workflow)
+              wf_version = Workflow::Version.find(log_entry.activity_loggable_id, :include => :workflow)
+              wf_version_number = wf_version.version
+              main_wf = wf_version.workflow
+              
+              authorized = my_event || main_wf.authorized?("view", current_viewer)
+              return nil unless authorized
+              
+              # display name is always the title of the latest version
+              workflow_path = workflow_path(wf_version.workflow_id)
+              workflow_visible_name = contributable_name_from_instance(main_wf)
+              if wf_version_number > 1 || action == "update"
+                workflow_path += "?version=#{wf_version_number}"
+              end
+              
+              if authorized
+                if action == "create" && wf_version.version == 1
+                  # new workflow created
+                  rtn << [timestamp, "#{culprit_link} <span class='news_feed_action'>created</span> the #{link_to workflow_visible_name, workflow_path} Workflow."]
+                elsif action == "create"
+                  # added new version for existing workflow
+                  rtn << [timestamp, "#{culprit_link} <span class='news_feed_action'>added</span> version #{wf_version_number} of the #{link_to workflow_visible_name, workflow_path} Workflow."]
+                elsif action == "update" 
+                  # updated an existing version
+                  rtn << [timestamp, "#{culprit_link} <span class='news_feed_action'>updated</span> version #{wf_version_number} of the #{link_to workflow_visible_name, workflow_path} Workflow."]
+                end
+              end
+            rescue ActiveRecord::RecordNotFound
+              # do nothing, but don't display the news entry for missing workflow / version
+            end
+        end
+      
+      when "Blob", "Pack"
+        case action
+          when "create", "update"
+            begin
               # check if contributable can still be found
               object, object_path = evaluate_object_instance_and_path(log_entry.activity_loggable_type, log_entry.activity_loggable_id)
               object_visible_name = contributable_name_from_instance(object)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]