added some commments

This commit is contained in:
Dario Bösch
2015-05-22 17:58:46 +02:00
parent 0bd75e7c59
commit e8ff313c28
5 changed files with 19 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
note note
description: "API to handle nodes of type blog" description: "API to handle nodes of type blog. Extends the node API."
author: "Dario B<>sch <daboesch@student.ethz.ch" author: "Dario B<>sch <daboesch@student.ethz.ch"
date: "$Date: 2015-05-21 14:46:00 +0100$" date: "$Date: 2015-05-21 14:46:00 +0100$"
revision: "$Revision: 96616 $" revision: "$Revision: 96616 $"
@@ -23,6 +23,7 @@ feature {NONE} -- Implementation
-- <Precursor> -- <Precursor>
do do
Precursor Precursor
-- Create the node storage for type blog
if attached {CMS_STORAGE_SQL_I} storage as l_storage_sql then if attached {CMS_STORAGE_SQL_I} storage as l_storage_sql then
create {CMS_BLOG_STORAGE_SQL} node_storage.make (l_storage_sql) create {CMS_BLOG_STORAGE_SQL} node_storage.make (l_storage_sql)
else else

View File

@@ -1,5 +1,5 @@
note note
description: "Request handler related to /blogs." description: "Request handler related to /blogs and /blogs/{page}. Displays all posts in the blog."
author: "Dario B<>sch <daboesch@student.ethz.ch>" author: "Dario B<>sch <daboesch@student.ethz.ch>"
date: "$Date: 2015-05-18 13:49:00 +0100 (lun., 18 mai 2015) $" date: "$Date: 2015-05-18 13:49:00 +0100 (lun., 18 mai 2015) $"
revision: "$9661667$" revision: "$9661667$"
@@ -67,13 +67,11 @@ feature -- HTTP Methods
local local
l_page: CMS_RESPONSE l_page: CMS_RESPONSE
do do
-- At the moment the template is hardcoded, but we can
-- get them from the configuration file and load them into
-- the setup class.
-- Read the page number from get variable -- Read the page number from get variable
page_number := page_number_path_parameter (req) page_number := page_number_path_parameter (req)
-- execute response by setting the main content
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
l_page.set_main_content (main_content_html(l_page)) l_page.set_main_content (main_content_html(l_page))
l_page.execute l_page.execute
@@ -83,7 +81,7 @@ feature -- Query
posts : LIST[CMS_NODE] posts : LIST[CMS_NODE]
-- The posts to list on the given page -- The posts to list on the given page ordered by date (descending)
do do
Result := node_api.blogs_order_created_desc_limited (entries_per_page, (page_number-1) * entries_per_page) Result := node_api.blogs_order_created_desc_limited (entries_per_page, (page_number-1) * entries_per_page)
end end
@@ -142,7 +140,7 @@ feature -- HTML Output
-- Get the posts from the current page (given by page number and entries per page) -- Get the posts from the current page (given by page number and entries per page)
if attached posts as lst then if attached posts as lst then
-- List all posts of the blog -- Start list of posts
Result.append ("<ul class=%"cms_blog_nodes%">%N") Result.append ("<ul class=%"cms_blog_nodes%">%N")
across across
lst as ic lst as ic
@@ -169,7 +167,7 @@ feature -- HTML Output
-- End of post list -- End of post list
Result.append ("</ul>%N") Result.append ("</ul>%N")
-- Pagination -- Pagination (older and newer links)
Result.append (pagination_html) Result.append (pagination_html)
--end --end
@@ -182,13 +180,12 @@ feature -- HTML Output
create Result.make_from_string ("<h2>Blog") create Result.make_from_string ("<h2>Blog")
if more_than_one_page then if more_than_one_page then
Result.append (" (Page " + page_number.out + " of " + pages.out + ")") Result.append (" (Page " + page_number.out + " of " + pages.out + ")")
-- Get the posts from the current page (limited by entries per page)
end end
Result.append ("</h2>") Result.append ("</h2>")
end end
creation_date_html (n: CMS_NODE) : STRING creation_date_html (n: CMS_NODE) : STRING
-- returns the creation date. At the moment hard coded as html -- returns the creation date as a html string
local local
hdate: HTTP_DATE hdate: HTTP_DATE
do do

View File

