Implemented view node by content type (no more hardcoded cases).
Added CMS_NODE_TYPE as descendant of CMS_CONTENT_TYPE, in case we have content which is not a node in the future. (probably useless, but for now, this extra abstraction is harmful) Moved all node related code under node module cluster. Applied comments from Javier Velilla. Code cleaning.
This commit is contained in:
@@ -29,21 +29,11 @@ feature -- Access
|
||||
Result := link (u.name, "/user/" + u.id.out, Void)
|
||||
end
|
||||
|
||||
node_link (n: CMS_NODE): like link
|
||||
do
|
||||
Result := link (n.title, "/node/" + n.id.out, Void)
|
||||
end
|
||||
|
||||
user_url (u: CMS_USER): like url
|
||||
do
|
||||
Result := url ("/user/" + u.id.out, Void)
|
||||
end
|
||||
|
||||
node_url (n: CMS_NODE): like url
|
||||
do
|
||||
Result := url ("/node/" + n.id.out, Void)
|
||||
end
|
||||
|
||||
feature -- Helper
|
||||
|
||||
is_empty (s: detachable READABLE_STRING_GENERAL): BOOLEAN
|
||||
|
||||
@@ -9,6 +9,9 @@ note
|
||||
deferred class
|
||||
CMS_CONTENT_TYPE
|
||||
|
||||
inherit
|
||||
CMS_API_ACCESS
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: READABLE_STRING_8
|
||||
@@ -33,18 +36,6 @@ feature -- Access
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Factory
|
||||
|
||||
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 based on partial `a_partial_node' if set.
|
||||
deferred
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
@@ -30,19 +30,19 @@ feature {NONE} -- Implementation
|
||||
else
|
||||
create {CMS_NODE_STORAGE_NULL} node_storage.make
|
||||
end
|
||||
initialize_content_types
|
||||
initialize_node_types
|
||||
end
|
||||
|
||||
initialize_content_types
|
||||
initialize_node_types
|
||||
-- Initialize content type system.
|
||||
local
|
||||
ct: CMS_PAGE_CONTENT_TYPE
|
||||
ct: CMS_PAGE_NODE_TYPE
|
||||
do
|
||||
create content_types.make (1)
|
||||
create content_type_webform_managers.make (1)
|
||||
create ct
|
||||
add_content_type (ct)
|
||||
add_content_type_webform_manager (create {CMS_PAGE_CONTENT_TYPE_WEBFORM_MANAGER}.make (ct))
|
||||
add_content_type_webform_manager (create {CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
|
||||
end
|
||||
|
||||
feature {CMS_MODULE} -- Access nodes storage.
|
||||
@@ -54,12 +54,27 @@ feature -- Content type
|
||||
content_types: ARRAYED_LIST [CMS_CONTENT_TYPE]
|
||||
-- Available content types
|
||||
|
||||
node_types: ARRAYED_LIST [CMS_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
|
||||
Result.extend (l_node_type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
add_content_type (a_type: CMS_CONTENT_TYPE)
|
||||
-- Register content type `a_type'.
|
||||
do
|
||||
content_types.force (a_type)
|
||||
end
|
||||
|
||||
content_type (a_name: READABLE_STRING_GENERAL): detachable CMS_CONTENT_TYPE
|
||||
-- Content type named `a_named' if any.
|
||||
do
|
||||
across
|
||||
content_types as ic
|
||||
@@ -73,33 +88,84 @@ feature -- Content type
|
||||
end
|
||||
end
|
||||
|
||||
node_type (a_name: READABLE_STRING_GENERAL): detachable CMS_NODE_TYPE
|
||||
-- Content type named `a_named' if any.
|
||||
do
|
||||
across
|
||||
content_types as ic
|
||||
until
|
||||
Result /= Void
|
||||
loop
|
||||
if
|
||||
attached {like node_type} ic.item as l_node_type and then
|
||||
a_name.is_case_insensitive_equal (l_node_type.name)
|
||||
then
|
||||
Result := l_node_type
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
node_type_for (a_node: CMS_NODE): detachable CMS_NODE_TYPE
|
||||
-- Content type for node `a_node' if any.
|
||||
local
|
||||
l_type_name: READABLE_STRING_8
|
||||
do
|
||||
l_type_name := a_node.content_type
|
||||
Result := node_type (l_type_name)
|
||||
end
|
||||
|
||||
feature -- Content type webform
|
||||
|
||||
content_type_webform_managers: ARRAYED_LIST [CMS_CONTENT_TYPE_WEBFORM_MANAGER]
|
||||
-- Available content types
|
||||
|
||||
add_content_type_webform_manager (a_type: CMS_CONTENT_TYPE_WEBFORM_MANAGER)
|
||||
add_content_type_webform_manager (a_manager: CMS_CONTENT_TYPE_WEBFORM_MANAGER)
|
||||
-- Register webform manager `a_manager'.
|
||||
do
|
||||
content_type_webform_managers.force (a_type)
|
||||
content_type_webform_managers.force (a_manager)
|
||||
end
|
||||
|
||||
content_type_webform_manager (a_name: READABLE_STRING_GENERAL): detachable CMS_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
content_type_webform_manager (a_content_type: CMS_CONTENT_TYPE): detachable CMS_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
-- Web form manager for content type `a_content_type' if any.
|
||||
local
|
||||
l_type_name: READABLE_STRING_GENERAL
|
||||
do
|
||||
l_type_name := a_content_type.name
|
||||
across
|
||||
content_type_webform_managers as ic
|
||||
until
|
||||
Result /= Void
|
||||
loop
|
||||
Result := ic.item
|
||||
if not a_name.is_case_insensitive_equal (Result.name) then
|
||||
if not l_type_name.is_case_insensitive_equal (Result.name) then
|
||||
Result := Void
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
node_type_webform_manager (a_node_type: CMS_NODE_TYPE): detachable CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
-- Web form manager for node type `a_node_type' if any.
|
||||
local
|
||||
l_type_name: READABLE_STRING_GENERAL
|
||||
do
|
||||
l_type_name := a_node_type.name
|
||||
across
|
||||
content_type_webform_managers as ic
|
||||
until
|
||||
Result /= Void
|
||||
loop
|
||||
if
|
||||
attached {CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER} ic.item as l_manager and then
|
||||
l_type_name.is_case_insensitive_equal (l_manager.name)
|
||||
then
|
||||
Result := l_manager
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- URL
|
||||
|
||||
new_content_path (ct: detachable CMS_CONTENT_TYPE): STRING
|
||||
new_content_path (ct: detachable CMS_NODE_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
|
||||
@@ -158,7 +224,7 @@ feature -- Access: Node
|
||||
-- otherwise return directly `a_node'.
|
||||
do
|
||||
if attached {CMS_PARTIAL_NODE} a_node as l_partial_node then
|
||||
if attached content_type (l_partial_node.content_type) as ct then
|
||||
if attached node_type_for (l_partial_node) as ct then
|
||||
Result := ct.new_node (l_partial_node)
|
||||
node_storage.fill_node (Result)
|
||||
else
|
||||
|
||||
30
src/modules/node/cms_node_type.e
Normal file
30
src/modules/node/cms_node_type.e
Normal file
@@ -0,0 +1,30 @@
|
||||
note
|
||||
description: "[
|
||||
Interface defining a CMS content type.
|
||||
]"
|
||||
status: "draft"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
CMS_NODE_TYPE
|
||||
|
||||
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 `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 based on partial `a_partial_node' if set.
|
||||
deferred
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
217
src/modules/node/content/cms_node.e
Normal file
217
src/modules/node/content/cms_node.e
Normal file
@@ -0,0 +1,217 @@
|
||||
note
|
||||
description: "[
|
||||
CMS abstraction for CMS content entity, named "node".
|
||||
]"
|
||||
status: "draft"
|
||||
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
|
||||
revision: "$Revision: 96542 $"
|
||||
|
||||
deferred class
|
||||
CMS_NODE
|
||||
|
||||
inherit
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
--create
|
||||
-- make,
|
||||
-- make_empty
|
||||
|
||||
feature{NONE} -- Initialization
|
||||
|
||||
make_empty
|
||||
-- Create empty node.
|
||||
do
|
||||
make ({STRING_32} "")
|
||||
end
|
||||
|
||||
make (a_title: READABLE_STRING_32)
|
||||
-- Create current node with `a_title'.
|
||||
local
|
||||
l_time: DATE_TIME
|
||||
do
|
||||
create l_time.make_now_utc
|
||||
set_title (a_title)
|
||||
set_creation_date (l_time)
|
||||
set_modification_date (l_time)
|
||||
set_publication_date (l_time)
|
||||
|
||||
debug ("refactor_fixme")
|
||||
fixme ("Remove default harcoded format")
|
||||
end
|
||||
ensure
|
||||
title_set: title = a_title
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
import_node (a_node: CMS_NODE)
|
||||
-- Import `a_node' into current node.
|
||||
do
|
||||
set_id (a_node.id)
|
||||
set_revision (a_node.revision)
|
||||
set_title (a_node.title)
|
||||
set_creation_date (a_node.creation_date)
|
||||
set_modification_date (a_node.modification_date)
|
||||
set_publication_date (a_node.publication_date)
|
||||
set_author (a_node.author)
|
||||
set_content (
|
||||
a_node.content,
|
||||
a_node.summary,
|
||||
a_node.format
|
||||
)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
id: INTEGER_64 assign set_id
|
||||
-- Unique id.
|
||||
--| Should we use NATURAL_64 instead?
|
||||
|
||||
revision: INTEGER_64 assign set_revision
|
||||
-- Revision value.
|
||||
--| Note: for now version is not supported.
|
||||
|
||||
content_type: READABLE_STRING_8
|
||||
-- Associated content type name.
|
||||
-- Page, Article, Blog, News, etc.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
title: READABLE_STRING_32
|
||||
-- Full title of the node.
|
||||
-- Required!
|
||||
|
||||
summary: detachable READABLE_STRING_8
|
||||
-- A short summary of the node.
|
||||
deferred
|
||||
end
|
||||
|
||||
content: detachable READABLE_STRING_8
|
||||
-- Content of the node.
|
||||
deferred
|
||||
end
|
||||
|
||||
format: detachable READABLE_STRING_8
|
||||
-- Format associated with `content' and `summary'.
|
||||
-- For example: text, mediawiki, html, etc
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Access: date
|
||||
|
||||
modification_date: DATE_TIME
|
||||
-- When the node was updated.
|
||||
|
||||
creation_date: DATE_TIME
|
||||
-- When the node was created.
|
||||
|
||||
publication_date: DATE_TIME
|
||||
-- When the node was published.
|
||||
|
||||
publication_date_output: READABLE_STRING_32
|
||||
-- Formatted output.
|
||||
|
||||
feature -- Access: author
|
||||
|
||||
author: detachable CMS_USER
|
||||
-- Author of current node.
|
||||
|
||||
feature -- status report
|
||||
|
||||
has_id: BOOLEAN
|
||||
-- Has unique identifier?
|
||||
do
|
||||
Result := id > 0
|
||||
end
|
||||
|
||||
same_node (a_node: CMS_NODE): BOOLEAN
|
||||
-- Is `a_node' same node as Current?
|
||||
do
|
||||
-- FIXME: if we introduce notion of revision, update this part!
|
||||
Result := Current = a_node or id = a_node.id
|
||||
ensure
|
||||
valid_result: Result implies a_node.id = id
|
||||
end
|
||||
|
||||
is_typed_as (a_content_type: READABLE_STRING_GENERAL): BOOLEAN
|
||||
-- Is current node of type `a_content_type' ?
|
||||
do
|
||||
Result := a_content_type.is_case_insensitive_equal (content_type)
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_content (a_content: like content; a_summary: like summary; a_format: like format)
|
||||
-- Set `content', `summary' and `format' to `a_content', `a_summary' and `a_format'.
|
||||
-- The `format' is associated with both `content' and `summary'
|
||||
deferred
|
||||
ensure
|
||||
content_assigned: content = a_content
|
||||
summary_assigned: summary = a_summary
|
||||
format_assigned: format = a_format
|
||||
end
|
||||
|
||||
set_title (a_title: like title)
|
||||
-- Assign `title' with `a_title'.
|
||||
do
|
||||
title := a_title
|
||||
ensure
|
||||
title_assigned: title = a_title
|
||||
end
|
||||
|
||||
set_modification_date (a_modification_date: like modification_date)
|
||||
-- Assign `modification_date' with `a_modification_date'.
|
||||
do
|
||||
modification_date := a_modification_date
|
||||
ensure
|
||||
modification_date_assigned: modification_date = a_modification_date
|
||||
end
|
||||
|
||||
set_creation_date (a_creation_date: like creation_date)
|
||||
-- Assign `creation_date' with `a_creation_date'.
|
||||
do
|
||||
creation_date := a_creation_date
|
||||
ensure
|
||||
creation_date_assigned: creation_date = a_creation_date
|
||||
end
|
||||
|
||||
set_publication_date (a_publication_date: like publication_date)
|
||||
-- Assign `publication_date' with `a_publication_date'.
|
||||
do
|
||||
publication_date := a_publication_date
|
||||
publication_date_output := publication_date.formatted_out ("yyyy/[0]mm/[0]dd")
|
||||
ensure
|
||||
publication_date_assigned: publication_date = a_publication_date
|
||||
end
|
||||
|
||||
set_id (a_id: like id)
|
||||
-- Assign `id' with `a_id'.
|
||||
do
|
||||
id := a_id
|
||||
ensure
|
||||
id_assigned: id = a_id
|
||||
end
|
||||
|
||||
set_revision (a_revision: like revision)
|
||||
-- Assign `revision' with `a_revision'.
|
||||
do
|
||||
revision := a_revision
|
||||
ensure
|
||||
revision_assigned: revision = a_revision
|
||||
end
|
||||
|
||||
set_author (u: like author)
|
||||
-- Assign 'author' with `u'
|
||||
do
|
||||
author := u
|
||||
ensure
|
||||
auther_set: author = u
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
85
src/modules/node/content/cms_partial_node.e
Normal file
85
src/modules/node/content/cms_partial_node.e
Normal file
@@ -0,0 +1,85 @@
|
||||
note
|
||||
description: "Node object representing the CMS_NODE data in database."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_PARTIAL_NODE
|
||||
|
||||
inherit
|
||||
CMS_NODE
|
||||
rename
|
||||
make_empty as make_empty_node,
|
||||
set_content as set_all_content
|
||||
end
|
||||
|
||||
create
|
||||
make_empty
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_empty (a_content_type: READABLE_STRING_8)
|
||||
require
|
||||
type_not_blank: not a_content_type.is_whitespace
|
||||
do
|
||||
content_type := a_content_type
|
||||
make_empty_node
|
||||
end
|
||||
|
||||
feature -- Access: code
|
||||
|
||||
content_type: READABLE_STRING_8
|
||||
-- <Precursor>
|
||||
|
||||
feature -- Access: content
|
||||
|
||||
summary: detachable READABLE_STRING_8
|
||||
-- A short summary of the node.
|
||||
|
||||
content: detachable READABLE_STRING_8
|
||||
-- Content of the node.
|
||||
|
||||
format: detachable READABLE_STRING_8
|
||||
-- Format associated with `content' and `summary'.
|
||||
-- For example: text, mediawiki, html, etc
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_all_content (a_content: like content; a_summary: like summary; a_format: like format)
|
||||
-- <Precursor>
|
||||
do
|
||||
set_content (a_content)
|
||||
set_summary (a_summary)
|
||||
set_format (a_format)
|
||||
end
|
||||
|
||||
set_content (a_content: like content)
|
||||
-- Assign `content' with `a_content', and set the associated `format'.
|
||||
do
|
||||
content := a_content
|
||||
ensure
|
||||
content_assigned: content = a_content
|
||||
end
|
||||
|
||||
set_summary (a_summary: like summary)
|
||||
-- Assign `summary' with `a_summary'.
|
||||
do
|
||||
summary := a_summary
|
||||
ensure
|
||||
summary_assigned: summary = a_summary
|
||||
end
|
||||
|
||||
set_format (a_format: like format)
|
||||
-- Assign `format' with `a_format'.
|
||||
do
|
||||
format := a_format
|
||||
ensure
|
||||
format_assigned: format = a_format
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
@@ -24,7 +24,7 @@ feature {NONE} -- Initialization
|
||||
Precursor
|
||||
end
|
||||
|
||||
feature {CMS_CONTENT_TYPE} -- Conversion
|
||||
feature -- Conversion
|
||||
|
||||
import_node (a_node: CMS_NODE)
|
||||
-- <Precursor>
|
||||
@@ -39,7 +39,7 @@ feature -- Access
|
||||
|
||||
content_type: READABLE_STRING_8
|
||||
once
|
||||
Result := {CMS_PAGE_CONTENT_TYPE}.name
|
||||
Result := {CMS_PAGE_NODE_TYPE}.name
|
||||
end
|
||||
|
||||
feature -- Access: content
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
note
|
||||
description: "Summary description for {CMS_PAGE_CONTENT_TYPE}."
|
||||
description: "Summary description for {CMS_PAGE_NODE_TYPE}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_PAGE_CONTENT_TYPE
|
||||
CMS_PAGE_NODE_TYPE
|
||||
|
||||
inherit
|
||||
CMS_CONTENT_TYPE
|
||||
CMS_NODE_TYPE
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
@@ -1,12 +1,17 @@
|
||||
note
|
||||
description: "Summary description for {CMS_CONTENT_TYPE_WEBFORM_MANAGER}."
|
||||
author: ""
|
||||
description: "[
|
||||
Html builder for content type `content_type'.
|
||||
This is used to build webform and html output for a specific node, or node content type.
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
CMS_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
|
||||
inherit
|
||||
CMS_API_ACCESS
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_type: like content_type)
|
||||
@@ -20,25 +25,9 @@ feature -- Access
|
||||
-- Associated content type.
|
||||
|
||||
name: READABLE_STRING_8
|
||||
-- Associated content type name.
|
||||
do
|
||||
Result := content_type.name
|
||||
end
|
||||
|
||||
feature -- Forms ...
|
||||
|
||||
fill_edit_form (response: NODE_RESPONSE; a_form: WSF_FORM; a_node: detachable CMS_NODE)
|
||||
deferred
|
||||
end
|
||||
|
||||
new_node (response: NODE_RESPONSE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): CMS_NODE
|
||||
deferred
|
||||
-- Result := content_type.new_node (a_node)
|
||||
end
|
||||
|
||||
change_node (response: NODE_RESPONSE; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
-- require
|
||||
-- a_node.has_id
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
note
|
||||
description: "Summary description for {CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER}."
|
||||
description: "[
|
||||
Html builder for content type `content_type'.
|
||||
This is used to build webform and html output for a specific node, or node content type.
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER [G -> CMS_NODE]
|
||||
deferred class
|
||||
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
|
||||
inherit
|
||||
CMS_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
@@ -12,148 +15,53 @@ inherit
|
||||
content_type
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Access
|
||||
|
||||
content_type: CMS_CONTENT_TYPE
|
||||
-- Associated content type.
|
||||
content_type: CMS_NODE_TYPE
|
||||
-- Associated content type.
|
||||
|
||||
feature -- Query
|
||||
|
||||
has_valid_node_type (a_node: CMS_NODE): BOOLEAN
|
||||
-- Accept `a_node' for Current operations.
|
||||
do
|
||||
Result := attached {like new_node} a_node
|
||||
end
|
||||
|
||||
feature -- Forms ...
|
||||
|
||||
fill_edit_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable like new_node)
|
||||
local
|
||||
ti: WSF_FORM_TEXT_INPUT
|
||||
fset: WSF_FORM_FIELD_SET
|
||||
ta: WSF_FORM_TEXTAREA
|
||||
tselect: WSF_FORM_SELECT
|
||||
opt: WSF_FORM_SELECT_OPTION
|
||||
do
|
||||
create ti.make ("title")
|
||||
ti.set_label ("Title")
|
||||
ti.set_size (70)
|
||||
if a_node /= Void then
|
||||
ti.set_text_value (a_node.title)
|
||||
end
|
||||
ti.set_is_required (True)
|
||||
f.extend (ti)
|
||||
|
||||
f.extend_html_text ("<br/>")
|
||||
|
||||
create ta.make ("body")
|
||||
ta.set_rows (10)
|
||||
ta.set_cols (70)
|
||||
if a_node /= Void then
|
||||
ta.set_text_value (a_node.content)
|
||||
end
|
||||
-- ta.set_label ("Body")
|
||||
ta.set_description ("This is the main content")
|
||||
ta.set_is_required (False)
|
||||
|
||||
create fset.make
|
||||
fset.set_legend ("Body")
|
||||
fset.extend (ta)
|
||||
|
||||
fset.extend_html_text ("<br/>")
|
||||
|
||||
create tselect.make ("format")
|
||||
tselect.set_label ("Body's format")
|
||||
tselect.set_is_required (True)
|
||||
across
|
||||
content_type.available_formats as c
|
||||
loop
|
||||
create opt.make (c.item.name, c.item.title)
|
||||
if attached c.item.html_help as f_help then
|
||||
opt.set_description ("<ul>" + f_help + "</ul>")
|
||||
end
|
||||
tselect.add_option (opt)
|
||||
end
|
||||
if a_node /= Void and then attached a_node.format as l_format then
|
||||
tselect.set_text_by_value (l_format)
|
||||
end
|
||||
|
||||
fset.extend (tselect)
|
||||
|
||||
f.extend (fset)
|
||||
|
||||
populate_form (response: NODE_RESPONSE; a_form: WSF_FORM; a_node: detachable CMS_NODE)
|
||||
-- Fill the web form `a_form' with data from `a_node' if set.
|
||||
require
|
||||
a_node = Void or else has_valid_node_type (a_node)
|
||||
deferred
|
||||
end
|
||||
|
||||
change_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: like new_node)
|
||||
local
|
||||
b: detachable READABLE_STRING_8
|
||||
f: detachable CONTENT_FORMAT
|
||||
do
|
||||
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
|
||||
check a_node.id = l_id end
|
||||
end
|
||||
if attached fd.string_item ("title") as l_title then
|
||||
a_node.set_title (l_title)
|
||||
end
|
||||
feature -- Node ...
|
||||
|
||||
if attached fd.string_item ("body") as l_body then
|
||||
b := l_body
|
||||
end
|
||||
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then
|
||||
f := f_format
|
||||
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
|
||||
f := f_format
|
||||
else
|
||||
f := response.api.formats.default_format
|
||||
end
|
||||
if b /= Void then
|
||||
a_node.set_content (b, Void, f.name) -- FIXME: summary
|
||||
end
|
||||
new_node (response: NODE_RESPONSE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): like content_type.new_node
|
||||
-- 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)
|
||||
deferred
|
||||
--| Possible implementation:
|
||||
--| Result := content_type.new_node (a_node)
|
||||
end
|
||||
|
||||
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable like new_node): like content_type.new_node
|
||||
-- <Precursor>
|
||||
local
|
||||
b: detachable READABLE_STRING_8
|
||||
f: detachable CONTENT_FORMAT
|
||||
l_node: detachable like new_node
|
||||
do
|
||||
l_node := a_node
|
||||
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
|
||||
if l_node /= Void then
|
||||
check l_node.id = l_id end
|
||||
else
|
||||
if attached {like new_node} response.node_api.node (l_id) as n then
|
||||
l_node := n
|
||||
else
|
||||
-- FIXME: Error
|
||||
end
|
||||
end
|
||||
end
|
||||
if attached fd.string_item ("title") as l_title then
|
||||
if l_node = Void then
|
||||
l_node := content_type.new_node (Void)
|
||||
l_node.set_title (l_title)
|
||||
else
|
||||
l_node.set_title (l_title)
|
||||
end
|
||||
else
|
||||
if l_node = Void then
|
||||
l_node := content_type.new_node_with_title ("...", Void)
|
||||
end
|
||||
end
|
||||
l_node.set_author (response.user)
|
||||
update_node (response: NODE_RESPONSE; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
-- Update node `a_node' with data from `a_form_data'.
|
||||
require
|
||||
has_valid_node_type (a_node)
|
||||
deferred
|
||||
end
|
||||
|
||||
if attached fd.string_item ("body") as l_body then
|
||||
b := l_body
|
||||
end
|
||||
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then
|
||||
f := f_format
|
||||
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
|
||||
f := f_format
|
||||
else
|
||||
f := response.api.formats.default_format
|
||||
end
|
||||
if b /= Void then
|
||||
l_node.set_content (b, Void, f.name)
|
||||
end
|
||||
Result := l_node
|
||||
feature -- Output
|
||||
|
||||
append_html_output_to (a_node: CMS_NODE; a_response: NODE_RESPONSE)
|
||||
-- Append an html representation of `a_node' to response `a_response'.
|
||||
require
|
||||
has_valid_node_type (a_node)
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
203
src/modules/node/handler/cms_node_type_webform_manager.e
Normal file
203
src/modules/node/handler/cms_node_type_webform_manager.e
Normal file
@@ -0,0 +1,203 @@
|
||||
note
|
||||
description: "Summary description for {CMS_NODE_TYPE_WEBFORM_MANAGER}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_NODE_TYPE_WEBFORM_MANAGER [G -> CMS_NODE]
|
||||
|
||||
inherit
|
||||
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Forms ...
|
||||
|
||||
populate_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE)
|
||||
local
|
||||
ti: WSF_FORM_TEXT_INPUT
|
||||
fset: WSF_FORM_FIELD_SET
|
||||
ta: WSF_FORM_TEXTAREA
|
||||
tselect: WSF_FORM_SELECT
|
||||
opt: WSF_FORM_SELECT_OPTION
|
||||
do
|
||||
create ti.make ("title")
|
||||
ti.set_label ("Title")
|
||||
ti.set_size (70)
|
||||
if a_node /= Void then
|
||||
ti.set_text_value (a_node.title)
|
||||
end
|
||||
ti.set_is_required (True)
|
||||
f.extend (ti)
|
||||
|
||||
f.extend_html_text ("<br/>")
|
||||
|
||||
create ta.make ("body")
|
||||
ta.set_rows (10)
|
||||
ta.set_cols (70)
|
||||
if a_node /= Void then
|
||||
ta.set_text_value (a_node.content)
|
||||
end
|
||||
-- ta.set_label ("Body")
|
||||
ta.set_description ("This is the main content")
|
||||
ta.set_is_required (False)
|
||||
|
||||
create fset.make
|
||||
fset.set_legend ("Body")
|
||||
fset.extend (ta)
|
||||
|
||||
fset.extend_html_text ("<br/>")
|
||||
|
||||
create tselect.make ("format")
|
||||
tselect.set_label ("Body's format")
|
||||
tselect.set_is_required (True)
|
||||
across
|
||||
content_type.available_formats as c
|
||||
loop
|
||||
create opt.make (c.item.name, c.item.title)
|
||||
if attached c.item.html_help as f_help then
|
||||
opt.set_description ("<ul>" + f_help + "</ul>")
|
||||
end
|
||||
tselect.add_option (opt)
|
||||
end
|
||||
if a_node /= Void and then attached a_node.format as l_format then
|
||||
tselect.set_text_by_value (l_format)
|
||||
end
|
||||
|
||||
fset.extend (tselect)
|
||||
|
||||
f.extend (fset)
|
||||
|
||||
end
|
||||
|
||||
update_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
local
|
||||
b: detachable READABLE_STRING_8
|
||||
f: detachable CONTENT_FORMAT
|
||||
do
|
||||
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
|
||||
check a_node.id = l_id end
|
||||
end
|
||||
if attached fd.string_item ("title") as l_title then
|
||||
a_node.set_title (l_title)
|
||||
end
|
||||
|
||||
if attached fd.string_item ("body") as l_body then
|
||||
b := l_body
|
||||
end
|
||||
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then
|
||||
f := f_format
|
||||
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
|
||||
f := f_format
|
||||
else
|
||||
f := response.api.formats.default_format
|
||||
end
|
||||
if b /= Void then
|
||||
a_node.set_content (b, Void, f.name) -- FIXME: summary
|
||||
end
|
||||
end
|
||||
|
||||
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable CMS_NODE): like content_type.new_node
|
||||
-- <Precursor>
|
||||
local
|
||||
b: detachable READABLE_STRING_8
|
||||
f: detachable CONTENT_FORMAT
|
||||
l_node: detachable like new_node
|
||||
do
|
||||
if attached {like new_node} a_node as l_arg_node then
|
||||
l_node := l_arg_node
|
||||
else
|
||||
l_node := content_type.new_node (a_node)
|
||||
end
|
||||
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
|
||||
if l_node /= Void then
|
||||
check l_node.id = l_id end
|
||||
else
|
||||
if attached {like new_node} response.node_api.node (l_id) as n then
|
||||
l_node := n
|
||||
else
|
||||
-- FIXME: Error
|
||||
end
|
||||
end
|
||||
end
|
||||
if attached fd.string_item ("title") as l_title then
|
||||
if l_node = Void then
|
||||
l_node := content_type.new_node (Void)
|
||||
l_node.set_title (l_title)
|
||||
else
|
||||
l_node.set_title (l_title)
|
||||
end
|
||||
else
|
||||
if l_node = Void then
|
||||
l_node := content_type.new_node_with_title ("...", Void)
|
||||
end
|
||||
end
|
||||
l_node.set_author (response.user)
|
||||
|
||||
if attached fd.string_item ("body") as l_body then
|
||||
b := l_body
|
||||
end
|
||||
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then
|
||||
f := f_format
|
||||
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
|
||||
f := f_format
|
||||
else
|
||||
f := response.api.formats.default_format
|
||||
end
|
||||
if b /= Void then
|
||||
l_node.set_content (b, Void, f.name)
|
||||
end
|
||||
Result := l_node
|
||||
end
|
||||
|
||||
feature -- Output
|
||||
|
||||
append_html_output_to (a_node: CMS_NODE; a_response: NODE_RESPONSE)
|
||||
-- <Precursor>
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
hdate: HTTP_DATE
|
||||
s: STRING
|
||||
node_api: CMS_NODE_API
|
||||
do
|
||||
node_api := a_response.node_api
|
||||
|
||||
a_response.add_variable (a_node, "node")
|
||||
create lnk.make ("View", node_api.node_path (a_node))
|
||||
lnk.set_weight (1)
|
||||
a_response.add_to_primary_tabs (lnk)
|
||||
create lnk.make ("Edit", node_api.node_path (a_node) + "/edit")
|
||||
lnk.set_weight (2)
|
||||
a_response.add_to_primary_tabs (lnk)
|
||||
|
||||
create s.make_empty
|
||||
s.append ("<div class=%"info%"> ")
|
||||
if attached a_node.author as l_author then
|
||||
s.append (" by ")
|
||||
s.append (l_author.name)
|
||||
end
|
||||
if attached a_node.modification_date as l_modified then
|
||||
s.append (" (modified: ")
|
||||
create hdate.make_from_date_time (l_modified)
|
||||
s.append (hdate.yyyy_mmm_dd_string)
|
||||
s.append (")")
|
||||
end
|
||||
s.append ("</div>")
|
||||
if attached a_node.content as l_content then
|
||||
s.append ("<p class=%"content%">")
|
||||
if attached node_api.cms_api.format (a_node.format) as f then
|
||||
s.append (f.formatted_output (l_content))
|
||||
else
|
||||
s.append (node_api.cms_api.formats.default_format.formatted_output (l_content))
|
||||
end
|
||||
|
||||
s.append ("</p>")
|
||||
end
|
||||
|
||||
a_response.set_title (a_node.title)
|
||||
a_response.set_main_content (s)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
note
|
||||
description: "Summary description for {CMS_PAGE_CONTENT_TYPE_WEBFORM_MANAGER}."
|
||||
description: "Summary description for {CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_PAGE_CONTENT_TYPE_WEBFORM_MANAGER
|
||||
CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER
|
||||
|
||||
inherit
|
||||
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER [CMS_PAGE]
|
||||
CMS_NODE_TYPE_WEBFORM_MANAGER [CMS_PAGE]
|
||||
redefine
|
||||
content_type
|
||||
content_type,
|
||||
append_html_output_to
|
||||
end
|
||||
|
||||
create
|
||||
@@ -18,7 +19,7 @@ create
|
||||
|
||||
feature -- Access
|
||||
|
||||
content_type: CMS_PAGE_CONTENT_TYPE
|
||||
content_type: CMS_PAGE_NODE_TYPE
|
||||
-- Associated content type.
|
||||
|
||||
feature -- Forms ...
|
||||
@@ -156,5 +157,29 @@ feature -- Forms ...
|
||||
-- Result := l_node
|
||||
-- end
|
||||
|
||||
feature -- Output
|
||||
|
||||
append_html_output_to (a_node: CMS_NODE; a_response: NODE_RESPONSE)
|
||||
-- <Precursor>
|
||||
local
|
||||
s: STRING
|
||||
do
|
||||
Precursor (a_node, a_response)
|
||||
if attached a_response.main_content as l_main_content then
|
||||
s := l_main_content
|
||||
else
|
||||
create s.make_empty
|
||||
end
|
||||
|
||||
if attached {CMS_PAGE} a_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_response.link (l_parent_node.title + " (#" + l_parent_node.id.out + ")", a_response.node_api.node_path (l_parent_node), Void))
|
||||
s.append ("</div>")
|
||||
end
|
||||
end
|
||||
|
||||
a_response.set_main_content (s)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,7 +1,5 @@
|
||||
note
|
||||
description: "Summary description for {NODE_FORM_RESPONSE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
description: "CMS Response handling node editing workflow using Web forms."
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
@@ -42,6 +40,7 @@ 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)
|
||||
@@ -49,7 +48,7 @@ feature -- Execution
|
||||
nid > 0 and then
|
||||
attached node_api.node (nid) as l_node
|
||||
then
|
||||
if attached node_api.content_type (l_node.content_type) as l_type then
|
||||
if attached node_api.node_type_for (l_node) as l_type then
|
||||
if has_permission ("edit " + l_type.name) then
|
||||
f := edit_form (l_node, url (request.path_info, Void), "edit-" + l_type.name, l_type)
|
||||
if request.is_post_request_method then
|
||||
@@ -65,9 +64,9 @@ feature -- Execution
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
|
||||
|
||||
b.append ("saved")
|
||||
b.append (html_encoded (l_type.title) + " saved")
|
||||
else
|
||||
set_title ("Edit #" + l_node.id.out)
|
||||
set_title ("Edit " + html_encoded (l_type.title) + " #" + l_node.id.out)
|
||||
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
|
||||
@@ -82,7 +81,7 @@ feature -- Execution
|
||||
end
|
||||
elseif
|
||||
attached {WSF_STRING} request.path_parameter ("type") as p_type and then
|
||||
attached node_api.content_type (p_type.value) as l_type
|
||||
attached node_api.node_type (p_type.value) as l_type
|
||||
then
|
||||
if has_permission ("create " + l_type.name) then
|
||||
if attached l_type.new_node (Void) as l_node then
|
||||
@@ -94,7 +93,7 @@ feature -- Execution
|
||||
fd := f.last_data
|
||||
end
|
||||
|
||||
set_title ("Edit #" + l_node.id.out)
|
||||
set_title ("Edit " + html_encoded (l_type.title) + " #" + l_node.id.out)
|
||||
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
|
||||
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
|
||||
@@ -106,16 +105,19 @@ feature -- Execution
|
||||
else
|
||||
b.append ("<h1>Access denied</h1>")
|
||||
end
|
||||
|
||||
else
|
||||
set_title ("Create new content ...")
|
||||
b.append ("<ul id=%"content-types%">")
|
||||
across
|
||||
node_api.content_types as c
|
||||
node_api.node_types as ic
|
||||
loop
|
||||
if has_permission ("create " + c.item.name) then
|
||||
b.append ("<li>" + link (c.item.name, "/node/add/" + c.item.name, Void))
|
||||
if attached c.item.description as d then
|
||||
l_node_type := ic.item
|
||||
if
|
||||
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
|
||||
b.append ("<div class=%"description%">" + d + "</div>")
|
||||
end
|
||||
b.append ("</li>")
|
||||
@@ -155,7 +157,7 @@ feature -- Form
|
||||
end
|
||||
end
|
||||
|
||||
edit_form_submit (fd: WSF_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_CONTENT_TYPE; b: STRING)
|
||||
edit_form_submit (fd: WSF_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_NODE_TYPE; b: STRING)
|
||||
local
|
||||
l_preview: BOOLEAN
|
||||
l_node: detachable CMS_NODE
|
||||
@@ -200,7 +202,7 @@ feature -- Form
|
||||
end
|
||||
end
|
||||
|
||||
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_CONTENT_TYPE): CMS_FORM
|
||||
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_NODE_TYPE): CMS_FORM
|
||||
local
|
||||
f: CMS_FORM
|
||||
ts: WSF_FORM_SUBMIT_INPUT
|
||||
@@ -231,26 +233,28 @@ feature -- Form
|
||||
Result := f
|
||||
end
|
||||
|
||||
new_node (a_content_type: CMS_CONTENT_TYPE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): CMS_NODE
|
||||
new_node (a_content_type: CMS_NODE_TYPE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): CMS_NODE
|
||||
--
|
||||
do
|
||||
if attached node_api.content_type_webform_manager (a_content_type.name) as wf then
|
||||
if attached node_api.node_type_webform_manager (a_content_type) as wf then
|
||||
Result := wf.new_node (Current, a_form_data, a_node)
|
||||
else
|
||||
Result := a_content_type.new_node (a_node)
|
||||
end
|
||||
end
|
||||
|
||||
change_node (a_content_type: CMS_CONTENT_TYPE; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
change_node (a_content_type: CMS_NODE_TYPE; 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.content_type_webform_manager (a_content_type.name) as wf then
|
||||
wf.change_node (Current, a_form_data, a_node)
|
||||
if attached node_api.node_type_webform_manager (a_content_type) as wf then
|
||||
wf.update_node (Current, a_form_data, a_node)
|
||||
end
|
||||
end
|
||||
|
||||
fill_edit_form (a_content_type: CMS_CONTENT_TYPE; a_form: WSF_FORM; a_node: detachable CMS_NODE)
|
||||
fill_edit_form (a_content_type: CMS_NODE_TYPE; a_form: WSF_FORM; a_node: detachable CMS_NODE)
|
||||
do
|
||||
if attached node_api.content_type_webform_manager (a_content_type.name) as wf then
|
||||
wf.fill_edit_form (Current, a_form, a_node)
|
||||
if attached node_api.node_type_webform_manager (a_content_type) as wf then
|
||||
wf.populate_form (Current, a_form, a_node)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
note
|
||||
description: "handler for CMS node in the CMS interface."
|
||||
description: "[
|
||||
handler for CMS node in the CMS interface.
|
||||
|
||||
TODO: implement REST API.
|
||||
]"
|
||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
@@ -61,13 +65,10 @@ feature -- HTTP Methods
|
||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- <Precursor>
|
||||
local
|
||||
l_page: CMS_RESPONSE
|
||||
s: STRING
|
||||
hdate: HTTP_DATE
|
||||
lnk: CMS_LOCAL_LINK
|
||||
l_node: detachable CMS_NODE
|
||||
l_nid: INTEGER_64
|
||||
edit_response: NODE_FORM_RESPONSE
|
||||
view_response: NODE_VIEW_RESPONSE
|
||||
do
|
||||
if req.path_info.ends_with_general ("/edit") then
|
||||
create edit_response.make (req, res, api, node_api)
|
||||
@@ -83,49 +84,9 @@ feature -- HTTP Methods
|
||||
l_node := node_api.node (l_nid)
|
||||
end
|
||||
if l_node /= Void then
|
||||
-- FIXME: allow a per content type display here!
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (l_node, "node")
|
||||
create lnk.make ("View", node_api.node_path (l_node))
|
||||
lnk.set_weight (1)
|
||||
l_page.add_to_primary_tabs (lnk)
|
||||
create lnk.make ("Edit", node_api.node_path (l_node) + "/edit")
|
||||
lnk.set_weight (2)
|
||||
l_page.add_to_primary_tabs (lnk)
|
||||
|
||||
create s.make_empty
|
||||
s.append ("<div class=%"info%"> ")
|
||||
if attached l_node.author as l_author then
|
||||
s.append (" by ")
|
||||
s.append (l_author.name)
|
||||
end
|
||||
if attached l_node.modification_date as l_modified then
|
||||
s.append (" (modified: ")
|
||||
create hdate.make_from_date_time (l_modified)
|
||||
s.append (hdate.yyyy_mmm_dd_string)
|
||||
s.append (")")
|
||||
end
|
||||
s.append ("</div>")
|
||||
if attached l_node.content as l_content then
|
||||
s.append ("<p class=%"content%">")
|
||||
if attached api.format (l_node.format) as f then
|
||||
s.append (f.formatted_output (l_content))
|
||||
else
|
||||
s.append (api.formats.default_format.formatted_output (l_content))
|
||||
end
|
||||
|
||||
s.append ("</p>")
|
||||
end
|
||||
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 (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
|
||||
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)
|
||||
else
|
||||
@@ -149,55 +110,57 @@ feature -- HTTP Methods
|
||||
create edit_response.make (req, res, api, node_api)
|
||||
edit_response.execute
|
||||
else
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- <Precursor>
|
||||
do
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
@@ -228,48 +191,49 @@ feature -- HTTP Methods
|
||||
|
||||
process_node_creation (req: WSF_REQUEST; res: WSF_RESPONSE; a_user: CMS_USER)
|
||||
local
|
||||
u_node: CMS_NODE
|
||||
-- u_node: CMS_NODE
|
||||
do
|
||||
-- New node
|
||||
-- FIXME !!!
|
||||
if
|
||||
attached {WSF_STRING} req.form_parameter ("type") as p_type and then
|
||||
attached node_api.content_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
|
||||
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
|
||||
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
|
||||
-- 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
|
||||
|
||||
@@ -296,81 +260,47 @@ feature {NONE} -- Node
|
||||
|
||||
create_new_node (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
l_page: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE
|
||||
l_node: detachable CMS_NODE
|
||||
l_gen_page: GENERIC_VIEW_CMS_RESPONSE
|
||||
edit_response: NODE_FORM_RESPONSE
|
||||
s: STRING
|
||||
do
|
||||
if
|
||||
attached {WSF_STRING} req.path_parameter ("type") as p_type and then
|
||||
attached node_api.content_type (p_type.value) as ct
|
||||
then
|
||||
if req.path_info.starts_with_general ("/node/add/") then
|
||||
create edit_response.make (req, res, api, node_api)
|
||||
edit_response.execute
|
||||
-- create l_page.make (req, res, api)
|
||||
-- l_node := ct.new_node (Void)
|
||||
-- l_page.set_main_content (l_node.out)
|
||||
-- l_page.execute
|
||||
elseif req.is_get_request_method then
|
||||
redirect_to (req.absolute_script_url ("/node/add/"), res)
|
||||
else
|
||||
create l_gen_page.make (req, res, api)
|
||||
|
||||
create s.make_empty
|
||||
s.append ("<ul>")
|
||||
across
|
||||
node_api.content_types as ic
|
||||
loop
|
||||
if api.user_has_permission (current_user (req), "create " + ic.item.name) then
|
||||
s.append ("<li>")
|
||||
s.append (l_gen_page.link (ic.item.title, 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_gen_page.html_encoded (l_description))
|
||||
s.append ("</p>")
|
||||
end
|
||||
s.append ("</li>")
|
||||
end
|
||||
end
|
||||
s.append ("</ul>")
|
||||
l_gen_page.set_title ("Create new content ...")
|
||||
l_gen_page.set_main_content (s)
|
||||
l_gen_page.execute
|
||||
send_bad_request (req, res)
|
||||
end
|
||||
-- if api.user_has_permission (current_user (req), "create node") then
|
||||
-- create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
-- l_page.execute
|
||||
-- else
|
||||
-- send_access_denied (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
|
||||
-- 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
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
note
|
||||
description: "Summary description for {NODE_RESPONSE}."
|
||||
author: ""
|
||||
description: "Generic CMS Response for a CMS NODE."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
@@ -26,6 +25,7 @@ feature {NONE} -- Initialization
|
||||
feature -- Access
|
||||
|
||||
node_api: CMS_NODE_API
|
||||
-- Associated node API.
|
||||
|
||||
feature -- Generation
|
||||
|
||||
|
||||
75
src/modules/node/handler/node_view_response.e
Normal file
75
src/modules/node/handler/node_view_response.e
Normal file
@@ -0,0 +1,75 @@
|
||||
note
|
||||
description: "Summary description for {NODE_VIEW_RESPONSE}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
NODE_VIEW_RESPONSE
|
||||
|
||||
inherit
|
||||
NODE_RESPONSE
|
||||
redefine
|
||||
make,
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (req: WSF_REQUEST; res: WSF_RESPONSE; a_api: like api; a_node_api: like node_api)
|
||||
do
|
||||
create {WSF_NULL_THEME} wsf_theme.make
|
||||
Precursor (req, res, a_api, a_node_api)
|
||||
end
|
||||
|
||||
initialize
|
||||
do
|
||||
Precursor
|
||||
create {WSF_CMS_THEME} wsf_theme.make (Current, theme)
|
||||
end
|
||||
|
||||
wsf_theme: WSF_THEME
|
||||
|
||||
feature -- Access
|
||||
|
||||
node: detachable CMS_NODE
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_node (a_node: like node)
|
||||
do
|
||||
node := a_node
|
||||
end
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process
|
||||
-- Computed response message.
|
||||
local
|
||||
b: STRING_8
|
||||
nid: INTEGER_64
|
||||
l_node: like node
|
||||
do
|
||||
l_node := node
|
||||
if l_node = Void then
|
||||
create b.make_empty
|
||||
nid := node_id_path_parameter (request)
|
||||
if nid > 0 then
|
||||
l_node := node_api.node (nid)
|
||||
end
|
||||
end
|
||||
if l_node /= Void then
|
||||
if
|
||||
attached node_api.node_type_for (l_node) as l_content_type and then
|
||||
attached node_api.node_type_webform_manager (l_content_type) as l_manager
|
||||
then
|
||||
l_manager.append_html_output_to (l_node, Current)
|
||||
end
|
||||
else
|
||||
set_main_content ("Missing node")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -47,7 +47,7 @@ feature {CMS_API} -- Module Initialization
|
||||
-- <Precursor>
|
||||
local
|
||||
p1,p2: CMS_PAGE
|
||||
ct: CMS_PAGE_CONTENT_TYPE
|
||||
ct: CMS_PAGE_NODE_TYPE
|
||||
l_node_api: like node_api
|
||||
do
|
||||
Precursor (api)
|
||||
|
||||
@@ -6,9 +6,6 @@ note
|
||||
deferred class
|
||||
CMS_NODE_STORAGE_I
|
||||
|
||||
inherit
|
||||
SHARED_LOGGER
|
||||
|
||||
feature -- Error Handling
|
||||
|
||||
error_handler: ERROR_HANDLER
|
||||
@@ -17,8 +17,6 @@ inherit
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
SHARED_LOGGER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
@@ -16,8 +16,6 @@ inherit
|
||||
node_storage
|
||||
end
|
||||
|
||||
SHARED_LOGGER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
@@ -30,7 +28,7 @@ feature -- Access
|
||||
|
||||
content_type: STRING
|
||||
once
|
||||
Result := {CMS_PAGE_CONTENT_TYPE}.name
|
||||
Result := {CMS_PAGE_NODE_TYPE}.name
|
||||
end
|
||||
|
||||
feature -- Persistence
|
||||
@@ -73,7 +71,7 @@ feature -- Persistence
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
n: INTEGER
|
||||
ct: CMS_PAGE_CONTENT_TYPE
|
||||
ct: CMS_PAGE_NODE_TYPE
|
||||
do
|
||||
error_handler.reset
|
||||
write_information_log (generator + ".fill_page")
|
||||
@@ -68,20 +68,6 @@ feature -- Access: user
|
||||
do
|
||||
end
|
||||
|
||||
feature -- User Nodes
|
||||
|
||||
user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST [CMS_NODE]
|
||||
-- Possible list of nodes where the user identified by `a_id', is a collaborator.
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
end
|
||||
|
||||
user_author_nodes (a_id: like {CMS_USER}.id): LIST [CMS_NODE]
|
||||
-- Possible list of nodes where the user identified by `a_id', is the author.
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||
end
|
||||
|
||||
feature -- Change: user
|
||||
|
||||
new_user (a_user: CMS_USER)
|
||||
|
||||
@@ -6,6 +6,9 @@ note
|
||||
deferred class
|
||||
CMS_STORAGE_SQL_I
|
||||
|
||||
inherit
|
||||
SHARED_LOGGER
|
||||
|
||||
feature -- Access
|
||||
|
||||
api: detachable CMS_API
|
||||
|
||||
9
src/service/cms_api_access.e
Normal file
9
src/service/cms_api_access.e
Normal file
@@ -0,0 +1,9 @@
|
||||
note
|
||||
description: "Interface having access to restricted features relate to CMS APIs."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
CMS_API_ACCESS
|
||||
|
||||
end
|
||||
@@ -20,7 +20,7 @@ feature {NONE} -- Implementation
|
||||
do
|
||||
end
|
||||
|
||||
feature {CMS_MODULE, CMS_API} -- Restricted access
|
||||
feature {CMS_API_ACCESS, CMS_MODULE, CMS_API} -- Restricted access
|
||||
|
||||
cms_api: CMS_API
|
||||
|
||||
|
||||
Reference in New Issue
Block a user