Cleaned the node module, to remove for now the REST api attempt.
This will be redone with care once the web cms is ready.
This commit is contained in:
@@ -7,7 +7,7 @@ class
|
||||
CMS_BLOG_NODE_TYPE
|
||||
|
||||
inherit
|
||||
CMS_NODE_TYPE
|
||||
CMS_NODE_TYPE [CMS_BLOG]
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
@@ -54,14 +54,14 @@ feature -- Content type
|
||||
content_types: ARRAYED_LIST [CMS_CONTENT_TYPE]
|
||||
-- Available content types
|
||||
|
||||
node_types: ARRAYED_LIST [CMS_NODE_TYPE]
|
||||
node_types: ARRAYED_LIST [attached like node_type]
|
||||
-- Node content types.
|
||||
do
|
||||
create Result.make (content_types.count)
|
||||
across
|
||||
content_types as ic
|
||||
loop
|
||||
if attached {CMS_NODE_TYPE} ic.item as l_node_type then
|
||||
if attached {like node_type} ic.item as l_node_type then
|
||||
Result.extend (l_node_type)
|
||||
end
|
||||
end
|
||||
@@ -88,7 +88,7 @@ feature -- Content type
|
||||
end
|
||||
end
|
||||
|
||||
node_type (a_name: READABLE_STRING_GENERAL): detachable CMS_NODE_TYPE
|
||||
node_type (a_name: READABLE_STRING_GENERAL): detachable CMS_NODE_TYPE [CMS_NODE]
|
||||
-- Content type named `a_named' if any.
|
||||
do
|
||||
across
|
||||
@@ -105,7 +105,7 @@ feature -- Content type
|
||||
end
|
||||
end
|
||||
|
||||
node_type_for (a_node: CMS_NODE): detachable CMS_NODE_TYPE
|
||||
node_type_for (a_node: CMS_NODE): like node_type
|
||||
-- Content type for node `a_node' if any.
|
||||
local
|
||||
l_type_name: READABLE_STRING_8
|
||||
@@ -143,7 +143,7 @@ feature -- Content type webform
|
||||
end
|
||||
end
|
||||
|
||||
node_type_webform_manager (a_node_type: CMS_NODE_TYPE): detachable CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
node_type_webform_manager (a_node_type: CMS_CONTENT_TYPE): detachable CMS_NODE_TYPE_WEBFORM_MANAGER_I [CMS_NODE]
|
||||
-- Web form manager for node type `a_node_type' if any.
|
||||
local
|
||||
l_type_name: READABLE_STRING_GENERAL
|
||||
@@ -155,7 +155,7 @@ feature -- Content type webform
|
||||
Result /= Void
|
||||
loop
|
||||
if
|
||||
attached {CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER} ic.item as l_manager and then
|
||||
attached {like node_type_webform_manager} ic.item as l_manager and then
|
||||
l_type_name.is_case_insensitive_equal (l_manager.name)
|
||||
then
|
||||
Result := l_manager
|
||||
@@ -165,14 +165,14 @@ feature -- Content type webform
|
||||
|
||||
feature -- URL
|
||||
|
||||
new_content_path (ct: detachable CMS_NODE_TYPE): STRING
|
||||
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/add/" + ct.name
|
||||
else
|
||||
Result := "/node/new"
|
||||
Result := "/node/"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,19 +7,19 @@ note
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
CMS_NODE_TYPE
|
||||
CMS_NODE_TYPE [G -> CMS_NODE]
|
||||
|
||||
inherit
|
||||
CMS_CONTENT_TYPE
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node
|
||||
new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node
|
||||
-- New node with `a_title' and fill from partial `a_partial_node' if set.
|
||||
deferred
|
||||
end
|
||||
|
||||
new_node (a_partial_node: detachable CMS_NODE): CMS_NODE
|
||||
new_node (a_partial_node: detachable CMS_NODE): G
|
||||
-- New node based on partial `a_partial_node' if set.
|
||||
deferred
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ class
|
||||
CMS_PAGE_NODE_TYPE
|
||||
|
||||
inherit
|
||||
CMS_NODE_TYPE
|
||||
CMS_NODE_TYPE [CMS_PAGE]
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
@@ -3,14 +3,11 @@ note
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
deferred class
|
||||
CMS_NODE_TYPE_WEBFORM_MANAGER [G -> CMS_NODE]
|
||||
|
||||
inherit
|
||||
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
|
||||
create
|
||||
make
|
||||
CMS_NODE_TYPE_WEBFORM_MANAGER_I [G]
|
||||
|
||||
feature -- Forms ...
|
||||
|
||||
@@ -68,7 +65,6 @@ feature -- Forms ...
|
||||
fset.extend (tselect)
|
||||
|
||||
f.extend (fset)
|
||||
|
||||
end
|
||||
|
||||
update_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
@@ -98,7 +94,7 @@ feature -- Forms ...
|
||||
end
|
||||
end
|
||||
|
||||
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable CMS_NODE): like content_type.new_node
|
||||
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable CMS_NODE): G
|
||||
-- <Precursor>
|
||||
local
|
||||
b: detachable READABLE_STRING_8
|
||||
|
||||
@@ -7,7 +7,7 @@ note
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
CMS_NODE_TYPE_WEBFORM_MANAGER_I [G -> CMS_NODE]
|
||||
|
||||
inherit
|
||||
CMS_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
@@ -17,7 +17,7 @@ inherit
|
||||
|
||||
feature -- Access
|
||||
|
||||
content_type: CMS_NODE_TYPE
|
||||
content_type: CMS_NODE_TYPE [G]
|
||||
-- Associated content type.
|
||||
|
||||
feature -- Query
|
||||
@@ -39,7 +39,7 @@ feature -- Forms ...
|
||||
|
||||
feature -- Node ...
|
||||
|
||||
new_node (response: NODE_RESPONSE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): like content_type.new_node
|
||||
new_node (response: NODE_RESPONSE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): G
|
||||
-- New typed node with data from `a_form_data', and eventually data from `a_node' if set.
|
||||
require
|
||||
a_node = Void or else has_valid_node_type (a_node)
|
||||
@@ -40,7 +40,6 @@ feature -- Execution
|
||||
f: like edit_form
|
||||
fd: detachable WSF_FORM_DATA
|
||||
nid: INTEGER_64
|
||||
l_node_type: CMS_NODE_TYPE
|
||||
do
|
||||
create b.make_empty
|
||||
nid := node_id_path_parameter (request)
|
||||
@@ -111,10 +110,9 @@ feature -- Execution
|
||||
across
|
||||
node_api.node_types as ic
|
||||
loop
|
||||
l_node_type := ic.item
|
||||
if
|
||||
has_permission ("create any")
|
||||
or has_permission ("create " + l_node_type.name)
|
||||
attached ic.item as l_node_type and then
|
||||
(has_permission ("create any") or has_permission ("create " + l_node_type.name))
|
||||
then
|
||||
b.append ("<li>" + link (l_node_type.name, "/node/add/" + l_node_type.name, Void))
|
||||
if attached l_node_type.description as d then
|
||||
@@ -157,7 +155,7 @@ feature -- Form
|
||||
end
|
||||
end
|
||||
|
||||
edit_form_submit (fd: WSF_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_NODE_TYPE; b: STRING)
|
||||
edit_form_submit (fd: WSF_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_NODE_TYPE [CMS_NODE]; b: STRING)
|
||||
local
|
||||
l_preview: BOOLEAN
|
||||
l_node: detachable CMS_NODE
|
||||
@@ -202,7 +200,7 @@ feature -- Form
|
||||
end
|
||||
end
|
||||
|
||||
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_NODE_TYPE): CMS_FORM
|
||||
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_NODE_TYPE [CMS_NODE]): CMS_FORM
|
||||
local
|
||||
f: CMS_FORM
|
||||
ts: WSF_FORM_SUBMIT_INPUT
|
||||
@@ -233,7 +231,7 @@ feature -- Form
|
||||
Result := f
|
||||
end
|
||||
|
||||
new_node (a_content_type: CMS_NODE_TYPE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): CMS_NODE
|
||||
new_node (a_content_type: CMS_NODE_TYPE [CMS_NODE]; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): CMS_NODE
|
||||
--
|
||||
do
|
||||
if attached node_api.node_type_webform_manager (a_content_type) as wf then
|
||||
@@ -243,7 +241,7 @@ feature -- Form
|
||||
end
|
||||
end
|
||||
|
||||
change_node (a_content_type: CMS_NODE_TYPE; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
change_node (a_content_type: CMS_NODE_TYPE [CMS_NODE]; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
-- Update node `a_node' with form_data `a_form_data' for the given content type `a_content_type'.
|
||||
do
|
||||
if attached node_api.node_type_webform_manager (a_content_type) as wf then
|
||||
@@ -251,7 +249,7 @@ feature -- Form
|
||||
end
|
||||
end
|
||||
|
||||
fill_edit_form (a_content_type: CMS_NODE_TYPE; a_form: WSF_FORM; a_node: detachable CMS_NODE)
|
||||
fill_edit_form (a_content_type: CMS_NODE_TYPE [CMS_NODE]; a_form: WSF_FORM; a_node: detachable CMS_NODE)
|
||||
do
|
||||
if attached node_api.node_type_webform_manager (a_content_type) as wf then
|
||||
wf.populate_form (Current, a_form, a_node)
|
||||
|
||||
@@ -60,6 +60,21 @@ feature -- execute
|
||||
execute (req, res)
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
node_id_path_parameter (req: WSF_REQUEST): INTEGER_64
|
||||
-- Node id passed as path parameter for request `req'.
|
||||
local
|
||||
s: STRING
|
||||
do
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as p_nid then
|
||||
s := p_nid.value
|
||||
if s.is_integer_64 then
|
||||
Result := s.to_integer_64
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- HTTP Methods
|
||||
|
||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
@@ -71,28 +86,24 @@ feature -- HTTP Methods
|
||||
view_response: NODE_VIEW_RESPONSE
|
||||
do
|
||||
if req.path_info.ends_with_general ("/edit") then
|
||||
check valid_url: req.path_info.starts_with_general ("/node/") end
|
||||
create edit_response.make (req, res, api, node_api)
|
||||
edit_response.execute
|
||||
else
|
||||
-- Existing node
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer then
|
||||
l_nid := l_id.value.to_integer_64
|
||||
end
|
||||
end
|
||||
-- Display existing node
|
||||
l_nid := node_id_path_parameter (req)
|
||||
if l_nid > 0 then
|
||||
l_node := node_api.node (l_nid)
|
||||
end
|
||||
if l_node /= Void then
|
||||
create view_response.make (req, res, api, node_api)
|
||||
view_response.set_node (l_node)
|
||||
view_response.execute
|
||||
elseif l_nid > 0 then --| i.e: l_node = Void
|
||||
send_not_found (req, res)
|
||||
if l_node /= Void then
|
||||
create view_response.make (req, res, api, node_api)
|
||||
view_response.set_node (l_node)
|
||||
view_response.execute
|
||||
else
|
||||
send_not_found (req, res)
|
||||
end
|
||||
else
|
||||
-- redirect_to (req.absolute_script_url ("/node/"), res) -- New node.
|
||||
-- send_bad_request (req, res)
|
||||
-- FIXME: should not be accepted
|
||||
-- Factory
|
||||
create_new_node (req, res)
|
||||
end
|
||||
end
|
||||
@@ -106,61 +117,20 @@ feature -- HTTP Methods
|
||||
if req.path_info.ends_with_general ("/edit") then
|
||||
create edit_response.make (req, res, api, node_api)
|
||||
edit_response.execute
|
||||
elseif req.path_info.starts_with_general ("/node/add/") then
|
||||
create edit_response.make (req, res, api, node_api)
|
||||
edit_response.execute
|
||||
-- elseif req.path_info.same_string_general ("/node/") then
|
||||
-- create edit_response.make (req, res, api, node_api)
|
||||
-- edit_response.execute
|
||||
else
|
||||
handle_not_implemented ("REST API not yet implemented", req, res)
|
||||
-- to_implement ("Check user permissions!!!")
|
||||
-- if attached current_user (req) as l_user then
|
||||
-- if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
-- if
|
||||
-- l_id.is_integer and then
|
||||
-- attached node_api.node (l_id.value.to_integer_64) as l_node
|
||||
-- then
|
||||
-- if attached {WSF_STRING} req.form_parameter ("method") as l_method then
|
||||
-- if l_method.is_case_insensitive_equal ("DELETE") then
|
||||
-- do_delete (req, res)
|
||||
-- elseif l_method.is_case_insensitive_equal ("PUT") then
|
||||
-- do_put (req, res)
|
||||
-- else
|
||||
-- process_node_update (req, res, l_user, l_node)
|
||||
-- -- Accept this, even if this is not proper usage of POST
|
||||
-- -- (create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
-- end
|
||||
-- end
|
||||
-- else
|
||||
-- do_error (req, res, l_id)
|
||||
-- end
|
||||
-- else
|
||||
-- process_node_creation (req, res, l_user)
|
||||
-- end
|
||||
-- else
|
||||
-- send_access_denied (req, res)
|
||||
-- end
|
||||
to_implement ("REST API")
|
||||
send_not_implemented ("REST API not yet implemented", req, res)
|
||||
end
|
||||
end
|
||||
|
||||
do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- <Precursor>
|
||||
do
|
||||
handle_not_implemented ("REST API not yet implemented", req, res)
|
||||
-- if attached current_user (req) as l_user then
|
||||
-- if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
-- if
|
||||
-- l_id.is_integer and then
|
||||
-- attached node_api.node (l_id.value.to_integer_64) as l_node
|
||||
-- then
|
||||
-- process_node_update (req, res, l_user, l_node)
|
||||
-- else
|
||||
-- do_error (req, res, l_id)
|
||||
-- end
|
||||
-- else
|
||||
-- (create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
-- end
|
||||
-- else
|
||||
-- send_access_denied (req, res)
|
||||
-- end
|
||||
to_implement ("REST API")
|
||||
send_not_implemented ("REST API not yet implemented", req, res)
|
||||
end
|
||||
|
||||
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
@@ -190,51 +160,11 @@ feature -- HTTP Methods
|
||||
end
|
||||
|
||||
process_node_creation (req: WSF_REQUEST; res: WSF_RESPONSE; a_user: CMS_USER)
|
||||
local
|
||||
-- u_node: CMS_NODE
|
||||
do
|
||||
-- New node
|
||||
-- FIXME !!!
|
||||
handle_not_implemented ("REST API not yet implemented", req, res)
|
||||
-- if
|
||||
-- attached {WSF_STRING} req.form_parameter ("type") as p_type and then
|
||||
-- attached node_api.node_type (p_type.value) as ct -- should be string 8 value.
|
||||
-- then
|
||||
-- if api.user_has_permission (a_user, "create " + ct.name) then
|
||||
-- u_node := ct.new_node (Void)
|
||||
-- -- create {CMS_PARTIAL_NODE} u_node.make_empty (p_type.url_encoded_value)
|
||||
-- update_node_from_data_form (req, u_node)
|
||||
-- u_node.set_author (a_user)
|
||||
-- node_api.new_node (u_node)
|
||||
-- if attached {WSF_STRING} req.item ("destination") as p_destination then
|
||||
-- redirect_to (req.absolute_script_url (p_destination.url_encoded_value), res)
|
||||
-- else
|
||||
-- redirect_to (req.absolute_script_url (""), res)
|
||||
-- end
|
||||
-- else
|
||||
-- send_access_denied (req, res)
|
||||
-- end
|
||||
-- else
|
||||
-- do_error (req, res, Void)
|
||||
-- end
|
||||
to_implement ("REST API")
|
||||
send_not_implemented ("REST API not yet implemented", req, res)
|
||||
end
|
||||
|
||||
-- process_node_update (req: WSF_REQUEST; res: WSF_RESPONSE; a_user: CMS_USER; a_node: CMS_NODE)
|
||||
-- do
|
||||
-- if api.user_has_permission (a_user, "modify " + a_node.content_type) then
|
||||
-- update_node_from_data_form (req, a_node)
|
||||
-- a_node.set_author (a_user)
|
||||
-- node_api.update_node (a_node)
|
||||
-- if attached {WSF_STRING} req.item ("destination") as p_destination then
|
||||
-- redirect_to (req.absolute_script_url (p_destination.url_encoded_value), res)
|
||||
-- else
|
||||
-- redirect_to (req.absolute_script_url (""), res)
|
||||
-- end
|
||||
-- else
|
||||
-- send_access_denied (req, res)
|
||||
-- end
|
||||
-- end
|
||||
|
||||
feature -- Error
|
||||
|
||||
do_error (req: WSF_REQUEST; res: WSF_RESPONSE; a_id: detachable WSF_STRING)
|
||||
@@ -260,47 +190,16 @@ feature {NONE} -- Node
|
||||
|
||||
create_new_node (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
l_gen_page: GENERIC_VIEW_CMS_RESPONSE
|
||||
edit_response: NODE_FORM_RESPONSE
|
||||
s: STRING
|
||||
do
|
||||
if req.path_info.starts_with_general ("/node/add/") then
|
||||
if req.path_info.starts_with_general ("/node/") then
|
||||
create edit_response.make (req, res, api, node_api)
|
||||
edit_response.execute
|
||||
elseif req.is_get_request_method then
|
||||
redirect_to (req.absolute_script_url ("/node/add/"), res)
|
||||
redirect_to (req.absolute_script_url ("/node/"), res)
|
||||
else
|
||||
send_bad_request (req, res)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- {NONE} Form data
|
||||
|
||||
-- update_node_from_data_form (req: WSF_REQUEST; a_node: CMS_NODE)
|
||||
-- -- Extract request form data and build a object
|
||||
-- -- Node
|
||||
-- local
|
||||
-- l_title: detachable READABLE_STRING_32
|
||||
-- l_summary, l_content, l_format: detachable READABLE_STRING_8
|
||||
-- do
|
||||
-- if attached {WSF_STRING} req.form_parameter ("title") as p_title then
|
||||
-- l_title := p_title.value
|
||||
-- a_node.set_title (l_title)
|
||||
-- end
|
||||
-- if attached {WSF_STRING} req.form_parameter ("summary") as p_summary then
|
||||
-- l_summary := html_encoded (p_summary.value)
|
||||
-- end
|
||||
-- if attached {WSF_STRING} req.form_parameter ("content") as p_content then
|
||||
-- l_content := html_encoded (p_content.value)
|
||||
-- end
|
||||
-- if attached {WSF_STRING} req.form_parameter ("format") as p_format then
|
||||
-- l_format := p_format.url_encoded_value
|
||||
-- end
|
||||
-- if l_format = Void then
|
||||
-- l_format := a_node.format
|
||||
-- end
|
||||
-- a_node.set_content (l_content, l_summary, l_format)
|
||||
-- end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -120,121 +120,33 @@ feature -- Access: router
|
||||
node_api := l_node_api
|
||||
end
|
||||
create Result.make (2)
|
||||
configure_cms (a_api, l_node_api, Result)
|
||||
-- configure_api (a_api, l_node_api, Result)
|
||||
configure_web (a_api, l_node_api, Result)
|
||||
end
|
||||
|
||||
configure_cms (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||
configure_web (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||
local
|
||||
l_node_handler: NODE_HANDLER
|
||||
l_edit_node_handler: NODE_HANDLER
|
||||
l_new_node_handler: NODE_HANDLER
|
||||
l_nodes_handler: NODES_HANDLER
|
||||
l_methods: WSF_REQUEST_METHODS
|
||||
l_uri_mapping: WSF_URI_MAPPING
|
||||
do
|
||||
-- TODO: for now, focused only on web interface, add REST api later. [2015-April-29]
|
||||
create l_node_handler.make (a_api, a_node_api)
|
||||
a_router.handle_with_request_methods ("/node", l_node_handler, a_router.methods_get_post)
|
||||
a_router.handle_with_request_methods ("/node/", l_node_handler, a_router.methods_get_post)
|
||||
|
||||
create l_new_node_handler.make (a_api, a_node_api)
|
||||
a_router.handle_with_request_methods ("/node/add/{type}", l_new_node_handler, a_router.methods_get_post)
|
||||
a_router.handle_with_request_methods ("/node/new", l_new_node_handler, 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_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)
|
||||
|
||||
create l_node_handler.make (a_api, a_node_api)
|
||||
a_router.handle_with_request_methods ("/node/{id}", l_node_handler, a_router.methods_get_put_delete + a_router.methods_get_post)
|
||||
create l_uri_mapping.make_trailing_slash_ignored ("/node", l_node_handler)
|
||||
a_router.map_with_request_methods (l_uri_mapping, a_router.methods_get_post)
|
||||
|
||||
a_router.handle_with_request_methods ("/node/add/{type}", l_node_handler, a_router.methods_get_post)
|
||||
a_router.handle_with_request_methods ("/node/{id}/edit", l_node_handler, a_router.methods_get_post)
|
||||
|
||||
a_router.handle_with_request_methods ("/node/{id}", l_node_handler, a_router.methods_get)
|
||||
-- For now: no REST API handling... a_router.methods_get_put_delete + a_router.methods_get_post)
|
||||
|
||||
-- Nodes
|
||||
create l_nodes_handler.make (a_api, a_node_api)
|
||||
create l_methods
|
||||
l_methods.enable_get
|
||||
a_router.handle_with_request_methods ("/nodes", l_nodes_handler, l_methods)
|
||||
create l_uri_mapping.make_trailing_slash_ignored ("/nodes", l_nodes_handler)
|
||||
a_router.map_with_request_methods (l_uri_mapping, a_router.methods_get)
|
||||
end
|
||||
|
||||
-- configure_api (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||
-- do
|
||||
-- configure_api_node (a_api, a_node_api, a_router)
|
||||
-- configure_api_nodes (a_api, a_node_api, a_router)
|
||||
-- configure_api_node_title (a_api, a_node_api, a_router)
|
||||
-- configure_api_node_summary (a_api, a_node_api, a_router)
|
||||
-- configure_api_node_content (a_api, a_node_api, a_router)
|
||||
-- end
|
||||
|
||||
feature {NONE} -- Implementation: routes
|
||||
|
||||
-- configure_api_node (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||
-- local
|
||||
-- l_node_handler: NODE_RESOURCE_HANDLER
|
||||
-- l_methods: WSF_REQUEST_METHODS
|
||||
-- do
|
||||
-- create l_node_handler.make (a_api, a_node_api)
|
||||
-- create l_methods
|
||||
-- l_methods.enable_get
|
||||
-- l_methods.enable_post
|
||||
-- l_methods.lock
|
||||
-- a_router.handle_with_request_methods ("/api/node", l_node_handler, l_methods)
|
||||
|
||||
-- create l_node_handler.make (a_api, a_node_api)
|
||||
-- a_router.handle_with_request_methods ("/api/node/{id}", l_node_handler, a_router.methods_get_put_delete + a_router.methods_get_post)
|
||||
-- end
|
||||
|
||||
-- configure_api_nodes (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||
-- local
|
||||
-- l_nodes_handler: NODE_RESOURCES_HANDLER
|
||||
-- l_methods: WSF_REQUEST_METHODS
|
||||
-- do
|
||||
-- create l_nodes_handler.make (a_api, a_node_api)
|
||||
-- create l_methods
|
||||
-- l_methods.enable_get
|
||||
-- a_router.handle_with_request_methods ("/api/nodes", l_nodes_handler, l_methods)
|
||||
-- end
|
||||
|
||||
-- configure_api_node_summary (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||
-- local
|
||||
-- l_report_handler: NODE_SUMMARY_HANDLER
|
||||
-- l_methods: WSF_REQUEST_METHODS
|
||||
-- do
|
||||
-- create l_report_handler.make (a_api, a_node_api)
|
||||
-- create l_methods
|
||||
-- l_methods.enable_get
|
||||
-- l_methods.enable_post
|
||||
-- l_methods.enable_put
|
||||
-- a_router.handle_with_request_methods ("/node/{id}/field/summary", l_report_handler, l_methods)
|
||||
-- end
|
||||
|
||||
-- configure_api_node_title (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||
-- local
|
||||
-- l_report_handler: NODE_TITLE_HANDLER
|
||||
-- l_methods: WSF_REQUEST_METHODS
|
||||
-- do
|
||||
-- create l_report_handler.make (a_api, a_node_api)
|
||||
-- create l_methods
|
||||
-- l_methods.enable_get
|
||||
-- l_methods.enable_post
|
||||
-- l_methods.enable_put
|
||||
-- a_router.handle_with_request_methods ("/node/{id}/field/title", l_report_handler, l_methods)
|
||||
-- end
|
||||
|
||||
-- configure_api_node_content (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER)
|
||||
-- local
|
||||
-- l_report_handler: NODE_CONTENT_HANDLER
|
||||
-- l_methods: WSF_REQUEST_METHODS
|
||||
-- do
|
||||
-- create l_report_handler.make (a_api, a_node_api)
|
||||
-- create l_methods
|
||||
-- l_methods.enable_get
|
||||
-- l_methods.enable_post
|
||||
-- l_methods.enable_put
|
||||
-- a_router.handle_with_request_methods ("/node/{id}/field/content", l_report_handler, l_methods)
|
||||
-- end
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
register_hooks (a_response: CMS_RESPONSE)
|
||||
@@ -265,53 +177,9 @@ feature -- Hooks
|
||||
do
|
||||
create lnk.make ("List of nodes", a_response.url ("/nodes", Void))
|
||||
a_menu_system.primary_menu.extend (lnk)
|
||||
|
||||
create lnk.make ("Create ..", a_response.url ("/node/", Void))
|
||||
a_menu_system.primary_menu.extend (lnk)
|
||||
end
|
||||
|
||||
--feature -- Handler
|
||||
|
||||
-- do_get_node_creation_selection (req: WSF_REQUEST; res: WSF_RESPONSE; a_node_api: CMS_NODE_API)
|
||||
-- local
|
||||
-- l_page: GENERIC_VIEW_CMS_RESPONSE
|
||||
-- s: STRING
|
||||
-- do
|
||||
-- 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
|
||||
|
||||
-- do_get_node_creation_by_type (req: WSF_REQUEST; res: WSF_RESPONSE; a_type_varname: READABLE_STRING_8; a_node_api: CMS_NODE_API)
|
||||
-- local
|
||||
-- l_page: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE
|
||||
-- l_node: detachable CMS_NODE
|
||||
-- do
|
||||
-- create l_page.make (req, res, a_node_api.cms_api)
|
||||
-- if
|
||||
-- attached {WSF_STRING} req.path_parameter (a_type_varname) as p_type and then
|
||||
-- attached a_node_api.content_type (p_type.value) as ct
|
||||
-- then
|
||||
-- l_node := ct.new_node (Void)
|
||||
-- l_page.set_main_content (l_node.out)
|
||||
-- end
|
||||
-- l_page.execute
|
||||
-- end
|
||||
|
||||
end
|
||||
|
||||
@@ -69,4 +69,16 @@ feature -- Response helpers
|
||||
r.execute
|
||||
end
|
||||
|
||||
send_not_implemented (a_message: detachable READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Send via `res' a not implemented response.
|
||||
local
|
||||
r: CMS_RESPONSE
|
||||
do
|
||||
create {NOT_IMPLEMENTED_ERROR_CMS_RESPONSE} r.make (req, res, api)
|
||||
if a_message /= Void then
|
||||
r.set_main_content (a_message)
|
||||
end
|
||||
r.execute
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user