Commit 936e54edd28d6b2a552fb8e663511b461afa4eb0

Authored by totoro
1 parent 059b51a6

revamp generator to handle, JSON, jQgrid and many more improvements

hayamiki_generator.aproj
@@ -525,6 +525,7 @@ @@ -525,6 +525,7 @@
525 <Compile Include="src\generation\create_table.anubis" /> 525 <Compile Include="src\generation\create_table.anubis" />
526 <Compile Include="src\generation\cxm_lib_menu.anubis" /> 526 <Compile Include="src\generation\cxm_lib_menu.anubis" />
527 <Compile Include="src\generation\densaku.anubis" /> 527 <Compile Include="src\generation\densaku.anubis" />
  528 + <Compile Include="src\generation\extractor.anubis" />
528 <Compile Include="src\generation\fields.anubis" /> 529 <Compile Include="src\generation\fields.anubis" />
529 <Compile Include="src\generation\files.anubis" /> 530 <Compile Include="src\generation\files.anubis" />
530 <Compile Include="src\generation\fn_delete.anubis" /> 531 <Compile Include="src\generation\fn_delete.anubis" />
@@ -532,9 +533,13 @@ @@ -532,9 +533,13 @@
532 <Compile Include="src\generation\hk_menu.anubis" /> 533 <Compile Include="src\generation\hk_menu.anubis" />
533 <Compile Include="src\generation\html.anubis" /> 534 <Compile Include="src\generation\html.anubis" />
534 <Compile Include="src\generation\icons.anubis" /> 535 <Compile Include="src\generation\icons.anubis" />
  536 + <Compile Include="src\generation\json.anubis" />
535 <Compile Include="src\generation\model.anubis" /> 537 <Compile Include="src\generation\model.anubis" />
  538 + <Compile Include="src\generation\SQL_get_all.anubis" />
  539 + <Compile Include="src\generation\SQL_get_count.anubis" />
536 <Compile Include="src\generation\types.anubis" /> 540 <Compile Include="src\generation\types.anubis" />
537 <Compile Include="src\generation\vt_edit.anubis" /> 541 <Compile Include="src\generation\vt_edit.anubis" />
  542 + <Compile Include="src\generation\vt_view.anubis" />
538 <Compile Include="src\generation\web_args.anubis" /> 543 <Compile Include="src\generation\web_args.anubis" />
539 <Compile Include="src\main.anubis" /> 544 <Compile Include="src\main.anubis" />
540 <Compile Include="src\model.3.0.0.anubis" /> 545 <Compile Include="src\model.3.0.0.anubis" />
src/generation/SQL_get_all.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 25/03/2017
  5 + * Time: 04:26
  6 + * © Calexium
  7 + */
  8 +
  9 +read hayamiki_lib/types/hayamiki.anubis
  10 +read tools/streams.anubis
  11 +read columns.anubis
  12 +
  13 +public define Maybe(One)
  14 + generate_get_all
  15 + (
  16 + Stream stream,
  17 + HK_Table table
  18 + )=
  19 + since table is hk_table(name, short_name, model, _),
  20 + since model is hk_model(columns, _),
  21 + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
  22 +
  23 + //generate the type of the table that contain all components
  24 + if write_string(stream,
  25 + "\n\n"+
  26 + "public define List("+type_name+")\n"+
  27 + " _get_all_"+name+"\n"+
  28 + " (\n"+
  29 + " One -> SQLite3Row table_cursor,\n"+
  30 + " List("+type_name+") so_far\n"+
  31 + " ) =\n"+
  32 + " if extract_"+name+"(table_cursor) is\n"+
  33 + " {\n"+
  34 + " failure then reverse(so_far),\n"+
  35 + " success(data) then _get_all_"+name+"(table_cursor, [data . so_far])\n"+
  36 + " }.\n"+
  37 + "\n\n"
  38 + //SQL query
  39 +// "public define List("+type_name+")\n"+
  40 +// " get_all_"+name+"\n"+
  41 +// " (\n"+
  42 +// " SQLite3DataBase db,\n"+
  43 +// " )=\n"+
  44 +// " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+";\", [], \"get_all_"+name+"\") is\n"+
  45 +// " {\n"+
  46 +// " error(_) then [],\n"+
  47 +// " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+
  48 +// " }.\n"+
  49 +// "\n\n"
  50 + ) is //end of the function
  51 + {
  52 + failure then println("can't write generate_get_all "+type_name); failure,
  53 + success(_) then success(unique)
  54 + }.
  55 +
  56 +
  57 +public define Maybe(One)
  58 + generate_get_all_with_clause
  59 + (
  60 + Stream stream,
  61 + HK_Table table
  62 + )=
  63 + since table is hk_table(name, short_name, model, _),
  64 + since model is hk_model(columns, _),
  65 + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
  66 +
  67 + //generate the type of the table that contain all components
  68 + if write_string(stream,
  69 + //SQL query
  70 + "public define Maybe(One -> SQLite3Row)\n"+
  71 + " get_all_"+name+"_by_clause\n"+
  72 + " (\n"+
  73 + " SQLite3DataBase db,\n"+
  74 + " String clause\n"+
  75 + " )=\n"+
  76 + " with final_clause = if clause = \"\" then\n"+
  77 + " \"\"\n"+
  78 + " else\n"+
  79 + " \"WHERE \"+clause,\n"+
  80 + "\n"+
  81 + " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+" \"+final_clause+\";\", [], \"get_all_"+name+"_by_clause\") is\n"+
  82 + " {\n"+
  83 + " error(_) then failure,\n"+
  84 + " ok(_, cursor, _) then success(cursor)\n"+
  85 + " }\n"+
  86 + ".\n"+
  87 + "\n"+
  88 + "public define List("+type_name+")\n"+
  89 + " get_all_"+name+"_by_clause_to_list_type\n"+
  90 + " (\n"+
  91 + " SQLite3DataBase db,\n"+
  92 + " String clause\n"+
  93 + " )=\n"+
  94 + " if get_all_"+name+"_by_clause(db, clause) is\n"+
  95 + " {\n"+
  96 + " failure then [],\n"+
  97 + " success(cursor) then _get_all_"+name+"(cursor, [])\n"+
  98 + " }\n"+
  99 + ".\n"+
  100 + "public define List(JsonValue)\n"+
  101 + " _get_all_"+name+"_to_json\n"+
  102 + " (\n"+
  103 + " SQLite3DataBase db,\n"+
  104 + " One -> SQLite3Row table_cursor,\n"+
  105 + " List(JsonValue) so_far\n"+
  106 + " ) =\n"+
  107 + " if extract_"+name+"_cursor_to_json(db, table_cursor) is\n"+
  108 + " {\n"+
  109 + " failure then reverse(so_far),\n"+
  110 + " success(data) then _get_all_"+name+"_to_json(db, table_cursor, [data . so_far])\n"+
  111 + " }\n"+
  112 + ".\n"+
  113 +"public define JsonMember\n"+
  114 +" get_all_"+name+"_by_clause_to_json\n"+
  115 +" (\n"+
  116 +" SQLite3DataBase db,\n"+
  117 +" String clause\n"+
  118 +" )=\n"+
  119 +" if get_all_"+name+"_by_clause(db, clause) is\n"+
  120 +" {\n"+
  121 +" failure then json_member(\"rows\", json_array([])),\n"+
  122 +" success(cursor) then json_member(\"rows\", json_array(_get_all_"+name+"_to_json(db, cursor, [])))\n"+
  123 +" }\n"+
  124 +".\n"
  125 + ) is //end of the function
  126 + {
  127 + failure then println("can't write generate_get_all "+type_name); failure,
  128 + success(_) then success(unique)
  129 + }
  130 +.
