myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2430] trunk: switched sorting code to use site v


From: noreply
Subject: [myexperiment-hackers] [2430] trunk: switched sorting code to use site viewings/ downloads and removed SQL fragments from the config file
Date: Wed, 9 Jun 2010 01:11:32 -0400 (EDT)

Revision
2430
Author
dgc
Date
2010-06-09 01:11:32 -0400 (Wed, 09 Jun 2010)

Log Message

switched sorting code to use site viewings/downloads and removed SQL fragments from the config file

Modified Paths

Diff

Modified: trunk/app/models/contribution.rb (2429 => 2430)


--- trunk/app/models/contribution.rb	2010-06-09 05:11:21 UTC (rev 2429)
+++ trunk/app/models/contribution.rb	2010-06-09 05:11:32 UTC (rev 2430)
@@ -16,38 +16,79 @@
            :order => "created_at DESC",
            :dependent => :destroy
 
-  def self.contributions_list(klass = nil, params = nil, user = nil)
+  def self.order_options
+    [
+      {
+        "order"  => "rank DESC",
+        "option" => "rank",
+        "label"  => "Rank"
+      },
+      
+      {
+        "order"  => "label, rank DESC",
+        "option" => "title",
+        "label"  => "Title"
+      },
 
-    sort_options = Conf.contribution_order_options
+      {
+        "order"  => "created_at DESC, rank DESC",
+        "option" => "latest",
+        "label"  => "Latest"
+      },
 
-    args = sort_options.first
+      {
+        "order"  => "updated_at DESC, rank DESC",
+        "option" => "last_updated",
+        "label"  => "Last updated"
+      },
 
-    sort_options.each do |sort_option|
-      args = sort_option if params["order"] == sort_option["option"]
-    end
-    
-    num    = 10
-    offset = 0
+      {
+        "order"  => "rating DESC, rank DESC",
+        "option" => "rating",
+        "label"  => "Community rating"
+      },
 
-    if params["page"]
-      offset = (params["page"].to_i - 1) * num
-    end
+      {
+        "order"  => "viewings_count DESC, rank DESC",
+        "option" => "viewings",
+        "label"  => "Most viewed"
+      },
 
-    # This uses the proprietary MySQL feature "SQL_CALC_FOUND_ROWS" to
-    # determine the total number of rows if it weren't for the LIMIT clause
+      {
+        "order"  => "downloads_count DESC, rank DESC",
+        "option" => "downloads",
+        "label"  => "Most downloaded"
+      },
 
+      {
+        "joins"  => "LEFT OUTER JOIN content_types ON contributions.content_type_id = content_types.id",
+        "order"  => "content_types.title, rank DESC",
+        "option" => "type",
+        "label"  => "Type"
+      },
+
+      {
+        "joins"  => "LEFT OUTER JOIN licenses ON contributions.license_id = licenses.id",
+        "order"  => "licenses.title, rank DESC",
+        "option" => "licence",
+        "label"  => "Licence"
+      }
+    ]
+  end
+
+  def self.contributions_list(klass = nil, params = nil, user = nil)
+
+    sort_options = Contribution.order_options.find do |x| x["option"] == params["order"] end
+
+    sort_options ||= Contribution.order_options.first
+
     results = Authorization.authorised_index(klass,
         :all,
-        :select => 'SQL_CALC_FOUND_ROWS contributions.*',
         :authorised_user => user,
         :contribution_records => true,
-        :limit => "#{offset}, #{num}",
-        :joins => args["joins"],
-        :order => args["order"])
-
-    total = ActiveRecord::Base.connection.execute("SELECT FOUND_ROWS()").fetch_row.first.to_i
-
-    PaginatedArray.new(results, :total => total, :limit => num, :offset => offset)
+        :page => { :size => 10, :current => params["page"] },
+        :joins => sort_options["joins"],
+        :order => sort_options["order"])
   end
 
   # returns the 'most downloaded' Contributions

