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
183
184
185
/*
* 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
.
public define Maybe(One)
/* Generate
*/
generate_VT_edit
(
Stream stream, //stream file where to write
HK_Table table, //
HK_Edit_View edit_view //edit view to generate
)=
since table is hk_table(table_name, short_name, model, display),
since model is hk_model( columns, _),
//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(view_name, _) then view_name
},
with current_edit_view = if edit_view is
{
edit_view_all then to_List_String(columns, false),
edit_view(_, cols) then cols
},
//generate the type of the table that contain all components
if write_string(stream,
"\n\n"+
//SQL query
"define VT_edit\n"+
" _get_editable_"+table_name+"_"+view_name+"\n"+
" (\n"+
" "+type_name+" "+table_name+",\n"+
" SQLite3DataBase db\n"+
" )=\n"+
" with edit_entries = (List(VT_edit_entry))\n"+
" [\n"+
edit_entries(columns, table_name, " ", [])+"\n"+
" ],\n"+
" vt_edit(\""+table_name+"\", \""+view_name+"\", edit_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
(
Stream stream, //stream file where to write
HK_Table table, //
List(HK_Edit_View) 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_VT_edit(stream, table, edit_view_all)
else
success(unique),
[view . t] then
if generate_VT_edit(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(view_name, _) then
//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)
}
}.
public define String
/* Generate
*/
_generate_get_editable_if_else
(
String table_name, //
List(HK_Edit_View) 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(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_Edit_View) edit_view //list view to generate
)=
since table is hk_table(table_name, short_name, model, display),
if write_string(stream,
"public define VT_edit\n"+
" get_editable_"+table_name+"\n"+
" (\n"+
" SQLite3DataBase db,\n"+
" VT_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\n"+
" if get_"+table_name+"(db, idx) is\n"+
" {\n"+
" failure then get_default_"+table_name+",\n"+
" success(data) then data\n"+
" }\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, _),
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
{
failure then failure,
success(_) then generate_get_viewable(stream, table, list_edit)
}.