Add comments to grid controls

This commit is contained in:
YNH Webdev
2013-09-22 14:35:26 +02:00
parent 57dd4ce259
commit f360e8a867
12 changed files with 85 additions and 72 deletions

View File

@@ -7,26 +7,26 @@ note
deferred class deferred class
WSF_DATASOURCE [G -> WSF_ENTITY] WSF_DATASOURCE [G -> WSF_ENTITY]
feature -- Update event feature --Event handling
set_on_update_agent (f: PROCEDURE [ANY, TUPLE]) set_on_update_agent (f: PROCEDURE [ANY, TUPLE])
--Set update listener
do do
on_update_agent := f on_update_agent := f
end end
update update
--Trigger update listener
do do
if attached on_update_agent as a then if attached on_update_agent as a then
a.call (Void) a.call (Void)
end end
end end
on_update_agent: detachable PROCEDURE [ANY, TUPLE] feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
feature --State
state: JSON_OBJECT state: JSON_OBJECT
-- Return state which contains the current html and if there is an event handle attached -- Return state which contains the current sort_column and sort_direction
do do
create Result.make create Result.make
if attached sort_column as a_sort_column then if attached sort_column as a_sort_column then
@@ -38,13 +38,8 @@ feature --State
end end
set_state (new_state: JSON_OBJECT) set_state (new_state: JSON_OBJECT)
-- Restore sort_column and sort_direction from json
do do
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 ("page_size") as new_page_size then
page_size := new_page_size.integer_type
end
if attached {JSON_STRING} new_state.item ("sort_column") as new_sort_column then if attached {JSON_STRING} new_state.item ("sort_column") as new_sort_column then
sort_column := new_sort_column.unescaped_string_32 -- Implicit Conversion ! sort_column := new_sort_column.unescaped_string_32 -- Implicit Conversion !
elseif attached {JSON_NULL} new_state.item ("sort_column") as new_sort_column then elseif attached {JSON_NULL} new_state.item ("sort_column") as new_sort_column then
@@ -55,21 +50,21 @@ feature --State
end end
end end
feature feature -- Change
set_sort_column (a_sort_column: like sort_column) set_sort_column (a_sort_column: like sort_column)
-- Set the column by which the data should be sorted
do do
sort_column := a_sort_column sort_column := a_sort_column
end end
set_sort_direction (a_sort_direction: like sort_direction) set_sort_direction (a_sort_direction: like sort_direction)
-- Set the sorting direction
do do
sort_direction := a_sort_direction sort_direction := a_sort_direction
end end
page: INTEGER feature -- Properties
page_size: INTEGER
sort_column: detachable STRING sort_column: detachable STRING
@@ -79,4 +74,6 @@ feature
deferred deferred
end end
on_update_agent: detachable PROCEDURE [ANY, TUPLE]
end end

View File

@@ -10,7 +10,7 @@ class
create create
make make
feature {NONE} feature {NONE} -- Initialization
make (a_header, a_field: STRING) make (a_header, a_field: STRING)
do do
@@ -19,7 +19,19 @@ feature {NONE}
sorting_name := a_field sorting_name := a_field
end end
feature feature -- Render
render_column (e: WSF_ENTITY): STRING
-- Return the rendered column cell for a specific entity (row)
do
if attached e.item (field_name) as data then
Result := data.out
else
Result := "[VOID]"
end
end
feature -- Properties
header: STRING header: STRING
@@ -29,13 +41,4 @@ feature
field_name: STRING field_name: STRING
render_column (e: WSF_ENTITY): STRING
do
if attached e.item (field_name) as data then
Result := data.out
else
Result := "[VOID]"
end
end
end end

View File

@@ -17,7 +17,7 @@ inherit
create create
make_grid make_grid
feature {NONE} feature {NONE} -- Initialization
make_grid (n: STRING; a_columns: ITERABLE [WSF_GRID_COLUMN]; a_datasource: WSF_DATASOURCE [G]) make_grid (n: STRING; a_columns: ITERABLE [WSF_GRID_COLUMN]; a_datasource: WSF_DATASOURCE [G])
do do
@@ -25,9 +25,10 @@ feature {NONE}
columns := a_columns columns := a_columns
end end
feature -- Implementation feature -- Render
render_item (item: G): STRING render_item (item: G): STRING
-- Render table row
do do
Result := "" Result := ""
across across
@@ -39,6 +40,7 @@ feature -- Implementation
end end
render_header: STRING render_header: STRING
-- Render table header
do do
Result := "" Result := ""
across across
@@ -50,6 +52,7 @@ feature -- Implementation
end end
render: STRING render: STRING
-- Render entre table and subcontrols
local local
table: STRING table: STRING
do do
@@ -58,12 +61,12 @@ feature -- Implementation
across across
controls as c controls as c
loop loop
Result := c.item.render + Result Result.append (c.item.render)
end end
Result := render_tag (table + Result, "") Result := render_tag (table + Result, "")
end end
feature feature -- Properties
columns: ITERABLE [WSF_GRID_COLUMN] columns: ITERABLE [WSF_GRID_COLUMN]

