Create new JSON_OBJECT

This commit is contained in:
YNH Webdev
2013-09-27 10:57:40 +02:00
parent 113df6efe1
commit b6c082e1fe
21 changed files with 224 additions and 94 deletions

View File

@@ -27,7 +27,7 @@ feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY
-- Implementation
local
o: JSON_OBJECT
o: WSF_JSON_OBJECT
do
create Result.make_array
across
@@ -35,7 +35,7 @@ feature -- Implementation
loop
if c.item.as_lower.has_substring (input.as_lower) then
create o.make
o.put (create {JSON_STRING}.make_json (c.item), "value")
o.put_string (c.item, "value")
Result.add (o)
end
end

View File

@@ -25,19 +25,19 @@ feature --Event handling
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- Return state which contains the current sort_column and sort_direction
do
create Result.make
if attached sort_column as a_sort_column then
Result.put (create {JSON_STRING}.make_json (a_sort_column), "sort_column")
Result.put_string (a_sort_column, "sort_column")
else
Result.put (create {JSON_NULL}, "sort_column")
end
Result.put (create {JSON_BOOLEAN}.make_boolean (sort_direction), "sort_direction")
Result.put_boolean (sort_direction, "sort_direction")
end
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- Restore sort_column and sort_direction from json
do
if attached {JSON_STRING} new_state.item ("sort_column") as new_sort_column then

View File

@@ -35,16 +35,16 @@ feature --Event handling
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- Return state which contains the current page, page_size and row_count
do
Result := Precursor
Result.put (create {JSON_NUMBER}.make_integer (page), "page")
Result.put (create {JSON_NUMBER}.make_integer (page_size), "page_size")
Result.put (create {JSON_NUMBER}.make_integer (row_count), "row_count")
Result.put_integer (page, "page")
Result.put_integer (page_size, "page_size")
Result.put_integer (row_count, "row_count")
end
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- Restore page, page_size and row_count from json
do
Precursor (new_state)

View File

@@ -26,13 +26,13 @@ feature {NONE}
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- Return empty
do
create Result.make
end
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- There is no state to restore states
do
end

View File

@@ -38,15 +38,15 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state_changes.replace (datasource.state, "datasource")
end
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- Restore datasource state from json
do
if attached {JSON_OBJECT} new_state.item ("datasource") as datasource_state then
if attached {WSF_JSON_OBJECT} new_state.item ("datasource") as datasource_state then
datasource.set_state (datasource_state)
end
end
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- Return state which contains the current datasource state
do
create Result.make

View File

@@ -39,10 +39,10 @@ feature {NONE} -- Initialization
feature -- State
state: JSON_OBJECT
state: WSF_JSON_OBJECT
do
Result := Precursor {WSF_INPUT_CONTROL}
Result.put (create {JSON_STRING}.make_json (template), "template")
Result.put_string (template, "template")
end
feature -- Callback

View File

@@ -26,7 +26,7 @@ feature {NONE} -- Initialization
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_BOOLEAN} new_state.item ("checked") as new_checked then
@@ -34,13 +34,13 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
end
end
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- 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), "checked")
Result.put (create {JSON_STRING}.make_json (checked_value), "checked_value")
Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), "callback_change")
Result.put_boolean (checked, "checked")
Result.put_string (checked_value, "checked_value")
Result.put_boolean (attached change_event, "callback_change")
end
feature --Event handling

View File

@@ -26,7 +26,7 @@ feature {NONE} -- Initialization
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_STRING} new_state.item ("text") as new_text then
@@ -34,12 +34,12 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
end
end
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- Return state which contains the current text and if there is an event handle attached
do
create Result.make
Result.put (create {JSON_STRING}.make_json (text), "text")
Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), "callback_change")
Result.put_string (text, "text")
Result.put_boolean (attached change_event, "callback_change")
end
feature --Event handling

View File

