diff --git a/modules/node/cms_node_api.e b/modules/node/cms_node_api.e
index 7681c64..8de31a4 100644
--- a/modules/node/cms_node_api.e
+++ b/modules/node/cms_node_api.e
@@ -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
diff --git a/modules/node/handler/cms_node_pagination_helper.e b/modules/node/handler/cms_node_pagination_helper.e
new file mode 100644
index 0000000..c3b48ed
--- /dev/null
+++ b/modules/node/handler/cms_node_pagination_helper.e
@@ -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 ("
Items:
")
+
+ a_output.append ("Current Page:")
+ a_output.append_integer (current_page)
+ a_output.append (" of ")
+ a_output.append_integer_64 (number_of_pages)
+ a_output.append (" pages
")
+ 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 ("%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
diff --git a/modules/node/handler/nodes_handler.e b/modules/node/handler/nodes_handler.e
index 18462d2..58839cb 100644
--- a/modules/node/handler/nodes_handler.e
+++ b/modules/node/handler/nodes_handler.e
@@ -37,22 +37,24 @@ feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
--
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 ("Nodes:
")
- if attached node_api.nodes as lst then
+ if attached node_api.recent_nodes (l_page_helper.pager) as lst then
s.append ("%N")
across
lst as ic
@@ -60,16 +62,16 @@ feature -- HTTP Methods
n := ic.item
lnk := node_api.node_link (n)
s.append ("- ")
- 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 ("
%N")
end
s.append ("
%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
", 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
", Void), "highlighted")
+ l_response.execute
end
end
diff --git a/modules/node/node_module.e b/modules/node/node_module.e
index ada3124..1f495d3 100644
--- a/modules/node/node_module.e
+++ b/modules/node/node_module.e
@@ -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
diff --git a/src/service/cms_api.e b/src/service/cms_api.e
index cba319d..47e3d0a 100644
--- a/src/service/cms_api.e
+++ b/src/service/cms_api.e
@@ -148,19 +148,15 @@ feature -- Permissions system
feature -- Query: module
- module (a_type: TYPE [detachable CMS_MODULE]): detachable CMS_MODULE
+ module (a_type: TYPE [CMS_MODULE]): detachable CMS_MODULE
-- Enabled module typed `a_type', if any.
--| usage: if attached module ({FOO_MODULE}) as mod then ...
local
- t: STRING_8
+-- t: STRING_8
l_type: TYPE [detachable CMS_MODULE]
do
- t := a_type.name
- if t.starts_with ("!") then
- t.remove_head (1)
- elseif t.starts_with ("?") then
- t.remove_head (1)
- end
+-- t := type_name_without_annotation (a_type)
+
across
setup.modules as ic
until
@@ -173,8 +169,12 @@ feature -- Query: module
l_type := Result.generating_type
if a_type ~ l_type then
-- Found
- elseif t.same_string (l_type.name) then
+ elseif
+ attached a_type.attempt (Result) and then attached l_type.generating_type.attempt (a_type)
+ then
-- Found
+-- elseif t.same_string (type_name_without_annotation (l_type)) then
+-- -- Found
else
Result := Void
end
@@ -322,6 +322,41 @@ feature {NONE}-- Implemenation
internal_user_api: detachable like user_api
-- Cached value for `user_api'.
+ type_name_without_annotation (a_type: TYPE [detachable ANY]): STRING
+ -- Type name for `a_type, without any annotation.
+ -- Used by `module' to search by type.
+ local
+ i,j,n: INTEGER
+ c: CHARACTER
+ do
+ create Result.make_from_string (a_type.name)
+ from
+ i := 1
+ n := Result.count
+ until
+ i > n
+ loop
+ c := Result[i]
+ if c = '!' or c = '?' then
+ Result.remove (i)
+ n := n - 1
+ elseif c.is_lower then
+ j := Result.index_of (' ', i + 1)
+ if j > 0 then
+ Result.remove_substring (i, j)
+ n := n - (j - i)
+ end
+ else
+ i := i + 1
+ end
+ end
+ if Result.starts_with ("!") or Result.starts_with ("?") then
+ Result.remove_head (1)
+ elseif Result.starts_with ("detachable ") then
+ Result.remove_head (11)
+ end
+ end
+
feature -- Environment
module_configuration (a_module_name: READABLE_STRING_GENERAL; a_name: detachable READABLE_STRING_GENERAL): detachable CONFIG_READER
diff --git a/src/service/cms_module_collection.e b/src/service/cms_module_collection.e
index 58ba768..42411f1 100644
--- a/src/service/cms_module_collection.e
+++ b/src/service/cms_module_collection.e
@@ -1,6 +1,5 @@
note
- description: "Summary description for {CMS_MODULE_COLLECTION}."
- author: ""
+ description: "Collection of CMS modules."
date: "$Date: 2015-02-09 22:29:56 +0100 (lun., 09 févr. 2015) $"
revision: "$Revision: 96596 $"
diff --git a/src/support/cms_ordered_pagination.e b/src/support/cms_ordered_pagination.e
new file mode 100644
index 0000000..42c5f3c
--- /dev/null
+++ b/src/support/cms_ordered_pagination.e
@@ -0,0 +1,55 @@
+note
+ description: "Pagination parameters with order capability"
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ CMS_ORDERED_PAGINATION
+
+inherit
+ CMS_PAGINATION
+
+create
+ make
+
+feature -- Access
+
+ order_by: detachable READABLE_STRING_8
+ -- field to order by.
+
+ order_ascending: BOOLEAN
+ -- is ascending ordering?
+
+feature -- Element change
+
+ set_ascending_order_by_field (a_field: detachable READABLE_STRING_8)
+ -- Pager with a order_by `a_field' asc.
+ do
+ if a_field /= Void then
+ order_by := a_field
+ order_ascending := True
+ else
+ order_by := Void
+ end
+ ensure
+ order_by_unset: a_field = Void implies order_by = Void
+ order_by_set: a_field /= Void implies attached order_by as l_order_by and then l_order_by.same_string (a_field)
+ asc_true: order_ascending
+ end
+
+ set_descending_order_by_field (a_field: detachable READABLE_STRING_8)
+ -- Pager sorting descending with field `a_field' if set, otherwise remove sorting.
+ do
+ if a_field /= Void then
+ order_by := a_field
+ order_ascending := False
+ else
+ order_by := Void
+ end
+ ensure
+ order_by_unset: a_field = Void implies order_by = Void
+ order_by_set: a_field /= Void implies attached order_by as l_order_by and then l_order_by.same_string (a_field)
+ asc_fasle: not order_ascending
+ end
+
+end
diff --git a/src/support/cms_pagination.e b/src/support/cms_pagination.e
new file mode 100644
index 0000000..72fc688
--- /dev/null
+++ b/src/support/cms_pagination.e
@@ -0,0 +1,50 @@
+note
+ description: "Pagination parameters"
+ date: "$Date$"
+ revision: "$Revision$"
+
+class
+ CMS_PAGINATION
+
+create
+ make
+
+feature {NONE} -- Initialization
+
+ make (a_offset: NATURAL; a_size: NATURAL)
+ do
+ offset := a_offset
+ size := a_size
+ ensure
+ size_set: size = a_size
+ offset_set: offset = a_offset
+ end
+
+feature -- Access
+
+ size: NATURAL assign set_size
+ -- Number of items per page.
+
+ offset: NATURAL assign set_offset
+ -- lower index of `items' pagination.
+
+feature -- Element change
+
+ set_size (a_size: NATURAL)
+ -- Set `size' with `a_size'.
+ do
+ size := a_size
+ ensure
+ size_set: size = a_size
+ end
+
+ set_offset (a_offset: NATURAL)
+ -- Set offset with `a_offset'.
+ do
+ offset := a_offset
+ ensure
+ limit_set: offset = a_offset
+ end
+
+
+end