Added helper functions to get uri path for a node, and other related resources.

Added description to cms content type.
Fixed initialization of node module to create test bed nodes.
This commit is contained in:
2015-04-14 16:07:09 +02:00
parent 133c243126
commit ea2b5b87d3
10 changed files with 172 additions and 43 deletions

View File

@@ -59,6 +59,34 @@ feature -- Content type
end
end
feature -- URL
new_content_path (ct: detachable CMS_CONTENT_TYPE): STRING
-- URI path for new content of type `ct'
-- or URI of path for selection of new content possibilities if ct is Void.
do
if ct /= Void then
Result := "/node/new/" + ct.name
else
Result := "/node/new"
end
end
node_path (a_node: CMS_NODE): STRING
-- URI path for node `a_node'.
-- using the /node/{nid} url.
require
a_node.has_id
do
Result := "/node/" + a_node.id.out
end
nodes_path: STRING
-- URI path for list of nodes.
do
Result := "/nodes"
end
feature -- Access: Node
nodes_count: INTEGER_64

View File

@@ -18,6 +18,9 @@ feature -- Access
title: STRING_32 = "Page"
-- Human readable name.
description: STRING_32 = "Use basic pages for your content, such as an 'About us' page."
-- Optional description
feature -- Factory
new_node (a_partial_node: detachable CMS_NODE): CMS_PAGE

View File

@@ -1,5 +1,5 @@
note
description: "Summary description for {NODE_HANDLER}."
description: "CMS handler for a node."
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
@@ -76,9 +76,6 @@ feature -- HTTP Methods
l_page.add_variable (l_node, "node")
create s.make_empty
s.append ("<h1 class=%"title%">")
s.append (html_encoded (l_node.title))
s.append ("</h1>")
s.append ("<div class=%"info%"> ")
if attached l_node.author as l_author then
s.append (" by ")
@@ -99,13 +96,11 @@ feature -- HTTP Methods
if attached {CMS_PAGE} l_node as l_node_page then
if attached l_node_page.parent as l_parent_node then
s.append ("<div>Parent page is ")
s.append ("<a href=%"/node/" + l_parent_node.id.out + "%">")
s.append (l_parent_node.title)
s.append (" (#")
s.append (l_parent_node.id.out)
s.append (")</a></div>")
s.append (l_page.link (l_parent_node.title + " (#" + l_parent_node.id.out + ")", node_api.node_path (l_parent_node), Void))
s.append ("</div>")
end
end
l_page.set_title (l_node.title)
l_page.set_main_content (s)
l_page.execute
else

View File

@@ -58,14 +58,7 @@ feature -- HTTP Methods
loop
n := ic.item
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
s.append ("<a href=%"")
s.append (req.script_url ("/node/" + n.id.out))
s.append ("%">")
s.append (api.html_encoded (n.title))
s.append (" (")
s.append (n.id.out)
s.append (")")
s.append ("</a>")
s.append (l_page.link (n.title + " (#" + n.id.out + ")", node_api.node_path (n), Void))
s.append ("</li>%N")
end
s.append ("</ul>%N")

View File

@@ -42,10 +42,32 @@ feature {CMS_API} -- Module Initialization
initialize (api: CMS_API)
-- <Precursor>
local
p1,p2: CMS_PAGE
ct: CMS_PAGE_CONTENT_TYPE
do
Precursor (api)
if attached {CMS_NODE_STORAGE_SQL} api.storage as l_sql_storage then
l_sql_storage.register_node_storage_extension (create {CMS_NODE_STORAGE_SQL_PAGE_EXTENSION}.make (l_sql_storage))
if l_sql_storage.sql_table_items_count ("page_nodes") = 0 then
-- Data
-- FIXME: for test purpose, remove later
if attached api.user_api.user_by_id (1) as u then
create ct
p1 := ct.new_node (Void)
p1.set_title ("Welcome")
p1.set_content ("Welcome, you are using the ROC Eiffel CMS", "Welcome Eiffel ROC user", Void) -- Use default format
p1.set_author (u)
api.storage.save_node (p1)
p2 := ct.new_node (Void)
p2.set_title ("A new page example")
p2.set_content ("This is the content of a page", "This is a new page", Void) -- Use default format
p2.set_author (u)
p2.set_parent (p1)
api.storage.save_node (p2)
end
end
else
-- FIXME: maybe provide a default solution based on file system, when no SQL storage is available.
end
@@ -63,32 +85,11 @@ feature {CMS_API} -- Module management
end
install (api: CMS_API)
local
p1,p2: CMS_PAGE
ct: CMS_PAGE_CONTENT_TYPE
do
-- Schema
if attached {CMS_STORAGE_SQL} api.storage as l_sql_storage then
l_sql_storage.sql_execute_file_script (api.setup.layout.path.extended ("scripts").extended (name).appended_with_extension ("sql"))
end
-- Data
-- FIXME: for test purpose, remove later
if attached api.user_api.user_by_id (1) as u then
create ct
p1 := ct.new_node (Void)
p1.set_title ("Welcome")
p1.set_content ("Welcome, you are using the ROC Eiffel CMS", "Welcome Eiffel ROC user", Void) -- Use default format
p1.set_author (u)
api.storage.save_node (p1)
p2 := ct.new_node (Void)
p2.set_title ("A new page example")
p2.set_content ("This is the content of a page", "This is a new page", Void) -- Use default format
p2.set_author (u)
p2.set_parent (p1)
api.storage.save_node (p2)
end
end
feature -- Access: router
@@ -121,7 +122,7 @@ feature -- Access: router
create l_new_node_handler.make (a_api, a_node_api)
a_router.handle_with_request_methods ("/node/new/{type}", create {WSF_URI_AGENT_HANDLER}.make (agent do_get_node_creation_by_type (?,?, "type", a_node_api)), a_router.methods_get)
a_router.handle_with_request_methods ("/node/new", create {WSF_URI_AGENT_HANDLER}.make (agent do_get_node_creation_selection (?,?, a_api)), a_router.methods_get)
a_router.handle_with_request_methods ("/node/new", create {WSF_URI_AGENT_HANDLER}.make (agent do_get_node_creation_selection (?,?, a_node_api)), a_router.methods_get)
create l_edit_node_handler.make (a_api, a_node_api)
a_router.handle_with_request_methods ("/node/{id}/edit", l_edit_node_handler, a_router.methods_get_post)
@@ -245,11 +246,30 @@ feature -- Hooks
feature -- Handler
do_get_node_creation_selection (req: WSF_REQUEST; res: WSF_RESPONSE; a_api: CMS_API)
do_get_node_creation_selection (req: WSF_REQUEST; res: WSF_RESPONSE; a_node_api: CMS_NODE_API)
local
l_page: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE
l_page: GENERIC_VIEW_CMS_RESPONSE
s: STRING
do
create l_page.make (req, res, a_api)
create l_page.make (req, res, a_node_api.cms_api)
create s.make_empty
s.append ("<ul>")
across
a_node_api.content_types as ic
loop
s.append ("<li>")
s.append (l_page.link (ic.item.title, a_node_api.new_content_path (ic.item), Void))
if attached ic.item.description as l_description then
s.append ("<p class=%"description%">")
s.append (l_page.html_encoded (l_description))
s.append ("</p>")
end
s.append ("</li>")
end
s.append ("</ul>")
l_page.set_title ("Create new content ...")
l_page.set_main_content (s)
l_page.execute
end