Skip to content
This repository was archived by the owner on Jun 4, 2021. It is now read-only.

Commit 7c7b9cf

Browse files
author
Scott McClellan
committed
Add pagination to commands collection
The commands collection, which can grow quite lengthy, currently does not allow any pagination. This provides the "start" and "limit" query arguments, which are present for many other collections.
1 parent daad0cd commit 7c7b9cf

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

app.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,9 @@ def render_template(name)
558558
#
559559
# @todo danielp 2013-06-26: this should be some sort of discovery, not a
560560
# hand-coded list, but ... it will do, for now.
561-
COLLECTIONS = [:brokers, :repos, :tags, :policies, [:nodes, {'start' => {"type" => "number"}, 'limit' => {"type" => "number"}}],
562-
:tasks, :commands,
561+
COLLECTIONS = [:brokers, :repos, :tags, :policies,
562+
[:nodes, {'start' => {"type" => "number"}, 'limit' => {"type" => "number"}}],
563+
:tasks, [:commands, {'start' => {'type' => 'number'}, 'limit' => {'type' => 'number'}}],
563564
[:events, {'start' => {"type" => "number"}, 'limit' => {"type" => "number"}}], :hooks]
564565

565566
#
@@ -692,7 +693,18 @@ def render_template(name)
692693
end
693694

694695
get '/api/collections/commands' do
695-
collection_view Razor::Data::Command.order(:submitted_at).order(:id), 'commands'
696+
limit = params[:limit]
697+
start = params[:start]
698+
699+
raise TypeError, _('limit must be a number, but was %{limit}') %
700+
{limit: limit} unless limit.to_i.to_s == limit or limit.nil?
701+
raise TypeError, _('start must be a number, but was %{start}') %
702+
{start: start} unless start.to_i.to_s == start or start.nil?
703+
limit = Integer(limit) if limit
704+
start = Integer(start) if start
705+
706+
collection_view Razor::Data::Command.order(:submitted_at).order(:id),
707+
'commands', limit: limit, start: start, facts: true
696708
end
697709

698710
get '/api/collections/commands/:id' do

0 commit comments

Comments
 (0)