From d9e18997eb74b0dedb4d571d0f5704c3747baf7a Mon Sep 17 00:00:00 2001 From: oblomov <102328295+oblomov-dev@users.noreply.github.com> Date: Wed, 17 Jan 2024 10:31:12 +0100 Subject: [PATCH] Popups & binding bugfixes (#786) * popups * bugfix binding --- src/00/z2ui5_cl_util_func.clas.abap | 133 ++++++++++-------- src/01/01/z2ui5_cl_fw_binding.clas.abap | 28 +++- src/01/01/z2ui5_cl_fw_client.clas.abap | 2 +- src/01/01/z2ui5_cl_fw_model.clas.abap | 2 + .../01/z2ui5_cl_popup_input_value.clas.abap | 26 ++-- 5 files changed, 116 insertions(+), 75 deletions(-) diff --git a/src/00/z2ui5_cl_util_func.clas.abap b/src/00/z2ui5_cl_util_func.clas.abap index 14b74143..cc6a2912 100644 --- a/src/00/z2ui5_cl_util_func.clas.abap +++ b/src/00/z2ui5_cl_util_func.clas.abap @@ -119,12 +119,14 @@ CLASS z2ui5_cl_util_func DEFINITION CLASS-METHODS trans_ref_tab_2_tab IMPORTING !ir_tab_from TYPE REF TO data + pretty_name TYPE abap_bool DEFAULT abap_false EXPORTING !t_result TYPE STANDARD TABLE. CLASS-METHODS trans_ref_struc_2_struc IMPORTING !ir_struc_from TYPE REF TO data + pretty_name TYPE abap_bool DEFAULT abap_false EXPORTING !r_result TYPE data. @@ -541,7 +543,68 @@ CLASS z2ui5_cl_util_func IMPLEMENTATION. METHOD trans_json_any_2. - result = /ui2/cl_json=>serialize( data = any pretty_name = CONV #( pretty_name ) compress = compress ). + result = /ui2/cl_json=>serialize( + data = any + pretty_name = CONV #( pretty_name ) + compress = compress ). + + ENDMETHOD. + + + METHOD trans_ref_struc_2_struc. + + FIELD-SYMBOLS TYPE any. + + ASSIGN ir_struc_from->* TO . + x_check_raise( xsdbool( sy-subrc <> 0 ) ). + CLEAR r_result. + + DATA(lo_struc) = CAST cl_abap_structdescr( cl_abap_datadescr=>describe_by_data( r_result ) ). + DATA(lt_components) = lo_struc->get_components( ). + LOOP AT lt_components INTO DATA(ls_comp). + + DATA(lv_from) = ls_comp-name. + IF pretty_name = abap_true. + REPLACE ALL OCCURRENCES OF `_` IN lv_from WITH ``. + ENDIF. + ASSIGN COMPONENT lv_from OF STRUCTURE TO FIELD-SYMBOL(). + IF sy-subrc <> 0. + CONTINUE. + ENDIF. + ASSIGN COMPONENT ls_comp-name OF STRUCTURE r_result TO FIELD-SYMBOL(). + IF sy-subrc <> 0. + CONTINUE. + ENDIF. + FIELD-SYMBOLS TYPE any. + ASSIGN ->* TO . + DATA(lv_type_kind) = rtti_get_type_kind( ). + + IF IS INITIAL. + CONTINUE. + ENDIF. + + CASE lv_type_kind. + + WHEN cl_abap_typedescr=>typekind_table. + trans_ref_tab_2_tab( + EXPORTING + ir_tab_from = + pretty_name = pretty_name + IMPORTING + t_result = ). + + WHEN cl_abap_typedescr=>typekind_struct1 OR cl_abap_typedescr=>typekind_struct2. + trans_ref_struc_2_struc( + EXPORTING + ir_struc_from = + IMPORTING + r_result = ). + + WHEN OTHERS. + = . + ENDCASE. + + ENDLOOP. ENDMETHOD. @@ -604,6 +667,9 @@ CLASS z2ui5_cl_util_func IMPLEMENTATION. ENDIF. FIELD-SYMBOLS TYPE data. + IF pretty_name = abap_true. + REPLACE ALL OCCURRENCES OF `_` IN ls_comp-name WITH ``. + ENDIF. ASSIGN COMPONENT ls_comp-name OF STRUCTURE TO . IF sy-subrc <> 0. @@ -615,8 +681,12 @@ CLASS z2ui5_cl_util_func IMPLEMENTATION. IF sy-subrc = 0. CASE ls_comp-type->kind. WHEN cl_abap_typedescr=>kind_table. - trans_ref_tab_2_tab( EXPORTING ir_tab_from = - IMPORTING t_result = ). + trans_ref_tab_2_tab( + EXPORTING + ir_tab_from = + pretty_name = pretty_name + IMPORTING + t_result = ). WHEN OTHERS. = . ENDCASE. @@ -629,66 +699,9 @@ CLASS z2ui5_cl_util_func IMPLEMENTATION. INSERT INTO TABLE t_result. ENDLOOP. - ENDMETHOD. - METHOD trans_ref_struc_2_struc. - - FIELD-SYMBOLS TYPE any. - - ASSIGN ir_struc_from->* TO . - x_check_raise( xsdbool( sy-subrc <> 0 ) ). - CLEAR r_result. - - DATA(lo_struc) = CAST cl_abap_structdescr( cl_abap_datadescr=>describe_by_data( r_result ) ). - DATA(lt_components) = lo_struc->get_components( ). - LOOP AT lt_components INTO DATA(ls_comp). - - DATA(lv_from) = ls_comp-name. -* REPLACE ALL OCCURRENCES OF `_` IN lv_from WITH ``. - ASSIGN COMPONENT lv_from OF STRUCTURE TO FIELD-SYMBOL(). - IF sy-subrc <> 0. - CONTINUE. - ENDIF. - ASSIGN COMPONENT ls_comp-name OF STRUCTURE r_result TO FIELD-SYMBOL(). - IF sy-subrc <> 0. - CONTINUE. - ENDIF. - FIELD-SYMBOLS TYPE any. - ASSIGN ->* TO . - DATA(lv_type_kind) = rtti_get_type_kind( ). - - IF IS INITIAL. - CONTINUE. - ENDIF. - - CASE lv_type_kind. - - WHEN cl_abap_typedescr=>typekind_table. - trans_ref_tab_2_tab( - EXPORTING - ir_tab_from = - IMPORTING - t_result = ). - - WHEN cl_abap_typedescr=>typekind_struct1 OR cl_abap_typedescr=>typekind_struct2. - trans_ref_struc_2_struc( - EXPORTING - ir_struc_from = - IMPORTING - r_result = ). - - WHEN OTHERS. - = . - ENDCASE. - - ENDLOOP. - - ENDMETHOD. - - - METHOD trans_xml_2_any. CALL TRANSFORMATION id diff --git a/src/01/01/z2ui5_cl_fw_binding.clas.abap b/src/01/01/z2ui5_cl_fw_binding.clas.abap index e972a679..eefe648d 100644 --- a/src/01/01/z2ui5_cl_fw_binding.clas.abap +++ b/src/01/01/z2ui5_cl_fw_binding.clas.abap @@ -27,7 +27,7 @@ CLASS z2ui5_cl_fw_binding DEFINITION check_dissolved TYPE abap_bool, check_temp TYPE abap_bool, viewname TYPE string, - pretty_name TYPE string, + pretty_name TYPE abap_bool, compress TYPE abap_bool, depth TYPE i, END OF ty_s_attri. @@ -153,12 +153,23 @@ CLASS z2ui5_cl_fw_binding IMPLEMENTATION. RETURN. ENDIF. - IF bind->bind_type <> mv_type AND bind->bind_type IS NOT INITIAL. + IF bind->bind_type IS NOT INITIAL and bind->bind_type <> mv_type. RAISE EXCEPTION TYPE z2ui5_cx_util_error EXPORTING val = `

Binding Error - Two different binding types for same attribute used (` && bind->name && `).`. ENDIF. + IF bind->bind_type IS NOT INITIAL and bind->pretty_name <> mv_pretty_name. + RAISE EXCEPTION TYPE z2ui5_cx_util_error + EXPORTING + val = `

Binding Error - Two different pretty types for same attribute used (` && bind->name && `).`. + ENDIF. + + IF bind->bind_type IS NOT INITIAL. + result = COND #( WHEN mv_type = cs_bind_type-two_way THEN `/` && cv_model_edit_name && `/` ELSE `/` ) && bind->name_front. + RETURN. + ENDIF. + bind->bind_type = mv_type. bind->pretty_name = mv_pretty_name. bind->compress = mv_compress. @@ -444,6 +455,19 @@ CLASS z2ui5_cl_fw_binding IMPLEMENTATION. result = replace( val = result sub = `>` with = `_` occ = 0 ). result = replace( val = result sub = `-` with = `_` occ = 0 ). + IF mv_pretty_name = abap_true. + SPLIT result AT `_` INTO TABLE DATA(lt_tab). + result = to_lower( lt_tab[ 1 ] ). + LOOP AT lt_tab INTO DATA(lv_val) FROM 2. + TRY. + lv_val = to_lower( lv_val ). + lv_val = to_upper( lv_val(1) ) && lv_val+1. + result = result && lv_val. + CATCH cx_root. + ENDTRY. + ENDLOOP. + ENDIF. + ENDMETHOD. diff --git a/src/01/01/z2ui5_cl_fw_client.clas.abap b/src/01/01/z2ui5_cl_fw_client.clas.abap index 89898424..be188706 100644 --- a/src/01/01/z2ui5_cl_fw_client.clas.abap +++ b/src/01/01/z2ui5_cl_fw_client.clas.abap @@ -304,7 +304,7 @@ CLASS Z2UI5_CL_FW_CLIENT IMPLEMENTATION. IF tab IS NOT INITIAL. - DATA(lv_name) = z2ui5_if_client~_bind_edit( val = tab path = abap_true ). + DATA(lv_name) = z2ui5_if_client~_bind_edit( val = tab path = abap_true pretty_name = pretty_name ). result = bind_tab_cell( iv_name = lv_name i_tab_index = tab_index diff --git a/src/01/01/z2ui5_cl_fw_model.clas.abap b/src/01/01/z2ui5_cl_fw_model.clas.abap index 5f6e9527..ac504963 100644 --- a/src/01/01/z2ui5_cl_fw_model.clas.abap +++ b/src/01/01/z2ui5_cl_fw_model.clas.abap @@ -77,6 +77,7 @@ CLASS z2ui5_cl_fw_model IMPLEMENTATION. z2ui5_cl_util_func=>trans_ref_tab_2_tab( EXPORTING ir_tab_from = + pretty_name = lr_attri->pretty_name IMPORTING t_result = ). @@ -84,6 +85,7 @@ CLASS z2ui5_cl_fw_model IMPLEMENTATION. z2ui5_cl_util_func=>trans_ref_struc_2_struc( EXPORTING ir_struc_from = + pretty_name = lr_attri->pretty_name IMPORTING r_result = ). diff --git a/src/03/01/z2ui5_cl_popup_input_value.clas.abap b/src/03/01/z2ui5_cl_popup_input_value.clas.abap index c29d1446..5a512755 100644 --- a/src/03/01/z2ui5_cl_popup_input_value.clas.abap +++ b/src/03/01/z2ui5_cl_popup_input_value.clas.abap @@ -9,21 +9,22 @@ CLASS z2ui5_cl_popup_input_value DEFINITION CLASS-METHODS factory IMPORTING - i_text TYPE string - i_title TYPE string DEFAULT `Title` - i_button_text_confirm TYPE string DEFAULT `OK` - i_button_text_cancel TYPE string DEFAULT `Cancel` + text TYPE string DEFAULT `Enter New Value` + val TYPE string OPTIONAL + title TYPE string DEFAULT `Popup Input Value` + button_text_confirm TYPE string DEFAULT `OK` + button_text_cancel TYPE string DEFAULT `Cancel` + PREFERRED PARAMETER val RETURNING - VALUE(r_result) TYPE REF TO z2ui5_cl_popup_input_value. + VALUE(r_result) TYPE REF TO z2ui5_cl_popup_input_value. TYPES: BEGIN OF ty_s_result, - text TYPE string, + value TYPE string, check_cancel TYPE abap_bool, END OF ty_s_result. DATA ms_result TYPE ty_s_result. - METHODS result RETURNING VALUE(result) TYPE ty_s_result. @@ -49,11 +50,12 @@ CLASS Z2UI5_CL_POPUP_INPUT_VALUE IMPLEMENTATION. METHOD factory. r_result = NEW #( ). - r_result->title = i_title. + r_result->title = title. * r_result->icon = i_icon. - r_result->question_text = i_text. - r_result->button_text_confirm = i_button_text_confirm. - r_result->button_text_cancel = i_button_text_cancel. + r_result->question_text = text. + r_result->button_text_confirm = button_text_confirm. + r_result->button_text_cancel = button_text_cancel. + r_result->ms_result-value = val. ENDMETHOD. @@ -75,7 +77,7 @@ CLASS Z2UI5_CL_POPUP_INPUT_VALUE IMPLEMENTATION. )->vbox( 'sapUiMediumMargin' )->label( text = question_text )->input( - value = client->_bind_edit( ms_result-text ) + value = client->_bind_edit( ms_result-value ) submit = client->_event( 'BUTTON_CONFIRM' ) )->get_parent( )->get_parent( )->footer( )->overflow_toolbar(