@@ -33,17 +33,17 @@ feature {NONE} -- Initialization
feature -- State handling
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
do
if attached {JSON_NUMBER} new_state.item ("progress") as new_progress then
progress := new_progress.item.to_integer
end
end
state: JSON_OBJECT
state: WSF_JSON_OBJECT
do
create Result.make
Result.put (create {JSON_NUMBER}.make_integer (progress_value), "progress")
Result.put_integer (progress_value, "progress")
end
feature -- Event handling
@@ -51,7 +51,7 @@ feature -- Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
do
if cname.same_string (control_name) and event.same_string ("progress_fetch") then
state_changes.put (create {JSON_NUMBER}.make_integer (progress_value), "progress")
state_changes.put_integer (progress_value, "progress")
end
end
@@ -75,7 +75,7 @@ feature -- Change
valid_input_value: p >= 0 and p <= 100
do
progress := p
state_changes.put (create {JSON_NUMBER}.make_integer (progress), "progress")
state_changes.put_integer (progress, "progress")
end
feature -- Implementation

View File

@@ -29,11 +29,11 @@ feature {NONE} -- Initialization
feature -- State handling
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
do
end
state: JSON_OBJECT
state: WSF_JSON_OBJECT
do
create Result.make
end

View File

@@ -35,10 +35,10 @@ feature -- Implementation
feature -- State
state: JSON_OBJECT
state: WSF_JSON_OBJECT
do
Result := Precursor
Result.put (create {JSON_NUMBER}.make_integer (max), "max")
Result.put_integer (max, "max")
end
feature -- Properties

View File

@@ -35,10 +35,10 @@ feature -- Implementation
feature -- State
state: JSON_OBJECT
state: WSF_JSON_OBJECT
do
Result := Precursor
Result.put (create {JSON_NUMBER}.make_integer (min), "min")
Result.put_integer (min, "min")
end
feature -- Properties

View File

@@ -40,12 +40,12 @@ feature -- Implementation
feature -- State
state: JSON_OBJECT
state: WSF_JSON_OBJECT
do
create Result.make
Result.put (create {JSON_STRING}.make_json ("WSF_REGEXP_VALIDATOR"), "name")
Result.put (create {JSON_STRING}.make_json (regexp_string), "expression")
Result.put (create {JSON_STRING}.make_json (error), "error")
Result.put_string ("WSF_REGEXP_VALIDATOR", "name")
Result.put_string (regexp_string, "expression")
Result.put_string (error, "error")
end
feature -- Properties

View File

@@ -17,12 +17,12 @@ feature {NONE} -- Initialization
feature -- Access
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- JSON state of this validator
do
create Result.make
Result.put (create {JSON_STRING}.make_json (generator), "name")
Result.put (create {JSON_STRING}.make_json (error), "error")
Result.put_string (generator, "name")
Result.put_string (error, "error")
end
is_valid (input: G): BOOLEAN

View File

@@ -27,7 +27,7 @@ feature {NONE} -- Initialization
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_STRING} new_state.item ("text") as new_text then
@@ -35,12 +35,12 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
end
end
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- Return state which contains the current text and if there is an event handle attached
do
create Result.make
Result.put (create {JSON_STRING}.make_json (text), "text")
Result.put (create {JSON_BOOLEAN}.make_boolean (attached click_event), "callback_click")
Result.put_string (text, "text")
Result.put_boolean (attached click_event, "callback_click")
end
feature --Event handling

View File

