Commit bba31ce5648894a7568ccf2a4ff080fe4a591dc2
1 parent
ea8ac774
manage the hk_filter for rendreing table in list
add order_by parameter in get_all_XXX_by_clause
Showing
5 changed files
with
158 additions
and
29 deletions
Show diff stats
model/display.anubis
| ... | ... | @@ -31,6 +31,15 @@ public define HK_Viewer |
| 31 | 31 | ( |
| 32 | 32 | String view_name, |
| 33 | 33 | List(String) columns, |
| 34 | + WEB_Action_Name action_name | |
| 35 | + )= | |
| 36 | + list_view(view_name, columns, [], action_name). | |
| 37 | + | |
| 38 | +public define HK_Viewer | |
| 39 | + list_view | |
| 40 | + ( | |
| 41 | + String view_name, | |
| 42 | + List(String) columns, | |
| 34 | 43 | List(HK_Filter) l_filter |
| 35 | 44 | )= |
| 36 | 45 | list_view(view_name, columns, l_filter, no_action). | ... | ... |
view/types/hk_view.anubis
| ... | ... | @@ -94,7 +94,7 @@ public type VT_view_row: |
| 94 | 94 | public type VT_View_DB_Calls: |
| 95 | 95 | vt_view_db_calls( |
| 96 | 96 | (SQLite3DataBase db, String clause) -> Int get_count, |
| 97 | - (SQLite3DataBase db, HK_Referer referer, String clause) -> JsonMember get_rows_json | |
| 97 | + (SQLite3DataBase db, HK_Referer referer, String clause, String order_by) -> JsonMember get_rows_json | |
| 98 | 98 | // (SQLite3DataBase db, String clause) -> List(VT_view_row) get_rows |
| 99 | 99 | ) |
| 100 | 100 | . | ... | ... |
view/view_table_manager_types.anubis
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | |
| 9 | 9 | read hayamiki_lib/view/types/hk_form.anubis |
| 10 | 10 | read hayamiki_lib/view/types/hk_view.anubis |
| 11 | +read hayamiki_lib/view/types/hk_filter.anubis | |
| 11 | 12 | read calexium_lib/web/CXM_common.anubis |
| 12 | 13 | |
| 13 | 14 | public type VTM_edit: |
| ... | ... | @@ -34,7 +35,7 @@ public type TM_delete_list: |
| 34 | 35 | tm_delete_list(List(TM_delete) list). |
| 35 | 36 | |
| 36 | 37 | public type VTM_view: |
| 37 | - vtm_view(String table_name, (String view_name) -> VT_view get_view, (One) -> List(String) get_all_view_name). | |
| 38 | + vtm_view(String table_name, (String view_name) -> VT_view get_view, (One) -> List((String, List(HK_Filter))) get_all_view_name). | |
| 38 | 39 | |
| 39 | 40 | public type VTM_view_list: |
| 40 | 41 | vtm_view_list(List(VTM_view) list). | ... | ... |
view/view_table_renderer.anubis
| ... | ... | @@ -39,31 +39,140 @@ read calexium_lib/web/widgets/css_helper.anubis |
| 39 | 39 | read calexium_lib/web/widgets/button.anubis |
| 40 | 40 | read calexium_lib/web/CXM_urllib.anubis |
| 41 | 41 | |
| 42 | +public define List(HK_Filter) | |
| 43 | + get_view_filters | |
| 44 | + ( | |
| 45 | + String view_name, | |
| 46 | + List((String, List(HK_Filter))) all_view_name | |
| 47 | + )= | |
| 48 | + if all_view_name is | |
| 49 | + { | |
| 50 | + [] then [], | |
| 51 | + [h . t] then | |
| 52 | + since h is (v_name, filters), | |
| 53 | + if v_name = view_name then | |
| 54 | + filters | |
| 55 | + else | |
| 56 | + get_view_filters(view_name, t) | |
| 57 | + } | |
| 58 | +. | |
| 59 | + | |
| 60 | +public define HK_Filter | |
| 61 | + get_default_filter | |
| 62 | + ( | |
| 63 | + VTM_view vtm_v, //virtual table manager view | |
| 64 | + String view_name // | |
| 65 | + )= | |
| 66 | + with all_view_name = vtm_v.get_all_view_name(unique), | |
| 67 | + with filters = get_view_filters(view_name, all_view_name), | |
| 68 | + filter_len = length(filters), | |
| 69 | + | |
| 70 | + if filter_len = 0 then | |
| 71 | + hk_filter("", "") | |
| 72 | + else | |
| 73 | + if filters is | |
| 74 | + { [] then hk_filter("", ""), | |
| 75 | + [h . _] then h | |
| 76 | + } | |
| 77 | +. | |
| 78 | + | |
| 79 | +public define HK_Filter | |
| 80 | + get_filter_from_name | |
| 81 | + ( | |
| 82 | + List(HK_Filter) filters, | |
| 83 | + String _filter_name | |
| 84 | + )= | |
| 85 | + if filters is | |
| 86 | + { | |
| 87 | + [] then hk_filter("", ""), | |
| 88 | + [h . t] then | |
| 89 | + if h.filter_name = _filter_name then | |
| 90 | + h | |
| 91 | + else | |
| 92 | + get_filter_from_name(t, _filter_name) | |
| 93 | + } | |
| 94 | +. | |
| 95 | + | |
| 96 | +public define HK_Filter | |
| 97 | + get_filter_from_name | |
| 98 | + ( | |
| 99 | + VTM_view vtm_v, //virtual table manager view | |
| 100 | + String view_name, // | |
| 101 | + String filter_name | |
| 102 | + )= | |
| 103 | + with all_view_name = vtm_v.get_all_view_name(unique), | |
| 104 | + with filters = get_view_filters(view_name, all_view_name), | |
| 105 | + | |
| 106 | + get_filter_from_name(filters, filter_name) | |
| 107 | +. | |
| 108 | + | |
| 109 | +define HTML_In_Form | |
| 110 | +/* create a selector for choosing the view name. | |
| 111 | + * The selector create an immediate action. This means when the entry is selected, the action is fired. | |
| 112 | + * If only one view exists, the selector is not created | |
| 113 | + */ | |
| 114 | + table_filter_selector | |
| 115 | + ( | |
| 116 | + (String) -> String _T, //translator function | |
| 117 | + List((String, List(HK_Filter))) all_view_name, //virtual table manager view | |
| 118 | + String current_view, // | |
| 119 | + String current_filter | |
| 120 | + )= | |
| 121 | + with filters = get_view_filters(current_view, all_view_name), | |
| 122 | + filter_len = length(filters), | |
| 123 | + println("filter length "+filter_len); | |
| 124 | + | |
| 125 | + if filter_len = 0 then | |
| 126 | + hidden(wan("filter_name"), wav("no_filter")) | |
| 127 | + else if filter_len = 1 then | |
| 128 | + with filter_name = if filters is { [] then "", [h . _] then h.filter_name }, | |
| 129 | + hidden(wan("filter_name"), wav(filter_name)) | |
| 130 | + else | |
| 131 | + actioner(same, same, | |
| 132 | + immediate_selector([id("select_view")], | |
| 133 | + wan("filter_name"), //web arg name of the selected entry | |
| 134 | + 1, | |
| 135 | + map(((HK_Filter) filter) |-> println("selector filter_name "+filter.filter_name); ([], wav(filter.filter_name), _T(filter.filter_name)), filters), | |
| 136 | + success(init(current_filter)), | |
| 137 | + "" | |
| 138 | + ), | |
| 139 | + hkc_list_view_filter, //web_actioner | |
| 140 | + [], []) | |
| 141 | +. | |
| 142 | + | |
| 42 | 143 | define HTML_Off_Form |
| 43 | 144 | /* create a selector for choosing the view name. |
| 44 | 145 | * The selector create an immediate action. This means when the entry is selected, the action is fired. |
| 45 | 146 | * If only one view exists, the selector is not created |
| 46 | 147 | */ |
| 47 | - table_view_selector | |
| 148 | + table_view_filter_selector | |
| 48 | 149 | ( |
| 49 | 150 | (String) -> String _T, //translator function |
| 50 | 151 | VTM_view vtm_v, //virtual table manager view |
| 51 | - String current_view // | |
| 152 | + String current_view, // | |
| 153 | + String current_filter | |
| 52 | 154 | )= |
| 53 | - if length(vtm_v.get_all_view_name(unique)) = 1 then | |
| 54 | - empty | |
| 55 | - else | |
| 56 | - form( "table_view_selector", [], "", [], | |
| 57 | - actioner(same, same, | |
| 58 | - immediate_selector([id("select_view")], | |
| 59 | - wan("view_name"), //web arg name of the selected entry | |
| 60 | - 1, | |
| 61 | - map((String view_name) |-> ([], wav(view_name), _T(view_name)), vtm_v.get_all_view_name(unique)), | |
| 62 | - success(init(current_view)), | |
| 63 | - "" | |
| 64 | - ), | |
| 65 | - hkc_list_view, | |
| 66 | - [("table_name", vtm_v.table_name)], [])) | |
| 155 | + with all_view_name = vtm_v.get_all_view_name(unique), | |
| 156 | + form( "table_view_filter_selector", [], "", [], | |
| 157 | + sequence([ | |
| 158 | + hidden(wan("table_name"), wav(vtm_v.table_name)), | |
| 159 | + (if length(all_view_name) = 1 then | |
| 160 | + empty | |
| 161 | + else | |
| 162 | + actioner(same, same, | |
| 163 | + immediate_selector([id("select_view")], | |
| 164 | + wan("view_name"), //web arg name of the selected entry | |
| 165 | + 1, | |
| 166 | + map(((String, List(HK_Filter)) name_and_filters) |-> since name_and_filters is (view_name, filters), ([], wav(view_name), _T(view_name)), all_view_name), | |
| 167 | + success(init(current_view)), | |
| 168 | + "" | |
| 169 | + ), | |
| 170 | + hkc_list_view_name, //web_actioner | |
| 171 | + [], [] | |
| 172 | + )), //!actionner | |
| 173 | + table_filter_selector(_T, all_view_name, current_view, current_filter) | |
| 174 | + ]) | |
| 175 | + )//!form | |
| 67 | 176 | . |
| 68 | 177 | |
| 69 | 178 | |
| ... | ... | @@ -246,8 +355,9 @@ public define HTML_Partial_Content |
| 246 | 355 | SQLite3DataBase db, |
| 247 | 356 | String uid, |
| 248 | 357 | VT_view rows, |
| 358 | + String filter_name, | |
| 249 | 359 | (String) -> String _T, |
| 250 | - String lang, | |
| 360 | + String lang, | |
| 251 | 361 | String clause, |
| 252 | 362 | HK_Referer table_referer |
| 253 | 363 | )= |
| ... | ... | @@ -273,7 +383,7 @@ public define HTML_Partial_Content |
| 273 | 383 | .autocomplete(\"option\", \"source\", newUniqueValues); |
| 274 | 384 | }; |
| 275 | 385 | $(\"#"+uid+"_grid\").jqGrid({ |
| 276 | -url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+filter_clause+referer_arg+"',"+ | |
| 386 | +url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+"&filter_name="+filter_name+filter_clause+referer_arg+"',"+ | |
| 277 | 387 | "datatype: \"json\", |
| 278 | 388 | "+ |
| 279 | 389 | to_jqGrid_ColModel(db, table_referer, _T, rows.view_model.list)+","+ |
| ... | ... | @@ -329,15 +439,19 @@ public define HTML_Partial_Content |
| 329 | 439 | String action_name, |
| 330 | 440 | VTM_view vtm_v, |
| 331 | 441 | String view_name, |
| 442 | + String filter_name, | |
| 332 | 443 | String f_clause, //filter for current table |
| 333 | 444 | HK_Referer table_referer, |
| 334 | 445 | String fk_clause //filter for foreign key of the table (one to many) |
| 335 | 446 | ) = |
| 447 | + with current_view = vtm_v.get_view(view_name), | |
| 448 | + //with _filter = get_filter_from_name(vtm_v, view_name, filter_name), | |
| 449 | + //with f_clause = if _filter.filter_string = "" then "" else if _f_clause = "" then _filter.filter_string else "("+_filter.filter_string+") AND "+_f_clause, | |
| 336 | 450 | with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause), |
| 337 | 451 | //with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause), |
| 338 | 452 | with referer_arg = "&"+to_Web_arg(table_referer, ""), |
| 339 | 453 | |
| 340 | - with current_view = vtm_v.get_view(view_name), | |
| 454 | + | |
| 341 | 455 | with uid = generate_random_string(20)+"_", |
| 342 | 456 | partial_content([ js(js_file("js/jscolor.min.js")) |
| 343 | 457 | ]+jq_dialog_init + jq_datetimepicker_init(lang), |
| ... | ... | @@ -349,10 +463,10 @@ public define HTML_Partial_Content |
| 349 | 463 | // (+) icon for adding new entry |
| 350 | 464 | partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), |
| 351 | 465 | // view selector if there is more than one view name |
| 352 | - table_view_selector(_T, vtm_v, view_name), | |
| 466 | + table_view_filter_selector(_T, vtm_v, view_name, filter_name), | |
| 353 | 467 | ])), |
| 354 | 468 | //grid with data |
| 355 | - partial(jqGrid_table(db, uid, current_view, _T, lang, f_clause, table_referer)) | |
| 469 | + partial(jqGrid_table(db, uid, current_view, filter_name, _T, lang, f_clause, table_referer)) | |
| 356 | 470 | //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)) |
| 357 | 471 | ]))]). |
| 358 | 472 | |
| ... | ... | @@ -366,6 +480,7 @@ public define HTML_Partial_Content |
| 366 | 480 | String action_name, |
| 367 | 481 | VTM_view vtm_v, |
| 368 | 482 | String view_name, |
| 483 | + String filter_name, | |
| 369 | 484 | String f_clause, //filter for current table |
| 370 | 485 | HK_Referer table_referer, |
| 371 | 486 | String fk_clause //filter for foreign key of the table (one to many) |
| ... | ... | @@ -383,7 +498,7 @@ public define HTML_Partial_Content |
| 383 | 498 | partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+current_view.table_name+filter_clause+referer_arg)))), |
| 384 | 499 | partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), |
| 385 | 500 | //table_view_selector(_T, vtm_v, view_name), |
| 386 | - partial(jqGrid_table(db, uid, current_view, _T, lang, fk_clause, table_referer)), | |
| 501 | + partial(jqGrid_table(db, uid, current_view, filter_name, _T, lang, fk_clause, table_referer)), | |
| 387 | 502 | //partial(jquery_datatable(uid+"table_view", view_table_form(_T, uid, action_name, rows), true, false, jq_dt_pt_full_numbers, false, scrollY(200), true, true, true, lang, no_extra, web_site_directory)) |
| 388 | 503 | ]). |
| 389 | 504 | |
| ... | ... | @@ -394,19 +509,20 @@ public define Maybe(HTML_Partial_Content) |
| 394 | 509 | (String) -> String _T, |
| 395 | 510 | String lang, |
| 396 | 511 | String web_site_directory, |
| 397 | - String table, | |
| 512 | + String table_name, | |
| 398 | 513 | String view_name, |
| 399 | 514 | String action_name, |
| 515 | + String filter_name, | |
| 400 | 516 | String f_clause, |
| 401 | 517 | HK_Referer table_referer, |
| 402 | 518 | String fk_clause, |
| 403 | 519 | VTM vtm |
| 404 | 520 | ) = |
| 405 | - if vtm_get_view(table, vtm.view_list) is | |
| 521 | + if vtm_get_view(table_name, vtm.view_list) is | |
| 406 | 522 | { |
| 407 | 523 | failure then failure, |
| 408 | 524 | success(vtm_v) then |
| 409 | - success(view_table_page(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, table_referer, fk_clause)) | |
| 525 | + success(view_table_page(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, filter_name, f_clause, table_referer, fk_clause)) | |
| 410 | 526 | }. |
| 411 | 527 | |
| 412 | 528 | public define Maybe(HTML_Partial_Content) |
| ... | ... | @@ -418,6 +534,7 @@ public define Maybe(HTML_Partial_Content) |
| 418 | 534 | String web_site_directory, |
| 419 | 535 | String table, |
| 420 | 536 | String view_name, |
| 537 | + String filter_name, | |
| 421 | 538 | String action_name, |
| 422 | 539 | String f_clause, |
| 423 | 540 | HK_Referer table_referer, |
| ... | ... | @@ -428,7 +545,7 @@ public define Maybe(HTML_Partial_Content) |
| 428 | 545 | { |
| 429 | 546 | failure then failure, |
| 430 | 547 | success(vtm_v) then |
| 431 | - success(table_in_list_view(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, table_referer, fk_filter)) | |
| 548 | + success(table_in_list_view(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, filter_name, f_clause, table_referer, fk_filter)) | |
| 432 | 549 | }. |
| 433 | 550 | |
| 434 | 551 | define CXM_Form_Field |
| ... | ... | @@ -647,7 +764,7 @@ public define HTML_Partial_Content |
| 647 | 764 | |-> |
| 648 | 765 | since tab is hk_form_tab(fk_table_name, fk_col_name, list_view_name), |
| 649 | 766 | with referer = hk_referer(table_name, id, fk_table_name, fk_col_name), |
| 650 | - if table_in_list_view_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", "", referer, fk_clause, vtm) is | |
| 767 | + if table_in_list_view_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "", "edit", "", referer, fk_clause, vtm) is | |
| 651 | 768 | { |
| 652 | 769 | failure then empty, |
| 653 | 770 | success(p_content) then partial(p_content) | ... | ... |
view/web_action.anubis
| ... | ... | @@ -15,6 +15,8 @@ public define WEB_Action_Name hkc_view_editor = controller_action("hk_c" |
| 15 | 15 | public define WEB_Action_Name hkc_grid_view = controller_action("hk_c", "grid_view"). |
| 16 | 16 | public define WEB_Action_Name hkc_grid_action = controller_action("hk_c", "grid_action"). |
| 17 | 17 | public define WEB_Action_Name hkc_list_view = controller_action("hk_c", "view_table"). |
| 18 | +public define WEB_Action_Name hkc_list_view_name = controller_action("hk_c", "hkc_list_view_name"). | |
| 19 | +public define WEB_Action_Name hkc_list_view_filter = controller_action("hk_c", "hkc_list_view_filter"). | |
| 18 | 20 | public define WEB_Action_Name hkc_save_row = controller_action("hk_c", "save_row"). |
| 19 | 21 | public define WEB_Action_Name hkc_save_row_and_new = controller_action("hk_c", "save_row_and_new"). |
| 20 | 22 | public define WEB_Action_Name hkc_update_row = controller_action("hk_c", "update_row"). | ... | ... |