Skip to content

Instantly share code, notes, and snippets.

@mbtools
Last active October 24, 2023 20:04
Show Gist options
  • Save mbtools/26989c0f8a18797e41d20facae6f4fc7 to your computer and use it in GitHub Desktop.
Save mbtools/26989c0f8a18797e41d20facae6f4fc7 to your computer and use it in GitHub Desktop.
ZTEST_ABAPGIT_HTML_VIEWER
REPORT ztest_abapgit_html_viewer.
SELECTION-SCREEN BEGIN OF SCREEN 1001.
* dummy for triggering screen
SELECTION-SCREEN END OF SCREEN 1001.
CLASS lcl_gui DEFINITION.
PUBLIC SECTION.
METHODS on_event
FOR EVENT sapevent OF zif_abapgit_html_viewer
IMPORTING
!action
!frame
!getdata
!postdata
!query_table .
METHODS startup
RAISING
zcx_abapgit_exception .
METHODS cache_html
IMPORTING
iv_text TYPE string
RETURNING
VALUE(rv_url) TYPE string
RAISING
zcx_abapgit_exception .
METHODS show_url
IMPORTING
iv_url TYPE string
RAISING
zcx_abapgit_exception .
METHODS render_page_1
RAISING
zcx_abapgit_exception .
METHODS render_page_2
RAISING
zcx_abapgit_exception .
METHODS handle_action
IMPORTING
!iv_action TYPE c
!iv_getdata TYPE c OPTIONAL
!it_postdata TYPE cnht_post_data_tab OPTIONAL.
METHODS back
RETURNING
VALUE(rv_exit) TYPE abap_bool
RAISING
zcx_abapgit_exception .
METHODS free
RAISING
zcx_abapgit_exception .
DATA mi_html_viewer TYPE REF TO zif_abapgit_html_viewer.
DATA mv_page TYPE i.
ENDCLASS.
CLASS lcl_gui IMPLEMENTATION.
METHOD startup.
DATA:
lt_events TYPE cntl_simple_events,
ls_event LIKE LINE OF lt_events.
mi_html_viewer = zcl_abapgit_ui_factory=>get_html_viewer( ).
ls_event-eventid = mi_html_viewer->c_id_sapevent.
ls_event-appl_event = abap_true.
APPEND ls_event TO lt_events.
mi_html_viewer->set_registered_events( lt_events ).
SET HANDLER on_event FOR mi_html_viewer.
ENDMETHOD.
METHOD cache_html.
DATA:
lv_size TYPE i,
lt_html TYPE w3htmltab.
zcl_abapgit_convert=>string_to_tab(
EXPORTING
iv_str = iv_text
IMPORTING
ev_size = lv_size
et_tab = lt_html ).
mi_html_viewer->load_data(
EXPORTING
iv_type = 'text'
iv_subtype = 'html'
iv_size = lv_size
IMPORTING
ev_assigned_url = rv_url
CHANGING
ct_data_table = lt_html ).
ENDMETHOD.
METHOD show_url.
mi_html_viewer->show_url( iv_url ).
ENDMETHOD.
METHOD render_page_1.
DATA:
lv_url TYPE string,
lv_html TYPE string.
mv_page = 1.
lv_html =
'<html><head></head><body><h1>Page 1: Click for Page 2</h1>' &&
'<form method="post" id="form"><input type="submit" value="Forward" formaction="sapevent:go-forward"></form>' &&
'</body></html>'.
lv_url = cache_html( lv_html ).
show_url( lv_url ).
ENDMETHOD.
METHOD render_page_2.
DATA:
lv_url TYPE string,
lv_html TYPE string.
mv_page = 2.
lv_html =
'<html><head></head><body><h1>Page 2: Click Back</h1>' &&
'<form method="post" id="form"><input type="submit" value="Back" formaction="sapevent:go-back"></form>' &&
'</body></html>'.
lv_url = cache_html( lv_html ).
show_url( lv_url ).
ENDMETHOD.
METHOD on_event.
handle_action(
iv_action = action
iv_getdata = getdata
it_postdata = postdata ).
ENDMETHOD.
METHOD handle_action.
TRY.
IF iv_action = 'go-forward'.
render_page_2( ).
ELSEIF iv_action = 'go-back'.
back( ).
ELSE.
BREAK-POINT.
ENDIF.
CATCH cx_root.
BREAK-POINT.
ENDTRY.
ENDMETHOD.
METHOD back.
IF mv_page = 2.
render_page_1( ).
ELSE.
rv_exit = abap_true.
ENDIF.
ENDMETHOD.
METHOD free.
SET HANDLER on_event FOR mi_html_viewer ACTIVATION space.
mi_html_viewer->close_document( ).
mi_html_viewer->free( ).
FREE mi_html_viewer.
ENDMETHOD.
ENDCLASS.
DATA go_gui TYPE REF TO lcl_gui.
AT SELECTION-SCREEN ON EXIT-COMMAND.
CASE sy-ucomm.
WHEN 'CBAC' OR 'CCAN'. "Back & Escape
IF go_gui->back( ) = abap_true.
go_gui->free( ).
ELSE.
LEAVE TO SCREEN 1001.
ENDIF.
ENDCASE.
START-OF-SELECTION.
CREATE OBJECT go_gui.
go_gui->startup( ).
go_gui->render_page_1( ).
CALL SELECTION-SCREEN 1001.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment