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

[Ovirt-devel] [Patch] 1st pass at paging



For this first pass, I added paging to just one place (the host list in pool/show) so everyone could agree/disagree on the path. Once this is set, I can quickly add it in the various places it will be needed. Background: * I am using a rails plugin for the actual pagination called will_paginate. This basically extends active record by adding a wrapper to the find method. The license for this plugin has been approved by Brian Faustyn, who told me it was MIT and should be fine with our gpl code. * For the javascript, I am using jquery and a jquery plugin. These are also MIT licenses.

I have not included these libraries in the patch as they are 3rd party code ad I wasn't sure what our process was on that.. Just let me know if anyone wants them included in the patch.

-j


diff --git a/wui/src/app/controllers/host_controller.rb b/wui/src/app/controllers/host_controller.rb
index ae61144..84a8fc8 100644
--- a/wui/src/app/controllers/host_controller.rb
+++ b/wui/src/app/controllers/host_controller.rb
@@ -45,11 +45,15 @@ class HostController < ApplicationController
       else
         conditions = "hardware_pool_id is null"
         conditions += " or hardware_pool_id=#{pool.superpool_id}" if pool.superpool
-        @hosts = Host.find(:all, :conditions => conditions)
+        @hosts = Host.paginate(:page => params[:page], :order => 'hostname', :conditions => conditions)
       end
     else
       # no permissions here yet -- do we disable raw host list?
-      @hosts = Host.find(:all)
+      @hosts = Host.paginate(:page => params[:page], :order => 'hostname', :per_page =>1, :conditions => {'hardware_pool_id' => params[:id]})
+      respond_to do |format|
+        format.html {redirect_to(:controller => 'pool', :action => 'show', :id => params[:id])}
+        format.js { render :partial => '/host/list',:locals => { :hosts => @hosts } }
+      end
     end
   end
 
diff --git a/wui/src/app/controllers/pool_controller.rb b/wui/src/app/controllers/pool_controller.rb
index a9d4121..cc5eb83 100644
--- a/wui/src/app/controllers/pool_controller.rb
+++ b/wui/src/app/controllers/pool_controller.rb
@@ -80,7 +80,7 @@ class PoolController < AbstractPoolController
       redirect_to :controller => "dashboard"
     end
   end
-
+  
   private
   #filter methods
   def pre_new
@@ -97,6 +97,7 @@ class PoolController < AbstractPoolController
   end
   def pre_show
     @organizational_pool = OrganizationalPool.find(params[:id])
+    @hosts = @organizational_pool.hosts.paginate(:page =>1,:order =>'hostname',:per_page =>10)
     @perm_obj = @organizational_pool
   end
 end
diff --git a/wui/src/app/models/network_map.rb b/wui/src/app/models/network_map.rb
index 7461149..7f0b8c6 100644
--- a/wui/src/app/models/network_map.rb
+++ b/wui/src/app/models/network_map.rb
@@ -18,7 +18,13 @@
 # also available at http://www.gnu.org/copyleft/gpl.html.
 
 class NetworkMap < HardwarePool
-
+#  this is an optional way we can set the number of results per page
+#  when using pagination if we don't want to put it in the call as was 
+#  done in the first cut
+#  def self.per_page
+#    1
+#  end
+  
   belongs_to :organizational_pool, :class_name => "OrganizationalPool", :foreign_key => "superpool_id"
   has_many :host_collections, :class_name => "HostCollection", :foreign_key => "superpool_id", :dependent => :nullify
 
diff --git a/wui/src/app/views/host/_list.rhtml b/wui/src/app/views/host/_list.rhtml
index 78fee6a..aa748f9 100644
--- a/wui/src/app/views/host/_list.rhtml
+++ b/wui/src/app/views/host/_list.rhtml
@@ -30,5 +30,9 @@
 <% end -%>
 </tr>
 <% end %>
+<tr>
+  <td colspan="7"><%= will_paginate @hosts, :params => {:controller =>'host', :action => :list} %></td>
+</tr>
 <tbody>
 </table>
+
diff --git a/wui/src/app/views/layouts/default.rhtml b/wui/src/app/views/layouts/default.rhtml
index 5f8a1ce..c6b5816 100644
--- a/wui/src/app/views/layouts/default.rhtml
+++ b/wui/src/app/views/layouts/default.rhtml
@@ -6,7 +6,7 @@
   <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
   <title><%= yield :title -%></title>
   <%= stylesheet_link_tag 'default' %>
-  <%= javascript_include_tag "prototype" -%>
+  <%= javascript_include_tag 'jquery.pack.js', 'jquery.livequery.js', 'application' %><!--%= javascript_include_tag "prototype" -%-->
   <%= yield :scripts -%>
 </head>
 <body>
diff --git a/wui/src/app/views/pool/show.rhtml b/wui/src/app/views/pool/show.rhtml
index 8f1ddf1..33ca96f 100644
--- a/wui/src/app/views/pool/show.rhtml
+++ b/wui/src/app/views/pool/show.rhtml
@@ -10,14 +10,13 @@
               <%= render :partial => "/layouts/hardware_pool_type_list", :locals => { :network_maps => @organizational_pool.network_maps, :host_collections => @organizational_pool.host_collections } %>
 
             </div> <!-- end .dataTable -->
-
-
+            
             <div class="data-section">
               <div class="data-section-header"><strong>Available Hosts (<%= @organizational_pool.hosts.size -%>)</strong></div>
               <div class="data-section-stats">Statistics Data</div>
               <div class="data-section-table">
-                <div class="inside">
-                <%= render :partial => "/host/list", :locals => { :hosts => @organizational_pool.hosts } %>
+                <div class="inside" id="host-list">
+                <%= render :partial => "/host/list", :locals => { :hosts => @hosts } %>
                 </div>
               </div>
             </div>
diff --git a/wui/src/public/javascripts/application.js b/wui/src/public/javascripts/application.js
index fe45776..5df7242 100644
--- a/wui/src/public/javascripts/application.js
+++ b/wui/src/public/javascripts/application.js
@@ -1,2 +1,12 @@
 // Place your application-specific JavaScript functions and classes here
 // This file is automatically included by javascript_include_tag :defaults
+jQuery.ajaxSetup({ 
+  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} 
+})
+
+jQuery(document).ready(function($) {
+  $('div.pagination a').livequery('click', function() {
+    $('#host-list').load(this.href);
+    return false;
+  })
+})
\ No newline at end of file

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