Skip to content

Commit

Permalink
navigation with app state (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
oblomov-dev authored Dec 16, 2024
1 parent 91bb335 commit 648eaf9
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/z2ui5_cl_demo_app_320.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ CLASS z2ui5_cl_demo_app_320 DEFINITION
CREATE PUBLIC.

PUBLIC SECTION.
INTERFACES if_serializable_object.
INTERFACES z2ui5_if_app.

DATA check_initialized TYPE abap_bool.
Expand Down
79 changes: 79 additions & 0 deletions src/z2ui5_cl_demo_app_321.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
CLASS z2ui5_cl_demo_app_321 DEFINITION
PUBLIC FINAL
CREATE PUBLIC.

PUBLIC SECTION.
INTERFACES z2ui5_if_app.

DATA mv_product TYPE string.
DATA mv_quantity TYPE string.
DATA mv_search TYPE string.

DATA mt_search TYPE z2ui5_cl_util=>ty_t_name_value.
PROTECTED SECTION.


DATA client TYPE REF TO z2ui5_if_client.
METHODS state_handling
RETURNING
VALUE(result) TYPE abap_bool.

ENDCLASS.


CLASS z2ui5_cl_demo_app_321 IMPLEMENTATION.

METHOD z2ui5_if_app~main.
me->client = client.
IF state_handling( ).
RETURN.
ENDIF.

IF client->check_on_navigated( ).
DATA(view) = z2ui5_cl_xml_view=>factory( ).
view->_z2ui5( )->history( client->_bind( mv_search ) ).
client->view_display( val = view->shell(
)->page(
title = 'abap2UI5 - Navigation with app state'
navbuttonpress = client->_event( 'BACK' )
shownavbutton = client->check_app_prev_stack( )
)->simple_form( title = 'Form Title' editable = abap_true
)->content( 'form'
)->title( 'Input'
)->label( 'quantity'
)->input( client->_bind_edit( mv_quantity )
)->label( `product`
)->input( client->_bind_edit( mv_product )
)->button(
text = 'post'
press = client->_event( val = 'BUTTON_POST' )
)->stringify( ) ).
ENDIF.

client->message_toast_display( `data updated` ).
ENDMETHOD.


METHOD state_handling.

IF client->check_on_init( ).
"we check if an app state is already set, if yes leave to this state (draft)
TRY.
mt_search = z2ui5_cl_util=>url_param_get_tab( client->get( )-s_config-search ).
DATA(lv_id) = mt_search[ n = `z2ui5-xapp-state` ]-v.
client->nav_app_leave( client->get_app( lv_id ) ).
result = abap_true.
RETURN.
CATCH cx_root.
ENDTRY.
ENDIF.

"set the url parameter with the actual app state id (draft)
DELETE mt_search WHERE n = `z2ui5-xapp-state`.
INSERT VALUE #( n = `z2ui5-xapp-state` v = client->get( )-s_draft-id ) INTO TABLE mt_search.
mv_search = `?` && z2ui5_cl_util=>url_param_create_url( mt_search ).
client->view_model_update( ).

ENDMETHOD.

ENDCLASS.
16 changes: 16 additions & 0 deletions src/z2ui5_cl_demo_app_321.clas.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>Z2UI5_CL_DEMO_APP_321</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Navigation - app state</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

0 comments on commit 648eaf9

Please sign in to comment.