src/generation/SQL_get_count.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 25/03/2017
  5 + * Time: 01:57
  6 + * © Calexium
  7 + */
  8 +
  9 +read hayamiki_lib/types/hayamiki.anubis
  10 +read tools/basis.anubis
  11 +read tools/streams.anubis
  12 +read system/string.anubis
  13 +
  14 +
  15 +public define Maybe(One)
  16 + generate_get_count_by_clause
  17 + (
  18 + Stream stream,
  19 + HK_Table table
  20 + )=
  21 + since table is hk_table(name, short_name, model, _),
  22 + since model is hk_model(columns, _),
  23 + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
  24 +
  25 + //generate the type of the table that contain all components
  26 + if write_string(stream,
  27 + //SQL query
  28 + "public define Int\n"+
  29 + " get_count_"+name+"_by_clause\n"+
  30 + " (\n"+
  31 + " SQLite3DataBase db,\n"+
  32 + " String clause\n"+
  33 + " )=\n"+
  34 + " with final_clause = if clause = \"\" then\n"+
  35 + " \"\"\n"+
  36 + " else\n"+
  37 + " \"WHERE \"+clause,\n"+
  38 + "\n"+
  39 + " if sql_query_timeout(db, \"SELECT COUNT(\\\"id\\\") FROM "+name+" \"+final_clause+\";\", [], \"get_count_"+name+"_by_clause\") is\n"+
  40 + " {\n"+
  41 + " error(_) then 0,\n"+
  42 + " ok(_, cursor, _) then db_get_integer(cursor)\n"+
  43 + " }\n"+
  44 + ".\n\n"
  45 +
  46 + ) is //end of the function
  47 + {
  48 + failure then println("can't write generate_get_all "+type_name); failure,
  49 + success(_) then success(unique)
  50 + }
  51 +.
src/generation/choices_selector.anubis
@@ -29,6 +29,7 @@ define Maybe(One) @@ -29,6 +29,7 @@ define Maybe(One)
29 " get_choices_selector_"+table_name+"_"+column_name+"\n"+ 29 " get_choices_selector_"+table_name+"_"+column_name+"\n"+
30 " (\n"+ 30 " (\n"+
31 " SQLite3DataBase db,\n"+ 31 " SQLite3DataBase db,\n"+
  32 + " String clause\n"+
32 " )=\n"+ 33 " )=\n"+
33 " [\n"+ 34 " [\n"+
34 concat(map((HK_Text_Choice hk_txt_choice) |-> 35 concat(map((HK_Text_Choice hk_txt_choice) |->
@@ -57,6 +58,7 @@ define Maybe(One) @@ -57,6 +58,7 @@ define Maybe(One)
57 " get_choices_selector_"+table_name+"_"+column_name+"\n"+ 58 " get_choices_selector_"+table_name+"_"+column_name+"\n"+
58 " (\n"+ 59 " (\n"+
59 " SQLite3DataBase db,\n"+ 60 " SQLite3DataBase db,\n"+
  61 + " String clause\n"+
60 " )=\n"+ 62 " )=\n"+
61 " [\n"+ 63 " [\n"+
62 concat(map((HK_Int_Choice hk_int_choice) |-> 64 concat(map((HK_Int_Choice hk_int_choice) |->
src/generation/columns.anubis
@@ -74,34 +74,6 @@ public define List(String) @@ -74,34 +74,6 @@ public define List(String)
74 _to_List_String(columns, with_pk, []). 74 _to_List_String(columns, with_pk, []).
75 75
76 76
77 -define List(String)  
78 -/**  
79 - */  
80 - components  
81 - (  
82 - List(HK_Model_Column) columns,  
83 - String cursor_name,  
84 - List(String) so_far,  
85 - Int idx  
86 - )=  
87 - if columns is  
88 - {  
89 - [] then reverse(so_far),  
90 - [h . t ] then  
91 - since h is hk_column(name, col_type, _, _),  
92 - with line = fill(from_DB_cursor(col_type, cursor_name, idx), 35)+ "/* "+name+" */",  
93 - components(t, cursor_name, [line . so_far], idx + 1 )  
94 - }.  
95 -  
96 -public define String  
97 - generate_constructor_from_cursor  
98 - (  
99 - String constructor_name,  
100 - String cursor_name,  
101 - List(HK_Model_Column) columns,  
102 - String indent  
103 - )=  
104 - indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", components(columns, cursor_name, [], 0))+"\n"+indent+")".  
105 77
106 public define String 78 public define String
107 generate_constructor 79 generate_constructor
@@ -316,13 +288,7 @@ public define String @@ -316,13 +288,7 @@ public define String
316 } 288 }
317 }. 289 }.
318 290
319 -public define String  
320 - make_list_view_header  
321 - (  
322 - List(String) list_view,  
323 - String indent  
324 - )=  
325 - indent+join(",\n"+indent, map((String text) |-> "text(\""+to_upper(text)+"\")", list_view)). 291 +
326 292
327 293
328 294
@@ -338,10 +304,8 @@ public define String @@ -338,10 +304,8 @@ public define String
338 ) = 304 ) =
339 since col is hk_column(name, col_type, _, _), 305 since col is hk_column(name, col_type, _, _),
340 if col_type is 306 if col_type is
341 - {  
342 - //anubis(_T) then "constant_byte_array(0,0)", 307 + {
343 p_key then "get_"+general_type_name+"_show_string(db, "+current_type_name+".id)", 308 p_key then "get_"+general_type_name+"_show_string(db, "+current_type_name+".id)",
344 - //binary then "constant_byte_array(0,0)",  
345 boolean_field then "to_String("+current_type_name+"."+name+")", 309 boolean_field then "to_String("+current_type_name+"."+name+")",
346 date_field(attrs) then "to_String("+current_type_name+"."+name+")", 310 date_field(attrs) then "to_String("+current_type_name+"."+name+")",
347 time_field(attrs) then "to_String("+current_type_name+"."+name+")", 311 time_field(attrs) then "to_String("+current_type_name+"."+name+")",
@@ -353,3 +317,5 @@ public define String @@ -353,3 +317,5 @@ public define String
353 password_field(_) then current_type_name+"."+name, 317 password_field(_) then current_type_name+"."+name,
354 text_field(_) then current_type_name+"."+name 318 text_field(_) then current_type_name+"."+name
355 }. 319 }.
  320 +
  321 +
