json creation (#269)

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* update

* update

* update

* update

* update
This commit is contained in:
oblomov 2023-06-14 13:27:54 +02:00
parent 84533639b6
commit b95f17bea1
4 changed files with 48 additions and 147 deletions

View File

@ -1,6 +1,6 @@
# abap2UI5 # abap2UI5
<img width="800" alt="image" src="https://github.com/oblomov-dev/abap2UI5/assets/102328295/6adde0de-fe8d-4a9b-8c1e-cf0316e1de8b"><br><br> ![bild](https://github.com/oblomov-dev/abap2UI5/assets/102328295/8cf3f160-2881-45b9-a38b-80abda0d8bb0)
Follow this project on [**twitter**](https://twitter.com/OblomovDev) to keep up to date and don't forget to explore the [**demo repository** :flashlight:](https://github.com/oblomov-dev/abap2UI5-demos) Follow this project on [**twitter** :sound:](https://twitter.com/OblomovDev) to keep up to date and don't forget to explore the [**demo repository** :flashlight:](https://github.com/oblomov-dev/abap2UI5-demos)
#### Features #### Features
* easy to use implement just one interface for a standalone UI5 application * easy to use implement just one interface for a standalone UI5 application
* pure ABAP development using 100% ABAP (no JavaScript, DDL, EML or Customizing) * pure ABAP development using 100% ABAP (no JavaScript, DDL, EML or Customizing)
@ -37,8 +37,8 @@ Follow this project on [**twitter**](https://twitter.com/OblomovDev) to keep up
* [work-in-progress] Launchpad integration with the following extension [(abap2UI5_ext-launchpad)](https://github.com/oblomov-dev/abap2UI5_ext-launchpad_app) * [work-in-progress] Launchpad integration with the following extension [(abap2UI5_ext-launchpad)](https://github.com/oblomov-dev/abap2UI5_ext-launchpad_app)
#### Installation #### Installation
Install with [abapGit](https://abapgit.org) ![abapGit](https://docs.abapgit.org/img/favicon.png), create a new HTTP service and replace the handler method with the following code snippet: Install with [abapGit](https://abapgit.org) ![abapGit](https://docs.abapgit.org/img/favicon.png), create a new HTTP service and replace the handler method with the following code:
##### Standard ABAP :computer: ##### Standard ABAP 🏠
```abap ```abap
METHOD if_http_extension~handle_request. METHOD if_http_extension~handle_request.
@ -62,7 +62,7 @@ METHOD if_http_extension~handle_request.
ENDMETHOD. ENDMETHOD.
``` ```
##### ABAP for Cloud :cloud: ##### ABAP for Cloud :cloud:
```abap ```abap
METHOD if_http_service_extension~handle_request. METHOD if_http_service_extension~handle_request.

View File

@ -622,7 +622,6 @@ CLASS z2ui5_lcl_utility_tree_json IMPLEMENTATION.
FIELD-SYMBOLS <attribute> TYPE any. FIELD-SYMBOLS <attribute> TYPE any.
DATA(lv_name) = c_prefix && replace( val = name sub = `-` with = `_` occ = 0 ). DATA(lv_name) = c_prefix && replace( val = name sub = `-` with = `_` occ = 0 ).
" DATA(lv_name) = c_prefix && replace( val = name sub = `-` with = `_` occ = 0 ).
ASSIGN (lv_name) TO <attribute>. ASSIGN (lv_name) TO <attribute>.
z2ui5_lcl_utility=>raise( when = xsdbool( sy-subrc <> 0 ) ). z2ui5_lcl_utility=>raise( when = xsdbool( sy-subrc <> 0 ) ).
@ -712,7 +711,6 @@ CLASS z2ui5_lcl_fw_handler DEFINITION.
id_prev TYPE string, id_prev TYPE string,
id_prev_app TYPE string, id_prev_app TYPE string,
id_prev_app_stack TYPE string, id_prev_app_stack TYPE string,
t_attri TYPE z2ui5_lcl_utility=>ty_t_attri, t_attri TYPE z2ui5_lcl_utility=>ty_t_attri,
o_app TYPE REF TO z2ui5_if_app, o_app TYPE REF TO z2ui5_if_app,
END OF ty_s_db. END OF ty_s_db.
@ -761,8 +759,6 @@ CLASS z2ui5_lcl_fw_handler DEFINITION.
RETURNING RETURNING
VALUE(result) TYPE REF TO z2ui5_lcl_fw_handler. VALUE(result) TYPE REF TO z2ui5_lcl_fw_handler.
METHODS set_app_leave METHODS set_app_leave
RETURNING RETURNING
VALUE(result) TYPE REF TO z2ui5_lcl_fw_handler. VALUE(result) TYPE REF TO z2ui5_lcl_fw_handler.
@ -781,7 +777,7 @@ CLASS z2ui5_lcl_fw_handler DEFINITION.
CLASS-METHODS bind_front_2_back CLASS-METHODS bind_front_2_back
IMPORTING IMPORTING
lo_model TYPE REF TO z2ui5_lcl_utility_tree_json lr_model TYPE REF TO data
lo_app TYPE REF TO object lo_app TYPE REF TO object
t_attri TYPE z2ui5_lcl_utility=>ty_t_attri ##NEEDED. t_attri TYPE z2ui5_lcl_utility=>ty_t_attri ##NEEDED.
@ -1254,11 +1250,16 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION.
ENDIF. ENDIF.
DATA(lo_resp) = z2ui5_lcl_utility_tree_json=>factory( ). DATA(lo_resp) = z2ui5_lcl_utility_tree_json=>factory( ).
DATA(lv_viewmodel) = COND #( WHEN ms_next-s_set-_viewmodel IS NOT INITIAL THEN ms_next-s_set-_viewmodel
ELSE bind_back_2_front( lo_app = ms_db-o_app t_attri = ms_db-t_attri ) ).
lo_resp->add_attribute( n = `OVIEWMODEL` v = lv_viewmodel apos_active = abap_false ).
CLEAR ms_next-s_set-_viewmodel.
lo_resp->add_attribute( n = `PARAMS` v = z2ui5_lcl_utility=>trans_any_2_json( ms_next-s_set ) apos_active = abap_false ). lo_resp->add_attribute( n = `PARAMS` v = z2ui5_lcl_utility=>trans_any_2_json( ms_next-s_set ) apos_active = abap_false ).
lo_resp->add_attribute( n = `S_MSG` v = z2ui5_lcl_utility=>trans_any_2_json( ms_next-s_msg ) apos_active = abap_false ). lo_resp->add_attribute( n = `S_MSG` v = z2ui5_lcl_utility=>trans_any_2_json( ms_next-s_msg ) apos_active = abap_false ).
lo_resp->add_attribute( n = `ID` v = ms_db-id ). lo_resp->add_attribute( n = `ID` v = ms_db-id ).
lo_resp->add_attribute( n = `OVIEWMODEL` v = bind_back_2_front( lo_app = ms_db-o_app t_attri = ms_db-t_attri ) apos_active = abap_false ).
result = lo_resp->get_root( )->stringify( ). result = lo_resp->get_root( )->stringify( ).
DELETE ms_db-t_attri WHERE bind_type = cs_bind_type-one_time. DELETE ms_db-t_attri WHERE bind_type = cs_bind_type-one_time.
@ -1269,30 +1270,31 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION.
METHOD bind_front_2_back. METHOD bind_front_2_back.
CONSTANTS c_prefix TYPE string VALUE `LO_APP->`. LOOP AT t_attri REFERENCE INTO DATA(lr_attri)
WHERE bind_type = cs_bind_type-two_way.
TRY.
FIELD-SYMBOLS <backend> TYPE any.
DATA(lv_name) = `LO_APP->` && lr_attri->name.
ASSIGN (lv_name) TO <backend>.
z2ui5_lcl_utility=>raise( when = xsdbool( sy-subrc <> 0 ) ).
TRY. FIELD-SYMBOLS <frontend> TYPE any.
lv_name = `LR_MODEL->` && replace( val = lr_attri->name sub = `-` with = `_` occ = 0 ).
LOOP AT t_attri REFERENCE INTO DATA(lr_attri) ASSIGN (lv_name) TO <frontend>.
WHERE bind_type = cs_bind_type-two_way.
FIELD-SYMBOLS <attribute> TYPE any.
DATA(lv_name) = c_prefix && to_upper( lr_attri->name ).
ASSIGN (lv_name) TO <attribute>.
z2ui5_lcl_utility=>raise( when = xsdbool( sy-subrc <> 0 ) ). z2ui5_lcl_utility=>raise( when = xsdbool( sy-subrc <> 0 ) ).
IF lr_attri->gen_kind IS NOT INITIAL. IF lr_attri->gen_kind IS NOT INITIAL.
CASE lr_attri->gen_kind. CASE lr_attri->gen_kind.
WHEN cl_abap_datadescr=>kind_elem. WHEN cl_abap_datadescr=>kind_elem.
CREATE DATA <attribute> TYPE (lr_attri->gen_type). CREATE DATA <backend> TYPE (lr_attri->gen_type).
ASSIGN <attribute>->* TO <attribute>. ASSIGN <backend>->* TO <backend>.
WHEN cl_abap_datadescr=>kind_table. WHEN cl_abap_datadescr=>kind_table.
DATA lr_data TYPE REF TO data. DATA lr_data TYPE REF TO data.
CREATE DATA lr_data TYPE (lr_attri->gen_type). CREATE DATA lr_data TYPE (lr_attri->gen_type).
ASSIGN lr_data->* TO FIELD-SYMBOL(<field>). ASSIGN lr_data->* TO FIELD-SYMBOL(<field>).
CREATE DATA <attribute> LIKE STANDARD TABLE OF <field>. CREATE DATA <backend> LIKE STANDARD TABLE OF <field>.
ASSIGN <attribute>->* TO <attribute>. ASSIGN <backend>->* TO <backend>.
ENDCASE. ENDCASE.
ENDIF. ENDIF.
@ -1300,30 +1302,27 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION.
WHEN `h`. WHEN `h`.
z2ui5_lcl_utility=>trans_ref_tab_2_tab( z2ui5_lcl_utility=>trans_ref_tab_2_tab(
EXPORTING ir_tab_from = lo_model->get_attribute( lr_attri->name )->mr_actual EXPORTING ir_tab_from = <frontend>
IMPORTING t_result = <attribute> ). IMPORTING t_result = <backend> ).
WHEN OTHERS. WHEN OTHERS.
DATA(lo_attri) = lo_model->get_attribute( lr_attri->name ). ASSIGN <frontend>->* TO <frontend>.
FIELD-SYMBOLS <val> TYPE any.
ASSIGN lo_attri->mr_actual->* TO <val>.
CASE lr_attri->type_kind. CASE lr_attri->type_kind.
WHEN 'D' OR 'T'. WHEN 'D' OR 'T'.
/ui2/cl_json=>deserialize( /ui2/cl_json=>deserialize(
EXPORTING EXPORTING
json = `"` && <val> && `"` json = `"` && <frontend> && `"`
CHANGING CHANGING
data = <attribute> ). data = <backend> ).
WHEN OTHERS. WHEN OTHERS.
<attribute> = <val>. <backend> = <frontend>.
ENDCASE. ENDCASE.
ENDCASE. ENDCASE.
ENDLOOP.
CATCH cx_root. CATCH cx_root.
ENDTRY. ENDTRY.
ENDLOOP.
ENDMETHOD. ENDMETHOD.
@ -1333,7 +1332,6 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION.
CONSTANTS c_prefix TYPE string VALUE `LO_APP->`. CONSTANTS c_prefix TYPE string VALUE `LO_APP->`.
DATA(r_view_model) = z2ui5_lcl_utility_tree_json=>factory( ). DATA(r_view_model) = z2ui5_lcl_utility_tree_json=>factory( ).
r_view_model->mv_name = `oViewModel`.
DATA(lo_update) = r_view_model->add_attribute_object( `oUpdate` ). DATA(lo_update) = r_view_model->add_attribute_object( `oUpdate` ).
LOOP AT t_attri REFERENCE INTO DATA(lr_attri) WHERE bind_type <> ``. LOOP AT t_attri REFERENCE INTO DATA(lr_attri) WHERE bind_type <> ``.
@ -1423,11 +1421,13 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION.
ENDTRY. ENDTRY.
bind_front_2_back( bind_front_2_back(
lo_model = mo_body->get_attribute( `OUPDATE` ) lr_model = mo_body->get_attribute( `OUPDATE` )->mr_actual
lo_app = result->ms_db-o_app lo_app = result->ms_db-o_app
t_attri = result->ms_db-t_attri t_attri = result->ms_db-t_attri
). ).
result->ms_actual-_viewmodel = mo_body->get_attribute( `OUPDATE` )->mr_actual.
ENDMETHOD. ENDMETHOD.
@ -1667,8 +1667,7 @@ CLASS z2ui5_lcl_fw_client IMPLEMENTATION.
event = mo_handler->ms_actual-event event = mo_handler->ms_actual-event
t_event_arg = mo_handler->ms_actual-t_event_arg t_event_arg = mo_handler->ms_actual-t_event_arg
t_scroll_pos = mo_handler->ms_actual-t_scroll_pos t_scroll_pos = mo_handler->ms_actual-t_scroll_pos
t_req_header = z2ui5_cl_http_handler=>client-t_header _viewmodel = mo_handler->ms_actual-_viewmodel
t_req_param = z2ui5_cl_http_handler=>client-t_param
). ).
ENDMETHOD. ENDMETHOD.
@ -1739,99 +1738,3 @@ CLASS z2ui5_lcl_fw_client IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
ENDCLASS. ENDCLASS.
CLASS z2ui5_lcl_fw_view DEFINITION.
PUBLIC SECTION.
CLASS-METHODS read_view
RETURNING
VALUE(result) TYPE string.
ENDCLASS.
CLASS z2ui5_lcl_fw_view IMPLEMENTATION.
METHOD read_view.
result = `<mvc:View ` && |\n| &&
` xmlns="sap.m" ` && |\n| &&
` xmlns:z2ui5="z2ui5" ` && |\n| &&
` xmlns:core="sap.ui.core" ` && |\n| &&
` xmlns:mvc="sap.ui.core.mvc" ` && |\n| &&
` xmlns:layout="sap.ui.layout" ` && |\n| &&
` xmlns:f="sap.f" ` && |\n| &&
` xmlns:form="sap.ui.layout.form" ` && |\n| &&
` xmlns:editor="sap.ui.codeeditor" ` && |\n| &&
` xmlns:mchart="sap.suite.ui.microchart" ` && |\n| &&
` xmlns:webc="sap.ui.webc.main" ` && |\n| &&
` xmlns:uxap="sap.uxap" ` && |\n| &&
` xmlns:sap="sap" ` && |\n| &&
` xmlns:text="sap.ui.richtextedito" ` && |\n| &&
` xmlns:html="http://www.w3.org/1999/xhtml" ` && |\n| &&
` displayBlock="true" ` && |\n| &&
` height="100%" ` && |\n| &&
` controllerName="z2ui5_controller" ` && |\n| &&
` > <Shell ` && |\n| &&
` > <Page ` && |\n| &&
` title="abap2UI5 - z2ui5_cl_app_hello_world" ` && |\n| &&
` > <form:SimpleForm ` && |\n| &&
` title="Hello World" ` && |\n| &&
` editable="true" ` && |\n| &&
` > <form:content ` && |\n| &&
` > <Title ` && |\n| &&
` text="Make an input here and send it to the server..." ` && |\n| &&
` /> <Label ` && |\n| &&
` text="quantity" ` && |\n| &&
` /> <Input ` && |\n| &&
` value="onEvent( {/oUpdate/QUANTITY} )` && |\n| &&
` /> <Label ` && |\n| &&
` text="product" ` && |\n| &&
` /> <Input ` && |\n| &&
` enabled="false" ` && |\n| &&
` value="{VALUE}" ` && |\n| &&
` /> <Button ` && |\n| &&
` press="onEvent( { &apos;EVENT&apos; : &apos;BUTTON_POST&apos;, &apos;METHOD&apos; : &apos;UPDATE&apos; , &apos;isHoldView&apos; : false })" ` && |\n| &&
` text="post" ` && |\n| &&
` /></form:content></form:SimpleForm></Page></Shell></mvc:View>`.
ENDMETHOD.
ENDCLASS.
CLASS z2ui5_lcl_fw_view_app DEFINITION.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
DATA quantity TYPE string VALUE `10` ##NEEDED.
ENDCLASS.
CLASS z2ui5_lcl_fw_view_app IMPLEMENTATION.
METHOD z2ui5_if_app~main.
DATA(lt_attri) = z2ui5_lcl_utility=>get_t_attri_by_ref( me ).
DATA(lv_view) = z2ui5_lcl_fw_view=>read_view( ).
SPLIT lv_view AT `{` INTO TABLE DATA(lt_view).
DELETE lt_view INDEX 1.
LOOP AT lt_view INTO DATA(lr_view).
SPLIT lr_view AT `}` INTO lr_view DATA(lv_dummy).
LOOP AT lt_attri REFERENCE INTO DATA(lr_attri).
IF lr_view = `/oUpdate/` && lr_attri->name.
lr_attri->bind_type = z2ui5_lcl_fw_handler=>cs_bind_type-two_way.
CONTINUE.
ENDIF.
IF lr_view = lr_attri->name.
lr_attri->bind_type = z2ui5_lcl_fw_handler=>cs_bind_type-one_way.
CONTINUE.
ENDIF.
ENDLOOP.
ENDLOOP.
client->set_next( VALUE #( xml_main = lv_view ) ).
ENDMETHOD.
ENDCLASS.

View File

@ -36,9 +36,9 @@ CLASS z2ui5_cl_xml_view DEFINITION
CLASS-METHODS hlp_get_source_code_url CLASS-METHODS hlp_get_source_code_url
IMPORTING IMPORTING
app TYPE REF TO z2ui5_if_app app TYPE REF TO z2ui5_if_app
get TYPE z2ui5_if_client=>ty_s_get get TYPE z2ui5_if_client=>ty_s_get
RETURNING RETURNING
VALUE(result) TYPE string. VALUE(result) TYPE string ##NEEDED.
CLASS-METHODS hlp_replace_controller_name CLASS-METHODS hlp_replace_controller_name
IMPORTING IMPORTING
@ -348,7 +348,6 @@ CLASS z2ui5_cl_xml_view DEFINITION
valuehelprequest TYPE clike OPTIONAL valuehelprequest TYPE clike OPTIONAL
class TYPE clike OPTIONAL class TYPE clike OPTIONAL
visible TYPE clike OPTIONAL visible TYPE clike OPTIONAL
submit TYPE clike OPTIONAL
PREFERRED PARAMETER value PREFERRED PARAMETER value
RETURNING RETURNING
VALUE(result) TYPE REF TO z2ui5_cl_xml_view. VALUE(result) TYPE REF TO z2ui5_cl_xml_view.
@ -1745,7 +1744,7 @@ CLASS Z2UI5_CL_XML_VIEW IMPLEMENTATION.
METHOD hlp_get_source_code_url. METHOD hlp_get_source_code_url.
DATA(lv_url) = get-t_req_header[ name = `referer` ]-value. DATA(lv_url) = z2ui5_cl_http_handler=>client-t_header[ name = `referer` ]-value.
SPLIT lv_url AT '?' INTO lv_url DATA(lv_dummy). SPLIT lv_url AT '?' INTO lv_url DATA(lv_dummy).
result = z2ui5_cl_http_handler=>client-t_header[ name = `origin` ]-value && `/sap/bc/adt/oo/classes/` && lcl_utility=>get_classname_by_ref( app ) && `/source/main`. result = z2ui5_cl_http_handler=>client-t_header[ name = `origin` ]-value && `/sap/bc/adt/oo/classes/` && lcl_utility=>get_classname_by_ref( app ) && `/source/main`.
@ -1820,7 +1819,6 @@ CLASS Z2UI5_CL_XML_VIEW IMPLEMENTATION.
( n = `valueHelpRequest` v = valuehelprequest ) ( n = `valueHelpRequest` v = valuehelprequest )
( n = `showValueHelp` v = lcl_utility=>get_json_boolean( showvaluehelp ) ) ( n = `showValueHelp` v = lcl_utility=>get_json_boolean( showvaluehelp ) )
( n = `class` v = class ) ( n = `class` v = class )
( n = `submit` v = submit )
) ). ) ).
ENDMETHOD. ENDMETHOD.

