Updated code based on comments.
This commit is contained in:
@@ -10,35 +10,35 @@ inherit
|
|||||||
|
|
||||||
CMS_PAGINATION_BUILDER [CMS_NODE]
|
CMS_PAGINATION_BUILDER [CMS_NODE]
|
||||||
|
|
||||||
CMS_NODE_HANDLER
|
|
||||||
redefine
|
|
||||||
make
|
|
||||||
end
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make (a_api: CMS_API; a_module_api: CMS_NODE_API)
|
make (a_api: CMS_NODE_API)
|
||||||
-- Create an object.
|
-- Create an object.
|
||||||
do
|
do
|
||||||
Precursor (a_api, a_module_api)
|
node_api := a_api
|
||||||
limit := 5
|
count := 5
|
||||||
offset := 0
|
offset := 0
|
||||||
ensure then
|
ensure
|
||||||
limit_set: limit = 5
|
node_api_set: node_api = a_api
|
||||||
|
limit_set: count = 5
|
||||||
offset_set: offset = 0
|
offset_set: offset = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
node_api: CMS_NODE_API
|
||||||
|
-- CMS API.
|
||||||
|
|
||||||
feature -- Pager
|
feature -- Pager
|
||||||
|
|
||||||
list: ITERABLE [CMS_NODE]
|
items: ITERABLE [CMS_NODE]
|
||||||
-- <Precursor>.
|
-- <Precursor>.
|
||||||
do
|
do
|
||||||
--NOTE: the current implementation does not use
|
--NOTE: the current implementation does not use
|
||||||
-- order by and ordering.
|
-- order by and ordering.
|
||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
Result := node_api.recent_nodes (offset.as_integer_32, limit.as_integer_32)
|
Result := node_api.recent_nodes (offset.as_integer_32, count.as_integer_32)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ deferred class
|
|||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
set_limit (a_limit: NATURAL)
|
set_count (a_count: NATURAL)
|
||||||
-- Set limit with `a_limit'.
|
-- Set `count' with `a_count'.
|
||||||
do
|
do
|
||||||
limit := a_limit
|
count := a_count
|
||||||
ensure
|
ensure
|
||||||
limit_set: limit = a_limit
|
count_set: count = a_count
|
||||||
end
|
end
|
||||||
|
|
||||||
set_offset (a_offset: NATURAL)
|
set_offset (a_offset: NATURAL)
|
||||||
@@ -46,21 +46,21 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Pager
|
feature -- Pager
|
||||||
|
|
||||||
list: ITERABLE[G]
|
items: ITERABLE [G]
|
||||||
-- Iterable of G with filters.
|
-- Iterable of G with filters.
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
limit: NATURAL
|
count: NATURAL
|
||||||
-- Number of rows per page.
|
-- Number of items per page.
|
||||||
|
|
||||||
offset: NATURAL
|
offset: NATURAL
|
||||||
-- rows starting from the next row to the given OFFSET.
|
-- lower index of `items' pagination.
|
||||||
|
|
||||||
order_by: detachable STRING
|
order_by: detachable STRING
|
||||||
-- field to order by
|
-- field to order by.
|
||||||
|
|
||||||
order_ascending: BOOLEAN
|
order_ascending: BOOLEAN
|
||||||
-- is ascending ordering?
|
-- is ascending ordering?
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ feature -- HTTP Methods
|
|||||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
l_page: CMS_RESPONSE
|
l_response: CMS_RESPONSE
|
||||||
s: STRING
|
s: STRING
|
||||||
n: CMS_NODE
|
n: CMS_NODE
|
||||||
lnk: CMS_LOCAL_LINK
|
lnk: CMS_LOCAL_LINK
|
||||||
@@ -49,30 +49,30 @@ feature -- HTTP Methods
|
|||||||
-- get them from the configuration file and load them into
|
-- get them from the configuration file and load them into
|
||||||
-- the setup class.
|
-- the setup class.
|
||||||
|
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} l_response.make (req, res, api)
|
||||||
l_page.add_variable (node_api.nodes, "nodes")
|
l_response.add_variable (node_api.nodes, "nodes")
|
||||||
|
|
||||||
create pager.make (api, node_api)
|
create pager.make (node_api)
|
||||||
number_of_pages := (node_api.nodes_count // pager.limit) + 1
|
number_of_pages := (node_api.nodes_count // pager.count) + 1
|
||||||
|
|
||||||
-- Size:limit
|
-- Size:limit
|
||||||
if
|
if
|
||||||
attached {WSF_STRING} req.query_parameter ("size") as l_size and then
|
attached {WSF_STRING} req.query_parameter ("size") as l_size and then
|
||||||
l_size.is_integer
|
l_size.is_integer
|
||||||
then
|
then
|
||||||
pager.set_limit (l_size.integer_value.to_natural_32)
|
pager.set_count (l_size.integer_value.to_natural_32)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--Page:offset
|
--Page:offset
|
||||||
if
|
if
|
||||||
attached {WSF_STRING} req.query_parameter ("page") as ll_page and then
|
attached {WSF_STRING} req.query_parameter ("page") as l_page and then
|
||||||
ll_page.is_integer
|
l_page.is_integer
|
||||||
then
|
then
|
||||||
current_page := ll_page.integer_value
|
current_page := l_page.integer_value
|
||||||
if current_page > 1 then
|
if current_page > 1 then
|
||||||
pager.set_offset (((current_page-1)*(pager.limit.to_integer_32)).to_natural_32)
|
pager.set_offset (((current_page-1)*(pager.count.to_integer_32)).to_natural_32)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
current_page := 1
|
current_page := 1
|
||||||
@@ -81,39 +81,44 @@ feature -- HTTP Methods
|
|||||||
|
|
||||||
|
|
||||||
-- NOTE: for development purposes we have the following hardcode output.
|
-- NOTE: for development purposes we have the following hardcode output.
|
||||||
create s.make_from_string ("<p>Nodes:</p>")
|
create s.make_from_string ("<p>Items:</p>")
|
||||||
|
|
||||||
|
s.append ("<p>Current Page:")
|
||||||
|
s.append_integer (current_page)
|
||||||
|
s.append (" of ")
|
||||||
|
s.append_integer_64 (number_of_pages)
|
||||||
|
s.append (" pages</p>")
|
||||||
|
|
||||||
s.append ("<p>Current Page:" + current_page.out + " of " + number_of_pages.out + " pages</p>" )
|
|
||||||
-- pager
|
-- pager
|
||||||
s.append ("<div class=%"col-xs-12%">%N")
|
s.append ("<div class=%"col-xs-12%">%N")
|
||||||
s.append ("<ul class=%"pager%">%N")
|
s.append ("<ul class=%"pager%">%N")
|
||||||
create lnk.make ("First", "nodes/?page=1&size="+pager.limit.out)
|
create lnk.make ("First", "nodes/?page=1&size="+pager.count.out)
|
||||||
s.append ("<li>")
|
s.append ("<li>")
|
||||||
s.append (l_page.link (lnk.title, lnk.location, Void))
|
s.append (l_response.link (lnk.title, lnk.location, Void))
|
||||||
s.append ("</li>")
|
s.append ("</li>")
|
||||||
if (current_page - 1) > 1 then
|
if (current_page - 1) > 1 then
|
||||||
create lnk.make ("Prev", "nodes/?page="+ (current_page-1).out +"&size="+pager.limit.out)
|
create lnk.make ("Prev", "nodes/?page="+ (current_page-1).out +"&size="+pager.count.out)
|
||||||
s.append ("<li>")
|
s.append ("<li>")
|
||||||
s.append (l_page.link (lnk.title, lnk.location, Void))
|
s.append (l_response.link (lnk.title, lnk.location, Void))
|
||||||
s.append ("</li>")
|
s.append ("</li>")
|
||||||
end
|
end
|
||||||
|
|
||||||
if (current_page + 1) < number_of_pages then
|
if (current_page + 1) < number_of_pages then
|
||||||
create lnk.make ("Next", "nodes/?page="+ (current_page+1).out +"&size="+pager.limit.out)
|
create lnk.make ("Next", "nodes/?page="+ (current_page+1).out +"&size="+pager.count.out)
|
||||||
s.append ("<li>")
|
s.append ("<li>")
|
||||||
s.append (l_page.link (lnk.title, lnk.location, Void))
|
s.append (l_response.link (lnk.title, lnk.location, Void))
|
||||||
s.append ("</li>")
|
s.append ("</li>")
|
||||||
end
|
end
|
||||||
create lnk.make ("Last", "nodes/?page="+ number_of_pages.out +"&size="+pager.limit.out)
|
create lnk.make ("Last", "nodes/?page="+ number_of_pages.out +"&size="+pager.count.out)
|
||||||
s.append ("<li>")
|
s.append ("<li>")
|
||||||
s.append (l_page.link (lnk.title, lnk.location, Void))
|
s.append (l_response.link (lnk.title, lnk.location, Void))
|
||||||
s.append ("</li>")
|
s.append ("</li>")
|
||||||
|
|
||||||
|
|
||||||
s.append ("</ul>%N")
|
s.append ("</ul>%N")
|
||||||
s.append ("<div>%N")
|
s.append ("<div>%N")
|
||||||
|
|
||||||
if attached pager.list as lst then
|
if attached pager.items as lst then
|
||||||
s.append ("<ul class=%"cms-nodes%">%N")
|
s.append ("<ul class=%"cms-nodes%">%N")
|
||||||
across
|
across
|
||||||
lst as ic
|
lst as ic
|
||||||
@@ -121,15 +126,15 @@ feature -- HTTP Methods
|
|||||||
n := ic.item
|
n := ic.item
|
||||||
lnk := node_api.node_link (n)
|
lnk := node_api.node_link (n)
|
||||||
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
|
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
|
||||||
s.append (l_page.link (lnk.title, lnk.location, Void))
|
s.append (l_response.link (lnk.title, lnk.location, Void))
|
||||||
s.append ("</li>%N")
|
s.append ("</li>%N")
|
||||||
end
|
end
|
||||||
s.append ("</ul>%N")
|
s.append ("</ul>%N")
|
||||||
end
|
end
|
||||||
|
|
||||||
l_page.set_main_content (s)
|
l_response.set_main_content (s)
|
||||||
l_page.add_block (create {CMS_CONTENT_BLOCK}.make ("nodes_warning", Void, "/nodes/ is not yet fully implemented<br/>", Void), "highlighted")
|
l_response.add_block (create {CMS_CONTENT_BLOCK}.make ("nodes_warning", Void, "/nodes/ is not yet fully implemented<br/>", Void), "highlighted")
|
||||||
l_page.execute
|
l_response.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user