From 30bc3c986f18aa29a4061c4bcb51088a043e4d71 Mon Sep 17 00:00:00 2001 From: totoro Date: Tue, 9 Feb 2016 19:35:23 +0100 Subject: [PATCH] sync with calexium_lib add the management of short_name in hk_table add the generation of the menu of application --- calexium_lib | 2 +- src/check.anubis | 8 ++++---- src/generation/create_table.anubis | 25 ++++--------------------- src/generation/files.anubis | 13 ++++++++----- src/generation/menu.anubis | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/generation/types.anubis | 32 ++++++++++++++++---------------- src/model.3.0.0.anubis | 52 ++++++++++++++++++++++++++-------------------------- 7 files changed, 149 insertions(+), 73 deletions(-) create mode 100644 src/generation/menu.anubis diff --git a/calexium_lib b/calexium_lib index ec6480d..03b4965 160000 --- a/calexium_lib +++ b/calexium_lib @@ -1 +1 @@ -Subproject commit ec6480d924ed1291d9c5017b8f878104544ae1a6 +Subproject commit 03b4965766405b4dec625516414cd1d6d7785723 diff --git a/src/check.anubis b/src/check.anubis index 8f0550a..71a2562 100644 --- a/src/check.anubis +++ b/src/check.anubis @@ -21,7 +21,7 @@ public define Maybe(List(String)) { [] then success(so_far), [h . t] then - since h is hk_app(name, _), + since h is hk_app(name, _, _, _), if name:so_far then println("The app name "+name+" already exists"); failure //'this' is not allowed as app name because the @@ -94,13 +94,13 @@ define Maybe(List(HK_Table)) { [] then success(reverse(so_far)), [h . t] then - since h is hk_table(name, model, display), + since h is hk_table(name, short_name, model, display), since model is hk_model(columns, display_string), with table_name = if length(app_name) > 0 then app_name +"_"+name else name, if resolve_foreign(apps_name, app_name, table_name, columns, []) is { failure then failure, - success(checked_model) then resolve_foreign(apps_name, app_name, t, [hk_table(table_name, hk_model(checked_model, display_string), display) . so_far]) + 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]) } }. @@ -110,7 +110,7 @@ define Maybe(HK_App) List(String) apps_name, HK_App app )= - since app is hk_app(name, tables), + since app is hk_app(name, _, _, tables), if resolve_foreign(apps_name, name, tables, []) is { failure then failure, diff --git a/src/generation/create_table.anubis b/src/generation/create_table.anubis index 7ae2a3d..e7b6bdc 100644 --- a/src/generation/create_table.anubis +++ b/src/generation/create_table.anubis @@ -41,7 +41,7 @@ define String ( HK_Table table )= - since table is hk_table(name, model, display), + since table is hk_table(name, short_name, model, display), since model is hk_model( columns, _), "\n"+ @@ -68,7 +68,7 @@ define String [] then //no more apps to generate so_far, //return the all create table generated so far [app. t_apps] then //another app available - since app is hk_app(name, app_tables), + since app is hk_app(name, _, _, app_tables), create_table_generate_all_tables(t_apps, app_tables, so_far + "\n /************ TABLES for Application '"+name+"' ***************/") }, @@ -77,20 +77,7 @@ define String create_table_generate_all_tables(apps, t, so_far + create_table_generate_one_table(table)) }. -define Int - longest_table_name_size - ( - List(HK_App) apps, - Int current_size - )= - if apps is - { - [] then current_size, - [app . t_apps] then - since app is hk_app(_, tables), - with max_size = max(map((HK_Table table) |-> length(table.name), tables), current_size), - longest_table_name_size(t_apps, max_size) - }. + define String generate_all_tables_list @@ -103,7 +90,7 @@ define String //hence we can make a beautiful formatting with max_space = longest_table_name_size(apps, 0) + 4, join(",\n", - map_append((HK_App app) |-> since app is hk_app(_, tables), + map_append((HK_App app) |-> since app is hk_app(_, _, _, tables), map((HK_Table table) |-> indent+"table("+fill("\""+table.name+"\",", max_space)+"create_table_"+table.name+")", tables), apps)). public define Maybe(One) @@ -131,10 +118,8 @@ public define Maybe(One) if write_string(script_stream, "/* * Created by 早見木 (Hayamiki). - * User: Automaton * Date: "+_Int_to_ISO_8601_date(now)+" * Time: "+_Int_to_ISO_8601_time(now)+" - * */ read data_base/sqlite_foreign_key.anubis read data_base/db_types.anubis\n"+ @@ -158,10 +143,8 @@ read data_base/db_types.anubis\n"+ write_string(stream, "/* * Created by 早見木 (Hayamiki). - * User: Automaton * Date: "+_Int_to_ISO_8601_date(now)+" * Time: "+_Int_to_ISO_8601_time(now)+" - * */ * read tools/basis.anubis diff --git a/src/generation/files.anubis b/src/generation/files.anubis index f17ab91..1e7ccdc 100644 --- a/src/generation/files.anubis +++ b/src/generation/files.anubis @@ -16,6 +16,7 @@ read tools/ISO-8601.anubis read generation/header.anubis read generation/types.anubis read generation/create_table.anubis +read generation/menu.anubis read check.anubis define Maybe(One) @@ -24,12 +25,12 @@ define Maybe(One) HK_Table org_table ) = - since org_table is hk_table(name, old_model, display), + since org_table is hk_table(name, short_name, old_model, display), since old_model is hk_model(columns, show_string), - since display is db_display(list_view, list_edit), + since display is hk_display(list_view, list_edit), with model = hk_model([hk_column("id", p_key, []). columns], show_string ), - with table = hk_table(name, model, display), + with table = hk_table(name, short_name, model, display), println("Generating file for table ["+name+"]"); with file_name = "database/generated/"+name+".anubis", @@ -78,7 +79,7 @@ define One ( List(HK_App) apps )= - map_forget((HK_App app) |-> since app is hk_app(app_name, tables), + map_forget((HK_App app) |-> since app is hk_app(app_name, _, _, tables), println("generating tables for App ["+app_name+"]"); make_all_tables(tables), apps). @@ -149,7 +150,7 @@ define One }, [table . t] then - since table is hk_table(name, _, _), + since table is hk_table(name, _, _, _), with transmit = "transmit "+name+".anubis", with view = "vtm_view(\""+name+"\", get_viewable_"+name+")", with edit = "vtm_edit(\""+name+"\", get_editable_"+name+")", @@ -184,6 +185,8 @@ public define One make_vtm(apps); println("Generating create for Database "+name); if generate_create_table(apps) is failure then println("failure") else + println("Generating menu for Database "+name); + if generate_menus(apps) is failure then println("failure") else unique }. diff --git a/src/generation/menu.anubis b/src/generation/menu.anubis new file mode 100644 index 0000000..9f576e9 --- /dev/null +++ b/src/generation/menu.anubis @@ -0,0 +1,90 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ + * Date: 06/02/2016 + * Time: 15:40 + * © Calexium + */ +read calexium_lib/database/model/db_model.anubis +read tools/basis.anubis +read tools/int.anubis +read system/string.anubis +read system/files.anubis +read tools/streams.anubis +read tools/ISO-8601.anubis + + +define String + generate_application_menu + ( + List(HK_App) apps, +// List(HK_Table) tables, //list of the table model description + String indent + )= + // hk_menu_list("111", help_text("222"), + // [ + // hk_menu_item("production_mass_storage", "view_table", "CURRENT", [("table_name", "production_mass_storage", ),("view_name", "current")]), + + //calculate then longest table name and add 4 for enclosed quote + coma + final space + //hence we can make a beautiful formatting + with max_space = longest_table_name_size(apps, 0) + 4, + + join(",\n", + map((HK_App app) |-> since app is hk_app(app_name, icon, help, tables), + indent+"hk_menu_list("+to_String(icon)+", "+ + //determine if there is help text for app. If not we use the App name as menu entry + 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, + to_Anubis_source(app_menu_name)+",\n"+indent+"[\n"+ + join(",\n", + map_append((HK_Table table) |-> + since table is hk_table(table_name, short_name, model, display), + since display is hk_display(list_views, _), + map((HK_List_View view ) |-> + with view_name = if view is list_view(v_name, _) then v_name else "default", + indent+" "+"hk_menu_item("+fill_or_cut("\""+table_name+"\",",max_space, ' ')+ "\"view_table\", "+ + fill_or_cut("\""+short_name+(if view_name="default" then "" else " "+view_name)+"\",",max_space, ' ')+ + "[(\"table_name\", "+fill_or_cut("\""+table_name+"\",",max_space, ' ')+"),(\"view_name\", \""+view_name+"\")])", list_views), tables))+"\n"+indent+"])", apps)). + + +public define Maybe(One) + generate_menus + ( + List(HK_App) apps //list of the table model description + )= + + with file_name = "web_pages/generated/apps_menu.anubis", + + //create all necessary directories if doesn't exist. + make_directories(file_name); + + //create script file name as new file. Previous file with same name will be erased + if file(file_name, new) is + { + failure then println("Can't create menu "+file_name);failure, + success(fd) then + with stream = make_stream(fd), + + write_string(stream, +"/* + * Created by 早見木 (Hayamiki). + * Date: "+_Int_to_ISO_8601_date(now)+" + * Time: "+_Int_to_ISO_8601_time(now)+" + */ + +transmis calexium_lib/database/model/db_model.anubis +transmit types/hk_menu_types.anubis + +public define HK_Menu + admin_menu + = +hk_menu([ + hk_menu_item(\"\", \"\", \"HOME\", []), + hk_menu_list(\"managers\", help_text_TAG(\"APPLICATIONS\"), + [\n"+ + generate_application_menu(apps, " ")+"\n + ]), + ] +).\n") + } + +. diff --git a/src/generation/types.anubis b/src/generation/types.anubis index 6d3da68..2904c7d 100644 --- a/src/generation/types.anubis +++ b/src/generation/types.anubis @@ -34,7 +34,7 @@ public define Maybe(One) Stream stream, HK_Table table )= - since table is hk_table(name, model, display), + since table is hk_table(name, short_name, model, display), since model is hk_model(columns, show_string), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. @@ -69,7 +69,7 @@ public define Maybe(One) Stream stream, HK_Table table )= - since table is hk_table(name, model, _), + since table is hk_table(name, short_name, model, _), since model is hk_model(columns, show_string), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. @@ -115,7 +115,7 @@ public define Maybe(One) Stream stream, HK_Table table )= - since table is hk_table(name, model, _), + since table is hk_table(name, short_name, model, _), since model is hk_model(columns, _), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. 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) Stream stream, HK_Table table )= - since table is hk_table(name, model, display), + since table is hk_table(name, short_name, model, display), since model is hk_model(columns, _), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. @@ -168,7 +168,7 @@ public define Maybe(One) Stream stream, HK_Table table )= - since table is hk_table(name, model, _), + since table is hk_table(name, short_name, model, _), since model is hk_model(columns, _), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. @@ -211,7 +211,7 @@ public define Maybe(One) Stream stream, HK_Table table )= - since table is hk_table(name, model, _), + since table is hk_table(name, short_name, model, _), since model is hk_model(columns, show_string), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. @@ -251,7 +251,7 @@ public define Maybe(One) Stream stream, HK_Table table )= - since table is hk_table(name, model, _), + since table is hk_table(name, short_name, model, _), since model is hk_model( columns, _), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. @@ -307,7 +307,7 @@ public define Maybe(One) Stream stream, HK_Table table )= - since table is hk_table(name, model, _), + since table is hk_table(name, short_name, model, _), since model is hk_model( columns, show_string), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. @@ -338,7 +338,7 @@ public define Maybe(One) Stream stream, HK_Table table )= - since table is hk_table(name, model, _), + since table is hk_table(name, short_name, model, _), since model is hk_model( columns, show_string), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. @@ -384,7 +384,7 @@ public define Maybe(One) HK_Table table, // HK_List_View list_view //list view to generate )= - since table is hk_table(table_name, model, display), + since table is hk_table(table_name, short_name, model, display), since model is hk_model( columns, _), //since display is db_display(list_view, list_edit), @@ -515,7 +515,7 @@ public define Maybe(One) HK_Table table, // List(HK_List_View) list_view //list view to generate )= - since table is hk_table(table_name, model, display), + since table is hk_table(table_name, short_name, model, display), if write_string(stream, "public define VT_view\n"+ " get_viewable_"+table_name+"\n"+ @@ -537,9 +537,9 @@ public define Maybe(One) Stream stream, HK_Table table )= - since table is hk_table(name, model, display), + since table is hk_table(name, short_name, model, display), since model is hk_model( columns, _), - since display is db_display(list_view, list_edit), + since display is hk_display(list_view, list_edit), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. if _generate_VT_view(stream, table, list_view, false) is //list view to generate @@ -555,9 +555,9 @@ public define Maybe(One) Stream stream, HK_Table table )= - since table is hk_table(name, model, display), - since model is hk_model( columns, _), - since display is db_display(list_view, list_edit), + since table is hk_table(name, short_name, model, display), + since model is hk_model( columns, _), + since display is hk_display(list_view, list_edit), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. //generate the type of the table that contain all components diff --git a/src/model.3.0.0.anubis b/src/model.3.0.0.anubis index 3bbe015..4a718b5 100644 --- a/src/model.3.0.0.anubis +++ b/src/model.3.0.0.anubis @@ -39,7 +39,7 @@ public define HK_Table mf_serial_table = ], "obj.serial" ), - db_display( + hk_display( [ //list_view @@ -65,7 +65,7 @@ public define HK_Table settings_table = ], "obj.var_name+\" = \"+obj.var_value" ), - db_display( + hk_display( //list_view [ list_view_all], //list edit @@ -90,7 +90,7 @@ public define HK_Table django_admin_log_table = ], "obj.object_repr" ), - db_display( + hk_display( //list_view [ list_view_all], //list edit @@ -108,7 +108,7 @@ public define HK_Table production_macaddress_table = ], "obj.mac+\" = MailFountain[\"+obj.mailfountain_id+\"]\"" ), - db_display( + hk_display( //list_view [ list_view_all], //list edit @@ -125,7 +125,7 @@ public define HK_Table production_mass_storage_type_table = ], "to_String(obj.id)+\":\"+obj.type" ), - db_display( + hk_display( //list_view [ list_view_all], //list edit @@ -150,7 +150,7 @@ public define HK_Table production_mass_storage_table = ], "obj.serial" ), - db_display( + hk_display( //list_view [ list_view("current",["model_id", "serial", "status", "date_created"]) @@ -189,7 +189,7 @@ public define HK_Table production_mass_storage_model_table = ], "obj.manufacturer" ), - db_display( + hk_display( //list_view [ list_view("default", ["manufacturer", "type_id", "capacity", "tr_min", "last_modified", "date_created"]) @@ -214,7 +214,7 @@ public define HK_Table production_memory_table = ], "obj.serial" ), - db_display( + hk_display( //list_view [ list_view("default", ["serial", "status", "last_modified", "date_created"]) @@ -235,7 +235,7 @@ public define HK_Table production_memory_model_table = ], "obj.manufacturer" ), - db_display( + hk_display( //list_view [ list_view_all], //list_edit @@ -252,7 +252,7 @@ public define HK_Table production_memory_type_table = ], "to_String(obj.id)+\":\"+obj.type" ), - db_display( + hk_display( //list_view [ list_view_all], //list edit @@ -276,7 +276,7 @@ public define HK_Table production_motherboard_table = ], "obj.serial" ), - db_display( + hk_display( //list_view [ list_view("default", ["serial", "week_fab", "status", "last_modified", "date_created"]) @@ -302,7 +302,7 @@ public define HK_Table production_motherboard_model_table = ], "obj.name" ), - db_display( + hk_display( //list_view [ list_view("default", ["name", "manufacturer", "cpu_model", "cpu_freq"]) @@ -327,7 +327,7 @@ public define HK_Table production_power_supply_table = ], "obj.serial" ), - db_display( + hk_display( //list_view [ list_view("default", ["serial", "status", "date_created", "last_modified"]) @@ -348,7 +348,7 @@ public define HK_Table production_power_supply_model_table = ], "obj.name" ), - db_display( + hk_display( //list_view [ list_view("default", ["name", "manufacturer"]) @@ -378,7 +378,7 @@ public define HK_Table production_product_reference_table = ], "obj.product_ref+\":\"+obj.product_name" ), - db_display( + hk_display( //list_view [ list_view("default", ["type_ref_id", "product_ref", "product_name", "description"]) @@ -415,7 +415,7 @@ public define HK_Table production_products_table = ], "obj.serial" ), - db_display( + hk_display( //list_view [ list_view("default", ["production_id", "date", "serial", "motherboard_id", "app_id", "status"]) @@ -449,7 +449,7 @@ public define HK_Table production_production_table = ], "date(obj.date)" ), - db_display( + hk_display( //list_view [ 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 = ], "obj.ref+\":\"+obj.name" ), - db_display( + hk_display( //list_view [ list_view("default", ["ref", "name", "city", "country"]) @@ -500,7 +500,7 @@ public define HK_Table production_purchase_table = ], "date(obj.date)" ), - db_display( + hk_display( //list_view [ list_view("default", ["date", "supplier_id", "description"]) @@ -520,7 +520,7 @@ public define HK_Table production_serial_prefix_table = ], "obj.prefix" ), - db_display( + hk_display( //list_view [list_view_all], //list_edit @@ -541,7 +541,7 @@ public define HK_Table production_type_number_table = ], "obj.type_ref+\":\"+obj.description" ), - db_display( + hk_display( //list_view [ list_view("default", ["type_ref", "description"]) @@ -576,7 +576,7 @@ public define HK_Table production_supplier_table = ], "obj.company" ), - db_display( + hk_display( //list_view [ list_view("default", ["company", "phone", "mobile", "email"]) @@ -601,7 +601,7 @@ public define HK_Table department_table = ], "obj.name" ), - db_display( + hk_display( //list_view [ list_view("default", ["name"]) @@ -624,7 +624,7 @@ public define HK_Table role_table = ], "obj.role_name" ), - db_display( + hk_display( //list_view [ list_view("default", ["role_name"]) @@ -652,7 +652,7 @@ public define HK_Table staff_table = ], "obj.email" ), - db_display( + hk_display( //list_view [ list_view("default", ["contact_id", "department_id", "role_id", "email"]), @@ -689,7 +689,7 @@ public define HK_Table address_book_contact_table = ], "obj.first_name +\" \"+obj.last_name " ), - db_display( + hk_display( //list_view [ list_view("short", ["first_name", "last_name", "company"]), -- libgit2 0.21.4