Commit 4d677a6833d4c02037f913f30dd460500a390bf1

Authored by totoro
1 parent 8bc8e53d

Add VTM (Virtual Table Management) system for management of Database table (SQLi…

…te3 for the moment). This generate automatically the web content for viewing data in table, editing and writing into database.
database/vtm/view_table_manager.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: Totoro
  4 + * Date: 16/11/2011
  5 + * Time: 23:53
  6 + */
  7 +
  8 +read tools/basis.anubis
  9 +read calexium_lib/database/vtm/view_table_types.anubis
  10 +read calexium_lib/database/vtm/view_table_manager_types.anubis
  11 +
  12 +public define Maybe(VTM_view)
  13 + _vtm_get_view
  14 + (
  15 + String table_name,
  16 + List(VTM_view) list
  17 + ) =
  18 + if list is
  19 + {
  20 + [] then println("_vtm_get_view "+table_name+" not found"); failure,
  21 + [ h . t ] then
  22 + if h is vtm_view(tb_name, get_view) then
  23 + if tb_name = table_name then
  24 + success(h)
  25 + else
  26 + _vtm_get_view(table_name, t)
  27 + }.
  28 +
  29 +public define Maybe(VTM_view)
  30 + vtm_get_view
  31 + (
  32 + String table_name,
  33 + VTM_view_list vtm_vlist
  34 + ) =
  35 + _vtm_get_view(table_name, vtm_vlist.list).
  36 +
  37 +
  38 +public define Maybe(VTM_edit)
  39 + _vtm_get_edit
  40 + (
  41 + String table_name,
  42 + List(VTM_edit) list
  43 + ) =
  44 + if list is
  45 + {
  46 + [] then failure,
  47 + [ h . t ] then
  48 + if h is vtm_edit(tb_name, get_edit) then
  49 + if tb_name = table_name then
  50 + success(h)
  51 + else
  52 + _vtm_get_edit(table_name, t)
  53 + }.
  54 +
  55 +public define Maybe(VTM_edit)
  56 + vtm_get_edit
  57 + (
  58 + String table_name,
  59 + VTM_edit_list vtm_vlist
  60 + ) =
  61 + _vtm_get_edit(table_name, vtm_vlist.list).
  62 +
  63 +public define Maybe(TM_writer)
  64 + _tm_get_writer
  65 + (
  66 + String table_name,
  67 + List(TM_writer) list
  68 + ) =
  69 + if list is
  70 + {
  71 + [] then failure,
  72 + [ h . t ] then
  73 + if h is tm_writer(tb_name, get_writer) then
  74 + if tb_name = table_name then
  75 + success(h)
  76 + else
  77 + _tm_get_writer(table_name, t)
  78 + }.
  79 +
  80 +public define Maybe(TM_writer)
  81 + tm_get_writer
  82 + (
  83 + String table_name,
  84 + TM_writer_list tm_wlist
  85 + ) =
  86 + _tm_get_writer(table_name, tm_wlist.list).
