Inital page builder implementation to add paging support to cms_nodes.
This commit is contained in:
37
modules/node/handler/node_page_builder.e
Normal file
37
modules/node/handler/node_page_builder.e
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {NODE_PAGE_BUILDER}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
NODE_PAGE_BUILDER
|
||||||
|
|
||||||
|
inherit
|
||||||
|
|
||||||
|
PAGE_BUILDER [CMS_NODE]
|
||||||
|
rename
|
||||||
|
make as page_make
|
||||||
|
end
|
||||||
|
create
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
|
make (a_api: CMS_API; a_module_api: CMS_NODE_API)
|
||||||
|
do
|
||||||
|
page_make (a_api, a_module_api)
|
||||||
|
limit := 5
|
||||||
|
offset := 0
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Pager
|
||||||
|
|
||||||
|
list: LIST[CMS_NODE]
|
||||||
|
do
|
||||||
|
create {ARRAYED_LIST[CMS_NODE]}Result.make (0)
|
||||||
|
Result := node_api.recent_nodes (offset.as_integer_32, limit.as_integer_32)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -41,6 +41,9 @@ feature -- HTTP Methods
|
|||||||
s: STRING
|
s: STRING
|
||||||
n: CMS_NODE
|
n: CMS_NODE
|
||||||
lnk: CMS_LOCAL_LINK
|
lnk: CMS_LOCAL_LINK
|
||||||
|
pager: NODE_PAGE_BUILDER
|
||||||
|
number_of_pages: INTEGER_64
|
||||||
|
current_page: INTEGER
|
||||||
do
|
do
|
||||||
-- At the moment the template is hardcoded, but we can
|
-- At the moment the template is hardcoded, but we can
|
||||||
-- get them from the configuration file and load them into
|
-- get them from the configuration file and load them into
|
||||||
@@ -49,10 +52,68 @@ feature -- HTTP Methods
|
|||||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||||
l_page.add_variable (node_api.nodes, "nodes")
|
l_page.add_variable (node_api.nodes, "nodes")
|
||||||
|
|
||||||
|
create pager.make (api, node_api)
|
||||||
|
number_of_pages := (node_api.nodes_count // pager.limit) + 1
|
||||||
|
|
||||||
|
-- Size:limit
|
||||||
|
if
|
||||||
|
attached {WSF_STRING} req.query_parameter ("size") as l_size and then
|
||||||
|
l_size.is_integer
|
||||||
|
then
|
||||||
|
pager.set_limit (l_size.integer_value.to_natural_32)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--Page:offset
|
||||||
|
if
|
||||||
|
attached {WSF_STRING} req.query_parameter ("page") as ll_page and then
|
||||||
|
ll_page.is_integer
|
||||||
|
then
|
||||||
|
current_page := ll_page.integer_value
|
||||||
|
if current_page > 1 then
|
||||||
|
pager.set_offset (((current_page-1)*(pager.limit.to_integer_32)).to_natural_32)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
current_page := 1
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- 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>Nodes:</p>")
|
||||||
if attached node_api.nodes as lst then
|
|
||||||
|
s.append ("<p>Current Page:" + current_page.out + " of " + number_of_pages.out + " pages</p>" )
|
||||||
|
-- pager
|
||||||
|
s.append ("<div class=%"col-xs-12%">%N")
|
||||||
|
s.append ("<ul class=%"pager%">%N")
|
||||||
|
create lnk.make ("First", "nodes/?page=1&size="+pager.limit.out)
|
||||||
|
s.append ("<li>")
|
||||||
|
s.append (l_page.link (lnk.title, lnk.location, Void))
|
||||||
|
s.append ("</li>")
|
||||||
|
if (current_page - 1) > 1 then
|
||||||
|
create lnk.make ("Prev", "nodes/?page="+ (current_page-1).out +"&size="+pager.limit.out)
|
||||||
|
s.append ("<li>")
|
||||||
|
s.append (l_page.link (lnk.title, lnk.location, Void))
|
||||||
|
s.append ("</li>")
|
||||||
|
end
|
||||||
|
|
||||||
|
if (current_page + 1) < number_of_pages then
|
||||||
|
create lnk.make ("Next", "nodes/?page="+ (current_page+1).out +"&size="+pager.limit.out)
|
||||||
|
s.append ("<li>")
|
||||||
|
s.append (l_page.link (lnk.title, lnk.location, Void))
|
||||||
|
s.append ("</li>")
|
||||||
|
end
|
||||||
|
create lnk.make ("Last", "nodes/?page="+ number_of_pages.out +"&size="+pager.limit.out)
|
||||||
|
s.append ("<li>")
|
||||||
|
s.append (l_page.link (lnk.title, lnk.location, Void))
|
||||||
|
s.append ("</li>")
|
||||||
|
|
||||||
|
|
||||||
|
s.append ("</ul>%N")
|
||||||
|
s.append ("<div>%N")
|
||||||
|
|
||||||
|
if attached pager.list 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
|
||||||
@@ -61,7 +122,6 @@ feature -- HTTP Methods
|
|||||||
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_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 ("</li>%N")
|
s.append ("</li>%N")
|
||||||
end
|
end
|
||||||
s.append ("</ul>%N")
|
s.append ("</ul>%N")
|
||||||
|
|||||||
70
modules/node/handler/page_builder.e
Normal file
70
modules/node/handler/page_builder.e
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
note
|
||||||
|
description: "Generic Page Builder Interface"
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
deferred class
|
||||||
|
PAGE_BUILDER [G->CMS_NODE]
|
||||||
|
|
||||||
|
inherit
|
||||||
|
CMS_NODE_HANDLER
|
||||||
|
|
||||||
|
feature -- Access
|
||||||
|
|
||||||
|
set_limit (a_limit: NATURAL)
|
||||||
|
-- Set limit with `a_limit'.
|
||||||
|
do
|
||||||
|
limit := a_limit
|
||||||
|
ensure
|
||||||
|
limit_set: limit = a_limit
|
||||||
|
end
|
||||||
|
|
||||||
|
set_offset (a_offset: NATURAL)
|
||||||
|
-- Set offset with `a_offset'.
|
||||||
|
do
|
||||||
|
offset := a_offset
|
||||||
|
ensure
|
||||||
|
limit_set: offset = a_offset
|
||||||
|
end
|
||||||
|
|
||||||
|
set_order_by_asc (a_field: READABLE_STRING_32)
|
||||||
|
-- Pager with a order_by `a_field' asc.
|
||||||
|
do
|
||||||
|
order_by := a_field
|
||||||
|
order_ascending := True
|
||||||
|
ensure
|
||||||
|
order_by_set: attached order_by as l_order_by implies l_order_by = a_field
|
||||||
|
asc_true: order_ascending
|
||||||
|
end
|
||||||
|
|
||||||
|
set_order_by_desc (a_field: READABLE_STRING_32)
|
||||||
|
-- Pager with a order_by `a_field' desc.
|
||||||
|
do
|
||||||
|
order_by := a_field
|
||||||
|
order_ascending := False
|
||||||
|
ensure
|
||||||
|
order_by_set: attached order_by as l_order_by implies l_order_by = a_field
|
||||||
|
asc_fasle: not order_ascending
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Pager
|
||||||
|
|
||||||
|
list: LIST[G]
|
||||||
|
-- List of G with filters.
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Access
|
||||||
|
|
||||||
|
limit: NATURAL
|
||||||
|
-- Number of rows per page.
|
||||||
|
|
||||||
|
offset: NATURAL
|
||||||
|
-- rows starting from the next row to the given OFFSET.
|
||||||
|
|
||||||
|
order_by: detachable STRING
|
||||||
|
-- field to order by
|
||||||
|
|
||||||
|
order_ascending: BOOLEAN
|
||||||
|
-- is ascending ordering?
|
||||||
|
end
|
||||||
@@ -186,10 +186,12 @@ feature -- Hooks
|
|||||||
create lnk.make ("List of nodes", "nodes")
|
create lnk.make ("List of nodes", "nodes")
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
a_menu_system.primary_menu.extend (lnk)
|
||||||
|
|
||||||
create lnk.make ("Trash", a_response.url ("trash", Void))
|
-- create lnk.make ("Trash", a_response.url ("trash/", Void))
|
||||||
|
create lnk.make ("Trash", "trash")
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
a_menu_system.primary_menu.extend (lnk)
|
||||||
|
|
||||||
create lnk.make ("Create ..", a_response.url ("node/", Void))
|
-- create lnk.make ("Create ..", a_response.url ("node/", Void))
|
||||||
|
create lnk.make ("Create ..", "node")
|
||||||
a_menu_system.primary_menu.extend (lnk)
|
a_menu_system.primary_menu.extend (lnk)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user