added blog handler that lists all blog entries
This commit is contained in:
@@ -8,11 +8,14 @@ class
|
|||||||
|
|
||||||
inherit
|
inherit
|
||||||
CMS_MODULE
|
CMS_MODULE
|
||||||
|
rename
|
||||||
|
module_api as node_api
|
||||||
redefine
|
redefine
|
||||||
register_hooks,
|
register_hooks,
|
||||||
initialize,
|
initialize,
|
||||||
is_installed,
|
is_installed,
|
||||||
install
|
install,
|
||||||
|
node_api
|
||||||
end
|
end
|
||||||
|
|
||||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
CMS_HOOK_MENU_SYSTEM_ALTER
|
||||||
@@ -36,10 +39,12 @@ feature {CMS_API} -- Module Initialization
|
|||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
ct: CMS_BLOG_NODE_TYPE
|
ct: CMS_BLOG_NODE_TYPE
|
||||||
|
l_node_api: like node_api
|
||||||
do
|
do
|
||||||
Precursor (api)
|
Precursor (api)
|
||||||
|
create l_node_api.make (api)
|
||||||
|
node_api := l_node_api
|
||||||
|
|
||||||
if attached {CMS_NODE_API} api.module_api ({NODE_MODULE}) as l_node_api then
|
|
||||||
create ct
|
create ct
|
||||||
l_node_api.add_content_type (ct)
|
l_node_api.add_content_type (ct)
|
||||||
l_node_api.add_content_type_webform_manager (create {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
|
l_node_api.add_content_type_webform_manager (create {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
|
||||||
@@ -49,7 +54,6 @@ feature {CMS_API} -- Module Initialization
|
|||||||
l_sql_node_storage.register_node_storage_extension (create {CMS_NODE_STORAGE_SQL_BLOG_EXTENSION}.make (l_sql_node_storage))
|
l_sql_node_storage.register_node_storage_extension (create {CMS_NODE_STORAGE_SQL_BLOG_EXTENSION}.make (l_sql_node_storage))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
feature {CMS_API} -- Module management
|
feature {CMS_API} -- Module management
|
||||||
|
|
||||||
@@ -82,12 +86,45 @@ CREATE TABLE "blog_post_nodes"(
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature {CMS_API} -- Access: API
|
||||||
|
|
||||||
|
node_api: detachable CMS_NODE_API
|
||||||
|
-- <Precursor>
|
||||||
|
|
||||||
feature -- Access: router
|
feature -- Access: router
|
||||||
|
|
||||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
|
local
|
||||||
|
l_node_api: like node_api
|
||||||
do
|
do
|
||||||
a_router.handle_with_request_methods ("/blogs/", create {WSF_URI_AGENT_HANDLER}.make (agent handle_blogs (?,?, a_api)), a_router.methods_get)
|
l_node_api := node_api
|
||||||
|
if l_node_api = Void then
|
||||||
|
create l_node_api.make (a_api)
|
||||||
|
node_api := l_node_api
|
||||||
|
end
|
||||||
|
configure_web (a_api, l_node_api, a_router)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--feature -- Access: router
|
||||||
|
|
||||||
|
--setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||||
|
-- <Precursor>
|
||||||
|
-- do
|
||||||
|
-- a_router.handle_with_request_methods ("/blogs/", create {WSF_URI_AGENT_HANDLER}.make (agent handle_blogs (?,?, a_api)), a_router.methods_get)
|
||||||
|
-- end
|
||||||
|
|
||||||
|
configure_web (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||||
|
local
|
||||||
|
l_blog_handler: BLOG_HANDLER
|
||||||
|
l_uri_mapping: WSF_URI_MAPPING
|
||||||
|
do
|
||||||
|
-- TODO: for now, focused only on web interface, add REST api later. [2015-May-18]
|
||||||
|
--create l_blog_handler.make (a_api, a_node_api)
|
||||||
|
--create l_uri_mapping.make_trailing_slash_ignored ("/blogs", l_blog_handler)
|
||||||
|
--a_router.map_with_request_methods (l_uri_mapping, a_router.methods_get)
|
||||||
|
--a_router.handle_with_request_methods ("/node/{id}", l_node_handler, a_router.methods_get)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Hooks
|
feature -- Hooks
|
||||||
|
|||||||
@@ -4,12 +4,15 @@ ul.cms-nodes {
|
|||||||
border: solid 1px #ccc;
|
border: solid 1px #ccc;
|
||||||
}
|
}
|
||||||
|
|
||||||
li.cms_type_page {
|
li.cms_type_page, li.cms_type_blog {
|
||||||
border-top: dotted 1px #ccc;
|
border-top: dotted 1px #ccc;
|
||||||
}
|
}
|
||||||
li.cms_type_page a::before {
|
li.cms_type_page a::before {
|
||||||
content: "[page] ";
|
content: "[page] ";
|
||||||
}
|
}
|
||||||
li.cms_type_page:first-child {
|
li.cms_type_blog a::before {
|
||||||
|
content: "[blog] ";
|
||||||
|
}
|
||||||
|
ul.cms-nodes li:first-child {
|
||||||
border-top: none;
|
border-top: none;
|
||||||
}
|
}
|
||||||
|
|||||||
64
modules/node/handler/blog_handler.e
Normal file
64
modules/node/handler/blog_handler.e
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
note
|
||||||
|
description: "Request handler related to /blogs."
|
||||||
|
author: "Dario B<>sch <daboesch@student.ethz.ch"
|
||||||
|
date: "$Date: 2015-05-18 13:49:99 +0100 (lun., 18 mai 2015) $"
|
||||||
|
revision: "$966167$"
|
||||||
|
|
||||||
|
class
|
||||||
|
BLOG_HANDLER
|
||||||
|
|
||||||
|
inherit
|
||||||
|
NODES_HANDLER
|
||||||
|
redefine
|
||||||
|
do_get
|
||||||
|
end
|
||||||
|
|
||||||
|
create
|
||||||
|
make
|
||||||
|
|
||||||
|
feature -- HTTP Methods
|
||||||
|
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||||
|
-- <Precursor>
|
||||||
|
local
|
||||||
|
l_page: CMS_RESPONSE
|
||||||
|
s: STRING
|
||||||
|
n: CMS_NODE
|
||||||
|
lnk: CMS_LOCAL_LINK
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
|
-- NOTE: for development purposes we have the following hardcode output.
|
||||||
|
create s.make_from_string ("<h2>Blog entries:</h2>")
|
||||||
|
if attached node_api.nodes as lst then
|
||||||
|
-- Filter out blog entries from all nodes
|
||||||
|
--if n.content_type.is_equal ("blog") then
|
||||||
|
s.append ("<ul class=%"cms-nodes%">%N")
|
||||||
|
across
|
||||||
|
lst as ic
|
||||||
|
loop
|
||||||
|
n := ic.item
|
||||||
|
if n.content_type.is_equal ("blog") then
|
||||||
|
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 ("</li>%N")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
s.append ("</ul>%N")
|
||||||
|
--end
|
||||||
|
end
|
||||||
|
|
||||||
|
l_page.set_main_content (s)
|
||||||
|
l_page.add_block (create {CMS_CONTENT_BLOCK}.make ("nodes_warning", Void, "/blogs/ is not yet fully implemented<br/>", Void), "highlighted")
|
||||||
|
l_page.execute
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user