json refactoring (#863)

This commit is contained in:
oblomov 2024-02-04 16:27:22 +01:00 committed by GitHub
parent 563a0e4306
commit afaeb7f871
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 105 additions and 126 deletions

View File

@ -184,11 +184,11 @@ CLASS Z2UI5_CL_FW_APP IMPLEMENTATION.
viewname = mo_http_post->ms_request-s_frontend-viewname
app = result->ms_db-app
t_attri = result->ms_db-t_attri
ajson_in = mo_http_post->ms_request-model
ajson_in = mo_http_post->ms_request-o_model
).
result->ms_actual-event = mo_http_post->ms_request-s_control-event.
result->ms_actual-t_event_arg = mo_http_post->ms_request-s_control-t_event_arg.
result->ms_actual-event = mo_http_post->ms_request-s_frontend-event.
result->ms_actual-t_event_arg = mo_http_post->ms_request-s_frontend-t_event_arg.
result->ms_actual-check_on_navigated = abap_false.
result->ms_db-check_attri = abap_false.
ENDMETHOD.

View File

@ -12,8 +12,6 @@ CLASS z2ui5_cl_fw_binding DEFINITION
one_time TYPE string VALUE `ONE_TIME`,
END OF cs_bind_type.
CONSTANTS cv_model_edit_name TYPE string VALUE `EDIT`.
TYPES:
BEGIN OF ty_s_attri,
name TYPE string,
@ -210,6 +208,7 @@ CLASS Z2UI5_CL_FW_BINDING IMPLEMENTATION.
ENDMETHOD.
METHOD bind.
FIELD-SYMBOLS <attri> TYPE any.
@ -251,7 +250,7 @@ CLASS Z2UI5_CL_FW_BINDING IMPLEMENTATION.
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.
result = COND #( WHEN mv_type = cs_bind_type-two_way THEN `/EDIT` ) && `/` && bind->name_front.
RETURN.
ENDIF.
@ -263,7 +262,7 @@ CLASS Z2UI5_CL_FW_BINDING IMPLEMENTATION.
bind->name_front = replace( val = bind->name sub = `-` with = `/` ).
bind->name_front = replace( val = bind->name_front sub = `>` with = `` ).
result = `/` && COND #( WHEN mv_type = cs_bind_type-two_way THEN cv_model_edit_name && `/` ) && bind->name_front.
result = COND #( WHEN mv_type = cs_bind_type-two_way THEN `/EDIT` ) && `/` && bind->name_front.
ENDMETHOD.

View File