@@ -40,49 +40,49 @@ feature -- Actions
start_modal(url:STRING; title:STRING)
--Start a modal window containg an other or the same page
local
modal:JSON_OBJECT
modal:WSF_JSON_OBJECT
do
create modal.make
modal.put (create {JSON_STRING}.make_json("start_modal"), "type")
modal.put (create {JSON_STRING}.make_json(url), "url")
modal.put (create {JSON_STRING}.make_json(title), "title")
modal.put_string ("start_modal", "type")
modal.put_string (url, "url")
modal.put_string (title, "title")
actions.add (modal)
end
show_alert(mesage:STRING)
--Start a modal window containg an other or the same page
local
modal:JSON_OBJECT
modal:WSF_JSON_OBJECT
do
create modal.make
modal.put (create {JSON_STRING}.make_json("show_alert"), "type")
modal.put (create {JSON_STRING}.make_json(mesage), "message")
modal.put_string ("show_alert", "type")
modal.put_string (mesage, "message")
actions.add (modal)
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
load_state (new_states: JSON_OBJECT)
load_state (new_states: WSF_JSON_OBJECT)
-- Select state stored with `control_name` as key
do
if attached {JSON_OBJECT} new_states.item ("state") as new_state_obj then
if attached {WSF_JSON_OBJECT} new_states.item ("state") as new_state_obj then
set_state (new_state_obj)
end
end
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- Before we process the callback. We restore the state of control.
deferred
end
full_state: JSON_OBJECT
full_state: WSF_JSON_OBJECT
-- Return state of object
do
create Result.make
Result.put (state, "state")
end
read_state_changes (states: JSON_OBJECT)
read_state_changes (states: WSF_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
@@ -102,14 +102,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
end
end
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- Returns the current state of the Control as JSON. This state will be transfered to the client.
deferred
ensure
controls_not_defined: not (attached Result.item ("controls"))
end
state_changes: JSON_OBJECT
state_changes: WSF_JSON_OBJECT
feature -- Rendering

View File

@@ -48,24 +48,24 @@ feature {NONE} -- Initialization
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
load_state (new_states: JSON_OBJECT)
load_state (new_states: WSF_JSON_OBJECT)
-- Pass new_states to subcontrols
do
Precursor (new_states)
if attached {JSON_OBJECT} new_states.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (value_control.control_name) as value_state then
if attached {WSF_JSON_OBJECT} new_states.item ("controls") as ct and then attached {WSF_JSON_OBJECT} ct.item (value_control.control_name) as value_state then
value_control.load_state (value_state)
end
end
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- Set new state
do
value_control.set_state (new_state)
end
full_state: JSON_OBJECT
full_state: WSF_JSON_OBJECT
local
controls_state: JSON_OBJECT
controls_state: WSF_JSON_OBJECT
do
Result := Precursor
create controls_state.make
@@ -73,14 +73,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
Result.put (controls_state, "controls")
end
read_state_changes (states: JSON_OBJECT)
read_state_changes (states: WSF_JSON_OBJECT)
-- Read states_changes in subcontrols
do
Precursor (states)
value_control.read_state_changes (states)
end
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- Read state
local
validator_description: JSON_ARRAY
@@ -92,7 +92,7 @@ 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), "value_control")
Result.put_string (value_control.control_name, "value_control")
Result.put (validator_description, "validators")
end

View File

@@ -25,7 +25,7 @@ feature {NONE} -- Initialization
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- Restore html from json
do
if attached {JSON_STRING} new_state.item ("html") as new_html then
@@ -33,11 +33,11 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
end
end
state: JSON_OBJECT
state: WSF_JSON_OBJECT
-- Return state which contains the current html and if there is an event handle attached
do
create Result.make
Result.put (create {JSON_STRING}.make_json (html), "html")
Result.put_string (html, "html")
end
feature --Event handling
@@ -58,7 +58,7 @@ feature -- Implementation
do
if not t.same_string (html) then
html := t
state_changes.replace (create {JSON_STRING}.make_json (html), "html")
state_changes.replace_with_string (html, "html")
end
end

View File

