mirror of
https://github.com/abap2UI5/abap2UI5.git
synced 2025-04-30 04:36:18 +08:00
session-stickyness (#1435)
* Added Component and Session Stateful (#1433) - Added Component support (TODO refactoring sap.z2ui5 and view handling -> instead of .placeAt use mainView of component manifest) - Added Session Stateful support *add the following lines to your REST handler in order to support stateful session handling* '''abap if attributes-stateful-switched = abap_true. server->set_session_stateful( stateful = attributes-stateful-active ). endif. ''' And here is an ABAP example class for testing session handling '''abap "! <p class="shorttext synchronized" lang="en">Session Demo</p> class z2ui5_cl_demo_app_session definition public create public. public section. interfaces z2ui5_if_app. data instance_counter type i read-only. data check_initialized type abap_bool read-only. data session_is_stateful type abap_bool read-only. data session_text type string read-only. protected section. private section. methods initialize_view importing client type ref to z2ui5_if_client. methods on_event importing client type ref to z2ui5_if_client. methods set_session_stateful importing client type ref to z2ui5_if_client stateful type abap_bool. endclass. class z2ui5_cl_demo_app_session implementation. method z2ui5_if_app~main. if check_initialized = abap_false. check_initialized = abap_true. initialize_view( client ). endif. on_event( client ). endmethod. method initialize_view. set_session_stateful( client = client stateful = abap_true ). data(view) = z2ui5_cl_xml_view=>factory( ). data(page) = view->shell( )->page( title = `abap2UI5 - Sample: Sticky Session` navbuttonpress = client->_event( 'BACK' ) shownavbutton = xsdbool( client->get( )-s_draft-id_prev_app_stack is not initial ) ). data(vbox) = page->vbox( ). vbox->info_label( text = client->_bind( session_text ) ). data(hbox) = vbox->hbox( alignitems = 'Center' ). hbox->label( text = 'press button to increment counter in backend session' class = 'sapUiTinyMarginEnd' ). hbox->button( text = client->_bind( instance_counter ) press = client->_event( 'INCREMENT' ) type = 'Emphasized' ). hbox = vbox->hbox( ). hbox->button( text = 'End session' press = client->_event( 'END_SESSION' ) ). hbox->button( text = 'Start session again' press = client->_event( 'START_SESSION' ) ). client->view_display( view->stringify( ) ). endmethod. method on_event. case client->get( )-event. when 'BACK'. client->nav_app_leave( ). when 'INCREMENT'. instance_counter = lcl_static_container=>increment( ). client->view_model_update( ). when 'END_SESSION'. set_session_stateful( client = client stateful = abap_false ). when 'START_SESSION'. set_session_stateful( client = client stateful = abap_true ). endcase. endmethod. method set_session_stateful. client->set_session_stateful( stateful ). session_is_stateful = stateful. if stateful = abap_true. session_text = 'Session ON (stateful)'. else. session_text = 'Session OFF (stateless)'. endif. client->view_model_update( ). endmethod. endclass. ''' * Update z2ui5_cl_core_http_get.clas.abap (#1434) updated to reflect latest changes (sorry some local changes were los) * lint fix * lint fix * xml fix --------- Co-authored-by: Michael Zinnöcker <29286643+mzinnoecker@users.noreply.github.com>
This commit is contained in:
parent
1e929668b0
commit
1fba55457c
|
@ -186,7 +186,7 @@
|
||||||
"severity": "Error"
|
"severity": "Error"
|
||||||
},
|
},
|
||||||
"method_parameter_names": false,
|
"method_parameter_names": false,
|
||||||
"mix_returning": true,
|
"mix_returning": false,
|
||||||
"modify_only_own_db_tables": {
|
"modify_only_own_db_tables": {
|
||||||
"reportDynamic": true,
|
"reportDynamic": true,
|
||||||
"ownTables": "^[yz]"
|
"ownTables": "^[yz]"
|
||||||
|
|
|
@ -341,4 +341,14 @@ CLASS z2ui5_cl_core_client IMPLEMENTATION.
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
|
||||||
|
METHOD z2ui5_if_client~set_session_stateful.
|
||||||
|
|
||||||
|
IF stateful = abap_true.
|
||||||
|
mo_action->ms_next-s_set-handler_attrs-stateful-active = 1.
|
||||||
|
ELSE.
|
||||||
|
mo_action->ms_next-s_set-handler_attrs-stateful-active = 0.
|
||||||
|
ENDIF.
|
||||||
|
mo_action->ms_next-s_set-handler_attrs-stateful-switched = abap_true.
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|
|
@ -40,6 +40,9 @@ CLASS z2ui5_cl_core_http_get DEFINITION
|
||||||
cs_config TYPE z2ui5_if_types=>ty_s_http_request_get
|
cs_config TYPE z2ui5_if_types=>ty_s_http_request_get
|
||||||
RETURNING VALUE(result) TYPE string.
|
RETURNING VALUE(result) TYPE string.
|
||||||
|
|
||||||
|
METHODS main_get_component_script
|
||||||
|
RETURNING
|
||||||
|
VALUE(result) TYPE string.
|
||||||
|
|
||||||
PRIVATE SECTION.
|
PRIVATE SECTION.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
@ -84,7 +87,9 @@ CLASS z2ui5_cl_core_http_get IMPLEMENTATION.
|
||||||
( n = `id` v = `sap-ui-bootstrap` )
|
( n = `id` v = `sap-ui-bootstrap` )
|
||||||
( n = `data-sap-ui-bindingSyntax` v = `complex` )
|
( n = `data-sap-ui-bindingSyntax` v = `complex` )
|
||||||
( n = `data-sap-ui-frameOptions` v = `trusted` )
|
( n = `data-sap-ui-frameOptions` v = `trusted` )
|
||||||
( n = `data-sap-ui-compatVersion` v = `edge` ) )
|
( n = `data-sap-ui-compatVersion` v = `edge` )
|
||||||
|
( n = `data-sap-ui-resourceroots` v = `{"z2ui5": "./"}` )
|
||||||
|
( n = `data-sap-ui-oninit` v = `onInitComponent` ) )
|
||||||
content_security_policy = lv_csp ).
|
content_security_policy = lv_csp ).
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
@ -153,6 +158,7 @@ CLASS z2ui5_cl_core_http_get IMPLEMENTATION.
|
||||||
` <meta http-equiv="X-UA-Compatible" content="IE=edge">` && |\n| &&
|
` <meta http-equiv="X-UA-Compatible" content="IE=edge">` && |\n| &&
|
||||||
| <title>{ cs_config-t_param[ n = `TITLE` ]-v }</title> \n| &&
|
| <title>{ cs_config-t_param[ n = `TITLE` ]-v }</title> \n| &&
|
||||||
| <style>{ cs_config-t_param[ n = `STYLE` ]-v }</style> \n| &&
|
| <style>{ cs_config-t_param[ n = `STYLE` ]-v }</style> \n| &&
|
||||||
|
main_get_component_script( ) && |\n| &&
|
||||||
` <script id="sap-ui-bootstrap"`.
|
` <script id="sap-ui-bootstrap"`.
|
||||||
|
|
||||||
LOOP AT cs_config-t_config REFERENCE INTO DATA(lr_config).
|
LOOP AT cs_config-t_config REFERENCE INTO DATA(lr_config).
|
||||||
|
@ -161,8 +167,8 @@ CLASS z2ui5_cl_core_http_get IMPLEMENTATION.
|
||||||
|
|
||||||
result = result &&
|
result = result &&
|
||||||
` ></script></head>` && |\n| &&
|
` ></script></head>` && |\n| &&
|
||||||
`<body class="sapUiBody sapUiSizeCompact" >` && |\n| &&
|
`<body class="sapUiBody sapUiSizeCompact" id="content">` && |\n| &&
|
||||||
` <div id="content" data-handle-validation="true" ></div>` && |\n| &&
|
` <div data-sap-ui-component data-name="z2ui5" id="content_container" data-id="container" data-handle-validation="true" data-settings=''{"id" : "z2ui5"}''></div>` && |\n| &&
|
||||||
`<abc/>` && |\n|.
|
`<abc/>` && |\n|.
|
||||||
|
|
||||||
DATA(lv_add_js) = get_js_cc_startup( ) && cs_config-custom_js.
|
DATA(lv_add_js) = get_js_cc_startup( ) && cs_config-custom_js.
|
||||||
|
@ -603,7 +609,7 @@ CLASS z2ui5_cl_core_http_get IMPLEMENTATION.
|
||||||
` sap.z2ui5.oParent.removeAllPages();` && |\n| &&
|
` sap.z2ui5.oParent.removeAllPages();` && |\n| &&
|
||||||
` sap.z2ui5.oParent.insertPage(sap.z2ui5.oView);` && |\n| &&
|
` sap.z2ui5.oParent.insertPage(sap.z2ui5.oView);` && |\n| &&
|
||||||
` } else {` && |\n| &&
|
` } else {` && |\n| &&
|
||||||
` sap.z2ui5.oView.placeAt("content");` && |\n| &&
|
` sap.z2ui5.oView.placeAt("container-uiarea");` && |\n| &&
|
||||||
` }` && |\n| &&
|
` }` && |\n| &&
|
||||||
` },` && |\n| &&
|
` },` && |\n| &&
|
||||||
` async readHttp() {` && |\n| &&
|
` async readHttp() {` && |\n| &&
|
||||||
|
@ -680,5 +686,40 @@ CLASS z2ui5_cl_core_http_get IMPLEMENTATION.
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD main_get_component_script.
|
||||||
|
result = `<script>` && |\n| &&
|
||||||
|
` function onInitComponent(){` && |\n| &&
|
||||||
|
` sap.ui.require.preload({` && |\n| &&
|
||||||
|
` "z2ui5/manifest.json": '{}', //todo define json` && |\n| &&
|
||||||
|
` "z2ui5/Component.js": function(){` && |\n| &&
|
||||||
|
` sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){` && |\n| &&
|
||||||
|
` return UIComponent.extend("z2ui5.Component", {` && |\n| &&
|
||||||
|
` metadata: { manifest: "json" },` && |\n| &&
|
||||||
|
` init: function(){` && |\n| &&
|
||||||
|
` UIComponent.prototype.init.apply(this, arguments);` && |\n| &&
|
||||||
|
` },` && |\n| &&
|
||||||
|
` destroy: function(){` && |\n| &&
|
||||||
|
` const sContextId = document.cookie.match(new RegExp("(^| )sap-contextid=([^;]+)"))?.at(2);` && |\n| &&
|
||||||
|
` if(sContextId){` && |\n| &&
|
||||||
|
` fetch(sap.z2ui5.pathname, {` && |\n| &&
|
||||||
|
` method: 'HEAD',` && |\n| &&
|
||||||
|
` headers: {` && |\n| &&
|
||||||
|
` 'sap-terminate': 'session',` && |\n| &&
|
||||||
|
` 'sap-contextid': sContextId,` && |\n| &&
|
||||||
|
` 'sap-contextid-accept': 'header'` && |\n| &&
|
||||||
|
` }` && |\n| &&
|
||||||
|
` });` && |\n| &&
|
||||||
|
` }` && |\n| &&
|
||||||
|
` UIComponent.prototype.destroy.apply(this, arguments);` && |\n| &&
|
||||||
|
` },` && |\n| &&
|
||||||
|
` });` && |\n| &&
|
||||||
|
` });` && |\n| &&
|
||||||
|
` }` && |\n| &&
|
||||||
|
` });` && |\n| &&
|
||||||
|
` sap.ui.require(["sap/ui/core/ComponentSupport"], function(ComponentSupport){` && |\n| &&
|
||||||
|
` ComponentSupport.run();` && |\n| &&
|
||||||
|
` });` && |\n| &&
|
||||||
|
` }` && |\n| &&
|
||||||
|
`</script>`.
|
||||||
|
ENDMETHOD.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|
|
@ -16,6 +16,8 @@ CLASS z2ui5_cl_core_http_post DEFINITION
|
||||||
val TYPE string.
|
val TYPE string.
|
||||||
|
|
||||||
METHODS main
|
METHODS main
|
||||||
|
EXPORTING
|
||||||
|
attributes TYPE z2ui5_if_types=>ty_s_http_handler_attributes
|
||||||
RETURNING
|
RETURNING
|
||||||
VALUE(result) TYPE string.
|
VALUE(result) TYPE string.
|
||||||
|
|
||||||
|
@ -46,6 +48,7 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION.
|
||||||
|
|
||||||
|
|
||||||
METHOD main.
|
METHOD main.
|
||||||
|
CLEAR attributes.
|
||||||
|
|
||||||
main_begin( ).
|
main_begin( ).
|
||||||
DO.
|
DO.
|
||||||
|
@ -54,6 +57,7 @@ CLASS z2ui5_cl_core_http_post IMPLEMENTATION.
|
||||||
ENDIF.
|
ENDIF.
|
||||||
ENDDO.
|
ENDDO.
|
||||||
result = mv_response.
|
result = mv_response.
|
||||||
|
attributes = ms_response-s_front-params-handler_attrs.
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@ INTERFACE z2ui5_if_core_types
|
||||||
BEGIN OF s_follow_up_action,
|
BEGIN OF s_follow_up_action,
|
||||||
custom_js TYPE string,
|
custom_js TYPE string,
|
||||||
END OF s_follow_up_action,
|
END OF s_follow_up_action,
|
||||||
|
handler_attrs TYPE z2ui5_if_types=>ty_s_http_handler_attributes,
|
||||||
END OF ty_s_next_frontend.
|
END OF ty_s_next_frontend.
|
||||||
|
|
||||||
TYPES:
|
TYPES:
|
||||||
|
|
|
@ -8,12 +8,16 @@ CLASS z2ui5_cl_http_handler DEFINITION
|
||||||
IMPORTING
|
IMPORTING
|
||||||
body TYPE string
|
body TYPE string
|
||||||
config TYPE z2ui5_if_types=>ty_s_http_request_get OPTIONAL
|
config TYPE z2ui5_if_types=>ty_s_http_request_get OPTIONAL
|
||||||
|
EXPORTING
|
||||||
|
attributes TYPE z2ui5_if_types=>ty_s_http_handler_attributes
|
||||||
RETURNING
|
RETURNING
|
||||||
VALUE(result) TYPE string.
|
VALUE(result) TYPE string.
|
||||||
|
|
||||||
CLASS-METHODS http_post
|
CLASS-METHODS http_post
|
||||||
IMPORTING
|
IMPORTING
|
||||||
val TYPE string
|
val TYPE string
|
||||||
|
EXPORTING
|
||||||
|
attributes TYPE z2ui5_if_types=>ty_s_http_handler_attributes
|
||||||
RETURNING
|
RETURNING
|
||||||
VALUE(result) TYPE string.
|
VALUE(result) TYPE string.
|
||||||
|
|
||||||
|
@ -41,20 +45,26 @@ CLASS z2ui5_cl_http_handler IMPLEMENTATION.
|
||||||
|
|
||||||
|
|
||||||
METHOD http_post.
|
METHOD http_post.
|
||||||
|
CLEAR attributes.
|
||||||
|
|
||||||
DATA(lo_post) = NEW z2ui5_cl_core_http_post( val ).
|
DATA(lo_post) = NEW z2ui5_cl_core_http_post( val ).
|
||||||
result = lo_post->main( ).
|
result = lo_post->main(
|
||||||
|
IMPORTING
|
||||||
|
attributes = attributes ).
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
METHOD main.
|
METHOD main.
|
||||||
|
CLEAR attributes.
|
||||||
|
|
||||||
IF body IS INITIAL.
|
IF body IS INITIAL.
|
||||||
DATA(lo_get) = NEW z2ui5_cl_core_http_get( config ).
|
DATA(lo_get) = NEW z2ui5_cl_core_http_get( config ).
|
||||||
result = lo_get->main( ).
|
result = lo_get->main( ).
|
||||||
ELSE.
|
ELSE.
|
||||||
DATA(lo_post) = NEW z2ui5_cl_core_http_post( body ).
|
DATA(lo_post) = NEW z2ui5_cl_core_http_post( body ).
|
||||||
result = lo_post->main( ).
|
result = lo_post->main(
|
||||||
|
IMPORTING
|
||||||
|
attributes = attributes ).
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
|
@ -9732,6 +9732,7 @@ CLASS z2ui5_cl_xml_view IMPLEMENTATION.
|
||||||
( n = `sap` v = `sap` )
|
( n = `sap` v = `sap` )
|
||||||
( n = `text` v = `sap.ui.richtexteditor` )
|
( n = `text` v = `sap.ui.richtexteditor` )
|
||||||
( n = `html` v = `http://www.w3.org/1999/xhtml` )
|
( n = `html` v = `http://www.w3.org/1999/xhtml` )
|
||||||
|
* ( n = `unified` v = `sap.ui.unified` )
|
||||||
( n = `fb` v = `sap.ui.comp.filterbar` )
|
( n = `fb` v = `sap.ui.comp.filterbar` )
|
||||||
( n = `u` v = `sap.ui.unified` )
|
( n = `u` v = `sap.ui.unified` )
|
||||||
( n = `gantt` v = `sap.gantt.simple` )
|
( n = `gantt` v = `sap.gantt.simple` )
|
||||||
|
@ -10031,7 +10032,7 @@ CLASS z2ui5_cl_xml_view IMPLEMENTATION.
|
||||||
METHOD color_picker.
|
METHOD color_picker.
|
||||||
|
|
||||||
result = me.
|
result = me.
|
||||||
_generic( ns = `unified`
|
_generic( ns = `u`
|
||||||
name = `ColorPicker`
|
name = `ColorPicker`
|
||||||
t_prop = VALUE #( ( n = `colorString` v = colorstring )
|
t_prop = VALUE #( ( n = `colorString` v = colorstring )
|
||||||
( n = `displayMode` v = displaymode )
|
( n = `displayMode` v = displaymode )
|
||||||
|
|
|
@ -32,6 +32,10 @@ INTERFACE z2ui5_if_client
|
||||||
|
|
||||||
METHODS view_model_update.
|
METHODS view_model_update.
|
||||||
|
|
||||||
|
METHODS set_session_stateful
|
||||||
|
IMPORTING
|
||||||
|
stateful TYPE abap_bool DEFAULT abap_true.
|
||||||
|
|
||||||
METHODS nest_view_display
|
METHODS nest_view_display
|
||||||
IMPORTING
|
IMPORTING
|
||||||
val TYPE clike
|
val TYPE clike
|
||||||
|
|
|
@ -16,6 +16,14 @@ INTERFACE z2ui5_if_types
|
||||||
t_param TYPE ty_t_name_value,
|
t_param TYPE ty_t_name_value,
|
||||||
END OF ty_s_http_request_get.
|
END OF ty_s_http_request_get.
|
||||||
|
|
||||||
|
TYPES:
|
||||||
|
BEGIN OF ty_s_http_handler_attributes,
|
||||||
|
BEGIN OF stateful,
|
||||||
|
active TYPE i,
|
||||||
|
switched TYPE abap_bool,
|
||||||
|
END OF stateful,
|
||||||
|
END OF ty_s_http_handler_attributes.
|
||||||
|
|
||||||
TYPES:
|
TYPES:
|
||||||
BEGIN OF ty_s_draft,
|
BEGIN OF ty_s_draft,
|
||||||
id TYPE string,
|
id TYPE string,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user