@ -21,10 +21,7 @@ ENDCLASS.
CLASS z2ui5_cl_fw_client IMPLEMENTATION.
CLASS Z2UI5_CL_FW_CLIENT IMPLEMENTATION.
METHOD constructor.
@ -33,6 +30,17 @@ CLASS z2ui5_cl_fw_client IMPLEMENTATION.
ENDMETHOD.
METHOD z2ui5_if_client~clear.
CASE val.
WHEN z2ui5_if_client~cs_clear-view.
CLEAR mo_app->ms_next-s_set-s_view.
ENDCASE.
ENDMETHOD.
METHOD z2ui5_if_client~get.
result = VALUE #(
@ -41,7 +49,12 @@ CLASS z2ui5_cl_fw_client IMPLEMENTATION.
t_event_arg = mo_app->ms_actual-t_event_arg
s_draft = CORRESPONDING #( mo_app->ms_db )
check_on_navigated = mo_app->ms_actual-check_on_navigated
s_config = mo_app->mo_http_post->ms_request-s_frontend-s_config
s_config = value #(
origin = mo_app->mo_http_post->ms_request-s_frontend-origin
pathname = mo_app->mo_http_post->ms_request-s_frontend-pathname
search = mo_app->mo_http_post->ms_request-s_frontend-search
t_startup_params = mo_app->mo_http_post->ms_request-s_frontend-t_startup_params
)
).
ENDMETHOD.
@ -213,19 +226,6 @@ CLASS z2ui5_cl_fw_client IMPLEMENTATION.
RETURN.
ENDIF.
* IF struc IS NOT INITIAL.
*
* DATA(lv_name_struc) = z2ui5_if_client~_bind_edit( val = struc
* path = abap_true ).
* result = z2ui5_cl_fw_binding=>bind_struc_comp(
* iv_name = lv_name_struc
* i_struc = struc
* i_val = val ).
*
* RETURN.
*
* ENDIF.
DATA(lo_binder) = z2ui5_cl_fw_binding=>factory(
app = mo_app->ms_db-app
attri = mo_app->ms_db-t_attri
@ -259,14 +259,6 @@ CLASS z2ui5_cl_fw_client IMPLEMENTATION.
ENDMETHOD.
METHOD z2ui5_if_client~clear.
CASE val.
WHEN z2ui5_if_client~cs_clear-view.
CLEAR mo_app->ms_next-s_set-s_view.
ENDCASE.
ENDMETHOD.
METHOD z2ui5_if_client~_bind_edit.
@ -279,14 +271,6 @@ CLASS z2ui5_cl_fw_client IMPLEMENTATION.
i_tab = tab
i_val = val ).
* ELSEIF struc IS NOT INITIAL.
* DATA(lv_name_struc) = z2ui5_if_client~_bind_edit( val = struc path = abap_true ).
* result = z2ui5_cl_fw_binding=>bind_struc_comp(
* iv_name = lv_name_struc
* i_struc = struc
* i_val = val ).
ELSE.
DATA(lo_binder) = z2ui5_cl_fw_binding=>factory(

View File

@ -416,7 +416,12 @@ CLASS Z2UI5_CL_FW_HTTP_GET IMPLEMENTATION.
` sap.z2ui5.oController.responseError(responseText);` && |\n| &&
` } else {` && |\n| &&
` const responseData = await response.json();` && |\n| &&
` sap.z2ui5.oController.responseSuccess(responseData);` && |\n| &&
` debugger;` && |\n| &&
` sap.z2ui5.oController.responseSuccess({` && |\n| &&
` ID : responseData.S_FRONTEND.ID,` && |\n| &&
` PARAMS : responseData.S_FRONTEND.PARAMS,` && |\n| &&
` OVIEWMODEL : responseData.MODEL,` && |\n| &&
` });` && |\n| &&
` }` && |\n| &&
|\n| &&
` },` && |\n| &&
@ -432,13 +437,27 @@ CLASS Z2UI5_CL_FW_HTTP_GET IMPLEMENTATION.
` PATHNAME: sap.z2ui5.pathname,` && |\n| &&
` SEARCH: window.location.search,` && |\n| &&
` // VERSION: sap.ui.getVersionInfo().gav,` && |\n| &&
* ` CHECK_LAUNCHPAD_ACTIVE: sap.ushell !== undefined,` && |\n| &&
* ` STARTUP_PARAMETERS: sap.z2ui5.startupParameters,` && |\n| &&
` T_STARTUP_PARAMETERS: sap.z2ui5.startupParameters,` && |\n| &&
` };` && |\n| &&
` if (sap.z2ui5.search) {` && |\n| &&
` sap.z2ui5.oBody.OLOCATION.SEARCH = sap.z2ui5.search;` && |\n| &&
` }` && |\n| &&
` let event = (args) => { if ( args != undefined ) { return args[ 0 ].EVENT; } };` && |\n| &&
* ` let args = (args) => { if ( args != undefined ) { if ( args.length > 1 ) { return args.shift(); } } };` && |\n| &&
` sap.z2ui5.oBody.S_FRONTEND = {` && |\n| &&
` ID: sap.z2ui5?.oBody?.ID,` && |\n| &&
` APP_START: sap.z2ui5?.oBody?.APP_START,` && |\n| &&
` EDIT: sap.z2ui5?.oBody?.EDIT,` && |\n| &&
` ORIGIN: sap.z2ui5.oBody.OLOCATION.ORIGIN,` && |\n| &&
` PATHNAME: sap.z2ui5.oBody.OLOCATION.PATHNAME,` && |\n| &&
` SEARCH: sap.z2ui5.oBody.OLOCATION.SEARCH,` && |\n| &&
` VIEWNAME: sap.z2ui5.oBody.VIEWNAME,` && |\n| &&
` T_STARTUP_PARAMETERS: sap.z2ui5.oBody.OLOCATION.T_STARTUP_PARAMETERS,` && |\n| &&
` EVENT: event(sap.z2ui5.oBody?.ARGUMENTS),` && |\n| &&
` };` && |\n| &&
` if ( sap.z2ui5.oBody?.ARGUMENTS != undefined ) { if ( sap.z2ui5.oBody?.ARGUMENTS.length > 0 ) { sap.z2ui5.oBody?.ARGUMENTS.shift(); } }` && |\n| &&
` sap.z2ui5.oBody.S_FRONTEND.T_EVENT_ARG = sap.z2ui5.oBody?.ARGUMENTS;` && |\n| &&
` debugger;` && |\n| &&
` sap.z2ui5.oController.readHttp();` && |\n| &&
` },` && |\n| &&
` })` && |\n| &&

View File

@ -38,7 +38,7 @@ ENDCLASS.
CLASS Z2UI5_CL_FW_HTTP_MAPPER IMPLEMENTATION.
CLASS z2ui5_cl_fw_http_mapper IMPLEMENTATION.
METHOD model_back_to_front.
@ -79,7 +79,7 @@ CLASS Z2UI5_CL_FW_HTTP_MAPPER IMPLEMENTATION.
ajson->set( iv_ignore_empty = abap_false iv_path = `/` iv_val = <attribute> ).
WHEN z2ui5_cl_fw_binding=>cs_bind_type-two_way.
lv_path = z2ui5_cl_fw_binding=>cv_model_edit_name && `/` && lr_attri->name_front.
lv_path = `EDIT/` && lr_attri->name_front.
ajson->set( iv_ignore_empty = abap_false iv_path = `/` iv_val = <attribute> ).
WHEN OTHERS.
@ -141,54 +141,36 @@ CLASS Z2UI5_CL_FW_HTTP_MAPPER IMPLEMENTATION.
METHOD request_json_to_abap.
TRY.
DATA(lo_ajson) = CAST z2ui5_if_ajson( z2ui5_cl_ajson=>parse( val ) ).
result-o_model = lo_ajson->slice( `/EDIT` ).
lo_ajson->delete( `/EDIT` ).
result-model = lo_ajson->slice( `/EDIT` ).
result-s_frontend-id = lo_ajson->get( `/ID` ).
result-s_frontend-viewname = lo_ajson->get( `/VIEWNAME` ).
result-s_frontend-app_start = to_upper( lo_ajson->get( `/APP_START` ) ).
result-s_frontend-arguments = lo_ajson->slice( `/ARGUMENTS` ).
lo_ajson = lo_ajson->slice( `/OLOCATION` ).
lo_ajson = lo_ajson->slice( `/S_FRONTEND`).
lo_ajson->to_abap(
EXPORTING
iv_corresponding = abap_true
iv_corresponding = abap_true
IMPORTING
ev_container = result-s_frontend-s_config ).
ev_container = result-s_frontend ).
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
result-s_control-check_launchpad = xsdbool(
result-s_frontend-s_config-search CS `scenario=LAUNCHPAD` ).
result-s_control-check_launchpad = xsdbool( result-s_frontend-search CS `scenario=LAUNCHPAD` ).
IF result-s_frontend-arguments IS BOUND.
DATA(lo_event) = result-s_frontend-arguments->clone( ).
result-s_control-event = lo_event->get( `/1/EVENT` ).
lo_event->delete( `/1` ).
lo_event->to_abap(
IMPORTING
ev_container = result-s_control-t_event_arg
).
IF result-s_frontend-id IS NOT INITIAL.
RETURN.
ENDIF.
IF result-s_frontend-id IS INITIAL.
TRY.
result-s_control-app_start = to_upper( z2ui5_cl_util_func=>c_trim( result-s_frontend-app_start ) ).
CATCH cx_root.
ENDTRY.
IF result-s_control-app_start IS INITIAL.
result-s_control-app_start = to_upper( z2ui5_cl_util_func=>url_param_get( val = `app_start`
url = result-s_frontend-s_config-search ) ).
ENDIF.
result-s_control-app_start = z2ui5_cl_util_func=>c_trim_upper( result-s_frontend-app_start ).
IF result-s_control-app_start IS NOT INITIAL.
RETURN.
ENDIF.
result-s_control-app_start = z2ui5_cl_util_func=>c_trim_upper(
z2ui5_cl_util_func=>url_param_get( val = `app_start` url = result-s_frontend-search ) ).
CATCH cx_root INTO DATA(x).
ASSERT x IS NOT BOUND.
ENDTRY.
@ -198,24 +180,16 @@ CLASS Z2UI5_CL_FW_HTTP_MAPPER IMPLEMENTATION.
METHOD response_abap_to_json.
TRY.
"todo performance - write all data directly into the target ajson
DATA(ajson_result) = CAST z2ui5_if_ajson( z2ui5_cl_ajson=>create_empty(
ii_custom_mapping = z2ui5_cl_ajson_mapping=>create_upper_case( ) ) ).
* ajson_result->set( iv_path = `/PARAMS` iv_val = ms_next-s_set ).
* ajson_result->set( iv_path = `/ID` iv_val = ms_db-id ).
ajson_result->set( iv_path = `/` iv_val = val-s_frontend ).
ajson_result = ajson_result->filter( NEW z2ui5_cl_fw_http_mapper( ) ).
* DATA(lo_ajson) = NEW z2ui5_cl_fw_http_mapper( )->model_back_to_front(
* app = ms_db-app
* t_attri = ms_db-t_attri ).
ajson_result->set( iv_path = `/OVIEWMODEL` iv_val = val-oviewmodel ).
result = ajson_result->stringify( ).
* z2ui5_cl_fw_db=>create( id = ms_db-id db = ms_db ).
result = `{` &&
|"S_FRONTEND" : { ajson_result->stringify( ) },| &&
|"MODEL" : { val-o_model->stringify( ) }| &&
`}`.
CATCH cx_root INTO DATA(x).
ASSERT x IS NOT BOUND.

