Commit 8abaa6f5ddef4dc974b002dd097b09b9fa761f74

Authored by totoro
1 parent cb2a37a5

add searchable fields in generation of foreign key

add generation of the hk_table_controller_list
calexium_lib @ 27e8cf1ccd9
1   -Subproject commit 647c64d2796d0c141d54b63c306ed534256acd46
  1 +Subproject commit 27e8cf1ccd9efc33d9c8bf4a247dfc0d3e5dbe7a
... ...
hayamiki_lib @ c35a0960043
1   -Subproject commit ea8ac774861113dbba1ab39abce5f5bb570287a1
  1 +Subproject commit c35a09600434ab87f1e00cb454b97dd668d99ccb
... ...
src/check.anubis
... ... @@ -42,7 +42,8 @@ define Maybe(HK_Model_Column)
42 42 HK_Model_Column col
43 43 )=
44 44 since col is hk_column(name, type, attrib, help),
45   - if type is foreign_key(fk_app, fk_table) then
  45 + if type is foreign_key(fk_app, fk_table, fields) then
  46 + //TODO check for searchable fields if exists in foreign table
46 47 with mb_fk_app = if (fk_app) is
47 48 {
48 49 this then println("this found replaced by "+current_app_name+" in app '"+current_app_name+"' table '"+table_name+"' column '"+name+"'");
... ... @@ -58,7 +59,7 @@ define Maybe(HK_Model_Column)
58 59 if mb_fk_app is
59 60 {
60 61 failure then failure,
61   - success(n_fk_app) then success(hk_column(name, foreign_key(if (fk_app) is app_name(_) then app_name(n_fk_app) else fk_app, (if length(n_fk_app)>0 then n_fk_app+"_"else "")+fk_table), attrib, help))
  62 + success(n_fk_app) then success(hk_column(name, foreign_key(if (fk_app) is app_name(_) then app_name(n_fk_app) else fk_app, (if length(n_fk_app)>0 then n_fk_app+"_"else "")+fk_table, fields), attrib, help))
62 63 }
63 64 else
64 65 success(col).
... ...
src/generation/choices_selector.anubis
... ... @@ -59,7 +59,8 @@ define Maybe(One)
59 59 " get_choices_selector_"+table_name+"_"+column_name+"\n"+
60 60 " (\n"+
61 61 " SQLite3DataBase db,\n"+
62   - " String clause\n"+
  62 + " HK_Referer referer, //Not used, only there for compatibility\n"+
  63 + " String filter //Not used, only there for compatibility\n"+
63 64 " )=\n"+
64 65 " [\n"+
65 66 concat(map((HK_Int_Choice hk_int_choice) |->
... ...
src/generation/columns.anubis
... ... @@ -146,7 +146,7 @@ public define Maybe(String)
146 146 auto_now_add then
147 147 if insert then success(name) else failure
148 148 },
149   - foreign_key(_,_) then success(name),
  149 + foreign_key(_,_,_) then success(name),
150 150 integer_field(_) then success(name),
151 151 float_field then success(name),
152 152 char_field(_,_) then success(name),
... ... @@ -240,8 +240,12 @@ public define Maybe(String)
240 240 auto_now then success("information(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".datetime, 18, "+to_Anubis_source(help)+")"),
241 241 auto_now_add then success("information(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".datetime, 18, "+to_Anubis_source(help)+")")
242 242 },
243   - foreign_key(app,foreign_table) then success("foreign_text(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"),
244   -
  243 + foreign_key(app,foreign_table,fields) then
  244 + if length(fields) = 0 then
  245 + success("foreign_text(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")")
  246 + else
  247 + with search_fields = join(", ", map((String field) |-> "\""+field+"\"",fields)),
  248 + success("foreign_text_search(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", \""+foreign_table+"\", ["+search_fields+"]"+to_Anubis_source(help)+")"),
245 249  
246 250 integer_field(choices) then
247 251 //success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"),
... ... @@ -317,7 +321,7 @@ public define String
317 321 date_field(attrs) then "to_String("+current_type_name+"."+name+")",
318 322 time_field(attrs) then "to_String("+current_type_name+"."+name+")",
319 323 datetime_field(attrs) then "to_String("+current_type_name+"."+name+")"
320   - foreign_key(app,foreign_table) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")",
  324 + foreign_key(app,foreign_table,_) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")",
321 325 integer_field(_) then "to_String("+current_type_name+"."+name+")",
322 326 float_field then "float_to_string("+current_type_name+"."+name+",5)",
323 327 char_field(_,_) then current_type_name+"."+name,
... ...
src/generation/extractor.anubis
... ... @@ -25,7 +25,7 @@ public define String
25 25 date_field(_) then "db_date(text"+cursor_index+")",
26 26 time_field(_) then "db_time(text"+cursor_index+")",
27 27 datetime_field(_) then "db_datetime(text"+cursor_index+")",
28   - foreign_key(_,_) then "db_id((Int)db_integer"+cursor_index+")",
  28 + foreign_key(_,_,_) then "db_id((Int)db_integer"+cursor_index+")",
29 29 integer_field(_) then "(Int)db_integer"+cursor_index,
30 30 float_field then "db_float"+cursor_index,
31 31 char_field(_,_) then "text"+cursor_index,
... ...
src/generation/fields.anubis
... ... @@ -30,7 +30,7 @@ public define String
30 30 date_field(_) then "DB_date",
31 31 time_field(_) then "DB_time",
32 32 datetime_field(_) then "DB_datetime",
33   - foreign_key(_,_) then "DB_id",
  33 + foreign_key(_,_,_) then "DB_id",
34 34 integer_field(_) then "Int",
35 35 float_field then "Float",
36 36 char_field(_,_) then "String",
... ... @@ -55,7 +55,7 @@ public define String
55 55 date_field(_) then "extern_type(\"DB_date\", \"calexium_lib/database/db_types.anubis\")",
56 56 time_field(_) then "extern_type(\"DB_time\", \"calexium_lib/database/db_types.anubis\")",
57 57 datetime_field(_) then "extern_type(\"DB_datetime\", \"calexium_lib/database/db_types.anubis\")",
58   - foreign_key(_,_) then "extern_type(\"DB_id\", \"calexium_lib/database/db_types.anubis\")",
  58 + foreign_key(_,_,_) then "extern_type(\"DB_id\", \"calexium_lib/database/db_types.anubis\")",
59 59 integer_field(_) then "int",
60 60 float_field then "float",
61 61 char_field(_,_) then "string",
... ... @@ -80,7 +80,7 @@ public define String
80 80 date_field(_) then fill("DATE", 15) + format_attributes(attributes),
81 81 time_field(_) then fill("TIME", 15) + format_attributes(attributes),
82 82 datetime_field(_) then fill("DATETIME", 15) + format_attributes(attributes),
83   - foreign_key(app,fk) then fill("INTEGER", 15) + format_attributes(attributes)+" REFERENCES "+fk+"(id) ",
  83 + foreign_key(app,fk,_) then fill("INTEGER", 15) + format_attributes(attributes)+" REFERENCES "+fk+"(id) ",
84 84 integer_field(_) then fill("INTEGER", 15) + format_attributes(attributes),
85 85 float_field then fill("DOUBLE", 15) + format_attributes(attributes),
86 86 char_field(_,size) then fill("VARCHAR("+size+")", 15) + format_attributes(attributes),
... ... @@ -105,7 +105,7 @@ public define String
105 105 date_field(_) then "db_date(\"\")",
106 106 time_field(_) then "db_time(\"\")",
107 107 datetime_field(_) then "db_datetime(\"\")",
108   - foreign_key(_,_) then "(DB_id)none",
  108 + foreign_key(_,_,_) then "(DB_id)none",
109 109 integer_field(_) then "(Int)0",
110 110 float_field then "(Float)0.0",
111 111 char_field(choices,size) then "\"\"",
... ... @@ -146,7 +146,7 @@ public define String
146 146 else
147 147 ""
148 148 },
149   - foreign_key(_,_) then "bind_DB_id_or_NULL(\":v_"+name+"\", "+type_name+"."+name+")",
  149 + foreign_key(_,_,_) then "bind_DB_id_or_NULL(\":v_"+name+"\", "+type_name+"."+name+")",
