Skip to content

added storage demo #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/z2ui5_cl_demo_app_000.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ CLASS z2ui5_cl_demo_app_000 IMPLEMENTATION.
class = 'sapUiTinyMarginEnd sapUiTinyMarginBottom'
).

panel->generic_tile( header = 'Local/Session Storage'
subheader = 'Store data inside localStorage or sessionStorage'
press = client->_event( 'z2ui5_cl_demo_app_327' )
mode = 'LineMode'
class = 'sapUiTinyMarginEnd sapUiTinyMarginBottom'
).


panel = page->panel( expandable = abap_false
expanded = abap_true
headertext = `Messages`
Expand Down
102 changes: 102 additions & 0 deletions src/z2ui5_cl_demo_app_327.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
CLASS z2ui5_cl_demo_app_327 DEFINITION
PUBLIC FINAL
CREATE PUBLIC.

PUBLIC SECTION.
INTERFACES z2ui5_if_app.

TYPES: BEGIN OF ty_value,
field1 TYPE i,
field2 TYPE string,
END OF ty_value.

TYPES: BEGIN OF ty_storage,
type TYPE string,
prefix TYPE string,
key TYPE string,
value TYPE string,
* value TYPE ty_value,
END OF ty_storage.

TYPES: BEGIN OF ty_storage_type,
type TYPE string,
END OF ty_storage_type.

DATA storage TYPE ty_storage.
DATA stored_value TYPE string.
DATA storage_types TYPE STANDARD TABLE OF ty_storage_type.

ENDCLASS.


CLASS z2ui5_cl_demo_app_327 IMPLEMENTATION.
METHOD z2ui5_if_app~main.
IF client->check_on_init( ).

storage_types = VALUE #( ( type = `local` )
( type = `session` ) ).
storage = VALUE #( type = `local`
prefix = `prefix1`
key = 'key1'
* value = VALUE #( field1 = 1
* field2 = 'textfld1' )
).

DATA(view) = z2ui5_cl_xml_view=>factory( ).

view->shell(
)->page( title = 'abap2UI5 - Storage'
navbuttonpress = client->_event( val = 'BACK' )
shownavbutton = xsdbool( client->get( )-s_draft-id_prev_app_stack IS NOT INITIAL )

)->simple_form( title = 'Local/Session Storage'
editable = abap_true
)->content( 'form'
)->label( 'Type'
)->select( forceselection = abap_true
selectedkey = client->_bind_edit( storage-type )
items = client->_bind( storage_types )
)->item( key = '{TYPE}'
text = '{TYPE}'
)->get_parent(
)->label( 'Prefix'
)->input( client->_bind_edit( storage-prefix )
)->label( 'Key'
)->input( client->_bind_edit( storage-key )
)->label( 'Value'
)->input( client->_bind_edit( storage-value )
)->button( text = 'store'
press = client->_event_client( val = z2ui5_if_client=>cs_event-store_data
t_arg = VALUE #( ( |${ client->_bind_edit( storage ) }| ) ) )

)->button( text = 'get'
press = client->_event( 'GET_STORED_VALUE' )
)->get_parent(
)->get_parent(

)->_z2ui5( )->storage(
finished = client->_event(
val = `LOCAL_STORAGE_LOADED`
t_arg = VALUE #( ( `${$parameters>/type}` ) ( `${$parameters>/prefix}` ) ( `${$parameters>/key}` ) ( `${$parameters>/value}` ) ) )
type = client->_bind_edit( storage-type )
prefix = client->_bind_edit( storage-prefix )
key = client->_bind_edit( storage-key )
value = client->_bind_edit( stored_value ) ).
client->view_display( view->stringify( ) ).

ENDIF.

CASE client->get( )-event.
WHEN 'LOCAL_STORAGE_LOADED'.
* z2ui5_cl_ajson=>parse( client->get_event_arg( 4 ) )->to_abap( IMPORTING ev_container = storage-value ).
storage-value = client->get_event_arg( 4 ).
client->view_model_update( ).
WHEN 'GET_STORED_VALUE'.
* z2ui5_cl_ajson=>parse( stored_value )->to_abap( IMPORTING ev_container = storage-value ).
storage-value = stored_value.
client->view_model_update( ).
WHEN 'BACK'.
client->nav_app_leave( client->get_app( client->get( )-s_draft-id_prev_app_stack ) ).
ENDCASE.
ENDMETHOD.
ENDCLASS.
16 changes: 16 additions & 0 deletions src/z2ui5_cl_demo_app_327.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_327</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Store data inside localStorage or sessionStorage</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>