From 4940a26a46c2a056c857c1923d6e420894c0075b Mon Sep 17 00:00:00 2001 From: oblomov-dev <102328295+oblomov-dev@users.noreply.github.com> Date: Tue, 17 Sep 2024 19:38:43 +0200 Subject: [PATCH] refactoring - filter functions - sticky functions (#1437) * refactoring - filter fucntions - sticky functions * update * udpate * update --- src/01/00/03/z2ui5_cl_util.clas.abap | 52 +++++++++++++++++++-- src/01/02/z2ui5_cl_core_action.clas.abap | 8 +++- src/01/02/z2ui5_cl_core_client.clas.abap | 2 + src/01/02/z2ui5_cl_core_http_post.clas.abap | 13 ++++-- src/01/04/z2ui5_cl_cc_multiinput.clas.abap | 11 ++++- src/02/z2ui5_cl_http_handler.clas.abap | 20 +++++++- src/02/z2ui5_if_app.intf.abap | 1 + 7 files changed, 94 insertions(+), 13 deletions(-) diff --git a/src/01/00/03/z2ui5_cl_util.clas.abap b/src/01/00/03/z2ui5_cl_util.clas.abap index e7bd30fa..43db550b 100644 --- a/src/01/00/03/z2ui5_cl_util.clas.abap +++ b/src/01/00/03/z2ui5_cl_util.clas.abap @@ -45,11 +45,13 @@ CLASS z2ui5_cl_util DEFINITION TYPES: BEGIN OF ty_s_filter_multi, - name TYPE string, - t_range TYPE ty_t_range, - t_token TYPE ty_t_token, - s_sql TYPE ty_S_sql, - sql_text TYPE string, + name TYPE string, + t_range TYPE ty_t_range, + t_token TYPE ty_t_token, + t_token_added TYPE ty_t_token, + t_token_removed TYPE ty_t_token, + s_sql TYPE ty_S_sql, + sql_text TYPE string, END OF ty_s_filter_multi. TYPES ty_t_filter_multi TYPE STANDARD TABLE OF ty_s_filter_multi WITH EMPTY KEY. @@ -133,6 +135,12 @@ CLASS z2ui5_cl_util DEFINITION RETURNING VALUE(result) TYPE ty_t_filter_multi. + CLASS-METHODS filter_get_data_by_multi + IMPORTING + val TYPE ty_t_filter_multi + RETURNING + VALUE(result) TYPE ty_t_filter_multi. + CLASS-METHODS filter_get_sql_by_sql_string IMPORTING val TYPE clike @@ -331,6 +339,13 @@ CLASS z2ui5_cl_util DEFINITION RETURNING VALUE(result) TYPE abap_bool. + CLASS-METHODS filter_update_tokens + IMPORTING + val TYPE ty_t_filter_multi + name TYPE string + RETURNING + VALUE(result) TYPE ty_t_filter_multi. + CLASS-METHODS filter_get_range_t_by_token_t IMPORTING val TYPE ty_t_token @@ -738,6 +753,27 @@ CLASS z2ui5_cl_util IMPLEMENTATION. ENDMETHOD. + METHOD filter_update_tokens. + + result = val. + DATA(lr_filter) = REF #( result[ name = name ] ). + LOOP AT lr_filter->t_token_removed INTO DATA(ls_token). + DELETE lr_filter->t_token WHERE key = ls_token-key. + ENDLOOP. + + LOOP AT lr_filter->t_token_added INTO ls_token. + INSERT VALUE #( key = ls_token-key text = ls_token-text visible = abap_true editable = abap_true ) INTO TABLE lr_filter->t_token. + ENDLOOP. + + CLEAR lr_filter->t_token_removed. + CLEAR lr_filter->t_token_added. + + data(lt_token) = result[ name = name ]-t_token. + data(lt_range) = z2ui5_cl_util=>filter_get_range_t_by_token_t( result[ name = name ]-t_token ). + lr_filter->t_range = lt_range. + + ENDMETHOD. + METHOD filter_get_range_t_by_token_t. LOOP AT val INTO DATA(ls_token). @@ -1450,6 +1486,12 @@ CLASS z2ui5_cl_util IMPLEMENTATION. METHOD itab_filter_by_t_range. + ENDMETHOD. + + METHOD filter_get_data_by_multi. + + + ENDMETHOD. ENDCLASS. diff --git a/src/01/02/z2ui5_cl_core_action.clas.abap b/src/01/02/z2ui5_cl_core_action.clas.abap index 37950f17..ae0c3856 100644 --- a/src/01/02/z2ui5_cl_core_action.clas.abap +++ b/src/01/02/z2ui5_cl_core_action.clas.abap @@ -68,7 +68,13 @@ CLASS z2ui5_cl_core_action IMPLEMENTATION. METHOD factory_by_frontend. result = NEW #( mo_http_post ). - result->mo_app = z2ui5_cl_core_app=>db_load( mo_http_post->ms_request-s_front-id ). + + IF mo_http_post->mo_action->mo_app->mo_app IS BOUND. + result->mo_app = mo_http_post->mo_action->mo_app. + ELSE. + result->mo_app = z2ui5_cl_core_app=>db_load( mo_http_post->ms_request-s_front-id ). + ENDIF. + result->mo_app->ms_draft-id = z2ui5_cl_util=>uuid_get_c32( ). result->mo_app->ms_draft-id_prev = mo_http_post->ms_request-s_front-id. diff --git a/src/01/02/z2ui5_cl_core_client.clas.abap b/src/01/02/z2ui5_cl_core_client.clas.abap index ffe47113..2a7d200b 100644 --- a/src/01/02/z2ui5_cl_core_client.clas.abap +++ b/src/01/02/z2ui5_cl_core_client.clas.abap @@ -345,8 +345,10 @@ CLASS z2ui5_cl_core_client IMPLEMENTATION. IF stateful = abap_true. mo_action->ms_next-s_set-handler_attrs-stateful-active = 1. + CAST z2ui5_if_app( mo_action->mo_app->mo_app )->check_sticky = abap_true. ELSE. mo_action->ms_next-s_set-handler_attrs-stateful-active = 0. + CAST z2ui5_if_app( mo_action->mo_app->mo_app )->check_sticky = abap_false. ENDIF. mo_action->ms_next-s_set-handler_attrs-stateful-switched = abap_true. diff --git a/src/01/02/z2ui5_cl_core_http_post.clas.abap b/src/01/02/z2ui5_cl_core_http_post.clas.abap index d7a25e50..460f4adf 100644 --- a/src/01/02/z2ui5_cl_core_http_post.clas.abap +++ b/src/01/02/z2ui5_cl_core_http_post.clas.abap @@ -117,7 +117,10 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION. mv_response = lo_json_mapper->response_abap_to_json( ms_response ). CLEAR mo_action->ms_next. - mo_action->mo_app->db_save( ). + + IF CAST z2ui5_if_app( mo_action->mo_app->mo_app )->check_sticky = abap_false. + mo_action->mo_app->db_save( ). + ENDIF. ENDMETHOD. @@ -134,9 +137,13 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION. ENDTRY. DATA(li_app) = CAST z2ui5_if_app( mo_action->mo_app->mo_app ). - ROLLBACK WORK. + IF li_app->check_sticky = abap_false. + ROLLBACK WORK. + ENDIF. li_app->main( li_client ). - ROLLBACK WORK. + IF li_app->check_sticky = abap_false. + ROLLBACK WORK. + ENDIF. IF mo_action->ms_next-o_app_leave IS NOT INITIAL. mo_action = mo_action->factory_stack_leave( ). diff --git a/src/01/04/z2ui5_cl_cc_multiinput.clas.abap b/src/01/04/z2ui5_cl_cc_multiinput.clas.abap index 30f4408f..d778327f 100644 --- a/src/01/04/z2ui5_cl_cc_multiinput.clas.abap +++ b/src/01/04/z2ui5_cl_cc_multiinput.clas.abap @@ -41,7 +41,7 @@ CLASS z2ui5_cl_cc_multiinput IMPLEMENTATION. ` },` && |\n| && |\n| && ` init() {` && |\n| && - ` sap.z2ui5.onAfterRendering.push( this.setControl.bind(this) ); ` && |\n| && + ` sap.z2ui5.onAfterRendering.push( this.setControl.bind(this) ); ` && |\n| && ` },` && |\n| && |\n| && ` onTokenUpdate(oEvent) { ` && |\n| && @@ -63,7 +63,13 @@ CLASS z2ui5_cl_cc_multiinput IMPLEMENTATION. ` }` && |\n| && ` this.fireChange();` && |\n| && ` },` && |\n| && - ` setControl(){ let table = sap.z2ui5.oView.byId( this.getProperty("MultiInputId"));` && |\n| && + ` renderer(oRm, oControl) { ` && + ` sap.z2ui5.onAfterRendering.push( this.setControl.bind(oControl) ); ` && |\n| && + ` },` && |\n| && + ` setControl(){ ` && |\n| && + ` let table = sap.z2ui5.oView.byId( this.getProperty("MultiInputId") );` && |\n| && + ` if (!table) { table = sap.ui.getCore().byId( this.getProperty("MultiInputId") ); } ` && |\n| && + ` if ( !table ){ return; } ` && |\n| && ` if ( this.getProperty("checkInit") == true ){ return; } ` && |\n| && ` this.setProperty( "checkInit" , true );` && |\n| && ` table.attachTokenUpdate(this.onTokenUpdate.bind(this));` && |\n| && @@ -73,6 +79,7 @@ CLASS z2ui5_cl_cc_multiinput IMPLEMENTATION. ` };` && |\n| && ` table.addValidator(fnValidator); }, ` && |\n| && ` renderer(oRM, oControl) {` && |\n| && +* ` sap.z2ui5.onAfterRendering.push( oControl.setControl.bind(oControl) ); ` && |\n| && ` }` && |\n| && ` });` && |\n| && `}); }`. diff --git a/src/02/z2ui5_cl_http_handler.clas.abap b/src/02/z2ui5_cl_http_handler.clas.abap index 57f83211..4e975985 100644 --- a/src/02/z2ui5_cl_http_handler.clas.abap +++ b/src/02/z2ui5_cl_http_handler.clas.abap @@ -4,6 +4,8 @@ CLASS z2ui5_cl_http_handler DEFINITION PUBLIC SECTION. + CLASS-DATA so_sticky_handler TYPE REF TO z2ui5_cl_core_http_post. + CLASS-METHODS main IMPORTING body TYPE string @@ -47,11 +49,17 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION. METHOD http_post. CLEAR attributes. - DATA(lo_post) = NEW z2ui5_cl_core_http_post( val ). + IF so_sticky_handler IS NOT BOUND. + DATA(lo_post) = NEW z2ui5_cl_core_http_post( val ). + ELSE. + so_sticky_handler = lo_post. + ENDIF. result = lo_post->main( IMPORTING attributes = attributes ). + so_sticky_handler = lo_post. + ENDMETHOD. METHOD main. @@ -61,12 +69,20 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION. DATA(lo_get) = NEW z2ui5_cl_core_http_get( config ). result = lo_get->main( ). ELSE. - DATA(lo_post) = NEW z2ui5_cl_core_http_post( body ). + IF so_sticky_handler IS NOT BOUND. + DATA(lo_post) = NEW z2ui5_cl_core_http_post( body ). + ELSE. + lo_post = so_sticky_handler. + lo_post->mv_request_json = body. + ENDIF. +* DATA(lo_post) = NEW z2ui5_cl_core_http_post( body ). result = lo_post->main( IMPORTING attributes = attributes ). ENDIF. + so_sticky_handler = lo_post. + ENDMETHOD. ENDCLASS. diff --git a/src/02/z2ui5_if_app.intf.abap b/src/02/z2ui5_if_app.intf.abap index 0b712f97..8ba7d195 100644 --- a/src/02/z2ui5_if_app.intf.abap +++ b/src/02/z2ui5_if_app.intf.abap @@ -8,6 +8,7 @@ INTERFACE z2ui5_if_app PUBLIC. DATA id_draft TYPE string. DATA id_app TYPE string. + DATA check_sticky TYPE abap_bool. METHODS main IMPORTING