vt_edit.anubis
6.01 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 28/08/2016
* Time: 01:16
* © Calexium
*/
read hayamiki_lib/types/hayamiki.anubis
read tools/basis.anubis
read tools/streams.anubis
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
public define Maybe(One)
/* Generate
*/
generate_HK_Form
(
Stream stream, //stream file where to write
HK_Table table, //
HK_Editor edit_view //edit view to generate
)=
since table is hk_table(table_name, short_name, model, display),
since model is hk_model( columns, constraints, _),
//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.
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)
}
form_table(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
public define Maybe(One)
/* Generate
*/
_generate_HK_Form
(
Stream stream, //stream file where to write
HK_Table table, //
List(HK_Editor) edit_view, //edit view to generate
Bool has_default //set to true if a default view was encountered.
)=
if edit_view is
{
[] then
//if default view was not generated, we force to generate it
if has_default = false then
generate_HK_Form(stream, table, edit_view_all)
else
success(unique),
[view . t] then
if generate_HK_Form(stream, table, view) is
{
failure then failure,
success(_) then
with new_has_default = if has_default = true then //already true, no need to go further
true
else
if view is
{
edit_view_all then true, //list_view_all is default view
edit_view_list_form(view_name, _, _) then
//if not we search for view named 'default'
if view_name = "default" then true else false
form_table(view_name, _) then
//if not we search for view named 'default'
if view_name = "default" then true else false
},
_generate_HK_Form(stream, table, t, new_has_default)
}
}.
public define String
/* Generate
*/
_generate_get_editable_if_else
(
String table_name, //
List(HK_Editor) edit_view, //edit view to generate
String so_far
)=
if edit_view is
{
[] then
so_far +
"\n"+
" _get_editable_"+table_name+"_default("+table_name+", db)\n",
[view . t] then
with view_name = if view is
{
edit_view_all then "default",
edit_view_list_form(view_name, _, _) then view_name
form_table(view_name, _) then view_name
},
_generate_get_editable_if_else( table_name, t,
so_far +
" if editor_view = \""+view_name+"\" then\n"+
" _get_editable_"+table_name+"_"+view_name+"("+table_name+", db)\n"+
" else"
)
}.
public define Maybe(One)
/* Generate the function which get the right editor according to editor name
*/
generate_get_viewable
(
Stream stream, //stream file where to write
HK_Table table, //
List(HK_Editor) edit_view //list view to generate
)=
since table is hk_table(table_name, short_name, model, display),
if write_string(stream,
"public define HK_Form\n"+
" get_editable_"+table_name+"\n"+
" (\n"+
" SQLite3DataBase db,\n"+
" HK_Form_action action,\n"+
" String editor_view\n"+
" )=\n"+
" with "+table_name+" = if action is\n"+
" {\n"+
" new_entry then get_default_"+table_name+"\n"+
" edit_entry(idx) then get_"+table_name+"(db, idx)\n"+
" },\n"+
_generate_get_editable_if_else(table_name, edit_view, "")+
".\n"
) is //end of the function
{
failure then println("can't write generate_get_editable "+table_name); failure,
success(_) then success(unique)
}.
public define Maybe(One)
generate_VT_all_edit
(
Stream stream,
HK_Table table
)=
since table is hk_table(name, short_name, model, display),
since model is hk_model( columns, constraints, _),
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_HK_Form(stream, table, list_edit, false) is //edit view to generate
{
failure then failure,
success(_) then generate_get_viewable(stream, table, list_edit)
}.