database/vtm/view_table_manager_types.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: Totoro
  4 + * Date: 17/11/2011
  5 + * Time: 00:32
  6 + *
  7 + */
  8 +
  9 +read calexium_lib/database/vtm/view_table_types.anubis
  10 +read calexium_lib/web/CXM_common.anubis
  11 +
  12 +public type VTM_edit:
  13 + vtm_edit(String table_name, (SQLite3DataBase db, VT_action action) -> VT_edit get_edit).
  14 +
  15 +public type VTM_edit_list:
  16 + vtm_edit_list(List(VTM_edit) list).
  17 +
  18 +public type TM_writer:
  19 + tm_writer(String table_name, (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(One) write).
  20 +
  21 +public type TM_writer_list:
  22 + tm_writer_list(List(TM_writer) list).
  23 +
  24 +
  25 +public type VTM_view:
  26 + vtm_view(String table_name, (SQLite3DataBase db) -> VT_view get_view).
  27 +
  28 +public type VTM_view_list:
  29 + vtm_view_list(List(VTM_view) list).
  30 +
  31 +public type VTM:
  32 + vtm(VTM_view_list view_list, VTM_edit_list edit_list, TM_writer_list writer_list).
database/vtm/view_table_renderer.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: Totoro
  4 + * Date: 30/11/2011
  5 + * Time: 21:22
  6 + *
  7 + */
  8 +
  9 +read calexium_lib/database/vtm/view_table_types.anubis
  10 +read calexium_lib/database/vtm/view_table_manager_types.anubis
  11 +read calexium_lib/database/vtm/view_table_manager.anubis
  12 +
  13 +read system/string.anubis
  14 +read locale/L3.anubis
  15 +read tools/basis.anubis
  16 +
  17 +read system_colors/rgb.anubis
  18 +read system/convert.anubis
  19 +
  20 +//read utils.anubis
  21 +read locale/L3LanguageInfo.anubis
  22 +read calexium_lib/web/CXM_common.anubis
  23 +read calexium_lib/web/CXM_making_a_web_site.anubis
  24 +read calexium_lib/web/CXM_multihost_http_server.anubis
  25 +read calexium_lib/web/jQuery/CXM_jquery_datatable.anubis
  26 +read calexium_lib/web/jQuery/CXM_jquery_datatable_types.anubis
  27 +read calexium_lib/web/jQuery/ui-addon/datetimepicker.anubis
  28 +read calexium_lib/web/CXM_form.anubis
  29 +read calexium_lib/web/widgets/css_helper.anubis
  30 +
  31 +
  32 + //Edit table part
  33 +public define List(CXM_Form_Field)
  34 + edit_form_lines
  35 + (
  36 + SQLite3DataBase db,
  37 + (String) -> String _T,
  38 + List(VT_edit_entry) list,
  39 + List(CXM_Form_Field) so_far
  40 + )=
  41 + if list is
  42 + {
  43 + [] then reverse(so_far),
  44 + [ h . t] then
  45 + with line =
  46 + if h is
  47 + {
  48 + hidden(name, value) then
  49 + print("hidden "+name+" = "+value);
  50 + hidden(htmlId(""), wan(name), init(value)),
  51 + primary_key(idx) then
  52 + hidden(htmlId(""), wan("id"), init(idx)),
  53 + information(s_name, c_name, value) then
  54 + input_readonly(_T(s_name), wan(c_name), init(value), narrow),
  55 + text(s_name, c_name, value) then
  56 + input(_T(s_name), wan(c_name), init(value), narrow, mandatory),
  57 + foreign_text(s_name, c_name, value, select) then
  58 + selector_c([],_T(s_name), htmlId(""), wan(c_name), 1, select.get(db), success(init(to_String(value))), mandatory),
  59 + text_area(s_name, c_name, value) then
  60 + text_area([],_T(s_name), htmlId(""), wan(c_name), init(value), narrow, (Int)5, mandatory),
  61 + boolean(s_name, c_name, value) then
  62 + checkboxr([],_T(s_name), htmlId(""), wan(c_name), wav(c_name),value, mandatory),
  63 + integer(s_name, c_name, value) then
  64 + input(_T(s_name), wan(c_name), init(abs_to_decimal(value)), small, mandatory)
  65 + date(s_name, c_name, value) then
  66 + input([class("datepicker")], _T(s_name), htmlId(c_name), wan(c_name), init(value), narrow, non_mandatory),
  67 + datetime(s_name, c_name, value) then
  68 + input([class("datetimepicker")], _T(s_name), htmlId(c_name), wan(c_name), init(value), narrow, mandatory),
  69 + },
  70 + edit_form_lines(db, _T, t, [line . so_far])
  71 + }.
  72 +
  73 +public define HTML_Partial_Content
  74 + edit_table_page
  75 + (
  76 + SQLite3DataBase db,
  77 + (String) -> String _T,
  78 + String lang,
  79 + VT_edit vt_elist
  80 + ) =
  81 + //if tb is tool_box(lang, _T, _, _, db, _) then
  82 + with table_name = vt_elist.table_name,
  83 + partial_content(jq_datetimepicker_init(lang),
  84 + partial(html_wave_box(
  85 + _T(to_upper(table_name)),
  86 + cxm_form( table_name, htmlId(table_name),
  87 + edit_form_lines(db, _T, vt_elist.list, [])+
  88 + [ submit("create", failure, _T("CREATE"), [("table_name", table_name)]) ]
  89 + )))).
  90 +
  91 +public define Maybe(HTML_Partial_Content)
  92 + edit_table_content
  93 + (
  94 + SQLite3DataBase db,
  95 + (String) -> String _T,
  96 + String lang,
  97 + String table,
  98 + VT_action action,
  99 + VTM vtm
  100 + ) =
  101 + if vtm_get_edit(table, vtm.edit_list) is
  102 + {
  103 + failure then failure,
  104 + success(vtm_e) then
  105 + since vtm_e is vtm_edit(_, get_edit),
  106 + success(edit_table_page(db, _T, lang, get_edit(db, action)))
  107 + }.
  108 +
  109 +
  110 + // View table part
  111 +define HTML_Row(HTML_Off_Form) make_line
  112 + (
  113 + //ToolBox tb,
  114 + String table_name,
  115 + String action_name, //default is "edit_table", but can be surcharged for own use
  116 + List(VT_view_entry) entries,
  117 + List(HTML_Cell(HTML_Off_Form)) so_far,
  118 + Int odd_even
  119 + )=
  120 + if entries is
  121 + {
  122 + [] then
  123 + with line = if odd_even = 0 then "tr_even" else "tr_odd",
  124 + row( [core_attrs([class(line)])], reverse(so_far)),
  125 + [h . t] then
  126 + with cell = if h is
  127 + {
  128 + text(string) then cell((HTML_Off_Form)text(string)),
  129 + link(id, string) then cell((HTML_Off_Form)actioner(same,same, link(string), action_name, [("table_name", table_name),("id",id)]))
  130 + },
  131 + make_line(table_name, action_name, t, [cell . so_far], odd_even)
  132 + }.
  133 +
  134 +define List(HTML_Row(HTML_Off_Form)) make_lines
  135 + (
  136 +// ToolBox tb,
  137 + String table_name,
  138 + String action_name,
  139 + List(VT_view_row) entries,
  140 + List(HTML_Row(HTML_Off_Form)) so_far,
  141 + Int odd_even
  142 + )=
  143 + if entries is
  144 + {
  145 + [] then reverse(so_far),
  146 + [h . t] then make_lines(table_name, action_name, t, [make_line(table_name, action_name, h.list, [], odd_even). so_far], 1 - odd_even )
  147 + }.
  148 +
  149 + // View table part
  150 +define HTML_Header_Row(HTML_Off_Form)
  151 + make_header
  152 + (
  153 + (String) -> String _T, //translator
  154 + List(VT_view_entry) entries,
  155 + List(HTML_Header_Cell(HTML_Off_Form)) so_far
  156 + )=
  157 + //if tb is tool_box(lang, _T, _, _, db, _) then
  158 + if entries is
  159 + {
  160 + [] then header_row( [], reverse(so_far)),
  161 + [h . t] then
  162 + with cell = if h is
  163 + {
  164 + text(string) then header_cell((HTML_Off_Form)text(_T(string))),
  165 + link(id, string) then header_cell((HTML_Off_Form)actioner(same,same, link(string),"edit_table",[])) //TODO
  166 + },
  167 + make_header(_T, t, [cell . so_far])
  168 + }.
  169 +
  170 +
  171 +public define HTML_Partial_Content view_table_form
  172 + (
  173 + (String) -> String _T,
  174 + String action_name,
  175 + VT_view rows
  176 + )=
  177 + //if tb is tool_box(_, _T, _, _, db, _) then
  178 + partial_content(div( [class("tableau")],
  179 + sequence(
  180 + [ actioner(same,same, link([class("my_button")],_T("NEW")),"edit_table",[("table_name", rows.table_name)]),
  181 + table([core_attrs([id("table_view"), class("display compact nowrap")])],
  182 + make_header(_T, rows.header.list, []),
  183 + make_lines(rows.table_name, action_name, rows.list, [], 0))
  184 + ]
  185 + )
  186 + ))
  187 + .
  188 +
  189 +public define HTML_Partial_Content
  190 + view_table_page
  191 + (
  192 + (String) -> String _T,
  193 + String lang,
  194 + String web_site_directory,
  195 + String action_name,
  196 + VT_view rows
  197 + ) =
  198 +
  199 +// if tb is tool_box(lang, _T, _, _, db, _) then
  200 +// println("view_table_page - lang : "+lang);
  201 +// println("view_table_page - web_site_directory : "+web_site_directory);
  202 + partial_content(
  203 + [html_wave_box_wide(_T(to_upper(rows.table_name)),
  204 + jquery_datatable("table_view", view_table_form(_T, action_name, rows), true, false, jq_dt_pt_full_numbers, scrollY(500), true, true, true, lang, no_extra, web_site_directory))]).
  205 +
  206 +public define Maybe(HTML_Partial_Content)
  207 + view_table_content
  208 + (
  209 + SQLite3DataBase db,
  210 + (String) -> String _T,
  211 + String lang,
  212 + String web_site_directory,
  213 + String table,
  214 + String action_name,
  215 + VTM vtm
  216 + ) =
  217 + if vtm_get_view(table, vtm.view_list) is
  218 + {
  219 + failure then failure,
  220 + success(vtm_v) then
  221 + since vtm_v is vtm_view(_, get_view),
  222 + success(view_table_page(_T, lang, web_site_directory, action_name, get_view(db)))
  223 + }.
database/vtm/view_table_types.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: Totoro
  4 + * Date: 15/11/2011
  5 + * Time: 20:32
  6 + */
  7 +
  8 +read calexium_lib/web/CXM_making_a_web_site.anubis
  9 +
  10 +public type VT_edit_selector:
  11 + vt_edit_selector((SQLite3DataBase db) -> List((List(CoreAttrs), WebArgValue, String)) get).
  12 +
  13 +public type VT_edit_entry:
  14 + hidden(String name, String value),
  15 + primary_key(String idx),
  16 + information(String s_name, String c_name, String v_name), //s_name = show_name for translation, v_name = string to show
  17 + text(String s_name, String c_name, String value), //s_name = show_name for translation, c_name = table column name
  18 + foreign_text(String s_name, String c_name, Int selected, VT_edit_selector selector),
  19 + text_area(String s_name, String c_name, String value), //s_name = show_name for translate, c_name = table column name
  20 + boolean(String s_name, String c_name, Bool value),
  21 + integer(String s_name, String c_name, Int value),
  22 + date(String s_name, String c_name, String value),
  23 + datetime(String s_name, String c_name, String value).
  24 +
  25 +public type VT_edit:
  26 + vt_edit(String table_name, List(VT_edit_entry) list).
  27 +
  28 +public type VT_view_entry:
  29 + text(String text),
  30 + link(String id, String text).
  31 +
  32 +public type VT_view_row:
  33 + vt_view_row(List(VT_view_entry) list).
  34 +
  35 +public type VT_view:
  36 + vt_view(String table_name, VT_view_row header, List(VT_view_row) list).
  37 +
  38 +
  39 +public type VT_action:
  40 + new_entry,
  41 + edit_entry(String idx).
  42 +
  43 +public define String default_select = "--------------------". //20 dash
  44 +public define (List(CoreAttrs),WebArgValue,String) selector_default_entry = ([], wav("0"),default_select).