Skip to content

Commit

Permalink
Refactoring (abap2UI5#1417)
Browse files Browse the repository at this point in the history
* refactoring

* update

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update z2ui5_cl_core_http_get2.clas.abap

* lint fix

* update

* Update abaplint.jsonc
  • Loading branch information
oblomov-dev authored Sep 11, 2024
1 parent 83fcc96 commit 622c19c
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 79 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ This project greatly benefits from its [contributors](https://github.com/abap2UI
* Want to help out? Review our [contribution guidelines](https://github.com/abap2UI5/abap2UI5-documentation/blob/main/CONTRIBUTING.md) to get started
* Stay updated! Follow us on [LinkedIn](https://www.linkedin.com/company/abap2ui5)

_We welcome all contributions! Share your knowledge, submit a PR, write a comment, give us a like, or simply tell others that you love abap2UI5. This project thrives on your support! 🚀_
_We welcome all contributions! Share your knowledge, hunt for or fix bugs, submit a PR, write a comment, give us a like, or simply tell your friends how much you love abap2UI5. This project thrives on your support! 🚀_


2 changes: 1 addition & 1 deletion ci/abaplint.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"strict_sql" : true,
"easy_to_find_messages" : true,
"fully_type_itabs" : true,
"align_parameters": true,
"align_parameters": false,
"smim_consistency": true,
"allowed_object_naming": true,
"allowed_object_types": {
Expand Down
1 change: 0 additions & 1 deletion src/01/02/z2ui5_cl_core_client.clas.abap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
CLASS z2ui5_cl_core_client DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .

PUBLIC SECTION.
Expand Down
147 changes: 79 additions & 68 deletions src/01/02/z2ui5_cl_core_http_get2.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ CLASS z2ui5_cl_core_http_get2 DEFINITION
CREATE PUBLIC .

PUBLIC SECTION.

DATA ms_request TYPE z2ui5_if_types=>ty_s_http_request_get2.
DATA mv_response TYPE string.
CLASS-METHODS class_constructor.

METHODS constructor
IMPORTING
val TYPE z2ui5_if_types=>ty_s_http_request_get2 OPTIONAL.
val TYPE z2ui5_if_types=>ty_s_config_index_html OPTIONAL.

METHODS main
RETURNING
VALUE(result) TYPE string.


PROTECTED SECTION.

CLASS-DATA cs_config_default TYPE z2ui5_if_types=>ty_s_config_index_html.

DATA ms_config_in TYPE z2ui5_if_types=>ty_s_config_index_html.
DATA mv_index_html TYPE string.

CLASS-METHODS set_default_config.

METHODS get_js
RETURNING
VALUE(result) TYPE string.
Expand All @@ -24,19 +32,13 @@ CLASS z2ui5_cl_core_http_get2 DEFINITION
RETURNING
VALUE(result) TYPE string.

PROTECTED SECTION.

METHODS get_default_t_param
RETURNING
VALUE(result) TYPE z2ui5_if_types=>ty_t_name_value.

METHODS get_default_t_option
METHODS main_set_config
RETURNING
VALUE(result) TYPE z2ui5_if_types=>ty_t_name_value.
VALUE(result) TYPE z2ui5_if_types=>ty_s_config_index_html.

METHODS get_default_security_policy
RETURNING
VALUE(result) TYPE string.
METHODS main_set_index_html
IMPORTING
cs_config TYPE z2ui5_if_types=>ty_s_config_index_html.

PRIVATE SECTION.
ENDCLASS.
Expand All @@ -45,58 +47,61 @@ ENDCLASS.

CLASS z2ui5_cl_core_http_get2 IMPLEMENTATION.


METHOD constructor.

ms_request = val.
me->ms_config_in = val.

ENDMETHOD.

METHOD get_default_t_param.
METHOD class_constructor.
set_default_config( ).
ENDMETHOD.

result = VALUE #(
( n = `TITLE` v = `abap2UI5` )
( n = `BODY_CLASS` v = `sapUiBody sapUiSizeCompact` )
( n = `CONTENT_SECURITY_POLICY` v = get_default_security_policy( ) )
).

LOOP AT ms_request-t_param REFERENCE INTO DATA(lr_input).
TRY.
result[ n = lr_input->n ]-v = lr_input->v.
CATCH cx_root.
INSERT lr_input->* INTO TABLE result.
ENDTRY.
ENDLOOP.
METHOD set_default_config.

DATA(lv_csp) = `default-src 'self' 'unsafe-inline' 'unsafe-eval' data: ` &&
`ui5.sap.com *.ui5.sap.com sapui5.hana.ondemand.com *.sapui5.hana.ondemand.com openui5.hana.ondemand.com *.openui5.hana.ondemand.com ` &&
`sdk.openui5.org *.sdk.openui5.org cdn.jsdelivr.net *.cdn.jsdelivr.net cdnjs.cloudflare.com *.cdnjs.cloudflare.com schemas *.schemas`.

cs_config_default = VALUE #(
t_param = VALUE #(
( n = `TITLE` v = `abap2UI5` )
( n = `BODY_CLASS` v = `sapUiBody sapUiSizeCompact` )
( n = `CONTENT_SECURITY_POLICY` v = lv_csp )
)
t_option = VALUE #(
( n = `src` v = `https://sdk.openui5.org/resources/sap-ui-cachebuster/sap-ui-core.js` )
* ( n = `src` v = `https://sdk.openui5.org/nightly/2/resources/sap-ui-core.js` )
( n = `data-sap-ui-theme` v = `sap_horizon` )
( n = `data-sap-ui-async` v = `true` )
( n = `id` v = `sap-ui-bootstrap` )
( n = `data-sap-ui-bindingSyntax` v = `complex` )
( n = `data-sap-ui-frameOptions` v = `trusted` )
( n = `data-sap-ui-compatVersion` v = `edge` )
) ).

ENDMETHOD.

METHOD get_default_t_option.
METHOD main_set_config.

result = VALUE #(
( n = `src` v = `https://sdk.openui5.org/resources/sap-ui-cachebuster/sap-ui-core.js` )
( n = `data-sap-ui-theme` v = `sap_horizon` )
( n = `data-sap-ui-async` v = `true` )
( n = `id` v = `sap-ui-bootstrap` )
( n = `data-sap-ui-bindingSyntax` v = `complex` )
( n = `data-sap-ui-frameOptions` v = `trusted` )
( n = `data-sap-ui-compatVersion` v = `edge` ) ).
result = cs_config_default.

