ACK

----- Original Message -----
From: "Mohammed Morsi" <[email protected]>
To: [email protected]
Cc: [email protected], "Mohammed Morsi" <[email protected]>
Sent: Friday, June 4, 2010 4:07:56 PM GMT +01:00 Amsterdam / Berlin / Bern / 
Rome / Stockholm / Vienna
Subject: [PATCH aggregator] instances index/list view and backend (revision 2)

---
 src/app/controllers/instance_controller.rb |   36 ++++++++++++++++++++++++++++
 src/app/views/dashboard/summary.haml       |    2 +
 src/app/views/instance/_list.html.erb      |   25 +++++++++++++++++++
 src/app/views/instance/index.html.erb      |    3 +-
 4 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 src/app/views/instance/_list.html.erb

diff --git a/src/app/controllers/instance_controller.rb 
b/src/app/controllers/instance_controller.rb
index c898691..d01cb10 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -27,6 +27,42 @@ class InstanceController < ApplicationController
   def index
   end
 
+  def paginated
+    # datatables sends pagination in format:
+    #   iDisplayStart - start index
+    #   iDisplayLength - num of recs
+    # => we need to count page num
+    page = params[:iDisplayStart].to_i / Instance::per_page
+
+    order_col_rec = Instance::COLUMNS[params[:iSortCol_0].to_i]
+    order_col = Instance::COLUMNS[2] unless order_col_rec && 
order_col_rec[:opts][:searchable]
+    order = order_col[:id] + " " + (params[:sSortDir_0] == 'desc' ? 'desc' : 
'asc')
+
+    # FIXME only return those instances in pools which user has instance_view
+    @instances = Instance.search_filter(params[:sSearch], 
Instance::SEARCHABLE_COLUMNS).paginate(
+      :page => page + 1,
+      :order => order
+    )
+
+    recs = @instances.map do |i|
+      [
+        i.id,
+        i.get_action_list.map {|action| "<a href=\"#{url_for :controller => 
"instance", :action => "instance_action", :id => i.id, :instance_action => 
action}\">#{action}</a>"}.join(" | "),
+        i.name,
+        i.state,
+        i.hardware_profile.name,
+        i.image.name
+      ]
+    end
+
+    render :json => {
+      :sEcho => params[:sEcho],
+      :iTotalRecords => @instances.total_entries,
+      :iTotalDisplayRecords => @instances.total_entries,
+      :aaData => recs
+    }
+  end
+
   # Right now this is essentially a duplicate of PoolController#show,
     # but really it should be a single instance should we decide to have a page
     # for that.  Redirect on create was all that brought you here anyway, so
diff --git a/src/app/views/dashboard/summary.haml 
b/src/app/views/dashboard/summary.haml
index f3d6ab6..d8b9e20 100644
--- a/src/app/views/dashboard/summary.haml
+++ b/src/app/views/dashboard/summary.haml
@@ -38,6 +38,8 @@
       Create a Template
     %a{:href => url_for(:controller => "users", :action => "new")}
       Create a User
+    %a{:href => url_for(:controller => "instance", :action => "index")}
+      View Instances
   - else
     %a{:href => url_for(:controller => "", :action => "")}
       Launch Instances
diff --git a/src/app/views/instance/_list.html.erb 
b/src/app/views/instance/_list.html.erb
new file mode 100644
index 0000000..9d12c76
--- /dev/null
+++ b/src/app/views/instance/_list.html.erb
@@ -0,0 +1,25 @@
+<%= datatable(
+  Instance::COLUMNS.map {|c| c[:opts]},
+  {
+    :table_dom_id => 'instances_table',
+    :per_page => Instance::per_page,
+    :sort_by => "[3, 'asc']",
+    :serverside => true,
+    :ajax_source => url_for(:controller => 'instance', :action => 'paginated'),
+    :append => ".fnSetFilteringDelay()",
+    :persist_state => false,
+    :click_callback => "function(ev) {clickRow(ev);}",
+  }
+) %>
+
+<table class="datatable display" id="instances_table">
+  <thead>
+    <tr>
+        <% Instance::COLUMNS.each do |c| %>
+          <%= "<th>#{c[:header]}</th>" %>
+        <% end %>
+    </tr>
+  </thead>
+  <tbody>
+  </tbody>
+</table>
diff --git a/src/app/views/instance/index.html.erb 
b/src/app/views/instance/index.html.erb
index a632f6c..c19c3fa 100644
--- a/src/app/views/instance/index.html.erb
+++ b/src/app/views/instance/index.html.erb
@@ -1,2 +1 @@
-<h1>Instance#index</h1>
-<p>Find me in app/views/instance/index.html.erb</p>
+<%= render :partial => 'list' %>
-- 
1.6.2.5

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to