From e52e06114e55d0d93616a6b5e1860e0273ee3364 Mon Sep 17 00:00:00 2001 From: oblomov-dev <102328295+oblomov-dev@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:41:39 +0100 Subject: [PATCH] tree sample (#460) --- src/z2ui5_cl_demo_app_000.clas.abap | 7 + src/z2ui5_cl_demo_app_035.clas.abap | 15 +- src/z2ui5_cl_demo_app_317.clas.abap | 165 +++++++++++++++++++++ src/z2ui5_cl_demo_app_317.clas.xml | 16 +++ src/z2ui5_cl_demo_app_318.clas.abap | 216 ++++++++++++++++++++++++++++ src/z2ui5_cl_demo_app_318.clas.xml | 16 +++ 6 files changed, 429 insertions(+), 6 deletions(-) create mode 100644 src/z2ui5_cl_demo_app_317.clas.abap create mode 100644 src/z2ui5_cl_demo_app_317.clas.xml create mode 100644 src/z2ui5_cl_demo_app_318.clas.abap create mode 100644 src/z2ui5_cl_demo_app_318.clas.xml diff --git a/src/z2ui5_cl_demo_app_000.clas.abap b/src/z2ui5_cl_demo_app_000.clas.abap index bbef522..650c7da 100644 --- a/src/z2ui5_cl_demo_app_000.clas.abap +++ b/src/z2ui5_cl_demo_app_000.clas.abap @@ -1065,6 +1065,13 @@ CLASS z2ui5_cl_demo_app_000 IMPLEMENTATION. class = 'sapUiTinyMarginEnd sapUiTinyMarginBottom' ). + panel->generic_tile( header = 'Tree Table IV' + subheader = 'Drag & Drop' + press = client->_event( 'z2ui5_cl_demo_app_116' ) + mode = 'LineMode' + class = 'sapUiTinyMarginEnd sapUiTinyMarginBottom' + ). + page = page2->panel( expandable = abap_true expanded = client->_bind_edit( ms_check_expanded-popups ) headertext = `Popups & Popovers` ). diff --git a/src/z2ui5_cl_demo_app_035.clas.abap b/src/z2ui5_cl_demo_app_035.clas.abap index d7eece4..46d9357 100644 --- a/src/z2ui5_cl_demo_app_035.clas.abap +++ b/src/z2ui5_cl_demo_app_035.clas.abap @@ -10,12 +10,13 @@ CLASS z2ui5_cl_demo_app_035 DEFINITION PUBLIC. DATA check_initialized TYPE abap_bool. DATA client TYPE REF TO z2ui5_if_client. - + DATA: lt_types TYPE z2ui5_if_types=>ty_t_name_value. METHODS view_display. PROTECTED SECTION. PRIVATE SECTION. + ENDCLASS. @@ -34,13 +35,13 @@ CLASS z2ui5_cl_demo_app_035 IMPLEMENTATION. )->input( client->_bind_edit( mv_path ) )->label( 'Option' ). - DATA(lt_types) = VALUE z2ui5_if_types=>ty_t_name_value( ). - lt_types = VALUE #( FOR row IN z2ui5_cl_util=>source_get_file_types( ) ( + lt_types = VALUE z2ui5_if_types=>ty_t_name_value( ). + LT_TYPES = VALUE #( FOR row IN z2ui5_cl_util=>source_get_file_types( ) ( n = shift_right( shift_left( row ) ) v = shift_right( shift_left( row ) ) ) ). DATA(temp3) = temp->input( value = client->_bind_edit( mv_type ) - suggestionitems = client->_bind_local( lt_types ) + suggestionitems = client->_bind_local( LT_TYPES ) )->get( ). temp3->suggestion_items( @@ -51,8 +52,8 @@ CLASS z2ui5_cl_demo_app_035 IMPLEMENTATION. press = client->_event( 'DB_LOAD' ) icon = 'sap-icon://download-from-cloud' ). - page->code_editor( type = mv_type - editable = mv_check_editable + page->code_editor( type = client->_bind_edit( mv_type ) + editable = client->_bind( mv_check_editable ) value = client->_bind( mv_editor ) ). page->footer( )->overflow_toolbar( @@ -102,6 +103,8 @@ CLASS z2ui5_cl_demo_app_035 IMPLEMENTATION. type = 'success' ). WHEN 'EDIT'. mv_check_editable = xsdbool( mv_check_editable = abap_false ). + client->view_model_update( ). + WHEN 'CLEAR'. mv_editor = ``. WHEN 'BACK'. diff --git a/src/z2ui5_cl_demo_app_317.clas.abap b/src/z2ui5_cl_demo_app_317.clas.abap new file mode 100644 index 0000000..bfd849c --- /dev/null +++ b/src/z2ui5_cl_demo_app_317.clas.abap @@ -0,0 +1,165 @@ +CLASS z2ui5_cl_demo_app_317 DEFINITION + PUBLIC + FINAL + CREATE PUBLIC. + + PUBLIC SECTION. + INTERFACES z2ui5_if_app. + + TYPES: + BEGIN OF ty_node4, + id TYPE string, + text TYPE string, +* nodes TYPE STANDARD TABLE OF ty_node5 WITH DEFAULT KEY, + END OF ty_node4, + BEGIN OF ty_node3, + id TYPE string, + text TYPE string, + nodes TYPE STANDARD TABLE OF ty_node4 WITH DEFAULT KEY, + END OF ty_node3, + BEGIN OF ty_node2, + id TYPE string, + text TYPE string, + nodes TYPE STANDARD TABLE OF ty_node3 WITH DEFAULT KEY, + END OF ty_node2, + BEGIN OF ty_node1, + id TYPE string, + text TYPE string, + nodes TYPE STANDARD TABLE OF ty_node2 WITH DEFAULT KEY, + END OF ty_node1, + ty_tree TYPE STANDARD TABLE OF ty_node1 WITH DEFAULT KEY. + DATA mt_tree TYPE ty_tree. + + TYPES: + BEGIN OF ty_S_node, + id TYPE string, + id_parent TYPE string, + text TYPE string, + END OF ty_S_node. + DATA mt_node TYPE STANDARD TABLE OF ty_S_node WITH EMPTY KEY. + + PROTECTED SECTION. + METHODS build_tree. + METHODS display_view + IMPORTING + client TYPE REF TO z2ui5_if_client. + +ENDCLASS. + +CLASS z2ui5_cl_demo_app_317 IMPLEMENTATION. + + METHOD z2ui5_if_app~main. + + IF client->check_on_init( ). + + mt_node = VALUE #( + ( id = '01' id_parent = '' text = 'Machines' ) + ( id = '03' id_parent = '01' text = 'Pumps' ) + ( id = '04' id_parent = '03' text = 'Pump 001' ) + ( id = '05' id_parent = '03' text = 'Pump 002' ) + ( id = '02' id_parent = '' text = 'Paints' ) + ( id = '06' id_parent = '02' text = 'Gloss paints' ) + ( id = '07' id_parent = '06' text = 'Paint 001' ) + ( id = '08' id_parent = '06' text = 'Paint 002' ) ). + + build_tree( ). + display_view( client ). + + ENDIF. + + CASE client->get( )-event. + + WHEN 'expand'. + client->follow_up_action( `debugger; z2ui5.oView.byId( 'tree' ).expandToLevel(10);`). + + WHEN 'onDrop'. + mt_node[ id = client->get_event_arg( 1 ) ]-id_parent = client->get_event_arg( 2 ). + build_tree( ). + display_view( client ). + ENDCASE. + + + ENDMETHOD. + + METHOD build_tree. + + CLEAR mt_tree. + LOOP AT mt_node INTO DATA(ls_node) WHERE id_parent IS INITIAL. + + DATA(ls_root) = CORRESPONDING ty_node1( ls_node ). + INSERT ls_root INTO TABLE mt_tree. + + ENDLOOP. + + + LOOP AT mt_tree REFERENCE INTO DATA(lr_node). + + LOOP AT mt_node INTO ls_node WHERE id_parent = lr_node->id. + DATA(ls_root2) = CORRESPONDING ty_node2( ls_node ). + INSERT ls_root2 INTO TABLE lr_node->nodes. + ENDLOOP. + + ENDLOOP. + + + LOOP AT mt_tree REFERENCE INTO lr_node. + LOOP AT lr_node->nodes REFERENCE INTO DATA(lr_node2). + + LOOP AT mt_node INTO ls_node WHERE id_parent = lr_node2->id. + DATA(ls_root3) = CORRESPONDING ty_node3( ls_node ). + INSERT ls_root3 INTO TABLE lr_node2->nodes. + ENDLOOP. + + ENDLOOP. + ENDLOOP. + + + LOOP AT mt_tree REFERENCE INTO lr_node. + LOOP AT lr_node->nodes REFERENCE INTO lr_node2. + LOOP AT lr_node2->nodes REFERENCE INTO DATA(lr_node3). + + LOOP AT mt_node INTO ls_node WHERE id_parent = lr_node3->id. + DATA(ls_root4) = CORRESPONDING ty_node4( ls_node ). + INSERT ls_root4 INTO TABLE lr_node3->nodes. + ENDLOOP. + + ENDLOOP. + ENDLOOP. + ENDLOOP. + + ENDMETHOD. + + + METHOD display_view. + + DATA(page) = z2ui5_cl_xml_view=>factory( )->page( ). + + page->_generic( name = `script` ns = `html` + )->_cc_plain_xml( + |function myFunction() \{ z2ui5.oView.byId('tree').expandToLevel(5); \}| + ). + + DATA(tree) = page->tree( items = client->_bind( mt_tree ) id = `tree` ). + tree->items( + )->standard_tree_item( title = '{TEXT}' + )->get( + )->custom_data( + )->core_custom_data( key = 'ID' value = '{ID}'). + + tree->drag_drop_config( ns = `` )->Drag_Drop_Info( + sourceAggregation = `items` + targetAggregation = `items` + dragStart = `Horizontal` + drop = client->_event( + val = 'onDrop' + t_arg = VALUE #( + ( `${$parameters>/draggedControl/mAggregations/customData/0/mProperties/value}` ) + ( `${$parameters>/droppedControl/mAggregations/customData/0/mProperties/value}` ) + ) ) ). + + client->follow_up_action( `myFunction()` ). + client->view_display( page->stringify( ) ). + + ENDMETHOD. + +ENDCLASS. diff --git a/src/z2ui5_cl_demo_app_317.clas.xml b/src/z2ui5_cl_demo_app_317.clas.xml new file mode 100644 index 0000000..dd3b2f9 --- /dev/null +++ b/src/z2ui5_cl_demo_app_317.clas.xml @@ -0,0 +1,16 @@ + + + + + + Z2UI5_CL_DEMO_APP_317 + E + tab -different odata models + 1 + X + X + X + + + + diff --git a/src/z2ui5_cl_demo_app_318.clas.abap b/src/z2ui5_cl_demo_app_318.clas.abap new file mode 100644 index 0000000..273694a --- /dev/null +++ b/src/z2ui5_cl_demo_app_318.clas.abap @@ -0,0 +1,216 @@ +CLASS z2ui5_cl_demo_app_318 DEFINITION PUBLIC. + + PUBLIC SECTION. + INTERFACES z2ui5_if_app. + + DATA mv_type TYPE string. + DATA mv_path TYPE string. + DATA mv_editor TYPE string. + DATA mv_check_editable TYPE abap_bool. + DATA check_initialized TYPE abap_bool. + + DATA client TYPE REF TO z2ui5_if_client. + DATA: lt_types TYPE z2ui5_if_types=>ty_t_name_value. + METHODS view_display. + + PROTECTED SECTION. + + PRIVATE SECTION. + +ENDCLASS. + + +CLASS z2ui5_cl_demo_app_318 IMPLEMENTATION. + METHOD view_display. + + mv_editor = ` ` && |\n| && + ` ` && |\n| && + `

Hi there 👋

` && |\n| && + `

This example was rendered by providing HTML code to the API. You can also tell the API to convert from a URL. Just remove the html parameter and add the url paramter.

` && |\n| && + ` ` && |\n| && + ``. + + DATA(view) = z2ui5_cl_xml_view=>factory( ). + + DATA(page) = view->shell( )->page( title = 'abap2UI5 - File Editor' + navbuttonpress = client->_event( 'BACK' ) + shownavbutton = xsdbool( client->get( )-s_draft-id_prev_app_stack IS NOT INITIAL ) ). + + DATA(temp) = page->simple_form( title = 'File' + editable = abap_true )->content( `form` + )->label( 'path' + )->input( client->_bind_edit( mv_path ) + )->label( 'Option' ). + + lt_types = VALUE z2ui5_if_types=>ty_t_name_value( ). + LT_TYPES = VALUE #( FOR row IN z2ui5_cl_util=>source_get_file_types( ) ( + n = shift_right( shift_left( row ) ) + v = shift_right( shift_left( row ) ) ) ). + + DATA(temp3) = temp->input( value = client->_bind_edit( mv_type ) + suggestionitems = client->_bind_local( LT_TYPES ) + )->get( ). + + temp3->suggestion_items( + )->list_item( text = '{N}' + additionaltext = '{V}' ). + + temp->label( '' )->button( text = 'Download' + press = client->_event( 'DB_LOAD' ) + icon = 'sap-icon://download-from-cloud' ). + + page->code_editor( type = `html` + editable = abap_true + value = client->_bind( mv_editor ) ). + + page->footer( )->overflow_toolbar( + )->toolbar_spacer( + )->button( text = 'PDF' + press = client->_event( 'PDF' ) + type = 'Emphasized' + enabled = xsdbool( mv_editor IS NOT INITIAL ) ). + + client->view_display( page->stringify( ) ). + ENDMETHOD. + + METHOD z2ui5_if_app~main. + me->client = client. + + IF check_initialized = abap_false. + check_initialized = abap_true. + mv_path = '../../demo/text'. + mv_type = 'plain_text'. + view_display( ). + ENDIF. + + CASE client->get( )-event. + + WHEN 'PDF'. + +* TRY. +** URL +* DATA(lv_url) = |https://api.pdfcrowd.com/convert/24.04/|. +* DATA: o_client TYPE REF TO if_http_client. +* +** Client-Objekt erzeugen +* cl_http_client=>create_by_url( EXPORTING +* url = lv_url +* IMPORTING +* client = o_client ). +* +* IF o_client IS BOUND. +** Anmeldedaten übermitteln +* o_client->authenticate( username = 'demo' +* password = 'ce544b6ea52a5621fb9d55f8b542d14d' ). +* +** Logon-Popup ein- bzw. ausschalten +** o_client->propertytype_logon_popup = o_client->co_enabled. +* +** HTTP-Prtotokoll-Version +** o_client->request->set_version( version = if_http_request=>co_protocol_version_1_1 ). +** HTTP-Method +* o_client->request->set_method( if_http_request=>co_request_method_post ). +* o_client->request->set_header_field( name = 'Content-Type' value = 'application/json' ). +* +* o_client->request->set_form_field( +* name = 'content_viewport_width' +* value = 'balanced' +* ). +* +* o_client->request->set_form_field( +* name = 'text' +* value = mv_editor +* ). +* Header-Felder explizit setzen +* o_client->request->set_header_field( name = '~request_method' +* value = 'GET' ). +* +* o_client->request->set_header_field( name = 'Content-Type' +* value = 'text/xml; charset=utf-8' ). +* +* o_client->request->set_header_field( name = 'Accept' +* value = 'text/xml, text/html' ). + +* Cookies akzeptieren +* o_client->propertytype_accept_cookie = if_http_client=>co_enabled. +* Kompression akzeptieren +* o_client->propertytype_accept_compress = if_http_client=>co_enabled. + +* HTTP GET senden, evtl. Timeout angeben +* o_client->send( timeout = if_http_client=>co_timeout_default ). +* +** Response lesen +* o_client->receive( ). +* +* DATA: lv_http_status TYPE i. +* DATA: lv_status_text TYPE string. +* +** HTTP Return Code holen +* o_client->response->get_status( IMPORTING +* code = lv_http_status +* reason = lv_status_text ). +* +** WRITE: / 'HTTP_STATUS_CODE:', lv_http_status. +** WRITE: / 'STATUS_TEXT:', lv_status_text. +** +*** Header-Daten der Übertragung +** WRITE: / 'HEADER_FIELDS:'. +** DATA(it_header_fields) = VALUE tihttpnvp( ). +** o_client->response->get_header_fields( CHANGING fields = it_header_fields ). +** +** LOOP AT it_header_fields ASSIGNING FIELD-SYMBOL(). +** WRITE: / '[', -name, ']', -value. +** ENDLOOP. +* +** Cookies holen +** WRITE: / 'COOKIES:'. +** DATA(it_cookies) = VALUE tihttpcki( ). +** o_client->response->get_cookies( CHANGING cookies = it_cookies ). +** +** LOOP AT it_cookies ASSIGNING FIELD-SYMBOL(). +** WRITE: / '[', -name, ']', -value, -xdomain, -path, -secure, -expires. +** ENDLOOP. +* +** vollständige HTTP Nachricht lesen +* DATA(lv_raw_message) = o_client->response->get_raw_message( ). +* DATA: lv_str_msg TYPE string. +* +** xstring -> string +* DATA(o_conv_r) = cl_abap_conv_in_ce=>create( input = lv_raw_message +* encoding = 'UTF-8' ). +* +* o_conv_r->read( IMPORTING data = lv_str_msg ). +* +* WRITE: / 'RAW MESSAGE:', lv_str_msg. +* +** Wenn Status 200 (Ok) +* IF lv_http_status = 200. +** HTTP Body als Character-Daten +* DATA(lv_result) = o_client->response->get_cdata( ). +* +* WRITE: / 'CDATA:'. +* WRITE: / lv_result. +* ENDIF. +* +** HTTP Connection schließen +* o_client->close( ). +* ENDIF. +* CATCH cx_root INTO DATA(e_txt). +* WRITE: / e_txt->get_text( ). +*ENDTRY. + + + WHEN 'DB_SAVE'. + client->message_box_display( text = 'Upload successfull. File saved!' + type = 'success' ). + WHEN 'EDIT'. + mv_check_editable = xsdbool( mv_check_editable = abap_false ). + client->view_model_update( ). + + WHEN 'CLEAR'. + mv_editor = ``. + WHEN 'BACK'. + client->nav_app_leave( ). + ENDCASE. + ENDMETHOD. +ENDCLASS. diff --git a/src/z2ui5_cl_demo_app_318.clas.xml b/src/z2ui5_cl_demo_app_318.clas.xml new file mode 100644 index 0000000..4486568 --- /dev/null +++ b/src/z2ui5_cl_demo_app_318.clas.xml @@ -0,0 +1,16 @@ + + + + + + Z2UI5_CL_DEMO_APP_318 + E + more - html pdf + 1 + X + X + X + + + +