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:
2015-04-29 17:28:33 +02:00
parent e8bb3790ba
commit c982f0ea9c
34 changed files with 756 additions and 521 deletions

View File

@@ -1,122 +0,0 @@
note
description: "Describe module features that adds one or more features to your web site."
date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
deferred class
CMS_MODULE
inherit
REFACTORING_HELPER
feature -- Access
is_enabled: BOOLEAN
-- Is the module enabled?
name: STRING
-- Name of the module.
description: STRING
-- Description of the module.
package: STRING
--
version: STRING
-- Version od the module?
feature {CMS_API} -- Module Initialization
initialize (api: CMS_API)
-- Initialize Current module with `api'.
require
is_enabled: is_enabled
do
-- Redefine to process specific module initialization.
end
feature {CMS_API} -- Access: API
module_api: detachable CMS_MODULE_API
-- Eventual module api.
feature {CMS_API} -- Module management
is_installed (api: CMS_API): BOOLEAN
-- Is Current module installed?
do
Result := is_enabled
-- FIXME: implement proper installation status.
end
install (api: CMS_API)
require
is_not_installed: not is_installed (api)
do
-- Not Yet Supported
end
uninstall (api: CMS_API)
require
is_installed: is_installed (api)
do
-- Not Yet Supported
end
feature -- Router
router (a_api: CMS_API): WSF_ROUTER
-- Router configuration.
require
is_enabled: is_enabled
deferred
end
feature -- Hooks configuration
register_hooks (a_response: CMS_RESPONSE)
-- Module hooks configuration.
require
is_enabled: is_enabled
do
end
feature -- Filter
filters (a_api: CMS_API): detachable LIST [WSF_FILTER]
-- Optional list of filter for Current module.
require
is_enabled: is_enabled
do
end
feature -- Settings
enable
-- enable the module.
do
is_enabled := True
ensure
module_enabled: is_enabled
end
disable
-- disable the module.
do
is_enabled := False
ensure
module_disbaled: not is_enabled
end
feature -- Hooks
help_text (a_path: STRING): STRING
do
debug ("refactor_fixme")
to_implement ("Add the corresponing implementation.")
end
create Result.make_empty
end
end

View File

@@ -1,81 +0,0 @@
note
description: "Summary description for {CMS_MODULE_COLLECTION}."
author: ""
date: "$Date: 2015-02-09 22:29:56 +0100 (lun., 09 févr. 2015) $"
revision: "$Revision: 96596 $"
class
CMS_MODULE_COLLECTION
inherit
ITERABLE [CMS_MODULE]
create
make
feature {NONE} -- Initialization
make (nb: INTEGER)
do
create modules.make (nb)
end
feature -- Access
new_cursor: INDEXABLE_ITERATION_CURSOR [CMS_MODULE]
-- <Precursor>
do
Result := modules.new_cursor
end
feature -- Status report
has (a_module: CMS_MODULE): BOOLEAN
-- Has `a_module'?
do
Result := modules.has (a_module)
end
has_module_with_same_type (a_module: CMS_MODULE): BOOLEAN
-- Has module of type `a_type' already inserted?
local
l_type: TYPE [detachable CMS_MODULE]
do
l_type := a_module.generating_type
across
modules as ic
until
Result
loop
Result := ic.item = a_module or else ic.item.generating_type = l_type
end
end
count: INTEGER
-- Number of modules.
do
Result := modules.count
end
feature -- Element change
extend (a_module: CMS_MODULE)
-- Add module
do
if not has (a_module) then
modules.force (a_module)
end
end
remove (a_module: CMS_MODULE)
-- Remove module
do
modules.prune_all (a_module)
end
feature {NONE} -- Implementation
modules: ARRAYED_LIST [CMS_MODULE]
-- List of available modules.
end

View File

@@ -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)"

View File

@@ -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

View 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

View 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

View 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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View 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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View 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

View File

@@ -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)

View File

@@ -0,0 +1,53 @@
note
description: "Node storage extension for specific node descendant."
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_NODE_STORAGE_EXTENSION [G -> CMS_NODE]
feature -- Access
content_type: READABLE_STRING_8
deferred
end
feature -- Status report
is_accepted (a_node: CMS_NODE): BOOLEAN
-- Is `a_node' accepted by current storage extension?
do
Result := attached {G} a_node
end
feature -- Persistence
store_node (a_node: CMS_NODE)
require
a_node_accepted: is_accepted (a_node)
do
if attached {G} a_node as obj then
store (obj)
end
end
load_node (a_node: CMS_NODE)
require
a_node_accepted: is_accepted (a_node)
do
if attached {G} a_node as obj then
load (obj)
end
end
feature {NONE} -- Persistence implementation
store (a_node: G)
deferred
end
load (a_node: G)
deferred
end
end