View File

@ -5,7 +5,7 @@ CLASS z2ui5_cl_fw_http_post DEFINITION
PUBLIC SECTION.
DATA mv_request_plain TYPE string.
DATA mv_request_json TYPE string.
DATA ms_request TYPE z2ui5_if_client=>ty_s_http_request_post.
DATA ms_response TYPE z2ui5_if_client=>ty_s_http_response_post.
@ -41,7 +41,7 @@ CLASS z2ui5_cl_fw_http_post IMPLEMENTATION.
METHOD factory.
result = NEW #( ).
result->mv_request_plain = val.
result->mv_request_json = val.
mo_http_mapper = NEW z2ui5_cl_fw_http_mapper( ).
result->mo_app = NEW z2ui5_cl_fw_app( result ).
@ -50,7 +50,7 @@ CLASS z2ui5_cl_fw_http_post IMPLEMENTATION.
METHOD main_begin.
ms_request = mo_http_mapper->request_json_to_abap( mv_request_plain ).
ms_request = mo_http_mapper->request_json_to_abap( mv_request_json ).
TRY.
IF ms_request-s_frontend-id IS NOT INITIAL.
@ -68,13 +68,15 @@ CLASS z2ui5_cl_fw_http_post IMPLEMENTATION.
METHOD main_end.
TRY.
DATA(lo_ajson) = NEW z2ui5_cl_fw_http_mapper( )->model_back_to_front(
app = mo_app->ms_db-app
t_attri = mo_app->ms_db-t_attri ).
z2ui5_cl_fw_draft=>create( id = mo_app->ms_db-id db = mo_app->ms_db ).
ms_response-o_model = NEW z2ui5_cl_fw_http_mapper( )->model_back_to_front(
app = mo_app->ms_db-app
t_attri = mo_app->ms_db-t_attri ).
ms_response-s_frontend-params = mo_app->ms_next-s_set.
ms_response-s_frontend-id = mo_app->ms_db-id.
ms_response-oviewmodel = lo_ajson.
CATCH cx_root INTO DATA(x).
ASSERT x IS NOT BOUND.
ENDTRY.

