From 7c694bdb28d105b490596e5a7c186da619654bbb Mon Sep 17 00:00:00 2001 From: totoro Date: Sun, 19 Mar 2017 22:41:04 +0100 Subject: [PATCH] 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 | 2 +- view/view_table_renderer.anubis | 344 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------- view/view_table_types.anubis | 2 +- 3 files changed, 205 insertions(+), 143 deletions(-) diff --git a/view/view_table_manager_types.anubis b/view/view_table_manager_types.anubis index 4813b29..e9c485f 100644 --- a/view/view_table_manager_types.anubis +++ b/view/view_table_manager_types.anubis @@ -33,7 +33,7 @@ public type TM_delete_list: tm_delete_list(List(TM_delete) list). public type VTM_view: - vtm_view(String table_name, (SQLite3DataBase db, String view_name) -> VT_view get_view). + vtm_view(String table_name, (SQLite3DataBase db, String view_name, String clause) -> VT_view get_view). public type VTM_view_list: vtm_view_list(List(VTM_view) list). diff --git a/view/view_table_renderer.anubis b/view/view_table_renderer.anubis index 1588273..82219d7 100644 --- a/view/view_table_renderer.anubis +++ b/view/view_table_renderer.anubis @@ -35,7 +35,183 @@ read calexium_lib/web/widgets/button.anubis + // View table part +define HTML_Row(HTML_Off_Form) make_line + ( + String uid, + String table_name, + String _action_name, //default is "edit_table", but can be surcharged for own use + List(VT_view_entry) entries, + List(HTML_Cell(HTML_Off_Form)) so_far + )= + if entries is + { + [] then row( [], reverse(so_far)), + [h . t] then + with cell = if h is + { + text(string) then cell((HTML_Off_Form)text(not_null_String(string))), +// link(id, string) then cell((HTML_Off_Form)actioner(same,same, link(string), action_name, [("table_name", table_name),("id",id)])), + link(id, string) then cell((HTML_Off_Form)literal(jq_dialog_open(string, dialog_id(uid+_action_name+"_dlg_ajax"), "'id="+id+"'"))), + link_id_action(id, name, action) then cell((HTML_Off_Form)actioner(same,same, link(name), action, [("id",id)])), + icon(icon_path) then cell((HTML_Off_Form)image([], icon_path, "")) + }, + make_line(uid, table_name, _action_name, t, [cell . so_far]) + }. + +define List(HTML_Row(HTML_Off_Form)) + make_lines + ( + (String) -> String _T, //translator + String uid, + String table_name, + String action_name, + List(VT_view_row) entries, + List(HTML_Row(HTML_Off_Form)) so_far + )= + if entries is + { + [] then reverse(so_far), + [h . t] then + //compute each line + //prepare here the first cell for actioner + with actions_cell = (HTML_Cell(HTML_Off_Form)) + cell([], + sequence([ + 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))])))))), + partial(img_button(icn16_edit, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax"), "'id="+to_String(h.db_id)+"'"))], "", [])), + ]) + ), + make_lines(_T, uid, table_name, action_name, t, [make_line(uid, table_name, action_name, h.list, [actions_cell]). so_far] ) + }. + + // View table part +define HTML_Header_Row(HTML_Off_Form) + make_header + ( + (String) -> String _T, //translator + List(VT_view_entry) entries, + List(HTML_Header_Cell(HTML_Off_Form)) so_far + )= + if entries is + { + [] then header_row( [], reverse(so_far)), + [h . t] then + with cell = if h is + { + text(string) then header_cell((HTML_Off_Form)text(_T(string))), + link(id, string) then header_cell((HTML_Off_Form)actioner(same, same, link(string), edit_table,[])), //TODO + link_id_action(id, text, action) then header_cell((HTML_Off_Form)actioner(same,same, link(text), action,[("id",id)])), //TODO + icon(icon_path) then header_cell((HTML_Off_Form)image([], icon_path, "")) + }, + make_header(_T, t, [cell . so_far]) + }. + + + +public define HTML_Partial_Content + view_table_form + ( + (String) -> String _T, + String uid, + String action_name, + VT_view rows + )= + with action_header_cell = header_cell((HTML_Off_Form)text(_T("ACTION"))), + partial_content( + div( [/*class("tableau")*/], + sequence( + [ + + partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+rows.table_name)))), + table([core_attrs([id(uid+"table_view"), class("tableau display compact nowrap")])], + make_header(_T, rows.header.list, [action_header_cell]), + make_lines(_T, uid, rows.table_name, action_name, rows.list, [])) + ] + ) + )) + . + +public define HTML_Partial_Content + view_table_page + ( + (String) -> String _T, + String lang, + String web_site_directory, + String action_name, + VT_view rows + ) = + +// if tb is tool_box(lang, _T, _, _, db, _) then +// println("view_table_page - lang : "+lang); +// println("view_table_page - web_site_directory : "+web_site_directory); + with uid = generate_random_string(20)+"_", + partial_content(jq_dialog_init + jq_datetimepicker_init(lang), + [html_wave_box_wide(_T(to_upper(rows.table_name)), + sequence([ + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), + 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)) + ]))]). + +public define HTML_Partial_Content + view_table + ( + (String) -> String _T, + String lang, + String web_site_directory, + String action_name, + VT_view rows + ) = + +// if tb is tool_box(lang, _T, _, _, db, _) then +// println("view_table_page - lang : "+lang); +// println("view_table_page - web_site_directory : "+web_site_directory); + with uid = generate_random_string(20)+"_", + partial_content(jq_dialog_init + jq_datetimepicker_init(lang), + [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))]). + +public define Maybe(HTML_Partial_Content) + view_table_content + ( + SQLite3DataBase db, + (String) -> String _T, + String lang, + String web_site_directory, + String table, + String view_name, + String action_name, + String clause, + VTM vtm + ) = + if vtm_get_view(table, vtm.view_list) is + { + failure then failure, + success(vtm_v) then + since vtm_v is vtm_view(_, get_view), + success(view_table_page(_T, lang, web_site_directory, action_name, get_view(db, view_name, clause))) + }. +public define Maybe(HTML_Partial_Content) + view_table_only + ( + SQLite3DataBase db, + (String) -> String _T, + String lang, + String web_site_directory, + String table, + String view_name, + String action_name, + String clause, + VTM vtm + ) = + if vtm_get_view(table, vtm.view_list) is + { + failure then failure, + success(vtm_v) then + since vtm_v is vtm_view(_, get_view), + success(view_table(_T, lang, web_site_directory, action_name, get_view(db, view_name, clause))) + }. + define CXM_Form_Field help_line ( @@ -94,9 +270,9 @@ public define List(CXM_Form_Field) ], foreign_text(s_name, c_name, value, select, help) then - [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)], + [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)], choices_text(s_name, c_name, value, select, help) then - [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)], + [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)], text_area(s_name, c_name, value, txt_editor, help) then with id = if txt_editor is { none then "", rich_editor then c_name+"_editor"}, [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) float(s_name, c_name, value, help) then [input(label(_T(s_name), no_help), wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)], choices_int(s_name, c_name, value, select, help) then - [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)], + [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)], date(s_name, c_name, value, help) then [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)], time(s_name, c_name, value, help) then @@ -150,18 +326,22 @@ public define HTML_Partial_Content SQLite3DataBase db, (String) -> String _T, String lang, + String web_site_directory, List(Web_arg) lwa, - VT_edit vt_elist + VT_edit vt_elist, + VTM vtm ) = with table_name = vt_elist.table_name, //true if need to create row or false for updating with create = if get_String(lwa, "id","none") = "none" then true else false, + with id = get_String(lwa, "id","none"), with button_name = if create then _T("CREATE") else _T("UPDATE"), with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"), partial_content( jq_datetimepicker_init(lang) + get_editor_header(vt_elist.list), //add editor header if need. Like init ck_editor + sequence([ cxm_form( table_name, lwa, edit_form_lines(db, _T, vt_elist.list, create, [])+ [ one_line_fields([ @@ -170,6 +350,20 @@ public define HTML_Partial_Content submit(hk_cancel, failure, _T("CANCEL")) ]) ] + )]+ + if id = "none" then + [] + else + map( (HK_V_Edit_Tab tab) + |-> + since tab is hk_v_edit_tab(fk_table_name, fk_col_name, list_view_name), + if view_table_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", fk_col_name+" = "+id, vtm) is + { + failure then empty, + success(p_content) then partial(p_content) + } + //text("Foreign Key from table ["+fk_table_name+"] columns ["+fk_col_name+"] view to use ["+list_view_name+"]") + ,vt_elist.tabs) )). public define Maybe(HTML_Partial_Content) @@ -178,10 +372,11 @@ public define Maybe(HTML_Partial_Content) SQLite3DataBase db, (String) -> String _T, String lang, + String web_site_directory, List(Web_arg) lwa, - String table, - String view_name, - VT_action action, + String table, //table name + String view_name, //view name to use + VT_action action, //new_entry or edit an existing record VTM vtm ) = if vtm_get_edit(table, vtm.edit_list) is @@ -189,140 +384,7 @@ public define Maybe(HTML_Partial_Content) failure then failure, success(vtm_e) then since vtm_e is vtm_edit(_, get_edit), - success(edit_table_page(db, _T, lang, lwa, get_edit(db, action, view_name))) - }. - - - // View table part -define HTML_Row(HTML_Off_Form) make_line - ( - String table_name, - String _action_name, //default is "edit_table", but can be surcharged for own use - List(VT_view_entry) entries, - List(HTML_Cell(HTML_Off_Form)) so_far - )= - if entries is - { - [] then row( [], reverse(so_far)), - [h . t] then - with cell = if h is - { - text(string) then cell((HTML_Off_Form)text(not_null_String(string))), -// link(id, string) then cell((HTML_Off_Form)actioner(same,same, link(string), action_name, [("table_name", table_name),("id",id)])), - link(id, string) then cell((HTML_Off_Form)literal(jq_dialog_open(string, dialog_id(_action_name+"_dlg_ajax"), "'id="+id+"'"))), - link_id_action(id, name, action) then cell((HTML_Off_Form)actioner(same,same, link(name), action, [("id",id)])), - icon(icon_path) then cell((HTML_Off_Form)image([], icon_path, "")) - }, - make_line(table_name, _action_name, t, [cell . so_far]) + success(edit_table_page(db, _T, lang, web_site_directory, lwa, get_edit(db, action, view_name), vtm)) }. -define List(HTML_Row(HTML_Off_Form)) - make_lines - ( - (String) -> String _T, //translator - String table_name, - String action_name, - List(VT_view_row) entries, - List(HTML_Row(HTML_Off_Form)) so_far - )= - if entries is - { - [] then reverse(so_far), - [h . t] then - //compute each line - //prepare here the first cell for actioner - with actions_cell = (HTML_Cell(HTML_Off_Form)) - cell([], - sequence([ - 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))])))))), - partial(img_button(icn16_edit, [event(onclick, jq_dialog_open(dialog_id(action_name+"_dlg_ajax"), "'id="+to_String(h.db_id)+"'"))], "", [])), - ]) - ), - make_lines(_T, table_name, action_name, t, [make_line(table_name, action_name, h.list, [actions_cell]). so_far] ) - }. - // View table part -define HTML_Header_Row(HTML_Off_Form) - make_header - ( - (String) -> String _T, //translator - List(VT_view_entry) entries, - List(HTML_Header_Cell(HTML_Off_Form)) so_far - )= - if entries is - { - [] then header_row( [], reverse(so_far)), - [h . t] then - with cell = if h is - { - text(string) then header_cell((HTML_Off_Form)text(_T(string))), - link(id, string) then header_cell((HTML_Off_Form)actioner(same, same, link(string), edit_table,[])), //TODO - link_id_action(id, text, action) then header_cell((HTML_Off_Form)actioner(same,same, link(text), action,[("id",id)])), //TODO - icon(icon_path) then header_cell((HTML_Off_Form)image([], icon_path, "")) - }, - make_header(_T, t, [cell . so_far]) - }. - - - -public define HTML_Partial_Content - view_table_form - ( - (String) -> String _T, - String action_name, - VT_view rows - )= - with action_header_cell = header_cell((HTML_Off_Form)text(_T("ACTION"))), - partial_content( - div( [/*class("tableau")*/], - sequence( - [ - partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(action_name+"_dlg_ajax")))], "", [])), - //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)))))), - //dialog used by datatable entries - partial(jq_dialog_create(dialog_id(action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+rows.table_name)))), - - table([core_attrs([id("table_view"), class("tableau display compact nowrap")])], - make_header(_T, rows.header.list, [action_header_cell]), - make_lines(_T, rows.table_name, action_name, rows.list, [])) - ] - ) - )) - . - -public define HTML_Partial_Content - view_table_page - ( - (String) -> String _T, - String lang, - String web_site_directory, - String action_name, - VT_view rows - ) = - -// if tb is tool_box(lang, _T, _, _, db, _) then -// println("view_table_page - lang : "+lang); -// println("view_table_page - web_site_directory : "+web_site_directory); - partial_content(jq_dialog_init + jq_datetimepicker_init(lang), - [partial(html_wave_box_wide(_T(to_upper(rows.table_name)), - 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)))]). - -public define Maybe(HTML_Partial_Content) - view_table_content - ( - SQLite3DataBase db, - (String) -> String _T, - String lang, - String web_site_directory, - String table, - String view_name, - String action_name, - VTM vtm - ) = - if vtm_get_view(table, vtm.view_list) is - { - failure then failure, - success(vtm_v) then - since vtm_v is vtm_view(_, get_view), - success(view_table_page(_T, lang, web_site_directory, action_name, get_view(db, view_name))) - }. diff --git a/view/view_table_types.anubis b/view/view_table_types.anubis index a721cf2..2ab2ac2 100644 --- a/view/view_table_types.anubis +++ b/view/view_table_types.anubis @@ -10,7 +10,7 @@ transmit calexium_lib/web/CXM_common.anubis read hayamiki_lib/types/hayamiki.anubis public type VT_edit_selector: - vt_edit_selector((SQLite3DataBase db) -> List((List(CoreAttrs), WebArgValue, String)) get). + vt_edit_selector((SQLite3DataBase db, String clause) -> List((List(CoreAttrs), WebArgValue, String)) get). public type VT_edit_entry: -- libgit2 0.21.4