LOOP AT ms_request-t_option REFERENCE INTO DATA(lr_input).
LOOP AT ms_config_in-t_param REFERENCE INTO DATA(lr_param).
TRY.
result[ n = lr_input->n ]-v = lr_input->v.
result-t_param[ n = lr_param->n ]-v = lr_param->v.
CATCH cx_root.
INSERT lr_input->* INTO TABLE result.
INSERT lr_param->* INTO TABLE result-t_param.
ENDTRY.
ENDLOOP.

ENDMETHOD.


METHOD get_default_security_policy.

result = `default-src 'self' 'unsafe-inline' 'unsafe-eval' data: ` &&
`ui5.sap.com *.ui5.sap.com sapui5.hana.ondemand.com *.sapui5.hana.ondemand.com openui5.hana.ondemand.com *.openui5.hana.ondemand.com ` &&
`sdk.openui5.org *.sdk.openui5.org cdn.jsdelivr.net *.cdn.jsdelivr.net cdnjs.cloudflare.com *.cdnjs.cloudflare.com schemas *.schemas`.
LOOP AT ms_config_in-t_option REFERENCE INTO DATA(lr_option).
TRY.
result-t_option[ n = lr_option->n ]-v = lr_option->v.
CATCH cx_root.
INSERT lr_option->* INTO TABLE result-t_option.
ENDTRY.
ENDLOOP.

ENDMETHOD.

Expand Down Expand Up @@ -125,42 +130,48 @@ CLASS z2ui5_cl_core_http_get2 IMPLEMENTATION.

METHOD main.

DATA(lt_config) = get_default_t_option( ).
DATA(lt_param) = get_default_t_param( ).
DATA(ls_config) = main_set_config( ).
main_set_index_html( ls_config ).
result = mv_index_html.

NEW z2ui5_cl_core_draft_srv( )->cleanup( ).

ENDMETHOD.


mv_response = `<!DOCTYPE html>` && |\n| &&
METHOD main_set_index_html.

mv_index_html = `<!DOCTYPE html>` && |\n| &&
`<head>` && |\n| &&
| <meta http-equiv="Content-Security-Policy" content="{ lt_param[ n = `CONTENT_SECURITY_POLICY` ]-v }"/>\n| &&
| <meta http-equiv="Content-Security-Policy" content="{ cs_config-t_param[ n = `CONTENT_SECURITY_POLICY` ]-v }"/>\n| &&
` <meta charset="UTF-8">` && |\n| &&
` <meta name="viewport" content="width=device-width, initial-scale=1.0">` && |\n| &&
| <title>{ lt_param[ n = `TITLE` ]-v }</title> \n| &&
| <title>{ cs_config-t_param[ n = `TITLE` ]-v }</title> \n| &&
` <script `.

LOOP AT lt_config REFERENCE INTO DATA(lr_config).
mv_response = mv_response && | { lr_config->n }='{ lr_config->v }'|.
LOOP AT cs_config-t_option REFERENCE INTO DATA(lr_config).
mv_index_html = mv_index_html && | { lr_config->n }='{ lr_config->v }'|.
ENDLOOP.

