Added CMS_NODE.is_published and is_trashed: BOOLEAN

For now, whenever we save a node, it is marked as published.
Display a node only if published.
Updated /trash page.
Updated /nodes/ page to take into account the node status.
This commit is contained in:
2015-07-16 17:16:35 +02:00
parent 769c14caf8
commit d8ac46f8b0
9 changed files with 97 additions and 32 deletions

View File

@@ -220,11 +220,11 @@ feature -- Access: Node
Result := node_storage.nodes
end
trashed_nodes (a_user: CMS_USER): LIST [CMS_NODE]
trashed_nodes (a_user: detachable CMS_USER): LIST [CMS_NODE]
-- List of nodes with status in {CMS_NODE_API}.trashed.
-- if the current user is admin, it will retrieve all the trashed nodes
-- if `a_user' is set, return nodes related to this user.
do
Result := node_storage.trashed_nodes (a_user.id)
Result := node_storage.trashed_nodes (a_user)
end
recent_nodes (params: CMS_DATA_QUERY_PARAMETERS): ITERABLE [CMS_NODE]

View File

@@ -73,12 +73,30 @@ feature -- Access
deferred
end
feature -- Status reports
status: INTEGER
-- Associated status for the current node.
-- default: {CMS_NODE_API}.Not_Published}
-- {CMS_NODE_API}.Published
-- {CMS_NODE_API}.Trashed
is_published: BOOLEAN
-- Is Current published?
do
Result := status = {CMS_NODE_API}.published
ensure
Result implies not is_trashed
end
is_trashed: BOOLEAN
-- Is Current trashed?
do
Result := status = {CMS_NODE_API}.trashed
ensure
Result implies not is_published
end
feature -- Access
title: READABLE_STRING_32

View File

@@ -48,7 +48,7 @@ feature -- Execution
attached node_api.node (nid) as l_node
then
if attached node_api.node_type_for (l_node) as l_type then
fixme ("refactor: process_edit, process_create porcess edit")
fixme ("refactor: process_edit, process_create process edit")
if
request.path_info.ends_with_general ("/edit") and then
node_api.has_permission_for_action_on_node ("edit", l_node, current_user (request))
@@ -249,6 +249,9 @@ feature -- Form
l_node.set_author (user)
s := "created"
end
fixme ("for now, publishing is not implemented, so let's assume any node saved is published.") -- FIXME
l_node.mark_published
node_api.save_node (l_node)
if attached current_user (request) as u then
api.log ("node",

View File

@@ -102,7 +102,9 @@ feature -- HTTP Methods
l_nid := node_id_path_parameter (req)
if l_nid > 0 then
l_node := node_api.node (l_nid)
if l_node /= Void then
if
l_node /= Void and then l_node.is_published
then
create view_response.make (req, res, api, node_api)
view_response.set_node (l_node)
view_response.execute

View File

@@ -44,6 +44,7 @@ feature -- HTTP Methods
l_page_helper: CMS_PAGINATION_GENERATOR
s_pager: STRING
l_count: NATURAL_64
l_include_trashed: BOOLEAN
do
-- At the moment the template are hardcoded, but we can
-- get them from the configuration file and load them into
@@ -71,19 +72,35 @@ feature -- HTTP Methods
end
if attached node_api.recent_nodes (create {CMS_DATA_QUERY_PARAMETERS}.make (l_page_helper.current_page_offset, l_page_helper.page_size)) as lst then
if attached {WSF_STRING} req.query_parameter ("include_trash") as v and then v.is_case_insensitive_equal ("yes") then
l_include_trashed := l_response.has_permissions (<<"view trash", "view any trash">>)
end
s.append ("<ul class=%"cms-nodes%">%N")
across
lst as ic
loop
n := ic.item
lnk := node_api.node_link (n)
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
s.append (l_response.link (lnk.title, lnk.location, Void))
debug
if attached node_api.content_type (n.content_type) as ct then
s.append ("<span class=%"description%">")
s.append (html_encoded (ct.title))
s.append ("</span>")
if not n.is_trashed or else l_include_trashed then
lnk := node_api.node_link (n)
s.append ("<li class=%"cms_type_"+ n.content_type)
if not n.is_published then
s.append (" not-published")
elseif n.is_trashed then
s.append (" trashed")
end
s.append ("%">")
s.append (l_response.link (lnk.title, lnk.location, Void))
if not n.is_published then
s.append (" <em>(not-published)</em>")
elseif n.is_trashed then
s.append (" <em>(trashed)</em>")
end
debug
if attached node_api.content_type (n.content_type) as ct then
s.append ("<span class=%"description%">")
s.append (html_encoded (ct.title))
s.append ("</span>")
end
end
end
s.append ("</li>%N")
@@ -93,6 +110,20 @@ feature -- HTTP Methods
-- Again the pager at the bottom, if needed
s.append (s_pager)
if l_response.has_permissions (<<"view trash", "view any trash">>) then
if not l_include_trashed then
s.append (l_response.link ("With trashed items", l_response.location + "?include_trash=yes", Void))
s.append (" | ")
end
s.append (l_response.link ("Global-Trash", "trash", Void))
s.append (" | ")
end
if attached l_response.user as u and then l_response.has_permission ("view own trash") then
s.append (l_response.link ("Your-trash", "trash?user=" + l_response.url_encoded (u.name), Void))
s.append (" | ")
end
l_response.set_main_content (s)
l_response.execute
end

View File

@@ -42,19 +42,29 @@ feature -- HTTP Methods
s: STRING
n: CMS_NODE
lnk: CMS_LOCAL_LINK
l_username: detachable READABLE_STRING_32
l_trash_owner: detachable CMS_USER
do
-- At the moment the template is hardcoded, but we can
-- get them from the configuration file and load them into
-- the setup class.
if attached current_user (req) as l_user then
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
l_page.add_variable (node_api.trashed_nodes (l_user), "nodes")
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
if attached {WSF_STRING} req.query_parameter ("user") as p_username then
l_username := p_username.value
l_trash_owner := api.user_api.user_by_name (l_username)
end
if
(l_trash_owner /= Void and then l_page.has_permissions (<<"view any trash", "view own trash">>))
or else (l_page.has_permission ("view trash"))
then
-- NOTE: for development purposes we have the following hardcode output.
create s.make_from_string ("<p>Nodes:</p>")
if attached node_api.trashed_nodes (l_user) as lst then
if l_trash_owner /= Void then
create s.make_from_string ("<p>Trash for user " + l_page.html_encoded (l_trash_owner.name) + "</p>")
else
create s.make_from_string ("<p>Trash</p>")
end
if attached node_api.trashed_nodes (l_trash_owner) as lst then
s.append ("<ul class=%"cms-nodes%">%N")
across
lst as ic

View File

@@ -73,8 +73,10 @@ feature -- Access
deferred
end
trashed_nodes (a_user_id: INTEGER_64): LIST [CMS_NODE]
-- List of nodes by user `a_user_id'.
trashed_nodes (a_user: detachable CMS_USER): LIST [CMS_NODE]
-- List of nodes by user `a_user' if set, or any.
require
a_user /= Void implies a_user.has_id
deferred
end

View File

@@ -41,8 +41,8 @@ feature -- Access: node
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end
trashed_nodes (a_user_id: INTEGER_64): LIST [CMS_NODE]
-- List of nodes by user `a_user_id'.
trashed_nodes (a_user: detachable CMS_USER): LIST [CMS_NODE]
-- <Precursor>.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end

