Commit 30bc3c986f18aa29a4061c4bcb51088a043e4d71

Authored by totoro
1 parent f8f2a481

sync with calexium_lib

add the management of short_name in hk_table
add the generation of the menu of application
calexium_lib @ 03b49657664
1   -Subproject commit ec6480d924ed1291d9c5017b8f878104544ae1a6
  1 +Subproject commit 03b4965766405b4dec625516414cd1d6d7785723
... ...
src/check.anubis
... ... @@ -21,7 +21,7 @@ public define Maybe(List(String))
21 21 {
22 22 [] then success(so_far),
23 23 [h . t] then
24   - since h is hk_app(name, _),
  24 + since h is hk_app(name, _, _, _),
25 25 if name:so_far then
26 26 println("The app name "+name+" already exists"); failure
27 27 //'this' is not allowed as app name because the
... ... @@ -94,13 +94,13 @@ define Maybe(List(HK_Table))
94 94 {
95 95 [] then success(reverse(so_far)),
96 96 [h . t] then
97   - since h is hk_table(name, model, display),
  97 + since h is hk_table(name, short_name, model, display),
98 98 since model is hk_model(columns, display_string),
99 99 with table_name = if length(app_name) > 0 then app_name +"_"+name else name,
100 100 if resolve_foreign(apps_name, app_name, table_name, columns, []) is
101 101 {
102 102 failure then failure,
103   - success(checked_model) then resolve_foreign(apps_name, app_name, t, [hk_table(table_name, hk_model(checked_model, display_string), display) . so_far])
  103 + success(checked_model) then resolve_foreign(apps_name, app_name, t, [hk_table(table_name, name, hk_model(checked_model, display_string), display) . so_far])
104 104 }
105 105 }.
106 106  
... ... @@ -110,7 +110,7 @@ define Maybe(HK_App)
110 110 List(String) apps_name,
111 111 HK_App app
112 112 )=
113   - since app is hk_app(name, tables),
  113 + since app is hk_app(name, _, _, tables),
114 114 if resolve_foreign(apps_name, name, tables, []) is
115 115 {
116 116 failure then failure,
... ...
src/generation/create_table.anubis
... ... @@ -41,7 +41,7 @@ define String
41 41 (
42 42 HK_Table table
43 43 )=
44   - since table is hk_table(name, model, display),
  44 + since table is hk_table(name, short_name, model, display),
45 45 since model is hk_model( columns, _),
46 46  
47 47 "\n"+
... ... @@ -68,7 +68,7 @@ define String
68 68 [] then //no more apps to generate
69 69 so_far, //return the all create table generated so far
70 70 [app. t_apps] then //another app available
71   - since app is hk_app(name, app_tables),
  71 + since app is hk_app(name, _, _, app_tables),
72 72 create_table_generate_all_tables(t_apps, app_tables, so_far + "\n /************ TABLES for Application '"+name+"' ***************/")
73 73 },
74 74  
... ... @@ -77,20 +77,7 @@ define String
77 77 create_table_generate_all_tables(apps, t, so_far + create_table_generate_one_table(table))
78 78 }.
79 79  
80   -define Int
81   - longest_table_name_size
82   - (
83   - List(HK_App) apps,
84   - Int current_size
85   - )=
86   - if apps is
87   - {
88   - [] then current_size,
89   - [app . t_apps] then
90   - since app is hk_app(_, tables),
91   - with max_size = max(map((HK_Table table) |-> length(table.name), tables), current_size),
92   - longest_table_name_size(t_apps, max_size)
93   - }.
  80 +
