Commit 7a716049818405b50ad77e64e8563c4f82603bbe

Authored by totoro
1 parent 2c062356

csv tools

database/csv_import_status.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 09/05/2017
  5 + * Time: 23:01
  6 + * © Calexium
  7 + */
  8 +
  9 +
  10 +public type CSV_Import_Status:
  11 + csv_ready,
  12 + csv_in_progress,
  13 + csv_finished,
  14 + csv_paused,
  15 + csv_cancelled,
  16 + csv_file_not_found,
  17 + csv_db_error,
  18 + csv_bad_format, // Bad format for input file
  19 + csv_error. // Unknown error
  20 +
  21 +public define String
  22 + to_String
  23 + (
  24 + CSV_Import_Status status
  25 + )=
  26 + if status is
  27 + {
  28 + csv_ready then "READY",
  29 + csv_in_progress then "IN_PROGRESS",
  30 + csv_finished then "FINISHED",
  31 + csv_paused then "PAUSED",
  32 + csv_cancelled then "CANCELLED",
  33 + csv_file_not_found then "FILE_NOT_FOUND",
  34 + csv_db_error then "DB_ERROR",
  35 + csv_bad_format then "BAD_FORMAT",
  36 + csv_error then "ERROR"
  37 + }.
  38 +
  39 +public define CSV_Import_Status
  40 + to_CSV_Import_Status
  41 + (
  42 + String status
  43 + )=
  44 + if status = "READY" then csv_ready else
  45 + if status = "IN_PROGRESS" then csv_in_progress else
  46 + if status = "FINISHED" then csv_finished else
  47 + if status = "PAUSED" then csv_paused else
  48 + if status = "CANCELLED" then csv_cancelled else
  49 + if status = "FILE_NOT_FOUND" then csv_file_not_found else
  50 + if status = "DB_ERROR" then csv_db_error else
  51 + if status = "BAD_FORMAT" then csv_bad_format else
  52 + if status = "ERROR" then csv_error else
  53 + csv_error
  54 +.
... ...
database/csv_tools.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 06/05/2017
  5 + * Time: 17:33
  6 + * © Calexium
  7 + */
  8 +
  9 +read tools/basis.anubis
  10 +read system/string.anubis
  11 +read system/data_io.anubis
  12 +read tools/line_reader.anubis
  13 +
  14 +public define (List(String), Bool, List(Word8))
  15 + csv_split_by_tokens
  16 + (
  17 + List(Word8) line, // list of left char to parse in the line
  18 + List(Word8) tokens, // list of tokens as separator
  19 + List(Word8) current, // current column chars
  20 + List(String) so_far, // list of already parsed column
  21 + Bool inside_string // flag which indicate we are inside string
  22 + ) =
  23 + if line is
  24 + {
  25 + [] then
  26 + if length(current) > 0 then
  27 + if inside_string then
  28 + (reverse(so_far), inside_string, current)
  29 + else
  30 + (reverse([ implode(reverse(current)) . so_far]), false, [])
  31 + else
  32 + (reverse(so_far), inside_string, []),
  33 +
  34 + [ char . t ] then
  35 + if char = '\"' then
  36 + with double_delimiter = if t is
  37 + {
  38 + [] then false,
  39 + [char2 . t2] then char2 = char
  40 + },
  41 + if inside_string then
  42 + if double_delimiter then
  43 + csv_split_by_tokens(if t is [_ . t2] then t2 else [], tokens, [ char . current ], so_far, inside_string)
  44 + else
  45 + csv_split_by_tokens(t, tokens, current, so_far, false) // end of string
  46 + else
  47 + csv_split_by_tokens(t, tokens, current, so_far, true) // start of string
  48 +
  49 + else if member(tokens, char) & inside_string = false then
  50 + csv_split_by_tokens( t, tokens, [], [ trim(implode(reverse(current))) . so_far], false)
  51 +
  52 + else
  53 + csv_split_by_tokens( t, tokens, [ char . current ], so_far, inside_string)
  54 + }.
  55 +
  56 +public define (List(String), Bool, List(Word8))
  57 + csv_split_by_tokens
  58 + (
  59 + String line,
  60 + List(Word8) tokens,
  61 + Bool inside_string
  62 + )=
  63 + csv_split_by_tokens(explode(line), tokens, [], [], inside_string).
  64 +
  65 +/**
  66 + * Splits a line using token as separator, taking care of '"' as string delimiter.
  67 + * So all tokens found between two delimiter will be ignored.
  68 + * Return the list of elements and a boolean set to true if the EOL was found inside a string.
  69 + */
  70 +public define (List(String), Bool, List(Word8))
  71 + csv_split
  72 + (
  73 + String line,
  74 + Word8 token,
  75 + Bool inside_string
  76 + )=
  77 + csv_split_by_tokens(explode(line), [token], [], [], inside_string).
  78 +
  79 +public define Maybe((String, List(String)))
  80 + csv_read_line
  81 + (
  82 + Data_IO io,
  83 + Word8 separator,
  84 + Bool inside_string,
  85 + String full_line,
  86 + List(Word8) current_column,
  87 + List(String) so_far
  88 + ) =
  89 + if (Maybe(String))read_line(io) is
  90 + {
  91 + failure then
  92 + if length(full_line) > 0 then
  93 + println("quitting csv_read_line (read_line failure)");
  94 + success((full_line, so_far))
  95 + else
  96 + failure,
  97 + success(line) then
  98 +
  99 + if csv_split_by_tokens(explode(line), [separator], current_column, [], inside_string) is (all_values, should_continue, partial) then
  100 + if should_continue then
  101 + csv_read_line(io, separator, true, full_line + line + "\n", partial, so_far + all_values)
  102 + else
  103 + success((full_line + line, so_far + all_values))
  104 + }.