View File

@@ -0,0 +1,173 @@
note
description: "Summary description for {CMS_NODE_STORAGE_I}."
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
deferred class
CMS_NODE_STORAGE_I
feature -- Error Handling
error_handler: ERROR_HANDLER
-- Error handler.
deferred
end
feature -- Storage extension
register_node_storage_extension (a_extension: CMS_NODE_STORAGE_EXTENSION [CMS_NODE])
-- Register `a_extension' as extension to the node storage system.
local
tb: like node_storage_extensions
do
tb := node_storage_extensions
if tb = Void then
create tb.make_caseless (1)
node_storage_extensions := tb
end
tb.force (a_extension, a_extension.content_type)
end
node_storage_extension (a_node: CMS_NODE): detachable CMS_NODE_STORAGE_EXTENSION [CMS_NODE]
-- Extension to the node storage system for node `a_node'.
do
if attached node_storage_extensions as tb then
Result := tb.item (a_node.content_type)
end
end
feature {NONE} -- Implementation
node_storage_extensions: detachable STRING_TABLE [CMS_NODE_STORAGE_EXTENSION [CMS_NODE]]
-- Table of node storage extensions.
extended_store (a_node: CMS_NODE)
-- Store extended data from `a_node'.
do
if attached node_storage_extension (a_node) as ext then
ext.store_node (a_node)
end
end
extended_load (a_node: CMS_NODE)
-- Load extended data into `a_node'.
do
if attached node_storage_extension (a_node) as ext then
ext.load_node (a_node)
end
end
feature -- Access
nodes_count: INTEGER_64
-- Count of nodes.
deferred
end
nodes: LIST [CMS_NODE]
-- List of nodes.
deferred
end
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
-- List of recent `a_count' nodes with an offset of `lower'.
deferred
end
node_by_id (a_id: INTEGER_64): detachable CMS_NODE
-- Retrieve node by id `a_id', if any.
require
a_id > 0
deferred
end
node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER
-- Node's author. if any.
require
valid_node: a_id > 0
deferred
end
feature -- Change: Node
save_node (a_node: CMS_NODE)
-- Create or update `a_node'.
do
if a_node.has_id then
update_node (a_node)
else
new_node (a_node)
end
end
new_node (a_node: CMS_NODE)
-- Save node `a_node'.
require
no_id: not a_node.has_id
valid_user: attached a_node.author as l_author and then l_author.id > 0
deferred
end
update_node (a_node: CMS_NODE)
-- Update node content `a_node'.
-- The user `a_id' is an existing or new collaborator.
require
has_id: a_node.has_id
has_author: attached a_node.author as l_author and then l_author.has_id
deferred
end
delete_node (a_node: CMS_NODE)
-- Delete `a_node'.
do
if a_node.has_id then
delete_node_by_id (a_node.id)
end
end
delete_node_by_id (a_id: INTEGER_64)
-- Remove node by id `a_id'.
require
valid_node_id: a_id > 0
deferred
end
-- update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- -- Update node title to `a_title', node identified by id `a_node_id'.
-- -- The user `a_user_id' is an existing or new collaborator.
-- require
-- valid_node_id: a_node_id > 0
-- valid_user_id: a_user_id > 0
-- deferred
-- end
-- update_node_summary (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- -- Update node summary to `a_summary', node identified by id `a_node_id'.
-- -- The user `a_user_id' is an existing or new collaborator.
-- require
-- valid_id: a_node_id > 0
-- valid_user_id: a_user_id > 0
-- deferred
-- end
-- update_node_content (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- -- Update node content to `a_content', node identified by id `a_node_id'.
-- -- The user `a_user_id' is an existing or new collaborator.
-- require
-- valid_id: a_node_id > 0
-- valid_user_id: a_user_id > 0
-- deferred
-- end
feature -- Helpers
fill_node (a_node: CMS_NODE)
-- Fill `a_node' with extra information from database.
-- i.e: specific to each content type data.
require
has_id: a_node.has_id
deferred
end
end

