Commit 7c694bdb28d105b490596e5a7c186da619654bbb

Authored by totoro
1 parent ea1efe8b

add SQL clause in vtm_view. This clause can be apply on data table for filtering the viewed data

Add the management of viewing the fk_view option of edit_view. fk_view option allow to watch the One to Many foreign key
view/view_table_manager_types.anubis
@@ -33,7 +33,7 @@ public type TM_delete_list: @@ -33,7 +33,7 @@ public type TM_delete_list:
33 tm_delete_list(List(TM_delete) list). 33 tm_delete_list(List(TM_delete) list).
34 34
35 public type VTM_view: 35 public type VTM_view:
36 - vtm_view(String table_name, (SQLite3DataBase db, String view_name) -> VT_view get_view). 36 + vtm_view(String table_name, (SQLite3DataBase db, String view_name, String clause) -> VT_view get_view).
37 37
38 public type VTM_view_list: 38 public type VTM_view_list:
39 vtm_view_list(List(VTM_view) list). 39 vtm_view_list(List(VTM_view) list).
view/view_table_renderer.anubis
@@ -35,7 +35,183 @@ read calexium_lib/web/widgets/button.anubis @@ -35,7 +35,183 @@ read calexium_lib/web/widgets/button.anubis
35 35
36 36
37 37
  38 + // View table part
  39 +define HTML_Row(HTML_Off_Form) make_line
  40 + (
  41 + String uid,
  42 + String table_name,
  43 + String _action_name, //default is "edit_table", but can be surcharged for own use
  44 + List(VT_view_entry) entries,
  45 + List(HTML_Cell(HTML_Off_Form)) so_far
  46 + )=
  47 + if entries is
  48 + {
  49 + [] then row( [], reverse(so_far)),
  50 + [h . t] then
  51 + with cell = if h is
  52 + {
  53 + text(string) then cell((HTML_Off_Form)text(not_null_String(string))),
  54 +// link(id, string) then cell((HTML_Off_Form)actioner(same,same, link(string), action_name, [("table_name", table_name),("id",id)])),
  55 + link(id, string) then cell((HTML_Off_Form)literal(jq_dialog_open(string, dialog_id(uid+_action_name+"_dlg_ajax"), "'id="+id+"'"))),
  56 + link_id_action(id, name, action) then cell((HTML_Off_Form)actioner(same,same, link(name), action, [("id",id)])),
  57 + icon(icon_path) then cell((HTML_Off_Form)image([], icon_path, ""))
  58 + },
  59 + make_line(uid, table_name, _action_name, t, [cell . so_far])
  60 + }.
  61 +
  62 +define List(HTML_Row(HTML_Off_Form))
  63 + make_lines
  64 + (
  65 + (String) -> String _T, //translator
  66 + String uid,
  67 + String table_name,
  68 + String action_name,
  69 + List(VT_view_row) entries,
  70 + List(HTML_Row(HTML_Off_Form)) so_far
  71 + )=
  72 + if entries is
  73 + {
  74 + [] then reverse(so_far),
  75 + [h . t] then
  76 + //compute each line
  77 + //prepare here the first cell for actioner
  78 + with actions_cell = (HTML_Cell(HTML_Off_Form))
  79 + cell([],
  80 + sequence([
  81 + partial(img_button_confirm(icn16_cross, _T("CONFIRMATION_REQUEST"), _T("CONFIRM_LINE_DELETION") , _T("OK"), _T("CANCEL"), jQuery_actioner(same, jqlink(controller_action("hk_c", "delete_row" + format_extra_operands([("table_name", table_name),("id",to_String(h.db_id))])))))),
  82 + partial(img_button(icn16_edit, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax"), "'id="+to_String(h.db_id)+"'"))], "", [])),
  83 + ])
  84 + ),
  85 + make_lines(_T, uid, table_name, action_name, t, [make_line(uid, table_name, action_name, h.list, [actions_cell]). so_far] )
  86 + }.
  87 +
  88 + // View table part
  89 +define HTML_Header_Row(HTML_Off_Form)
  90 + make_header
  91 + (
  92 + (String) -> String _T, //translator
  93 + List(VT_view_entry) entries,
  94 + List(HTML_Header_Cell(HTML_Off_Form)) so_far
  95 + )=
  96 + if entries is
  97 + {
  98 + [] then header_row( [], reverse(so_far)),
  99 + [h . t] then
  100 + with cell = if h is
  101 + {
  102 + text(string) then header_cell((HTML_Off_Form)text(_T(string))),
  103 + link(id, string) then header_cell((HTML_Off_Form)actioner(same, same, link(string), edit_table,[])), //TODO
  104 + link_id_action(id, text, action) then header_cell((HTML_Off_Form)actioner(same,same, link(text), action,[("id",id)])), //TODO
  105 + icon(icon_path) then header_cell((HTML_Off_Form)image([], icon_path, ""))
  106 + },
  107 + make_header(_T, t, [cell . so_far])
  108 + }.
  109 +
  110 +
  111 +
  112 +public define HTML_Partial_Content
  113 + view_table_form
  114 + (
  115 + (String) -> String _T,
  116 + String uid,
  117 + String action_name,
  118 + VT_view rows
  119 + )=
  120 + with action_header_cell = header_cell((HTML_Off_Form)text(_T("ACTION"))),
  121 + partial_content(
  122 + div( [/*class("tableau")*/],
  123 + sequence(
  124 + [
  125 +
  126 + partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+rows.table_name)))),
  127 + table([core_attrs([id(uid+"table_view"), class("tableau display compact nowrap")])],
  128 + make_header(_T, rows.header.list, [action_header_cell]),
  129 + make_lines(_T, uid, rows.table_name, action_name, rows.list, []))
  130 + ]
  131 + )
  132 + ))
  133 + .
  134 +
  135 +public define HTML_Partial_Content
  136 + view_table_page
  137 + (
  138 + (String) -> String _T,
  139 + String lang,
  140 + String web_site_directory,
  141 + String action_name,
  142 + VT_view rows
  143 + ) =
  144 +
  145 +// if tb is tool_box(lang, _T, _, _, db, _) then
  146 +// println("view_table_page - lang : "+lang);
  147 +// println("view_table_page - web_site_directory : "+web_site_directory);
  148 + with uid = generate_random_string(20)+"_",
  149 + partial_content(jq_dialog_init + jq_datetimepicker_init(lang),
  150 + [html_wave_box_wide(_T(to_upper(rows.table_name)),
  151 + sequence([
  152 + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])),
  153 + partial(jquery_datatable(uid+"table_view", view_table_form(_T, uid, action_name, rows), true, false, jq_dt_pt_full_numbers, false, scrollY(500), true, true, true, lang, no_extra, web_site_directory))
  154 + ]))]).
  155 +
  156 +public define HTML_Partial_Content
  157 + view_table
  158 + (
  159 + (String) -> String _T,
  160 + String lang,
  161 + String web_site_directory,
  162 + String action_name,
  163 + VT_view rows
  164 + ) =
  165 +
  166 +// if tb is tool_box(lang, _T, _, _, db, _) then
  167 +// println("view_table_page - lang : "+lang);
  168 +// println("view_table_page - web_site_directory : "+web_site_directory);
  169 + with uid = generate_random_string(20)+"_",
  170 + partial_content(jq_dialog_init + jq_datetimepicker_init(lang),
  171 + [partial(jquery_datatable(uid+"table_view", view_table_form(_T, uid, action_name, rows), true, false, jq_dt_pt_full_numbers, false, scrollY(500), true, true, true, lang, no_extra, web_site_directory))]).
  172 +
  173 +public define Maybe(HTML_Partial_Content)
  174 + view_table_content
  175 + (
  176 + SQLite3DataBase db,
  177 + (String) -> String _T,
  178 + String lang,
  179 + String web_site_directory,
  180 + String table,
  181 + String view_name,
  182 + String action_name,
  183 + String clause,
  184 + VTM vtm
  185 + ) =
  186 + if vtm_get_view(table, vtm.view_list) is
  187 + {
  188 + failure then failure,
  189 + success(vtm_v) then
  190 + since vtm_v is vtm_view(_, get_view),
  191 + success(view_table_page(_T, lang, web_site_directory, action_name, get_view(db, view_name, clause)))
  192 + }.