View File

@@ -60,7 +60,7 @@ feature -- Access
-- end
end
trashed_nodes (a_user_id: INTEGER_64): LIST [CMS_NODE]
trashed_nodes (a_user: detachable CMS_USER): LIST [CMS_NODE]
-- List of nodes.
local
l_parameters: STRING_TABLE [detachable ANY]
@@ -72,9 +72,8 @@ feature -- Access
from
create l_parameters.make (1)
if a_user_id > 1 then
-- Not admin user
l_parameters.put (a_user_id, "author")
if a_user /= Void and then a_user.has_id then
l_parameters.put (a_user.id, "author")
sql_query (sql_select_trash_nodes_by_author, l_parameters)
else
sql_query (sql_select_trash_nodes, Void)
@@ -295,15 +294,15 @@ feature {NONE} -- Queries
-- Nodes count (Published and not Published)
--| note: {CMS_NODE_API}.trashed = -1
sql_select_nodes: STRING = "SELECT * FROM nodes WHERE status != -1 ;"
sql_select_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status != -1 ;"
-- SQL Query to retrieve all nodes.
--| note: {CMS_NODE_API}.trashed = -1
sql_select_trash_nodes: STRING = "SELECT * FROM nodes WHERE status = -1 ;"
sql_select_trash_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status = -1 ;"
-- SQL Query to retrieve all trahsed nodes.
--| note: {CMS_NODE_API}.trashed = -1
sql_select_trash_nodes_by_author: STRING = "SELECT * FROM nodes WHERE status = -1 and author = :author ;"
sql_select_trash_nodes_by_author: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status = -1 and author = :author ;"
-- SQL Query to retrieve all nodes by a given author.
--| note: {CMS_NODE_API}.trashed = -1