Commit b0e5ce0d6103b9179b98d3967fbdc994fcc76265
1 parent
d684d8d7
add to_Message in types/model/database.anubis which convert HK_Database into Muscle message.
This is useful for save the database into file and keep compatibility up and down and also for transmitting through the network.
Showing
9 changed files
with
665 additions
and
11 deletions
Show diff stats
types/model/app.anubis
| @@ -10,7 +10,8 @@ transmit help.anubis | @@ -10,7 +10,8 @@ transmit help.anubis | ||
| 10 | transmit tables.anubis | 10 | transmit tables.anubis |
| 11 | transmit icons.anubis | 11 | transmit icons.anubis |
| 12 | 12 | ||
| 13 | - | 13 | +read tools/basis.anubis |
| 14 | +transmit system/muscle.anubis | ||
| 14 | 15 | ||
| 15 | public type HK_App: | 16 | public type HK_App: |
| 16 | hk_app( | 17 | hk_app( |
| @@ -47,3 +48,56 @@ public define HK_App | @@ -47,3 +48,56 @@ public define HK_App | ||
| 47 | List(HK_Table) hk_tables | 48 | List(HK_Table) hk_tables |
| 48 | )= | 49 | )= |
| 49 | hk_app(app_name, no_icon, no_help_text, hk_tables). | 50 | hk_app(app_name, no_icon, no_help_text, hk_tables). |
| 51 | + | ||
| 52 | + type HK_App: | ||
| 53 | + hk_app( | ||
| 54 | + String app_name, | ||
| 55 | + HK_Icon icon, | ||
| 56 | + HK_Help_Text help, | ||
| 57 | + List(HK_Table) hk_tables | ||
| 58 | + ). | ||
| 59 | + | ||
| 60 | + _HK_APP: | ||
| 61 | + ======== | ||
| 62 | + +----------+---------------+-------------------------- | ||
| 63 | + | name | type | description | ||
| 64 | + +----------+---------------+-------------------------------- | ||
| 65 | + | "name" | String | Name of the application | ||
| 66 | + | "icon" | Message | Icon description, contained in message id _HK_ICON | ||
| 67 | + | "help" | Message | Help string, contained in message id _HK_HELP_TEXT | ||
| 68 | + | "tables" | List(Message) | List of tables of that application contained in message id _HK_TABLE | ||
| 69 | + | ||
| 70 | +public define Message | ||
| 71 | + to_Message | ||
| 72 | + ( | ||
| 73 | + HK_App app | ||
| 74 | + )= | ||
| 75 | + with hk_app_message = message(_HK_APP), | ||
| 76 | + forget(add_string(hk_app_message, "name", app.app_name)); | ||
| 77 | + forget(add_message(hk_app_message, "icon", to_Message(app.icon))); | ||
| 78 | + forget(add_message(hk_app_message, "help", to_Message(app.help))); | ||
| 79 | + map_forget((HK_Table table) |-> add_message(hk_app_message, "tables", to_Message(table)), app.hk_tables); | ||
| 80 | + //print_to_stream(hk_app_message); | ||
| 81 | + hk_app_message | ||
| 82 | + . | ||
| 83 | + | ||
| 84 | +public define Maybe(HK_App) | ||
| 85 | + from_Message | ||
| 86 | + ( | ||
| 87 | + Message hk_app_message | ||
| 88 | + )= | ||
| 89 | + if *hk_app_message.what = _HK_APP then | ||
| 90 | + if find_string(hk_app_message, "name") is {failure then failure, success(name) then | ||
| 91 | + if find_message(hk_app_message, "icon") is {failure then failure, success(icon_msg) then | ||
| 92 | + if (Maybe(HK_Icon))from_Message(icon_msg) is {failure then failure, success(icon) then | ||
| 93 | + if find_message(hk_app_message, "help") is {failure then failure, success(help_msg) then | ||
| 94 | + if (Maybe(HK_Help_Text))from_Message(help_msg) is {failure then failure, success(help) then | ||
| 95 | + | ||
| 96 | + with tables = map_escape((Message msg_app) |-> (Maybe(HK_Table))from_Message(msg_app), find_messages(hk_app_message, "tables")), | ||
| 97 | + if tables is {failure then failure, success(table_list) then | ||
| 98 | + //return the application | ||
| 99 | + success(hk_app(name, icon, help, table_list)) | ||
| 100 | + }}}}}} | ||
| 101 | + else | ||
| 102 | + failure | ||
| 103 | + . |
types/model/columns.anubis
| @@ -6,6 +6,8 @@ | @@ -6,6 +6,8 @@ | ||
| 6 | * © Calexium | 6 | * © Calexium |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | +read tools/basis.anubis | ||
| 10 | + | ||
| 9 | transmit help.anubis | 11 | transmit help.anubis |
| 10 | transmit fields.anubis | 12 | transmit fields.anubis |
| 11 | 13 | ||
| @@ -16,8 +18,44 @@ public type HK_Model_Attr: | @@ -16,8 +18,44 @@ public type HK_Model_Attr: | ||
| 16 | // in a table which already contains some rows) | 18 | // in a table which already contains some rows) |
| 17 | not_null. | 19 | not_null. |
| 18 | 20 | ||
| 19 | - *** (1.4) 'HK_Model_Column' (describing a column in a table). | 21 | +public define Message |
| 22 | + to_Message | ||
| 23 | + ( | ||
| 24 | + HK_Model_Attr hk_model_attr | ||
| 25 | + )= | ||
| 26 | + with hk_model_attr_message = message(_HK_COLUMN_ATTRIBUTES), | ||
| 27 | + if hk_model_attr is | ||
| 28 | + { | ||
| 29 | + unique then forget(add_string(hk_model_attr_message, "hk_column_attr", "unique")), | ||
| 30 | + indexed then forget(add_string(hk_model_attr_message, "hk_column_attr", "indexed")), | ||
| 31 | + default(value) then forget(add_string(hk_model_attr_message, "hk_column_attr", "default")); | ||
| 32 | + forget(add_string(hk_model_attr_message, "value", value)), | ||
| 33 | + not_null then forget(add_string(hk_model_attr_message, "hk_column_attr", "not_null")) | ||
| 34 | + }; | ||
| 35 | + hk_model_attr_message | ||
| 36 | + . | ||
| 20 | 37 | ||
| 38 | +public define Maybe(HK_Model_Attr) | ||
| 39 | + from_Message | ||
| 40 | + ( | ||
| 41 | + Message hk_model_attr_message | ||
| 42 | + )= | ||
| 43 | + if *hk_model_attr_message.what = _HK_COLUMN_ATTRIBUTES then | ||
| 44 | + if find_string(hk_model_attr_message, "hk_column_attr") is {failure then failure, success(col_attr) then | ||
| 45 | + if col_attr = "unique" then success(unique) | ||
| 46 | + else if col_attr = "indexed" then success(indexed) | ||
| 47 | + else if col_attr = "default" then | ||
| 48 | + if find_string(hk_model_attr_message, "value") is {failure then failure, success(value) then | ||
| 49 | + success(default(value)) | ||
| 50 | + } | ||
| 51 | + else if col_attr = "not_null" then success(not_null) | ||
| 52 | + else failure | ||
| 53 | + } | ||
| 54 | + else | ||
| 55 | + failure | ||
| 56 | + . | ||
| 57 | + | ||
| 58 | + 'HK_Model_Column' (describing a column in a table). | ||
| 21 | Description of a column: | 59 | Description of a column: |
| 22 | 60 | ||
| 23 | public type HK_Model_Column: | 61 | public type HK_Model_Column: |
| @@ -50,3 +88,50 @@ public define HK_Model_Column | @@ -50,3 +88,50 @@ public define HK_Model_Column | ||
| 50 | hk_column(name, type, [], no_help_text). | 88 | hk_column(name, type, [], no_help_text). |
| 51 | 89 | ||
| 52 | 90 | ||
| 91 | + _HK_COLUMN message format: | ||
| 92 | + ========================== | ||
| 93 | + | ||
| 94 | + +--------------+---------------+-------------------------- | ||
| 95 | + | name | type | description | ||
| 96 | + +--------------+---------------+-------------------------------- | ||
| 97 | + | "name" | String | Name of the column in table | ||
| 98 | + | "field_type" | Message | computation String to be shown to summarize row content. This string is Anubis source code | ||
| 99 | + | "attributes" | List(Message) | List of attributes of the table Message id is _HK_COLUMN_ATTRIBUTES | ||
| 100 | + | "text" | Message | help text to use during edit screen | ||
| 101 | + | ||
| 102 | +public define Message | ||
| 103 | + to_Message | ||
| 104 | + ( | ||
| 105 | + HK_Model_Column hk_column | ||
| 106 | + )= | ||
| 107 | + with hk_model_column = message(_HK_COLUMN), | ||
| 108 | + forget(add_string(hk_model_column, "name", hk_column.name)); | ||
| 109 | + forget(add_message(hk_model_column, "field_type", to_Message(hk_column.type))); | ||
| 110 | + map_forget((HK_Model_Attr attribute) |-> add_message(hk_model_column, "attributes", to_Message(attribute)), hk_column.attributes); | ||
| 111 | + forget(add_message(hk_model_column, "text", to_Message(hk_column.help))); | ||
| 112 | + | ||
| 113 | + //print_to_stream(hk_model_column); | ||
| 114 | + hk_model_column | ||
| 115 | + . | ||
| 116 | + | ||
| 117 | + | ||
| 118 | +public define Maybe(HK_Model_Column) | ||
| 119 | + from_Message | ||
| 120 | + ( | ||
| 121 | + Message msg_hk_column | ||
| 122 | + )= | ||
| 123 | + if *msg_hk_column.what = _HK_COLUMN then | ||
| 124 | + if find_string(msg_hk_column, "name") is {failure then failure, success(name) then | ||
| 125 | + if find_message(msg_hk_column, "field_type") is {failure then failure, success(field_type_msg) then | ||
| 126 | + if (Maybe(HK_Model_Field))from_Message(field_type_msg) is {failure then failure, success(field_type) then | ||
| 127 | + if find_message(msg_hk_column, "text") is {failure then failure, success(help_msg) then | ||
| 128 | + if (Maybe(HK_Help_Text))from_Message(help_msg) is {failure then failure, success(help) then | ||
| 129 | + | ||
| 130 | + with mb_attribs = map_escape((Message msg_col) |-> (Maybe(HK_Model_Attr))from_Message(msg_col), find_messages(msg_hk_column, "attributes")), | ||
| 131 | + if mb_attribs is {failure then failure, success(attributes_list) then | ||
| 132 | + //return the application | ||
| 133 | + success(hk_column(name, field_type, attributes_list, help)) | ||
| 134 | + }}}}}} | ||
| 135 | + else | ||
| 136 | + failure | ||
| 137 | + . |
types/model/database.anubis
| @@ -8,7 +8,58 @@ | @@ -8,7 +8,58 @@ | ||
| 8 | 8 | ||
| 9 | transmit app.anubis | 9 | transmit app.anubis |
| 10 | 10 | ||
| 11 | +transmit tools/basis.anubis | ||
| 12 | +transmit system/muscle.anubis | ||
| 13 | +transmit calexium_lib/CXM_message_constants.anubis | ||
| 14 | + | ||
| 15 | + | ||
| 11 | public type HK_Database: | 16 | public type HK_Database: |
| 12 | hk_database (String name, // name of the database | 17 | hk_database (String name, // name of the database |
| 13 | List(HK_App) apps //list of applications | 18 | List(HK_App) apps //list of applications |
| 14 | ). | 19 | ). |
| 20 | + | ||
| 21 | + | ||
| 22 | + _HK_DATABASE message format: | ||
| 23 | + ========================= | ||
| 24 | + | ||
| 25 | + +-----------+---------------+-------------------------- | ||
| 26 | + | name | type | description | ||
| 27 | + +-----------+---------------+-------------------------------- | ||
| 28 | + | "name" | String | Name of the database | ||
| 29 | + | "apps" | List(Message) | List of Application of the database the application Message id is _HK_APP | ||
| 30 | + | ||
| 31 | +public define Message | ||
| 32 | + to_Message | ||
| 33 | + ( | ||
| 34 | + HK_Database hk_db | ||
| 35 | + )= | ||
| 36 | + with hk_db_message = message(_HK_DATABASE), | ||
| 37 | + forget(add_string(hk_db_message, "name", hk_db.name)); | ||
| 38 | + map_forget((HK_App app) |-> add_message(hk_db_message, "apps", to_Message(app)), hk_db.apps); | ||
| 39 | + | ||
| 40 | + //print_to_stream(hk_db_message); | ||
| 41 | + hk_db_message | ||
| 42 | + . | ||
| 43 | + | ||
| 44 | + | ||
| 45 | +public define Maybe(HK_Database) | ||
| 46 | + from_Message | ||
| 47 | + ( | ||
| 48 | + Message hk_db_message | ||
| 49 | + )= | ||
| 50 | + if *hk_db_message.what = _HK_DATABASE then | ||
| 51 | + if find_string(hk_db_message, "name") is | ||
| 52 | + { | ||
| 53 | + failure then failure, | ||
| 54 | + success(name) then | ||
| 55 | + with app_list = map_escape((Message msg_app) |-> (Maybe(HK_App))from_Message(msg_app), find_messages(hk_db_message, "apps")), | ||
| 56 | + if app_list is | ||
| 57 | + { | ||
| 58 | + failure then failure, | ||
| 59 | + success(apps) then success(hk_database(name, apps)) | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + else | ||
| 63 | + failure | ||
| 64 | + . | ||
| 65 | + |
types/model/display.anubis
| @@ -6,16 +6,95 @@ | @@ -6,16 +6,95 @@ | ||
| 6 | * © Calexium | 6 | * © Calexium |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | +transmit system/muscle.anubis | ||
| 10 | +transmit tools/basis.anubis | ||
| 11 | +transmit calexium_lib/CXM_message_constants.anubis | ||
| 9 | 12 | ||
| 10 | public type HK_List_View: | 13 | public type HK_List_View: |
| 11 | list_view_all, | 14 | list_view_all, |
| 12 | list_view(String view_name, List(String) columns). | 15 | list_view(String view_name, List(String) columns). |
| 13 | 16 | ||
| 17 | +public define Message | ||
| 18 | + to_Message | ||
| 19 | + ( | ||
| 20 | + HK_List_View list_view | ||
| 21 | + )= | ||
| 22 | + with _msg = message(_HK_LIST_VIEW), | ||
| 23 | + if list_view is | ||
| 24 | + { | ||
| 25 | + list_view_all then forget(add_string(_msg, "type", "list_view_all")), | ||
| 26 | + list_view(name, columns) then | ||
| 27 | + forget(add_string(_msg, "type", "list_view")); | ||
| 28 | + forget(add_string(_msg, "view_name", name)); | ||
| 29 | + map_forget((String column) |-> forget(add_string(_msg, "columns", column)), columns) | ||
| 30 | + }; | ||
| 31 | + _msg | ||
| 32 | + . | ||
| 33 | + | ||
| 34 | +public define Maybe(HK_List_View) | ||
| 35 | + from_Message | ||
| 36 | + ( | ||
| 37 | + Message msg | ||
| 38 | + )= | ||
| 39 | + if *msg.what = _HK_LIST_VIEW then | ||
| 40 | + if find_string(msg, "type") is {failure then failure, success(type) then | ||
| 41 | + if type = "list_view_all" then success(list_view_all) else | ||
| 42 | + if type = "list_view" then | ||
| 43 | + if find_string(msg, "view_name") is {failure then failure, success(view_name) then | ||
| 44 | + with columns = find_strings(msg, "columns"), | ||
| 45 | + success(list_view(view_name, columns))} | ||
| 46 | + else | ||
| 47 | + failure | ||
| 48 | + } | ||
| 49 | + else | ||
| 50 | + failure | ||
| 51 | + . | ||
| 52 | + | ||
| 14 | public type HK_Edit_View: | 53 | public type HK_Edit_View: |
| 15 | edit_view_all, | 54 | edit_view_all, |
| 16 | edit_view(String view_name, List(String) columns). | 55 | edit_view(String view_name, List(String) columns). |
| 56 | + | ||
| 57 | + _HK_MODEL_DISPLAY message format: | ||
| 58 | + ========================= | ||
| 59 | + The message string name is "hk_display" | ||
| 60 | + +--------------+---------------+-------------------------------- | ||
| 61 | + | name | type | description | ||
| 62 | + +--------------+---------------+-------------------------------- | ||
| 63 | + | "edits" | List(String) | List of columns for edit panel | ||
| 64 | + | "list_views" | List(Message) | List of (view list) the Message id is _HK_LIST_VIEW | ||
| 65 | + | ||
| 17 | 66 | ||
| 18 | public type HK_Display: | 67 | public type HK_Display: |
| 19 | hk_display(List(HK_List_View) list_views, | 68 | hk_display(List(HK_List_View) list_views, |
| 20 | //List(HK_Edit_View) edit_views | 69 | //List(HK_Edit_View) edit_views |
| 21 | List(String)). | 70 | List(String)). |
| 71 | + | ||
| 72 | +public define Message | ||
| 73 | + to_Message | ||
| 74 | + ( | ||
| 75 | + HK_Display display | ||
| 76 | + )= | ||
| 77 | + with hk_display_msg = message(_HK_MODEL_DISPLAY), | ||
| 78 | + since display is hk_display(list_views, list_edit), | ||
| 79 | + map_forget((HK_List_View _view) |-> add_message(hk_display_msg, "list_views", to_Message(_view)), list_views); | ||
| 80 | + map_forget((String _str) |-> add_string(hk_display_msg, "edits", _str), list_edit); | ||
| 81 | + hk_display_msg | ||
| 82 | + . | ||
| 83 | + | ||
| 84 | +public define Maybe(HK_Display) | ||
| 85 | + get_hk_display | ||
| 86 | + ( | ||
| 87 | + Message msg | ||
| 88 | + )= | ||
| 89 | + if find_message(msg, "hk_display") is { failure then failure, success(msg_hk_display) then | ||
| 90 | + if *msg_hk_display.what = _HK_MODEL_DISPLAY then | ||
| 91 | + with view_list = map_escape((Message _msg) |-> (Maybe(HK_List_View))from_Message(_msg), find_messages(msg_hk_display, "list_views")), | ||
| 92 | + if view_list is | ||
| 93 | + { | ||
| 94 | + failure then failure, | ||
| 95 | + success(list_views) then success(hk_display(list_views, find_strings(msg, "edits"))) | ||
| 96 | + } | ||
| 97 | + else | ||
| 98 | + failure | ||
| 99 | + }. | ||
| 100 | + |
types/model/fields.anubis
| @@ -6,6 +6,10 @@ | @@ -6,6 +6,10 @@ | ||
| 6 | * © Calexium | 6 | * © Calexium |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | +transmit tools/basis.anubis | ||
| 10 | +transmit system/convert.anubis | ||
| 11 | +transmit system/muscle.anubis | ||
| 12 | +transmit calexium_lib/CXM_message_constants.anubis | ||
| 9 | 13 | ||
| 10 | 14 | ||
| 11 | *** 'HK_Model_Field' (data types of table columns). | 15 | *** 'HK_Model_Field' (data types of table columns). |
| @@ -31,23 +35,90 @@ public type HK_App_Name: | @@ -31,23 +35,90 @@ public type HK_App_Name: | ||
| 31 | app_name(String name), | 35 | app_name(String name), |
| 32 | none. | 36 | none. |
| 33 | 37 | ||
| 38 | +public define Message | ||
| 39 | + to_Message | ||
| 40 | + ( | ||
| 41 | + HK_App_Name hk_app_name | ||
| 42 | + )= | ||
| 43 | + with hk_app_name_message = message(_HK_APP_NAME), | ||
| 44 | + if hk_app_name is | ||
| 45 | + { | ||
| 46 | + this then forget(add_string(hk_app_name_message, "type", "this")), | ||
| 47 | + app_name(name)then forget(add_string(hk_app_name_message, "type", "app_name")); | ||
| 48 | + forget(add_string(hk_app_name_message, "name", name)), | ||
| 49 | + none then forget(add_string(hk_app_name_message, "type", "none")) | ||
| 50 | + }; | ||
| 51 | + hk_app_name_message | ||
| 52 | + . | ||
| 53 | + | ||
| 54 | +public define Maybe(HK_App_Name) | ||
| 55 | + from_Message | ||
| 56 | + ( | ||
| 57 | + Message hk_app_name_message | ||
| 58 | + )= | ||
| 59 | + if *hk_app_name_message.what = _HK_APP_NAME then | ||
| 60 | + if find_string(hk_app_name_message, "type") is {failure then failure, success(type) then | ||
| 61 | + if type = "this" then success(this) | ||
| 62 | + else if type = "app_name" then | ||
| 63 | + if find_string(hk_app_name_message, "name") is {failure then failure, success(name) then | ||
| 64 | + success(app_name(name)) | ||
| 65 | + } | ||
| 66 | + else if type = "none" then success(none) | ||
| 67 | + else failure | ||
| 68 | + } | ||
| 69 | + else | ||
| 70 | + failure | ||
| 71 | + . | ||
| 72 | + | ||
| 73 | + | ||
| 34 | public type HK_Datetime_Field_Attr: | 74 | public type HK_Datetime_Field_Attr: |
| 35 | none, //Nothing special, normal behaviour | 75 | none, //Nothing special, normal behaviour |
| 36 | auto_now, //Always update datetime at SQL update | 76 | auto_now, //Always update datetime at SQL update |
| 37 | auto_now_add. //Set current datetime when row is created and can't be edited anymore | 77 | auto_now_add. //Set current datetime when row is created and can't be edited anymore |
| 38 | 78 | ||
| 79 | +define String | ||
| 80 | + to_String | ||
| 81 | + ( | ||
| 82 | + HK_Datetime_Field_Attr attr | ||
| 83 | + )= | ||
| 84 | + if attr is | ||
| 85 | + { | ||
| 86 | + none then "none", | ||
| 87 | + auto_now then "auto_now", | ||
| 88 | + auto_now_add then "auto_now_add" | ||
| 89 | + }. | ||
| 39 | 90 | ||
| 91 | +define HK_Datetime_Field_Attr | ||
| 92 | + to_HK_Datetime_Field_Attr | ||
| 93 | + ( | ||
| 94 | + String dt_attr_str | ||
| 95 | + )= | ||
| 96 | + if dt_attr_str = "none" then none else | ||
| 97 | + if dt_attr_str = "auto_now" then auto_now else | ||
| 98 | + if dt_attr_str = "auto_now_add" then auto_now_add | ||
| 99 | + else none. | ||
| 100 | + | ||
| 101 | +define HK_Datetime_Field_Attr | ||
| 102 | + get_dt_attribute | ||
| 103 | + ( | ||
| 104 | + Message msg | ||
| 105 | + )= | ||
| 106 | + if find_string(msg, "dt_attribute") is | ||
| 107 | + { | ||
| 108 | + failure then none, | ||
| 109 | + success(dt_attrib) then to_HK_Datetime_Field_Attr(dt_attrib) | ||
| 110 | + }. | ||
| 40 | 111 | ||
| 41 | public type HK_Model_Field: | 112 | public type HK_Model_Field: |
| 42 | - p_key, | ||
| 43 | - boolean_field, // true or false | ||
| 44 | - date_field (HK_Datetime_Field_Attr), // date with the precision of the day | ||
| 45 | - time_field (HK_Datetime_Field_Attr), // time with the precision of the second | ||
| 46 | - datetime_field(HK_Datetime_Field_Attr), // datetime with the precision of the second | ||
| 47 | - foreign_key (HK_App_Name app_name, String table_name), // foreign key to 'id' in another (or same) table and column_name for choice selector. | ||
| 48 | - integer_field, // integer of arbitrary size | ||
| 49 | - char_field (Int size), // text of maximal size 'size' (number of characters) | ||
| 50 | - text_field. // text of variable size | 113 | + p_key, |
| 114 | + boolean_field, // true or false | ||
| 115 | + date_field (HK_Datetime_Field_Attr), // date with the precision of the day | ||
| 116 | + time_field (HK_Datetime_Field_Attr), // time with the precision of the second | ||
| 117 | + datetime_field(HK_Datetime_Field_Attr), // datetime with the precision of the second | ||
| 118 | + foreign_key (HK_App_Name app_name, String table_name), // foreign key to 'id' in another (or same) table and column_name for choice selector. | ||
| 119 | + integer_field, // integer of arbitrary size | ||
| 120 | + char_field (Int size), // text of maximal size 'size' (number of characters) | ||
| 121 | + text_field. // text of variable size | ||
| 51 | 122 | ||
| 52 | public define HK_Model_Field | 123 | public define HK_Model_Field |
| 53 | foreign_key | 124 | foreign_key |
| @@ -55,3 +126,113 @@ public define HK_Model_Field | @@ -55,3 +126,113 @@ public define HK_Model_Field | ||
| 55 | String table_name | 126 | String table_name |
| 56 | )= | 127 | )= |
| 57 | foreign_key(this, table_name). | 128 | foreign_key(this, table_name). |
| 129 | + | ||
| 130 | + /* * | ||
| 131 | + _HK_FIELD message format: | ||
| 132 | + ============================= | ||
| 133 | + +----------------+-----------+-------------------------------- | ||
| 134 | + | name | type | description | ||
| 135 | + +----------------+-----------+-------------------------------- | ||
| 136 | + | "type" | String | type of the field. It sould be | ||
| 137 | + "p_key" | ||
| 138 | + "boolean_field" | ||
| 139 | + "date_field" __________ | ||
| 140 | + "time_field" ________ | | ||
| 141 | + "datetime_field" __ | | | ||
| 142 | + ________________________________________________|_|_| | ||
| 143 | + | "foreign_key" _________ | ||
| 144 | + | "integer_field" | ||
| 145 | + | "char_field" | ||
| 146 | + | "text_field" | ||
| 147 | + | | ||
| 148 | + --> date_field or time_field or datetime_field: | ||
| 149 | + +-------------+--------+------------------------------------+ | ||
| 150 | + | name | type | description | | ||
| 151 | + |-------------+--------+------------------------------------| | ||
| 152 | + | "attribute" | String | 'none', 'auto_now', 'auto_now_add' | | ||
| 153 | + +-----------------------------------------------------------+ | ||
| 154 | + | ||
| 155 | +*/ | ||
| 156 | + | ||
| 157 | +public define Message | ||
| 158 | + to_Message | ||
| 159 | + ( | ||
| 160 | + HK_Model_Field hk_model_field | ||
| 161 | + )= | ||
| 162 | + with hk_model_field_message = message(_HK_FIELD), | ||
| 163 | + if hk_model_field is | ||
| 164 | + { | ||
| 165 | + p_key then | ||
| 166 | + forget(add_string(hk_model_field_message, "type", "p_key")), | ||
| 167 | + | ||
| 168 | + boolean_field then | ||
| 169 | + forget(add_string(hk_model_field_message, "type", "boolean_field")), | ||
| 170 | + | ||
| 171 | + date_field(attr) then | ||
| 172 | + forget(add_string(hk_model_field_message, "type", "date_field")); | ||
| 173 | + forget(add_string(hk_model_field_message, "dt_attribute", to_String(attr))), | ||
| 174 | + | ||
| 175 | + time_field(attr) then | ||
| 176 | + forget(add_string(hk_model_field_message, "type", "time_field")); | ||
| 177 | + forget(add_string(hk_model_field_message, "dt_attribute", to_String(attr))), | ||
| 178 | + | ||
| 179 | + datetime_field(attr) then | ||
| 180 | + forget(add_string(hk_model_field_message, "type", "datetime_field")); | ||
| 181 | + forget(add_string(hk_model_field_message, "dt_attribute", to_String(attr))), | ||
| 182 | + | ||
| 183 | + foreign_key(app_name, table_name) then // foreign key to 'id' in another (or same) table and column_name for choice selector. | ||
| 184 | + forget(add_string(hk_model_field_message, "type", "foreign_key")); | ||
| 185 | + forget(add_message(hk_model_field_message, "app_name", to_Message(app_name))); | ||
| 186 | + forget(add_string(hk_model_field_message, "table_name", table_name)), | ||
| 187 | + | ||
| 188 | + integer_field then // integer of arbitrary size | ||
| 189 | + forget(add_string(hk_model_field_message, "type", "integer_field")), | ||
| 190 | + | ||
| 191 | + char_field (size) then // text of maximal size 'size' (number of characters) | ||
| 192 | + forget(add_string(hk_model_field_message, "type", "char_field")); | ||
| 193 | + forget(add_int32(hk_model_field_message, "size", truncate_to_Word32(size))), | ||
| 194 | + | ||
| 195 | + text_field then // text of variable size | ||
| 196 | + forget(add_string(hk_model_field_message, "type", "text_field")) | ||
| 197 | + | ||
| 198 | + }; | ||
| 199 | + hk_model_field_message | ||
| 200 | + . | ||
| 201 | + | ||
| 202 | +define Maybe(HK_Model_Field) | ||
| 203 | + get_field | ||
| 204 | + ( | ||
| 205 | + Message hk_model_field_message, | ||
| 206 | + String type | ||
| 207 | + )= | ||
| 208 | + if type = "p_key" then success(p_key) | ||
| 209 | + else if type = "boolean_field" then success(boolean_field) | ||
| 210 | + else if type = "date_field" then success(date_field(get_dt_attribute(hk_model_field_message))) | ||
| 211 | + else if type = "time_field" then success(time_field(get_dt_attribute(hk_model_field_message))) | ||
| 212 | + else if type = "datetime_field" then success(datetime_field(get_dt_attribute(hk_model_field_message))) | ||
| 213 | + else if type = "foreign_key" then | ||
| 214 | + if find_string(hk_model_field_message, "table_name") is {failure then failure, success(table_name) then | ||
| 215 | + if find_message(hk_model_field_message, "app_name") is {failure then failure, success(msg_app_name) then | ||
| 216 | + if from_Message(msg_app_name) is {failure then failure, success(app_name) then | ||
| 217 | + success(foreign_key(app_name, table_name)) | ||
| 218 | + }}} | ||
| 219 | + else if type = "integer_field" then success(integer_field) | ||
| 220 | + else if type = "char_field" then | ||
| 221 | + if find_int32(hk_model_field_message, "size") is {failure then failure, success(w32_size) then | ||
| 222 | + success(char_field(to_Int(w32_size)))} | ||
| 223 | + else if type = "text_field" then success(text_field) | ||
| 224 | + else failure | ||
| 225 | + . | ||
| 226 | + | ||
| 227 | +public define Maybe(HK_Model_Field) | ||
| 228 | + from_Message | ||
| 229 | + ( | ||
| 230 | + Message hk_model_field_message | ||
| 231 | + )= | ||
| 232 | + if *hk_model_field_message.what = _HK_FIELD then | ||
| 233 | + if find_string(hk_model_field_message, "type") is {failure then failure, success(type) then | ||
| 234 | + get_field(hk_model_field_message, type) | ||
| 235 | + } | ||
| 236 | + else | ||
| 237 | + failure | ||
| 238 | + . |
types/model/help.anubis
| @@ -6,6 +6,9 @@ | @@ -6,6 +6,9 @@ | ||
| 6 | * © Calexium | 6 | * © Calexium |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | +transmit tools/basis.anubis | ||
| 10 | +transmit system/muscle.anubis | ||
| 11 | +transmit calexium_lib/CXM_message_constants.anubis | ||
| 9 | 12 | ||
| 10 | public type HK_Help_Text: | 13 | public type HK_Help_Text: |
| 11 | no_help_text, //no help text available | 14 | no_help_text, //no help text available |
| @@ -25,3 +28,63 @@ public define String | @@ -25,3 +28,63 @@ public define String | ||
| 25 | help_text_TAG(tag) then "help_text_TAG(\""+tag+"\")", | 28 | help_text_TAG(tag) then "help_text_TAG(\""+tag+"\")", |
| 26 | help_text(str) then "help_text(\""+str+"\")" | 29 | help_text(str) then "help_text(\""+str+"\")" |
| 27 | }. | 30 | }. |
| 31 | + | ||
| 32 | + /* * | ||
| 33 | + _HK_HELP_TEXT message format: | ||
| 34 | + ============================= | ||
| 35 | + +----------------+-----------+-------------------------------- | ||
| 36 | + | name | type | description | ||
| 37 | + +----------------+-----------+-------------------------------- | ||
| 38 | + | "hk_help_text" | String | type of the help text. It sould be | ||
| 39 | + "no_help" | ||
| 40 | + "TAG" ____ | ||
| 41 | + "text" __ | | ||
| 42 | + ______________________________________|_| | ||
| 43 | + | | ||
| 44 | + --> TAG or text: | ||
| 45 | + +---------+-----------+-------------------------------- | ||
| 46 | + | name | type | description | ||
| 47 | + +---------+-----------+-------------------------------- | ||
| 48 | + | "value" | String | String name of the 16x16 icon. | ||
| 49 | + | ||
| 50 | +*/ | ||
| 51 | + | ||
| 52 | +public define Message | ||
| 53 | + to_Message | ||
| 54 | + ( | ||
| 55 | + HK_Help_Text hk_help | ||
| 56 | + )= | ||
| 57 | + with hk_help_message = message(_HK_HELP_TEXT), | ||
| 58 | + if hk_help is | ||
| 59 | + { | ||
| 60 | + no_help_text then forget(add_string(hk_help_message, "hk_help_text", "no_help")), | ||
| 61 | + help_text_TAG(tag) then forget(add_string(hk_help_message, "hk_help_text", "TAG")); | ||
| 62 | + forget(add_string(hk_help_message, "value", tag)), | ||
| 63 | + help_text(value) then forget(add_string(hk_help_message, "hk_help_text", "text")); | ||
| 64 | + forget(add_string(hk_help_message, "value", value)) | ||
| 65 | + }; | ||
| 66 | + hk_help_message | ||
| 67 | + . | ||
| 68 | + | ||
| 69 | +public define Maybe(HK_Help_Text) | ||
| 70 | + from_Message | ||
| 71 | + ( | ||
| 72 | + Message hk_help_message | ||
| 73 | + )= | ||
| 74 | + if *hk_help_message.what = _HK_HELP_TEXT then | ||
| 75 | + if find_string(hk_help_message, "hk_help_text") is {failure then failure, success(help_type) then | ||
| 76 | + if help_type = "no_help" then success(no_help_text) | ||
| 77 | + else if help_type = "TAG" then | ||
| 78 | + if find_string(hk_help_message, "value") is {failure then failure, success(value) then | ||
| 79 | + success(help_text_TAG(value)) | ||
| 80 | + } | ||
| 81 | + else if help_type = "text" then | ||
| 82 | + if find_string(hk_help_message, "value") is {failure then failure, success(value) then | ||
| 83 | + success(help_text(value)) | ||
| 84 | + } | ||
| 85 | + else failure | ||
| 86 | + } | ||
| 87 | + else | ||
| 88 | + failure | ||
| 89 | + . | ||
| 90 | + |
types/model/icons.anubis
| @@ -6,6 +6,9 @@ | @@ -6,6 +6,9 @@ | ||
| 6 | * © Calexium | 6 | * © Calexium |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | +transmit tools/basis.anubis | ||
| 10 | +transmit system/muscle.anubis | ||
| 11 | +transmit calexium_lib/CXM_message_constants.anubis | ||
| 9 | 12 | ||
| 10 | public type HK_Icon: | 13 | public type HK_Icon: |
| 11 | no_icon, | 14 | no_icon, |
| @@ -36,3 +39,56 @@ public define String | @@ -36,3 +39,56 @@ public define String | ||
| 36 | no_icon then "\"\"", | 39 | no_icon then "\"\"", |
| 37 | icon16(icn_str) then "\""+icn_str+"_icon\"" | 40 | icon16(icn_str) then "\""+icn_str+"_icon\"" |
| 38 | }. | 41 | }. |
| 42 | + | ||
| 43 | + * * | ||
| 44 | + _HK_ICON message format: | ||
| 45 | + ======================= | ||
| 46 | + +-----------+-----------+-------------------------------- | ||
| 47 | + | name | type | description | ||
| 48 | + +-----------+-----------+-------------------------------- | ||
| 49 | + | "hk_icon" | String | type of the icon. It sould be | ||
| 50 | + "no_icon" | ||
| 51 | + "icon_16" __ | ||
| 52 | + ______________________________________| | ||
| 53 | + | | ||
| 54 | + --> icon_16: | ||
| 55 | + +-----------+-----------+-------------------------------- | ||
| 56 | + | name | type | description | ||
| 57 | + +-----------+-----------+-------------------------------- | ||
| 58 | + | "icn_str" | String | String name of the 16x16 icon. | ||
| 59 | + | ||
| 60 | + */ | ||
| 61 | + | ||
| 62 | +public define Message | ||
| 63 | + to_Message | ||
| 64 | + ( | ||
| 65 | + HK_Icon hk_icon | ||
| 66 | + )= | ||
| 67 | + with hk_icon_message = message(_HK_ICON), | ||
| 68 | + if hk_icon is | ||
| 69 | + { | ||
| 70 | + no_icon then forget(add_string(hk_icon_message, "hk_icon", "no_icon")); | ||
| 71 | + hk_icon_message, | ||
| 72 | + icon16(icn_str) then forget(add_string(hk_icon_message, "hk_icon", "icon_16")); | ||
| 73 | + forget(add_string(hk_icon_message, "icn_str", icn_str)); | ||
| 74 | + hk_icon_message | ||
| 75 | + }. | ||
| 76 | + | ||
| 77 | +public define Maybe(HK_Icon) | ||
| 78 | + from_Message | ||
| 79 | + ( | ||
| 80 | + Message hk_icon_message | ||
| 81 | + )= | ||
| 82 | + if *hk_icon_message.what = _HK_ICON then | ||
| 83 | + if find_string(hk_icon_message, "hk_icon") is {failure then failure, success(hk_icon) then | ||
| 84 | + if hk_icon = "no_icon" then success(no_icon) | ||
| 85 | + else if hk_icon = "icon_16" then | ||
| 86 | + if find_string(hk_icon_message, "icn_str") is {failure then failure, success(icn_str) then | ||
| 87 | + success(icon16(icn_str)) | ||
| 88 | + } | ||
| 89 | + else failure | ||
| 90 | + } | ||
| 91 | + else | ||
| 92 | + failure | ||
| 93 | + . | ||
| 94 | + |
types/model/model.anubis
| @@ -6,10 +6,50 @@ | @@ -6,10 +6,50 @@ | ||
| 6 | * © Calexium | 6 | * © Calexium |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | +transmit tools/basis.anubis | ||
| 9 | transmit columns.anubis | 10 | transmit columns.anubis |
| 10 | 11 | ||
| 11 | public type HK_Model: | 12 | public type HK_Model: |
| 12 | hk_model( List(HK_Model_Column) columns, // columns other than the primary key column (if any) | 13 | hk_model( List(HK_Model_Column) columns, // columns other than the primary key column (if any) |
| 13 | String show_string). | 14 | String show_string). |
| 14 | 15 | ||
| 16 | + _HK_MODEL message format: | ||
| 17 | + ======================== | ||
| 18 | + | ||
| 19 | + +------------+---------------+-------------------------- | ||
| 20 | + | name | type | description | ||
| 21 | + +------------+---------------+-------------------------------- | ||
| 22 | + | "columns" | List(Message) | List of columns of the table Message id is _HK_COLUMN | ||
| 23 | + | "show_str" | String | computation String to be shown to summarize row content. This string is Anubis source code | ||
| 24 | + where the row content is in datum, named "obj". | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +public define Message | ||
| 28 | + to_Message | ||
| 29 | + ( | ||
| 30 | + HK_Model hk_model | ||
| 31 | + )= | ||
| 32 | + with hk_model_message = message(_HK_MODEL), | ||
| 33 | + map_forget((HK_Model_Column column) |-> add_message(hk_model_message, "columns", to_Message(column)), hk_model.columns); | ||
| 34 | + forget(add_string(hk_model_message, "show_str", hk_model.show_string)); | ||
| 35 | + | ||
| 36 | + //print_to_stream(hk_model_message); | ||
| 37 | + hk_model_message | ||
| 38 | + . | ||
| 39 | + | ||
| 15 | 40 | ||
| 41 | +public define Maybe(HK_Model) | ||
| 42 | + from_Message | ||
| 43 | + ( | ||
| 44 | + Message hk_model_msg | ||
| 45 | + )= | ||
| 46 | + if *hk_model_msg.what = _HK_MODEL then | ||
| 47 | + if find_string(hk_model_msg, "show_str") is {failure then failure, success(show_str) then | ||
| 48 | + with mb_columns = map_escape((Message column_msg) |-> (Maybe(HK_Model_Column))from_Message(column_msg), find_messages(hk_model_msg, "columns")), | ||
| 49 | + if mb_columns is {failure then failure, success(columns_list) then | ||
| 50 | + //return the model | ||
| 51 | + success(hk_model(columns_list, show_str)) | ||
| 52 | + }} | ||
| 53 | + else | ||
| 54 | + failure | ||
| 55 | + . |
types/model/tables.anubis
| @@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
| 6 | * © Calexium | 6 | * © Calexium |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | +read tools/basis.anubis | ||
| 9 | transmit display.anubis | 10 | transmit display.anubis |
| 10 | transmit model.anubis | 11 | transmit model.anubis |
| 11 | 12 | ||
| @@ -23,3 +24,47 @@ public define HK_Table | @@ -23,3 +24,47 @@ public define HK_Table | ||
| 23 | HK_Display display | 24 | HK_Display display |
| 24 | )= | 25 | )= |
| 25 | hk_table(name, "", model, display). | 26 | hk_table(name, "", model, display). |
| 27 | + | ||
| 28 | + | ||
| 29 | + _HK_TABLE message format: | ||
| 30 | + ========================= | ||
| 31 | + +--------------+-----------+-------------------------- | ||
| 32 | + | name | type | description | ||
| 33 | + +--------------+-----------+-------------------------------- | ||
| 34 | + | "name" | String | Name of the table | ||
| 35 | + | "short_name" | String | Name of the table without app_name prefix | ||
| 36 | + | "model" | Message | Model description, contained in message id _HK_MODEL | ||
| 37 | + | "hk_display" | Message | Help string, contained in message id _HK_MODEL_DISPLAY | ||
| 38 | + | ||
| 39 | + | ||
| 40 | +public define Message | ||
| 41 | + to_Message | ||
| 42 | + ( | ||
| 43 | + HK_Table table | ||
| 44 | + )= | ||
| 45 | + with hk_table_message = message(_HK_TABLE), | ||
| 46 | + forget(add_string(hk_table_message, "name", table.name)); | ||
| 47 | + forget(add_string(hk_table_message, "short_name", table.name)); | ||
| 48 | + forget(add_message(hk_table_message, "model", to_Message(table.model))); | ||
| 49 | + forget(add_message(hk_table_message, "hk_display", to_Message(table.display))); | ||
| 50 | + //print_to_stream(hk_table_message); | ||
| 51 | + hk_table_message. | ||
| 52 | + | ||
| 53 | +public define Maybe(HK_Table) | ||
| 54 | + from_Message | ||
| 55 | + ( | ||
| 56 | + Message table_message | ||
| 57 | + )= | ||
| 58 | + if *table_message.what = _HK_TABLE then | ||
| 59 | + if find_string(table_message, "name") is {failure then failure, success(name) then | ||
| 60 | + if find_string(table_message, "short_name") is {failure then failure, success(short_name) then | ||
| 61 | + if find_message(table_message, "model") is {failure then failure, success(model_msg) then | ||
| 62 | + if (Maybe(HK_Model))from_Message(model_msg) is {failure then failure, success(model) then | ||
| 63 | + if get_hk_display(table_message) is {failure then failure, success(display) then | ||
| 64 | + //return the table | ||
| 65 | + success(hk_table(name, "", model, display)) | ||
| 66 | + }}}}} | ||
| 67 | + else | ||
| 68 | + failure | ||
| 69 | + . | ||
| 70 | + |