Added recent_changes module.
Revisited hooks management, and added new CMS_HOOK_MANAGER. Added admin, and other link into navigation menu that goes into first sidebar. Fixed theme info, and template for sidebar ids. Better css class name for cms node content.
This commit is contained in:
82
modules/recent_changes/cms_recent_change_container.e
Normal file
82
modules/recent_changes/cms_recent_change_container.e
Normal file
@@ -0,0 +1,82 @@
|
||||
note
|
||||
description: "Container of recent change items, and associated parameters."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_RECENT_CHANGE_CONTAINER
|
||||
|
||||
inherit
|
||||
ITERABLE [CMS_RECENT_CHANGE_ITEM]
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make (a_limit: NATURAL_32; a_date: detachable DATE_TIME; a_source: detachable READABLE_STRING_8)
|
||||
do
|
||||
limit := a_limit
|
||||
date := a_date
|
||||
source := a_source
|
||||
create items.make (a_limit.to_integer_32)
|
||||
end
|
||||
|
||||
feature -- Settings
|
||||
|
||||
limit: NATURAL_32
|
||||
|
||||
date: detachable DATE_TIME
|
||||
|
||||
source: detachable READABLE_STRING_8
|
||||
|
||||
feature -- Access
|
||||
|
||||
items: ARRAYED_LIST [CMS_RECENT_CHANGE_ITEM]
|
||||
-- List of recent events.
|
||||
|
||||
count: INTEGER
|
||||
-- Number of change items.
|
||||
do
|
||||
Result := items.count
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
new_cursor: ITERATION_CURSOR [CMS_RECENT_CHANGE_ITEM]
|
||||
-- <Precursor>
|
||||
do
|
||||
Result := items.new_cursor
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
force (a_item: CMS_RECENT_CHANGE_ITEM)
|
||||
-- Add `a_item'.
|
||||
do
|
||||
items.force (a_item)
|
||||
end
|
||||
|
||||
feature -- Sorting
|
||||
|
||||
sort
|
||||
-- Sort `items' from older, to newer.
|
||||
do
|
||||
change_item_sorter.sort (items)
|
||||
end
|
||||
|
||||
reverse_sort
|
||||
-- Sort `items' from newer to older.
|
||||
do
|
||||
change_item_sorter.reverse_sort (items)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
change_item_sorter: QUICK_SORTER [CMS_RECENT_CHANGE_ITEM]
|
||||
-- New change item sorter.
|
||||
once
|
||||
create Result.make (create {COMPARABLE_COMPARATOR [CMS_RECENT_CHANGE_ITEM]})
|
||||
end
|
||||
|
||||
end
|
||||
64
modules/recent_changes/cms_recent_change_item.e
Normal file
64
modules/recent_changes/cms_recent_change_item.e
Normal file
@@ -0,0 +1,64 @@
|
||||
note
|
||||
description: "Information related to change event."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_RECENT_CHANGE_ITEM
|
||||
|
||||
inherit
|
||||
COMPARABLE
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_source: READABLE_STRING_8; lnk: CMS_LOCAL_LINK; a_date_time: DATE_TIME)
|
||||
do
|
||||
source := a_source
|
||||
link := lnk
|
||||
date := a_date_time
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
link: CMS_LOCAL_LINK
|
||||
-- Local link associated with the resource.
|
||||
|
||||
date: DATE_TIME
|
||||
-- Time of the event item.
|
||||
|
||||
author: detachable CMS_USER
|
||||
-- Optional author.
|
||||
|
||||
source: READABLE_STRING_8
|
||||
-- Source of Current event.
|
||||
|
||||
information: detachable READABLE_STRING_8
|
||||
-- Optional information related to Current event.
|
||||
--| For instance: creation, trashed, modified, ...
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_author (u: like author)
|
||||
-- Set `author' to `u'.
|
||||
do
|
||||
author := u
|
||||
end
|
||||
|
||||
set_information (a_info: like information)
|
||||
-- Set `information' to `a_info'.
|
||||
do
|
||||
information := a_info
|
||||
end
|
||||
|
||||
feature -- Comparison
|
||||
|
||||
is_less alias "<" (other: like Current): BOOLEAN
|
||||
-- <Precursor>
|
||||
do
|
||||
Result := date < other.date
|
||||
end
|
||||
|
||||
end
|
||||
20
modules/recent_changes/cms_recent_changes_hook.e
Normal file
20
modules/recent_changes/cms_recent_changes_hook.e
Normal file
@@ -0,0 +1,20 @@
|
||||
note
|
||||
description: "Hook provided by module {CMS_RECENT_CHANGES_MODULE}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
CMS_RECENT_CHANGES_HOOK
|
||||
|
||||
inherit
|
||||
CMS_HOOK
|
||||
|
||||
feature -- Invocation
|
||||
|
||||
populate_recent_changes (a_changes: CMS_RECENT_CHANGE_CONTAINER; a_sources: LIST [READABLE_STRING_8])
|
||||
-- Populate recent changes inside `a_changes' according to associated parameters.
|
||||
-- Also provide sources of information.
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
||||
234
modules/recent_changes/cms_recent_changes_module.e
Normal file
234
modules/recent_changes/cms_recent_changes_module.e
Normal file
@@ -0,0 +1,234 @@
|
||||
note
|
||||
description: "CMS module that bring support for recent changes."
|
||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
class
|
||||
CMS_RECENT_CHANGES_MODULE
|
||||
|
||||
inherit
|
||||
CMS_MODULE
|
||||
rename
|
||||
module_api as recent_changes_api
|
||||
redefine
|
||||
register_hooks
|
||||
end
|
||||
|
||||
CMS_HOOK_MENU_SYSTEM_ALTER
|
||||
|
||||
CMS_HOOK_RESPONSE_ALTER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Create Current module, disabled by default.
|
||||
do
|
||||
version := "1.0"
|
||||
description := "Service to access recent changes"
|
||||
package := "notification"
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING = "recent_changes"
|
||||
|
||||
feature -- Access: router
|
||||
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- <Precursor>
|
||||
do
|
||||
a_router.handle ("/recent_changes/", create {WSF_URI_AGENT_HANDLER}.make (agent handle_recent_changes (a_api, ?, ?)), a_router.methods_head_get)
|
||||
end
|
||||
|
||||
feature -- Handler
|
||||
|
||||
handle_recent_changes (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
r: CMS_RESPONSE
|
||||
l_changes: CMS_RECENT_CHANGE_CONTAINER
|
||||
l_sources: ARRAYED_LIST [READABLE_STRING_8]
|
||||
dt, prev_dt: detachable DATE
|
||||
ch: detachable CMS_RECENT_CHANGE_ITEM
|
||||
htdate: HTTP_DATE
|
||||
l_content: STRING
|
||||
l_form: CMS_FORM
|
||||
l_select: WSF_FORM_SELECT
|
||||
l_until_date: detachable DATE_TIME
|
||||
l_filter_source: detachable READABLE_STRING_8
|
||||
l_size: NATURAL_32
|
||||
l_query: STRING
|
||||
opt: WSF_FORM_SELECT_OPTION
|
||||
do
|
||||
if attached {WSF_STRING} req.query_parameter ("date") as p_until_date then
|
||||
create htdate.make_from_timestamp (p_until_date.value.to_integer_64)
|
||||
l_until_date := htdate.date_time
|
||||
-- l_until_date.second_add (-1)
|
||||
end
|
||||
if attached {WSF_STRING} req.query_parameter ("filter") as p_filter then
|
||||
l_filter_source := p_filter.url_encoded_value
|
||||
end
|
||||
if attached {WSF_STRING} req.query_parameter ("size") as p_size then
|
||||
l_size := p_size.integer_value.to_natural_32
|
||||
end
|
||||
if l_size = 0 then
|
||||
l_size := 25
|
||||
end
|
||||
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
|
||||
create l_changes.make (l_size, l_until_date, l_filter_source)
|
||||
|
||||
create l_content.make (1024)
|
||||
if attached r.hooks.subscribers ({CMS_RECENT_CHANGES_HOOK}) as lst then
|
||||
create l_sources.make (lst.count)
|
||||
across
|
||||
lst as ic
|
||||
loop
|
||||
if attached {CMS_RECENT_CHANGES_HOOK} ic.item as h then
|
||||
h.populate_recent_changes (l_changes, l_sources)
|
||||
end
|
||||
end
|
||||
create l_form.make (req.percent_encoded_path_info, "recent-changes")
|
||||
create l_select.make ("source")
|
||||
l_select.set_label ("Sources")
|
||||
create opt.make ("", "...")
|
||||
l_select.add_option (opt)
|
||||
across
|
||||
l_sources as ic
|
||||
loop
|
||||
create opt.make (ic.item, ic.item)
|
||||
if l_filter_source /= Void and then ic.item.is_case_insensitive_equal (l_filter_source) then
|
||||
opt.set_is_selected (True)
|
||||
end
|
||||
l_select.add_option (opt)
|
||||
end
|
||||
l_form.extend (l_select)
|
||||
l_form.extend_html_text ("<br/>")
|
||||
l_form.append_to_html (create {CMS_TO_WSF_THEME}.make (r, r.theme), l_content)
|
||||
end
|
||||
|
||||
l_changes.reverse_sort
|
||||
l_content.append ("<table class=%"recent-changes%" style=%"border-spacing: 5px;%">")
|
||||
l_content.append ("<thead>")
|
||||
l_content.append ("<tr>")
|
||||
l_content.append ("<th>Date</th>")
|
||||
l_content.append ("<th>Source</th>")
|
||||
l_content.append ("<th>Resource</th>")
|
||||
l_content.append ("<th>User</th>")
|
||||
l_content.append ("<th>Information</th>")
|
||||
l_content.append ("</tr>")
|
||||
l_content.append ("</thead>")
|
||||
l_content.append ("<tbody>")
|
||||
|
||||
across
|
||||
l_changes as ic
|
||||
loop
|
||||
ch := ic.item
|
||||
dt := ch.date.date
|
||||
if dt /~ prev_dt then
|
||||
l_content.append ("<tr>")
|
||||
l_content.append ("<td class=%"title%" colspan=%"5%">")
|
||||
l_content.append (dt.formatted_out ("ddd, dd mmm yyyy"))
|
||||
l_content.append ("</td>")
|
||||
l_content.append ("</tr>")
|
||||
end
|
||||
prev_dt := dt
|
||||
l_content.append ("<tr>")
|
||||
l_content.append ("<td class=%"date%">")
|
||||
create htdate.make_from_date_time (ch.date)
|
||||
htdate.append_to_rfc1123_string (l_content)
|
||||
l_content.append ("</td>")
|
||||
l_content.append ("<td class=%"source%">" + ch.source + "</td>")
|
||||
l_content.append ("<td class=%"resource%">")
|
||||
l_content.append (r.link (ch.link.title, ch.link.location, Void))
|
||||
l_content.append ("</td>")
|
||||
l_content.append ("<td class=%"user%">")
|
||||
if attached ch.author as u then
|
||||
l_content.append (r.link (u.name, "user/" + u.id.out, Void))
|
||||
end
|
||||
l_content.append ("</td>")
|
||||
l_content.append ("<td class=%"info%">")
|
||||
if attached ch.information as l_info then
|
||||
l_content.append ("<strong>" + l_info + "</strong> ")
|
||||
end
|
||||
l_content.append ("</td>")
|
||||
l_content.append ("</tr>%N")
|
||||
end
|
||||
l_content.append ("</tbody>")
|
||||
l_content.append ("</table>%N")
|
||||
|
||||
if ch /= Void then
|
||||
if l_until_date /= Void then
|
||||
l_content.append (" <a href=%"")
|
||||
l_content.append (r.url (r.location, Void))
|
||||
l_content.append ("?size=" + l_size.out + "%"><<</a> ")
|
||||
end
|
||||
|
||||
if l_until_date /~ ch.date then
|
||||
create htdate.make_from_date_time (ch.date)
|
||||
create l_query.make_from_string ("size=" + l_size.out)
|
||||
l_query.append ("&date=")
|
||||
l_query.append (htdate.timestamp.out)
|
||||
if l_filter_source /= Void then
|
||||
l_query.append ("&filter=")
|
||||
l_query.append (l_filter_source)
|
||||
end
|
||||
l_content.append ("<a href=%"")
|
||||
l_content.append (r.url (r.location, create {CMS_API_OPTIONS}.make_from_manifest (<<["query", l_query]>>)))
|
||||
l_content.append ("%">More ...</a>")
|
||||
end
|
||||
end
|
||||
|
||||
r.set_main_content (l_content)
|
||||
if l_until_date = Void then
|
||||
r.set_title ("Recent changes")
|
||||
else
|
||||
create htdate.make_from_date_time (l_until_date)
|
||||
r.set_title ("Recent changes before " + htdate.string)
|
||||
end
|
||||
|
||||
r.execute
|
||||
end
|
||||
|
||||
feature -- Hooks configuration
|
||||
|
||||
register_hooks (a_response: CMS_RESPONSE)
|
||||
-- Module hooks configuration.
|
||||
do
|
||||
a_response.hooks.subscribe_to_menu_system_alter_hook (Current)
|
||||
a_response.hooks.subscribe_to_response_alter_hook (Current)
|
||||
end
|
||||
|
||||
feature -- Hook
|
||||
|
||||
response_alter (a_response: CMS_RESPONSE)
|
||||
do
|
||||
a_response.add_additional_head_line ("[
|
||||
<style>
|
||||
table.recent-changes th { padding: 3px; }
|
||||
table.recent-changes td { padding: 3px; border: dotted 1px #ddd; }
|
||||
table.recent-changes td.date { padding-left: 15px; }
|
||||
table.recent-changes td.title { font-weight: bold; }
|
||||
</style>
|
||||
]", True)
|
||||
end
|
||||
|
||||
menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
||||
-- Hook execution on collection of menu contained by `a_menu_system'
|
||||
-- for related response `a_response'.
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
do
|
||||
create lnk.make ("Recent changes", "recent_changes/")
|
||||
lnk.set_permission_arguments (<<"view recent changes">>)
|
||||
a_menu_system.navigation_menu.extend (lnk)
|
||||
end
|
||||
|
||||
-- populate_recent_changes (lst: LIST [CMS_RECENT_CHANGE_ITEM]; a_date: detachable DATE_TIME; a_limit: INTEGER)
|
||||
-- do
|
||||
-- end
|
||||
|
||||
|
||||
end
|
||||
25
modules/recent_changes/recent_changes-safe.ecf
Normal file
25
modules/recent_changes/recent_changes-safe.ecf
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="recent_changes" uuid="1C3893A3-46FC-4E60-86AE-37CB7939BC7F" library_target="recent_changes">
|
||||
<target name="recent_changes">
|
||||
<root all_classes="true"/>
|
||||
<file_rule>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
<exclude>/CVS$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="all" syntax="transitional">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="base_extension" location="$ISE_LIBRARY\library\base_extension\base_extension-safe.ecf"/>
|
||||
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
|
||||
<library name="cms" location="..\..\cms-safe.ecf"/>
|
||||
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/>
|
||||
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
|
||||
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
|
||||
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension-safe.ecf" readonly="false"/>
|
||||
<library name="wsf_html" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf_html\wsf_html-safe.ecf" readonly="false"/>
|
||||
<cluster name="src" location=".\" recursive="true"/>
|
||||
</target>
|
||||
</system>
|
||||
Reference in New Issue
Block a user