Updated CMS code.

Separated code to have a lib and an example.
Improved design, fixed a few issues related to folder location.

This is still experimental and require more work to be really friendly to use.
This commit is contained in:
Jocelyn Fiat
2013-01-31 15:33:24 +01:00
parent 40ea982293
commit ce469b6ede
136 changed files with 1841 additions and 299 deletions

View File

@@ -0,0 +1,57 @@
note
description: "Summary description for {ADMIN_BLOCKS_CMS_EXECUTION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
ADMIN_BLOCKS_CMS_EXECUTION
inherit
CMS_EXECUTION
create
make
feature -- Execution
process
-- Computed response message.
local
b: STRING_8
do
set_title ("Blocks")
-- check Permission !!!
create b.make_empty
if has_permission ("administrate blocks") then
b.append ("<ul id=%"block-list%">")
across
blocks as c
loop
if attached c.item as b_info then
if b_info.block.is_enabled then
b.append ("<li class=%"enabled%">")
else
b.append ("<li class=%"disabled%">")
end
b.append ("<strong>" + b_info.name + "</strong> (region=" + b_info.region + ")")
if b_info.block.is_enabled then
b.append (" [<a href=%"%">disable</a>]")
else
b.append (" [<a href=%"%">enable</a>]")
end
if attached b_info.block.title as l_title then
b.append ("<div>title=<em>" + l_title + "</em></div>")
end
b.append ("</li>")
end
end
b.append ("</ul>")
else
b.append ("<div class=%"denied%">Access denied</div>")
end
set_main_content (b)
end
end

View File

@@ -0,0 +1,43 @@
note
description: "Summary description for {CMS_ADMIN_EXECUTION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
ADMIN_CMS_EXECUTION
inherit
CMS_EXECUTION
create
make
feature -- Execution
process
-- Computed response message.
local
b: STRING_8
do
set_title ("Administration")
-- check Permission !!!
create b.make_empty
if has_permission ("administrate modules") then
b.append ("<li>" + link ("Modules", "/admin/modules/", Void) + "</li>")
end
if has_permission ("administrate blocks") then
b.append ("<li>" + link ("Blocks", "/admin/blocks/", Void) + "</li>")
end
if has_permission ("administrate users") then
b.append ("<li>" + link ("Users", "/admin/users/", Void) + "</li>")
end
if has_permission ("administrate logs") then
b.append ("<li>" + link ("Logs", "/admin/logs/", Void) + "</li>")
end
set_main_content (b)
end
end

View File

@@ -0,0 +1,47 @@
note
description: "Summary description for {ADMIN_LOGS_CMS_EXECUTION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
ADMIN_LOGS_CMS_EXECUTION
inherit
CMS_EXECUTION
create
make
feature -- Execution
process
-- Computed response message.
local
b: STRING_8
do
set_title ("Logs")
-- check Permission !!!
create b.make_empty
if has_permission ("admin logs") then
b.append ("<ul id=%"log-list%">")
across
storage.recent_logs (1, 25) as c
loop
if attached c.item as l_log then
b.append ("<li class=%"log%">")
b.append (link ("[" + l_log.id.out + "]", "/admin/log/" + l_log.id.out, Void))
b.append (" <strong>" + l_log.category + "</strong> (level=" + l_log.level_name + ")")
b.append (": " + truncated_string (l_log.message, 60, "..."))
b.append ("</li>")
end
end
b.append ("</ul>")
else
b.append ("<div class=%"denied%">Access denied</div>")
end
set_main_content (b)
end
end

View File

