Minor changes

- using http_client library instead of libcurl directly
 - using implicit conversion to JSON_STRING to improve code readability
 - use ARRAYED_LIST instead of LINKED_LIST .. for performance.
 - cosmetic .. but still a lot of feature clauses are missing, comments, assertions ...
This commit is contained in:
2013-09-20 10:27:00 +02:00
parent 1da678f726
commit 48f5cb78d5
22 changed files with 201 additions and 161 deletions

View File

@@ -9,7 +9,7 @@ deferred class
feature -- Update event
set_on_update_agent (f: PROCEDURE [ANY, TUPLE []])
set_on_update_agent (f: PROCEDURE [ANY, TUPLE])
do
on_update_agent := f
end
@@ -17,11 +17,11 @@ feature -- Update event
update
do
if attached on_update_agent as a then
a.call ([])
a.call (Void)
end
end
on_update_agent: detachable PROCEDURE [ANY, TUPLE []]
on_update_agent: detachable PROCEDURE [ANY, TUPLE]
feature --State
@@ -30,27 +30,27 @@ feature --State
do
create Result.make
if attached sort_column as a_sort_column then
Result.put (create {JSON_STRING}.make_json (a_sort_column), create {JSON_STRING}.make_json ("sort_column"))
Result.put (create {JSON_STRING}.make_json (a_sort_column), "sort_column")
else
Result.put (create {JSON_NULL}, create {JSON_STRING}.make_json ("sort_column"))
Result.put (create {JSON_NULL}, "sort_column")
end
Result.put (create {JSON_BOOLEAN}.make_boolean (sort_direction), create {JSON_STRING}.make_json ("sort_direction"))
Result.put (create {JSON_BOOLEAN}.make_boolean (sort_direction), "sort_direction")
end
set_state (new_state: JSON_OBJECT)
do
if attached {JSON_NUMBER} new_state.item (create {JSON_STRING}.make_json ("page")) as new_page then
if attached {JSON_NUMBER} new_state.item ("page") as new_page then
page := new_page.integer_type
end
if attached {JSON_NUMBER} new_state.item (create {JSON_STRING}.make_json ("page_size")) as new_page_size then
if attached {JSON_NUMBER} new_state.item ("page_size") as new_page_size then
page_size := new_page_size.integer_type
end
if attached {JSON_STRING} new_state.item (create {JSON_STRING}.make_json ("sort_column")) as new_sort_column then
sort_column := new_sort_column.unescaped_string_32
elseif attached {JSON_NULL} new_state.item (create {JSON_STRING}.make_json ("sort_column")) as new_sort_column then
sort_column := VOID
if attached {JSON_STRING} new_state.item ("sort_column") as new_sort_column then
sort_column := new_sort_column.unescaped_string_32 -- Implicit Conversion !
elseif attached {JSON_NULL} new_state.item ("sort_column") as new_sort_column then
sort_column := Void
end
if attached {JSON_BOOLEAN} new_state.item (create {JSON_STRING}.make_json ("sort_direction")) as new_sort_direction then
if attached {JSON_BOOLEAN} new_state.item ("sort_direction") as new_sort_direction then
sort_direction := new_sort_direction.item
end
end

View File

@@ -1,15 +1,15 @@
note
description: "Summary description for {WSF_ENTITY}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_ENTITY
feature
feature -- Access
get (field: STRING): detachable ANY
item (a_field: READABLE_STRING_GENERAL): detachable ANY
-- Value for field item `a_field'.
deferred
end

View File

@@ -8,11 +8,11 @@ class
WSF_GRID_COLUMN
create
make_column
make
feature {NONE}
make_column (a_header, a_field: STRING)
make (a_header, a_field: STRING)
do
header := a_header
field_name := a_field
@@ -31,7 +31,7 @@ feature
render_column (e: WSF_ENTITY): STRING
do
if attached e.get (field_name) as data then
if attached e.item (field_name) as data then
Result := data.out
else
Result := "[VOID]"

View File

@@ -10,16 +10,18 @@ class
inherit
WSF_GRID_COLUMN
rename
make as make_column
redefine
render_column
end
create
make_image_column
make
feature {NONE}
make_image_column (a_header, a_field: STRING)
make (a_header, a_field: STRING)
do
make_column (a_header, a_field)
end
@@ -28,7 +30,7 @@ feature
render_column (e: WSF_ENTITY): STRING
do
if attached e.get (field_name) as data then
if attached e.item (field_name) as data then
Result := "<img src=%"" + data.out + "%" />"
else
Result := "[VOID]"

View File

@@ -58,7 +58,7 @@ feature
update
do
state_changes.replace (create {JSON_STRING}.make_json (render), create {JSON_STRING}.make_json ("_html"))
state_changes.replace (create {JSON_STRING}.make_json (render), "_html")
end
render: STRING

View File

@@ -34,14 +34,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
update
do
state_changes.replace (create {JSON_STRING}.make_json (render_body), create {JSON_STRING}.make_json ("_body"))
state_changes.replace (datasource.state, create {JSON_STRING}.make_json ("datasource"))
state_changes.replace (create {JSON_STRING}.make_json (render_body), "_body")
state_changes.replace (datasource.state, "datasource")
end
set_state (new_state: JSON_OBJECT)
-- Restore html from json
do
if attached {JSON_OBJECT} new_state.item (create {JSON_STRING}.make_json ("datasource")) as datasource_state then
if attached {JSON_OBJECT} new_state.item ("datasource") as datasource_state then
datasource.set_state (datasource_state)
end
end
@@ -50,7 +50,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
-- Return state which contains the current html and if there is an event handle attached
do
create Result.make
Result.put (datasource.state, create {JSON_STRING}.make_json ("datasource"))
Result.put (datasource.state, "datasource")
end
feature --EVENT HANDLING

View File

@@ -28,7 +28,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
set_state (new_state: JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_BOOLEAN} new_state.item (create {JSON_STRING}.make_json ("checked")) as new_checked then
if attached {JSON_BOOLEAN} new_state.item ("checked") as new_checked then
checked := new_checked.item
end
end
@@ -37,9 +37,9 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
-- Return state which contains the current text and if there is an event handle attached
do
create Result.make
Result.put (create {JSON_BOOLEAN}.make_boolean (checked), create {JSON_STRING}.make_json ("checked"))
Result.put (create {JSON_STRING}.make_json (checked_value), create {JSON_STRING}.make_json ("checked_value"))
Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), create {JSON_STRING}.make_json ("callback_change"))
Result.put (create {JSON_BOOLEAN}.make_boolean (checked), "checked")
Result.put (create {JSON_STRING}.make_json (checked_value), "checked_value")
Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), "callback_change")
end
feature --EVENT HANDLING
@@ -52,9 +52,9 @@ feature --EVENT HANDLING
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
do
if Current.control_name.is_equal (cname) and attached change_event as cevent then
if event.is_equal ("change") then
cevent.call ([])
if Current.control_name.same_string (cname) and attached change_event as cevent then
if event.same_string ("change") then
cevent.call (Void)
end
end
end
@@ -85,6 +85,6 @@ feature
checked_value: STRING
change_event: detachable PROCEDURE [ANY, TUPLE []]
change_event: detachable PROCEDURE [ANY, TUPLE]
end

View File

@@ -32,7 +32,7 @@ feature
value: LIST [STRING]
do
create {LINKED_LIST [STRING]} Result.make
create {ARRAYED_LIST [STRING]} Result.make (0)
across
controls as c
loop

View File

@@ -70,7 +70,7 @@ feature {NONE} -- Initialization
collapse_button.add_control (icon_bar)
collapse_button.add_control (icon_bar)
collapse_button.add_control (icon_bar)
--collapse_button.set_attributes ("data-target=%".navbar-collapse%" data-toggle=%"collapse%" type=%"button%"")
-- collapse_button.set_attributes ("data-target=%".navbar-collapse%" data-toggle=%"collapse%" type=%"button%"")
brand.add_class ("navbar-brand")
brand.set_attributes ("href=%"#%"")
brand.set_content (b)

View File

@@ -17,15 +17,9 @@ create
feature {NONE} -- Initialization
attributes: STRING
content: STRING
make_control (t: STRING)
do
make (t)
attributes := ""
content := ""
make_with_body (t, "", "")
end
make_with_body (t,attr,a_content: STRING)
@@ -35,6 +29,12 @@ feature {NONE} -- Initialization
content := a_content
end
feature -- Access
attributes: STRING
content: STRING
feature -- Rendering
render: STRING

View File

@@ -34,7 +34,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
load_state (new_states: JSON_OBJECT)
-- Select state stored with `control_name` as key
do
if attached {JSON_OBJECT} new_states.item (create {JSON_STRING}.make_json (control_name)) as new_state_obj then
if attached {JSON_OBJECT} new_states.item (control_name) as new_state_obj then
set_state (new_state_obj)
end
end
@@ -47,14 +47,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
read_state (states: JSON_OBJECT)
-- Add a new entry in the `states` JSON object with the `control_name` as key and the `state` as value
do
states.put (state, create {JSON_STRING}.make_json (control_name))
states.put (state, control_name)
end
read_state_changes (states: JSON_OBJECT)
-- Add a new entry in the `states_changes` JSON object with the `control_name` as key and the `state` as value
do
if state_changes.count > 0 then
states.put (state_changes, create {JSON_STRING}.make_json (control_name))
states.put (state_changes, control_name)
end
end
@@ -69,7 +69,7 @@ feature -- Rendering
render_tag (body, attrs: STRING): STRING
do
Result:=render_tag_with_generator_name (generator, body, attrs)
Result := render_tag_with_generator_name (generator, body, attrs)
end
render_tag_with_generator_name (a_generator, body, attrs: STRING): STRING
@@ -87,7 +87,7 @@ feature -- Rendering
Result := render_tag_with_tagname (tag_name, body, l_attributes, css_classes_string)
end
feature --EVENT HANDLING
feature -- EVENT HANDLING
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Method called if any callback received. In this method you can route the callback to the event handler

View File

@@ -24,14 +24,11 @@ create
feature {NONE}
make_form_element (a_label: STRING; c: WSF_VALUE_CONTROL [G])
local
a_validators: LINKED_LIST [WSF_VALIDATOR [G]]
do
create a_validators.make
make_form_element_with_validators (a_label, c, a_validators)
make_form_element_with_validators (a_label, c, create {ARRAYED_LIST [WSF_VALIDATOR [G]]}.make (0))
end
make_form_element_with_validators (a_label: STRING; c: WSF_VALUE_CONTROL [G]; v: LINKED_LIST [WSF_VALIDATOR [G]])
make_form_element_with_validators (a_label: STRING; c: WSF_VALUE_CONTROL [G]; v: LIST [WSF_VALIDATOR [G]])
do
make_control (c.control_name + "_container", "div")
add_class ("form-group")
@@ -87,8 +84,8 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
loop
validator_description.add (v.item.state)
end
Result.put (create {JSON_STRING}.make_json (value_control.control_name), create {JSON_STRING}.make_json ("value_control"))
Result.put (validator_description, create {JSON_STRING}.make_json ("validators"))
Result.put (create {JSON_STRING}.make_json (value_control.control_name), "value_control")
Result.put (validator_description, "validators")
end
feature --EVENT HANDLING
@@ -96,8 +93,8 @@ feature --EVENT HANDLING
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Pass callback to subcontrols
do
if equal (cname, control_name) then
if event.is_equal ("validate") then
if cname.same_string (control_name) then
if event.same_string ("validate") then
validate
end
else
@@ -113,11 +110,11 @@ feature --Implementation
do
body := ""
if not label.is_empty then
body := "<label class=%"col-lg-2 control-label%" for=%"" + value_control.control_name + "%">" + label + "</label>"
body.append ("<label class=%"col-lg-2 control-label%" for=%"" + value_control.control_name + "%">" + label + "</label>")
end
body := body + "<div class=%"col-lg-10%">"
body := body + value_control.render
body := body + "</div>"
body.append ("<div class=%"col-lg-10%">")
body.append (value_control.render)
body.append ("</div>")
Result := render_tag (body, "")
end
@@ -161,7 +158,7 @@ feature
value_control: WSF_VALUE_CONTROL [G]
validators: LINKED_LIST [WSF_VALIDATOR [G]]
validators: LIST [WSF_VALIDATOR [G]]
label: STRING

View File

@@ -52,7 +52,6 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
do
end
read_state (states: JSON_OBJECT)
-- Read states in subcontrols
do
@@ -85,7 +84,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
create Result.make
end
feature --EVENT HANDLING
feature -- EVENT HANDLING
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Pass callback to subcontrols

View File

@@ -7,40 +7,40 @@ note
deferred class
WSF_STATELESS_CONTROL
feature
tag_name: STRING
css_classes: LINKED_LIST [STRING]
--TODO: Maybe improve
feature {NONE}
make (a_tag_name: STRING)
do
tag_name := a_tag_name
create css_classes.make
create css_classes.make (0)
ensure
attached css_classes
end
feature
feature -- Access
tag_name: STRING
css_classes: ARRAYED_LIST [STRING]
--TODO: Maybe improve
feature -- Change
add_class (c: STRING)
do
css_classes.extend (c)
css_classes.force (c)
end
render_tag (body, attrs: STRING): STRING
local
css_classes_string: STRING
do
css_classes_string := ""
create css_classes_string.make_empty
across
css_classes as c
loop
css_classes_string := css_classes_string + " " + c.item
css_classes_string.append (" " + c.item)
end
Result := render_tag_with_tagname (tag_name, body, attrs, css_classes_string)
end
@@ -49,20 +49,28 @@ feature
local
l_attributes: STRING
do
l_attributes := attrs
create l_attributes.make_from_string (attrs)
if not css_classes_string.is_empty then
l_attributes := l_attributes + " class=%"" + css_classes_string + "%""
l_attributes.append (" class=%"")
l_attributes.append (css_classes_string)
l_attributes.append_character ('%"')
end
Result := "<" + tag + " " + l_attributes
if body.is_empty and not tag.is_equal ("textarea") and not tag.is_equal ("span") and not tag.is_equal ("button") and not tag.is_equal ("ul") then
Result := Result + " />"
if
body.is_empty and
not tag.same_string ("textarea") and
not tag.same_string ("span") and
not tag.same_string ("button") and
not tag.same_string ("ul")
then
Result.append (" />")
else
Result := Result + " >" + body + "</" + tag + ">"
Result.append (" >" + body + "</" + tag + ">")
end
end
render: STRING
-- Return html representaion of control
-- Return html representation of control
deferred
end