Modified: trunk/app/views/blobs/index.rhtml (2429 => 2430)


--- trunk/app/views/blobs/index.rhtml	2010-06-09 05:11:21 UTC (rev 2429)
+++ trunk/app/views/blobs/index.rhtml	2010-06-09 05:11:32 UTC (rev 2430)
@@ -13,7 +13,7 @@
 	<%= render :partial => "blobs/all_tags" %>
 <% end -%>
 
-<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions, :sort_by => Conf.contribution_order_options } %>
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions, :sort_by => Contribution.order_options } %>
 
 <%= render :partial => "contributions/list", :locals => { :collection => @contributions, :table => true } %>
 

Modified: trunk/app/views/packs/index.rhtml (2429 => 2430)


--- trunk/app/views/packs/index.rhtml	2010-06-09 05:11:21 UTC (rev 2429)
+++ trunk/app/views/packs/index.rhtml	2010-06-09 05:11:32 UTC (rev 2430)
@@ -33,7 +33,7 @@
 	<%= render :partial => "packs/all_tags" %>
 <% end -%>
 
-<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions, :sort_by => Conf.contribution_order_options } %>
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions, :sort_by => Contribution.order_options } %>
 
 <%= render :partial => "contributions/list", :locals => { :collection => @contributions, :table => true } %>
 

Modified: trunk/app/views/workflows/index.rhtml (2429 => 2430)


--- trunk/app/views/workflows/index.rhtml	2010-06-09 05:11:21 UTC (rev 2429)
+++ trunk/app/views/workflows/index.rhtml	2010-06-09 05:11:32 UTC (rev 2430)
@@ -15,7 +15,7 @@
 	<%= render :partial => "workflows/all_tags" %>
 <% end -%>
 
-<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions, :sort_by => Conf.contribution_order_options } %>
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions, :sort_by => Contribution.order_options } %>
 
 <%= render :partial => "contributions/list", :locals => { :collection => @contributions, :table => true } %>
 

Modified: trunk/config/default_settings.yml (2429 => 2430)


--- trunk/config/default_settings.yml	2010-06-09 05:11:21 UTC (rev 2429)
+++ trunk/config/default_settings.yml	2010-06-09 05:11:32 UTC (rev 2430)
@@ -421,43 +421,3 @@
 
 label_icons:
 
-contribution_order_options:
-
-  - option: rank
-    label:  Rank
-    order:  rank DESC
-
-  - option: title
-    label:  Title
-    order:  label, rank DESC
-    
-  - option: latest
-    label:  Latest
-    order:  created_at DESC, rank DESC
-    
-  - option: last_updated
-    label:  Last updated
-    order:  updated_at DESC, rank DESC
-    
-  - option: rating
-    label:  Community rating
-    order:  rating DESC, rank DESC
-    
-  - option: viewings
-    label:  Most viewed
-    order:  viewings_count DESC, rank DESC
-    
-  - option: downloads
-    label:  Most downloaded
-    order:  downloads_count DESC, rank DESC
-
-  - option: type
-    label:  Type
-    joins:  LEFT OUTER JOIN content_types ON contributions.content_type_id = content_types.id
-    order:  content_types.title, rank DESC
-
-  - option: licence
-    label:  Licence
-    joins:  LEFT OUTER JOIN licenses ON contributions.license_id = licenses.id
-    order:  licenses.title, rank DESC
-

Modified: trunk/lib/conf.rb (2429 => 2430)


--- trunk/lib/conf.rb	2010-06-09 05:11:21 UTC (rev 2429)
+++ trunk/lib/conf.rb	2010-06-09 05:11:32 UTC (rev 2430)
@@ -134,10 +134,6 @@
     self.fetch_entry('validate_email_veracity')
   end
 
-  def self.contribution_order_options
-    self.fetch_entry('contribution_order_options')
-  end
-
   # This method is required to create an administrator in the test fixtures
 
   def self.admins=(value)

reply via email to

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