150 150 integer_field(_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")",
151 151 float_field then "bind_Float(\":v_"+name+"\", "+type_name+"."+name+")",
152 152 char_field(_,_) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")",
... ...
src/generation/files.anubis
... ... @@ -125,6 +125,7 @@ define Maybe(One)
125 125 List(String) edit,
126 126 List(String) writer,
127 127 List(String) delete,
  128 + List(String) controllers,
128 129 String dest_dir
129 130 )=
130 131 with file_name = dest_dir+"database/generated/vtm.anubis",
... ... @@ -158,6 +159,10 @@ join("\n", transmit)+"\n\n"+
158 159 "public define List(TM_delete)\n"+
159 160 " generated_tm_delete_list =\n"+
160 161 " [\n "+join(",\n ",delete)+"\n"+
  162 +" ].\n\n"+
  163 +"public define List(HK_Table_controller)\n"+
  164 +" generated_hk_table_controller_list =\n"+
  165 +" [\n "+join(",\n ",controllers)+"\n"+
161 166 " ].\n\n"
162 167 ) is //end of the function
163 168 {
... ... @@ -177,6 +182,7 @@ define One
177 182 List(String) so_far_edit,
178 183 List(String) so_far_writer,
179 184 List(String) so_far_delete,
  185 + List(String) so_far_controllers,
180 186 String dest_dir
181 187 )=
182 188 if tables is
... ... @@ -184,9 +190,9 @@ define One
184 190 [] then
185 191 if apps is
186 192 {
187   - [] then forget(generate_vtm_file(so_far_transmit, so_far_view, so_far_edit, so_far_writer, so_far_delete, dest_dir));println("Generation finished"),
  193 + [] then forget(generate_vtm_file(so_far_transmit, so_far_view, so_far_edit, so_far_writer, so_far_delete, so_far_controllers, dest_dir));println("Generation finished"),
188 194 [app . apps_t] then
189   - _make_vtm(apps_t, app.hk_tables, so_far_transmit, so_far_view, so_far_edit, so_far_writer, so_far_delete, dest_dir)
  195 + _make_vtm(apps_t, app.hk_tables, so_far_transmit, so_far_view, so_far_edit, so_far_writer, so_far_delete, so_far_controllers, dest_dir)
190 196  
191 197 },
192 198  
... ... @@ -197,7 +203,19 @@ define One
197 203 with edit = "vtm_edit(\""+name+"\", get_editable_"+name+")",
198 204 with writer = "tm_writer(\""+name+"\", update_"+name+"_from_type, update_"+name+"_from_fields)",
199 205 with delete = "tm_delete(\""+name+"\", delete_"+name+")",
200   - _make_vtm(apps, t, [transmit . so_far_transmit], [view . so_far_view], [edit . so_far_edit], [writer . so_far_writer], [delete . so_far_delete], dest_dir)
  206 + with controller =
  207 +"hk_table_controller(\""+name+"\",
  208 + //Create
  209 + update_"+name+"_from_type,
  210 + update_"+name+"_from_fields,
  211 + //Read
  212 + get_count_"+name+"_by_clause,
  213 + get_all_"+name+"_by_clause_to_json,
  214 + //Delete
  215 + delete_"+name+
  216 +")",
  217 +
  218 + _make_vtm(apps, t, [transmit . so_far_transmit], [view . so_far_view], [edit . so_far_edit], [writer . so_far_writer], [delete . so_far_delete], [controller . so_far_controllers], dest_dir)