38 193
  194 +public define Maybe(HTML_Partial_Content)
  195 + view_table_only
  196 + (
  197 + SQLite3DataBase db,
  198 + (String) -> String _T,
  199 + String lang,
  200 + String web_site_directory,
  201 + String table,
  202 + String view_name,
  203 + String action_name,
  204 + String clause,
  205 + VTM vtm
  206 + ) =
  207 + if vtm_get_view(table, vtm.view_list) is
  208 + {
  209 + failure then failure,
  210 + success(vtm_v) then
  211 + since vtm_v is vtm_view(_, get_view),
  212 + success(view_table(_T, lang, web_site_directory, action_name, get_view(db, view_name, clause)))
  213 + }.
  214 +
39 define CXM_Form_Field 215 define CXM_Form_Field
40 help_line 216 help_line
41 ( 217 (
@@ -94,9 +270,9 @@ public define List(CXM_Form_Field) @@ -94,9 +270,9 @@ public define List(CXM_Form_Field)
94 ], 270 ],
95 271
96 foreign_text(s_name, c_name, value, select, help) then 272 foreign_text(s_name, c_name, value, select, help) then
97 - [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db), success(init(to_String(value))), mandatory), help_line(help, _T)], 273 + [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, ""), success(init(to_String(value))), mandatory), help_line(help, _T)],
98 choices_text(s_name, c_name, value, select, help) then 274 choices_text(s_name, c_name, value, select, help) then
99 - [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db), success(init(value)), mandatory), help_line(help, _T)], 275 + [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, ""), success(init(value)), mandatory), help_line(help, _T)],
100 text_area(s_name, c_name, value, txt_editor, help) then 276 text_area(s_name, c_name, value, txt_editor, help) then
101 with id = if txt_editor is { none then "", rich_editor then c_name+"_editor"}, 277 with id = if txt_editor is { none then "", rich_editor then c_name+"_editor"},
102 [text_area([],label(_T(s_name), no_help), html_Id(id), wan(c_name), init(not_null_String(value)), narrow, (Int)5, mandatory), help_line(help, _T)], 278 [text_area([],label(_T(s_name), no_help), html_Id(id), wan(c_name), init(not_null_String(value)), narrow, (Int)5, mandatory), help_line(help, _T)],
@@ -107,7 +283,7 @@ public define List(CXM_Form_Field) @@ -107,7 +283,7 @@ public define List(CXM_Form_Field)
107 float(s_name, c_name, value, help) then 283 float(s_name, c_name, value, help) then
108 [input(label(_T(s_name), no_help), wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)], 284 [input(label(_T(s_name), no_help), wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)],
109 choices_int(s_name, c_name, value, select, help) then 285 choices_int(s_name, c_name, value, select, help) then
110 - [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db), success(init(to_String(value))), mandatory), help_line(help, _T)], 286 + [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, ""), success(init(to_String(value))), mandatory), help_line(help, _T)],
111 date(s_name, c_name, value, help) then 287 date(s_name, c_name, value, help) then
112 [input([class("datepicker")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(value), small, non_mandatory), help_line(help, _T)], 288 [input([class("datepicker")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(value), small, non_mandatory), help_line(help, _T)],
113 time(s_name, c_name, value, help) then 289 time(s_name, c_name, value, help) then
@@ -150,18 +326,22 @@ public define HTML_Partial_Content @@ -150,18 +326,22 @@ public define HTML_Partial_Content
150 SQLite3DataBase db, 326 SQLite3DataBase db,
151 (String) -> String _T, 327 (String) -> String _T,
152 String lang, 328 String lang,
  329 + String web_site_directory,
153 List(Web_arg) lwa, 330 List(Web_arg) lwa,
154 - VT_edit vt_elist 331 + VT_edit vt_elist,
  332 + VTM vtm
155 ) = 333 ) =
156 with table_name = vt_elist.table_name, 334 with table_name = vt_elist.table_name,
157 //true if need to create row or false for updating 335 //true if need to create row or false for updating
158 with create = if get_String(lwa, "id","none") = "none" then true else false, 336 with create = if get_String(lwa, "id","none") = "none" then true else false,
  337 + with id = get_String(lwa, "id","none"),
