Commit 6cf67b09e781c09f8475c678ba69991772066a76
1 parent
204b0087
add HK_List_View type in db_display. Now we can define a set of named view list display
add some icon add to_Icon for bool value which become red cross for false and green check for true
Showing
2 changed files
with
145 additions
and
34 deletions
Show diff stats
database/model/db_model.anubis
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | * © Calexium | 6 | * © Calexium |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | - The Anubis project | 9 | + The HayamiKi (早見木) project |
| 10 | 10 | ||
| 11 | Interfacing and generating a database with Anubis | 11 | Interfacing and generating a database with Anubis |
| 12 | 12 | ||
| @@ -82,14 +82,16 @@ public type DB_Model_Attr: | @@ -82,14 +82,16 @@ public type DB_Model_Attr: | ||
| 82 | unique, // by default, the values in a column are not required to be all different | 82 | unique, // by default, the values in a column are not required to be all different |
| 83 | indexed, // by default, a column is not indexed | 83 | indexed, // by default, a column is not indexed |
| 84 | default(String). // default value (used in case of creation of a NON NULL column | 84 | default(String). // default value (used in case of creation of a NON NULL column |
| 85 | - // in a table which already contains some rows) | 85 | + // in a table which already contains some rows) |
| 86 | 86 | ||
| 87 | public type DB_Help_Text: | 87 | public type DB_Help_Text: |
| 88 | no_help_text, //no help text available | 88 | no_help_text, //no help text available |
| 89 | - help_text_TAG(String), //TAG | ||
| 90 | - help_text(String). //TAG | 89 | + help_text_TAG(String), //TAG use with Anubis translation tool /locale/L3.anubis |
| 90 | + help_text(String). //pure text to show | ||
| 91 | 91 | ||
| 92 | public define String | 92 | public define String |
| 93 | +/* Return the Anubis source of the type component | ||
| 94 | +*/ | ||
| 93 | to_Anubis_source | 95 | to_Anubis_source |
| 94 | ( | 96 | ( |
| 95 | DB_Help_Text help | 97 | DB_Help_Text help |
| @@ -117,6 +119,9 @@ public type DB_Model_Column: | @@ -117,6 +119,9 @@ public type DB_Model_Column: | ||
| 117 | ). | 119 | ). |
| 118 | 120 | ||
| 119 | public define DB_Model_Column | 121 | public define DB_Model_Column |
| 122 | +/* Constructor helper for db_column without help attribute. | ||
| 123 | + the real type constructor will be called with the attribute no_help_text | ||
| 124 | +*/ | ||
| 120 | db_column | 125 | db_column |
| 121 | ( | 126 | ( |
| 122 | String name, | 127 | String name, |
| @@ -142,10 +147,18 @@ public type DB_Model: | @@ -142,10 +147,18 @@ public type DB_Model: | ||
| 142 | db_model( List(DB_Model_Column) columns, // columns other than the primary key column (if any) | 147 | db_model( List(DB_Model_Column) columns, // columns other than the primary key column (if any) |
| 143 | String show_string). | 148 | String show_string). |
| 144 | 149 | ||
| 150 | +public type HK_List_View: | ||
| 151 | + list_view_all, | ||
| 152 | + list_view(String view_name, List(String) columns). | ||
| 145 | 153 | ||
| 154 | +public type HK_Edit_View: | ||
| 155 | + edit_view_all, | ||
| 156 | + edit_view(String view_name, List(String) columns). | ||
| 157 | + | ||
| 146 | public type DB_Display: | 158 | public type DB_Display: |
| 147 | - db_display(List(String) list_view, | ||
| 148 | - List(String) edit_view). | 159 | + db_display(List(HK_List_View) list_views, |
| 160 | + //List(HK_Edit_View) edit_views | ||
| 161 | + List(String)). | ||
| 149 | 162 | ||
| 150 | public type DB_Table: | 163 | public type DB_Table: |
| 151 | db_table ( String name, // name of the table | 164 | db_table ( String name, // name of the table |
| @@ -195,7 +208,7 @@ read tools/basis.anubis | @@ -195,7 +208,7 @@ read tools/basis.anubis | ||
| 195 | read tools/base64.anubis | 208 | read tools/base64.anubis |
| 196 | read system/string.anubis | 209 | read system/string.anubis |
| 197 | read tools/ISO-8601.anubis | 210 | read tools/ISO-8601.anubis |
| 198 | - | 211 | +read calexium_lib/web/widgets/icons_set.anubis |
| 199 | 212 | ||
| 200 | *** [1] Tools. | 213 | *** [1] Tools. |
| 201 | 214 | ||
| @@ -422,30 +435,45 @@ public define String | @@ -422,30 +435,45 @@ public define String | ||
| 422 | text_field then "get_String(lwa, \""+name+"\")" | 435 | text_field then "get_String(lwa, \""+name+"\")" |
| 423 | }. | 436 | }. |
| 424 | 437 | ||
| 425 | -public define List(String) | ||
| 426 | -/** | 438 | +define List(String) |
| 439 | +/* return the list of all columns name | ||
| 427 | */ | 440 | */ |
| 428 | - components | 441 | + _to_List_String |
| 429 | ( | 442 | ( |
| 430 | List(DB_Model_Column) columns, | 443 | List(DB_Model_Column) columns, |
| 444 | + Bool with_pk, | ||
| 431 | List(String) so_far | 445 | List(String) so_far |
| 432 | )= | 446 | )= |
| 433 | if columns is | 447 | if columns is |
| 434 | { | 448 | { |
| 435 | [] then reverse(so_far), | 449 | [] then reverse(so_far), |
| 436 | [h . t ] then | 450 | [h . t ] then |
| 437 | - since h is db_column(name, col_type, _, _), | ||
| 438 | - components(t, [ name . so_far]) | 451 | + since h is db_column(name, _, _, _), |
| 452 | + if name = "id" & with_pk = false then | ||
| 453 | + _to_List_String(t, with_pk, so_far) | ||
| 454 | + else | ||
| 455 | + _to_List_String(t, with_pk, [ name . so_far]) | ||
| 439 | }. | 456 | }. |
| 440 | 457 | ||
| 458 | +public define List(String) | ||
| 459 | +/* return the list of all columns name | ||
| 460 | + */ | ||
| 461 | + to_List_String | ||
| 462 | + ( | ||
| 463 | + List(DB_Model_Column) columns, | ||
| 464 | + Bool with_pk | ||
| 465 | + )= | ||
| 466 | + _to_List_String(columns, with_pk, []). | ||
| 467 | + | ||
| 468 | + | ||
| 441 | public define String | 469 | public define String |
| 442 | generate_constructor | 470 | generate_constructor |
| 443 | ( | 471 | ( |
| 444 | - String constructor_name, | 472 | + String constructor_name, |
| 445 | List(DB_Model_Column) columns, | 473 | List(DB_Model_Column) columns, |
| 446 | - String indent | 474 | + String indent |
| 447 | )= | 475 | )= |
| 448 | - indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", components(columns, []))+")". | 476 | + indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", to_List_String(columns, true))+")". |
| 449 | 477 | ||
| 450 | public define String | 478 | public define String |
| 451 | to_Bind | 479 | to_Bind |
| @@ -673,7 +701,7 @@ public define Maybe(DB_Model_Column) | @@ -673,7 +701,7 @@ public define Maybe(DB_Model_Column) | ||
| 673 | }. | 701 | }. |
| 674 | 702 | ||
| 675 | public define String | 703 | public define String |
| 676 | -/** to_String return the String | 704 | +/** to_String return the String of the given model of the column 'col' |
| 677 | */ | 705 | */ |
| 678 | to_String | 706 | to_String |
| 679 | ( | 707 | ( |
| @@ -696,10 +724,51 @@ public define String | @@ -696,10 +724,51 @@ public define String | ||
| 696 | char_field(Int size) then current_type_name+"."+name, | 724 | char_field(Int size) then current_type_name+"."+name, |
| 697 | text_field then current_type_name+"."+name | 725 | text_field then current_type_name+"."+name |
| 698 | }. | 726 | }. |
| 699 | - | 727 | + |
| 728 | +public define String | ||
| 729 | +/** to_String return the String of the given model of the column 'col' | ||
| 730 | + */ | ||
| 731 | + to_Icon | ||
| 732 | + ( | ||
| 733 | + DB_Model_Column col, | ||
| 734 | + String current_type_name, | ||
| 735 | + String general_type_name | ||
| 736 | + ) = | ||
| 737 | + since col is db_column(name, col_type, _, _), | ||
| 738 | + if col_type is | ||
| 739 | + { | ||
| 740 | + p_key then icn16_key, | ||
| 741 | + boolean_field then "to_Icon("+current_type_name+"."+name+")", | ||
| 742 | + date_field(attrs) then icn16_clock, | ||
| 743 | + time_field(attrs) then icn16_clock, | ||
| 744 | + datetime_field(attrs) then icn16_clock, | ||
| 745 | + foreign_key(foreign_table) then icn16_question, | ||
| 746 | + integer_field then icn16_question, | ||
| 747 | + char_field(Int size) then icn16_question, | ||
| 748 | + text_field then icn16_question | ||
| 749 | + }. | ||
| 750 | + | ||
| 700 | public define String | 751 | public define String |
| 701 | to_HTML_cell_text | 752 | to_HTML_cell_text |
| 702 | ( | 753 | ( |
| 754 | + DB_Model_Column column, | ||
| 755 | + String data_name, | ||
| 756 | + String general_type_name | ||
| 757 | + )= | ||
| 758 | + "text("+to_String(column, data_name, general_type_name)+")". | ||
| 759 | + | ||
| 760 | +public define String | ||
| 761 | + to_HTML_cell_link | ||
| 762 | + ( | ||
| 763 | + DB_Model_Column column, | ||
| 764 | + String data_name, | ||
| 765 | + String general_type_name | ||
| 766 | + )= | ||
| 767 | + "link(to_String("+data_name+".id), "+to_String(column, data_name, general_type_name)+")". | ||
| 768 | + | ||
| 769 | +public define String | ||
| 770 | + to_HTML_cell_link | ||
| 771 | + ( | ||
| 703 | List(DB_Model_Column) columns, | 772 | List(DB_Model_Column) columns, |
| 704 | String column_name, | 773 | String column_name, |
| 705 | String data_name, | 774 | String data_name, |
| @@ -708,11 +777,21 @@ public define String | @@ -708,11 +777,21 @@ public define String | ||
| 708 | if get_column_type(columns, column_name) is | 777 | if get_column_type(columns, column_name) is |
| 709 | { | 778 | { |
| 710 | failure then "column name "+column_name+"doesn't exist", | 779 | failure then "column name "+column_name+"doesn't exist", |
| 711 | - success(column) then "text("+to_String(column, data_name, general_type_name)+")" | 780 | + success(column) then to_HTML_cell_link(column, data_name, general_type_name) |
| 712 | }. | 781 | }. |
| 713 | 782 | ||
| 714 | public define String | 783 | public define String |
| 715 | - to_HTML_cell_link | 784 | + to_HTML_cell_icon |
| 785 | + ( | ||
| 786 | + DB_Model_Column column, | ||
| 787 | + String data_name, | ||
| 788 | + String general_type_name | ||
| 789 | + )= | ||
| 790 | + "icon("+to_Icon(column, data_name, general_type_name)+")". | ||
| 791 | + | ||
| 792 | + | ||
| 793 | +public define String | ||
| 794 | + to_HTML_cell | ||
| 716 | ( | 795 | ( |
| 717 | List(DB_Model_Column) columns, | 796 | List(DB_Model_Column) columns, |
| 718 | String column_name, | 797 | String column_name, |
| @@ -722,28 +801,50 @@ public define String | @@ -722,28 +801,50 @@ public define String | ||
| 722 | if get_column_type(columns, column_name) is | 801 | if get_column_type(columns, column_name) is |
| 723 | { | 802 | { |
| 724 | failure then "column name "+column_name+"doesn't exist", | 803 | failure then "column name "+column_name+"doesn't exist", |
| 725 | - success(column) then "link(to_String("+data_name+".id), "+to_String(column, data_name, general_type_name)+")" | 804 | + success(column) then |
| 805 | + since column is db_column(name, col_type, _, _), | ||
| 806 | + if col_type is | ||
| 807 | + { | ||
| 808 | + //anubis(_T) then "constant_byte_array(0,0)", | ||
| 809 | + p_key then to_HTML_cell_link(column, data_name, general_type_name), | ||
| 810 | + //binary then "constant_byte_array(0,0)", | ||
| 811 | + boolean_field then to_HTML_cell_icon(column, data_name, general_type_name), | ||
| 812 | + date_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), | ||
| 813 | + time_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), | ||
| 814 | + datetime_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), | ||
| 815 | + foreign_key(foreign_table) then to_HTML_cell_text(column, data_name, general_type_name), | ||
| 816 | + integer_field then to_HTML_cell_text(column, data_name, general_type_name), | ||
| 817 | + char_field(Int size) then to_HTML_cell_text(column, data_name, general_type_name), | ||
| 818 | + text_field then to_HTML_cell_text(column, data_name, general_type_name), | ||
| 819 | + } | ||
| 726 | }. | 820 | }. |
| 727 | 821 | ||
| 728 | public define String | 822 | public define String |
| 729 | make_list_view_row | 823 | make_list_view_row |
| 730 | ( | 824 | ( |
| 731 | - DB_Table table, | ||
| 732 | - String data_name, | ||
| 733 | - String indent | 825 | + DB_Table table, //table to format |
| 826 | + String data_name, //name of data | ||
| 827 | + String indent, //indentation string to use | ||
| 828 | + HK_List_View list_view //list view to generate | ||
| 734 | )= | 829 | )= |
| 735 | - since table is db_table(name, model, display), | ||
| 736 | - since model is db_model( columns, _), | ||
| 737 | - since display is db_display(list_view, _), | ||
| 738 | - if list_view is | 830 | + since table is db_table(table_name, model, _), //get name and model of the table |
| 831 | + since model is db_model( columns, _), //get all columns of table | ||
| 832 | +// since display is db_display(views, _), // | ||
| 833 | + with current_list_column = if list_view is | ||
| 834 | + { | ||
| 835 | + list_view_all then to_List_String(columns, false), //generate a list of columns string to view from columns model | ||
| 836 | + list_view(v_name, v_col) then v_col | ||
| 837 | + }, | ||
| 838 | + | ||
| 839 | + if current_list_column is | ||
| 739 | { | 840 | { |
| 740 | [] then "", | 841 | [] then "", |
| 741 | [h . t] then | 842 | [h . t] then |
| 742 | indent+join(",\n"+indent, | 843 | indent+join(",\n"+indent, |
| 743 | //Make first column as link | 844 | //Make first column as link |
| 744 | - [to_HTML_cell_link(columns, h, data_name, name)] + | 845 | + [to_HTML_cell_link(columns, h, data_name, table_name)] + |
| 745 | 846 | ||
| 746 | //and the other set with list_view | 847 | //and the other set with list_view |
| 747 | - map((String column_name) |-> to_HTML_cell_text(columns, column_name, data_name, name), t) | 848 | + map((String column_name) |-> to_HTML_cell(columns, column_name, data_name, table_name), t) |
| 748 | ) | 849 | ) |
| 749 | }. | 850 | }. |
web/widgets/icons_set.anubis
| @@ -6,15 +6,23 @@ | @@ -6,15 +6,23 @@ | ||
| 6 | * © Calexium | 6 | * © Calexium |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | -public define String icn16_cross = "icons/16x16/cross.png". | ||
| 10 | -public define String icn16_edit = "icons/16x16/edit.png". | ||
| 11 | -public define String icn16_check = "icons/16x16/check.png". | ||
| 12 | -public define String icn16_phone = "icons/16x16/phone.png". | ||
| 13 | -public define String icn16_locked = "icons/16x16/locked.png". | 9 | + |
| 10 | +public define String icn16_edit = "icons/16x16/edit.png". | ||
| 11 | +public define String icn16_calendar = "icons/16x16/calendar.png". | ||
| 12 | +public define String icn16_check = "icons/16x16/check.png". | ||
| 14 | public define String icn16_clock = "icons/16x16/clock.png". | 13 | public define String icn16_clock = "icons/16x16/clock.png". |
| 14 | +public define String icn16_cross = "icons/16x16/cross.png". | ||
| 15 | +public define String icn16_key = "icons/16x16/key.png". | ||
| 16 | +public define String icn16_locked = "icons/16x16/locked.png". | ||
| 17 | +public define String icn16_phone = "icons/16x16/phone.png". | ||
| 15 | public define String icn16_vcard_add = "icons/16x16/vcard_add.png". | 18 | public define String icn16_vcard_add = "icons/16x16/vcard_add.png". |
| 16 | public define String icn16_folder_edit = "icons/16x16/folder_edit.png". | 19 | public define String icn16_folder_edit = "icons/16x16/folder_edit.png". |
| 17 | public define String icn16_group = "icons/16x16/group.png". | 20 | public define String icn16_group = "icons/16x16/group.png". |
| 21 | +public define String icn16_question = "icons/16x16/question.png". | ||
| 22 | +public define String icn16_warning = "icons/16x16/warning.png". | ||
| 23 | + | ||
| 24 | +public define String icn16_true = "icons/16x16/check.png". | ||
| 25 | +public define String icn16_false = "icons/16x16/cross.png". | ||
| 18 | 26 | ||
| 19 | /****------------------ MIME PART -----------------****/ | 27 | /****------------------ MIME PART -----------------****/ |
| 20 | 28 | ||
| @@ -24,3 +32,5 @@ public define String icn16_mime_csv = "icons/16x16/mimetypes/csv.png". | @@ -24,3 +32,5 @@ public define String icn16_mime_csv = "icons/16x16/mimetypes/csv.png". | ||
| 24 | public define String icn16_mime_unknown = "icons/16x16/mimetypes/unknown.png". | 32 | public define String icn16_mime_unknown = "icons/16x16/mimetypes/unknown.png". |
| 25 | 33 | ||
| 26 | public define String icn16_mime(String mimetype) = "icons/16x16/mimetypes/"+mimetype+".png". | 34 | public define String icn16_mime(String mimetype) = "icons/16x16/mimetypes/"+mimetype+".png". |
| 35 | + | ||
| 36 | +public define String to_Icon (Bool value)= if value then icn16_true else icn16_false. |