94 81  
95 82 define String
96 83 generate_all_tables_list
... ... @@ -103,7 +90,7 @@ define String
103 90 //hence we can make a beautiful formatting
104 91 with max_space = longest_table_name_size(apps, 0) + 4,
105 92 join(",\n",
106   - map_append((HK_App app) |-> since app is hk_app(_, tables),
  93 + map_append((HK_App app) |-> since app is hk_app(_, _, _, tables),
107 94 map((HK_Table table) |-> indent+"table("+fill("\""+table.name+"\",", max_space)+"create_table_"+table.name+")", tables), apps)).
108 95  
109 96 public define Maybe(One)
... ... @@ -131,10 +118,8 @@ public define Maybe(One)
131 118 if write_string(script_stream,
132 119 "/*
133 120 * Created by 早見木 (Hayamiki).
134   - * User: Automaton
135 121 * Date: "+_Int_to_ISO_8601_date(now)+"
136 122 * Time: "+_Int_to_ISO_8601_time(now)+"
137   - *
138 123 */
139 124 read data_base/sqlite_foreign_key.anubis
140 125 read data_base/db_types.anubis\n"+
... ... @@ -158,10 +143,8 @@ read data_base/db_types.anubis\n"+
158 143 write_string(stream,
159 144 "/*
160 145 * Created by 早見木 (Hayamiki).
161   - * User: Automaton
162 146 * Date: "+_Int_to_ISO_8601_date(now)+"
163 147 * Time: "+_Int_to_ISO_8601_time(now)+"
164   - *
165 148 */
166 149 *
167 150 read tools/basis.anubis
... ...
src/generation/files.anubis
... ... @@ -16,6 +16,7 @@ read tools/ISO-8601.anubis
16 16 read generation/header.anubis
17 17 read generation/types.anubis
18 18 read generation/create_table.anubis
  19 +read generation/menu.anubis
19 20 read check.anubis
20 21  
21 22 define Maybe(One)
... ... @@ -24,12 +25,12 @@ define Maybe(One)
24 25 HK_Table org_table
25 26 )
26 27 =
27   - since org_table is hk_table(name, old_model, display),
  28 + since org_table is hk_table(name, short_name, old_model, display),
28 29 since old_model is hk_model(columns, show_string),
29   - since display is db_display(list_view, list_edit),
  30 + since display is hk_display(list_view, list_edit),
30 31  
31 32 with model = hk_model([hk_column("id", p_key, []). columns], show_string ),
32   - with table = hk_table(name, model, display),
  33 + with table = hk_table(name, short_name, model, display),
33 34 println("Generating file for table ["+name+"]");
34 35 with file_name = "database/generated/"+name+".anubis",
35 36  
... ... @@ -78,7 +79,7 @@ define One
78 79 (
79 80 List(HK_App) apps
80 81 )=
81   - map_forget((HK_App app) |-> since app is hk_app(app_name, tables),
  82 + map_forget((HK_App app) |-> since app is hk_app(app_name, _, _, tables),
82 83 println("generating tables for App ["+app_name+"]");
83 84 make_all_tables(tables), apps).
84 85  
... ... @@ -149,7 +150,7 @@ define One
149 150 },
150 151  
151 152 [table . t] then
152   - since table is hk_table(name, _, _),
  153 + since table is hk_table(name, _, _, _),
153 154 with transmit = "transmit "+name+".anubis",
154 155 with view = "vtm_view(\""+name+"\", get_viewable_"+name+")",
155 156 with edit = "vtm_edit(\""+name+"\", get_editable_"+name+")",
... ... @@ -184,6 +185,8 @@ public define One
184 185 make_vtm(apps);
185 186 println("Generating create for Database "+name);
186 187 if generate_create_table(apps) is failure then println("failure") else
  188 + println("Generating menu for Database "+name);
  189 + if generate_menus(apps) is failure then println("failure") else
187 190 unique
188 191 }.
189 192  
... ...
src/generation/menu.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ
  4 + * Date: 06/02/2016
  5 + * Time: 15:40
  6 + * © Calexium
  7 + */
  8 +read calexium_lib/database/model/db_model.anubis
  9 +read tools/basis.anubis
  10 +read tools/int.anubis
  11 +read system/string.anubis
  12 +read system/files.anubis
  13 +read tools/streams.anubis
  14 +read tools/ISO-8601.anubis
  15 +
  16 +
  17 +define String
  18 + generate_application_menu
  19 + (
  20 + List(HK_App) apps,
  21 +// List(HK_Table) tables, //list of the table model description
  22 + String indent
  23 + )=
  24 + // hk_menu_list("111", help_text("222"),
  25 + // [
  26 + // hk_menu_item("production_mass_storage", "view_table", "CURRENT", [("table_name", "production_mass_storage", ),("view_name", "current")]),
  27 +
  28 + //calculate then longest table name and add 4 for enclosed quote + coma + final space
  29 + //hence we can make a beautiful formatting
  30 + with max_space = longest_table_name_size(apps, 0) + 4,
  31 +
  32 + join(",\n",
  33 + map((HK_App app) |-> since app is hk_app(app_name, icon, help, tables),
  34 + indent+"hk_menu_list("+to_String(icon)+", "+
  35 + //determine if there is help text for app. If not we use the App name as menu entry
  36 + with app_menu_name = if help is no_help_text then help_text(to_upper(if app_name ="" then "base" else app_name)) else help,
  37 + to_Anubis_source(app_menu_name)+",\n"+indent+"[\n"+
  38 + join(",\n",
  39 + map_append((HK_Table table) |->
  40 + since table is hk_table(table_name, short_name, model, display),
  41 + since display is hk_display(list_views, _),
  42 + map((HK_List_View view ) |->
  43 + with view_name = if view is list_view(v_name, _) then v_name else "default",
  44 + indent+" "+"hk_menu_item("+fill_or_cut("\""+table_name+"\",",max_space, ' ')+ "\"view_table\", "+
  45 + fill_or_cut("\""+short_name+(if view_name="default" then "" else " "+view_name)+"\",",max_space, ' ')+
  46 + "[(\"table_name\", "+fill_or_cut("\""+table_name+"\",",max_space, ' ')+"),(\"view_name\", \""+view_name+"\")])", list_views), tables))+"\n"+indent+"])", apps)).
  47 +
  48 +
  49 +public define Maybe(One)
  50 + generate_menus
  51 + (
  52 + List(HK_App) apps //list of the table model description
  53 + )=
  54 +
  55 + with file_name = "web_pages/generated/apps_menu.anubis",
  56 +
  57 + //create all necessary directories if doesn't exist.
  58 + make_directories(file_name);
  59 +
  60 + //create script file name as new file. Previous file with same name will be erased
  61 + if file(file_name, new) is
  62 + {
  63 + failure then println("Can't create menu "+file_name);failure,
  64 + success(fd) then
  65 + with stream = make_stream(fd),
  66 +
  67 + write_string(stream,
  68 +"/*
  69 + * Created by 早見木 (Hayamiki).
  70 + * Date: "+_Int_to_ISO_8601_date(now)+"
  71 + * Time: "+_Int_to_ISO_8601_time(now)+"
  72 + */
  73 +
  74 +transmis calexium_lib/database/model/db_model.anubis
  75 +transmit types/hk_menu_types.anubis
  76 +
  77 +public define HK_Menu
  78 + admin_menu
  79 + =
  80 +hk_menu([
  81 + hk_menu_item(\"\", \"\", \"HOME\", []),
  82 + hk_menu_list(\"managers\", help_text_TAG(\"APPLICATIONS\"),
  83 + [\n"+
  84 + generate_application_menu(apps, " ")+"\n
  85 + ]),
  86 + ]
  87 +).\n")
  88 + }
  89 +
  90 +.
... ...
src/generation/types.anubis
... ... @@ -34,7 +34,7 @@ public define Maybe(One)
34 34 Stream stream,
35 35 HK_Table table
36 36 )=
37   - since table is hk_table(name, model, display),
  37 + since table is hk_table(name, short_name, model, display),
38 38 since model is hk_model(columns, show_string),
39 39 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
40 40  
... ... @@ -69,7 +69,7 @@ public define Maybe(One)
69 69 Stream stream,
70 70 HK_Table table
71 71 )=
72   - since table is hk_table(name, model, _),
  72 + since table is hk_table(name, short_name, model, _),
73 73 since model is hk_model(columns, show_string),
74 74 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
75 75  
... ... @@ -115,7 +115,7 @@ public define Maybe(One)
115 115 Stream stream,
116 116 HK_Table table
117 117 )=
118   - since table is hk_table(name, model, _),
  118 + since table is hk_table(name, short_name, model, _),