159 with button_name = if create then _T("CREATE") else _T("UPDATE"), 338 with button_name = if create then _T("CREATE") else _T("UPDATE"),
160 with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"), 339 with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"),
161 340
162 partial_content( 341 partial_content(
163 jq_datetimepicker_init(lang) + 342 jq_datetimepicker_init(lang) +
164 get_editor_header(vt_elist.list), //add editor header if need. Like init ck_editor 343 get_editor_header(vt_elist.list), //add editor header if need. Like init ck_editor
  344 + sequence([
165 cxm_form( table_name, lwa, 345 cxm_form( table_name, lwa,
166 edit_form_lines(db, _T, vt_elist.list, create, [])+ 346 edit_form_lines(db, _T, vt_elist.list, create, [])+
167 [ one_line_fields([ 347 [ one_line_fields([
@@ -170,6 +350,20 @@ public define HTML_Partial_Content @@ -170,6 +350,20 @@ public define HTML_Partial_Content
170 submit(hk_cancel, failure, _T("CANCEL")) 350 submit(hk_cancel, failure, _T("CANCEL"))
171 ]) 351 ])
172 ] 352 ]
  353 + )]+
  354 + if id = "none" then
  355 + []
  356 + else
  357 + map( (HK_V_Edit_Tab tab)
  358 + |->
  359 + since tab is hk_v_edit_tab(fk_table_name, fk_col_name, list_view_name),
  360 + if view_table_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", fk_col_name+" = "+id, vtm) is
  361 + {
  362 + failure then empty,
  363 + success(p_content) then partial(p_content)
  364 + }
  365 + //text("Foreign Key from table ["+fk_table_name+"] columns ["+fk_col_name+"] view to use ["+list_view_name+"]")
  366 + ,vt_elist.tabs)
173 )). 367 )).
174 368
175 public define Maybe(HTML_Partial_Content) 369 public define Maybe(HTML_Partial_Content)
@@ -178,10 +372,11 @@ public define Maybe(HTML_Partial_Content) @@ -178,10 +372,11 @@ public define Maybe(HTML_Partial_Content)
178 SQLite3DataBase db, 372 SQLite3DataBase db,
179 (String) -> String _T, 373 (String) -> String _T,
180 String lang, 374 String lang,
  375 + String web_site_directory,