... ...
web/CXM_jquery.anubis
... ... @@ -13,12 +13,13 @@ read tools/basis.anubis
13 13 /* jQuery Actioner type */
14 14 public type JQuery_Actioner_type:
15 15 jqform ( String form),
16   - jqlink ( WEB_Action_Name name),
  16 + jqlink ( WEB_Action_Name name, List((String,String)) extra_ops),
17 17 jqflink ( String link),
18 18 jqscript( String script)
19 19 .
20 20  
21   -public define JQuery_Actioner_type jqlink(String name) = jqlink(action_name(name)).
  21 +public define JQuery_Actioner_type jqlink(WEB_Action_Name name) = jqlink(name, []).
  22 +public define JQuery_Actioner_type jqlink(String name) = jqlink(action_name(name), []).
22 23  
23 24 /* jQuery Actioner */
24 25 public type JQuery_Actioner:
... ... @@ -74,11 +75,11 @@ public define String
74 75 if act_type is
75 76 {
76 77 jqform(form) then "$('#"+form+"').submit();",
77   - jqlink(control_action) then
  78 + jqlink(control_action, extra_ops) then
78 79 if control_action is
79 80 {
80 81 no_action then "",
81   - controller_action(ctrl, action) then "document.location='/?aws_controller="+ctrl+"&aws_action="+action+"';",
  82 + controller_action(ctrl, action) then "document.location='/?aws_controller="+ctrl+"&aws_action="+action+format_extra_operands(extra_ops)+"';",
82 83 action_name(action) then "document.location='/?aws_action="+action+"';",
83 84 url(url) then "document.location='"+url+"';",
84 85 }
... ... @@ -89,12 +90,12 @@ public define String
89 90 if act_type is
90 91 {
91 92 jqform(form) then "$('#"+form+"').submit();",
92   - jqlink(control_action) then
  93 + jqlink(control_action, extra_ops) then
93 94 if control_action is
94 95 {
95 96 no_action then "",
96   - controller_action(ctrl, action) then "document.location='/?aws_controller="+ctrl+"&aws_action="+action+"';",
97   - action_name(action) then "document.location='/?aws_action="+action+"';",
  97 + controller_action(ctrl, action) then "document.location='/?aws_controller="+ctrl+"&aws_action="+action+format_extra_operands(extra_ops)+"';",
  98 + action_name(action) then "document.location='/?aws_action="+action+format_extra_operands(extra_ops)+"';",
98 99 url(url) then "document.location='"+url+"';",
99 100 }
100 101 jqflink(link) then "document.location='"+link+"';",
... ... @@ -104,15 +105,15 @@ public define String
104 105 if act_type is
105 106 {
106 107 jqform(form) then "$('#"+form+"').submit();",//il s'agit d'une soumision d'un formulaire => cela se fait uniquement dans la même fenêtre !
107   - jqlink(control_action) then
  108 + jqlink(control_action, extra_ops) then
108 109 if control_action is
109 110 {
110 111 no_action then "",
111 112 controller_action(ctrl, action) then
112   - "window.open('aws_controller="+ctrl+"&aws_action="+action+"', '"+window_name+"', '"+jquery_button_get_onclick_action_window_options(window_options, "")+"');",
  113 + "window.open('aws_controller="+ctrl+"&aws_action="+action+format_extra_operands(extra_ops)+"', '"+window_name+"', '"+jquery_button_get_onclick_action_window_options(window_options, "")+"');",
113 114 //"document.location='/?aws_controller="+ctrl+"&aws_action="+action+"';",
114 115 action_name(action) then
115   - "window.open('"+action+"', '"+window_name+"', '"+jquery_button_get_onclick_action_window_options(window_options, "")+"');",
  116 + "window.open('"+action+format_extra_operands(extra_ops)+"', '"+window_name+"', '"+jquery_button_get_onclick_action_window_options(window_options, "")+"');",
116 117 url(url) then "document.location='"+url+"';",
117 118 }
118 119 jqflink(link) then "document.location='"+link+"';",
... ...
web/jQuery/CXM_jquery_button.anubis
... ... @@ -289,9 +289,16 @@ public define HTML_Partial_Content
289 289 button_name = uid,
290 290 _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)) + ");")),
291 291  
292   - partial_content([js(js_file("js/cxm/cxm.js")), js_inline(jquery_ready(js_data))],sequence([
293   - partial(jquery_button(jQuery_button(button, uid, button_name, button_label, _actioner, jq_icon_none, jq_icon_none)))
294   - ])).
  292 + partial_content([
  293 + js(js_file("js/cxm/cxm.js")),
  294 + css(css_file("css/cxm/cxm_button.css")),
  295 + js_inline(jquery_ready(js_data))
  296 + ],
  297 + sequence([
  298 + partial(jquery_button(jQuery_button(button, uid, button_name, button_label, _actioner, jq_icon_none, jq_icon_none)))
  299 + ])
  300 + )
  301 +.
295 302  
296 303 public define HTML_Partial_Content
297 304 jq_button_confirm
... ... @@ -318,9 +325,15 @@ public define HTML_Partial_Content
318 325 _button_name = uid,
319 326 _actioner = jQuery_actioner(same, jqscript("CalexiumToolBox.make_confirm_dialog(this, " + to_JS_String(jquery_button_get_onclick_action(actioner)) +");")),
320 327  
321   - partial_content([js(js_file("js/cxm/cxm.js")), js_inline(jquery_ready(js_data))],sequence([
322   - partial(jquery_button(jquery_img_button(img_url, button_label, _button_name, _actioner, orientation)))
323   - ])).
  328 + partial_content([
  329 + js(js_file("js/cxm/cxm.js")),
  330 + js_inline(jquery_ready(js_data))
  331 + ],
  332 + sequence([
  333 + partial(jquery_button(jquery_img_button(img_url, button_label, _button_name, _actioner, orientation)))
  334 + ])
  335 + )
  336 +.
324 337  
325 338 public define HTML_Partial_Content
326 339 img_submit_button
... ...