From 7bf95cd927b7c132a59ffbffaa886564cb5f26a4 Mon Sep 17 00:00:00 2001 From: YNH Webdev Date: Wed, 1 Jan 2014 23:50:12 +0100 Subject: [PATCH] Add serverside file id to file structure --- .../wsf_js_widget/kernel/input/wsf_file.e | 44 +++++++++++++++++ .../kernel/input/wsf_file_control.e | 47 +++++++++---------- .../kernel/input/wsf_pending_file.e | 30 ------------ .../kernel/validator/wsf_filesize_validator.e | 4 +- examples/widgetapp/upload_page.e | 4 +- 5 files changed, 69 insertions(+), 60 deletions(-) create mode 100644 draft/library/wsf_js_widget/kernel/input/wsf_file.e delete mode 100644 draft/library/wsf_js_widget/kernel/input/wsf_pending_file.e diff --git a/draft/library/wsf_js_widget/kernel/input/wsf_file.e b/draft/library/wsf_js_widget/kernel/input/wsf_file.e new file mode 100644 index 00000000..bc4a4a62 --- /dev/null +++ b/draft/library/wsf_js_widget/kernel/input/wsf_file.e @@ -0,0 +1,44 @@ +note + description: "Summary description for {WSF_FILE}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + WSF_FILE + +create + make + +feature {NONE} + + make (a_name, a_type: STRING; a_size: INTEGER; a_id: detachable STRING) + do + name := a_name + type := a_type + size := a_size + id := a_id + end + +feature + + set_id (a_id: detachable STRING) + do + id := a_id + end + +feature --Properties + + name: STRING + -- File name + + type: STRING + -- File mime type + + size: INTEGER + -- File size + + id: detachable STRING + -- Server side file id (e.g. S3 filename) + +end diff --git a/draft/library/wsf_js_widget/kernel/input/wsf_file_control.e b/draft/library/wsf_js_widget/kernel/input/wsf_file_control.e index 8b2f57a5..64e7b2b0 100644 --- a/draft/library/wsf_js_widget/kernel/input/wsf_file_control.e +++ b/draft/library/wsf_js_widget/kernel/input/wsf_file_control.e @@ -9,7 +9,7 @@ class inherit - WSF_VALUE_CONTROL [detachable WSF_PENDING_FILE] + WSF_VALUE_CONTROL [detachable WSF_FILE] rename make as make_value_control end @@ -30,10 +30,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management -- Restore text from json do if attached {JSON_STRING} new_state.item ("file") as new_name and attached {JSON_STRING} new_state.item ("type") as new_type and attached {JSON_NUMBER} new_state.item ("size") as new_size then - create file.make (new_name.unescaped_string_32, new_type.unescaped_string_32, new_size.item.to_integer_32); - end - if attached {JSON_STRING} new_state.item ("upload_file") as f then - upload_file:=f.unescaped_string_32; + create file.make (new_name.unescaped_string_32, new_type.unescaped_string_32, new_size.item.to_integer_32, VOID); end end @@ -42,16 +39,11 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management do create Result.make Result.put_boolean (attached change_event, "callback_change") - end - -feature -- Uploaded Files - - set_uploaded_file (p: detachable STRING) - -- Store link to uploaded file in control state. In order to make it availabe for future callbacks - do - if attached p as a_p then - upload_file := a_p - state_changes.put_string (a_p, "upload_file") + if attached file as f then + Result.put_string (f.name, "file_name") + Result.put_string (f.type, "file_type") + Result.put_integer (f.size, "file_size") + Result.put_string (f.id, "file_id") end end @@ -70,13 +62,19 @@ feature -- Event handling end handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY) + local + a_file: WSF_FILE do if Current.control_name.same_string (cname [1]) then - if attached change_event as cevent and event.same_string ("change") then + if attached change_event as cevent and event.same_string ("change") then cevent.call (Void) - elseif attached upload_function as ufunction and event.same_string ("uploadfile") and attached {ITERABLE[WSF_UPLOADED_FILE]}event_parameter as files then - - set_uploaded_file(ufunction.item ([files])) + elseif attached upload_function as ufunction and event.same_string ("uploadfile") and attached {ITERABLE [WSF_UPLOADED_FILE]} event_parameter as files then + if attached file as f then + a_file := f + else + create a_file.make ("", "", 0, VOID) + end + a_file.set_id (ufunction.item ([files])) end end end @@ -94,7 +92,7 @@ feature -- Upload feature -- Implementation - value: detachable WSF_PENDING_FILE + value: detachable WSF_FILE do Result := file end @@ -106,16 +104,13 @@ feature -- Implementation feature -- Properties - file: detachable WSF_PENDING_FILE + file: detachable WSF_FILE -- Text to be displayed change_event: detachable PROCEDURE [ANY, TUPLE] -- Procedure to be execued on change - upload_function: detachable FUNCTION [ANY, TUPLE[ITERABLE[WSF_UPLOADED_FILE]],detachable STRING] - -- Procedure to be execued on change - - upload_file: detachable STRING - -- Link to uploaded file + upload_function: detachable FUNCTION [ANY, TUPLE [ITERABLE [WSF_UPLOADED_FILE]], detachable STRING] + -- Store uploaded file and return server side file id end diff --git a/draft/library/wsf_js_widget/kernel/input/wsf_pending_file.e b/draft/library/wsf_js_widget/kernel/input/wsf_pending_file.e deleted file mode 100644 index 759d39f3..00000000 --- a/draft/library/wsf_js_widget/kernel/input/wsf_pending_file.e +++ /dev/null @@ -1,30 +0,0 @@ -note - description: "Summary description for {WSF_PENDING_FILE}." - author: "" - date: "$Date$" - revision: "$Revision$" - -class - WSF_PENDING_FILE - -create - make - -feature {NONE} - - make (a_name, a_type: STRING; a_size: INTEGER) - do - name := a_name - type := a_type - size := a_size - end - -feature --Properties - - name: STRING - - type: STRING - - size: INTEGER - -end diff --git a/draft/library/wsf_js_widget/kernel/validator/wsf_filesize_validator.e b/draft/library/wsf_js_widget/kernel/validator/wsf_filesize_validator.e index 517decdf..c0158b41 100644 --- a/draft/library/wsf_js_widget/kernel/validator/wsf_filesize_validator.e +++ b/draft/library/wsf_js_widget/kernel/validator/wsf_filesize_validator.e @@ -9,7 +9,7 @@ class inherit - WSF_VALIDATOR [detachable WSF_PENDING_FILE] + WSF_VALIDATOR [detachable WSF_FILE] rename make as make_validator redefine @@ -30,7 +30,7 @@ feature {NONE} -- Initialization feature -- Implementation - is_valid (input: detachable WSF_PENDING_FILE): BOOLEAN + is_valid (input: detachable WSF_FILE): BOOLEAN do Result := True if attached input as a_input then diff --git a/examples/widgetapp/upload_page.e b/examples/widgetapp/upload_page.e index 56cc594e..b0437cad 100644 --- a/examples/widgetapp/upload_page.e +++ b/examples/widgetapp/upload_page.e @@ -87,9 +87,9 @@ feature -- Properties filebox2: WSF_FILE_CONTROL - n0_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_PENDING_FILE] + n0_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_FILE] - n1_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_PENDING_FILE] + n1_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_FILE] end