@@ -1,5 +1,5 @@
note note
description: "Request handler related to /blogs/user/{id}/. Displays all posts of the given user" description: "Request handler related to /blogs/user/{id}/ or /blogs/user/{id}/page/{page}. Displays all posts of the given user"
author: "Dario B<>sch <daboesch@student.ethz.ch>" author: "Dario B<>sch <daboesch@student.ethz.ch>"
date: "$Date: 2015-05-22 15:13:00 +0100 (lun., 18 mai 2015) $" date: "$Date: 2015-05-22 15:13:00 +0100 (lun., 18 mai 2015) $"
revision: "$Revision 96616$" revision: "$Revision 96616$"
@@ -35,9 +35,10 @@ feature -- HTTP Methods
-- Check if userID valid -- Check if userID valid
if user_valid (req) then if user_valid (req) then
user := load_user(req) user := load_user(req)
-- Output the results, similar as in the blog hanlder (but with other queries)
precursor(req, res) precursor(req, res)
else else
-- Throw a bad request error if the user is not valid -- Throw a bad request error because the user is not valid
create l_error.make (req, res, api) create l_error.make (req, res, api)
l_error.set_main_content ("<h1>Error</h1>User with id " + user_path_parameter(req).out + " doesn't exist!") l_error.set_main_content ("<h1>Error</h1>User with id " + user_path_parameter(req).out + " doesn't exist!")
l_error.execute l_error.execute
@@ -88,7 +89,7 @@ feature -- Query
end end
posts : LIST[CMS_NODE] posts : LIST[CMS_NODE]
-- The posts to list on the given page -- The posts to list on the given page. Filters out the posts of the current user
do do
if attached user as l_user then if attached user as l_user then
Result := node_api.blogs_from_user_order_created_desc_limited (l_user.id.to_integer_32, entries_per_page, (page_number-1) * entries_per_page) Result := node_api.blogs_from_user_order_created_desc_limited (l_user.id.to_integer_32, entries_per_page, (page_number-1) * entries_per_page)
@@ -98,7 +99,7 @@ feature -- Query
end end
total_entries : NATURAL_32 total_entries : NATURAL_32
-- Returns the number of total entries/posts -- Returns the number of total entries/posts of the current user
do do
if attached user as l_user then if attached user as l_user then
Result := node_api.blogs_count_from_user(l_user.id).to_natural_32 Result := node_api.blogs_count_from_user(l_user.id).to_natural_32
@@ -111,7 +112,7 @@ feature -- Query
feature -- HTML Output feature -- HTML Output
page_title_html : STRING page_title_html : STRING
-- Returns the title of the page as a html string. It shows the current page number -- Returns the title of the page as a html string. It shows the current page number and the name of the current user
do do
create Result.make_from_string ("<h2>Posts from ") create Result.make_from_string ("<h2>Posts from ")
if attached user as l_user then if attached user as l_user then
@@ -127,7 +128,7 @@ feature -- HTML Output
end end
base_path : STRING base_path : STRING
-- the path to the page that lists all blogs -- the path to the page that lists all blogs. It must include the user id
do do
if attached user as l_user then if attached user as l_user then
Result := "/blogs/user/" + l_user.id.out Result := "/blogs/user/" + l_user.id.out

View File

@@ -1,8 +1,8 @@
note note
description: "Summary description for {CMS_NODE_HANDLER}." description: "Deferred request handler related to /blogs/... Has an own blog api."
author: "" author: "Dario B<>sch <daboesch@student.ethz.ch>"
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $" date: "$Date: 2015-05-18 13:49:00 +0100 (lun., 18 mai 2015) $"
revision: "$Revision: 96616 $" revision: "$9661667$"
deferred class deferred class
CMS_BLOG_HANDLER CMS_BLOG_HANDLER

View File

@@ -36,11 +36,6 @@ feature -- Initialization
create u.make ("admin") create u.make ("admin")
u.set_password ("istrator#") u.set_password ("istrator#")
u.set_email (a_setup.site_email) u.set_email (a_setup.site_email)
a_storage.new_user (u)
create u.make ("daboesch")
u.set_password ("eiffel")
u.set_email ("daboesch@student.ethz.ch")
a_storage.new_user (u) a_storage.new_user (u)
--| Node --| Node