myexperiment-hackers
[Top][All Lists]
Advanced

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

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


From: noreply
Subject: [myexperiment-hackers] [2412] trunk/app/controllers/networks_controller.rb: fixed pack licence error and made rank a secondary sort criteria
Date: Tue, 25 May 2010 06:22:03 -0400 (EDT)

Revision
2412
Author
dgc
Date
2010-05-25 06:22:03 -0400 (Tue, 25 May 2010)

Log Message

fixed pack licence error and made rank a secondary sort criteria

Modified Paths

Diff

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


--- trunk/app/controllers/networks_controller.rb	2010-05-24 12:40:58 UTC (rev 2411)
+++ trunk/app/controllers/networks_controller.rb	2010-05-25 10:22:03 UTC (rev 2412)
@@ -245,7 +245,7 @@
       ["uploader",      "Uploader"],
       ["last_updated",  "Last updated"],
       ["rating",        "User rating"],
-      ["license",       "License"],
+      ["licence",       "Licence"],
       ["workflow_type", "Workflow Type"]
     ]
 
@@ -266,7 +266,11 @@
       end
 
       when "uploader"; @shared_items.sort! do |a, b|
-        a.contributor.label <=> b.contributor.label
+        if a.contributor.label == b.contributor.label
+          a.rank <=> b.rank
+        else
+          a.contributor.label <=> b.contributor.label
+        end
       end
 
       when "last_updated"; @shared_items.sort! do |a, b|
@@ -274,15 +278,43 @@
       end
 
       when "rating"; @shared_items.sort! do |a, b|
-        b.rating <=> a.rating
+
+        a_rating = a.rating
+        b_rating = b.rating
+
+        if a_rating == b_rating
+          a.rank <=> b.rank
+        else
+          b.rating <=> a.rating
+        end
       end
 
-      when "license"; @shared_items.sort! do |a, b|
-        a.contributable.license.title <=> b.contributable.license.title
+      when "licence"; @shared_items.sort! do |a, b|
+
+        a_has_licence = a.contributable.respond_to?('license')
+        b_has_licence = b.contributable.respond_to?('license')
+
+        if (a_has_licence && b_has_licence)
+          if a.contributable.license == b.contributable.license
+            a.rank <=> b.rank
+          else
+            a.contributable.license.title <=> b.contributable.license.title
+          end
+        elsif (a_has_licence && !b_has_licence)
+          -1
+        elsif (!a_has_licence && b_has_licence)
+          1
+        else
+          a.rank <=> b.rank
+        end
       end
 
       when "workflow_type"; @shared_items.sort! do |a, b|
-        a.contributable.content_type.title <=> b.contributable.content_type.title
+        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
       end
 
     end

reply via email to

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