@@ -0,0 +1,130 @@
note
description: "Summary description for {WSF_JSON_OBJECT}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_JSON_OBJECT
inherit
JSON_OBJECT
create
make
feature
put_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: JSON_STRING
do
create l_value.make_json_from_string_32 (value.as_string_32)
put (l_value, key)
end
put_integer (value: INTEGER_64; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: JSON_NUMBER
do
create l_value.make_integer (value)
put (l_value, key)
end
put_natural (value: NATURAL_64; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: JSON_NUMBER
do
create l_value.make_natural (value)
put (l_value, key)
end
put_real (value: DOUBLE; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: JSON_NUMBER
do
create l_value.make_real (value)
put (l_value, key)
end
put_boolean (value: BOOLEAN; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
require
key_not_present: not has_key (key)
local
l_value: JSON_BOOLEAN
do
create l_value.make_boolean (value)
put (l_value, key)
end
replace_with_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: JSON_STRING
do
create l_value.make_json_from_string_32 (value.as_string_32)
replace (l_value, key)
end
replace_with_integer (value: INTEGER_64; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: JSON_NUMBER
do
create l_value.make_integer (value)
replace (l_value, key)
end
replace_with_with_natural (value: NATURAL_64; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: JSON_NUMBER
do
create l_value.make_natural (value)
replace (l_value, key)
end
replace_with_real (value: DOUBLE; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: JSON_NUMBER
do
create l_value.make_real (value)
replace (l_value, key)
end
replace_with_boolean (value: BOOLEAN; key: JSON_STRING)
-- Assuming there is no item of key `key',
-- insert `value' with `key'.
local
l_value: JSON_BOOLEAN
do
create l_value.make_boolean (value)
replace (l_value, key)
end
end

View File

@@ -36,16 +36,16 @@ feature {NONE} -- Initialization
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
load_state (new_states: JSON_OBJECT)
load_state (new_states: WSF_JSON_OBJECT)
-- Pass new_states to subcontrols
do
Precursor (new_states)
if attached {JSON_OBJECT} new_states.item ("controls") as ct then
if attached {WSF_JSON_OBJECT} new_states.item ("controls") as ct then
across
controls as c
loop
if attached {WSF_CONTROL} c.item as cont then
if attached {JSON_OBJECT} ct.item (cont.control_name) as value_state then
if attached {WSF_JSON_OBJECT} ct.item (cont.control_name) as value_state then
cont.load_state (value_state)
end
end
@@ -53,15 +53,15 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
end
end
set_state (new_state: JSON_OBJECT)
set_state (new_state: WSF_JSON_OBJECT)
-- Before we process the callback. We restore the state of control.
do
end
full_state: JSON_OBJECT
full_state: WSF_JSON_OBJECT
-- Read states in subcontrols
local
controls_state: JSON_OBJECT
controls_state: WSF_JSON_OBJECT
do
Result := Precursor
create controls_state.make
@@ -75,7 +75,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
Result.put (controls_state, "controls")
end
read_state_changes (states: JSON_OBJECT)
read_state_changes (states: WSF_JSON_OBJECT)
-- Read states_changes in subcontrols
do
Precursor (states)
@@ -88,7 +88,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
end
end
state: JSON_OBJECT
state: WSF_JSON_OBJECT
--Read state
do
create Result.make

View File

@@ -60,7 +60,7 @@ feature -- Implementation
event_parameter: detachable STRING
event_control_name: detachable STRING
states: STRING
states_changes: JSON_OBJECT
states_changes: WSF_JSON_OBJECT
json_parser: JSON_PARSER
do
event_control_name := get_parameter ("control_name")
@@ -70,7 +70,7 @@ feature -- Implementation
create states.make_empty
request.read_input_data_into (states)
create json_parser.make_parser (states)
if attached {JSON_OBJECT} json_parser.parse_json as sp then
if attached {WSF_JSON_OBJECT} json_parser.parse_json as sp then
set_state (sp)
end
handle_callback (event_control_name, event, event_parameter)
@@ -126,7 +126,7 @@ feature -- Implementation
end
read_state_changes (states: JSON_OBJECT)
read_state_changes (states: WSF_JSON_OBJECT)
-- Add a new entry in the `states_changes` JSON object with the `control_name` as key and the `state` as value
do
Precursor (states)
@@ -155,24 +155,24 @@ feature -- Event handling
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: JSON_OBJECT
state: WSF_JSON_OBJECT
do
create Result.make
Result.put (create {JSON_STRING}.make_json (control_name), "id")
Result.put (create {JSON_STRING}.make_json (request.path_info), "url")
Result.put (create {JSON_STRING}.make_json (request.query_string), "url_params")
Result.put_string (control_name, "id")
Result.put_string (request.path_info, "url")
Result.put_string (request.query_string, "url_params")
end
set_state (sp: JSON_OBJECT)
set_state (sp: WSF_JSON_OBJECT)
do
if attached {JSON_OBJECT} sp.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (control.control_name) as value_state then
if attached {WSF_JSON_OBJECT} sp.item ("controls") as ct and then attached {WSF_JSON_OBJECT} ct.item (control.control_name) as value_state then
control.load_state (value_state)
end
end
full_state: JSON_OBJECT
full_state: WSF_JSON_OBJECT
local
controls_state: JSON_OBJECT
controls_state: WSF_JSON_OBJECT
do
create Result.make
create controls_state.make