From 7a716049818405b50ad77e64e8563c4f82603bbe Mon Sep 17 00:00:00 2001 From: totoro Date: Fri, 12 May 2017 00:24:25 +0900 Subject: [PATCH] csv tools --- database/csv_import_status.anubis | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ database/csv_tools.anubis | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ web/CXM_jquery.anubis | 21 +++++++++++---------- web/jQuery/CXM_jquery_button.anubis | 25 +++++++++++++++++++------ 4 files changed, 188 insertions(+), 16 deletions(-) create mode 100644 database/csv_import_status.anubis create mode 100644 database/csv_tools.anubis diff --git a/database/csv_import_status.anubis b/database/csv_import_status.anubis new file mode 100644 index 0000000..2306a82 --- /dev/null +++ b/database/csv_import_status.anubis @@ -0,0 +1,54 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 09/05/2017 + * Time: 23:01 + * © Calexium + */ + + +public type CSV_Import_Status: + csv_ready, + csv_in_progress, + csv_finished, + csv_paused, + csv_cancelled, + csv_file_not_found, + csv_db_error, + csv_bad_format, // Bad format for input file + csv_error. // Unknown error + +public define String + to_String + ( + CSV_Import_Status status + )= + if status is + { + csv_ready then "READY", + csv_in_progress then "IN_PROGRESS", + csv_finished then "FINISHED", + csv_paused then "PAUSED", + csv_cancelled then "CANCELLED", + csv_file_not_found then "FILE_NOT_FOUND", + csv_db_error then "DB_ERROR", + csv_bad_format then "BAD_FORMAT", + csv_error then "ERROR" + }. + +public define CSV_Import_Status + to_CSV_Import_Status + ( + String status + )= + if status = "READY" then csv_ready else + if status = "IN_PROGRESS" then csv_in_progress else + if status = "FINISHED" then csv_finished else + if status = "PAUSED" then csv_paused else + if status = "CANCELLED" then csv_cancelled else + if status = "FILE_NOT_FOUND" then csv_file_not_found else + if status = "DB_ERROR" then csv_db_error else + if status = "BAD_FORMAT" then csv_bad_format else + if status = "ERROR" then csv_error else + csv_error +. diff --git a/database/csv_tools.anubis b/database/csv_tools.anubis new file mode 100644 index 0000000..40ac4b4 --- /dev/null +++ b/database/csv_tools.anubis @@ -0,0 +1,104 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 06/05/2017 + * Time: 17:33 + * © Calexium + */ + +read tools/basis.anubis +read system/string.anubis +read system/data_io.anubis +read tools/line_reader.anubis + +public define (List(String), Bool, List(Word8)) + csv_split_by_tokens + ( + List(Word8) line, // list of left char to parse in the line + List(Word8) tokens, // list of tokens as separator + List(Word8) current, // current column chars + List(String) so_far, // list of already parsed column + Bool inside_string // flag which indicate we are inside string + ) = + if line is + { + [] then + if length(current) > 0 then + if inside_string then + (reverse(so_far), inside_string, current) + else + (reverse([ implode(reverse(current)) . so_far]), false, []) + else + (reverse(so_far), inside_string, []), + + [ char . t ] then + if char = '\"' then + with double_delimiter = if t is + { + [] then false, + [char2 . t2] then char2 = char + }, + if inside_string then + if double_delimiter then + csv_split_by_tokens(if t is [_ . t2] then t2 else [], tokens, [ char . current ], so_far, inside_string) + else + csv_split_by_tokens(t, tokens, current, so_far, false) // end of string + else + csv_split_by_tokens(t, tokens, current, so_far, true) // start of string + + else if member(tokens, char) & inside_string = false then + csv_split_by_tokens( t, tokens, [], [ trim(implode(reverse(current))) . so_far], false) + + else + csv_split_by_tokens( t, tokens, [ char . current ], so_far, inside_string) + }. + +public define (List(String), Bool, List(Word8)) + csv_split_by_tokens + ( + String line, + List(Word8) tokens, + Bool inside_string + )= + csv_split_by_tokens(explode(line), tokens, [], [], inside_string). + +/** + * Splits a line using token as separator, taking care of '"' as string delimiter. + * So all tokens found between two delimiter will be ignored. + * Return the list of elements and a boolean set to true if the EOL was found inside a string. + */ +public define (List(String), Bool, List(Word8)) + csv_split + ( + String line, + Word8 token, + Bool inside_string + )= + csv_split_by_tokens(explode(line), [token], [], [], inside_string). + +public define Maybe((String, List(String))) + csv_read_line + ( + Data_IO io, + Word8 separator, + Bool inside_string, + String full_line, + List(Word8) current_column, + List(String) so_far + ) = + if (Maybe(String))read_line(io) is + { + failure then + if length(full_line) > 0 then + println("quitting csv_read_line (read_line failure)"); + success((full_line, so_far)) + else + failure, + success(line) then + + if csv_split_by_tokens(explode(line), [separator], current_column, [], inside_string) is (all_values, should_continue, partial) then + if should_continue then + csv_read_line(io, separator, true, full_line + line + "\n", partial, so_far + all_values) + else + success((full_line + line, so_far + all_values)) + }. diff --git a/web/CXM_jquery.anubis b/web/CXM_jquery.anubis index 85dadaa..6bdf2c2 100644 --- a/web/CXM_jquery.anubis +++ b/web/CXM_jquery.anubis @@ -13,12 +13,13 @@ read tools/basis.anubis /* jQuery Actioner type */ public type JQuery_Actioner_type: jqform ( String form), - jqlink ( WEB_Action_Name name), + jqlink ( WEB_Action_Name name, List((String,String)) extra_ops), jqflink ( String link), jqscript( String script) . -public define JQuery_Actioner_type jqlink(String name) = jqlink(action_name(name)). +public define JQuery_Actioner_type jqlink(WEB_Action_Name name) = jqlink(name, []). +public define JQuery_Actioner_type jqlink(String name) = jqlink(action_name(name), []). /* jQuery Actioner */ public type JQuery_Actioner: @@ -74,11 +75,11 @@ public define String if act_type is { jqform(form) then "$('#"+form+"').submit();", - jqlink(control_action) then + jqlink(control_action, extra_ops) then if control_action is { no_action then "", - controller_action(ctrl, action) then "document.location='/?aws_controller="+ctrl+"&aws_action="+action+"';", + controller_action(ctrl, action) then "document.location='/?aws_controller="+ctrl+"&aws_action="+action+format_extra_operands(extra_ops)+"';", action_name(action) then "document.location='/?aws_action="+action+"';", url(url) then "document.location='"+url+"';", } @@ -89,12 +90,12 @@ public define String if act_type is { jqform(form) then "$('#"+form+"').submit();", - jqlink(control_action) then + jqlink(control_action, extra_ops) then if control_action is { no_action then "", - controller_action(ctrl, action) then "document.location='/?aws_controller="+ctrl+"&aws_action="+action+"';", - action_name(action) then "document.location='/?aws_action="+action+"';", + controller_action(ctrl, action) then "document.location='/?aws_controller="+ctrl+"&aws_action="+action+format_extra_operands(extra_ops)+"';", + action_name(action) then "document.location='/?aws_action="+action+format_extra_operands(extra_ops)+"';", url(url) then "document.location='"+url+"';", } jqflink(link) then "document.location='"+link+"';", @@ -104,15 +105,15 @@ public define String if act_type is { jqform(form) then "$('#"+form+"').submit();",//il s'agit d'une soumision d'un formulaire => cela se fait uniquement dans la même fenêtre ! - jqlink(control_action) then + jqlink(control_action, extra_ops) then if control_action is { no_action then "", controller_action(ctrl, action) then - "window.open('aws_controller="+ctrl+"&aws_action="+action+"', '"+window_name+"', '"+jquery_button_get_onclick_action_window_options(window_options, "")+"');", + "window.open('aws_controller="+ctrl+"&aws_action="+action+format_extra_operands(extra_ops)+"', '"+window_name+"', '"+jquery_button_get_onclick_action_window_options(window_options, "")+"');", //"document.location='/?aws_controller="+ctrl+"&aws_action="+action+"';", action_name(action) then - "window.open('"+action+"', '"+window_name+"', '"+jquery_button_get_onclick_action_window_options(window_options, "")+"');", + "window.open('"+action+format_extra_operands(extra_ops)+"', '"+window_name+"', '"+jquery_button_get_onclick_action_window_options(window_options, "")+"');", url(url) then "document.location='"+url+"';", } jqflink(link) then "document.location='"+link+"';", diff --git a/web/jQuery/CXM_jquery_button.anubis b/web/jQuery/CXM_jquery_button.anubis index db5c545..3317af0 100644 --- a/web/jQuery/CXM_jquery_button.anubis +++ b/web/jQuery/CXM_jquery_button.anubis @@ -289,9 +289,16 @@ public define HTML_Partial_Content button_name = uid, _actioner = jQuery_actioner(same, jqscript("CalexiumToolBox.make_confirm_dialog(this, " /*+ to_js_string("/?a=" + url + format_extra_operands(extra_ops))+*/ + to_JS_String(jquery_button_get_onclick_action(actioner)) + ");")), - partial_content([js(js_file("js/cxm/cxm.js")), js_inline(jquery_ready(js_data))],sequence([ - partial(jquery_button(jQuery_button(button, uid, button_name, button_label, _actioner, jq_icon_none, jq_icon_none))) - ])). + partial_content([ + js(js_file("js/cxm/cxm.js")), + css(css_file("css/cxm/cxm_button.css")), + js_inline(jquery_ready(js_data)) + ], + sequence([ + partial(jquery_button(jQuery_button(button, uid, button_name, button_label, _actioner, jq_icon_none, jq_icon_none))) + ]) + ) +. public define HTML_Partial_Content jq_button_confirm @@ -318,9 +325,15 @@ public define HTML_Partial_Content _button_name = uid, _actioner = jQuery_actioner(same, jqscript("CalexiumToolBox.make_confirm_dialog(this, " + to_JS_String(jquery_button_get_onclick_action(actioner)) +");")), - partial_content([js(js_file("js/cxm/cxm.js")), js_inline(jquery_ready(js_data))],sequence([ - partial(jquery_button(jquery_img_button(img_url, button_label, _button_name, _actioner, orientation))) - ])). + partial_content([ + js(js_file("js/cxm/cxm.js")), + js_inline(jquery_ready(js_data)) + ], + sequence([ + partial(jquery_button(jquery_img_button(img_url, button_label, _button_name, _actioner, orientation))) + ]) + ) +. public define HTML_Partial_Content img_submit_button -- libgit2 0.21.4