From f360e8a8677dec7ca4923f3fb2aaf393d941cfd2 Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Sun, 22 Sep 2013 14:35:26 +0200 Subject: [PATCH] Add comments to grid controls --- .../wsf_js_widget/grid/wsf_datasource.e | 27 +++++++++---------- .../wsf_js_widget/grid/wsf_grid_column.e | 25 +++++++++-------- .../wsf_js_widget/grid/wsf_grid_control.e | 11 +++++--- .../grid/wsf_grid_image_column.e | 5 ++-- .../grid/wsf_pagable_datasource.e | 25 ++++++++++------- .../grid/wsf_pagination_control.e | 24 ++++++++++------- .../wsf_js_widget/grid/wsf_repeater_control.e | 23 +++++++--------- .../progressbar/wsf_progress_control.e | 3 ++- .../validator/wsf_min_validator.e | 2 +- .../webcontrol/wsf_multi_control.e | 4 +-- .../webcontrol/wsf_page_control.e | 4 +-- .../webcontrol/wsf_stateless_multi_control.e | 4 +-- 12 files changed, 85 insertions(+), 72 deletions(-) diff --git a/library/server/wsf_js_widget/grid/wsf_datasource.e b/library/server/wsf_js_widget/grid/wsf_datasource.e index bd8a3c97..7a7a7e4e 100644 --- a/library/server/wsf_js_widget/grid/wsf_datasource.e +++ b/library/server/wsf_js_widget/grid/wsf_datasource.e @@ -7,26 +7,26 @@ note deferred class WSF_DATASOURCE [G -> WSF_ENTITY] -feature -- Update event +feature --Event handling set_on_update_agent (f: PROCEDURE [ANY, TUPLE]) + --Set update listener do on_update_agent := f end update + --Trigger update listener do if attached on_update_agent as a then a.call (Void) end end - on_update_agent: detachable PROCEDURE [ANY, TUPLE] - -feature --State +feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management 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 create Result.make if attached sort_column as a_sort_column then @@ -38,13 +38,8 @@ feature --State end set_state (new_state: JSON_OBJECT) + -- Restore sort_column and sort_direction from json 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 sort_column := new_sort_column.unescaped_string_32 -- Implicit Conversion ! elseif attached {JSON_NULL} new_state.item ("sort_column") as new_sort_column then @@ -55,21 +50,21 @@ feature --State end end -feature +feature -- Change set_sort_column (a_sort_column: like sort_column) + -- Set the column by which the data should be sorted do sort_column := a_sort_column end set_sort_direction (a_sort_direction: like sort_direction) + -- Set the sorting direction do sort_direction := a_sort_direction end - page: INTEGER - - page_size: INTEGER +feature -- Properties sort_column: detachable STRING @@ -79,4 +74,6 @@ feature deferred end + on_update_agent: detachable PROCEDURE [ANY, TUPLE] + end diff --git a/library/server/wsf_js_widget/grid/wsf_grid_column.e b/library/server/wsf_js_widget/grid/wsf_grid_column.e index 95bc8c34..01a4cf6c 100644 --- a/library/server/wsf_js_widget/grid/wsf_grid_column.e +++ b/library/server/wsf_js_widget/grid/wsf_grid_column.e @@ -10,7 +10,7 @@ class create make -feature {NONE} +feature {NONE} -- Initialization make (a_header, a_field: STRING) do @@ -19,7 +19,19 @@ feature {NONE} sorting_name := a_field 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 @@ -29,13 +41,4 @@ feature 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 diff --git a/library/server/wsf_js_widget/grid/wsf_grid_control.e b/library/server/wsf_js_widget/grid/wsf_grid_control.e index 0dd39b37..35a500a2 100644 --- a/library/server/wsf_js_widget/grid/wsf_grid_control.e +++ b/library/server/wsf_js_widget/grid/wsf_grid_control.e @@ -17,7 +17,7 @@ inherit create make_grid -feature {NONE} +feature {NONE} -- Initialization make_grid (n: STRING; a_columns: ITERABLE [WSF_GRID_COLUMN]; a_datasource: WSF_DATASOURCE [G]) do @@ -25,9 +25,10 @@ feature {NONE} columns := a_columns end -feature -- Implementation +feature -- Render render_item (item: G): STRING + -- Render table row do Result := "" across @@ -39,6 +40,7 @@ feature -- Implementation end render_header: STRING + -- Render table header do Result := "" across @@ -50,6 +52,7 @@ feature -- Implementation end render: STRING + -- Render entre table and subcontrols local table: STRING do @@ -58,12 +61,12 @@ feature -- Implementation across controls as c loop - Result := c.item.render + Result + Result.append (c.item.render) end Result := render_tag (table + Result, "") end -feature +feature -- Properties columns: ITERABLE [WSF_GRID_COLUMN] diff --git a/library/server/wsf_js_widget/grid/wsf_grid_image_column.e b/library/server/wsf_js_widget/grid/wsf_grid_image_column.e index a06dd93c..eeefea05 100644 --- a/library/server/wsf_js_widget/grid/wsf_grid_image_column.e +++ b/library/server/wsf_js_widget/grid/wsf_grid_image_column.e @@ -19,16 +19,17 @@ inherit create make -feature {NONE} +feature {NONE} -- Initialization make (a_header, a_field: STRING) do make_column (a_header, a_field) end -feature +feature -- Render render_column (e: WSF_ENTITY): STRING + -- Return the rendered column image cell for a specific entity (row) do if attached e.item (field_name) as data then Result := "" diff --git a/library/server/wsf_js_widget/grid/wsf_pagable_datasource.e b/library/server/wsf_js_widget/grid/wsf_pagable_datasource.e index 463f4917..e6324baf 100644 --- a/library/server/wsf_js_widget/grid/wsf_pagable_datasource.e +++ b/library/server/wsf_js_widget/grid/wsf_pagable_datasource.e @@ -16,29 +16,27 @@ inherit update end -feature -- Update event +feature --Event handling set_on_update_page_agent (f: PROCEDURE [ANY, TUPLE]) + --Set paging update listener do on_update_page_agent := f end update + --Trigger update listeners do - if attached on_update_agent as a then - a.call (Void) - end + Precursor if attached on_update_page_agent as a then a.call (Void) end end - on_update_page_agent: detachable PROCEDURE [ANY, TUPLE] - -feature --States +feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management 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 Result := Precursor Result.put (create {JSON_NUMBER}.make_integer (page), "page") @@ -47,6 +45,7 @@ feature --States end set_state (new_state: JSON_OBJECT) + -- Restore page, page_size and row_count from json do Precursor (new_state) if attached {JSON_NUMBER} new_state.item ("page") as new_page then @@ -60,13 +59,19 @@ feature --States end end -feature +feature -- Change set_page (p: INTEGER) do page := p.min (page_count).max (1) end +feature -- Properties + + page: INTEGER + + page_size: INTEGER + row_count: INTEGER page_count: INTEGER @@ -74,4 +79,6 @@ feature Result := (row_count / page_size).ceiling end + on_update_page_agent: detachable PROCEDURE [ANY, TUPLE] + end diff --git a/library/server/wsf_js_widget/grid/wsf_pagination_control.e b/library/server/wsf_js_widget/grid/wsf_pagination_control.e index 999d51ca..bcb4eb27 100644 --- a/library/server/wsf_js_widget/grid/wsf_pagination_control.e +++ b/library/server/wsf_js_widget/grid/wsf_pagination_control.e @@ -24,21 +24,29 @@ feature {NONE} datasource.set_on_update_page_agent (agent update) end -feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT +feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management state: JSON_OBJECT - -- Return state which contains the current html and if there is an event handle attached + -- Return empty do create Result.make end set_state (new_state: JSON_OBJECT) + -- There is no state to restore states do 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 goto/next/prev events do if Current.control_name.same_string (cname) then if event.same_string ("next") then @@ -54,14 +62,10 @@ feature --EVENT HANDLING end end -feature - - update - do - state_changes.replace (create {JSON_STRING}.make_json (render), "_html") - end +feature -- Render render: STRING + -- Render paging control local paging_start: INTEGER paging_end: INTEGER @@ -85,7 +89,7 @@ feature Result := render_tag (Result, "") end -feature +feature -- Properties datasource: WSF_PAGABLE_DATASOURCE [G] diff --git a/library/server/wsf_js_widget/grid/wsf_repeater_control.e b/library/server/wsf_js_widget/grid/wsf_repeater_control.e index ead2a1dd..7aa6e61f 100644 --- a/library/server/wsf_js_widget/grid/wsf_repeater_control.e +++ b/library/server/wsf_js_widget/grid/wsf_repeater_control.e @@ -13,11 +13,10 @@ inherit redefine set_state, state, - handle_callback, render end -feature {NONE} +feature {NONE} -- Initialization make_repeater (n: STRING; a_datasource: WSF_DATASOURCE [G]) do @@ -30,16 +29,17 @@ feature {NONE} end end -feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT +feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management update + -- Send new renederd control to client on update do 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 + -- Restore datasource state from json do if attached {JSON_OBJECT} new_state.item ("datasource") as datasource_state then datasource.set_state (datasource_state) @@ -47,26 +47,22 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT end 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 create Result.make Result.put (datasource.state, "datasource") end -feature --EVENT HANDLING - handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING) - do - Precursor (cname, event, event_parameter) - end - -feature -- Implementation +feature -- Rendering render_item (item: G): STRING + --Render item deferred end render_body: STRING + --Render Body do Result := "" across @@ -77,6 +73,7 @@ feature -- Implementation end render: STRING + --Render repeater inclusive paging if paging is available local content: STRING do @@ -91,7 +88,7 @@ feature -- Implementation Result := render_tag_with_generator_name ("WSF_REPEATER_CONTROL", content + Result, "") end -feature +feature -- Properties datasource: WSF_DATASOURCE [G] diff --git a/library/server/wsf_js_widget/progressbar/wsf_progress_control.e b/library/server/wsf_js_widget/progressbar/wsf_progress_control.e index 5d0e8e96..51b7c171 100644 --- a/library/server/wsf_js_widget/progressbar/wsf_progress_control.e +++ b/library/server/wsf_js_widget/progressbar/wsf_progress_control.e @@ -71,7 +71,8 @@ feature -- Change 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 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 progress := p state_changes.put (create {JSON_NUMBER}.make_integer (progress), "progress") diff --git a/library/server/wsf_js_widget/validator/wsf_min_validator.e b/library/server/wsf_js_widget/validator/wsf_min_validator.e index 5bdb917e..b93d9c15 100644 --- a/library/server/wsf_js_widget/validator/wsf_min_validator.e +++ b/library/server/wsf_js_widget/validator/wsf_min_validator.e @@ -41,7 +41,7 @@ feature -- State Result.put (create {JSON_NUMBER}.make_integer (min), "min") end -feature -- Propertiess +feature -- Properties min: INTEGER -- The minimal allowed value diff --git a/library/server/wsf_js_widget/webcontrol/wsf_multi_control.e b/library/server/wsf_js_widget/webcontrol/wsf_multi_control.e index 8ade4618..4bcc54c1 100644 --- a/library/server/wsf_js_widget/webcontrol/wsf_multi_control.e +++ b/library/server/wsf_js_widget/webcontrol/wsf_multi_control.e @@ -31,7 +31,7 @@ feature {NONE} -- Initialization -- Initialize with specified control name and tag do make_control (n, t) - controls := create {LINKED_LIST [G]}.make; + controls := create {ARRAYED_LIST [G]}.make(5); end feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management @@ -129,7 +129,7 @@ feature -- Change feature -- Properties - controls: LINKED_LIST [G] + controls: ARRAYED_LIST [G] -- List of current controls in this multi control end diff --git a/library/server/wsf_js_widget/webcontrol/wsf_page_control.e b/library/server/wsf_js_widget/webcontrol/wsf_page_control.e index f5a12f12..b5e10d69 100644 --- a/library/server/wsf_js_widget/webcontrol/wsf_page_control.e +++ b/library/server/wsf_js_widget/webcontrol/wsf_page_control.e @@ -20,10 +20,10 @@ feature {NONE} -- Initialization feature -- Access request: WSF_REQUEST - -- The request + -- The http request response: WSF_RESPONSE - -- The response + -- The http response feature -- Specific implementation diff --git a/library/server/wsf_js_widget/webcontrol/wsf_stateless_multi_control.e b/library/server/wsf_js_widget/webcontrol/wsf_stateless_multi_control.e index 84184895..4fe5a98c 100644 --- a/library/server/wsf_js_widget/webcontrol/wsf_stateless_multi_control.e +++ b/library/server/wsf_js_widget/webcontrol/wsf_stateless_multi_control.e @@ -26,7 +26,7 @@ feature {NONE} -- Initialization -- Initialize with specified tag do make (t) - controls := create {LINKED_LIST [WSF_STATELESS_CONTROL]}.make; + controls := create {ARRAYED_LIST [WSF_STATELESS_CONTROL]}.make (5); end feature -- Rendering @@ -53,7 +53,7 @@ feature -- Change feature -- Properties - controls: LINKED_LIST [WSF_STATELESS_CONTROL] + controls: ARRAYED_LIST [WSF_STATELESS_CONTROL] -- List of controls end