181 List(Web_arg) lwa, 376 List(Web_arg) lwa,
182 - String table,  
183 - String view_name,  
184 - VT_action action, 377 + String table, //table name
  378 + String view_name, //view name to use
  379 + VT_action action, //new_entry or edit an existing record
185 VTM vtm 380 VTM vtm
186 ) = 381 ) =
187 if vtm_get_edit(table, vtm.edit_list) is 382 if vtm_get_edit(table, vtm.edit_list) is
@@ -189,140 +384,7 @@ public define Maybe(HTML_Partial_Content) @@ -189,140 +384,7 @@ public define Maybe(HTML_Partial_Content)
189 failure then failure, 384 failure then failure,
190 success(vtm_e) then 385 success(vtm_e) then
191 since vtm_e is vtm_edit(_, get_edit), 386 since vtm_e is vtm_edit(_, get_edit),
192 - success(edit_table_page(db, _T, lang, lwa, get_edit(db, action, view_name)))  
193 - }.  
194 -  
195 -  
196 - // View table part  
197 -define HTML_Row(HTML_Off_Form) make_line  
198 - (  
199 - String table_name,  
200 - String _action_name, //default is "edit_table", but can be surcharged for own use  
201 - List(VT_view_entry) entries,  
202 - List(HTML_Cell(HTML_Off_Form)) so_far  
203 - )=  
204 - if entries is  
205 - {  
206 - [] then row( [], reverse(so_far)),  
207 - [h . t] then  
208 - with cell = if h is  
209 - {  
210 - text(string) then cell((HTML_Off_Form)text(not_null_String(string))),  
211 -// link(id, string) then cell((HTML_Off_Form)actioner(same,same, link(string), action_name, [("table_name", table_name),("id",id)])),  
212 - link(id, string) then cell((HTML_Off_Form)literal(jq_dialog_open(string, dialog_id(_action_name+"_dlg_ajax"), "'id="+id+"'"))),  
213 - link_id_action(id, name, action) then cell((HTML_Off_Form)actioner(same,same, link(name), action, [("id",id)])),  
214 - icon(icon_path) then cell((HTML_Off_Form)image([], icon_path, ""))  
215 - },  
216 - make_line(table_name, _action_name, t, [cell . so_far]) 387 + success(edit_table_page(db, _T, lang, web_site_directory, lwa, get_edit(db, action, view_name), vtm))
217 }. 388 }.
218 389
219 -define List(HTML_Row(HTML_Off_Form))  
220 - make_lines  
221 - (  
222 - (String) -> String _T, //translator  
223 - String table_name,  
224 - String action_name,  
225 - List(VT_view_row) entries,  
226 - List(HTML_Row(HTML_Off_Form)) so_far  
227 - )=  
228 - if entries is  
229 - {  
230 - [] then reverse(so_far),  
231 - [h . t] then  
232 - //compute each line  
233 - //prepare here the first cell for actioner  
234 - with actions_cell = (HTML_Cell(HTML_Off_Form))  
235 - cell([],  
236 - sequence([  
237 - partial(img_button_confirm(icn16_cross, _T("CONFIRMATION_REQUEST"), _T("CONFIRM_LINE_DELETION") , _T("OK"), _T("CANCEL"), jQuery_actioner(same, jqlink(controller_action("hk_c", "delete_row" + format_extra_operands([("table_name", table_name),("id",to_String(h.db_id))])))))),  
238 - partial(img_button(icn16_edit, [event(onclick, jq_dialog_open(dialog_id(action_name+"_dlg_ajax"), "'id="+to_String(h.db_id)+"'"))], "", [])),  
239 - ])  
240 - ),  
241 - make_lines(_T, table_name, action_name, t, [make_line(table_name, action_name, h.list, [actions_cell]). so_far] )  
242 - }.  
243 390
244 - // View table part  
245 -define HTML_Header_Row(HTML_Off_Form)  
246 - make_header  
247 - (  
248 - (String) -> String _T, //translator  
249 - List(VT_view_entry) entries,  
250 - List(HTML_Header_Cell(HTML_Off_Form)) so_far  
251 - )=  
252 - if entries is  
253 - {  
254 - [] then header_row( [], reverse(so_far)),  
255 - [h . t] then  
256 - with cell = if h is  
257 - {  
258 - text(string) then header_cell((HTML_Off_Form)text(_T(string))),  
259 - link(id, string) then header_cell((HTML_Off_Form)actioner(same, same, link(string), edit_table,[])), //TODO  
260 - link_id_action(id, text, action) then header_cell((HTML_Off_Form)actioner(same,same, link(text), action,[("id",id)])), //TODO  
261 - icon(icon_path) then header_cell((HTML_Off_Form)image([], icon_path, ""))  
262 - },  
263 - make_header(_T, t, [cell . so_far])  
264 - }.  
265 -  
266 -  
267 -  
268 -public define HTML_Partial_Content  
269 - view_table_form  
270 - (  
271 - (String) -> String _T,  
272 - String action_name,  
273 - VT_view rows  
274 - )=  
275 - with action_header_cell = header_cell((HTML_Off_Form)text(_T("ACTION"))),  
276 - partial_content(  
277 - div( [/*class("tableau")*/],  
278 - sequence(  
279 - [  
280 - partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(action_name+"_dlg_ajax")))], "", [])),  
281 - //partial(jquery_button(jQuery_button(button, "edit_table_"+rows.table_name, "", _T("NEW"), jQuery_actioner(same, jqlink(controller_action("hk_c", "edit_table&table_name="+rows.table_name)))))),  
282 - //dialog used by datatable entries  
283 - partial(jq_dialog_create(dialog_id(action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+rows.table_name)))),  
284 -  
285 - table([core_attrs([id("table_view"), class("tableau display compact nowrap")])],  
286 - make_header(_T, rows.header.list, [action_header_cell]),  
287 - make_lines(_T, rows.table_name, action_name, rows.list, []))  
288 - ]  
289 - )  
290 - ))  
291 - .  
292 -  
293 -public define HTML_Partial_Content  
294 - view_table_page  
295 - (  
296 - (String) -> String _T,  
297 - String lang,  
298 - String web_site_directory,  
299 - String action_name,  
300 - VT_view rows  
301 - ) =  
302 -  
303 -// if tb is tool_box(lang, _T, _, _, db, _) then  
304 -// println("view_table_page - lang : "+lang);  
305 -// println("view_table_page - web_site_directory : "+web_site_directory);  
306 - partial_content(jq_dialog_init + jq_datetimepicker_init(lang),  
307 - [partial(html_wave_box_wide(_T(to_upper(rows.table_name)),  
308 - jquery_datatable("table_view", view_table_form(_T, action_name, rows), true, false, jq_dt_pt_full_numbers, false, scrollY(500), true, true, true, lang, no_extra, web_site_directory)))]).  
309 -  
310 -public define Maybe(HTML_Partial_Content)  
311 - view_table_content  
312 - (  
313 - SQLite3DataBase db,  
314 - (String) -> String _T,  
315 - String lang,  
316 - String web_site_directory,  
317 - String table,  
318 - String view_name,  
319 - String action_name,  
320 - VTM vtm  
321 - ) =  
322 - if vtm_get_view(table, vtm.view_list) is  
323 - {  
324 - failure then failure,  
325 - success(vtm_v) then  
326 - since vtm_v is vtm_view(_, get_view),  
327 - success(view_table_page(_T, lang, web_site_directory, action_name, get_view(db, view_name)))  
328 - }.  
view/view_table_types.anubis
@@ -10,7 +10,7 @@ transmit calexium_lib/web/CXM_common.anubis @@ -10,7 +10,7 @@ transmit calexium_lib/web/CXM_common.anubis
10 read hayamiki_lib/types/hayamiki.anubis 10 read hayamiki_lib/types/hayamiki.anubis
11 11
12 public type VT_edit_selector: 12 public type VT_edit_selector:
13 - vt_edit_selector((SQLite3DataBase db) -> List((List(CoreAttrs), WebArgValue, String)) get). 13 + vt_edit_selector((SQLite3DataBase db, String clause) -> List((List(CoreAttrs), WebArgValue, String)) get).
14 14
15 15
16 public type VT_edit_entry: 16 public type VT_edit_entry: