Merged remote-tracking branch 'jvelilla/roc_pg' into pagination
Renamed pagination related classes, and moved them to cms library under "support" cluster.
This commit is contained in:
@@ -220,10 +220,10 @@ feature -- Access: Node
|
||||
Result := node_storage.trashed_nodes (a_user.id)
|
||||
end
|
||||
|
||||
recent_nodes (a_offset, a_rows: INTEGER): LIST [CMS_NODE]
|
||||
recent_nodes (a_pagination: CMS_PAGINATION): ITERABLE [CMS_NODE]
|
||||
-- List of the `a_rows' most recent nodes starting from `a_offset'.
|
||||
do
|
||||
Result := node_storage.recent_nodes (a_offset, a_rows)
|
||||
Result := node_storage.recent_nodes (a_pagination.offset.to_integer_32, a_pagination.size.to_integer_32)
|
||||
end
|
||||
|
||||
node (a_id: INTEGER_64): detachable CMS_NODE
|
||||
|
||||
161
modules/node/handler/cms_node_pagination_helper.e
Normal file
161
modules/node/handler/cms_node_pagination_helper.e
Normal file
@@ -0,0 +1,161 @@
|
||||
note
|
||||
description: "Helper class to build the html pagination links and header summary"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_NODE_PAGINATION_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_resource: READABLE_STRING_8; req: WSF_REQUEST; a_response: CMS_RESPONSE; a_nodes_count: INTEGER_64)
|
||||
-- Create an object with default values.
|
||||
do
|
||||
make_size (a_resource, req, a_response, a_nodes_count, 5)
|
||||
end
|
||||
|
||||
make_size (a_resource: READABLE_STRING_8; req: WSF_REQUEST; a_response: CMS_RESPONSE; a_nodes_count: INTEGER_64; a_page_size: NATURAL)
|
||||
-- Create an object with a pages of size `a_page_size'.
|
||||
do
|
||||
create resource.make_from_string (a_resource)
|
||||
number_of_nodes := a_nodes_count
|
||||
create pager.make (0, a_page_size)
|
||||
response := a_response
|
||||
process (req)
|
||||
end
|
||||
|
||||
process (req: WSF_REQUEST)
|
||||
-- Process request query paraments to build the pager.
|
||||
do
|
||||
--TODO: at the moment the code looks for hardcoded parameters
|
||||
-- size and page, maybe we can parametrize these names.
|
||||
-- Size:limit.
|
||||
if
|
||||
attached {WSF_STRING} req.query_parameter ("size") as l_size and then
|
||||
attached l_size.value as l_value and then
|
||||
l_value.is_natural
|
||||
then
|
||||
pager.set_size (l_value.to_natural_32)
|
||||
end
|
||||
|
||||
--Page:offset
|
||||
if
|
||||
attached {WSF_STRING} req.query_parameter ("page") as l_page and then
|
||||
l_page.is_integer
|
||||
then
|
||||
current_page := l_page.integer_value
|
||||
if current_page > 1 then
|
||||
pager.set_offset ((current_page - 1).to_natural_32 * pager.size)
|
||||
end
|
||||
else
|
||||
current_page := 1
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
pager: CMS_PAGINATION
|
||||
-- Paginator.
|
||||
|
||||
resource: IMMUTABLE_STRING_8
|
||||
|
||||
current_page: INTEGER
|
||||
-- current page.
|
||||
|
||||
number_of_pages: INTEGER_64
|
||||
-- total number of pages.
|
||||
do
|
||||
Result := (number_of_nodes // pager.size.as_integer_32) + 1
|
||||
end
|
||||
|
||||
number_of_nodes: INTEGER_64
|
||||
-- number of nodes.
|
||||
|
||||
response: CMS_RESPONSE
|
||||
-- cms response
|
||||
|
||||
feature -- Parameters
|
||||
|
||||
page_parameter: STRING = "page"
|
||||
|
||||
size_parameter: STRING = "size"
|
||||
|
||||
feature -- Paginator
|
||||
|
||||
append_pagination_summary_to (a_output: STRING)
|
||||
-- Header summary
|
||||
-- Current page 1 of n pages.
|
||||
do
|
||||
a_output.append ("<p>Items:</p>")
|
||||
|
||||
a_output.append ("<p>Current Page:")
|
||||
a_output.append_integer (current_page)
|
||||
a_output.append (" of ")
|
||||
a_output.append_integer_64 (number_of_pages)
|
||||
a_output.append (" pages</p>")
|
||||
end
|
||||
|
||||
append_html_pager_to (a_output: STRING)
|
||||
-- Append html pager to `a_output'.
|
||||
-- note: First, [Prev], [Next], Last.
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
s: STRING
|
||||
do
|
||||
-- NOTE: for development purposes we have the following hardcode output.
|
||||
-- pager
|
||||
a_output.append ("<ul class=%"pager%">%N")
|
||||
create s.make_from_string (resource)
|
||||
append_query_parameters_to (s, "1", pager.size.out)
|
||||
create lnk.make ("First", s)
|
||||
a_output.append ("<li>")
|
||||
a_output.append (response.link (lnk.title, lnk.location, Void))
|
||||
a_output.append ("</li>")
|
||||
if (current_page - 1) > 1 then
|
||||
create s.make_from_string (resource)
|
||||
append_query_parameters_to (s, (current_page - 1).out, pager.size.out)
|
||||
|
||||
create lnk.make ("Prev", s)
|
||||
a_output.append ("<li>")
|
||||
a_output.append (response.link (lnk.title, lnk.location, Void))
|
||||
a_output.append ("</li>")
|
||||
end
|
||||
|
||||
if (current_page + 1) < number_of_pages then
|
||||
create s.make_from_string (resource)
|
||||
append_query_parameters_to (s, (current_page + 1).out, pager.size.out)
|
||||
create lnk.make ("Next", s)
|
||||
a_output.append ("<li>")
|
||||
a_output.append (response.link (lnk.title, lnk.location, Void))
|
||||
a_output.append ("</li>")
|
||||
end
|
||||
create s.make_from_string (resource)
|
||||
append_query_parameters_to (s, number_of_pages.out, pager.size.out)
|
||||
create lnk.make ("Last", s)
|
||||
a_output.append ("<li>")
|
||||
a_output.append (response.link (lnk.title, lnk.location, Void))
|
||||
a_output.append ("</li>")
|
||||
|
||||
a_output.append ("</ul>%N")
|
||||
end
|
||||
|
||||
append_query_parameters_to (s: STRING; a_page: STRING; a_size: STRING)
|
||||
do
|
||||
if s.has ('?') then
|
||||
s.append ("&")
|
||||
else
|
||||
s.append ("?")
|
||||
end
|
||||
s.append (page_parameter)
|
||||
s.append_character ('=')
|
||||
s.append (a_page)
|
||||
s.append_character ('&')
|
||||
s.append (size_parameter)
|
||||
s.append_character ('=')
|
||||
s.append (a_size)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -37,22 +37,24 @@ feature -- HTTP Methods
|
||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- <Precursor>
|
||||
local
|
||||
l_page: CMS_RESPONSE
|
||||
l_response: CMS_RESPONSE
|
||||
s: STRING
|
||||
n: CMS_NODE
|
||||
lnk: CMS_LOCAL_LINK
|
||||
l_page_helper: CMS_NODE_PAGINATION_HELPER
|
||||
do
|
||||
-- At the moment the template is hardcoded, but we can
|
||||
-- get them from the configuration file and load them into
|
||||
-- the setup class.
|
||||
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (node_api.nodes, "nodes")
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_response.make (req, res, api)
|
||||
create l_page_helper.make ("nodes/", req, l_response, node_api.nodes_count)
|
||||
|
||||
create s.make_empty
|
||||
l_page_helper.append_pagination_summary_to (s)
|
||||
l_page_helper.append_html_pager_to (s)
|
||||
|
||||
-- NOTE: for development purposes we have the following hardcode output.
|
||||
create s.make_from_string ("<p>Nodes:</p>")
|
||||
if attached node_api.nodes as lst then
|
||||
if attached node_api.recent_nodes (l_page_helper.pager) as lst then
|
||||
s.append ("<ul class=%"cms-nodes%">%N")
|
||||
across
|
||||
lst as ic
|
||||
@@ -60,16 +62,16 @@ feature -- HTTP Methods
|
||||
n := ic.item
|
||||
lnk := node_api.node_link (n)
|
||||
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
|
||||
s.append (l_page.link (lnk.title, lnk.location, Void))
|
||||
-- s.append (l_page.link (n.title + " (#" + n.id.out + ")", node_api.node_path (n), Void))
|
||||
s.append (l_response.link (lnk.title, lnk.location, Void))
|
||||
s.append ("</li>%N")
|
||||
end
|
||||
s.append ("</ul>%N")
|
||||
end
|
||||
l_page_helper.append_html_pager_to (s)
|
||||
|
||||
l_page.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_page.execute
|
||||
l_response.set_main_content (s)
|
||||
l_response.add_block (create {CMS_CONTENT_BLOCK}.make ("nodes_warning", Void, "/nodes/ is not yet fully implemented<br/>", Void), "highlighted")
|
||||
l_response.execute
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -206,7 +206,7 @@ feature -- Hooks
|
||||
create lnk.make ("Trash", "trash")
|
||||
a_menu_system.primary_menu.extend (lnk)
|
||||
|
||||
create lnk.make ("Create ..", "node/")
|
||||
create lnk.make ("Create ..", "node")
|
||||
a_menu_system.primary_menu.extend (lnk)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user