src/generation/extractor.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 25/03/2017
  5 + * Time: 03:18
  6 + * © Calexium
  7 + */
  8 +
  9 +read hayamiki_lib/types/hayamiki.anubis
  10 +read json.anubis
  11 +read tools/streams.anubis
  12 +
  13 +public define String
  14 + from_DB_cursor
  15 + (
  16 + HK_Model_Field t,
  17 + String cursor, //db cursor name
  18 + Int index //current index of the column in the cursor
  19 + ) =
  20 + with cursor_index = "("+cursor+")("+index+")",
  21 + if t is
  22 + {
  23 + p_key then "db_id((Int)db_integer"+cursor_index+")",
  24 + boolean_field then "db_bool"+cursor_index,
  25 + date_field(_) then "db_date(text"+cursor_index+")",
  26 + time_field(_) then "db_time(text"+cursor_index+")",
  27 + datetime_field(_) then "db_datetime(text"+cursor_index+")",
  28 + foreign_key(_,_) then "db_id((Int)db_integer"+cursor_index+")",
  29 + integer_field(_) then "(Int)db_integer"+cursor_index,
  30 + float_field then "db_float"+cursor_index,
  31 + char_field(_,_) then "text"+cursor_index,
  32 + password_field(_) then "text"+cursor_index,
  33 + text_field(_) then "text"+cursor_index
  34 + }.
  35 +
  36 +define List(String)
  37 +/**
  38 + */
  39 + components
  40 + (
  41 + List(HK_Model_Column) columns,
  42 + String cursor_name,
  43 + List(String) so_far,
  44 + Int idx
  45 + )=
  46 + if columns is
  47 + {
  48 + [] then reverse(so_far),
  49 + [h . t ] then
  50 + since h is hk_column(name, col_type, _, _),
  51 + with line = fill(from_DB_cursor(col_type, cursor_name, idx), 35)+ "/* "+name+" */",
  52 + components(t, cursor_name, [line . so_far], idx + 1 )
  53 + }.
  54 +
  55 +public define String
  56 + generate_constructor_from_cursor
  57 + (
  58 + String constructor_name,
  59 + String cursor_name,
  60 + List(HK_Model_Column) columns,
  61 + String indent
  62 + )=
  63 + indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", components(columns, cursor_name, [], 0))+"\n"+indent+")".
  64 +
  65 +
  66 +public define Maybe(One)
  67 + generate_extract_db_cursor_to_mb_type
  68 + (
  69 + Stream stream,
  70 + HK_Table table
  71 + )=
  72 + since table is hk_table(name, short_name, model, display),
  73 + since model is hk_model(columns, _),
  74 + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
  75 +
  76 + //generate the type of the table that contain all components
  77 + if write_string(stream,
  78 + "\n\n"+
  79 + "public define Maybe("+type_name+")\n"+
  80 + " extract_"+name+"\n"+
  81 + " (\n"+
  82 + " One -> SQLite3Row table_cursor\n"+
  83 + " ) =\n"+
  84 + " if table_cursor(unique) is\n"+
  85 + " {\n"+
  86 + " error(sql_error) then println(db_error(sql_error, \"extract_"+name+"\")); failure,\n"+
  87 + " no_more_row then failure,\n"+
  88 + " row(cursor) then\n"+
  89 + " success(\n"+generate_constructor_from_cursor(name, "cursor", columns, " ")+")\n"+ //generate type construction with values got from web arg
  90 + " }.\n") is //end of the function
  91 + {
  92 + failure then println("can't write generate_extract_db_cursor "+type_name); failure,
  93 + success(_) then success(unique)
  94 + }.
  95 + /************* JSON *************/
  96 +
  97 +define List(String)
  98 +/**
  99 + */
  100 + to_json_member
  101 + (
  102 + List(HK_Model_Column) columns,
  103 + String cursor_name,
  104 + List(String) so_far,
  105 + Int idx
  106 + )=
  107 + if columns is
  108 + {
  109 + [] then reverse(so_far),
  110 + [h . t ] then
  111 + since h is hk_column(name, col_type, _, _),
  112 + with line = fill(from_DB_cursor_to_JSON(h, cursor_name, idx), 135)+ "/* "+name+" */",
  113 + to_json_member(t, cursor_name, [line . so_far], idx + 1 )
  114 + }
  115 +.
  116 +
  117 +public define String
  118 + generate_json_object_from_cursor
  119 + (
  120 + String constructor_name,
  121 + String cursor_name,
  122 + List(HK_Model_Column) columns,
  123 + String indent
  124 + )=
  125 + indent+"json_object([\n"+indent+" "+join(",\n"+indent+" ", to_json_member(columns, cursor_name, [], 0))+"\n"+indent+"])".
  126 +
  127 +
  128 +public define Maybe(One)
  129 + generate_extract_db_cursor_to_json
  130 + (
  131 + Stream stream,
  132 + HK_Table table
  133 + )=
  134 + since table is hk_table(name, short_name, model, display),
  135 + since model is hk_model(columns, _),
  136 + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
  137 +
  138 + //generate the type of the table that contain all components
  139 + if write_string(stream,
  140 + "\n\n"+
  141 + "public define Maybe(JsonValue)\n"+
  142 + " extract_"+name+"_cursor_to_json\n"+
  143 + " (\n"+
  144 + " SQLite3DataBase db,\n"+
  145 + " One -> SQLite3Row table_cursor\n"+
  146 + " ) =\n"+
  147 + " if table_cursor(unique) is\n"+
  148 + " {\n"+
  149 + " error(sql_error) then println(db_error(sql_error, \"extract_"+name+"\")); failure,\n"+
  150 + " no_more_row then failure,\n"+
  151 + " row(cursor) then\n"+
  152 + " success("+generate_json_object_from_cursor(name, "cursor", columns, " ")+")\n"+ //generate type construction with values got from web arg
  153 + " }\n.\n"
  154 + ) is //end of the function
  155 + {
  156 + failure then println("can't write generate_extract_db_cursor "+type_name); failure,
  157 + success(_) then success(unique)
  158 + }.
src/generation/fields.anubis
@@ -106,28 +106,7 @@ public define String @@ -106,28 +106,7 @@ public define String
106 106
107 107
108 108
109 -public define String  
110 - from_DB_cursor  
111 - (  
112 - HK_Model_Field t,  
113 - String cursor, //db cursor name  
114 - Int index //current index of the column in the cursor  
115 - ) =  
116 - with cursor_index = "("+cursor+")("+index+")",  
117 - if t is  
118 - {  
119 - p_key then "db_id((Int)db_integer"+cursor_index+")",  
120 - boolean_field then "db_bool"+cursor_index,  
121 - date_field(_) then "db_date(text"+cursor_index+")",  
122 - time_field(_) then "db_time(text"+cursor_index+")",  
123 - datetime_field(_) then "db_datetime(text"+cursor_index+")",  
124 - foreign_key(_,_) then "db_id((Int)db_integer"+cursor_index+")",  
125 - integer_field(_) then "(Int)db_integer"+cursor_index,  
126 - float_field then "db_float"+cursor_index,  
127 - char_field(_,_) then "text"+cursor_index,  
128 - password_field(_) then "text"+cursor_index,  
129 - text_field(_) then "text"+cursor_index  
130 - }. 109 +
131 110
132 public define String 111 public define String
133 to_Bind 112 to_Bind
src/generation/files.anubis
@@ -19,13 +19,17 @@ read tools/ISO-8601.anubis @@ -19,13 +19,17 @@ read tools/ISO-8601.anubis
19 read generation/header.anubis 19 read generation/header.anubis
20 read generation/types.anubis 20 read generation/types.anubis
21 read generation/densaku.anubis 21 read generation/densaku.anubis
  22 +read generation/extractor.anubis