119 119 since model is hk_model(columns, _),
120 120 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
121 121 since _generate_extract_web_arg(columns, [], 0) is ((List(String))list_of_web_arg, (Int) nb_closure),
... ... @@ -137,7 +137,7 @@ public define Maybe(One)
137 137 Stream stream,
138 138 HK_Table table
139 139 )=
140   - since table is hk_table(name, model, display),
  140 + since table is hk_table(name, short_name, model, display),
141 141 since model is hk_model(columns, _),
142 142 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
143 143  
... ... @@ -168,7 +168,7 @@ public define Maybe(One)
168 168 Stream stream,
169 169 HK_Table table
170 170 )=
171   - since table is hk_table(name, model, _),
  171 + since table is hk_table(name, short_name, model, _),
172 172 since model is hk_model(columns, _),
173 173 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
174 174  
... ... @@ -211,7 +211,7 @@ public define Maybe(One)
211 211 Stream stream,
212 212 HK_Table table
213 213 )=
214   - since table is hk_table(name, model, _),
  214 + since table is hk_table(name, short_name, model, _),
215 215 since model is hk_model(columns, show_string),
216 216 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
217 217  
... ... @@ -251,7 +251,7 @@ public define Maybe(One)
251 251 Stream stream,
252 252 HK_Table table
253 253 )=
254   - since table is hk_table(name, model, _),
  254 + since table is hk_table(name, short_name, model, _),