201 219 }.
202 220  
203 221 define One
... ... @@ -207,7 +225,7 @@ define One
207 225 String dest_dir
208 226 )
209 227 =
210   - _make_vtm(apps, [], [], [], [], [], [], dest_dir).
  228 + _make_vtm(apps, [], [], [], [], [], [], [], dest_dir).
211 229  
212 230  
213 231 define Maybe(One)
... ...
src/generation/header.anubis
... ... @@ -22,7 +22,7 @@ define Maybe(One)
22 22 [] then success(unique),
23 23 [h . t] then
24 24 since h is hk_column(_, type, _, _),
25   - if type is foreign_key(app, table_name) then
  25 + if type is foreign_key(app, table_name, _) then
26 26 if write_string(stream, "\nread database/generated/"+table_name+".anubis") is
27 27 {
28 28 failure then failure,
... ...
src/generation/html.anubis
... ... @@ -94,7 +94,7 @@ public define String
94 94 date_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name),
95 95 time_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name),
96 96 datetime_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name),
97   - foreign_key(app, foreign_table) then to_HTML_cell_text(column, data_name, general_type_name),
  97 + foreign_key(app, foreign_table,_) then to_HTML_cell_text(column, data_name, general_type_name),
98 98 integer_field(choices) then to_HTML_cell_text(column, data_name, general_type_name),
99 99 float_field then to_HTML_cell_text(column, data_name, general_type_name),
100 100 char_field(choices, size) then to_HTML_cell_text(column, data_name, general_type_name),
... ...
src/generation/icons.anubis
... ... @@ -28,7 +28,7 @@ public define String
28 28 date_field(attrs) then icn16_clock,
29 29 time_field(attrs) then icn16_clock,
30 30 datetime_field(attrs) then icn16_clock,
31   - foreign_key(app,foreign_table) then icn16_question,
  31 + foreign_key(app,foreign_table,_) then icn16_question,
