edit_view_table_form.anubis
3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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)
}.