diff --git a/hayamiki_generator.aproj b/hayamiki_generator.aproj
index 21dcce6..3605e5e 100644
--- a/hayamiki_generator.aproj
+++ b/hayamiki_generator.aproj
@@ -517,6 +517,8 @@
+
+
diff --git a/hayamiki_lib b/hayamiki_lib
index 23eeeae..fed6db1 160000
--- a/hayamiki_lib
+++ b/hayamiki_lib
@@ -1 +1 @@
-Subproject commit 23eeeae84177732211b508466d55b46abae6fb17
+Subproject commit fed6db131cf6d306092a560ce5764ee87a6f4436
diff --git a/src/generation/columns.anubis b/src/generation/columns.anubis
index 8ff80cf..751017e 100644
--- a/src/generation/columns.anubis
+++ b/src/generation/columns.anubis
@@ -211,65 +211,65 @@ public define Maybe(String)
get_HK_Form_Entry
(
HK_Model_Column col,
- String type_name
+ String type_name //name of the instanciated type
) =
- since col is hk_column(name, col_type, _, help),
+ since col is hk_column(col_name, col_type, _, help),
if col_type is
{
//anubis(_T) then "constant_byte_array(0,0)",
- p_key then success("primary_key(to_String("+type_name+"."+name+"))"),
+ p_key then success("primary_key(to_String("+type_name+"."+col_name+"))"),
//binary then "constant_byte_array(0,0)",
- boolean_field then success("boolean(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
+ boolean_field then success("boolean(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", "+to_Anubis_source(help)+")"),
date_field(attrs) then if attrs is
{
- none then success("date(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, "+to_Anubis_source(help)+")"),
- auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, 10, "+to_Anubis_source(help)+")"),
- auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, 10, "+to_Anubis_source(help)+")")
+ none then success("date(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".date, "+to_Anubis_source(help)+")"),
+ auto_now then success("information(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".date, 10, "+to_Anubis_source(help)+")"),
+ auto_now_add then success("information(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".date, 10, "+to_Anubis_source(help)+")")
},
time_field(attrs) then if attrs is
{
- none then success("time(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, "+to_Anubis_source(help)+")"),
- auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, 10, "+to_Anubis_source(help)+")"),
- auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, 10, "+to_Anubis_source(help)+")")
+ none then success("time(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".time, "+to_Anubis_source(help)+")"),
+ auto_now then success("information(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".time, 10, "+to_Anubis_source(help)+")"),
+ auto_now_add then success("information(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".time, 10, "+to_Anubis_source(help)+")")
},
datetime_field(attrs) then if attrs is
{
- none then success("datetime(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"),
- auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, 18, "+to_Anubis_source(help)+")"),
- auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, 18, "+to_Anubis_source(help)+")")
+ none then success("datetime(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".datetime, "+to_Anubis_source(help)+")"),
+ auto_now then success("information(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".datetime, 18, "+to_Anubis_source(help)+")"),
+ auto_now_add then success("information(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".datetime, 18, "+to_Anubis_source(help)+")")
},
- foreign_key(app,foreign_table) then success("foreign_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"),
+ foreign_key(app,foreign_table) then success("foreign_text(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"),
integer_field(choices) then
//success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
if choices is
{
- no_choice then success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
+ no_choice then success("integer(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", "+to_Anubis_source(help)+")"),
int_choices(choices_list) then
//if choice list is NOT empty we construct the possible choices selector
if length(choices_list) > 0 then
- success("choices_int(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", hk_form_selector(get_choices_selector_"+to_lower(type_name)+"_"+name+"), "+to_Anubis_source(help)+")")
+ success("choices_int(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", hk_form_selector(get_choices_selector_"+to_lower(type_name)+"_"+col_name+"), "+to_Anubis_source(help)+")")
else
- success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
+ success("integer(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", "+to_Anubis_source(help)+")"),
}
- float_field then success("float(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
+ float_field then success("float(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", "+to_Anubis_source(help)+")"),
//TODO make choices selection if need
char_field(choices,_) then
if choices is
{
- no_choice then success("text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
+ no_choice then success("text(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", "+to_Anubis_source(help)+")"),
text_choices(choices_list) then
//if choice list is NOT empty we construct the possible choices selector
if length(choices_list) > 0 then
- success("choices_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", hk_form_selector(get_choices_selector_"+to_lower(type_name)+"_"+name+"), "+to_Anubis_source(help)+")")
+ success("choices_text(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", hk_form_selector(get_choices_selector_"+to_lower(type_name)+"_"+col_name+"), "+to_Anubis_source(help)+")")
else
- success("text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")")
+ success("text(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", "+to_Anubis_source(help)+")")
}
- password_field(min_size) then success("password(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")")
- text_field(txt_attr) then success("text_area(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(txt_attr)+", "+to_Anubis_source(help)+")"),
- color_field then success("color(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
+ password_field(min_size) then success("password(\""+to_upper(col_name)+"\", \""+col_name+"\", "+to_Anubis_source(help)+")")
+ text_field(txt_attr) then success("text_area(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", "+to_Anubis_source(txt_attr)+", "+to_Anubis_source(help)+")"),
+ color_field then success("color(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", "+to_Anubis_source(help)+")"),
}.
public define String
diff --git a/src/generation/edit_view_list_form.anubis b/src/generation/edit_view_list_form.anubis
new file mode 100644
index 0000000..8d2383a
--- /dev/null
+++ b/src/generation/edit_view_list_form.anubis
@@ -0,0 +1,76 @@
+/*
+ * Created by PyramIDE.
+ * User: フランスのトトロ aka (David RENÉ)
+ * Date: 09/04/2017
+ * Time: 16:40
+ * © Calexium
+ */
+
+read hayamiki_lib/types/hayamiki.anubis
+read tools/basis.anubis
+read tools/list.anubis
+read tools/streams.anubis
+read system/string.anubis
+read columns.anubis
+read html.anubis
+
+define String
+ hk_form_tab_entries
+ (
+ List(HK_FK_View) fk_views,
+ String indent
+ )=
+ join(",\n",
+ map((HK_FK_View fk_view)
+ |->
+ since fk_view is fk_view(app_name, fk_table_name, fk_col),
+ indent+" hk_form_tab(\""+fk_table_name+"\", \""+fk_col+"\", \"default\")"
+ ,
+ fk_views)
+ )
+.
+
+public define Maybe(One)
+/* Generate
+
+*/
+ generate_edit_view_list_form
+ (
+ Stream stream, //stream file where to write
+ HK_Table table, //db table name
+ String view_name, //name of the form
+ List(HK_Model_Column) l_cols, //Columns selected to be editable in this list form
+ List(HK_FK_View) l_fk_view //List of foreign key view to display
+ )=
+ since table is hk_table(table_name, short_name, model, display),
+ since model is hk_model( columns, _),
+ with type_name = to_upper(table_name, 1), //make the first character to upper case and be an Anubis Type.
+
+ if write_string(stream,
+ "\n\n"+
+ //SQL query
+ "define HK_Form\n"+
+ " _get_editable_"+table_name+"_"+view_name+"\n"+
+ " (\n"+
+ " "+type_name+" "+table_name+",\n"+
+ " SQLite3DataBase db\n"+
+ " )=\n"+
+ " with edit_entries = (List(HK_Form_Entry))\n"+
+ " [\n"+
+ " hidden(\"id\", to_String("+table_name+".id)),\n"+
+ edit_entries(l_cols, table_name, " ", [])+"\n"+
+ " ],\n"+
+ (if is_empty(l_fk_view) then
+ " hk_form_in_list(\""+table_name+"\", \""+view_name+"\", edit_entries, []).\n\n"
+ else
+ " with fk_view_entries = (List(HK_Form_Tab))\n"+
+ " [\n"+
+ hk_form_tab_entries(l_fk_view, " ")+"\n"+
+ " ],\n\n"+
+ " hk_form_in_list(\""+table_name+"\", \""+view_name+"\", edit_entries, fk_view_entries).\n\n"
+ )
+ ) is //end of the function
+ {
+ failure then println("can't write generate_VT_view "+type_name); failure,
+ success(_) then success(unique)
+ }.
diff --git a/src/generation/edit_view_table_form.anubis b/src/generation/edit_view_table_form.anubis
new file mode 100644
index 0000000..3c01d79
--- /dev/null
+++ b/src/generation/edit_view_table_form.anubis
@@ -0,0 +1,122 @@
+/*
+ * Created by PyramIDE.
+ * User: フランスのトトロ aka (David RENÉ)
+ * Date: 09/04/2017
+ * Time: 02:37
+ * © Calexium
+ */
+
+read hayamiki_lib/types/hayamiki.anubis
+read tools/streams.anubis
+read columns.anubis
+
+public define String
+ make_cell
+ (
+ HK_Edit_View_Table_Cell cell_description, //
+ List(HK_Model_Column) columns,
+ String type_name
+ )=
+ if cell_description is
+ {
+ empty then ""
+ column(col_name) then
+ if get_column_type_from_name(columns, col_name) is
+ {
+ failure then "label(\"column ["+col_name+"] not found\")",
+ success(col_type) then
+ if get_HK_Form_Entry(col_type, type_name) is
+ {
+ failure then "label(\" form for column ["+col_name+"] not found\")",
+ success(form_string) then form_string
+ }
+ }
+ label(label_str) then "label(\""+label_str+"\")"
+
+ }
+.
+
+
+ get_column_type_from_name(columns, column_name)
+
+public define String
+ make_cells
+ (
+ List(HK_Edit_View_Table_Cell) cells,
+ List(HK_Model_Column) columns,
+ String table_name,
+ String indent
+ ) =
+ if is_empty(cells) then
+ ""
+ else
+ "\n"+indent+ join(",\n"+indent, map((HK_Edit_View_Table_Cell cell) |-> "hk_form_table_cell("+ make_cell(cell, columns, table_name) +")", cells))
+.
+
+
+ if columns is
+ {
+ [] then indent+" "+join(",\n"+indent+" ", reverse(so_far)),
+ [h . t] then
+ if get_HK_Form_Entry(h, type_name) is
+ {
+ failure then edit_entries(t, type_name, indent, so_far)
+ success(result) then edit_entries(t, type_name, indent, [result . so_far])
+ }
+ }.
+
+define String
+ make_lines
+ (
+ List(HK_Edit_View_Table_Line) lines,
+ List(HK_Model_Column) columns,
+ String table_name,
+ String indent
+ )=
+ if is_empty(lines) then
+ ""
+ else
+ "\n"+indent+ join(",\n"+indent, map((HK_Edit_View_Table_Line line) |-> "hk_form_table_line(["+ make_cells(line.cells, columns, table_name, indent+" ") +"\n"+indent+"])", lines))
+.
+
+
+public define Maybe(One)
+/* Generate
+
+*/
+ generate_edit_view_table_form
+ (
+ Stream stream, //stream file where to write
+ HK_Table table, //
+ String view_name,
+ HK_Edit_View_Table form_in_table //edit view to generate
+ )=
+ since table is hk_table(table_name, short_name, model, display),
+ since model is hk_model( columns, _),
+ with type_name = to_upper(table_name, 1), //make the first character to upper case and be an Anubis Type.
+
+ //generate the type of the table that contain all components
+ if write_string(stream,
+ "\n\n"+
+ //SQL query
+ "define HK_Form\n"+
+ " _get_editable_"+table_name+"_"+view_name+"\n"+
+ " (\n"+
+ " "+type_name+" "+table_name+",\n"+
+ " SQLite3DataBase db\n"+
+ " )=\n"+
+ " with form_table = hk_form_table( [\n"+
+ " //Attributes of the table\n"+
+ " hidden(\"id\", to_String("+table_name+".id)),\n"+
+ " ],\n"+
+ " //All lines and cells of the table \n"+
+ " ["+
+
+ make_lines(form_in_table.lines, columns, table_name, " ")+"\n"+
+ " ]),\n\n"+
+ " hk_form_in_table(\""+table_name+"\", \""+view_name+"\", form_table).\n\n"
+ ) is //end of the function
+ {
+ failure then println("can't write generate_VT_view "+type_name); failure,
+ success(_) then success(unique)
+ }.
diff --git a/src/generation/vt_edit.anubis b/src/generation/vt_edit.anubis
index 726ea3c..1ecf22a 100644
--- a/src/generation/vt_edit.anubis
+++ b/src/generation/vt_edit.anubis
@@ -13,28 +13,16 @@ read system/string.anubis
read fields.anubis
read columns.anubis
read html.anubis
+read edit_view_list_form.anubis
+read edit_view_table_form.anubis
+
-define String
- hk_form_tab_entries
- (
- List(HK_FK_View) fk_views,
- String indent
- )=
- join(",\n",
- map((HK_FK_View fk_view)
- |->
- since fk_view is fk_view(app_name, fk_table_name, fk_col),
- indent+" hk_form_tab(\""+fk_table_name+"\", \""+fk_col+"\", \"default\")"
- ,
- fk_views)
- )
-.
public define Maybe(One)
/* Generate
*/
- generate_VT_edit
+ generate_HK_Form
(
Stream stream, //stream file where to write
HK_Table table, //
@@ -45,61 +33,37 @@ public define Maybe(One)
//since display is db_display(list_view, list_edit),
with type_name = to_upper(table_name, 1), //make the first character to upper case and be an Anubis Type.
- with view_name = if edit_view is
- {
- edit_view_all then "default",
- edit_view_list_form(v_name, _, _) then v_name,
- edit_view_table_form(v_name, _) then v_name
- },
- with current_edit_view = if edit_view is
- {
- edit_view_all then columns,
- edit_view_list_form(v_name, cols, _) then
- if get_HK_Model_Column_list_from_name_list(columns, cols) is
- {
- failure then println("generate_VT_edit: can't get all specified columns for table \""+table_name+"\" view name \""+v_name+"\" cols["+join(", ",cols)+"]");[],
- success(got_columns) then got_columns,
- }
- edit_view_table_form(_,_) then todo "handle case 'edit_view_table_form'"
- },
- with current_fk_views = if edit_view is
- {
- edit_view_all then [],
- edit_view_list_form(_, _, lfk) then lfk,
- edit_view_table_form(_,_) then []
- },
+ if edit_view is
+ {
+ //generate the form with all entries in list form
+ edit_view_all then
+ generate_edit_view_list_form(stream, table, "default", columns, []),
+
+ //generate the list form with given columns
+ edit_view_list_form(v_name, cols, lfk) then
+ if get_HK_Model_Column_list_from_name_list(columns, cols) is
+ {
+ failure then
+ println("generate_HK_Form: can't get all specified columns for table \""+table_name+"\" view name \""+v_name+"\" cols["+join(", ",cols)+"]");
+ failure,
+ success(got_columns) then
+ generate_edit_view_list_form(stream, table, v_name, got_columns, lfk)
+ }
+ edit_view_table_form(v_name, table_description) then
+ generate_edit_view_table_form(stream, table, v_name, table_description)
+ //generate the table form
+
+ }
+.
//generate the type of the table that contain all components
- if write_string(stream,
- "\n\n"+
- //SQL query
- "define HK_Form\n"+
- " _get_editable_"+table_name+"_"+view_name+"\n"+
- " (\n"+
- " "+type_name+" "+table_name+",\n"+
- " SQLite3DataBase db\n"+
- " )=\n"+
- " with edit_entries = (List(HK_Form_Entry))\n"+
- " [\n"+
- " hidden(\"id\", to_String("+table_name+".id)),\n"+
- edit_entries(current_edit_view, table_name, " ", [])+"\n"+
- " ],\n"+
- " with fk_view_entries = (List(HK_Form_Tab))\n"+
- " [\n"+
- hk_form_tab_entries(current_fk_views, " ")+"\n"+
- " ],\n"+
- " hk_form_in_list(\""+table_name+"\", \""+view_name+"\", edit_entries, fk_view_entries).\n\n"
- ) is //end of the function
- {
- failure then println("can't write generate_VT_view "+type_name); failure,
- success(_) then success(unique)
- }.
+
public define Maybe(One)
/* Generate
*/
- _generate_VT_edit
+ _generate_HK_Form
(
Stream stream, //stream file where to write
HK_Table table, //
@@ -111,11 +75,11 @@ public define Maybe(One)
[] then
//if default view was not generated, we force to generate it
if has_default = false then
- generate_VT_edit(stream, table, edit_view_all)
+ generate_HK_Form(stream, table, edit_view_all)
else
success(unique),
[view . t] then
- if generate_VT_edit(stream, table, view) is
+ if generate_HK_Form(stream, table, view) is
{
failure then failure,
success(_) then
@@ -132,7 +96,7 @@ public define Maybe(One)
//if not we search for view named 'default'
if view_name = "default" then true else false
},
- _generate_VT_edit(stream, table, t, new_has_default)
+ _generate_HK_Form(stream, table, t, new_has_default)
}
}.
@@ -215,7 +179,7 @@ public define Maybe(One)
since display is hk_display(_, list_edit),
with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
- if _generate_VT_edit(stream, table, list_edit, false) is //edit view to generate
+ if _generate_HK_Form(stream, table, list_edit, false) is //edit view to generate
{
failure then failure,
success(_) then generate_get_viewable(stream, table, list_edit)
--
libgit2 0.21.4