[ARVADOS] updated: 44e147b16322f9bdd4606cda7deec631b951ab06
git at public.curoverse.com
git at public.curoverse.com
Thu Mar 13 17:07:50 EDT 2014
Summary of changes:
.../app/controllers/application_controller.rb | 14 +++-
.../app/controllers/collections_controller.rb | 14 +++-
apps/workbench/app/models/arvados_api_client.rb | 8 ++
apps/workbench/app/models/arvados_resource_list.rb | 15 ++++
.../app/views/application/_paging.html.erb | 87 ++++++++++++++++++++
.../app/views/application/_show_recent.html.erb | 4 +
.../app/views/collections/_show_recent.html.erb | 6 +-
.../app/views/groups/_show_recent.html.erb | 4 +
.../views/pipeline_instances/_show_recent.html.erb | 4 +
.../views/pipeline_templates/_show_recent.html.erb | 4 +
10 files changed, 157 insertions(+), 3 deletions(-)
create mode 100644 apps/workbench/app/views/application/_paging.html.erb
via 44e147b16322f9bdd4606cda7deec631b951ab06 (commit)
from 18358de3cd35ef29e8826f45897a3373a79de291 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 44e147b16322f9bdd4606cda7deec631b951ab06
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Thu Mar 13 17:07:46 2014 -0400
* Added support for offset and limit query parameters (?limit=x&offset=y) to workbench index pages.
* Created _paging partial for rendering forward/backward/jump to page N
* Added paging to generic index page, index pages for collections, pipeline instances, pipeline templates, groups.
diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index 61351d6..d31ecd3 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -58,7 +58,19 @@ class ApplicationController < ActionController::Base
end
def index
- @objects ||= model_class.limit(200).all
+ if params[:limit]
+ limit = params[:limit].to_i
+ else
+ limit = 200
+ end
+
+ if params[:offset]
+ offset = params[:offset].to_i
+ else
+ offset = 0
+ end
+
+ @objects ||= model_class.limit(limit).offset(offset).all
respond_to do |f|
f.json { render json: @objects }
f.html { render }
diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index d46ec03..01abbb4 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -12,7 +12,19 @@ class CollectionsController < ApplicationController
Collection.where(any: ['contains', params[:search]])).
uniq { |c| c.uuid }
else
- @collections = Collection.limit(100)
+ if params[:limit]
+ limit = params[:limit].to_i
+ else
+ limit = 100
+ end
+
+ if params[:offset]
+ offset = params[:offset].to_i
+ else
+ offset = 0
+ end
+
+ @collections = Collection.limit(limit).offset(offset)
end
@links = Link.limit(1000).
where(head_uuid: @collections.collect(&:uuid))
diff --git a/apps/workbench/app/models/arvados_api_client.rb b/apps/workbench/app/models/arvados_api_client.rb
index 84735d9..6d9269e 100644
--- a/apps/workbench/app/models/arvados_api_client.rb
+++ b/apps/workbench/app/models/arvados_api_client.rb
@@ -97,6 +97,14 @@ class ArvadosApiClient
(class << ary; self; end).class_eval { attr_accessor :items_available }
ary.items_available = j[:items_available]
end
+ if j[:offset]
+ (class << ary; self; end).class_eval { attr_accessor :offset }
+ ary.offset = j[:offset]
+ end
+ if j[:limit]
+ (class << ary; self; end).class_eval { attr_accessor :limit }
+ ary.limit = j[:limit]
+ end
ary
elsif j.is_a? Hash and (kind || j[:kind])
oclass = self.kind_class(kind || j[:kind])
diff --git a/apps/workbench/app/models/arvados_resource_list.rb b/apps/workbench/app/models/arvados_resource_list.rb
index 72495cf..3842c97 100644
--- a/apps/workbench/app/models/arvados_resource_list.rb
+++ b/apps/workbench/app/models/arvados_resource_list.rb
@@ -15,6 +15,11 @@ class ArvadosResourceList
self
end
+ def offset(skip)
+ @offset = skip
+ self
+ end
+
def order(orderby_spec)
@orderby_spec = orderby_spec
self
@@ -51,6 +56,7 @@ class ArvadosResourceList
}
api_params[:eager] = '1' if @eager
api_params[:limit] = @limit if @limit
+ api_params[:offset] = @offset if @offset
api_params[:order] = @orderby_spec if @orderby_spec
res = $arvados_api_client.api @resource_class, '', api_params
@results = $arvados_api_client.unpack_api_response res
@@ -108,4 +114,13 @@ class ArvadosResourceList
def items_available
results.items_available if results.respond_to? :items_available
end
+
+ def result_limit
+ results.limit if results.respond_to? :limit
+ end
+
+ def result_offset
+ results.offset if results.respond_to? :offset
+ end
+
end
diff --git a/apps/workbench/app/views/application/_paging.html.erb b/apps/workbench/app/views/application/_paging.html.erb
new file mode 100644
index 0000000..f5677f7
--- /dev/null
+++ b/apps/workbench/app/views/application/_paging.html.erb
@@ -0,0 +1,87 @@
+<% content_for :css do %>
+.index-paging {
+text-align: center;
+padding-left: 1em;
+padding-right: 1em;
+background-color: whitesmoke;
+}
+<% end %>
+
+<% if results.result_offset != nil and results.result_limit != nil and results.items_available != nil %>
+<div class="index-paging">
+
+<% if results.result_offset > 0 %>
+ <% if results.result_offset > results.result_limit %>
+ <% prev_offset = results.result_offset - results.result_limit %>
+ <% else %>
+ <% prev_offset = 0 %>
+ <% end %>
+<% else %>
+ <% prev_offset = nil %>
+<% end %>
+
+<% this_offset = results.result_offset %>
+<% this_page = results.result_offset / results.result_limit %>
+
+<% if (results.result_offset + results.result_limit) < results.items_available %>
+ <% next_offset = results.result_offset + results.result_limit %>
+<% else %>
+ <% next_offset = nil %>
+<% end %>
+
+<span class="pull-left">
+<% if results.result_offset > 0 %>
+ <%= link_to raw("<span class='glyphicon glyphicon-fast-backward'></span>"), {:id => object, :offset => 0, :limit => results.result_limit} %>
+<% else %>
+ <span class='glyphicon glyphicon-fast-backward text-muted'></span>
+<% end %>
+
+<% if prev_offset %>
+ <%= link_to raw("<span class='glyphicon glyphicon-step-backward'></span>"), {:id => object, :offset => prev_offset, :limit => results.result_limit} %>
+<% else %>
+<span class='glyphicon glyphicon-step-backward text-muted'></span>
+<% end %>
+</span>
+
+<% n = this_page - 10 %>
+<% if n >= 0 %>
+ <% last = this_page + 10 %>
+ …
+<% else %>
+ <% n = 0 %>
+ <% last = 20 %>
+<% end %>
+
+<% i = n * results.result_limit %>
+<% while i < results.items_available and n < last %>
+<% if n != this_page %>
+ <%= link_to "#{n+1}", {:id => @object, :offset => i, :limit => results.result_limit} %>
+<% else %>
+ <%= n+1 %>
+<% end %>
+<% i += results.result_limit %>
+<% n += 1 %>
+<% end %>
+
+<% if i < results.items_available %>
+…
+<% end %>
+
+<span class="pull-right">
+<% if next_offset %>
+ <%= link_to raw("<span class='glyphicon glyphicon-step-forward'></span>"), {:id => @object, :offset => next_offset, :limit => results.result_limit} %>
+<% else %>
+<span class='glyphicon glyphicon-forward text-muted'></span>
+<% end %>
+
+<% if (results.items_available - results.result_offset) >= results.result_limit %>
+ <%= link_to raw("<span class='glyphicon glyphicon-fast-forward'></span>"), {:id => @object, :offset => results.items_available - (results.items_available % results.result_limit),
+ :limit => results.result_limit} %>
+<% else %>
+ <span class='glyphicon glyphicon-fast-forward text-muted'></span>
+<% end %>
+
+</span>
+
+</div>
+<% end %>
diff --git a/apps/workbench/app/views/application/_show_recent.html.erb b/apps/workbench/app/views/application/_show_recent.html.erb
index ef4a8d1..04387ff 100644
--- a/apps/workbench/app/views/application/_show_recent.html.erb
+++ b/apps/workbench/app/views/application/_show_recent.html.erb
@@ -8,6 +8,8 @@
<% attr_blacklist = ' created_at modified_at modified_by_user_uuid modified_by_client_uuid updated_at' %>
+<%= render partial: "paging", locals: {results: @objects, object: @object} %>
+
<%= form_tag do |f| %>
<table class="table table-condensed arv-index">
@@ -63,4 +65,6 @@
<% end %>
+<%= render partial: "paging", locals: {results: @objects, object: @object} %>
+
<% end %>
diff --git a/apps/workbench/app/views/collections/_show_recent.html.erb b/apps/workbench/app/views/collections/_show_recent.html.erb
index a3b93d8..e0a12ff 100644
--- a/apps/workbench/app/views/collections/_show_recent.html.erb
+++ b/apps/workbench/app/views/collections/_show_recent.html.erb
@@ -13,11 +13,13 @@
</div>
<% end %>
+<%= render partial: "paging", locals: {results: @collections, object: @object} %>
+
<div style="padding-right: 1em">
<%= form_tag do |f| %>
-<table id="collections-index" class="topalign table table-condensed table-fixedlayout table-fixed-header-row">
+<table id="collections-index" class="topalign table table-condensed table-fixedlayout"> <!-- table-fixed-header-row -->
<colgroup>
<col width="4%" />
<col width="10%" />
@@ -47,6 +49,8 @@
</div>
+<%= render partial: "paging", locals: {results: @collections, object: @object} %>
+
<% content_for :footer_js do %>
$(document).on('click', 'form[data-remote] input[type=submit]', function() {
$('table#collections-index tbody').fadeTo(200, 0.3);
diff --git a/apps/workbench/app/views/groups/_show_recent.html.erb b/apps/workbench/app/views/groups/_show_recent.html.erb
index c372b88..c709e89 100644
--- a/apps/workbench/app/views/groups/_show_recent.html.erb
+++ b/apps/workbench/app/views/groups/_show_recent.html.erb
@@ -1,3 +1,5 @@
+<%= render partial: "paging", locals: {results: @groups, object: @object} %>
+
<table class="table table-hover">
<thead>
<tr class="contain-align-left">
@@ -36,3 +38,5 @@
</tbody>
</table>
+
+<%= render partial: "paging", locals: {results: @groups, object: @object} %>
diff --git a/apps/workbench/app/views/pipeline_instances/_show_recent.html.erb b/apps/workbench/app/views/pipeline_instances/_show_recent.html.erb
index 09eae0f..f7dc138 100644
--- a/apps/workbench/app/views/pipeline_instances/_show_recent.html.erb
+++ b/apps/workbench/app/views/pipeline_instances/_show_recent.html.erb
@@ -5,6 +5,8 @@
<% end rescue nil %>
<% end %>
+<%= render partial: "paging", locals: {results: @objects, object: @object} %>
+
<%= form_tag do |f| %>
<table class="table table-condensed table-fixedlayout">
@@ -71,6 +73,8 @@
<% end %>
+<%= render partial: "paging", locals: {results: @objects, object: @object} %>
+
<% content_for :footer_js do %>
var showhide_compare = function() {
var form = $('form#compare')[0];
diff --git a/apps/workbench/app/views/pipeline_templates/_show_recent.html.erb b/apps/workbench/app/views/pipeline_templates/_show_recent.html.erb
index 342a743..3ea7d8c 100644
--- a/apps/workbench/app/views/pipeline_templates/_show_recent.html.erb
+++ b/apps/workbench/app/views/pipeline_templates/_show_recent.html.erb
@@ -11,6 +11,8 @@
}
<% end %>
+<%= render partial: "paging", locals: {results: @objects, object: @object} %>
+
<table class="table table-hover">
<thead>
<tr class="contain-align-left">
@@ -54,3 +56,5 @@
</tbody>
</table>
+
+<%= render partial: "paging", locals: {results: @objects, object: @object} %>
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list