From 3db774b081a51e9b15fb208807f52b4b13ab0ff4 Mon Sep 17 00:00:00 2001 From: totoro Date: Sun, 21 May 2017 11:05:45 +0200 Subject: [PATCH] add hk_filter in model description and manage it --- hayamiki_generator.aproj | 1 + hayamiki_lib | 2 +- src/generation/SQL_get_all.anubis | 13 +++++++------ src/generation/cxm_lib_menu.anubis | 2 +- src/generation/header.anubis | 1 + src/generation/hk_menu.anubis | 2 +- src/generation/html.anubis | 14 +++++++------- src/generation/vt_view.anubis | 43 ++++++++++++++++++++++++++----------------- src/model.3.0.0.anubis | 275 +++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 9 files changed, 48 insertions(+), 305 deletions(-) diff --git a/hayamiki_generator.aproj b/hayamiki_generator.aproj index 1a46299..a5804bb 100644 --- a/hayamiki_generator.aproj +++ b/hayamiki_generator.aproj @@ -157,6 +157,7 @@ + diff --git a/hayamiki_lib b/hayamiki_lib index 5ef0dd2..acfe3c6 160000 --- a/hayamiki_lib +++ b/hayamiki_lib @@ -1 +1 @@ -Subproject commit 5ef0dd2a124781ed0bec0c17b95f4a4d78ec7822 +Subproject commit acfe3c6df4dc48c85e9af860ce25e07099c278fc diff --git a/src/generation/SQL_get_all.anubis b/src/generation/SQL_get_all.anubis index 0c0868d..fe934bb 100644 --- a/src/generation/SQL_get_all.anubis +++ b/src/generation/SQL_get_all.anubis @@ -113,13 +113,14 @@ public define Maybe(One) "public define JsonMember\n"+ " get_all_"+name+"_by_clause_to_json\n"+ " (\n"+ -" SQLite3DataBase db,\n"+ -" HK_Referer referer,\n"+ -" String filter\n"+ +" SQLite3DataBase db,\n"+ +" HK_Referer referer,\n"+ +" String filter,\n"+ +" String order_by\n"+ " )=\n"+ -" with clause = referer_to_sql_clause(referer, \""+name+"\", "+name+"_columns),\n\n"+ -" //with _and_ = if length(clause) > 0 & length(filter) > 0 then \" AND \" else \"\",\n"+ -" if get_all_"+name+"_by_clause(db, clause+filter) is\n"+ +" with ref_clause = referer_to_sql_clause(referer, \""+name+"\", "+name+"_columns),\n\n"+ +" with _and_ = if length(ref_clause) > 0 & length(filter) > 0 then \" AND \" else \"\",\n"+ +" if get_all_"+name+"_by_clause(db, ref_clause+_and_+filter+\" \"+order_by) is\n"+ " {\n"+ " failure then json_member(\"rows\", json_array([])),\n"+ " success(cursor) then json_member(\"rows\", json_array(_get_all_"+name+"_to_json(db, cursor, [])))\n"+ diff --git a/src/generation/cxm_lib_menu.anubis b/src/generation/cxm_lib_menu.anubis index 58e194e..e0228ac 100644 --- a/src/generation/cxm_lib_menu.anubis +++ b/src/generation/cxm_lib_menu.anubis @@ -47,7 +47,7 @@ define String since table is hk_table(table_name, short_name, model, display), since display is hk_display(list_views, _), map((HK_Viewer view ) |-> - with view_name = if view is list_view(v_name, _, _) then v_name else "default", + with view_name = if view is list_view(v_name, _, _, _) then v_name else "default", indent+" "+"menu_item("+ fill("\""+short_name+(if view_name="default" then "" else " "+view_name)+"\",",max_space)+ //fill("\""+table_name+"\",",max_space)+ diff --git a/src/generation/header.anubis b/src/generation/header.anubis index bf761d9..cc749ad 100644 --- a/src/generation/header.anubis +++ b/src/generation/header.anubis @@ -64,6 +64,7 @@ read calexium_lib/database/db_utils.anubis read calexium_lib/database/db_types.anubis read hayamiki_lib/view/types/hk_form.anubis read hayamiki_lib/view/types/hk_view.anubis +read hayamiki_lib/view/types/hk_filter.anubis read hayamiki_lib/types/hayamiki.anubis read hayamiki_lib/controller/hk_sql_utils.anubis read system/logger.anubis diff --git a/src/generation/hk_menu.anubis b/src/generation/hk_menu.anubis index 828f1b4..ea12a20 100644 --- a/src/generation/hk_menu.anubis +++ b/src/generation/hk_menu.anubis @@ -42,7 +42,7 @@ define String since table is hk_table(table_name, short_name, model, display), since display is hk_display(list_views, _), map((HK_Viewer view ) |-> - with view_name = if view is list_view(v_name, _, _) then v_name else "default", + with view_name = if view is list_view(v_name, _, _, _) then v_name else "default", indent+" "+"hk_menu_item("+fill("\""+table_name+"\",",max_space)+ "\"view_table\", "+ fill("help_text(\""+short_name+(if view_name="default" then "" else " "+view_name)+"\"),",max_space)+ "[(\"table_name\", "+fill("\""+table_name+"\",",max_space)+"),(\"view_name\", \""+view_name+"\")])", list_views), tables))+"\n"+indent+"])", apps)). diff --git a/src/generation/html.anubis b/src/generation/html.anubis index af35604..78b2b66 100644 --- a/src/generation/html.anubis +++ b/src/generation/html.anubis @@ -111,9 +111,9 @@ public define String public define String make_list_view_row ( - HK_Table table, //table to format - String data_name, //name of data - String indent, //indentation string to use + HK_Table table, //table to format + String data_name, //name of data + String indent, //indentation string to use HK_Viewer list_view //list view to generate )= since table is hk_table(table_name, short, model, _), //get name and model of the table @@ -121,13 +121,13 @@ public define String // since display is db_display(views, _), // with current_list_column = if list_view is { - list_view_all then to_List_String(columns, false), //generate a list of columns string to view from columns model - list_view(v_name, v_col, _) then v_col + list_view_all then to_List_String(columns, false), //generate a list of columns string to view from columns model + list_view(v_name, v_col, l_filters, _) then v_col }, with action_name = if list_view is { - list_view_all then no_action, - list_view(_, _, an) then an + list_view_all then no_action, + list_view(_, _, _, an) then an }, if current_list_column is diff --git a/src/generation/vt_view.anubis b/src/generation/vt_view.anubis index 0d2f4b4..58e4d37 100644 --- a/src/generation/vt_view.anubis +++ b/src/generation/vt_view.anubis @@ -7,6 +7,7 @@ */ read hayamiki_lib/types/hayamiki.anubis +read hayamiki_lib/view/hk_filter.anubis read tools/basis.anubis read tools/streams.anubis read system/string.anubis @@ -119,17 +120,17 @@ public define Maybe(One) with view_name = if list_view is { list_view_all then "default", - list_view(view_name, _, _) then view_name + list_view(view_name, _, _, _) then view_name }, with current_list_view = if list_view is { list_view_all then to_List_String(columns, false), - list_view(_, cols, _) then cols + list_view(_, cols, _, _) then cols }, with current_view_models = if list_view is { list_view_all then columns, - list_view(v_name, cols, _) then + list_view(v_name, cols, _, _) then if get_HK_Model_Column_list_from_name_list(columns, cols) is { failure then println("generate_VT_view: can't get all specified columns for table \""+table_name+"\" view name \""+v_name+"\" cols["+join(", ",cols)+"]");[], @@ -207,7 +208,7 @@ public define Maybe(One) if view is { list_view_all then true, //list_view_all is default view - list_view(view_name, _, _) then + list_view(view_name, _, _, _) then //if not we search for view named 'default' if view_name = "default" then true else false }, @@ -235,7 +236,7 @@ public define String with view_name = if view is { list_view_all then "default", - list_view(view_name, _, _) then view_name + list_view(view_name, _, _, _) then view_name }, _generate_get_viewable_if_else( table_name, t, so_far + @@ -270,22 +271,30 @@ public define Maybe(One) success(_) then success(unique) }. +define String + make_filter + ( + List(HK_Filter) filters + )= + join(", \n", map((HK_Filter filter) |-> to_Anubis_source(filter), filters)) +. + public define List(String) /* Generate */ _generate_list_view_name ( - List(HK_Viewer) list_view, //list view to generate - List(String) so_far, - Bool has_default //set to true if a default view was encountered. + List(HK_Viewer) list_view, //list view to generate + List(String) so_far, + Bool has_default //set to true if a default view was encountered. )= if list_view is { [] then //if default view was not generated, we force to generate it if has_default = false then - reverse(["\"default\"" . so_far]) + reverse(["(\"default\", [])" . so_far]) else reverse(so_far), [view . t] then @@ -295,29 +304,29 @@ public define List(String) if view is { list_view_all then true, //list_view_all is default view - list_view(view_name, _, _) then + list_view(view_name, _, _, _) then //if not we search for view named 'default' if view_name = "default" then true else false }, - with view_name = if view is + with entry = if view is { - list_view_all then "default", - list_view(view_name, _, _) then view_name + list_view_all then "(\"default\", [])", + list_view(view_name, _, filter, _) then "(\""+view_name+"\", ["+make_filter(filter)+"])" }, - _generate_list_view_name(t, ["\""+view_name+"\"" . so_far], new_has_default) + _generate_list_view_name(t, [entry . so_far], new_has_default) } . public define Maybe(One) _generate_get_all_view_name ( - Stream stream, - HK_Table table, // + Stream stream, + HK_Table table, // List(HK_Viewer) list_view )= since table is hk_table(table_name, short_name, model, display), if write_string(stream, - "\n\npublic define List(String)\n"+ + "\n\npublic define List((String, List(HK_Filter)))\n"+ " get_all_"+table_name+"_view_name\n"+ " (\n"+ " One dummy\n"+ diff --git a/src/model.3.0.0.anubis b/src/model.3.0.0.anubis index 1e8f855..5a1cb4c 100644 --- a/src/model.3.0.0.anubis +++ b/src/model.3.0.0.anubis @@ -44,267 +44,7 @@ public define HK_Table django_admin_log_table = [ edit_view_all] ) ). - -public define HK_Table production_macaddress_table = - hk_table("macaddress", - hk_model( - [ - - hk_column("mac", char_field(20), []), - hk_column("mailfountain_id", integer_field, []), - ], - "obj.mac+\" = MailFountain[\"+obj.mailfountain_id+\"]\"" - ), - hk_display( - //list_view - [ list_view_all], - //list edit - [edit_view_all] - ) - ). - -public define HK_Table production_mass_storage_type_table = - hk_table("mass_storage_type", - hk_model( - [ - - hk_column("type", char_field(20), []), - ], - "to_String(obj.id)+\":\"+obj.type" - ), - hk_display( - //list_view - [ list_view_all], - //list edit - [edit_view_all] - ) - ). - - - -public define HK_Table production_mass_storage_table = - hk_table("mass_storage", - hk_model( - [ - - hk_column("purchase_id", foreign_key("purchase"), []), - hk_column("model_id", foreign_key("mass_storage_model"), []), - hk_column("serial", char_field(40), []), // - hk_column("status", char_field(10), []), // - hk_column("date_created", datetime_field(auto_now_add), []), - hk_column("last_modified", datetime_field(auto_now), []), - hk_column("comments", text_field, []) // whatever the user wants to keep - ], - "obj.serial" - ), - hk_display( - //list_view - [ - list_view("current",["model_id", "serial", "status", "date_created"]) - ], - //list_edit - [ edit_view_list_form("default", ["purchase_id", "model_id", "serial", "status", "comments"])] - ) - ). - - "CREATE TABLE production_purchase ( - id integer NOT NULL PRIMARY KEY, - date date NOT NULL, - buyer_id integer NOT NULL REFERENCES staff_staff (id), - supplier_id integer NOT NULL REFERENCES production_supplier (id), - order_ref varchar(50) NOT NULL, - description varchar(200) NOT NULL, - date_created datetime NOT NULL, - last_modified datetime NOT NULL, - comments text NOT NULL - )" - - - -public define HK_Table production_mass_storage_model_table = - hk_table("mass_storage_model", - hk_model( - [ - - hk_column("manufacturer", char_field(20), []), - hk_column("type_id", foreign_key("mass_storage_type"), []), - hk_column("capacity", integer_field, []), // - hk_column("tr_min", integer_field, []), // - hk_column("date_created", datetime_field(auto_now_add), []), - hk_column("last_modified", datetime_field(auto_now), []), - hk_column("comments", text_field, []) // whatever the user wants to keep - ], - "obj.manufacturer" - ), - hk_display( - //list_view - [ - list_view("default", ["manufacturer", "type_id", "capacity", "tr_min", "last_modified", "date_created"]) - ], - //list_edit - [edit_view_all] - ) - ). - -public define HK_Table production_memory_table = - hk_table("memory", - hk_model( - [ - - hk_column("purchase_id", foreign_key("purchase"), []), - hk_column("model_id", foreign_key("memory_model"), []), - hk_column("serial", char_field(40), []), // - hk_column("status", char_field(10), []), // - hk_column("date_created", datetime_field(auto_now_add), []), - hk_column("last_modified", datetime_field(auto_now), []), - hk_column("comments", text_field, []) // whatever the user wants to keep - ], - "obj.serial" - ), - hk_display( - //list_view - [ - list_view("default", ["serial", "status", "last_modified", "date_created"]) - ], - //list_edit - [edit_view_all] - ) - ). - -public define HK_Table production_memory_model_table = - hk_table("memory_model", - hk_model( - [ - - hk_column("type_id", foreign_key("memory_type"), []), - hk_column("manufacturer", char_field(20), []), // - hk_column("capacity", integer_field, []) // - ], - "obj.manufacturer" - ), - hk_display( - //list_view - [ list_view_all], - //list_edit - [edit_view_all] - ) - ). - -public define HK_Table production_memory_type_table = - hk_table("memory_type", - hk_model( - [ - - hk_column("type", char_field(20), []), - ], - "to_String(obj.id)+\":\"+obj.type" - ), - hk_display( - //list_view - [ list_view_all], - //list edit - [edit_view_all] - ) - ). - -public define HK_Table production_motherboard_table = - hk_table("motherboard", - hk_model( - [ - - hk_column("purchase_id", foreign_key("purchase"), []), - hk_column("model_id", foreign_key("motherboard_model"), []), - hk_column("serial", char_field(40), []), // - hk_column("week_fab", char_field(10), []), // - hk_column("status", char_field(10), []), // - hk_column("date_created", datetime_field(auto_now_add), []), - hk_column("last_modified", datetime_field(auto_now), []), - hk_column("comments", text_field, []) // whatever the user wants to keep - ], - "obj.serial" - ), - hk_display( - //list_view - [ - list_view("default", ["serial", "week_fab", "status", "last_modified", "date_created"]) - ], - //list_edit - [edit_view_all] - ) - ). - -public define HK_Table production_motherboard_model_table = - hk_table("motherboard_model", - hk_model( - [ - - hk_column("name", char_field(30), []), - hk_column("manufacturer", char_field(20), []), - hk_column("has_nand", boolean_field, []), - hk_column("nand_capacity", integer_field, []), // - hk_column("memory", integer_field, []), // - hk_column("cpu_freq", integer_field, []), // - hk_column("cpu_model", char_field(30), []), - hk_column("endian", char_field(1), []) // whatever the user wants to keep - ], - "obj.name" - ), - hk_display( - //list_view - [ - list_view("default", ["name", "manufacturer", "cpu_model", "cpu_freq"]) - ], - //list_edit - [edit_view_all] - ) - ). -public define HK_Table production_power_supply_table = - hk_table("power_supply", - hk_model( - [ - - hk_column("purchase_id", foreign_key("purchase"), []), - hk_column("model_id", foreign_key("power_supply_model"), []), - hk_column("serial", char_field(40), []), // - hk_column("status", char_field(10), []), // - hk_column("date_created", datetime_field(auto_now_add), []), - hk_column("last_modified", datetime_field(auto_now), []), - hk_column("comments", text_field(rich_editor), []) // whatever the user wants to keep - ], - "obj.serial" - ), - hk_display( - //list_view - [ - list_view("default", ["serial", "status", "date_created", "last_modified"]) - ], - //list_edit - [edit_view_all] - ) - ). - -public define HK_Table production_power_supply_model_table = - hk_table("power_supply_model", - hk_model( - [ - - hk_column("name", char_field(30), []), - hk_column("manufacturer", char_field(20), []), - hk_column("power", integer_field, []) - ], - "obj.name" - ), - hk_display( - //list_view - [ - list_view("default", ["name", "manufacturer"]) - ], - //list_edit - [edit_view_all] - ) - ). - public define HK_Table production_product_reference_table = hk_table("product_reference", hk_model( @@ -610,7 +350,9 @@ public define HK_Table staff_table = hk_display( //list_view [ - list_view("default", ["contact_id", "department_id", "role_id", "email"]), + list_view("default", ["contact_id", "department_id", "role_id", "email"], + [hk_filter("présent", "still_present = 1")] + ), list_view("details", ["contact_id", "department_id", "role_id", "email", "incoming_date", "still_present"]) ], @@ -667,17 +409,6 @@ public define HK_Database //mf_serial_table hk_app("production", [ - production_mass_storage_table, - production_mass_storage_type_table, - production_mass_storage_model_table, - production_memory_table, - production_memory_model_table, - production_memory_type_table, - production_macaddress_table, - production_motherboard_table, - production_motherboard_model_table, - production_power_supply_table, - production_power_supply_model_table, production_product_reference_table, production_production_table, production_production_site_table, -- libgit2 0.21.4