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

@@ -41,6 +41,16 @@ ul.horizontal {
} }
#content { #content {
margin-left: 20px; margin-left: 20px;
#highlighted {
position: relative;
border: solid 1px #ddd;
background-color: #ffc;
width: 70%;
left: 15%;
right: 15%;
padding: 5px;
font-style: italic;
}
} }
.sidebar { .sidebar {
padding: 5px; padding: 5px;

View File

@@ -21,6 +21,11 @@ feature -- Access
deferred deferred
end end
description: detachable READABLE_STRING_32
-- Optional description
deferred
end
feature -- Factory feature -- Factory
new_node (a_partial_node: detachable CMS_NODE): CMS_NODE new_node (a_partial_node: detachable CMS_NODE): CMS_NODE

View File

@@ -59,6 +59,34 @@ feature -- Content type
end end
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 feature -- Access: Node
nodes_count: INTEGER_64 nodes_count: INTEGER_64

View File

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

View File

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

View File

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

View File

@@ -42,10 +42,32 @@ feature {CMS_API} -- Module Initialization
initialize (api: CMS_API) initialize (api: CMS_API)
-- <Precursor> -- <Precursor>
local
p1,p2: CMS_PAGE
ct: CMS_PAGE_CONTENT_TYPE
do do
Precursor (api) Precursor (api)
if attached {CMS_NODE_STORAGE_SQL} api.storage as l_sql_storage then 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)) 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 else
-- FIXME: maybe provide a default solution based on file system, when no SQL storage is available. -- FIXME: maybe provide a default solution based on file system, when no SQL storage is available.
end end
@@ -63,32 +85,11 @@ feature {CMS_API} -- Module management
end end
install (api: CMS_API) install (api: CMS_API)
local
p1,p2: CMS_PAGE
ct: CMS_PAGE_CONTENT_TYPE
do do
-- Schema -- Schema
if attached {CMS_STORAGE_SQL} api.storage as l_sql_storage then 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")) l_sql_storage.sql_execute_file_script (api.setup.layout.path.extended ("scripts").extended (name).appended_with_extension ("sql"))
end 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 end
feature -- Access: router feature -- Access: router
@@ -121,7 +122,7 @@ feature -- Access: router
create l_new_node_handler.make (a_api, a_node_api) 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/{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) 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) 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 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 local
l_page: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE l_page: GENERIC_VIEW_CMS_RESPONSE
s: STRING
do 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 l_page.execute
end end

View File

@@ -163,6 +163,20 @@ feature -- Helper
-- FIXME: find better solution -- FIXME: find better solution
end end
sql_table_items_count (a_table_name: READABLE_STRING_8): INTEGER_64
-- Number of items in table `a_table_name'?
local
l_params: STRING_TABLE [detachable ANY]
do
reset_error
create l_params.make (1)
l_params.force (a_table_name, "tbname")
sql_query ("SELECT count(*) FROM :tbname ;", l_params)
if not has_error then
Result := sql_read_integer_64 (1)
end
end
feature -- Access feature -- Access
sql_rows_count: INTEGER sql_rows_count: INTEGER

View File

@@ -48,7 +48,7 @@ feature -- Persistence
l_parameters.put (a_node.revision, "revision") l_parameters.put (a_node.revision, "revision")
sql_query (sql_select_page_data, l_parameters) sql_query (sql_select_page_data, l_parameters)
if has_error then if not has_error then
if sql_rows_count = 1 then if sql_rows_count = 1 then
l_previous_parent_id := sql_read_integer_64 (3) l_previous_parent_id := sql_read_integer_64 (3)
l_update := True l_update := True

View File

@@ -39,6 +39,62 @@ feature -- Core
end end
end end
feature -- Link
link (a_text: detachable READABLE_STRING_GENERAL; a_path: READABLE_STRING_8; opts: detachable CMS_API_OPTIONS): STRING
do
create Result.make (32)
append_link_to_html (a_text, a_path, opts, Result)
end
link_with_raw_text (a_raw_text: detachable READABLE_STRING_8; a_path: READABLE_STRING_8; opts: detachable CMS_API_OPTIONS): STRING
do
create Result.make (32)
append_link_with_raw_text_to_html (a_raw_text, a_path, opts, Result)
end
append_link_to_html (a_text: detachable READABLE_STRING_GENERAL; a_path: READABLE_STRING_8; opts: detachable CMS_API_OPTIONS; a_html: STRING_8)
local
l_html: BOOLEAN
t: READABLE_STRING_GENERAL
do
l_html := True
if opts /= Void then
l_html := opts.boolean_item ("html", l_html)
end
a_html.append ("<a href=%"" + checked_url (url (a_path, opts)) + "%">")
if a_text = Void then
t := a_path
else
t := a_text
end
if l_html then
a_html.append (html_encoded (t))
else
a_html.append (checked_plain (t))
end
a_html.append ("</a>")
end
append_link_with_raw_text_to_html (a_raw_text: detachable READABLE_STRING_8; a_path: READABLE_STRING_8; opts: detachable CMS_API_OPTIONS; a_html: STRING_8)
local
l_html: BOOLEAN
t: READABLE_STRING_8
do
l_html := True
if opts /= Void then
l_html := opts.boolean_item ("html", l_html)
end
a_html.append ("<a href=%"" + checked_url (url (a_path, opts)) + "%">")
if a_raw_text = Void then
t := a_path
else
t := a_raw_text
end
a_html.append (t)
a_html.append ("</a>")
end
feature -- Url feature -- Url
absolute_url (a_path: STRING; opts: detachable CMS_API_OPTIONS): STRING absolute_url (a_path: STRING; opts: detachable CMS_API_OPTIONS): STRING
@@ -126,4 +182,9 @@ feature -- Url
Result := a_url Result := a_url
end end
checked_plain (a_text: READABLE_STRING_GENERAL): STRING_8
do
Result := html_encoded (a_text)
end
end end