View File

@ -17,8 +17,7 @@ INTERFACE z2ui5_if_client
id_prev_app TYPE string, id_prev_app TYPE string,
id_prev_app_stack TYPE string, id_prev_app_stack TYPE string,
t_scroll_pos TYPE ty_t_name_value, t_scroll_pos TYPE ty_t_name_value,
t_req_param TYPE ty_t_name_value, _viewmodel TYPE REF TO data,
t_req_header TYPE ty_t_name_value,
END OF ty_s_get. END OF ty_s_get.
TYPES: TYPES:
@ -39,6 +38,7 @@ INTERFACE z2ui5_if_client
interval_ms TYPE string, interval_ms TYPE string,
event_finished TYPE string, event_finished TYPE string,
END OF s_timer, END OF s_timer,
_viewmodel TYPE string,
END OF ty_s_next. END OF ty_s_next.
METHODS set_next METHODS set_next
@ -91,9 +91,9 @@ INTERFACE z2ui5_if_client
METHODS _event METHODS _event
IMPORTING IMPORTING
val TYPE clike val TYPE clike
hold_view TYPE abap_bool DEFAULT abap_false hold_view TYPE abap_bool DEFAULT abap_false
t_arg TYPE string_table OPTIONAL t_arg TYPE string_table OPTIONAL
RETURNING RETURNING
VALUE(result) TYPE string. VALUE(result) TYPE string.