View File

@@ -0,0 +1,106 @@
note
description: "[
Objects that ...
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
class
CMS_NODE_STORAGE_NULL
inherit
CMS_NODE_STORAGE_I
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
create error_handler.make
end
feature -- Error Handling
error_handler: ERROR_HANDLER
-- Error handler.
feature -- Access: node
nodes_count: INTEGER_64
-- Count of nodes.
do
end
nodes: LIST[CMS_NODE]
-- List of nodes.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
-- List of the `a_count' most recent nodes, starting from `a_lower'.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end
node_by_id (a_id: INTEGER_64): detachable CMS_NODE
-- <Precursor>
do
end
node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER
-- Node's author. if any.
do
end
node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER]
-- Possible list of node's collaborator.
do
create {ARRAYED_LIST [CMS_USER]} Result.make (0)
end
feature -- Node
new_node (a_node: CMS_NODE)
-- Add a new node
do
end
delete_node_by_id (a_id: INTEGER_64)
-- <Precursor>
do
end
update_node (a_node: CMS_NODE)
-- <Precursor>
do
end
-- update_node_title (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- -- <Precursor>
-- do
-- end
-- update_node_summary (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- -- <Precursor>
-- do
-- end
-- update_node_content (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- -- <Precursor>
-- do
-- end
feature -- Helpers
fill_node (a_node: CMS_NODE)
-- Fill `a_node' with extra information from database.
-- i.e: specific to each content type data.
do
end
end

View File

@@ -0,0 +1,360 @@
note
description: "[
CMS NODE Storage based on SQL statements.
]"
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $"
class
CMS_NODE_STORAGE_SQL
inherit
CMS_PROXY_STORAGE_SQL
CMS_NODE_STORAGE_I
CMS_STORAGE_SQL_I
REFACTORING_HELPER
create
make
feature -- Access
nodes_count: INTEGER_64
-- Number of items nodes.
do
error_handler.reset
write_information_log (generator + ".nodes_count")
sql_query (sql_select_nodes_count, Void)
if sql_rows_count = 1 then
Result := sql_read_integer_64 (1)
end
end
nodes: LIST [CMS_NODE]
-- List of nodes.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
error_handler.reset
write_information_log (generator + ".nodes")
from
sql_query (sql_select_nodes, Void)
sql_start
until
sql_after
loop
if attached fetch_node as l_node then
Result.force (l_node)
end
sql_forth
end
-- across
-- Result as ic
-- loop
-- fill_node (ic.item)
-- end
end
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
-- List of recent `a_count' nodes with an offset of `lower'.
local
l_parameters: STRING_TABLE [detachable ANY]
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
error_handler.reset
write_information_log (generator + ".nodes")
from
create l_parameters.make (2)
l_parameters.put (a_count, "rows")
l_parameters.put (a_lower, "offset")
sql_query (sql_select_recent_nodes, l_parameters)
sql_start
until
sql_after
loop
if attached fetch_node as l_node then
Result.force (l_node)
end
sql_forth
end
end
node_by_id (a_id: INTEGER_64): detachable CMS_NODE
-- Retrieve node by id `a_id', if any.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
write_information_log (generator + ".node")
create l_parameters.make (1)
l_parameters.put (a_id, "nid")
sql_query (sql_select_node_by_id, l_parameters)
if sql_rows_count = 1 then
Result := fetch_node
end
end
node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER
-- Node's author for the given node id.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
write_information_log (generator + ".node_author")
create l_parameters.make (1)
l_parameters.put (a_id, "node_id")
sql_query (select_node_author, l_parameters)
if sql_rows_count >= 1 then
Result := fetch_author
end
end
last_inserted_node_id: INTEGER_64
-- Last insert node id.
do
error_handler.reset
write_information_log (generator + ".last_inserted_node_id")
sql_query (Sql_last_insert_node_id, Void)
if sql_rows_count = 1 then
Result := sql_read_integer_64 (1)
end
end
feature -- Change: Node
new_node (a_node: CMS_NODE)
-- Save node `a_node'.
do
store_node (a_node)
end
update_node (a_node: CMS_NODE)
-- Update node content `a_node'.
do
store_node (a_node)
end
delete_node_by_id (a_id: INTEGER_64)
-- Remove node by id `a_id'.
local
l_parameters: STRING_TABLE [ANY]
do
write_information_log (generator + ".delete_node")
error_handler.reset
create l_parameters.make (1)
l_parameters.put (a_id, "nid")
sql_change (sql_delete_node, l_parameters)
end
-- update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- -- <Precursor>
-- local
-- l_parameters: STRING_TABLE [detachable ANY]
-- do
-- -- FIXME: unused a_user_id !
-- error_handler.reset
-- write_information_log (generator + ".update_node_title")
-- create l_parameters.make (3)
-- l_parameters.put (a_title, "title")
-- l_parameters.put (create {DATE_TIME}.make_now_utc, "changed")
-- l_parameters.put (a_node_id, "nid")
-- sql_change (sql_update_node_title, l_parameters)
-- end
-- update_node_summary (a_user_id: Like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- -- <Precursor>
-- local
-- l_parameters: STRING_TABLE [detachable ANY]
-- do
-- -- FIXME: unused a_user_id !
-- error_handler.reset
-- write_information_log (generator + ".update_node_summary")
-- create l_parameters.make (3)
-- l_parameters.put (a_summary, "summary")
-- l_parameters.put (create {DATE_TIME}.make_now_utc, "changed")
-- l_parameters.put (a_node_id, "nid")
-- sql_change (sql_update_node_summary, l_parameters)
-- end
-- update_node_content (a_user_id: Like {CMS_USER}.id;a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- -- <Precursor>
-- local
-- l_parameters: STRING_TABLE [detachable ANY]
-- do
-- -- FIXME: unused a_user_id !
-- error_handler.reset
-- write_information_log (generator + ".update_node_content")
-- create l_parameters.make (3)
-- l_parameters.put (a_content, "content")
-- l_parameters.put (create {DATE_TIME}.make_now_utc, "changed")
-- l_parameters.put (a_node_id, "nid")
-- sql_change (sql_update_node_content, l_parameters)
-- end
feature {NONE} -- Implementation
store_node (a_node: CMS_NODE)
local
l_parameters: STRING_TABLE [detachable ANY]
now: DATE_TIME
do
create now.make_now_utc
error_handler.reset
write_information_log (generator + ".store_node")
create l_parameters.make (8)
l_parameters.put (a_node.content_type, "type")
l_parameters.put (a_node.title, "title")
l_parameters.put (a_node.summary, "summary")
l_parameters.put (a_node.content, "content")
l_parameters.put (a_node.format, "format")
l_parameters.put (a_node.publication_date, "publish")
l_parameters.put (now, "changed")
if attached a_node.author as l_author then
check valid_author: l_author.has_id end
l_parameters.put (l_author.id, "author")
else
l_parameters.put (0, "author")
end
sql_begin_transaction
if a_node.has_id then
-- Update
l_parameters.put (a_node.id, "nid")
sql_change (sql_update_node, l_parameters)
if not error_handler.has_error then
-- FIXED: FOR NOW no revision
-- a_node.set_revision (a_node.revision + 1) -- FIXME: Should be incremented by one, in same transaction...but check!
a_node.set_modification_date (now)
end
else
-- Store new node
l_parameters.put (a_node.creation_date, "created")
sql_change (sql_insert_node, l_parameters)
if not error_handler.has_error then
a_node.set_modification_date (now)
a_node.set_id (last_inserted_node_id)
a_node.set_revision (1) -- New object.
end
end
extended_store (a_node)
sql_commit_transaction
end
feature -- Helpers
fill_node (a_node: CMS_NODE)
-- Fill `a_node' with extra information from database.
-- i.e: specific to each content type data.
do
error_handler.reset
write_information_log (generator + ".fill_node")
extended_load (a_node)
end
feature {NONE} -- Queries
sql_select_nodes_count: STRING = "SELECT count(*) from Nodes;"
sql_select_nodes: STRING = "SELECT * from Nodes;"
-- SQL Query to retrieve all nodes.
sql_select_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed FROM Nodes WHERE nid =:nid ORDER BY revision desc, publish desc LIMIT 1;"
sql_select_recent_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed FROM Nodes ORDER BY nid desc, publish desc LIMIT :rows OFFSET :offset ;"
sql_insert_node: STRING = "INSERT INTO nodes (revision, type, title, summary, content, format, publish, created, changed, author) VALUES (1, :type, :title, :summary, :content, :format, :publish, :created, :changed, :author);"
-- SQL Insert to add a new node.
sql_update_node : STRING = "UPDATE nodes SET revision = revision, type=:type, title=:title, summary=:summary, content=:content, format=:format, publish=:publish, changed=:changed, author=:author WHERE nid=:nid;"
-- FIXME: for now no revision inc.!
-- sql_update_node : STRING = "UPDATE nodes SET revision = revision + 1, type=:type, title=:title, summary=:summary, content=:content, format=:format, publish=:publish, changed=:changed, revision = revision + 1, author=:author WHERE nid=:nid;"
-- SQL node.
sql_delete_node: STRING = "DELETE FROM nodes WHERE nid=:nid;"
-- sql_update_node_author: STRING = "UPDATE nodes SET author=:author WHERE nid=:nid;"
-- sql_update_node_title: STRING ="UPDATE nodes SET title=:title, changed=:changed, revision = revision + 1 WHERE nid=:nid;"
-- -- SQL update node title.
-- sql_update_node_summary: STRING ="UPDATE nodes SET summary=:summary, changed=:changed, revision = revision + 1 WHERE nid=:nid;"
-- -- SQL update node summary.
-- sql_update_node_content: STRING ="UPDATE nodes SET content=:content, changed=:changed, revision = revision + 1 WHERE nid=:nid;"
-- -- SQL node content.
sql_last_insert_node_id: STRING = "SELECT MAX(nid) FROM nodes;"
feature {NONE} -- Sql Queries: USER_ROLES collaborators, author
Select_user_author: STRING = "SELECT uid, name, password, salt, email, status, created, signed FROM Nodes INNER JOIN users ON nodes.author=users.uid AND users.uid = :uid;"
Select_node_author: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed FROM users INNER JOIN nodes ON nodes.author=users.uid AND nodes.nid =:nid;"
feature {NONE} -- Implementation
fetch_node: detachable CMS_PARTIAL_NODE
do
if attached sql_read_string (3) as l_type then
create Result.make_empty (l_type)
if attached sql_read_integer_64 (1) as l_id then
Result.set_id (l_id)
end
if attached sql_read_integer_64 (2) as l_revision then
Result.set_revision (l_revision)
end
if attached sql_read_string_32 (4) as l_title then
Result.set_title (l_title)
end
if attached sql_read_string_32 (5) as l_summary then
Result.set_summary (l_summary)
end
if attached sql_read_string (6) as l_content then
Result.set_content (l_content)
end
if attached sql_read_string (7) as l_format then
Result.set_format (l_format)
end
if attached sql_read_integer_64 (8) as l_author_id then
Result.set_author (create {CMS_PARTIAL_USER}.make_with_id (l_author_id))
end
if attached sql_read_date_time (9) as l_publication_date then
Result.set_publication_date (l_publication_date)
end
if attached sql_read_date_time (10) as l_creation_date then
Result.set_creation_date (l_creation_date)
end
if attached sql_read_date_time (11) as l_modif_date then
Result.set_modification_date (l_modif_date)
end
end
end
fetch_author: detachable CMS_USER
do
if attached sql_read_string_32 (2) as l_name and then not l_name.is_whitespace then
create Result.make (l_name)
if attached sql_read_integer_32 (1) as l_id then
Result.set_id (l_id)
end
if attached sql_read_string (3) as l_password then
-- FIXME: should we return the password here ???
Result.set_hashed_password (l_password)
end
if attached sql_read_string (5) as l_email then
Result.set_email (l_email)
end
else
check expected_valid_user: False end
end
end
end

View File

@@ -0,0 +1,110 @@
note
description: "Storage extension for Page nodes."
date: "$Date$"
revision: "$Revision$"
class
CMS_NODE_STORAGE_SQL_PAGE_EXTENSION
inherit
CMS_NODE_STORAGE_EXTENSION [CMS_PAGE]
CMS_PROXY_STORAGE_SQL
rename
sql_storage as node_storage
redefine
node_storage
end
create
make
feature {NONE} -- Initialization
node_storage: CMS_NODE_STORAGE_SQL
-- <Precursor>
feature -- Access
content_type: STRING
once
Result := {CMS_PAGE_NODE_TYPE}.name
end
feature -- Persistence
store (a_node: CMS_PAGE)
local
l_parameters: STRING_TABLE [ANY]
l_new_parent_id, l_previous_parent_id: INTEGER_64
l_update: BOOLEAN
do
error_handler.reset
write_information_log (generator + ".store_page_data")
create l_parameters.make (2)
l_parameters.put (a_node.id, "nid")
l_parameters.put (a_node.revision, "revision")
sql_query (sql_select_page_data, l_parameters)
if not has_error then
if sql_rows_count = 1 then
l_previous_parent_id := sql_read_integer_64 (3)
l_update := True
end
if attached a_node.parent as l_parent then
l_new_parent_id := l_parent.id
else
l_new_parent_id := 0
end
l_parameters.put (l_new_parent_id, "parent")
if l_update and l_new_parent_id /= l_previous_parent_id then
sql_change (sql_update_page_data, l_parameters)
elseif l_new_parent_id > 0 then
sql_change (sql_insert_page_data, l_parameters)
else
-- no page data, means everything is empty.
end
end
end
load (a_node: CMS_PAGE)
local
l_parameters: STRING_TABLE [ANY]
n: INTEGER
ct: CMS_PAGE_NODE_TYPE
do
error_handler.reset
write_information_log (generator + ".fill_page")
create l_parameters.make (2)
l_parameters.put (a_node.id, "nid")
l_parameters.put (a_node.revision, "revision")
sql_query (sql_select_page_data, l_parameters)
if not has_error then
n := sql_rows_count
if n = 1 then
-- nid, revision, parent
if
attached sql_read_integer_64 (3) as l_parent_id and then
l_parent_id /= a_node.id and then
attached node_storage.node_by_id (l_parent_id) as l_parent
then
-- FIXME: find a simple way to access the declared content types.
create ct
a_node.set_parent (ct.new_node (l_parent))
else
write_debug_log ("Invalid parent node id!")
end
else
check unique_data: n = 0 end
end
end
end
feature -- SQL
sql_select_page_data: STRING = "SELECT nid, revision, parent FROM page_nodes WHERE nid =:nid AND revision=:revision;"
sql_insert_page_data: STRING = "INSERT INTO page_nodes (nid, revision, parent) VALUES (:nid, :revision, :parent);"
sql_update_page_data: STRING = "UPDATE page_nodes SET nid=:nid, revision=:revision, parent=:parent WHERE nid=:nid AND revision=:revision;"
end