Added feed ordered by publication on /nodes/{type}/feed.
This commit is contained in:
@@ -190,6 +190,12 @@ feature -- Access: Node
|
|||||||
Result := node_storage.recent_nodes_of_type (a_content_type, params.offset.to_integer_32, params.size.to_integer_32)
|
Result := node_storage.recent_nodes_of_type (a_content_type, params.offset.to_integer_32, params.size.to_integer_32)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
recent_published_nodes_of_type (a_content_type: CMS_CONTENT_TYPE; params: CMS_DATA_QUERY_PARAMETERS): ITERABLE [CMS_NODE]
|
||||||
|
-- Most recent published `a_content_type` nodes according to `params.offset' and `params.size', and order by publication_date.
|
||||||
|
do
|
||||||
|
Result := node_storage.recent_published_nodes_of_type (a_content_type, params.offset.to_integer_32, params.size.to_integer_32)
|
||||||
|
end
|
||||||
|
|
||||||
recent_node_changes_before (params: CMS_DATA_QUERY_PARAMETERS; a_date: DATE_TIME): ITERABLE [CMS_NODE]
|
recent_node_changes_before (params: CMS_DATA_QUERY_PARAMETERS; a_date: DATE_TIME): ITERABLE [CMS_NODE]
|
||||||
-- List of recent changes, before `a_date', according to `params' settings.
|
-- List of recent changes, before `a_date', according to `params' settings.
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ feature -- Access: router
|
|||||||
create l_uri_mapping.make_trailing_slash_ignored ("/nodes", l_nodes_handler)
|
create l_uri_mapping.make_trailing_slash_ignored ("/nodes", l_nodes_handler)
|
||||||
a_router.map (l_uri_mapping, a_router.methods_get)
|
a_router.map (l_uri_mapping, a_router.methods_get)
|
||||||
a_router.handle ("/nodes/{type}", l_nodes_handler, a_router.methods_get)
|
a_router.handle ("/nodes/{type}", l_nodes_handler, a_router.methods_get)
|
||||||
|
a_router.handle ("/nodes/{type}/feed", l_nodes_handler, a_router.methods_get)
|
||||||
|
|
||||||
-- Trash
|
-- Trash
|
||||||
create l_trash_handler.make (a_api, a_node_api)
|
create l_trash_handler.make (a_api, a_node_api)
|
||||||
|
|||||||
@@ -55,10 +55,100 @@ feature -- HTTP Methods
|
|||||||
|
|
||||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
|
local
|
||||||
|
l_content_type: detachable CMS_CONTENT_TYPE
|
||||||
|
do
|
||||||
|
if attached {WSF_STRING} req.path_parameter ("type") as p_node_type and then attached api.content_type (p_node_type.value) as ct then
|
||||||
|
l_content_type := api.content_type (p_node_type.value)
|
||||||
|
end
|
||||||
|
if l_content_type /= Void and then req.path_info.ends_with_general ("/feed") then
|
||||||
|
do_nodes_feed (l_content_type, req, res)
|
||||||
|
else
|
||||||
|
do_nodes_html (l_content_type, req, res)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
do_nodes_feed (a_content_type: CMS_CONTENT_TYPE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
local
|
||||||
|
l_feed: FEED
|
||||||
|
l_feed_item: FEED_ITEM
|
||||||
|
l_params: CMS_DATA_QUERY_PARAMETERS
|
||||||
|
n: CMS_NODE
|
||||||
|
pg, nb: NATURAL_64
|
||||||
|
l_size: NATURAL_64
|
||||||
|
l_exhausted: BOOLEAN
|
||||||
|
lnk: FEED_LINK
|
||||||
|
mesg: CMS_CUSTOM_RESPONSE_MESSAGE
|
||||||
|
l_payload: STRING
|
||||||
|
do
|
||||||
|
create l_feed.make (a_content_type.name)
|
||||||
|
l_feed.set_date (create {DATE_TIME}.make_now_utc)
|
||||||
|
|
||||||
|
if attached {WSF_STRING} req.query_parameter ("size") as p_size and then p_size.is_integer then
|
||||||
|
l_size := p_size.integer_value.to_natural_64
|
||||||
|
else
|
||||||
|
l_size := 25
|
||||||
|
end
|
||||||
|
|
||||||
|
from
|
||||||
|
nb := 0
|
||||||
|
pg := 0
|
||||||
|
until
|
||||||
|
nb = l_size or l_exhausted
|
||||||
|
loop
|
||||||
|
create l_params.make (1 + (pg * 25), 25)
|
||||||
|
if attached node_api.recent_published_nodes_of_type (a_content_type, l_params) as lst then
|
||||||
|
l_exhausted := True
|
||||||
|
across
|
||||||
|
lst as ic
|
||||||
|
until
|
||||||
|
nb = l_size
|
||||||
|
loop
|
||||||
|
l_exhausted := False
|
||||||
|
n := ic.item
|
||||||
|
if n.is_published then
|
||||||
|
create l_feed_item.make (n.title)
|
||||||
|
if attached n.author as u then
|
||||||
|
l_feed_item.set_author (create {FEED_AUTHOR}.make (api.user_api.user_display_name (u)))
|
||||||
|
end
|
||||||
|
l_feed_item.set_date (n.publication_date)
|
||||||
|
create lnk.make (req.absolute_script_url ("/" + node_api.node_link (n).location))
|
||||||
|
l_feed_item.links.force (lnk, "")
|
||||||
|
if attached n.summary as l_summary and then not l_summary.is_whitespace then
|
||||||
|
l_feed_item.set_description (l_summary)
|
||||||
|
-- elseif attached n.content as l_content then
|
||||||
|
-- l_feed_item.set_content (l_content, Void)
|
||||||
|
end
|
||||||
|
if attached {CMS_TAXONOMY_API} api.module_api ({CMS_TAXONOMY_MODULE}) as l_taxonomy_api then
|
||||||
|
if attached l_taxonomy_api.terms_of_content (n, Void) as coll then
|
||||||
|
across
|
||||||
|
coll as coll_ic
|
||||||
|
loop
|
||||||
|
l_feed_item.set_category (coll_ic.item.text)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
nb := nb + 1
|
||||||
|
l_feed.extend (l_feed_item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
l_exhausted := True
|
||||||
|
end
|
||||||
|
pg := pg + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
create l_payload.make (2_048)
|
||||||
|
l_feed.accept (create {ATOM_FEED_GENERATOR}.make (l_payload))
|
||||||
|
create mesg.make ({HTTP_STATUS_CODE}.ok)
|
||||||
|
mesg.set_payload (l_payload)
|
||||||
|
res.send (mesg)
|
||||||
|
end
|
||||||
|
|
||||||
|
do_nodes_html (a_content_type: detachable CMS_CONTENT_TYPE; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
l_response: CMS_RESPONSE
|
l_response: CMS_RESPONSE
|
||||||
s: STRING
|
s: STRING
|
||||||
l_content_type: detachable CMS_CONTENT_TYPE
|
|
||||||
n: CMS_NODE
|
n: CMS_NODE
|
||||||
lnk: CMS_LOCAL_LINK
|
lnk: CMS_LOCAL_LINK
|
||||||
l_page_helper: CMS_PAGINATION_GENERATOR
|
l_page_helper: CMS_PAGINATION_GENERATOR
|
||||||
@@ -71,10 +161,6 @@ feature -- HTTP Methods
|
|||||||
-- At the moment the template are hardcoded, but we can
|
-- At the moment the template are hardcoded, but we can
|
||||||
-- 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.
|
||||||
if attached {WSF_STRING} req.path_parameter ("type") as p_node_type and then attached api.content_type (p_node_type.value) as ct then
|
|
||||||
l_content_type := api.content_type (p_node_type.value)
|
|
||||||
end
|
|
||||||
|
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} l_response.make (req, res, api)
|
create {GENERIC_VIEW_CMS_RESPONSE} l_response.make (req, res, api)
|
||||||
|
|
||||||
create s.make_empty
|
create s.make_empty
|
||||||
@@ -83,7 +169,7 @@ feature -- HTTP Methods
|
|||||||
loop
|
loop
|
||||||
if attached {CMS_NODE_TYPE [CMS_NODE]} ic.item as l_note_type then
|
if attached {CMS_NODE_TYPE [CMS_NODE]} ic.item as l_note_type then
|
||||||
create lnk.make (l_note_type.name, "nodes/" + l_note_type.name)
|
create lnk.make (l_note_type.name, "nodes/" + l_note_type.name)
|
||||||
if l_note_type = l_content_type then
|
if l_note_type = a_content_type then
|
||||||
lnk.set_is_active (True)
|
lnk.set_is_active (True)
|
||||||
end
|
end
|
||||||
l_response.add_to_primary_tabs (lnk)
|
l_response.add_to_primary_tabs (lnk)
|
||||||
@@ -91,14 +177,14 @@ feature -- HTTP Methods
|
|||||||
end
|
end
|
||||||
|
|
||||||
create s_pager.make_empty
|
create s_pager.make_empty
|
||||||
if l_content_type /= Void then
|
if a_content_type /= Void then
|
||||||
l_count := node_api.nodes_of_type_count (l_content_type)
|
l_count := node_api.nodes_of_type_count (a_content_type)
|
||||||
if l_count > 1 then
|
if l_count > 1 then
|
||||||
l_response.set_title ("Listing " + l_count.out + " " + l_content_type.name + " nodes")
|
l_response.set_title ("Listing " + l_count.out + " " + a_content_type.name + " nodes")
|
||||||
else
|
else
|
||||||
l_response.set_title ("Listing " + l_count.out + " " + l_content_type.name + " node")
|
l_response.set_title ("Listing " + l_count.out + " " + a_content_type.name + " node")
|
||||||
end
|
end
|
||||||
create l_page_helper.make ("nodes/" + l_content_type.name + "/?page={page}&size={size}", l_count, 25) -- FIXME: Make this default page size a global CMS settings
|
create l_page_helper.make ("nodes/" + a_content_type.name + "/?page={page}&size={size}", l_count, 25) -- FIXME: Make this default page size a global CMS settings
|
||||||
else
|
else
|
||||||
l_count := node_api.nodes_count
|
l_count := node_api.nodes_count
|
||||||
if l_count > 1 then
|
if l_count > 1 then
|
||||||
@@ -117,8 +203,8 @@ feature -- HTTP Methods
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if l_content_type /= Void then
|
if a_content_type /= Void then
|
||||||
lst := node_api.recent_nodes_of_type (l_content_type, create {CMS_DATA_QUERY_PARAMETERS}.make (l_page_helper.current_page_offset, l_page_helper.page_size))
|
lst := node_api.recent_nodes_of_type (a_content_type, create {CMS_DATA_QUERY_PARAMETERS}.make (l_page_helper.current_page_offset, l_page_helper.page_size))
|
||||||
else
|
else
|
||||||
lst := node_api.recent_nodes (create {CMS_DATA_QUERY_PARAMETERS}.make (l_page_helper.current_page_offset, l_page_helper.page_size))
|
lst := node_api.recent_nodes (create {CMS_DATA_QUERY_PARAMETERS}.make (l_page_helper.current_page_offset, l_page_helper.page_size))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<library name="cms_sitemap_module" location="..\..\modules\sitemap\sitemap-safe.ecf" readonly="false"/>
|
<library name="cms_sitemap_module" location="..\..\modules\sitemap\sitemap-safe.ecf" readonly="false"/>
|
||||||
<library name="cms_taxonomy_module" location="..\..\modules\taxonomy\taxonomy-safe.ecf" readonly="false"/>
|
<library name="cms_taxonomy_module" location="..\..\modules\taxonomy\taxonomy-safe.ecf" readonly="false"/>
|
||||||
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
|
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
|
||||||
|
<library name="feed" location="$ISE_LIBRARY\contrib\library\text\parser\feed\feed-safe.ecf"/>
|
||||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
|
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
|
||||||
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\web\authentication\http_authorization\http_authorization-safe.ecf" readonly="false"/>
|
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\web\authentication\http_authorization\http_authorization-safe.ecf" readonly="false"/>
|
||||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
|
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
<library name="cms_sitemap_module" location="..\..\modules\sitemap\sitemap.ecf" readonly="false"/>
|
<library name="cms_sitemap_module" location="..\..\modules\sitemap\sitemap.ecf" readonly="false"/>
|
||||||
<library name="cms_taxonomy_module" location="..\..\modules\taxonomy\taxonomy.ecf" readonly="false"/>
|
<library name="cms_taxonomy_module" location="..\..\modules\taxonomy\taxonomy.ecf" readonly="false"/>
|
||||||
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error.ecf"/>
|
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error.ecf"/>
|
||||||
|
<library name="feed" location="$ISE_LIBRARY\contrib\library\text\parser\feed\feed.ecf"/>
|
||||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
|
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
|
||||||
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\web\authentication\http_authorization\http_authorization.ecf" readonly="false"/>
|
<library name="http_authorization" location="$ISE_LIBRARY\contrib\library\web\authentication\http_authorization\http_authorization.ecf" readonly="false"/>
|
||||||
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf"/>
|
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf"/>
|
||||||
|
|||||||
@@ -107,6 +107,14 @@ feature -- Access
|
|||||||
across Result as ic all ic.item.is_typed_as (a_node_type.name) end
|
across Result as ic all ic.item.is_typed_as (a_node_type.name) end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
recent_published_nodes_of_type (a_node_type: CMS_CONTENT_TYPE; a_lower: INTEGER; a_count: INTEGER): ITERABLE [CMS_NODE]
|
||||||
|
-- Recent published `a_count` nodes of type `a_node_type` with an offset of `lower`
|
||||||
|
deferred
|
||||||
|
ensure
|
||||||
|
expected_type: across Result as ic all ic.item.is_typed_as (a_node_type.name) end
|
||||||
|
published: across Result as ic all ic.item.is_published end
|
||||||
|
end
|
||||||
|
|
||||||
recent_node_changes_before (a_lower: INTEGER; a_count: INTEGER; a_date: DATE_TIME): LIST [CMS_NODE]
|
recent_node_changes_before (a_lower: INTEGER; a_count: INTEGER; a_date: DATE_TIME): LIST [CMS_NODE]
|
||||||
-- List of recent changes, before `a_date', according to `params' settings.
|
-- List of recent changes, before `a_date', according to `params' settings.
|
||||||
deferred
|
deferred
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ feature -- Access: node
|
|||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
recent_published_nodes_of_type (a_node_type: CMS_CONTENT_TYPE; a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
|
||||||
|
-- <Precursor>
|
||||||
|
do
|
||||||
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
|
end
|
||||||
|
|
||||||
recent_node_changes_before (a_lower: INTEGER; a_count: INTEGER; a_date: DATE_TIME): LIST [CMS_NODE]
|
recent_node_changes_before (a_lower: INTEGER; a_count: INTEGER; a_date: DATE_TIME): LIST [CMS_NODE]
|
||||||
-- List of recent changes, before `a_date', according to `params' settings.
|
-- List of recent changes, before `a_date', according to `params' settings.
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -187,6 +187,32 @@ feature -- Access
|
|||||||
sql_finalize
|
sql_finalize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
recent_published_nodes_of_type (a_node_type: CMS_CONTENT_TYPE; a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
|
||||||
|
-- <Precursor>
|
||||||
|
local
|
||||||
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
|
do
|
||||||
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
|
error_handler.reset
|
||||||
|
from
|
||||||
|
create l_parameters.make (4)
|
||||||
|
l_parameters.put (a_node_type.name, "node_type")
|
||||||
|
l_parameters.put (a_count, "size")
|
||||||
|
l_parameters.put (a_lower, "offset")
|
||||||
|
l_parameters.put ({CMS_NODE_API}.published, "status")
|
||||||
|
sql_query (sql_select_recent_published_nodes_of_type, l_parameters)
|
||||||
|
sql_start
|
||||||
|
until
|
||||||
|
sql_after
|
||||||
|
loop
|
||||||
|
if attached fetch_node as l_node then
|
||||||
|
Result.force (l_node)
|
||||||
|
end
|
||||||
|
sql_forth
|
||||||
|
end
|
||||||
|
sql_finalize
|
||||||
|
end
|
||||||
|
|
||||||
recent_node_changes_before (a_lower: INTEGER; a_count: INTEGER; a_date: DATE_TIME): LIST [CMS_NODE]
|
recent_node_changes_before (a_lower: INTEGER; a_count: INTEGER; a_date: DATE_TIME): LIST [CMS_NODE]
|
||||||
-- List of recent changes, before `a_date', according to `params' settings.
|
-- List of recent changes, before `a_date', according to `params' settings.
|
||||||
local
|
local
|
||||||
@@ -580,6 +606,12 @@ feature {NONE} -- Queries nodes
|
|||||||
Result := sql_select_all_from_nodes + " WHERE type=:node_type ORDER BY changed DESC, publish DESC LIMIT :size OFFSET :offset ;"
|
Result := sql_select_all_from_nodes + " WHERE type=:node_type ORDER BY changed DESC, publish DESC LIMIT :size OFFSET :offset ;"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sql_select_recent_published_nodes_of_type: STRING
|
||||||
|
-- published nodes order by publication_date.
|
||||||
|
once
|
||||||
|
Result := sql_select_all_from_nodes + " WHERE type=:node_type AND status=:status ORDER BY publish DESC, changed DESC LIMIT :size OFFSET :offset ;"
|
||||||
|
end
|
||||||
|
|
||||||
sql_select_recent_node_changes_before: STRING
|
sql_select_recent_node_changes_before: STRING
|
||||||
--
|
--
|
||||||
once
|
once
|
||||||
|
|||||||
Reference in New Issue
Block a user