255 255 since model is hk_model( columns, _),
256 256 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
257 257  
... ... @@ -307,7 +307,7 @@ public define Maybe(One)
307 307 Stream stream,
308 308 HK_Table table
309 309 )=
310   - since table is hk_table(name, model, _),
  310 + since table is hk_table(name, short_name, model, _),
311 311 since model is hk_model( columns, show_string),
312 312 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
313 313  
... ... @@ -338,7 +338,7 @@ public define Maybe(One)
338 338 Stream stream,
339 339 HK_Table table
340 340 )=
341   - since table is hk_table(name, model, _),
  341 + since table is hk_table(name, short_name, model, _),
342 342 since model is hk_model( columns, show_string),
343 343 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
344 344  
... ... @@ -384,7 +384,7 @@ public define Maybe(One)
384 384 HK_Table table, //
385 385 HK_List_View list_view //list view to generate
386 386 )=
387   - since table is hk_table(table_name, model, display),
  387 + since table is hk_table(table_name, short_name, model, display),
388 388 since model is hk_model( columns, _),
389 389 //since display is db_display(list_view, list_edit),
390 390  
... ... @@ -515,7 +515,7 @@ public define Maybe(One)
515 515 HK_Table table, //
516 516 List(HK_List_View) list_view //list view to generate
517 517 )=
518   - since table is hk_table(table_name, model, display),
  518 + since table is hk_table(table_name, short_name, model, display),
519 519 if write_string(stream,
520 520 "public define VT_view\n"+
521 521 " get_viewable_"+table_name+"\n"+
... ... @@ -537,9 +537,9 @@ public define Maybe(One)
537 537 Stream stream,
538 538 HK_Table table
539 539 )=
540   - since table is hk_table(name, model, display),
  540 + since table is hk_table(name, short_name, model, display),
541 541 since model is hk_model( columns, _),
542   - since display is db_display(list_view, list_edit),
  542 + since display is hk_display(list_view, list_edit),
543 543  
544 544 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
545 545 if _generate_VT_view(stream, table, list_view, false) is //list view to generate
... ... @@ -555,9 +555,9 @@ public define Maybe(One)
555 555 Stream stream,
556 556 HK_Table table
557 557 )=
558   - since table is hk_table(name, model, display),
559   - since model is hk_model( columns, _),
560   - since display is db_display(list_view, list_edit),
  558 + since table is hk_table(name, short_name, model, display),
  559 + since model is hk_model( columns, _),
  560 + since display is hk_display(list_view, list_edit),
