diff --git a/controller/hk_controller.anubis b/controller/hk_controller.anubis index c871971..fa68d27 100644 --- a/controller/hk_controller.anubis +++ b/controller/hk_controller.anubis @@ -8,7 +8,7 @@ read tools/basis.anubis transmit hayamiki_lib/types/hayamiki.anubis -transmit hayamiki_lib/controller/hk_delete.anubis +//transmit hayamiki_lib/controller/hk_delete.anubis transmit hayamiki_lib/controller/hk_trigger.anubis transmit kayamiki_lib/controller/hk_rows_import.anubis @@ -31,6 +31,7 @@ public type HK_Table_controller: (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(Int) write_from_fields, //Read (SQLite3DataBase db, String clause) -> Int get_count, + //(SQLite3DataBase db, String clause) -> List($T) get_all_by_clause_to_list_type, (SQLite3DataBase db, List(String) columns, Bool resolve_fk, DB_id) -> JsonValue get_one_json, (SQLite3DataBase db, List(String) columns, Bool resolve_fk, HK_Referer referer, String clause, String order_by) -> JsonValue get_rows_json, //Update diff --git a/controller/hk_sql_utils.anubis b/controller/hk_sql_utils.anubis index c6af667..80725e7 100644 --- a/controller/hk_sql_utils.anubis +++ b/controller/hk_sql_utils.anubis @@ -9,6 +9,7 @@ read data_base/sqlite.anubis read calexium_lib/database/db_utils.anubis read hayamiki_lib/types/hayamiki.anubis +transmit hayamiki_lib/controller/hk_controller.anubis public define String referer_to_sql_clause @@ -95,6 +96,62 @@ public define List(Int) } . +public define List(Int) + get_ids_by_clause + ( + SQLite3DataBase db, + String table_name, + String id_col, + String clause + )= + with final_clause = if clause = "" then + "" + else + "WHERE "+clause, + + if sql_query_timeout(db, "SELECT \""+id_col+"\" FROM "+table_name+" "+final_clause+";", [], "get_ids_by_clause") is + { + error(_) then [], + ok(_, cursor, _) then db_get_integer_list(cursor) + } +. + relation_table + id = id of that relation + source_id = id of the first record in relation + target_id = id of the second record in relation + + for example we search the all record targeted by source id + + relation_id | source_id | target_id + ----------------------------------- + 0 | 1 | 1 + 1 | 1 | 2 + 2 | 1 | 4 + 3 | 0 | 2 + + if we want to get all relation from source matching with id 1 we will get a list of ids [1, 2, 4] + + +public define List($T) + get_relation + ( + SQLite3DataBase db, + String relation_table, + String relation_source_id_col, + String relation_target_id_col, + String relation_condition, //only the right part atfer = in SQL format. This means the SQL query will be constructed with "relation_source_id_col = " relation_condition + String foreign_order, + (SQLite3DataBase db, String clause) -> List($T) get_all_by_clause_to_list_type + )= + //get + with ids = get_ids_by_clause(db, relation_table, relation_target_id_col, relation_source_id_col+" = "+relation_condition), + if length(ids) = 0 then + [] + else + with the_clause = " id IN ("+join(", ", to_List_String(ids))+") "+foreign_order, + get_all_by_clause_to_list_type(db, the_clause) +. + public define Maybe(Int) insert_or_update ( diff --git a/view/view_table_renderer.anubis b/view/view_table_renderer.anubis index 6bfa90f..f9e14d0 100644 --- a/view/view_table_renderer.anubis +++ b/view/view_table_renderer.anubis @@ -655,7 +655,7 @@ public define List(CXM_Form_Field) foreign_text(s_name, c_name, value, foreign_table_name, select, help) then with uid = "_"+generate_random_string(20)+"_", with refresh_func = uid+foreign_table_name+"_"+c_name+"_selector_refresh", - with load_script = script("text/javascript","function "+refresh_func+"() { CalexiumToolBox.ajax_load_content('"+uid+foreign_table_name+"_"+c_name+"_selector', '?aws_controller=hk_c&aws_action=selector&table_name="+foreign_table_name+"&fk_filter="+fk_clause+"&selected="+value+"');} "+refresh_func+"(); "), + with load_script = script("text/javascript","function "+refresh_func+"() { CalexiumToolBox.ajax_load_content('"+uid+foreign_table_name+"_"+c_name+"_selector', '?aws_controller=hk_c&aws_action=selector&table_name="+foreign_table_name+"&fk_filter="+fk_clause+"&selected="+value+"&"+to_Web_arg(table_referer, "")+"');} "+refresh_func+"(); "), [ partial(jq_dialog_create(dialog_id(uid+foreign_table_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&dialog_id="+uid+foreign_table_name+"_dlg_ajax&sub_dialog=true&table_name="+foreign_table_name+"&after_close_cb="+refresh_func)))), one_line_fields([ -- libgit2 0.21.4