22 read generation/create_table.anubis 23 read generation/create_table.anubis
23 read generation/hk_menu.anubis 24 read generation/hk_menu.anubis
24 read generation/cxm_lib_menu.anubis 25 read generation/cxm_lib_menu.anubis
25 read generation/fn_delete.anubis 26 read generation/fn_delete.anubis
26 read generation/choices_selector.anubis 27 read generation/choices_selector.anubis
27 read generation/vt_edit.anubis 28 read generation/vt_edit.anubis
  29 +read generation/vt_view.anubis
28 read generation/web_args.anubis 30 read generation/web_args.anubis
  31 +read generation/SQL_get_count.anubis
  32 +read generation/SQL_get_all.anubis
29 read check.anubis 33 read check.anubis
30 34
31 define Maybe(One) 35 define Maybe(One)
@@ -59,11 +63,13 @@ define Maybe(One) @@ -59,11 +63,13 @@ define Maybe(One)
59 if generate_get_default(strm, table) is { failure then failure, success(_) then 63 if generate_get_default(strm, table) is { failure then failure, success(_) then
60 if generate_extract_web_arg_to_type(strm, table) is { failure then failure, success(_) then 64 if generate_extract_web_arg_to_type(strm, table) is { failure then failure, success(_) then
61 if generate_extract_web_arg_to_update_field(strm, table) is { failure then failure, success(_) then 65 if generate_extract_web_arg_to_update_field(strm, table) is { failure then failure, success(_) then
62 - if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then 66 + if generate_extract_db_cursor_to_mb_type(strm, table) is { failure then failure, success(_) then
  67 + if generate_extract_db_cursor_to_json(strm, table) is { failure then failure, success(_) then
63 if generate_get_all(strm, table) is { failure then failure, success(_) then 68 if generate_get_all(strm, table) is { failure then failure, success(_) then
64 if generate_get_all_with_clause(strm, table) is { failure then failure, success(_) then 69 if generate_get_all_with_clause(strm, table) is { failure then failure, success(_) then
65 if generate_get_one(strm, table) is { failure then failure, success(_) then 70 if generate_get_one(strm, table) is { failure then failure, success(_) then
66 if generate_get_one_with_clause(strm, table) is { failure then failure, success(_) then 71 if generate_get_one_with_clause(strm, table) is { failure then failure, success(_) then
  72 + if generate_get_count_by_clause(strm, table) is { failure then failure, success(_) then
67 if generate_update(strm, table) is { failure then failure, success(_) then 73 if generate_update(strm, table) is { failure then failure, success(_) then
68 if generate_delete(strm, table) is { failure then failure, success(_) then 74 if generate_delete(strm, table) is { failure then failure, success(_) then
69 if generate_show_string(strm, table) is { failure then failure, success(_) then 75 if generate_show_string(strm, table) is { failure then failure, success(_) then
@@ -71,7 +77,7 @@ define Maybe(One) @@ -71,7 +77,7 @@ define Maybe(One)
71 if generate_choices_selector(strm, table) is { failure then failure, success(_) then 77 if generate_choices_selector(strm, table) is { failure then failure, success(_) then
72 if generate_VT_all_view(strm, table) is { failure then failure, success(_) then 78 if generate_VT_all_view(strm, table) is { failure then failure, success(_) then
73 if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then 79 if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then
74 - success(unique)}}}}}}}}}}}}}}}}}} 80 + success(unique)}}}}}}}}}}}}}}}}}}}}
75 }. 81 }.
76 82
77 define One 83 define One
src/generation/header.anubis
@@ -56,6 +56,7 @@ read calexium_lib/web/CXM_making_a_web_site.anubis @@ -56,6 +56,7 @@ read calexium_lib/web/CXM_making_a_web_site.anubis
56 read calexium_lib/web/CXM_common.anubis 56 read calexium_lib/web/CXM_common.anubis
57 read calexium_lib/web/CXM_web_dump.anubis 57 read calexium_lib/web/CXM_web_dump.anubis
58 read calexium_lib/web/CXM_web_arg_utils.anubis 58 read calexium_lib/web/CXM_web_arg_utils.anubis
  59 +read calexium_lib/web/CXM_json.anubis
59 read calexium_lib/web/widgets/icons_set.anubis 60 read calexium_lib/web/widgets/icons_set.anubis
60 read data_base/sqlite.anubis 61 read data_base/sqlite.anubis
61 read data_base/db_tools.anubis 62 read data_base/db_tools.anubis
src/generation/json.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 25/03/2017
  5 + * Time: 00:54
  6 + * © Calexium
  7 + */
  8 +
  9 +read hayamiki_lib/types/hayamiki.anubis
  10 +read tools/basis.anubis
  11 +read columns.anubis
  12 +
  13 +public define String
  14 +/** to_String return the content of the given model column 'col' in String format.
  15 + *
  16 + */
  17 + to_JSON_String
  18 + (
  19 + HK_Model_Column col, //Model of the column
  20 + String current_type_name, //Instance name of the type i.e. toto (this is instance of Toto_Type below)
  21 + String general_type_name //Type declaration name i.e. Toto_Type
  22 + ) =
  23 + since col is hk_column(name, col_type, _, _),
  24 + if col_type is
  25 + {
  26 + p_key then current_type_name+".id",
  27 + boolean_field then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
  28 + date_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
  29 + time_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
  30 + datetime_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
  31 + foreign_key(app,foreign_table) then "to_JSON_String(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+"))",
  32 + integer_field(_) then current_type_name+"."+name,
  33 + float_field then "float_to_string("+current_type_name+"."+name+",5)",
  34 + char_field(_,_) then "to_JSON_String("+current_type_name+"."+name+")",
  35 + password_field(_) then "to_JSON_String("+current_type_name+"."+name+")",
  36 + text_field(_) then "to_JSON_String("+current_type_name+"."+name+")"
  37 + }
  38 +.
  39 +
  40 +
  41 +
  42 +public define String
  43 +/** to_String return the content of the given model column 'col' in String format.
  44 + *
  45 + */
  46 + to_JSON
  47 + (
  48 + HK_Model_Column col, //Model of the column
  49 + String current_type_name, //Instance name of the type i.e. toto (this is instance of Toto_Type below)
  50 + String general_type_name //Type declaration name i.e. Toto_Type
  51 + ) =
  52 + since col is hk_column(name, col_type, _, _),
  53 + if col_type is
  54 + {
  55 + p_key then "json_member(\""+name+"\", json_int("+current_type_name+".id))",
  56 + boolean_field then "json_member(\""+name+"\", json_bool("+current_type_name+"."+name+"))",
  57 + date_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
  58 + time_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
  59 + datetime_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
  60 + foreign_key(app,foreign_table) then "json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")))",
  61 + integer_field(_) then "json_member(\""+name+"\", json_int("+current_type_name+"."+name+"))",
  62 + float_field then "json_member(\""+name+"\", json_float("+current_type_name+"."+name+",5))",
  63 + char_field(_,_) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
  64 + password_field(_) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
  65 + text_field(_) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))"
  66 + }
  67 +.
  68 +
  69 +public define String
  70 + from_DB_cursor_to_JSON
  71 + (
  72 + HK_Model_Column col, //Model of the column
  73 + String cursor, //db cursor name
  74 + Int index //current index of the column in the cursor
  75 + ) =
  76 + with cursor_index = "("+cursor+")("+index+")",
  77 + since col is hk_column(name, col_type, _, _),
  78 + if col_type is
  79 + {
  80 + p_key then "json_member(\""+name+"\", json_int((Int)db_integer"+cursor_index+"))",
  81 + boolean_field then "json_member(\""+name+"\", json_bool(db_bool"+cursor_index+"))",
  82 + date_field(_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))",
  83 + time_field(_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))",
  84 + datetime_field(_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))",
  85 + foreign_key(app,foreign_table) then "json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, db_id((Int)db_integer"+cursor_index+"))))",
  86 + integer_field(_) then "json_member(\""+name+"\", json_int((Int)db_integer"+cursor_index+"))",
  87 + float_field then "json_member(\""+name+"\", json_float(db_float"+cursor_index+",5))",
  88 + char_field(_,_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))",
  89 + password_field(_) then "json_member(\""+name+"\", json_string(\"******\"))",
  90 + text_field(_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))"
  91 + }
  92 +.