View File

@ -36,28 +36,29 @@ INTERFACE z2ui5_if_client
TYPES:
BEGIN OF ty_s_config,
version TYPE string,
origin TYPE string,
pathname TYPE string,
search TYPE string,
t_startup_params TYPE ty_t_name_value,
origin TYPE string,
pathname TYPE string,
search TYPE string,
t_startup_params TYPE ty_t_name_value,
END OF ty_s_config.
TYPES:
BEGIN OF ty_s_http_request_post,
model TYPE REF TO z2ui5_if_ajson,
o_model TYPE REF TO z2ui5_if_ajson,
BEGIN OF s_frontend,
id TYPE string,
viewname type string,
arguments TYPE REF TO z2ui5_if_ajson,
app_start type string,
s_config TYPE ty_s_config,
id TYPE string,
viewname TYPE string,
t_event_arg TYPE string_table,
app_start TYPE string,
origin TYPE string,
pathname TYPE string,
search TYPE string,
event TYPE string,
t_startup_params TYPE ty_t_name_value,
END OF s_frontend,
BEGIN OF s_control,
check_launchpad TYPE abap_bool,
event type string,
app_start type string,
t_event_arg type string_table,
app_start TYPE string,
END OF s_control,
END OF ty_s_http_request_post.
@ -67,16 +68,16 @@ INTERFACE z2ui5_if_client
params TYPE z2ui5_cl_fw_app=>ty_s_next2,
id TYPE string,
END OF s_frontend,
oviewmodel TYPE REF TO z2ui5_if_ajson,
o_model TYPE REF TO z2ui5_if_ajson,
END OF ty_s_http_response_post.
TYPES:
BEGIN OF ty_s_http_request_get,
t_config TYPE ty_t_name_value,
content_security_policy TYPE string,
custom_js TYPE string,
json_model_limit TYPE string,
END OF ty_s_http_request_get.
TYPES:
BEGIN OF ty_s_http_request_get,
t_config TYPE ty_t_name_value,
content_security_policy TYPE string,
custom_js TYPE string,
json_model_limit TYPE string,
END OF ty_s_http_request_get.
TYPES:
BEGIN OF ty_s_draft,
@ -100,13 +101,13 @@ INTERFACE z2ui5_if_client
TYPES:
BEGIN OF ty_s_actual,
event TYPE string,
t_event_arg TYPE string_table,
event TYPE string,
t_event_arg TYPE string_table,
* check_launchpad_active TYPE abap_bool,
check_on_navigated TYPE abap_bool,
viewname TYPE string,
s_draft TYPE ty_s_draft,
s_config TYPE ty_s_config,
check_on_navigated TYPE abap_bool,
viewname TYPE string,
s_draft TYPE ty_s_draft,
s_config TYPE ty_s_config,
END OF ty_s_actual.
METHODS view_destroy.