diff --git a/database/model/db_model.anubis b/database/model/db_model.anubis index 30306a6..51502ef 100644 --- a/database/model/db_model.anubis +++ b/database/model/db_model.anubis @@ -6,7 +6,7 @@ * © Calexium */ - The Anubis project + The HayamiKi (早見木) project Interfacing and generating a database with Anubis @@ -82,14 +82,16 @@ public type DB_Model_Attr: unique, // by default, the values in a column are not required to be all different indexed, // by default, a column is not indexed default(String). // default value (used in case of creation of a NON NULL column - // in a table which already contains some rows) + // in a table which already contains some rows) public type DB_Help_Text: no_help_text, //no help text available - help_text_TAG(String), //TAG - help_text(String). //TAG + help_text_TAG(String), //TAG use with Anubis translation tool /locale/L3.anubis + help_text(String). //pure text to show public define String +/* Return the Anubis source of the type component +*/ to_Anubis_source ( DB_Help_Text help @@ -117,6 +119,9 @@ public type DB_Model_Column: ). public define DB_Model_Column +/* Constructor helper for db_column without help attribute. + the real type constructor will be called with the attribute no_help_text +*/ db_column ( String name, @@ -142,10 +147,18 @@ public type DB_Model: db_model( List(DB_Model_Column) columns, // columns other than the primary key column (if any) String show_string). +public type HK_List_View: + list_view_all, + list_view(String view_name, List(String) columns). +public type HK_Edit_View: + edit_view_all, + edit_view(String view_name, List(String) columns). + public type DB_Display: - db_display(List(String) list_view, - List(String) edit_view). + db_display(List(HK_List_View) list_views, + //List(HK_Edit_View) edit_views + List(String)). public type DB_Table: db_table ( String name, // name of the table @@ -195,7 +208,7 @@ read tools/basis.anubis read tools/base64.anubis read system/string.anubis read tools/ISO-8601.anubis - +read calexium_lib/web/widgets/icons_set.anubis *** [1] Tools. @@ -422,30 +435,45 @@ public define String text_field then "get_String(lwa, \""+name+"\")" }. -public define List(String) -/** +define List(String) +/* return the list of all columns name */ - components + _to_List_String ( List(DB_Model_Column) columns, + Bool with_pk, List(String) so_far )= if columns is { [] then reverse(so_far), [h . t ] then - since h is db_column(name, col_type, _, _), - components(t, [ name . so_far]) + since h is db_column(name, _, _, _), + if name = "id" & with_pk = false then + _to_List_String(t, with_pk, so_far) + else + _to_List_String(t, with_pk, [ name . so_far]) }. +public define List(String) +/* return the list of all columns name + */ + to_List_String + ( + List(DB_Model_Column) columns, + Bool with_pk + )= + _to_List_String(columns, with_pk, []). + + public define String generate_constructor ( - String constructor_name, + String constructor_name, List(DB_Model_Column) columns, - String indent + String indent )= - indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", components(columns, []))+")". + indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", to_List_String(columns, true))+")". public define String to_Bind @@ -673,7 +701,7 @@ public define Maybe(DB_Model_Column) }. public define String -/** to_String return the String +/** to_String return the String of the given model of the column 'col' */ to_String ( @@ -696,10 +724,51 @@ public define String char_field(Int size) then current_type_name+"."+name, text_field then current_type_name+"."+name }. - + +public define String +/** to_String return the String of the given model of the column 'col' + */ + to_Icon + ( + DB_Model_Column col, + String current_type_name, + String general_type_name + ) = + since col is db_column(name, col_type, _, _), + if col_type is + { + p_key then icn16_key, + boolean_field then "to_Icon("+current_type_name+"."+name+")", + date_field(attrs) then icn16_clock, + time_field(attrs) then icn16_clock, + datetime_field(attrs) then icn16_clock, + foreign_key(foreign_table) then icn16_question, + integer_field then icn16_question, + char_field(Int size) then icn16_question, + text_field then icn16_question + }. + public define String to_HTML_cell_text ( + DB_Model_Column column, + String data_name, + String general_type_name + )= + "text("+to_String(column, data_name, general_type_name)+")". + +public define String + to_HTML_cell_link + ( + DB_Model_Column column, + String data_name, + String general_type_name + )= + "link(to_String("+data_name+".id), "+to_String(column, data_name, general_type_name)+")". + +public define String + to_HTML_cell_link + ( List(DB_Model_Column) columns, String column_name, String data_name, @@ -708,11 +777,21 @@ public define String if get_column_type(columns, column_name) is { failure then "column name "+column_name+"doesn't exist", - success(column) then "text("+to_String(column, data_name, general_type_name)+")" + success(column) then to_HTML_cell_link(column, data_name, general_type_name) }. public define String - to_HTML_cell_link + to_HTML_cell_icon + ( + DB_Model_Column column, + String data_name, + String general_type_name + )= + "icon("+to_Icon(column, data_name, general_type_name)+")". + + +public define String + to_HTML_cell ( List(DB_Model_Column) columns, String column_name, @@ -722,28 +801,50 @@ public define String if get_column_type(columns, column_name) is { failure then "column name "+column_name+"doesn't exist", - success(column) then "link(to_String("+data_name+".id), "+to_String(column, data_name, general_type_name)+")" + success(column) then + since column is db_column(name, col_type, _, _), + if col_type is + { + //anubis(_T) then "constant_byte_array(0,0)", + p_key then to_HTML_cell_link(column, data_name, general_type_name), + //binary then "constant_byte_array(0,0)", + boolean_field then to_HTML_cell_icon(column, data_name, general_type_name), + date_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), + time_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), + datetime_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), + foreign_key(foreign_table) then to_HTML_cell_text(column, data_name, general_type_name), + integer_field then to_HTML_cell_text(column, data_name, general_type_name), + char_field(Int size) then to_HTML_cell_text(column, data_name, general_type_name), + text_field then to_HTML_cell_text(column, data_name, general_type_name), + } }. public define String make_list_view_row ( - DB_Table table, - String data_name, - String indent + DB_Table table, //table to format + String data_name, //name of data + String indent, //indentation string to use + HK_List_View list_view //list view to generate )= - since table is db_table(name, model, display), - since model is db_model( columns, _), - since display is db_display(list_view, _), - if list_view is + since table is db_table(table_name, model, _), //get name and model of the table + since model is db_model( columns, _), //get all columns of table +// 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 + }, + + if current_list_column is { [] then "", [h . t] then indent+join(",\n"+indent, //Make first column as link - [to_HTML_cell_link(columns, h, data_name, name)] + + [to_HTML_cell_link(columns, h, data_name, table_name)] + //and the other set with list_view - map((String column_name) |-> to_HTML_cell_text(columns, column_name, data_name, name), t) + map((String column_name) |-> to_HTML_cell(columns, column_name, data_name, table_name), t) ) }. diff --git a/web/widgets/icons_set.anubis b/web/widgets/icons_set.anubis index 2a47ebb..d50c0b5 100644 --- a/web/widgets/icons_set.anubis +++ b/web/widgets/icons_set.anubis @@ -6,15 +6,23 @@ * © Calexium */ -public define String icn16_cross = "icons/16x16/cross.png". -public define String icn16_edit = "icons/16x16/edit.png". -public define String icn16_check = "icons/16x16/check.png". -public define String icn16_phone = "icons/16x16/phone.png". -public define String icn16_locked = "icons/16x16/locked.png". + +public define String icn16_edit = "icons/16x16/edit.png". +public define String icn16_calendar = "icons/16x16/calendar.png". +public define String icn16_check = "icons/16x16/check.png". public define String icn16_clock = "icons/16x16/clock.png". +public define String icn16_cross = "icons/16x16/cross.png". +public define String icn16_key = "icons/16x16/key.png". +public define String icn16_locked = "icons/16x16/locked.png". +public define String icn16_phone = "icons/16x16/phone.png". public define String icn16_vcard_add = "icons/16x16/vcard_add.png". public define String icn16_folder_edit = "icons/16x16/folder_edit.png". public define String icn16_group = "icons/16x16/group.png". +public define String icn16_question = "icons/16x16/question.png". +public define String icn16_warning = "icons/16x16/warning.png". + +public define String icn16_true = "icons/16x16/check.png". +public define String icn16_false = "icons/16x16/cross.png". /****------------------ MIME PART -----------------****/ @@ -24,3 +32,5 @@ public define String icn16_mime_csv = "icons/16x16/mimetypes/csv.png". public define String icn16_mime_unknown = "icons/16x16/mimetypes/unknown.png". public define String icn16_mime(String mimetype) = "icons/16x16/mimetypes/"+mimetype+".png". + +public define String to_Icon (Bool value)= if value then icn16_true else icn16_false. -- libgit2 0.21.4