diff --git a/examples/demo/modules/blog/cms_blog_api.e b/examples/demo/modules/blog/cms_blog_api.e new file mode 100644 index 0000000..d75779b --- /dev/null +++ b/examples/demo/modules/blog/cms_blog_api.e @@ -0,0 +1,52 @@ +note + description: "API to handle nodes of type blog" + author: "Dario Bösch + do + Precursor + if attached {CMS_STORAGE_SQL_I} storage as l_storage_sql then + create {CMS_BLOG_STORAGE_SQL} node_storage.make (l_storage_sql) + else + create {CMS_BLOG_STORAGE_NULL} node_storage.make + end + initialize_node_types + end + +feature {CMS_MODULE} -- Access nodes storage. + + node_storage: CMS_BLOG_STORAGE_I + +feature -- Access node + + blogs_count: INTEGER_64 + -- Number of nodes of type blog + do + Result := node_storage.blogs_count + end + + blogs_order_created_desc: LIST[CMS_NODE] + -- List of nodes ordered by creation date (descending) + do + Result := node_storage.blogs + end + +end diff --git a/examples/demo/modules/blog/cms_blog_module-safe.ecf b/examples/demo/modules/blog/cms_blog_module-safe.ecf index bf6db6e..373775e 100644 --- a/examples/demo/modules/blog/cms_blog_module-safe.ecf +++ b/examples/demo/modules/blog/cms_blog_module-safe.ecf @@ -20,6 +20,7 @@ + diff --git a/examples/demo/modules/blog/cms_blog_module.e b/examples/demo/modules/blog/cms_blog_module.e index bd34810..1cd49dc 100644 --- a/examples/demo/modules/blog/cms_blog_module.e +++ b/examples/demo/modules/blog/cms_blog_module.e @@ -42,7 +42,7 @@ feature {CMS_API} -- Module Initialization do Precursor (api) - if attached {CMS_NODE_API} api.module_api ({NODE_MODULE}) as l_node_api then + if attached {CMS_BLOG_API} api.module_api ({NODE_MODULE}) as l_node_api then create ct l_node_api.add_content_type (ct) l_node_api.add_content_type_webform_manager (create {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}.make (ct)) @@ -87,7 +87,7 @@ CREATE TABLE "blog_post_nodes"( feature {CMS_API} -- Access: API - node_api: detachable CMS_NODE_API + node_api: detachable CMS_BLOG_API -- feature -- Access: router @@ -114,10 +114,9 @@ feature -- Access: router -- a_router.handle_with_request_methods ("/blogs/", create {WSF_URI_AGENT_HANDLER}.make (agent handle_blogs (?,?, a_api)), a_router.methods_get) -- end -configure_web (a_api: CMS_API; a_node_api: CMS_NODE_API; a_router: WSF_ROUTER) +configure_web (a_api: CMS_API; a_node_api: CMS_BLOG_API; a_router: WSF_ROUTER) local l_blog_handler: BLOG_HANDLER - l_node_handler: NODE_HANDLER l_uri_mapping: WSF_URI_MAPPING do -- TODO: for now, focused only on web interface, add REST api later. [2015-May-18] @@ -140,16 +139,4 @@ feature -- Hooks create lnk.make ("Blogs", "/blogs/") a_menu_system.primary_menu.extend (lnk) end - -feature -- Handler - - handle_blogs (req: WSF_REQUEST; res: WSF_RESPONSE; a_api: CMS_API) - local - r: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE - do - create r.make (req, res, a_api) - r.set_main_content ("Blog module is in development ...") - r.execute - end - end diff --git a/modules/node/handler/blog_handler.e b/examples/demo/modules/blog/handler/blog_handler.e similarity index 89% rename from modules/node/handler/blog_handler.e rename to examples/demo/modules/blog/handler/blog_handler.e index 1e8d67d..66efe1a 100644 --- a/modules/node/handler/blog_handler.e +++ b/examples/demo/modules/blog/handler/blog_handler.e @@ -1,6 +1,6 @@ note description: "Request handler related to /blogs." - author: "Dario Bösch " date: "$Date: 2015-05-18 13:49:99 +0100 (lun., 18 mai 2015) $" revision: "$966167$" @@ -8,14 +8,31 @@ class BLOG_HANDLER inherit - NODES_HANDLER + CMS_BLOG_HANDLER + + WSF_URI_HANDLER + rename + new_mapping as new_uri_mapping + end + + WSF_RESOURCE_HANDLER_HELPER redefine do_get end + REFACTORING_HELPER + create make +feature -- execute + + execute (req: WSF_REQUEST; res: WSF_RESPONSE) + -- Execute request handler + do + execute_methods (req, res) + end + feature -- Settings entries_per_page : INTEGER -- The numbers of posts that are shown on one page. If there are more post a pagination is generated diff --git a/examples/demo/modules/blog/handler/cms_blog_handler.e b/examples/demo/modules/blog/handler/cms_blog_handler.e new file mode 100644 index 0000000..c33d834 --- /dev/null +++ b/examples/demo/modules/blog/handler/cms_blog_handler.e @@ -0,0 +1,16 @@ +note + description: "Summary description for {CMS_NODE_HANDLER}." + author: "" + date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $" + revision: "$Revision: 96616 $" + +deferred class + CMS_BLOG_HANDLER + +inherit + CMS_MODULE_HANDLER [CMS_BLOG_API] + rename + module_api as node_api + end + +end diff --git a/examples/demo/modules/blog/persistence/cms_blog_storage_i.e b/examples/demo/modules/blog/persistence/cms_blog_storage_i.e new file mode 100644 index 0000000..21d081a --- /dev/null +++ b/examples/demo/modules/blog/persistence/cms_blog_storage_i.e @@ -0,0 +1,24 @@ +note + description: "Interface for accessing blog contents from the database." + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_BLOG_STORAGE_I + +inherit + CMS_NODE_STORAGE_I + +feature -- Access + + blogs_count: INTEGER_64 + -- Count of blog nodes + deferred + end + + blogs: LIST [CMS_NODE] + -- List of nodes ordered by creation date (descending). + deferred + end + +end diff --git a/examples/demo/modules/blog/persistence/cms_blog_storage_null.e b/examples/demo/modules/blog/persistence/cms_blog_storage_null.e new file mode 100644 index 0000000..fff5c0d --- /dev/null +++ b/examples/demo/modules/blog/persistence/cms_blog_storage_null.e @@ -0,0 +1,31 @@ +note + description: "Summary description for {CMS_BLOG_STORAGE_NULL}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + CMS_BLOG_STORAGE_NULL + +inherit + CMS_NODE_STORAGE_NULL + + CMS_BLOG_STORAGE_I + +create + make + +feature -- Access + + blogs_count: INTEGER_64 + -- Count of nodes. + do + end + + blogs: LIST[CMS_NODE] + -- List of nodes. + do + create {ARRAYED_LIST [CMS_NODE]} Result.make (0) + end + +end diff --git a/examples/demo/modules/blog/persistence/cms_blog_storage_sql.e b/examples/demo/modules/blog/persistence/cms_blog_storage_sql.e new file mode 100644 index 0000000..e39f103 --- /dev/null +++ b/examples/demo/modules/blog/persistence/cms_blog_storage_sql.e @@ -0,0 +1,61 @@ +note + description: "Summary description for {CMS_BLOG_STORAGE_SQL}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + CMS_BLOG_STORAGE_SQL + +inherit + CMS_NODE_STORAGE_SQL + + CMS_BLOG_STORAGE_I + +create + make + +feature -- Access + + blogs_count: INTEGER_64 + -- Count of blog nodes + do + error_handler.reset + write_information_log (generator + ".nodes_count") + sql_query (sql_select_blog_count, Void) + if sql_rows_count = 1 then + Result := sql_read_integer_64 (1) + end + end + + blogs: LIST [CMS_NODE] + -- List of nodes ordered by creation date (descending). + do + create {ARRAYED_LIST [CMS_NODE]} Result.make (0) + + error_handler.reset + write_information_log (generator + ".nodes") + + from + sql_query (sql_select_blogs_order_created_desc, Void) + sql_start + until + sql_after + loop + if attached fetch_node as l_node then + Result.force (l_node) + end + sql_forth + end + end + +feature {NONE} -- Queries + + sql_select_blog_count: STRING = "SELECT count(*) FROM Nodes WHERE status != -1 AND type = %"blog%";" + -- Nodes count (Published and not Published) + --| note: {CMS_NODE_API}.trashed = -1 + + sql_select_blogs_order_created_desc: STRING = "SELECT * FROM Nodes WHERE status != -1 AND type = %"blog%" ORDER BY created DESC;" + -- SQL Query to retrieve all nodes that are from the type "blog" ordered by descending creation date. + +end diff --git a/modules/node/cms_node_api.e b/modules/node/cms_node_api.e index c811ebd..d324d3b 100644 --- a/modules/node/cms_node_api.e +++ b/modules/node/cms_node_api.e @@ -212,11 +212,6 @@ feature -- Access: Node Result := node_storage.nodes end - blogs_order_created_desc: LIST[CMS_NODE] - -- List of nodes ordered by creation date (descending) - do - Result := node_storage.blogs - end recent_nodes (a_offset, a_rows: INTEGER): LIST [CMS_NODE] -- List of the `a_rows' most recent nodes starting from `a_offset'. diff --git a/modules/node/persistence/cms_node_storage_i.e b/modules/node/persistence/cms_node_storage_i.e index 9b68303..6090d95 100644 --- a/modules/node/persistence/cms_node_storage_i.e +++ b/modules/node/persistence/cms_node_storage_i.e @@ -70,11 +70,6 @@ feature -- Access deferred end - blogs: LIST [CMS_NODE] - -- List of nodes ordered by creation date (descending). - 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 diff --git a/modules/node/persistence/cms_node_storage_null.e b/modules/node/persistence/cms_node_storage_null.e index c574235..87559af 100644 --- a/modules/node/persistence/cms_node_storage_null.e +++ b/modules/node/persistence/cms_node_storage_null.e @@ -41,12 +41,6 @@ feature -- Access: node create {ARRAYED_LIST [CMS_NODE]} Result.make (0) end - blogs: LIST[CMS_NODE] - -- List of nodes ordered descending by creation date - 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 diff --git a/modules/node/persistence/cms_node_storage_sql.e b/modules/node/persistence/cms_node_storage_sql.e index 7365f80..756d61d 100644 --- a/modules/node/persistence/cms_node_storage_sql.e +++ b/modules/node/persistence/cms_node_storage_sql.e @@ -33,31 +33,6 @@ feature -- Access end end - blogs: LIST [CMS_NODE] - -- List of nodes ordered by creation date (descending). - do - create {ARRAYED_LIST [CMS_NODE]} Result.make (0) - - error_handler.reset - write_information_log (generator + ".nodes") - - from - sql_query (sql_select_blogs_order_created_desc, 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 nodes: LIST [CMS_NODE] -- List of nodes. @@ -254,10 +229,6 @@ feature {NONE} -- Queries -- SQL Query to retrieve all nodes. --| note: {CMS_NODE_API}.trashed = -1 - sql_select_blogs_order_created_desc: STRING = "SELECT * FROM Nodes WHERE status != -1 AND type = %"blog%" ORDER BY created DESC;" - -- SQL Query to retrieve all nodes that are from the type "blog" ordered by descending creation date. - --| note: {CMS_NODE_API}.trashed = -1 - sql_select_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status 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, status FROM Nodes ORDER BY nid DESC, publish DESC LIMIT :rows OFFSET :offset ;"