src/generation/types.anubis
@@ -99,115 +99,10 @@ public define Maybe(One) @@ -99,115 +99,10 @@ public define Maybe(One)
99 99
100 100
101 101
102 -public define Maybe(One)  
103 - generate_extract_db_cursor  
104 - (  
105 - Stream stream,  
106 - HK_Table table  
107 - )=  
108 - since table is hk_table(name, short_name, model, display),  
109 - since model is hk_model(columns, _),  
110 - with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.  
111 -  
112 - //generate the type of the table that contain all components  
113 - if write_string(stream,  
114 - "\n\n"+  
115 - "public define Maybe("+type_name+")\n"+  
116 - " extract_"+name+"\n"+  
117 - " (\n"+  
118 - " One -> SQLite3Row table_cursor\n"+  
119 - " ) =\n"+  
120 - " if table_cursor(unique) is\n"+  
121 - " {\n"+  
122 - " error(sql_error) then println(db_error(sql_error, \"extract_"+name+"\")); failure,\n"+  
123 - " no_more_row then failure,\n"+  
124 - " row(cursor) then\n"+  
125 - " success(\n"+generate_constructor_from_cursor(name, "cursor", columns, " ")+")\n"+ //generate type construction with values got from web arg  
126 - " }.\n") is //end of the function  
127 - {  
128 - failure then println("can't write generate_extract_db_cursor "+type_name); failure,  
129 - success(_) then success(unique)  
130 - }.  
131 102
132 103
133 -public define Maybe(One)  
134 - generate_get_all  
135 - (  
136 - Stream stream,  
137 - HK_Table table  
138 - )=  
139 - since table is hk_table(name, short_name, model, _),  
140 - since model is hk_model(columns, _),  
141 - with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.  
142 -  
143 - //generate the type of the table that contain all components  
144 - if write_string(stream,  
145 - "\n\n"+  
146 - "public define List("+type_name+")\n"+  
147 - " _get_all_"+name+"\n"+  
148 - " (\n"+  
149 - " One -> SQLite3Row table_cursor,\n"+  
150 - " List("+type_name+") so_far\n"+  
151 - " ) =\n"+  
152 - " if extract_"+name+"(table_cursor) is\n"+  
153 - " {\n"+  
154 - " failure then reverse(so_far),\n"+  
155 - " success(data) then _get_all_"+name+"(table_cursor, [data . so_far])\n"+  
156 - " }.\n"+  
157 - "\n\n"  
158 - //SQL query  
159 -// "public define List("+type_name+")\n"+  
160 -// " get_all_"+name+"\n"+  
161 -// " (\n"+  
162 -// " SQLite3DataBase db,\n"+  
163 -// " )=\n"+  
164 -// " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+";\", [], \"get_all_"+name+"\") is\n"+  
165 -// " {\n"+  
166 -// " error(_) then [],\n"+  
167 -// " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+  
168 -// " }.\n"+  
169 -// "\n\n"  
170 - ) is //end of the function  
171 - {  
172 - failure then println("can't write generate_get_all "+type_name); failure,  
173 - success(_) then success(unique)  
174 - }.  
175 104
176 -public define Maybe(One)  
177 - generate_get_all_with_clause  
178 - (  
179 - Stream stream,  
180 - HK_Table table  
181 - )=  
182 - since table is hk_table(name, short_name, model, _),  
183 - since model is hk_model(columns, _),  
184 - with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.  
185 -  
186 - //generate the type of the table that contain all components  
187 - if write_string(stream,  
188 - //SQL query  
189 - "public define List("+type_name+")\n"+  
190 - " get_all_"+name+"_by_clause\n"+  
191 - " (\n"+  
192 - " SQLite3DataBase db,\n"+  
193 - " String clause\n"+  
194 - " )=\n"+  
195 - " with final_clause = if clause = \"\" then\n"+  
196 - " \"\"\n"+  
197 - " else\n"+  
198 - " \"WHERE \"+clause,\n"+  
199 - "\n"+  
200 - " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+" \"+final_clause+\";\", [], \"get_all_"+name+"_by_clause\") is\n"+  
201 - " {\n"+  
202 - " error(_) then [],\n"+  
203 - " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+  
204 - " }.\n"  
205 -  
206 - ) is //end of the function  
207 - {  
208 - failure then println("can't write generate_get_all "+type_name); failure,  
209 - success(_) then success(unique)  
210 - }. 105 +
211 106
212 public define Maybe(One) 107 public define Maybe(One)
213 generate_get_one 108 generate_get_one
@@ -284,7 +179,7 @@ public define Maybe(One) @@ -284,7 +179,7 @@ public define Maybe(One)
284 " {\n"+ 179 " {\n"+
285 " error(_) then failure,\n"+ 180 " error(_) then failure,\n"+
286 " ok(_, cursor, _) then extract_"+name+"(cursor)\n"+ 181 " ok(_, cursor, _) then extract_"+name+"(cursor)\n"+
287 - " }.\n" 182 + " }.\n\n"
288 ) is //end of the function 183 ) is //end of the function
289 { 184 {
290 failure then println("can't write generate_get_one_by_clause "+type_name); failure, 185 failure then println("can't write generate_get_one_by_clause "+type_name); failure,
@@ -458,236 +353,10 @@ public define Maybe(One) @@ -458,236 +353,10 @@ public define Maybe(One)
458 " SQLite3DataBase db,\n"+ 353 " SQLite3DataBase db,\n"+
459 " String clause\n"+ 354 " String clause\n"+
460 " )=\n"+ 355 " )=\n"+
461 - " _get_selector_"+name+"(db, get_all_"+name+"_by_clause(db, clause), [])." 356 + " _get_selector_"+name+"(db, get_all_"+name+"_by_clause_to_list_type(db, clause), [])."
462 ) is //end of the function 357 ) is //end of the function
463 { 358 {
464 failure then println("can't write generate_show_string "+type_name); failure, 359 failure then println("can't write generate_show_string "+type_name); failure,
465 success(_) then success(unique) 360 success(_) then success(unique)
466 }. 361 }.
467 -  
468 -public define Maybe(One)  
469 -/* Generate  
470 -  
471 -*/  
472 - generate_VT_view  
473 - (  
474 - Stream stream, //stream file where to write  
475 - HK_Table table, //  
476 - HK_List_View list_view //list view to generate  
477 - )=  
478 - since table is hk_table(table_name, short_name, model, display),  
479 - since model is hk_model( columns, _),  
480 - //since display is db_display(list_view, list_edit),  
481 -  
482 - with type_name = to_upper(table_name, 1), //make the first character to upper case and be an Anubis Type.  
483 - with view_name = if list_view is  
484 - {  
485 - list_view_all then "default",  
486 - list_view(view_name, _, _) then view_name  
487 - },  
488 - with current_list_view = if list_view is  
489 - {  
490 - list_view_all then to_List_String(columns, false),  
491 - list_view(_, cols, _) then cols  
492 - },  
493 - //generate the type of the table that contain all components  
494 - if write_string(stream,  
495 - "\n\n"+  
496 - //SQL query  
497 - "define VT_view\n"+  
498 - " _get_viewable_"+table_name+"_"+view_name+"\n"+  
499 - " (\n"+  
500 - " SQLite3DataBase db,\n"+  
501 - " List("+type_name+") list,\n"+  
502 - " List(VT_view_row) so_far\n"+  
503 - " )=\n"+  
504 - " if list is\n"+  
505 - " {\n"+  
506 - " [] then //last entry, add the header and the reverse the list \n"+  
507 - " with header = vt_view_row_header([\n"+  
508 - // view row header  
509 - make_list_view_header(current_list_view, " ")+"\n"+  
510 - " ]),\n"+  
511 - " vt_view(\""+table_name+"\", \""+view_name+"\", header, reverse(so_far)),\n"+  
512 - " [ h . t ] then\n"+  
513 - " with entry = vt_view_row(to_Int(h.id), [\n"+  
514 - // view row  
515 - make_list_view_row(table, "h", " ", list_view)+"\n"+  
516 - " ]),\n"+  
517 - " _get_viewable_"+table_name+"_"+view_name+"(db, t, [entry . so_far])\n"+  
518 - " }.\n\n"+  
519 - "public define VT_view\n"+  
520 - " get_viewable_"+table_name+"_"+view_name+"\n"+  
521 - " (\n"+  
522 - " SQLite3DataBase db,\n"+  
523 - " String clause\n"+  
524 - " )=\n"+  
525 - " _get_viewable_"+table_name+"_"+view_name+"(db, get_all_"+table_name+"_by_clause(db, clause), []).\n\n"  
526 - ) is //end of the function  
527 - {  
528 - failure then println("can't write generate_VT_view "+type_name); failure,  
529 - success(_) then success(unique)  
530 - }.  
531 -  
532 -public define Maybe(One)  
533 -/* Generate  
534 -  
535 -*/  
536 - _generate_VT_view  
537 - (  
538 - Stream stream, //stream file where to write  
539 - HK_Table table, //  
540 - List(HK_List_View) list_view, //list view to generate  
541 - Bool has_default //set to true if a default view was encountered.  
542 - )=  
543 - if list_view is  
544 - {  
545 - [] then  
546 - //if default view was not generated, we force to generate it  
547 - if has_default = false then  
548 - generate_VT_view(stream, table, list_view_all)  
549 - else  
550 - success(unique),  
551 - [view . t] then  
552 - if generate_VT_view(stream, table, view) is  
553 - {  
554 - failure then failure,  
555 - success(_) then  
556 - with new_has_default = if has_default = true then //already true, no need to go further  
557 - true  
558 - else  
559 - if view is  
560 - {  
561 - list_view_all then true, //list_view_all is default view  
562 - list_view(view_name, _, _) then  
563 - //if not we search for view named 'default'  
564 - if view_name = "default" then true else false  
565 - },  
566 - _generate_VT_view(stream, table, t, new_has_default)  
567 - }  
568 - }.  
569 -  
570 -public define String  
571 -/* Generate  
572 -  
573 -*/  
574 - _generate_get_viewable_if_else  
575 - (  
576 - String table_name, //  
577 - List(HK_List_View) list_view, //list view to generate  
578 - String so_far  
579 - )=  
580 - if list_view is  
581 - {  
582 - [] then  
583 - so_far +  
584 - "\n"+  
585 - " _get_viewable_"+table_name+"_default(db, get_all_"+table_name+"_by_clause(db, clause), [])\n",  
586 - [view . t] then  
587 - with view_name = if view is  
588 - {  
589 - list_view_all then "default",  
590 - list_view(view_name, _, _) then view_name  
591 - },  
592 - _generate_get_viewable_if_else( table_name, t,  
593 - so_far +  
594 - " if view = \""+view_name+"\" then\n"+  
595 - " _get_viewable_"+table_name+"_"+view_name+"(db, get_all_"+table_name+"_by_clause(db, clause), [])\n"+  
596 - " else"  
597 - )  
598 - }.  
599 -  
600 -public define Maybe(One)  
601 -/* Generate  
602 -  
603 -*/  
604 - generate_get_viewable  
605 - (  
606 - Stream stream, //stream file where to write  
607 - HK_Table table, //  
608 - List(HK_List_View) list_view //list view to generate  
609 - )=  
610 - since table is hk_table(table_name, short_name, model, display),  
611 - if write_string(stream,  
612 - "public define VT_view\n"+  
613 - " get_viewable_"+table_name+"\n"+  
614 - " (\n"+  
615 - " SQLite3DataBase db,\n"+  
616 - " String view,\n"+  
617 - " String clause\n"+  
618 - " )=\n"+  
619 - _generate_get_viewable_if_else(table_name, list_view, "")+  
620 - ".\n"  
621 - ) is //end of the function  
622 - {  
623 - failure then println("can't write generate_get_viewable "+table_name); failure,  
624 - success(_) then success(unique)  
625 - }.  
626 -  
627 -public define Maybe(One)  
628 - generate_VT_all_view  
629 - (  
630 - Stream stream,  
631 - HK_Table table  
632 - )=  
633 - since table is hk_table(name, short_name, model, display),  
634 - since model is hk_model( columns, _),  
635 - since display is hk_display(list_view, list_edit),  
636 -  
637 - with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.  
638 - if _generate_VT_view(stream, table, list_view, false) is //list view to generate  
639 - {  
640 - failure then failure,  
641 - success(_) then generate_get_viewable(stream, table, list_view)  
642 - }.  
643 -  
644 -  
645 - public define Maybe(One)  
646 - generate_VT_edit  
647 - (  
648 - Stream stream,  
649 - HK_Table table  
650 - )=  
651 - since table is hk_table(name, short_name, model, display),  
652 - since model is hk_model( columns, _),  
653 - since display is hk_display(list_view, list_edit),  
654 - with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.  
655 -  
656 - //generate the type of the table that contain all components  
657 - if write_string(stream,  
658 - "\n ********** EDITABLE VIEWs ***************\n"+  
659 - //SQL query  
660 - "define VT_edit\n"+  
661 - " _get_editable_"+name+"\n"+  
662 - " (\n"+  
663 - " "+type_name+" "+name+",\n"+  
664 - " SQLite3DataBase db\n"+  
665 - " )=\n"+  
666 - " with edit_entries = (List(VT_edit_entry))\n"+  
667 - " [\n"+  
668 - edit_entries(columns, name, " ", [])+"\n"+  
669 - " ],\n"+  
670 - " vt_edit(\""+name+"\", edit_entries).\n\n"+  
671 -  
672 - "public define VT_edit\n"+  
673 - " get_editable_"+name+"\n"+  
674 - " (\n"+  
675 - " SQLite3DataBase db,\n"+  
676 - " VT_action action\n"+  
677 - " )=\n"+  
678 - " with "+name+" = if action is\n"+  
679 - " {\n"+  
680 - " new_entry then get_default_"+name+"\n"+  
681 - " edit_entry(idx) then\n"+  
682 - " if get_"+name+"(db, idx) is\n"+  
683 - " {\n"+  
684 - " failure then get_default_"+name+",\n"+  
685 - " success(data) then data\n"+  
686 - " }\n"+  
687 - " },\n"+  
688 - " _get_editable_"+name+"("+name+", db).\n\n"  
689 - ) is //end of the function  
690 - {  
691 - failure then println("can't write generate_VT_edit "+type_name); failure,  
692 - success(_) then success(unique)  
693 - }. 362 +
src/generation/vt_edit.anubis
@@ -78,6 +78,7 @@ public define Maybe(One) @@ -78,6 +78,7 @@ public define Maybe(One)
78 " )=\n"+ 78 " )=\n"+
79 " with edit_entries = (List(VT_edit_entry))\n"+ 79 " with edit_entries = (List(VT_edit_entry))\n"+
80 " [\n"+ 80 " [\n"+
  81 + " hidden(\"id\", to_String("+table_name+".id)),\n"+
81 edit_entries(current_edit_view, table_name, " ", [])+"\n"+ 82 edit_entries(current_edit_view, table_name, " ", [])+"\n"+
82 " ],\n"+ 83 " ],\n"+
83 " with fk_view_entries = (List(HK_V_Edit_Tab))\n"+ 84 " with fk_view_entries = (List(HK_V_Edit_Tab))\n"+
src/generation/vt_view.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 21/03/2017
  5 + * Time: 22:00
  6 + * © Calexium
  7 + */
  8 +
  9 +read hayamiki_lib/types/hayamiki.anubis
  10 +read tools/basis.anubis
  11 +read tools/streams.anubis
  12 +read system/string.anubis
  13 +read fields.anubis
  14 +read columns.anubis
  15 +read html.anubis
  16 +read json.anubis
  17 +
  18 +public define String
  19 + make_list_view_json_row
  20 + (
  21 + HK_Table table, //table to format
  22 + String data_name, //name of data
  23 + String indent, //indentation string to use
  24 + List(HK_Model_Column) columns //list view to generate
  25 + )=
  26 + since table is hk_table(table_name, short, model, _), //get name and model of the table
  27 +// since model is hk_model( columns, _), //get all columns of table
  28 +// since display is db_display(views, _), //
  29 + //and the other set with list_view
  30 +// "\"{ "+ join("+\", ", map((HK_Model_Column column) |-> column.name+": \"+to_JSON_String(" + to_String(column, data_name, table_name)+")", columns))+"+\" }\""
  31 + "\"{ id : \"+to_JSON_String(to_String("+data_name+".id))+\", "+
  32 +
  33 + join("+\", ", map((HK_Model_Column column) |-> column.name+": \"+" + to_JSON_String(column, data_name, table_name), columns)) +"+\" }\""
  34 +
  35 + .
  36 +
  37 +define String
  38 + to_VT_view_model
  39 + (
  40 + HK_Model_Column col,
  41 + String type_name
  42 + )=
  43 + since col is hk_column(name, col_type, _, help),
  44 + if col_type is
  45 + {
  46 + p_key then "primary_key",
  47 + boolean_field then "boolean(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
  48 + date_field(attrs) then "date(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
  49 + time_field(attrs) then "time(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
  50 + datetime_field(attrs) then "datetime(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
  51 + foreign_key(app,foreign_table) then "foreign_text(\""+to_upper(name)+"\", \""+name+"\", vt_edit_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")",
  52 + integer_field(choices) then
  53 + if choices is
  54 + {
  55 + no_choice then "integer(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
  56 + int_choices(choices_list) then
  57 + //if choice list is NOT empty we construct the possible choices selector
  58 + if length(choices_list) > 0 then
  59 + "choices_int(\""+to_upper(name)+"\", \""+name+"\", vt_edit_selector(get_choices_selector_"+to_lower(type_name)+"_"+name+"), "+to_Anubis_source(help)+")"
  60 + else
  61 + "integer(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
  62 + }
  63 + float_field then "float(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
  64 +
  65 + //TODO make choices selection if need
  66 + char_field(choices,_) then
  67 + if choices is
  68 + {
  69 + no_choice then "text(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
  70 + text_choices(choices_list) then
  71 + //if choice list is NOT empty we construct the possible choices selector
  72 + if length(choices_list) > 0 then
  73 + "choices_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", vt_edit_selector(get_choices_selector_"+to_lower(type_name)+"_"+name+"), "+to_Anubis_source(help)+")"
  74 + else
  75 + "text(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")"
  76 + }
  77 + password_field(min_size) then "password(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")"
  78 + text_field(txt_attr) then "text_area(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")"
  79 + }.
  80 +
  81 +
  82 +public define String
  83 + make_list_view_model
  84 + (
  85 + List(HK_Model_Column) columns,
  86 + String type_name,
  87 + String indent
  88 + )=
  89 + indent+join(",\n"+indent, map(((HK_Model_Column col) |-> to_VT_view_model(col, type_name)), columns))
  90 +.
  91 +
  92 +public define String
  93 + make_list_view_header
  94 + (
  95 + List(String) list_view,
  96 + String indent
  97 + )=
  98 + indent+join(",\n"+indent, map((String text) |-> "text(\""+to_upper(text)+"\")", list_view)).
  99 +
  100 +public define Maybe(One)
  101 +/* Generate
  102 +
  103 +*/
  104 + generate_VT_view
  105 + (
  106 + Stream stream, //stream file where to write
  107 + HK_Table table, //
  108 + HK_List_View list_view //list view to generate
  109 + )=
  110 + since table is hk_table(table_name, short_name, model, display),
  111 + since model is hk_model( columns, _),
  112 + //since display is db_display(list_view, list_edit),
  113 +
  114 + with type_name = to_upper(table_name, 1), //make the first character to upper case and be an Anubis Type.
  115 + with view_name = if list_view is
  116 + {
  117 + list_view_all then "default",
  118 + list_view(view_name, _, _) then view_name
  119 + },
  120 + with current_list_view = if list_view is
  121 + {
  122 + list_view_all then to_List_String(columns, false),
  123 + list_view(_, cols, _) then cols
  124 + },
  125 + with current_view_models = if list_view is
  126 + {
  127 + list_view_all then columns,
  128 + list_view(v_name, cols, _) then
  129 + if get_HK_Model_Column_list_from_name_list(columns, cols) is
  130 + {
  131 + failure then println("generate_VT_view: can't get all specified columns for table \""+table_name+"\" view name \""+v_name+"\" cols["+join(", ",cols)+"]");[],
  132 + success(got_columns) then got_columns,
  133 + }
  134 + },
  135 + //generate the type of the table that contain all components
  136 + if write_string(stream,
  137 + "\n\n"+
  138 + //SQL query
  139 + "define VT_view\n"+
  140 + " _get_viewable_"+table_name+"_"+view_name+"\n"+
  141 + " =\n"+
  142 + " with header = vt_view_row_header([\n"+
  143 + // view row header
  144 + make_list_view_header(current_list_view, " ")+"\n"+
  145 + " ]),\n"+
  146 + " with model = vt_view_model([\n"+
  147 + //view model
  148 + make_list_view_model(current_view_models, type_name, " ")+"\n"+
  149 + " ]),\n"+
  150 + " vt_view(\n"+
  151 + " \""+table_name+"\", //Name of the database table\n"+
  152 + " \""+view_name+"\", //Name of the view\n"+
  153 + " model,\n"+
  154 + " header,\n"+
  155 +" vt_view_db_calls(\n"+
  156 +" get_count_"+table_name+"_by_clause,\n"+
  157 +" get_all_"+table_name+"_by_clause_to_json\n"+
  158 +//" get_"+xxx+"_rows\n"+
  159 +" )\n"+
  160 +" )\n"+
  161 +".\n\n"
  162 +
  163 +// "public define VT_view\n"+
  164 +// " get_viewable_"+table_name+"_"+view_name+"\n"+
  165 +// " (\n"+
  166 +// " SQLite3DataBase db,\n"+
  167 +// " String clause\n"+
  168 +// " )=\n"+
  169 +// " _get_viewable_"+table_name+"_"+view_name+"(db, get_all_"+table_name+"_by_clause(db, clause), [], [] ).\n\n"
  170 + ) is //end of the function
  171 + {
  172 + failure then println("can't write generate_VT_view "+type_name); failure,
  173 + success(_) then success(unique)
  174 + }.
  175 +
  176 +public define Maybe(One)
  177 +/* Generate
  178 +
  179 +*/
  180 + _generate_VT_view
  181 + (
  182 + Stream stream, //stream file where to write
  183 + HK_Table table, //
  184 + List(HK_List_View) list_view, //list view to generate
  185 + Bool has_default //set to true if a default view was encountered.
  186 + )=
  187 + if list_view is
  188 + {
  189 + [] then
  190 + //if default view was not generated, we force to generate it
  191 + if has_default = false then
  192 + generate_VT_view(stream, table, list_view_all)
  193 + else
  194 + success(unique),
  195 + [view . t] then
  196 + if generate_VT_view(stream, table, view) is
  197 + {
  198 + failure then failure,
  199 + success(_) then
  200 + with new_has_default = if has_default = true then //already true, no need to go further
  201 + true
  202 + else
  203 + if view is
  204 + {
  205 + list_view_all then true, //list_view_all is default view
  206 + list_view(view_name, _, _) then
  207 + //if not we search for view named 'default'
  208 + if view_name = "default" then true else false
  209 + },
  210 + _generate_VT_view(stream, table, t, new_has_default)
  211 + }
  212 + }.
  213 +
  214 +public define String
  215 +/* Generate
  216 +
  217 +*/
  218 + _generate_get_viewable_if_else
  219 + (
  220 + String table_name, //
  221 + List(HK_List_View) list_view, //list view to generate
  222 + String so_far
  223 + )=
  224 + if list_view is
  225 + {
  226 + [] then
  227 + so_far +
  228 + "\n"+
  229 + " _get_viewable_"+table_name+"_default\n",
  230 + [view . t] then
  231 + with view_name = if view is
  232 + {
  233 + list_view_all then "default",
  234 + list_view(view_name, _, _) then view_name
  235 + },
  236 + _generate_get_viewable_if_else( table_name, t,
  237 + so_far +
  238 + " if view = \""+view_name+"\" then\n"+
  239 + " _get_viewable_"+table_name+"_"+view_name+"\n"+
  240 + " else"
  241 + )
  242 + }.
  243 +
  244 +public define Maybe(One)
  245 +/* Generate
  246 +
  247 +*/
  248 + generate_get_viewable
  249 + (
  250 + Stream stream, //stream file where to write
  251 + HK_Table table, //
  252 + List(HK_List_View) list_view //list view to generate
  253 + )=
  254 + since table is hk_table(table_name, short_name, model, display),
  255 + if write_string(stream,
  256 + "public define VT_view\n"+
  257 + " get_viewable_"+table_name+"\n"+
  258 + " (\n"+
  259 + " String view,\n"+
  260 + " )=\n"+
  261 + _generate_get_viewable_if_else(table_name, list_view, "")+
  262 + ".\n"
  263 + ) is //end of the function
  264 + {
  265 + failure then println("can't write generate_get_viewable "+table_name); failure,
  266 + success(_) then success(unique)
  267 + }.
  268 +
  269 +public define Maybe(One)
  270 + generate_VT_all_view
  271 + (
  272 + Stream stream,
  273 + HK_Table table
  274 + )=
  275 + since table is hk_table(name, short_name, model, display),
  276 + since model is hk_model( columns, _),
  277 + since display is hk_display(list_view, list_edit),
  278 +
  279 + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
  280 + if _generate_VT_view(stream, table, list_view, false) is //list view to generate
  281 + {
  282 + failure then failure,
  283 + success(_) then generate_get_viewable(stream, table, list_view)
  284 + }.