561 561 with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
562 562  
563 563 //generate the type of the table that contain all components
... ...
src/model.3.0.0.anubis
... ... @@ -39,7 +39,7 @@ public define HK_Table mf_serial_table =
39 39 ],
40 40 "obj.serial"
41 41 ),
42   - db_display(
  42 + hk_display(
43 43  
44 44 [
45 45 //list_view
... ... @@ -65,7 +65,7 @@ public define HK_Table settings_table =
65 65 ],
66 66 "obj.var_name+\" = \"+obj.var_value"
67 67 ),
68   - db_display(
  68 + hk_display(
69 69 //list_view
70 70 [ list_view_all],
71 71 //list edit
... ... @@ -90,7 +90,7 @@ public define HK_Table django_admin_log_table =
90 90 ],
91 91 "obj.object_repr"
92 92 ),
93   - db_display(
  93 + hk_display(
94 94 //list_view
95 95 [ list_view_all],
96 96 //list edit
... ... @@ -108,7 +108,7 @@ public define HK_Table production_macaddress_table =
108 108 ],
109 109 "obj.mac+\" = MailFountain[\"+obj.mailfountain_id+\"]\""
110 110 ),
111   - db_display(
  111 + hk_display(
112 112 //list_view
113 113 [ list_view_all],
114 114 //list edit
... ... @@ -125,7 +125,7 @@ public define HK_Table production_mass_storage_type_table =
125 125 ],
126 126 "to_String(obj.id)+\":\"+obj.type"
127 127 ),
128   - db_display(
  128 + hk_display(
129 129 //list_view
130 130 [ list_view_all],
131 131 //list edit
... ... @@ -150,7 +150,7 @@ public define HK_Table production_mass_storage_table =
150 150 ],
151 151 "obj.serial"
152 152 ),
153   - db_display(
  153 + hk_display(
154 154 //list_view
155 155 [
156 156 list_view("current",["model_id", "serial", "status", "date_created"])
... ... @@ -189,7 +189,7 @@ public define HK_Table production_mass_storage_model_table =
189 189 ],
190 190 "obj.manufacturer"
191 191 ),
192   - db_display(
  192 + hk_display(
193 193 //list_view
194 194 [
195 195 list_view("default", ["manufacturer", "type_id", "capacity", "tr_min", "last_modified", "date_created"])
... ... @@ -214,7 +214,7 @@ public define HK_Table production_memory_table =
214 214 ],
215 215 "obj.serial"
216 216 ),
217   - db_display(
  217 + hk_display(
218 218 //list_view
219 219 [
220 220 list_view("default", ["serial", "status", "last_modified", "date_created"])
... ... @@ -235,7 +235,7 @@ public define HK_Table production_memory_model_table =
235 235 ],
236 236 "obj.manufacturer"
237 237 ),
238   - db_display(
  238 + hk_display(
239 239 //list_view
240 240 [ list_view_all],
241 241 //list_edit
... ... @@ -252,7 +252,7 @@ public define HK_Table production_memory_type_table =
252 252 ],
253 253 "to_String(obj.id)+\":\"+obj.type"
254 254 ),
255   - db_display(
  255 + hk_display(
256 256 //list_view
257 257 [ list_view_all],
258 258 //list edit
... ... @@ -276,7 +276,7 @@ public define HK_Table production_motherboard_table =
276 276 ],
277 277 "obj.serial"
278 278 ),
279   - db_display(
  279 + hk_display(
280 280 //list_view
281 281 [
282 282 list_view("default", ["serial", "week_fab", "status", "last_modified", "date_created"])
... ... @@ -302,7 +302,7 @@ public define HK_Table production_motherboard_model_table =
302 302 ],
303 303 "obj.name"
304 304 ),
305   - db_display(
  305 + hk_display(
306 306 //list_view
307 307 [
308 308 list_view("default", ["name", "manufacturer", "cpu_model", "cpu_freq"])
... ... @@ -327,7 +327,7 @@ public define HK_Table production_power_supply_table =
327 327 ],
328 328 "obj.serial"
329 329 ),
330   - db_display(
  330 + hk_display(
331 331 //list_view
332 332 [
333 333 list_view("default", ["serial", "status", "date_created", "last_modified"])
... ... @@ -348,7 +348,7 @@ public define HK_Table production_power_supply_model_table =
348 348 ],
349 349 "obj.name"
350 350 ),
351   - db_display(
  351 + hk_display(
352 352 //list_view
353 353 [
354 354 list_view("default", ["name", "manufacturer"])
... ... @@ -378,7 +378,7 @@ public define HK_Table production_product_reference_table =
378 378 ],
379 379 "obj.product_ref+\":\"+obj.product_name"
380 380 ),
381   - db_display(
  381 + hk_display(
382 382 //list_view
383 383 [
384 384 list_view("default", ["type_ref_id", "product_ref", "product_name", "description"])
... ... @@ -415,7 +415,7 @@ public define HK_Table production_products_table =
415 415 ],
416 416 "obj.serial"
417 417 ),
418   - db_display(
  418 + hk_display(
419 419 //list_view
420 420 [
421 421 list_view("default", ["production_id", "date", "serial", "motherboard_id", "app_id", "status"])
... ... @@ -449,7 +449,7 @@ public define HK_Table production_production_table =
449 449 ],
450 450 "date(obj.date)"
451 451 ),
452   - db_display(
  452 + hk_display(
453 453 //list_view
454 454 [
455 455 list_view("default", ["date", "type_ref_id", "sticker_tpl_id", "product_ref_id", "site_id", "product_count", "produced_count"])
... ... @@ -475,7 +475,7 @@ public define HK_Table production_production_site_table =
475 475 ],
476 476 "obj.ref+\":\"+obj.name"
477 477 ),
478   - db_display(
  478 + hk_display(
479 479 //list_view
480 480 [
481 481 list_view("default", ["ref", "name", "city", "country"])
... ... @@ -500,7 +500,7 @@ public define HK_Table production_purchase_table =
500 500 ],
501 501 "date(obj.date)"
502 502 ),
503   - db_display(
  503 + hk_display(
504 504 //list_view
505 505 [
506 506 list_view("default", ["date", "supplier_id", "description"])
... ... @@ -520,7 +520,7 @@ public define HK_Table production_serial_prefix_table =
520 520 ],
521 521 "obj.prefix"
522 522 ),
523   - db_display(
  523 + hk_display(
524 524 //list_view
525 525 [list_view_all],
526 526 //list_edit
... ... @@ -541,7 +541,7 @@ public define HK_Table production_type_number_table =
541 541 ],
542 542 "obj.type_ref+\":\"+obj.description"
543 543 ),
544   - db_display(
  544 + hk_display(
545 545 //list_view
546 546 [
547 547 list_view("default", ["type_ref", "description"])
... ... @@ -576,7 +576,7 @@ public define HK_Table production_supplier_table =
576 576 ],
577 577 "obj.company"
578 578 ),
579   - db_display(
  579 + hk_display(
580 580 //list_view
581 581 [
582 582 list_view("default", ["company", "phone", "mobile", "email"])
... ... @@ -601,7 +601,7 @@ public define HK_Table department_table =
601 601 ],
602 602 "obj.name"
603 603 ),
604   - db_display(
  604 + hk_display(
605 605 //list_view
606 606 [
607 607 list_view("default", ["name"])
... ... @@ -624,7 +624,7 @@ public define HK_Table role_table =
624 624 ],
625 625 "obj.role_name"
626 626 ),
627   - db_display(
  627 + hk_display(
628 628 //list_view
629 629 [
630 630 list_view("default", ["role_name"])
... ... @@ -652,7 +652,7 @@ public define HK_Table staff_table =
652 652 ],
653 653 "obj.email"
654 654 ),
655   - db_display(
  655 + hk_display(
656 656 //list_view
657 657 [
658 658 list_view("default", ["contact_id", "department_id", "role_id", "email"]),
... ... @@ -689,7 +689,7 @@ public define HK_Table address_book_contact_table =
689 689 ],
690 690 "obj.first_name +\" \"+obj.last_name "
691 691 ),
692   - db_display(
  692 + hk_display(
693 693 //list_view
694 694 [
695 695 list_view("short", ["first_name", "last_name", "company"]),
... ...