Added custom-template in examples, as a base template to integrate easily other JS widgets.

Added custom example (based on custom-template project) that demonstrates how to integrate a thirdparty JS component such as d3 within the application using wsf_js_widget.

Removed various unecessary ecf dependencies.
This commit is contained in:
2014-07-07 12:15:18 +02:00
parent 0427f7a8d3
commit f6ebd414d6
53 changed files with 24893 additions and 8 deletions

View File

@@ -0,0 +1,107 @@
note
description: "simple application root class"
date: "$Date$"
revision: "$Revision$"
class
APPLICATION
inherit
WSF_ROUTED_SERVICE
rename
execute as execute_router
end
WSF_FILTERED_SERVICE
WSF_DEFAULT_SERVICE
redefine
initialize
end
WSF_FILTER
rename
execute as execute_router
end
create
make_and_launch
feature {NONE} -- Initialization
initialize
-- Initialize current service.
do
initialize_router
initialize_filter
Precursor
set_service_option ("port", 7070)
end
feature -- Router and Filter
create_filter
-- Create `filter'
local
f, l_filter: detachable WSF_FILTER
do
l_filter := Void
-- Maintenance
create {WSF_MAINTENANCE_FILTER} f
f.set_next (l_filter)
l_filter := f
-- Logging
create {WSF_LOGGING_FILTER} f
f.set_next (l_filter)
l_filter := f
filter := l_filter
end
setup_filter
-- Setup `filter'
local
f: WSF_FILTER
do
from
f := filter
until
not attached f.next as l_next
loop
f := l_next
end
f.set_next (Current)
end
setup_router
do
map_agent_uri ("/", agent execute_hello, Void)
-- NOTE: you could put all those files in a specific folder, and use WSF_FILE_SYSTEM_HANDLER with "/"
-- this way, it handles the caching and so on
router.handle_with_request_methods ("/assets", create {WSF_FILE_SYSTEM_HANDLER}.make_hidden ("assets"), router.methods_GET)
end
feature -- Helper: mapping
map_agent_uri (a_uri: READABLE_STRING_8; a_action: like {WSF_URI_AGENT_HANDLER}.action; rqst_methods: detachable WSF_REQUEST_METHODS)
do
router.map_with_request_methods (create {WSF_URI_MAPPING}.make (a_uri, create {WSF_URI_AGENT_HANDLER}.make (a_action)), rqst_methods)
end
feature -- Execution
execute_hello (request: WSF_REQUEST; response: WSF_RESPONSE)
local
page: EMPTY_PAGE
do
-- To send a response we need to setup, the status code and
-- the response headers.
create page.make (request, response)
page.execute
end
end

View File

@@ -0,0 +1,40 @@
note
description: "Summary description for {BASE_PAGE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
BASE_PAGE
inherit
WSF_PAGE_CONTROL
redefine
control,
initialize_controls
end
feature
initialize_controls
do
create control.make
control.add_class ("container")
create navbar.make_with_brand ("EWF JS CUSTOM WIDGET")
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/%"", "Home"))
create main_control.make
control.add_control (navbar)
control.add_control (main_control)
end
feature -- Properties
main_control: WSF_LAYOUT_CONTROL
control: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
navbar: WSF_NAVBAR_CONTROL
end

View File

@@ -0,0 +1,55 @@
note
description: "Summary description for {EMPTY_PAGE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
EMPTY_PAGE
inherit
BASE_PAGE
redefine
initialize_controls
end
create
make
feature -- Initialization
initialize_controls
do
Precursor
-- Bind custom.js
add_javascript ("assets/custom.js")
navbar.set_active (1)
-- Define colum 12/12
main_control.add_column (6)
main_control.add_column (6)
create chart.make
chart.set_data (<<["Eiffel",100.0],["Java",20.0],["C++",40.0]>>)
main_control.add_control (1,chart)
-- Create button
create button.make ("Load new dataset")
button.set_click_event (agent do
chart.set_data (<<["Eiffel",120.0],["Java",60.0],["C#",30.0],["Python",230.0]>>)
end)
--Add button control
main_control.add_control (2,button)
end
feature -- Implementation
process
do
end
feature
button: WSF_BUTTON_CONTROL
chart: WSF_BARCHART_CONTROL
end

View File

@@ -0,0 +1,95 @@
note
description: "Summary description for {WSF_BARCHART_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_BARCHART_CONTROL
inherit
WSF_CONTROL
rename
make as make_control
end
create
make
feature {NONE} -- Initialization
make
do
make_control ("div")
data := <<>>
end
feature -- State handling
set_state (new_state: JSON_OBJECT)
-- Restore data from json
do
if attached {JSON_ARRAY} new_state.item ("data") as new_data then
create data.make_filled (["",0.0], 1, new_data.array_representation.count)
across
new_data.array_representation as d
loop
if attached {JSON_OBJECT} d.item as citem
and then attached {JSON_STRING} citem.item ("key") as key
and then attached {JSON_NUMBER} citem.item ("value") as value then
data.put ([key.item,value.item.to_real_64], d.cursor_index)
end
end
end
end
state: WSF_JSON_OBJECT
-- Return state with data
do
create Result.make
Result.put (data_as_json, "data")
end
feature -- Callback
handle_callback (cname: LIST [STRING_32]; event: STRING_32; event_parameter: detachable ANY)
do
-- Do nothing here
end
feature -- Data
set_data (a_data: like data)
do
data := a_data
state_changes.replace (data_as_json, "data")
end
data_as_json : JSON_ARRAY
local
item: WSF_JSON_OBJECT
do
create Result.make_array
across
data as el
loop
create item.make
if attached {STRING_8} el.item.at(1) as key and attached {DOUBLE}el.item.at(2) as value then
item.put_string (key, "key")
item.put_real (value, "value")
Result.add(item)
end
end
end
data: ARRAY [TUPLE [STRING_8, DOUBLE]]
feature -- Rendering
render: STRING_32
do
Result := render_tag ("Loading ...", "")
end
end