---
src/app/controllers/instance_controller.rb | 26 ++++++++++++++++++++++++++
src/app/models/instance.rb | 1 +
src/app/views/dashboard/summary.haml | 2 ++
src/app/views/instance/_list.html.erb | 25 +++++++++++++++++++++++++
src/app/views/instance/index.html.erb | 3 +--
5 files changed, 55 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..eaeab35 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -27,6 +27,32 @@ 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
+ #@instances = Instance.list_for_user(current_user, Privilege::INSTANCE_VIEW)
+ @instances = Instance.search_filter(params[:sSearch],
Instance::SEARCHABLE_COLUMNS).paginate(
+ :page => page + 1,
+ :order => order
+ )
+
+ render :json => {
+ :sEcho => params[:sEcho],
+ :iTotalRecords => @instances.total_entries,
+ :iTotalDisplayRecords => @instances.total_entries,
+ :aaData => @instances.map {|i| [i.id, "", i.name, i.state,
i.hardware_profile.name, i.image.name]}
+ }
+ 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/models/instance.rb b/src/app/models/instance.rb
index 21a5cef..a3cf347 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -21,6 +21,7 @@
class Instance < ActiveRecord::Base
include SearchFilter
+ include PermissionedObject
cattr_reader :per_page
@@per_page = 15
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
Show replies by date