32 32 integer_field(choice) then icn16_question,
33 33 float_field then icn16_question,
34 34 char_field(choice, size) then icn16_question,
... ...
src/generation/json.anubis
... ... @@ -28,7 +28,7 @@ public define String
28 28 date_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
29 29 time_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
30 30 datetime_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
31   - foreign_key(app,foreign_table) then "to_JSON_String(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+"))",
  31 + foreign_key(app,foreign_table,_) then "to_JSON_String(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+"))",
32 32 integer_field(_) then current_type_name+"."+name,
33 33 float_field then "float_to_string("+current_type_name+"."+name+",5)",
34 34 char_field(_,_) then "to_JSON_String("+current_type_name+"."+name+")",
... ... @@ -60,7 +60,7 @@ public define String
60 60 date_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
61 61 time_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
62 62 datetime_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
63   - foreign_key(app,foreign_table) then "json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")))",
  63 + foreign_key(app,foreign_table,_) then "json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")))",
64 64 integer_field(_) then "json_member(\""+name+"\", json_int("+current_type_name+"."+name+"))",
65 65 float_field then "json_member(\""+name+"\", json_float("+current_type_name+"."+name+",5))",
66 66 char_field(_,_) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
... ... @@ -88,7 +88,7 @@ public define String
88 88 date_field(_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))",
89 89 time_field(_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))",
90 90 datetime_field(_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))",
91   - foreign_key(app,foreign_table) then "json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, db_id((Int)db_integer"+cursor_index+"))))",
  91 + foreign_key(app,foreign_table,_) then "json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, db_id((Int)db_integer"+cursor_index+"))))",
92 92 integer_field(_) then "json_member(\""+name+"\", json_int((Int)db_integer"+cursor_index+"))",
93 93 float_field then "json_member(\""+name+"\", json_float(db_float"+cursor_index+",5))",
94 94 char_field(_,_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))",
... ...
src/generation/vt_view.anubis
... ... @@ -49,7 +49,7 @@ define String
49 49 date_field(attrs) then "date(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
50 50 time_field(attrs) then "time(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
51 51 datetime_field(attrs) then "datetime(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")",
52   - foreign_key(app,foreign_table) then "foreign_text(\""+to_upper(name)+"\", \""+name+"\", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")",
  52 + foreign_key(app,foreign_table,_) then "foreign_text(\""+to_upper(name)+"\", \""+name+"\", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")",