View File

@@ -19,16 +19,17 @@ inherit
create create
make make
feature {NONE} feature {NONE} -- Initialization
make (a_header, a_field: STRING) make (a_header, a_field: STRING)
do do
make_column (a_header, a_field) make_column (a_header, a_field)
end end
feature feature -- Render
render_column (e: WSF_ENTITY): STRING render_column (e: WSF_ENTITY): STRING
-- Return the rendered column image cell for a specific entity (row)
do do
if attached e.item (field_name) as data then if attached e.item (field_name) as data then
Result := "<img src=%"" + data.out + "%" />" Result := "<img src=%"" + data.out + "%" />"

View File

@@ -16,29 +16,27 @@ inherit
update update
end end
feature -- Update event feature --Event handling
set_on_update_page_agent (f: PROCEDURE [ANY, TUPLE]) set_on_update_page_agent (f: PROCEDURE [ANY, TUPLE])
--Set paging update listener
do do
on_update_page_agent := f on_update_page_agent := f
end end
update update
--Trigger update listeners
do do
if attached on_update_agent as a then Precursor
a.call (Void)
end
if attached on_update_page_agent as a then if attached on_update_page_agent as a then
a.call (Void) a.call (Void)
end end
end end
on_update_page_agent: detachable PROCEDURE [ANY, TUPLE] feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
feature --States
state: JSON_OBJECT state: JSON_OBJECT
-- Return state which contains the current html and if there is an event handle attached -- Return state which contains the current page, page_size and row_count
do do
Result := Precursor Result := Precursor
Result.put (create {JSON_NUMBER}.make_integer (page), "page") Result.put (create {JSON_NUMBER}.make_integer (page), "page")
@@ -47,6 +45,7 @@ feature --States
end end
set_state (new_state: JSON_OBJECT) set_state (new_state: JSON_OBJECT)
-- Restore page, page_size and row_count from json
do do
Precursor (new_state) Precursor (new_state)
if attached {JSON_NUMBER} new_state.item ("page") as new_page then if attached {JSON_NUMBER} new_state.item ("page") as new_page then
@@ -60,13 +59,19 @@ feature --States
end end
end end
feature feature -- Change
set_page (p: INTEGER) set_page (p: INTEGER)
do do
page := p.min (page_count).max (1) page := p.min (page_count).max (1)
end end
feature -- Properties
page: INTEGER
page_size: INTEGER
row_count: INTEGER row_count: INTEGER
page_count: INTEGER page_count: INTEGER
@@ -74,4 +79,6 @@ feature
Result := (row_count / page_size).ceiling Result := (row_count / page_size).ceiling
end end
on_update_page_agent: detachable PROCEDURE [ANY, TUPLE]
end end

View File

@@ -24,21 +24,29 @@ feature {NONE}
datasource.set_on_update_page_agent (agent update) datasource.set_on_update_page_agent (agent update)
end end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
state: JSON_OBJECT state: JSON_OBJECT
-- Return state which contains the current html and if there is an event handle attached -- Return empty
do do
create Result.make create Result.make
end end
set_state (new_state: JSON_OBJECT) set_state (new_state: JSON_OBJECT)
-- There is no state to restore states
do do
end end
feature --EVENT HANDLING update
-- Send new renederd control to client on update
do
state_changes.replace (create {JSON_STRING}.make_json (render), "_html")
end
feature --Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING) handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Handle goto/next/prev events
do do
if Current.control_name.same_string (cname) then if Current.control_name.same_string (cname) then
if event.same_string ("next") then if event.same_string ("next") then
@@ -54,14 +62,10 @@ feature --EVENT HANDLING
end end
end end
feature feature -- Render
update
do
state_changes.replace (create {JSON_STRING}.make_json (render), "_html")
end
render: STRING render: STRING
-- Render paging control
local local
paging_start: INTEGER paging_start: INTEGER
paging_end: INTEGER paging_end: INTEGER
@@ -85,7 +89,7 @@ feature
Result := render_tag (Result, "") Result := render_tag (Result, "")
end end
feature feature -- Properties
datasource: WSF_PAGABLE_DATASOURCE [G] datasource: WSF_PAGABLE_DATASOURCE [G]

View File

