|
| 1 | +"! Generated port of a UI5 demo kit sample - not yet manually reviewed |
| 2 | +"! Rebuild of the UI5 demo kit sample: https://sapui5.hana.ondemand.com/sdk/#/entity/sap.m.FacetFilter/sample/sap.m.sample.FacetFilterLight |
| 3 | +"! This is a 'Light' version of the Facet Filter. It is for small displays where only a selectable |
| 4 | +"! summary bar is shown, and a dialog is shown for setting the facet values. |
| 5 | +CLASS z2ui5_cl_demo_app_401 DEFINITION PUBLIC. |
| 6 | + |
| 7 | + PUBLIC SECTION. |
| 8 | + INTERFACES z2ui5_if_app. |
| 9 | + |
| 10 | + TYPES: |
| 11 | + BEGIN OF ty_s_product, |
| 12 | + name TYPE string, |
| 13 | + category TYPE string, |
| 14 | + supplier_name TYPE string, |
| 15 | + dimensions TYPE string, |
| 16 | + weight_measure TYPE string, |
| 17 | + weight_unit TYPE string, |
| 18 | + weight_state TYPE string, |
| 19 | + price TYPE string, |
| 20 | + currency_code TYPE string, |
| 21 | + END OF ty_s_product. |
| 22 | + TYPES ty_t_product TYPE STANDARD TABLE OF ty_s_product WITH EMPTY KEY. |
| 23 | + TYPES: |
| 24 | + BEGIN OF ty_s_facet, |
| 25 | + text TYPE string, |
| 26 | + count TYPE i, |
| 27 | + END OF ty_s_facet. |
| 28 | + TYPES ty_t_facet TYPE STANDARD TABLE OF ty_s_facet WITH EMPTY KEY. |
| 29 | + DATA t_products TYPE ty_t_product. |
| 30 | + DATA t_products_all TYPE ty_t_product. |
| 31 | + DATA t_categories TYPE ty_t_facet. |
| 32 | + DATA t_suppliers TYPE ty_t_facet. |
| 33 | + |
| 34 | + PROTECTED SECTION. |
| 35 | + DATA client TYPE REF TO z2ui5_if_client. |
| 36 | + DATA t_range_category TYPE RANGE OF string. |
| 37 | + DATA t_range_supplier TYPE RANGE OF string. |
| 38 | + |
| 39 | + METHODS set_data. |
| 40 | + METHODS view_display. |
| 41 | + METHODS on_event_list_close |
| 42 | + IMPORTING |
| 43 | + facet TYPE string. |
| 44 | + |
| 45 | + PRIVATE SECTION. |
| 46 | +ENDCLASS. |
| 47 | + |
| 48 | + |
| 49 | +CLASS z2ui5_cl_demo_app_401 IMPLEMENTATION. |
| 50 | + |
| 51 | + METHOD z2ui5_if_app~main. |
| 52 | + |
| 53 | + me->client = client. |
| 54 | + IF client->check_on_init( ). |
| 55 | + |
| 56 | + set_data( ). |
| 57 | + view_display( ). |
| 58 | + |
| 59 | + ELSEIF client->check_on_event( `RESET` ). |
| 60 | + |
| 61 | + t_range_category = VALUE #( ). |
| 62 | + t_range_supplier = VALUE #( ). |
| 63 | + t_products = t_products_all. |
| 64 | + client->view_model_update( ). |
| 65 | + |
| 66 | + ELSEIF client->check_on_event( `LIST_CLOSE_CATEGORY` ). |
| 67 | + on_event_list_close( `CATEGORY` ). |
| 68 | + ELSEIF client->check_on_event( `LIST_CLOSE_SUPPLIER` ). |
| 69 | + on_event_list_close( `SUPPLIER` ). |
| 70 | + ENDIF. |
| 71 | + |
| 72 | + ENDMETHOD. |
| 73 | + |
| 74 | + |
| 75 | + METHOD set_data. |
| 76 | + |
| 77 | + " Data taken from the shared mock data sap/ui/demo/mock/products.json of the original sample |
| 78 | + t_products = VALUE #( |
| 79 | + ( name = `Comfort Easy` category = `Accessories` supplier_name = `Technocom` dimensions = `84 x 1.5 x 14 cm` weight_measure = `0.2` weight_unit = `KG` weight_state = `Success` price = `1679.00` currency_code = `EUR` ) |
| 80 | + ( name = `Comfort Senior` category = `Accessories` supplier_name = `Technocom` dimensions = `80 x 1.6 x 13 cm` weight_measure = `0.8` weight_unit = `KG` weight_state = `Success` price = `512.00` currency_code = `EUR` ) |
| 81 | + ( name = `Ergo Screen E-I` category = `Flat Screen Monitors` supplier_name = `Very Best Screens` dimensions = `37 x 12 x 36 cm` weight_measure = `21` weight_unit = `KG` weight_state = `Error` price = `230.00` currency_code = `EUR` ) |
| 82 | + ( name = `ITelO Vault` category = `Accessories` supplier_name = `Technocom` dimensions = `32 x 22 x 3 cm` weight_measure = `0.2` weight_unit = `KG` weight_state = `Success` price = `299.00` currency_code = `EUR` ) |
| 83 | + ( name = `ITelO Vault Net` category = `Accessories` supplier_name = `Technocom` dimensions = `10 x 1.8 x 17 cm` weight_measure = `0.16` weight_unit = `KG` weight_state = `Success` price = `459.00` currency_code = `EUR` ) |
| 84 | + ( name = `ITelO Vault SAT` category = `Accessories` supplier_name = `Technocom` dimensions = `11 x 1.7 x 18 cm` weight_measure = `0.18` weight_unit = `KG` weight_state = `Success` price = `149.00` currency_code = `EUR` ) |
| 85 | + ( name = `Notebook Basic 15` category = `Laptops` supplier_name = `Very Best Screens` dimensions = `30 x 18 x 3 cm` weight_measure = `4.2` weight_unit = `KG` weight_state = `Warning` price = `956.00` currency_code = `EUR` ) |
| 86 | + ( name = `Notebook Basic 17` category = `Laptops` supplier_name = `Very Best Screens` dimensions = `29 x 17 x 3.1 cm` weight_measure = `4.5` weight_unit = `KG` weight_state = `Warning` price = `1249.00` currency_code = `EUR` ) |
| 87 | + ( name = `Notebook Basic 19` category = `Laptops` supplier_name = `Smartcards` dimensions = `32 x 21 x 4 cm` weight_measure = `4.2` weight_unit = `KG` weight_state = `Warning` price = `1650.00` currency_code = `EUR` ) |
| 88 | + ( name = `Notebook Professional 15` category = `Accessories` supplier_name = `Very Best Screens` dimensions = `33 x 20 x 3 cm` weight_measure = `4.3` weight_unit = `KG` weight_state = `Warning` price = `1999.00` currency_code = `EUR` ) ). |
| 89 | + |
| 90 | + SORT t_products BY name. |
| 91 | + t_products_all = t_products. |
| 92 | + |
| 93 | + " Facet values with counters as delivered precomputed in /ProductCollectionStats/Filters |
| 94 | + t_categories = VALUE #( |
| 95 | + ( text = `Accessories` count = 6 ) |
| 96 | + ( text = `Flat Screen Monitors` count = 1 ) |
| 97 | + ( text = `Laptops` count = 3 ) ). |
| 98 | + t_suppliers = VALUE #( |
| 99 | + ( text = `Smartcards` count = 1 ) |
| 100 | + ( text = `Technocom` count = 5 ) |
| 101 | + ( text = `Very Best Screens` count = 4 ) ). |
| 102 | + |
| 103 | + ENDMETHOD. |
| 104 | + |
| 105 | + |
| 106 | + METHOD view_display. |
| 107 | + |
| 108 | + DATA(view) = z2ui5_cl_xml_view=>factory( ). |
| 109 | + DATA(page) = view->shell( |
| 110 | + )->page( |
| 111 | + title = `abap2UI5 - Sample: Facet Filter - Light` |
| 112 | + navbuttonpress = client->_event_nav_app_leave( ) |
| 113 | + shownavbutton = client->check_app_prev_stack( ) ). |
| 114 | + |
| 115 | + page->header_content( |
| 116 | + )->link( |
| 117 | + text = `UI5 Demo Kit` |
| 118 | + target = `_blank` |
| 119 | + href = `https://sapui5.hana.ondemand.com/sdk/#/entity/sap.m.FacetFilter/sample/sap.m.sample.FacetFilterLight` ). |
| 120 | + |
| 121 | + DATA(vbox) = page->vbox( id = `idVBox` ). |
| 122 | + |
| 123 | + " The bound lists collection of the original is unrolled into two static facet filter lists |
| 124 | + vbox->facet_filter( id = `idFacetFilter` |
| 125 | + type = `Light` |
| 126 | + showpersonalization = abap_true |
| 127 | + showreset = abap_true |
| 128 | + reset = client->_event( `RESET` ) |
| 129 | + )->facet_filter_list( title = `Category` |
| 130 | + key = `Category` |
| 131 | + mode = `MultiSelect` |
| 132 | + listclose = client->_event( val = `LIST_CLOSE_CATEGORY` |
| 133 | + t_arg = VALUE #( ( `$event.mParameters.selectedItems` ) ) ) |
| 134 | + items = client->_bind( t_categories ) |
| 135 | + )->facet_filter_item( text = `{TEXT}` |
| 136 | + key = `{TEXT}` |
| 137 | + counter = `{COUNT}` )->get_parent( )->get_parent( |
| 138 | + )->facet_filter_list( title = `SupplierName` |
| 139 | + key = `SupplierName` |
| 140 | + mode = `MultiSelect` |
| 141 | + listclose = client->_event( val = `LIST_CLOSE_SUPPLIER` |
| 142 | + t_arg = VALUE #( ( `$event.mParameters.selectedItems` ) ) ) |
| 143 | + items = client->_bind( t_suppliers ) |
| 144 | + )->facet_filter_item( text = `{TEXT}` |
| 145 | + key = `{TEXT}` |
| 146 | + counter = `{COUNT}` ). |
| 147 | + |
| 148 | + " The original controller appends the demo table of sap.m.sample.Table with an adjusted first column |
| 149 | + DATA(tab) = vbox->table( id = `idProductsTable` |
| 150 | + inset = abap_false |
| 151 | + items = client->_bind( t_products ) ). |
| 152 | + |
| 153 | + tab->header_toolbar( |
| 154 | + )->overflow_toolbar( |
| 155 | + )->title( text = `Products` |
| 156 | + level = `H2` |
| 157 | + )->toolbar_spacer( ). |
| 158 | + |
| 159 | + DATA(columns) = tab->columns( ). |
| 160 | + columns->column( `12em` )->text( `Product` ). |
| 161 | + columns->column( minscreenwidth = `Tablet` |
| 162 | + demandpopin = abap_true )->text( `Supplier` ). |
| 163 | + columns->column( minscreenwidth = `Desktop` |
| 164 | + demandpopin = abap_true |
| 165 | + halign = `End` )->text( `Dimensions` ). |
| 166 | + columns->column( minscreenwidth = `Desktop` |
| 167 | + demandpopin = abap_true |
| 168 | + halign = `Center` )->text( `Weight` ). |
| 169 | + columns->column( halign = `End` )->text( `Price` ). |
| 170 | + |
| 171 | + DATA(cells) = tab->items( )->column_list_item( valign = `Middle` )->cells( ). |
| 172 | + cells->object_identifier( title = `{NAME}` |
| 173 | + text = `{CATEGORY}` )->get_parent( ). |
| 174 | + cells->text( `{SUPPLIER_NAME}` ). |
| 175 | + cells->text( `{DIMENSIONS}` ). |
| 176 | + cells->object_number( number = `{WEIGHT_MEASURE}` |
| 177 | + unit = `{WEIGHT_UNIT}` |
| 178 | + state = `{WEIGHT_STATE}` ). |
| 179 | + cells->object_number( number = `{PRICE}` |
| 180 | + unit = `{CURRENCY_CODE}` ). |
| 181 | + |
| 182 | + client->view_display( view->stringify( ) ). |
| 183 | + |
| 184 | + ENDMETHOD. |
| 185 | + |
| 186 | + |
| 187 | + METHOD on_event_list_close. |
| 188 | + |
| 189 | + DATA t_range TYPE RANGE OF string. |
| 190 | + |
| 191 | + TRY. |
| 192 | + DATA(t_arg) = client->get( )-t_event_arg. |
| 193 | + DATA(json) = z2ui5_cl_ajson=>parse( t_arg[ 1 ] ). |
| 194 | + |
| 195 | + LOOP AT json->members( `/` ) INTO DATA(member). |
| 196 | + APPEND VALUE #( sign = `I` |
| 197 | + option = `EQ` |
| 198 | + low = json->get( |/{ member }/mProperties/text| ) ) TO t_range. |
| 199 | + ENDLOOP. |
| 200 | + |
| 201 | + CATCH cx_root. |
| 202 | + ENDTRY. |
| 203 | + |
| 204 | + IF facet = `CATEGORY`. |
| 205 | + t_range_category = t_range. |
| 206 | + ELSE. |
| 207 | + t_range_supplier = t_range. |
| 208 | + ENDIF. |
| 209 | + |
| 210 | + t_products = t_products_all. |
| 211 | + DELETE t_products WHERE category NOT IN t_range_category OR supplier_name NOT IN t_range_supplier. |
| 212 | + |
| 213 | + client->view_model_update( ). |
| 214 | + |
| 215 | + ENDMETHOD. |
| 216 | + |
| 217 | +ENDCLASS. |
0 commit comments