From e547279016d320f5cae785c93fd490fd64075b3c Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 30 Mar 2017 17:16:02 +0200 Subject: [PATCH] Implemented save/publish/unpublish control on nodes. Display on published blogs (except for admin, or author of the related blog). --- modules/blog/handler/blog_handler.e | 44 +++++++---- .../handler/cms_node_type_webform_manager_i.e | 5 ++ modules/node/handler/node_form_response.e | 77 ++++++++++++++++--- src/service/cms_api.e | 3 - 4 files changed, 102 insertions(+), 27 deletions(-) diff --git a/modules/blog/handler/blog_handler.e b/modules/blog/handler/blog_handler.e index 731a58e..d483133 100644 --- a/modules/blog/handler/blog_handler.e +++ b/modules/blog/handler/blog_handler.e @@ -156,6 +156,7 @@ feature -- HTML Output local n: CMS_NODE lnk: CMS_LOCAL_LINK + l_hide: BOOLEAN do -- Output the title. If more than one page, also output the current page number append_page_title_html_to (page, a_output) @@ -169,25 +170,42 @@ feature -- HTML Output posts as ic loop n := ic.item - lnk := blog_api.node_api.node_link (n) - a_output.append ("
  • ") + l_hide := not n.is_published + if l_hide then + if + attached api.user as u + then + if api.user_api.is_admin_user (u) then + l_hide := False + else + l_hide := not u.same_as (n.author) + end + end + end + if not l_hide then + lnk := blog_api.node_api.node_link (n) + a_output.append ("
  • ") - -- Output the creation date - append_creation_date_html_to (n, a_output) + if not n.is_published then + a_output.append ("
    This entry is not yet published!
    ") + end + -- Output the creation date + append_creation_date_html_to (n, a_output) - -- Output the author of the post - append_author_html_to (n, page, a_output) + -- Output the author of the post + append_author_html_to (n, page, a_output) - -- Output the title of the post as a link (to the detail page) - append_title_html_to (n, page, a_output) + -- Output the title of the post as a link (to the detail page) + append_title_html_to (n, page, a_output) - -- Output associated tags. - append_taxonomy_html_to (n, page, a_output) + -- Output associated tags. + append_taxonomy_html_to (n, page, a_output) - -- Output the summary of the post and a more link to the detail page - append_summary_html_to (n, page, a_output) + -- Output the summary of the post and a more link to the detail page + append_summary_html_to (n, page, a_output) - a_output.append ("
  • %N") + a_output.append ("%N") + end end -- End of post list diff --git a/modules/node/handler/cms_node_type_webform_manager_i.e b/modules/node/handler/cms_node_type_webform_manager_i.e index 78337f7..9eecd96 100644 --- a/modules/node/handler/cms_node_type_webform_manager_i.e +++ b/modules/node/handler/cms_node_type_webform_manager_i.e @@ -88,6 +88,11 @@ feature -- Output a_response.set_value (a_node, "node") a_response.set_value (a_node.content_type, "optional_content_type") create s.make_empty + if a_node.is_not_published then + a_response.add_warning_message ("This node is NOT published!") + elseif a_node.is_trashed then + a_response.add_warning_message ("This node is in the TRASH!") + end append_content_as_html_to (a_node, False, s, a_response) a_response.set_main_content (s) end diff --git a/modules/node/handler/node_form_response.e b/modules/node/handler/node_form_response.e index 2389be8..c554ef8 100644 --- a/modules/node/handler/node_form_response.e +++ b/modules/node/handler/node_form_response.e @@ -254,15 +254,25 @@ feature -- Form edit_form_submit (fd: WSF_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_NODE_TYPE [CMS_NODE]; b: STRING) local - l_preview: BOOLEAN + l_preview, l_op_save, l_op_publish, l_op_unpublish: BOOLEAN l_node: detachable CMS_NODE s: STRING l_node_path: READABLE_STRING_8 l_path_alias, l_existing_path_alias, l_auto_path_alias: detachable READABLE_STRING_8 do - fixme ("Refactor code per operacion: Preview, Save") - l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview") + fixme ("Refactor code per operation: Preview, Save/Publish/UnPublish") + l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string (preview_submit_label) if not l_preview then + l_op_save := True + if attached {WSF_STRING} fd.item ("op") as l_op then + if l_op.same_string (publish_submit_label) then + l_op_publish := True + elseif l_op.same_string (unpublish_submit_label) then + l_op_unpublish := True + else + check l_op.same_string (save_submit_label) end + end + end debug ("cms") across fd as c @@ -289,8 +299,13 @@ feature -- Form end fixme ("for now, publishing is not implemented, so let's assume any node saved is published.") -- FIXME - l_node.mark_published - + if l_op_publish then + l_node.mark_published + elseif l_op_unpublish then + l_node.mark_not_published + else + -- Default status + end node_api.save_node (l_node) if attached user as u then api.log ("node", @@ -362,6 +377,7 @@ feature -- Form f: CMS_FORM ts: WSF_FORM_SUBMIT_INPUT th: WSF_FORM_HIDDEN_INPUT + div: WSF_WIDGET_DIV do create f.make (a_url, a_name) create th.make ("node-id") @@ -375,18 +391,50 @@ feature -- Form populate_form (a_node_type, f, a_node) f.extend_html_text ("
    ") - create ts.make ("op") - ts.set_default_value ("Save") - f.extend (ts) + + create div.make + div.add_css_class ("css-editing-buttons") + f.extend (div) create ts.make ("op") - ts.set_default_value ("Preview") - f.extend (ts) + ts.set_default_value (preview_submit_label) + ts.set_description ("Preview without saving.") + div.extend (ts) + if a_node = Void then + create ts.make ("op") + ts.set_default_value (save_submit_label) + div.extend (ts) + + create ts.make ("op") + ts.set_default_value (publish_submit_label) + ts.set_description ("Save and mark published.") + div.extend (ts) + else + if a_node.is_published then + create ts.make ("op") + ts.set_default_value (save_submit_label) + ts.set_description ("Save and keep published.") + div.extend (ts) + + create ts.make ("op") + ts.set_default_value (unpublish_submit_label) + ts.set_description ("Save and mark unpublished.") + div.extend (ts) + else + create ts.make ("op") + ts.set_default_value (save_submit_label) + div.extend (ts) + + create ts.make ("op") + ts.set_default_value (publish_submit_label) + ts.set_description ("Save and mark published.") + div.extend (ts) + end + end Result := f end - new_delete_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_node_type: CMS_NODE_TYPE [CMS_NODE]): CMS_FORM -- Create a web form named `a_name' for node `a_node' (if set), using form action url `a_url', and for type of node `a_node_type'. require @@ -487,4 +535,11 @@ feature -- Form end end +feature -- Labels + + save_submit_label: STRING = "Save" + publish_submit_label: STRING = "Publish" + unpublish_submit_label: STRING = "Unpublish" + preview_submit_label: STRING = "Preview" + end diff --git a/src/service/cms_api.e b/src/service/cms_api.e index 3442596..ea5aca5 100644 --- a/src/service/cms_api.e +++ b/src/service/cms_api.e @@ -248,11 +248,8 @@ feature {CMS_API_ACCESS} -- CMS Formats management -- Save `formats`. local f: CMS_FORMAT - jp: JSON_PARSER - cfg: JSON_CONFIG j,ji: JSON_OBJECT s: STRING_32 - l_name, l_title: READABLE_STRING_8 ct: CMS_CONTENT_TYPE do -- { "plain_text": { "title": "Plain text", "filters": "plain_text+foobar+toto"}, ...}