@@ -13,11 +13,10 @@ inherit
redefine redefine
set_state, set_state,
state, state,
handle_callback,
render render
end end
feature {NONE} feature {NONE} -- Initialization
make_repeater (n: STRING; a_datasource: WSF_DATASOURCE [G]) make_repeater (n: STRING; a_datasource: WSF_DATASOURCE [G])
do do
@@ -30,16 +29,17 @@ feature {NONE}
end end
end end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
update update
-- Send new renederd control to client on update
do do
state_changes.replace (create {JSON_STRING}.make_json (render_body), "_body") state_changes.replace (create {JSON_STRING}.make_json (render_body), "_body")
state_changes.replace (datasource.state, "datasource") state_changes.replace (datasource.state, "datasource")
end end
set_state (new_state: JSON_OBJECT) set_state (new_state: JSON_OBJECT)
-- Restore html from json -- Restore datasource state from json
do do
if attached {JSON_OBJECT} new_state.item ("datasource") as datasource_state then if attached {JSON_OBJECT} new_state.item ("datasource") as datasource_state then
datasource.set_state (datasource_state) datasource.set_state (datasource_state)
@@ -47,26 +47,22 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
end end
state: JSON_OBJECT state: JSON_OBJECT
-- Return state which contains the current html and if there is an event handle attached -- Return state which contains the current datasource state
do do
create Result.make create Result.make
Result.put (datasource.state, "datasource") Result.put (datasource.state, "datasource")
end end
feature --EVENT HANDLING
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING) feature -- Rendering
do
Precursor (cname, event, event_parameter)
end
feature -- Implementation
render_item (item: G): STRING render_item (item: G): STRING
--Render item
deferred deferred
end end
render_body: STRING render_body: STRING
--Render Body
do do
Result := "" Result := ""
across across
@@ -77,6 +73,7 @@ feature -- Implementation
end end
render: STRING render: STRING
--Render repeater inclusive paging if paging is available
local local
content: STRING content: STRING
do do
@@ -91,7 +88,7 @@ feature -- Implementation
Result := render_tag_with_generator_name ("WSF_REPEATER_CONTROL", content + Result, "") Result := render_tag_with_generator_name ("WSF_REPEATER_CONTROL", content + Result, "")
end end
feature feature -- Properties
datasource: WSF_DATASOURCE [G] datasource: WSF_DATASOURCE [G]

View File

@@ -71,7 +71,8 @@ feature -- Change
set_progress (p: INTEGER) set_progress (p: INTEGER)
-- Set current progress value to specified value. Must be between 0 and 100. Must only be called when no progresssource has been set to this progress control -- Set current progress value to specified value. Must be between 0 and 100. Must only be called when no progresssource has been set to this progress control
require require
no_progress_source: not (attached progress_source) and p >= 0 and p <= 100 no_progress_source: not (attached progress_source)
valid_input_value: p >= 0 and p <= 100
do do
progress := p progress := p
state_changes.put (create {JSON_NUMBER}.make_integer (progress), "progress") state_changes.put (create {JSON_NUMBER}.make_integer (progress), "progress")

View File

@@ -41,7 +41,7 @@ feature -- State
Result.put (create {JSON_NUMBER}.make_integer (min), "min") Result.put (create {JSON_NUMBER}.make_integer (min), "min")
end end
feature -- Propertiess feature -- Properties
min: INTEGER min: INTEGER
-- The minimal allowed value -- The minimal allowed value

View File

@@ -31,7 +31,7 @@ feature {NONE} -- Initialization
-- Initialize with specified control name and tag -- Initialize with specified control name and tag
do do
make_control (n, t) make_control (n, t)
controls := create {LINKED_LIST [G]}.make; controls := create {ARRAYED_LIST [G]}.make(5);
end end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
@@ -129,7 +129,7 @@ feature -- Change
feature -- Properties feature -- Properties
controls: LINKED_LIST [G] controls: ARRAYED_LIST [G]
-- List of current controls in this multi control -- List of current controls in this multi control
end end

View File

@@ -20,10 +20,10 @@ feature {NONE} -- Initialization
feature -- Access feature -- Access
request: WSF_REQUEST request: WSF_REQUEST
-- The request -- The http request
response: WSF_RESPONSE response: WSF_RESPONSE
-- The response -- The http response
feature -- Specific implementation feature -- Specific implementation

View File

@@ -26,7 +26,7 @@ feature {NONE} -- Initialization
-- Initialize with specified tag -- Initialize with specified tag
do do
make (t) make (t)
controls := create {LINKED_LIST [WSF_STATELESS_CONTROL]}.make; controls := create {ARRAYED_LIST [WSF_STATELESS_CONTROL]}.make (5);
end end
feature -- Rendering feature -- Rendering
@@ -53,7 +53,7 @@ feature -- Change
feature -- Properties feature -- Properties
controls: LINKED_LIST [WSF_STATELESS_CONTROL] controls: ARRAYED_LIST [WSF_STATELESS_CONTROL]
-- List of controls -- List of controls
end end