From 48f5cb78d5fbbbc66c93d389b42cb93e752fab3a Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 20 Sep 2013 10:27:00 +0200 Subject: [PATCH] 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 ... --- examples/widgetapp/application.e | 52 ++++++++++++++++++- .../autocompletion/google_autocompletion.e | 36 +++++-------- examples/widgetapp/googlenews/google_news.e | 26 ++++++---- .../googlenews/google_news_datasource.e | 42 ++++++--------- examples/widgetapp/grid_page.e | 3 +- examples/widgetapp/repeater_page.e | 11 ++-- examples/widgetapp/widgetapp.ecf | 17 +++--- .../wsf_html/webcontrol/grid/wsf_datasource.e | 26 +++++----- .../wsf_html/webcontrol/grid/wsf_entity.e | 6 +-- .../webcontrol/grid/wsf_grid_column.e | 6 +-- .../webcontrol/grid/wsf_grid_image_column.e | 8 +-- .../webcontrol/grid/wsf_pagination_control.e | 2 +- .../webcontrol/grid/wsf_repeater_control.e | 8 +-- .../webcontrol/input/wsf_checkbox_control.e | 16 +++--- .../input/wsf_checkbox_list_control.e | 2 +- .../webcontrol/navbar/wsf_navbar_control.e | 2 +- .../wsf_html/webcontrol/wsf_basic_control.e | 14 ++--- .../server/wsf_html/webcontrol/wsf_control.e | 10 ++-- .../webcontrol/wsf_form_element_control.e | 25 ++++----- .../wsf_html/webcontrol/wsf_multi_control.e | 3 +- .../webcontrol/wsf_stateless_control.e | 46 +++++++++------- tests/all-safe.ecf | 1 + 22 files changed, 201 insertions(+), 161 deletions(-) diff --git a/examples/widgetapp/application.e b/examples/widgetapp/application.e index a84e7c74..33253619 100644 --- a/examples/widgetapp/application.e +++ b/examples/widgetapp/application.e @@ -9,12 +9,22 @@ class 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 @@ -24,10 +34,47 @@ feature {NONE} -- Initialization -- Initialize current service. do initialize_router + initialize_filter + Precursor set_service_option ("port", 9090) end -feature {NONE} -- Initialization +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 @@ -35,6 +82,9 @@ feature {NONE} -- Initialization map_agent_uri ("/", agent execute_hello, Void) map_agent_uri ("/grid", agent grid_demo, Void) map_agent_uri ("/repeater", agent repeater_demo, 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 map_agent_uri ("/widget.js", agent load_file("widget.js", ?, ?), Void) map_agent_uri ("/jquery.min.js", agent load_file("jquery.min.js", ?, ?), Void) map_agent_uri ("/typeahead.min.js", agent load_file("typeahead.min.js", ?, ?), Void) diff --git a/examples/widgetapp/autocompletion/google_autocompletion.e b/examples/widgetapp/autocompletion/google_autocompletion.e index 75979911..aa0b96cb 100644 --- a/examples/widgetapp/autocompletion/google_autocompletion.e +++ b/examples/widgetapp/autocompletion/google_autocompletion.e @@ -16,7 +16,7 @@ create feature {NONE} -- Initialization - make () + make do template := "{{=value}}"; end @@ -25,26 +25,24 @@ feature -- Implementation autocompletion (input: STRING): JSON_ARRAY local + cl: LIBCURL_HTTP_CLIENT + sess: HTTP_CLIENT_SESSION + l_json: detachable READABLE_STRING_8 + o: JSON_OBJECT - l_result: INTEGER - l_curl_string: CURL_STRING json_parser: JSON_PARSER query_str: STRING do query_str := input query_str.replace_substring_all (" ", "+") - curl_handle := curl_easy.init + create cl.make + sess := cl.new_session ("http://google.com") + if attached sess.get ("/complete/search?client=chrome&q=" + query_str, Void) as resp and then not resp.error_occurred then + l_json := resp.body + end create Result.make_array - if curl_handle /= default_pointer then - create l_curl_string.make_empty - curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_url, "http://google.com/complete/search?client=chrome&q=" + query_str) - curl_easy.set_write_function (curl_handle) - curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_writedata, l_curl_string.object_id) - l_result := curl_easy.perform (curl_handle) - - -- Always cleanup - curl_easy.cleanup (curl_handle) - create json_parser.make_parser (l_curl_string.out) + if l_json /= Void and then not l_json.is_empty then + create json_parser.make_parser (l_json) if attached {JSON_ARRAY} json_parser.parse_json as data and then attached {JSON_ARRAY} data.i_th (2) as list then across 1 |..| list.count as c @@ -59,14 +57,4 @@ feature -- Implementation end end -feature {NONE} -- Implementation - - curl_easy: CURL_EASY_EXTERNALS - once - create Result - end - - curl_handle: POINTER; - -- cURL handle - end diff --git a/examples/widgetapp/googlenews/google_news.e b/examples/widgetapp/googlenews/google_news.e index 232e9571..59068094 100644 --- a/examples/widgetapp/googlenews/google_news.e +++ b/examples/widgetapp/googlenews/google_news.e @@ -18,18 +18,21 @@ feature {NONE} make_from_json (json: JSON_OBJECT) do - if attached {JSON_STRING} json.item (create {JSON_STRING}.make_json ("title")) as a_title then - title := a_title.unescaped_string_32 + if attached {JSON_STRING} json.item ("title") as l_title then + title := l_title.unescaped_string_32 end - if attached {JSON_STRING} json.item (create {JSON_STRING}.make_json ("content")) as a_content then - content := a_content.unescaped_string_32 + if attached {JSON_STRING} json.item ("content") as l_content then + content := l_content.unescaped_string_32 end - if attached {JSON_OBJECT} json.item (create {JSON_STRING}.make_json ("image")) as img and then attached {JSON_STRING} img.item (create {JSON_STRING}.make_json ("url")) as a_image then - image := a_image.item + if + attached {JSON_OBJECT} json.item ("image") as img and then + attached {JSON_STRING} img.item ("url") as l_image + then + image := l_image.item end end -feature +feature -- Access title: detachable STRING @@ -37,13 +40,14 @@ feature image: detachable STRING - get (field: STRING): detachable ANY + item (a_field: READABLE_STRING_GENERAL): detachable ANY + -- do - if field.is_equal ("title") then + if a_field.same_string ("title") then Result := title - elseif field.is_equal ("content") then + elseif a_field.same_string ("content") then Result := content - elseif field.is_equal ("image") then + elseif a_field.same_string ("image") then Result := image end end diff --git a/examples/widgetapp/googlenews/google_news_datasource.e b/examples/widgetapp/googlenews/google_news_datasource.e index 9a575887..f76c5fe0 100644 --- a/examples/widgetapp/googlenews/google_news_datasource.e +++ b/examples/widgetapp/googlenews/google_news_datasource.e @@ -47,26 +47,28 @@ feature data: ITERABLE [GOOGLE_NEWS] local list: LINKED_LIST [GOOGLE_NEWS] - l_result: INTEGER - l_curl_string: CURL_STRING + l_json: detachable READABLE_STRING_8 json_parser: JSON_PARSER query_str: STRING + cl: LIBCURL_HTTP_CLIENT + sess: HTTP_CLIENT_SESSION do - curl_handle := curl_easy.init create list.make row_count := 0 - if curl_handle /= default_pointer then - create l_curl_string.make_empty - query_str := query.out - query_str.replace_substring_all (" ", "+") - curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_url, "https://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=" + query_str + "&rsz=" + page_size.out + "&start=" + (page_size * (page - 1)).out) - curl_easy.set_write_function (curl_handle) - curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_writedata, l_curl_string.object_id) - l_result := curl_easy.perform (curl_handle) - - -- Always cleanup - curl_easy.cleanup (curl_handle) - create json_parser.make_parser (l_curl_string.out) + query_str := query.out + query_str.replace_substring_all (" ", "+") + create cl.make + sess := cl.new_session ("https://ajax.googleapis.com/ajax/services/search") + sess.set_is_insecure (True) + if sess.is_available then + if attached {HTTP_CLIENT_RESPONSE} sess.get ("/news?v=1.0&q=" + query_str + "&rsz=" + page_size.out + "&start=" + (page_size * (page - 1)).out, Void) as l_response then + if not l_response.error_occurred then + l_json := l_response.body + end + end + end + if l_json /= Void and then not l_json.is_empty then + create json_parser.make_parser (l_json) if attached {JSON_OBJECT} json_parser.parse_json as sp then if attached {JSON_OBJECT} sp.item (create {JSON_STRING}.make_json ("responseData")) as responsedata and then attached {JSON_ARRAY} responsedata.item (create {JSON_STRING}.make_json ("results")) as results then if attached {JSON_OBJECT} responsedata.item (create {JSON_STRING}.make_json ("cursor")) as cursor and then attached {JSON_STRING} cursor.item (create {JSON_STRING}.make_json ("estimatedResultCount")) as count then @@ -94,14 +96,4 @@ feature query: STRING -feature {NONE} -- Implementation - - curl_easy: CURL_EASY_EXTERNALS - once - create Result - end - - curl_handle: POINTER; - -- cURL handle - end diff --git a/examples/widgetapp/grid_page.e b/examples/widgetapp/grid_page.e index 09401298..5b7dc318 100644 --- a/examples/widgetapp/grid_page.e +++ b/examples/widgetapp/grid_page.e @@ -29,7 +29,8 @@ feature search_query.set_change_event (agent change_query) container.add_control (search_query) container.add_control (create {WSF_BASIC_CONTROL}.make_with_body("h2","","Results")) - create grid.make_grid ("mygrid", <>, datasource) + create grid.make_grid ("mygrid", <>, datasource) container.add_control (grid) control := container end diff --git a/examples/widgetapp/repeater_page.e b/examples/widgetapp/repeater_page.e index 705ff149..d76a1592 100644 --- a/examples/widgetapp/repeater_page.e +++ b/examples/widgetapp/repeater_page.e @@ -8,11 +8,10 @@ class REPEATER_PAGE inherit - BASE_PAGE - redefine - initialize_controls - end + redefine + initialize_controls + end create make @@ -22,13 +21,13 @@ feature initialize_controls do Precursor - container.add_control (create {WSF_BASIC_CONTROL}.make_with_body("h1","","Repeater Demo")) + container.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("h1", ""," Repeater Demo")) create datasource.make_news create search_query.make_autocomplete ("query", create {GOOGLE_AUTOCOMPLETION}.make) search_query.add_class ("form-control") search_query.set_change_event (agent change_query) container.add_control (search_query) - container.add_control (create {WSF_BASIC_CONTROL}.make_with_body("h2","","Results")) + container.add_control (create {WSF_BASIC_CONTROL}.make_with_body("h2", "", "Results")) create repeater.make_repeater ("myrepeater", datasource) container.add_control (repeater) end diff --git a/examples/widgetapp/widgetapp.ecf b/examples/widgetapp/widgetapp.ecf index 69cf01a3..7cc3767d 100644 --- a/examples/widgetapp/widgetapp.ecf +++ b/examples/widgetapp/widgetapp.ecf @@ -1,33 +1,32 @@ - + /EIFGENs$ /CVS$ /.svn$ - - + - + - - - + - @@ -35,7 +34,7 @@ - diff --git a/library/server/wsf_html/webcontrol/grid/wsf_datasource.e b/library/server/wsf_html/webcontrol/grid/wsf_datasource.e index 8f19529a..bd8a3c97 100644 --- a/library/server/wsf_html/webcontrol/grid/wsf_datasource.e +++ b/library/server/wsf_html/webcontrol/grid/wsf_datasource.e @@ -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 diff --git a/library/server/wsf_html/webcontrol/grid/wsf_entity.e b/library/server/wsf_html/webcontrol/grid/wsf_entity.e index 5f80caf3..7a28ee3a 100644 --- a/library/server/wsf_html/webcontrol/grid/wsf_entity.e +++ b/library/server/wsf_html/webcontrol/grid/wsf_entity.e @@ -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 diff --git a/library/server/wsf_html/webcontrol/grid/wsf_grid_column.e b/library/server/wsf_html/webcontrol/grid/wsf_grid_column.e index f6a5aeb0..95bc8c34 100644 --- a/library/server/wsf_html/webcontrol/grid/wsf_grid_column.e +++ b/library/server/wsf_html/webcontrol/grid/wsf_grid_column.e @@ -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]" diff --git a/library/server/wsf_html/webcontrol/grid/wsf_grid_image_column.e b/library/server/wsf_html/webcontrol/grid/wsf_grid_image_column.e index d1824013..a06dd93c 100644 --- a/library/server/wsf_html/webcontrol/grid/wsf_grid_image_column.e +++ b/library/server/wsf_html/webcontrol/grid/wsf_grid_image_column.e @@ -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 := "" else Result := "[VOID]" diff --git a/library/server/wsf_html/webcontrol/grid/wsf_pagination_control.e b/library/server/wsf_html/webcontrol/grid/wsf_pagination_control.e index 2024746d..e3390989 100644 --- a/library/server/wsf_html/webcontrol/grid/wsf_pagination_control.e +++ b/library/server/wsf_html/webcontrol/grid/wsf_pagination_control.e @@ -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 diff --git a/library/server/wsf_html/webcontrol/grid/wsf_repeater_control.e b/library/server/wsf_html/webcontrol/grid/wsf_repeater_control.e index e4246dac..ead2a1dd 100644 --- a/library/server/wsf_html/webcontrol/grid/wsf_repeater_control.e +++ b/library/server/wsf_html/webcontrol/grid/wsf_repeater_control.e @@ -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 diff --git a/library/server/wsf_html/webcontrol/input/wsf_checkbox_control.e b/library/server/wsf_html/webcontrol/input/wsf_checkbox_control.e index 38bf4bf4..26381083 100644 --- a/library/server/wsf_html/webcontrol/input/wsf_checkbox_control.e +++ b/library/server/wsf_html/webcontrol/input/wsf_checkbox_control.e @@ -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 diff --git a/library/server/wsf_html/webcontrol/input/wsf_checkbox_list_control.e b/library/server/wsf_html/webcontrol/input/wsf_checkbox_list_control.e index 34b7d36e..023d5b5c 100644 --- a/library/server/wsf_html/webcontrol/input/wsf_checkbox_list_control.e +++ b/library/server/wsf_html/webcontrol/input/wsf_checkbox_list_control.e @@ -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 diff --git a/library/server/wsf_html/webcontrol/navbar/wsf_navbar_control.e b/library/server/wsf_html/webcontrol/navbar/wsf_navbar_control.e index 162b37c4..99345c61 100644 --- a/library/server/wsf_html/webcontrol/navbar/wsf_navbar_control.e +++ b/library/server/wsf_html/webcontrol/navbar/wsf_navbar_control.e @@ -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) diff --git a/library/server/wsf_html/webcontrol/wsf_basic_control.e b/library/server/wsf_html/webcontrol/wsf_basic_control.e index d789b35a..10c4344d 100644 --- a/library/server/wsf_html/webcontrol/wsf_basic_control.e +++ b/library/server/wsf_html/webcontrol/wsf_basic_control.e @@ -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 diff --git a/library/server/wsf_html/webcontrol/wsf_control.e b/library/server/wsf_html/webcontrol/wsf_control.e index 10c8900a..049b838a 100644 --- a/library/server/wsf_html/webcontrol/wsf_control.e +++ b/library/server/wsf_html/webcontrol/wsf_control.e @@ -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 diff --git a/library/server/wsf_html/webcontrol/wsf_form_element_control.e b/library/server/wsf_html/webcontrol/wsf_form_element_control.e index c58f095c..96c15211 100644 --- a/library/server/wsf_html/webcontrol/wsf_form_element_control.e +++ b/library/server/wsf_html/webcontrol/wsf_form_element_control.e @@ -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 := "" + body.append ("") end - body := body + "
" - body := body + value_control.render - body := body + "
" + body.append ("
") + body.append (value_control.render) + body.append ("
") 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 diff --git a/library/server/wsf_html/webcontrol/wsf_multi_control.e b/library/server/wsf_html/webcontrol/wsf_multi_control.e index 5cec2c3c..c11d9948 100644 --- a/library/server/wsf_html/webcontrol/wsf_multi_control.e +++ b/library/server/wsf_html/webcontrol/wsf_multi_control.e @@ -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 diff --git a/library/server/wsf_html/webcontrol/wsf_stateless_control.e b/library/server/wsf_html/webcontrol/wsf_stateless_control.e index 6497f6c8..845946a7 100644 --- a/library/server/wsf_html/webcontrol/wsf_stateless_control.e +++ b/library/server/wsf_html/webcontrol/wsf_stateless_control.e @@ -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 + "" + Result.append (" >" + body + "") end end render: STRING - -- Return html representaion of control + -- Return html representation of control deferred end diff --git a/tests/all-safe.ecf b/tests/all-safe.ecf index cb24fecd..d3016c51 100644 --- a/tests/all-safe.ecf +++ b/tests/all-safe.ecf @@ -56,6 +56,7 @@ +
Compiling as Windows , on other platforms than Windows