myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2413] trunk/app/controllers/networks_controller.


From: noreply
Subject: [myexperiment-hackers] [2413] trunk/app/controllers/networks_controller.rb: fixed content type sorting option when some items don' t have a content_type
Date: Tue, 25 May 2010 06:27:44 -0400 (EDT)

Revision
2413
Author
dgc
Date
2010-05-25 06:27:43 -0400 (Tue, 25 May 2010)

Log Message

fixed content type sorting option when some items don't have a content_type

Modified Paths

Diff

Modified: trunk/app/controllers/networks_controller.rb (2412 => 2413)


--- trunk/app/controllers/networks_controller.rb	2010-05-25 10:22:03 UTC (rev 2412)
+++ trunk/app/controllers/networks_controller.rb	2010-05-25 10:27:43 UTC (rev 2413)
@@ -246,7 +246,7 @@
       ["last_updated",  "Last updated"],
       ["rating",        "User rating"],
       ["licence",       "Licence"],
-      ["workflow_type", "Workflow Type"]
+      ["content_type",  "Content Type"]
     ]
 
     @shared_items = @network.shared_contributions
@@ -309,14 +309,25 @@
         end
       end
 
-      when "workflow_type"; @shared_items.sort! do |a, b|
-        if a.contributable.content_type == b.contributable.content_type
+      when "content_type"; @shared_items.sort! do |a, b|
+
+        a_has_content_type = a.contributable.respond_to?('content_type')
+        b_has_content_type = b.contributable.respond_to?('content_type')
+
+        if (a_has_content_type && b_has_content_type)
+          if a.contributable.content_type == b.contributable.content_type
+            a.rank <=> b.rank
+          else
+            a.contributable.content_type.title <=> b.contributable.content_type.title
+          end
+        elsif (a_has_content_type && !b_has_content_type)
+          -1
+        elsif (!a_has_content_type && b_has_content_type)
+          1
+        else
           a.rank <=> b.rank
-        else
-          a.contributable.content_type.title <=> b.contributable.content_type.title
         end
       end
-
     end
 
     respond_to do |format|

reply via email to

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