mv_response = mv_response &&
mv_index_html = mv_index_html &&
| ></script></head> \n| &&
| <body class="{ lt_param[ n = 'BODY_CLASS' ]-v }" id="content" > \n| &&
| <body class="{ cs_config-t_param[ n = 'BODY_CLASS' ]-v }" id="content" > \n| &&
|<body class="sapUiBody" id="content" > \n| &&
| <div data-sap-ui-component data-height="100%" data-id="container" ></div> \n| &&
|<abc/> \n|.

DATA(lv_add_js) = get_js_cc_startup( ) && ms_request-add_js.
DATA(lv_add_js) = get_js_cc_startup( ) && ms_config_in-add_js.

mv_response = mv_response &&
| <script> sap.z2ui5 = sap.z2ui5 \|\| \{\} ; if ( typeof z2ui5 == "undefined" ) \{ var z2ui5 = \{\}; \}; \n| &&
mv_index_html = mv_index_html &&
| <script> sap.z2ui5 = sap.z2ui5 \|\| \{\} ; if ( typeof z2ui5 == "undefined" ) \{ var z2ui5 = \{\}; \}; \n| &&
| { get_js( ) } \n| &&
| { lv_add_js } \n|.

mv_response = mv_response && z2ui5_cl_cc_debug_tool=>get_js( ) && `</script><abc/></body></html>`.

NEW z2ui5_cl_core_draft_srv( )->cleanup( ).
result = mv_response.
| { lv_add_js } \n| &&
| { z2ui5_cl_cc_debug_tool=>get_js( ) } \n| &&
| </script><abc/></body></html> |.

ENDMETHOD.


METHOD get_js.

DATA(lv_two_way_model) = z2ui5_if_core_types=>cs_ui5-two_way_model.
Expand Down
10 changes: 8 additions & 2 deletions src/01/02/z2ui5_cl_core_http_post.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,14 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION.

METHOD main_process.
TRY.

DATA(li_client) = NEW z2ui5_cl_core_client( mo_action ).
DATA li_client TYPE REF TO z2ui5_cl_core_client.
TRY.
CREATE OBJECT li_client TYPE ('ZCL_2UI5_CUSTOM_CLIENT')
EXPORTING
action = mo_action.
CATCH cx_root.
li_client = NEW z2ui5_cl_core_client( mo_action ).
ENDTRY.
DATA(li_app) = CAST z2ui5_if_app( mo_action->mo_app->mo_app ).

ROLLBACK WORK.
Expand Down
2 changes: 1 addition & 1 deletion src/01/03/z2ui5_cl_core_app_startup.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ CLASS Z2UI5_CL_CORE_APP_STARTUP IMPLEMENTATION.
simple_form2->toolbar( )->title( `Social Media` ).

simple_form2->label( ).
simple_form2->link( text = `Follow abap2UI5 on Linkedin`
simple_form2->link( text = `Follow us on LinkedIn`
target = `_blank`
href = `https://www.linkedin.com/company/abap2ui5` ).

Expand Down
6 changes: 3 additions & 3 deletions src/02/z2ui5_cl_http_handler2.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CLASS z2ui5_cl_http_handler2 DEFINITION
CLASS-METHODS main
IMPORTING
body TYPE string
config TYPE z2ui5_if_types=>ty_s_http_request_get2 OPTIONAL
config TYPE z2ui5_if_types=>ty_s_config_index_html OPTIONAL
RETURNING
VALUE(result) TYPE string.

Expand All @@ -17,13 +17,13 @@ ENDCLASS.



CLASS Z2UI5_CL_HTTP_HANDLER2 IMPLEMENTATION.
CLASS z2ui5_cl_http_handler2 IMPLEMENTATION.

METHOD main.

IF body IS INITIAL.
DATA(lo_get) = NEW z2ui5_cl_core_http_get2( config ).
result = lo_get->main( ).
result = lo_get->main( ).
ELSE.
DATA(lo_post) = NEW z2ui5_cl_core_http_post( body ).
result = lo_post->main( ).
Expand Down
4 changes: 2 additions & 2 deletions src/02/z2ui5_if_types.intf.abap
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ INTERFACE z2ui5_if_types
END OF ty_s_http_request_get.

TYPES:
BEGIN OF ty_s_http_request_get2,
BEGIN OF ty_s_config_index_html,
t_option TYPE ty_t_name_value,
t_param TYPE ty_t_name_value,
add_js TYPE string,
END OF ty_s_http_request_get2.
END OF ty_s_config_index_html.

TYPES:
BEGIN OF ty_s_draft,
Expand Down

0 comments on commit 622c19c

Please sign in to comment.