@@ -0,0 +1,100 @@
note
description: "Summary description for {ADMIN_MODULE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
ADMIN_MODULE
inherit
CMS_MODULE
CMS_HOOK_MENU_ALTER
create
make
feature {NONE} -- Initialization
make (a_service: like service)
do
service := a_service
name := "admin"
version := "1.0"
description := "Set of service to administrate the site"
package := "core"
enable
end
feature {CMS_SERVICE} -- Registration
service: CMS_SERVICE
register (a_service: CMS_SERVICE)
do
a_service.map_uri ("/admin/", agent handle_admin)
a_service.map_uri ("/admin/users/", agent handle_admin_users)
a_service.map_uri ("/admin/blocks/", agent handle_admin_blocks)
a_service.map_uri ("/admin/modules/", agent handle_admin_modules)
a_service.map_uri ("/admin/logs/", agent handle_admin_logs)
a_service.map_uri_template ("/admin/log/{log-id}", agent handle_admin_log_view)
a_service.add_menu_alter_hook (Current)
end
feature -- Hooks
menu_alter (a_menu_system: CMS_MENU_SYSTEM; a_execution: CMS_EXECUTION)
local
lnk: CMS_LOCAL_LINK
do
create lnk.make ("Administer", "/admin/")
lnk.set_permission_arguments (<<"administer">>)
a_menu_system.management_menu.extend (lnk)
end
links: HASH_TABLE [CMS_MODULE_LINK, STRING]
-- Link indexed by path
local
-- lnk: CMS_MODULE_LINK
do
create Result.make (3)
-- create lnk.make ("Date/time demo")
-- lnk.set_callback (agent process_date_time_demo, <<"arg">>)
-- Result["/demo/date/{arg}"] := lnk
end
handle_admin (req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ADMIN_CMS_EXECUTION}.make (req, res, service)).execute
end
handle_admin_users (req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ADMIN_USERS_CMS_EXECUTION}.make (req, res, service)).execute
end
handle_admin_blocks (req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ADMIN_BLOCKS_CMS_EXECUTION}.make (req, res, service)).execute
end
handle_admin_modules (req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ADMIN_MODULES_CMS_EXECUTION}.make (req, res, service)).execute
end
handle_admin_logs (req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {ADMIN_LOGS_CMS_EXECUTION}.make (req, res, service)).execute
end
handle_admin_log_view (req: WSF_REQUEST; res: WSF_RESPONSE)
do
(create {LOG_VIEW_CMS_EXECUTION}.make (req, res, service)).execute
end
end

View File

@@ -0,0 +1,57 @@
note
description: "Summary description for {ADMIN_MODULES_CMS_EXECUTION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
ADMIN_MODULES_CMS_EXECUTION
inherit
CMS_EXECUTION
create
make
feature -- Execution
process
-- Computed response message.
local
b: STRING_8
do
set_title ("Modules")
-- check Permission !!!
create b.make_empty
if has_permission ("administrate modules") then
b.append ("<ul id=%"module-list%">")
across
service.modules as m
loop
if attached m.item as mod then
if mod.is_enabled then
b.append ("<li class=%"enabled%">")
else
b.append ("<li class=%"disabled%">")
end
b.append ("<strong>" + mod.name + "</strong> (version:" + mod.version + ")")
b.append (" package=" + mod.package)
if mod.is_enabled then
b.append (" [<a href=%"%">disable</a>]")
else
b.append (" [<a href=%"%">enable</a>]")
end
b.append ("<pre>" + mod.description + "</pre>")
b.append ("</li>")
end
end
b.append ("</ul>")
else
b.append ("<div class=%"denied%">Access denied</div>")
end
set_main_content (b)
end
end

View File

@@ -0,0 +1,56 @@
note
description: "Summary description for {ADMIN_USERS_CMS_EXECUTION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
ADMIN_USERS_CMS_EXECUTION
inherit
CMS_EXECUTION
create
make
feature -- Execution
process
-- Computed response message.
local
b: STRING_8
do
set_title ("Users")
-- check Permission !!!
create b.make_empty
if has_permission ("administrate users") then
b.append ("<ul id=%"user-list%">")
across
service.storage.all_users as c
loop
if attached c.item as u then
b.append ("<li class=%"user%">")
b.append ("<strong>" + user_link (u) + "</strong> (id=" + u.id.out + ")")
if attached u.email as l_email then
b.append (" [<a mailto=%""+ l_email +"%">"+ l_email +"</a>]")
end
if attached u.creation_date as dt then
b.append (" - created: " + dt.out)
end
if attached u.last_login_date as dt then
b.append (" - last signed: " + dt.out)
end
b.append ("</li>")
end
end
b.append ("</ul>")
else
b.append ("<div class=%"denied%">Access denied</div>")
end
set_main_content (b)
end
end

View File

@@ -0,0 +1,39 @@
note
description: "Summary description for {LOG_VIEW_CMS_EXECUTION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
LOG_VIEW_CMS_EXECUTION
inherit
CMS_EXECUTION
create
make
feature -- Execution
process
-- Computed response message.
local
b: STRING_8
do
if attached {WSF_STRING} request.path_parameter ("log-id") as p_id and then p_id.is_integer then
create b.make_empty
if attached storage.log (p_id.integer_value) as l_log then
set_title ("Log #" + l_log.id.out)
b.append (l_log.to_html (theme))
else
set_title ("Log [" + p_id.value + "] does not exists!")
end
set_main_content (b)
else
set_redirection ("/admin/logs")
set_main_content ("not found")
end
end
end