53 53 integer_field(choices) then
54 54 if choices is
55 55 {
... ...
src/generation/web_args.anubis
... ... @@ -25,7 +25,7 @@ public define String
25 25 date_field(attrs) then if attrs = none then "get_DB_date(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_date,",
26 26 time_field(attrs) then if attrs = none then "get_DB_time(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_time,",
27 27 datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,",
28   - foreign_key(_,_) then "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),",
  28 + foreign_key(_,_,_) then "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),",
29 29 integer_field(_) then "get_Int(lwa, __prefix__+\""+name+"\")",
30 30 float_field then "get_Float(lwa, __prefix__+\""+name+"\")",
31 31 char_field(_,_) then "get_String(lwa, __prefix__+\""+name+"\")",
... ... @@ -123,7 +123,7 @@ public define String
123 123 "if get_DB_datetime(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Datetime(\":v_"+name+"\", "+name+"))] }"
124 124 else
125 125 "[]",
126   - foreign_key(_,_) then //"with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),",
  126 + foreign_key(_,_,_) then //"with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),",
127 127 "if get_mb_DB_id(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_DB_id_or_NULL(\":v_"+name+"\", "+name+"))] }"
128 128 integer_field(_) then //"get_Int(lwa, __prefix__+\""+name+"\")",
129 129 "if get_Int(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Int(\":v_"+name+"\", "+name+"))] }"
... ...
src/model.3.0.0.anubis
... ... @@ -118,7 +118,7 @@ public define HK_Table production_production_table =
118 118 [
119 119  
120 120 hk_column("date", date_field(none), []),
121   - hk_column("assembler_id", foreign_key(app_name("staff"),"staff"), []),
  121 + hk_column("assembler_id", foreign_key(app_name("staff"),"staff", []), []),
122 122 hk_column("type_ref_id", foreign_key("type_number"), []),
123 123 hk_column("product_ref_id", foreign_key("product_reference"), []),
124 124 hk_column("site_id", foreign_key("production_site"), []),
... ... @@ -176,7 +176,7 @@ public define HK_Table production_purchase_table =
176 176 hk_model(
177 177 [
178 178 hk_column("date", date_field(none), []),
179   - hk_column("buyer_id", foreign_key(app_name("staff"),"staff"), []),
  179 + hk_column("buyer_id", foreign_key(app_name("staff"),"staff", []), []),
180 180 hk_column("supplier_id", foreign_key("supplier"), []),
181 181 hk_column("order_ref", char_field(50), []), //
182 182 hk_column("description", char_field(200), []), // description of the purchase
... ... @@ -243,7 +243,7 @@ public define HK_Table production_supplier_table =
243 243 [
244 244  
245 245 hk_column("company", char_field(100), []),
246   - hk_column("contact_id", foreign_key(none, "address_book_contact"), []),
  246 + hk_column("contact_id", foreign_key(none, "address_book_contact", []), []),
247 247 hk_column("address1", char_field(100), []),
248 248 hk_column("address2", char_field(100), []),
249 249 hk_column("zipcode", char_field(10), []),
... ... @@ -334,7 +334,7 @@ public define HK_Table staff_table =
334 334 hk_model(
335 335 [
336 336  
337   - hk_column("contact_id", foreign_key(none, "address_book_contact"), []),
  337 + hk_column("contact_id", foreign_key(none, "address_book_contact", []), []),
338 338 hk_column("department_id", foreign_key("department"), []),
339 339 hk_column("role_id", foreign_key("role"), []),
340 340 hk_column("email", email_field, []),
... ...