src/generation/web_args.anubis
@@ -104,7 +104,7 @@ public define String @@ -104,7 +104,7 @@ public define String
104 //anubis(_T) then "constant_byte_array(0,0)", 104 //anubis(_T) then "constant_byte_array(0,0)",
105 p_key then "[]", 105 p_key then "[]",
106 boolean_field then 106 boolean_field then
107 - "with "+name+" = get_Bool(lwa, __prefix__+\""+name+"\"), [field(\""+name+"\", bind_Bool(\":v_"+name+"\", "+name+"))]", 107 + "if get_mb_Bool(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Bool(\":v_"+name+"\", "+name+"))] }",
108 date_field(attrs) then 108 date_field(attrs) then
109 if attrs = none then 109 if attrs = none then
110 "if get_DB_date(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Date(\":v_"+name+"\", "+name+"))] }" 110 "if get_DB_date(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Date(\":v_"+name+"\", "+name+"))] }"
@@ -121,7 +121,7 @@ public define String @@ -121,7 +121,7 @@ public define String
121 else 121 else
122 "[]", 122 "[]",
123 foreign_key(_,_) then //"with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),", 123 foreign_key(_,_) then //"with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),",
124 - "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"), [field(\""+name+"\", bind_DB_id_or_NULL(\":v_"+name+"\", "+name+"))]" 124 + "if get_mb_DB_id(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_DB_id_or_NULL(\":v_"+name+"\", "+name+"))] }"
125 integer_field(_) then //"get_Int(lwa, __prefix__+\""+name+"\")", 125 integer_field(_) then //"get_Int(lwa, __prefix__+\""+name+"\")",
126 "if get_Int(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Int(\":v_"+name+"\", "+name+"))] }" 126 "if get_Int(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Int(\":v_"+name+"\", "+name+"))] }"
127 float_field then //"get_Float(lwa, __prefix__+\""+name+"\")", 127 float_field then //"get_Float(lwa, __prefix__+\""+name+"\")",