CLASS zcl_abapgit_gui_chunk_lib DEFINITION PUBLIC FINAL CREATE PUBLIC. PUBLIC SECTION. CLASS-METHODS render_error IMPORTING ix_error TYPE REF TO zcx_abapgit_exception OPTIONAL iv_error TYPE string OPTIONAL RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html. CLASS-METHODS render_repo_top IMPORTING io_repo TYPE REF TO zcl_abapgit_repo iv_show_package TYPE abap_bool DEFAULT abap_true iv_show_branch TYPE abap_bool DEFAULT abap_true iv_interactive_branch TYPE abap_bool DEFAULT abap_false iv_branch TYPE string OPTIONAL io_news TYPE REF TO zcl_abapgit_news OPTIONAL RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html RAISING zcx_abapgit_exception. CLASS-METHODS render_item_state IMPORTING iv1 TYPE char1 iv2 TYPE char1 RETURNING VALUE(rv_html) TYPE string. CLASS-METHODS render_branch_span IMPORTING iv_branch TYPE string io_repo TYPE REF TO zcl_abapgit_repo_online iv_interactive TYPE abap_bool RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html RAISING zcx_abapgit_exception. CLASS-METHODS render_js_error_banner RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html RAISING zcx_abapgit_exception. CLASS-METHODS render_news IMPORTING io_news TYPE REF TO zcl_abapgit_news RETURNING VALUE(ro_html) TYPE REF TO zcl_abapgit_html RAISING zcx_abapgit_exception. ENDCLASS. CLASS ZCL_ABAPGIT_GUI_CHUNK_LIB IMPLEMENTATION. METHOD render_branch_span. DATA: lv_text TYPE string, lv_class TYPE string. lv_text = zcl_abapgit_git_branch_list=>get_display_name( iv_branch ). IF iv_branch = io_repo->get_head_branch_name( ) OR iv_branch = zif_abapgit_definitions=>c_head_name. lv_class = 'branch branch_head'. ELSEIF zcl_abapgit_git_branch_list=>get_type( iv_branch ) = zif_abapgit_definitions=>c_git_branch_type-branch. lv_class = 'branch branch_branch'. ELSE. lv_class = 'branch'. ENDIF. CREATE OBJECT ro_html. ro_html->add( || ). ro_html->add_icon( iv_name = 'git-branch/darkgrey' iv_hint = 'Current branch' ). IF iv_interactive = abap_true. ro_html->add_a( iv_act = |{ zif_abapgit_definitions=>gc_action-git_branch_switch }?{ io_repo->get_key( ) }| iv_txt = lv_text ). ELSE. ro_html->add( lv_text ). ENDIF. ro_html->add( '' ). ENDMETHOD. "render_branch_span METHOD render_error. DATA lv_error TYPE string. CREATE OBJECT ro_html. IF ix_error IS BOUND. lv_error = ix_error->get_text( ). ELSE. lv_error = iv_error. ENDIF. ro_html->add( '
' ). ro_html->add( |{ zcl_abapgit_html=>icon( 'alert/red' ) } Error: { lv_error }| ). ro_html->add( '
' ). ENDMETHOD. "render_error METHOD render_item_state. DATA: lv_system TYPE string. FIELD-SYMBOLS TYPE char1. rv_html = ''. DO 2 TIMES. CASE sy-index. WHEN 1. ASSIGN iv1 TO . lv_system = 'Local:'. WHEN 2. ASSIGN iv2 TO . lv_system = 'Remote:'. ENDCASE. CASE . WHEN zif_abapgit_definitions=>gc_state-unchanged. "None or unchanged IF iv1 = zif_abapgit_definitions=>gc_state-added OR iv2 = zif_abapgit_definitions=>gc_state-added. rv_html = rv_html && |X|. ELSE. rv_html = rv_html && | |. ENDIF. WHEN zif_abapgit_definitions=>gc_state-modified. "Changed rv_html = rv_html && |M|. WHEN zif_abapgit_definitions=>gc_state-added. "Added new rv_html = rv_html && |A|. WHEN zif_abapgit_definitions=>gc_state-mixed. "Multiple changes (multifile) rv_html = rv_html && ||. WHEN zif_abapgit_definitions=>gc_state-deleted. "Deleted rv_html = rv_html && |D|. ENDCASE. ENDDO. rv_html = rv_html && ''. ENDMETHOD. "render_item_state METHOD render_js_error_banner. CREATE OBJECT ro_html. ro_html->add( '
' ). ro_html->add( |{ zcl_abapgit_html=>icon( 'alert/red' ) }| && ' If this does not disappear soon,' && ' then there is a JS init error, please log an issue' ). ro_html->add( '
' ). ENDMETHOD. "render_js_error_stub METHOD render_news. DATA: lv_text TYPE string, lv_display TYPE string, lt_log TYPE zcl_abapgit_news=>tt_log. FIELD-SYMBOLS: LIKE LINE OF lt_log. CREATE OBJECT ro_html. IF io_news IS NOT BOUND OR io_news->has_news( ) = abap_false. RETURN. ENDIF. lt_log = io_news->get_log( ). IF io_news->has_unseen( ) = abap_false. lv_display = 'display:none'. ENDIF. ro_html->add( |
| ). ro_html->add( '
Announcement of the latest changes' && '
' && zcl_abapgit_html=>a( iv_txt = '❌' iv_typ = zif_abapgit_definitions=>gc_action_type-onclick iv_act = 'displayNews()' iv_class = 'close-btn' ) && '
' ). IF io_news->has_important( ) = abap_true. ro_html->add( '
' && zcl_abapgit_html=>icon( iv_name = 'alert' iv_class = 'pad-right' ) && 'Please note changes marked with "!"' && '
' ). ENDIF. " Generate news ro_html->add( |
| ). LOOP AT lt_log ASSIGNING . IF -is_header = abap_true. IF -pos_to_cur > 0. lv_text = -text && 'update'. ELSEIF -pos_to_cur = 0. lv_text = -text && 'current'. ELSE. " < 0 lv_text = -text. ENDIF. ro_html->add( |

{ lv_text }

| ). ELSE. ro_html->add( |
  • { -text }
  • | ). ENDIF. ENDLOOP. ro_html->add( '
    ' ). ro_html->add( '
    ' ). ENDMETHOD. "render_news METHOD render_repo_top. DATA: lo_repo_online TYPE REF TO zcl_abapgit_repo_online, lo_pback TYPE REF TO zcl_abapgit_persist_background, lv_hint TYPE string, lv_icon TYPE string. CREATE OBJECT ro_html. CREATE OBJECT lo_pback. IF io_repo->is_offline( ) = abap_true. lv_icon = 'plug/darkgrey' ##NO_TEXT. lv_hint = 'Offline repository' ##NO_TEXT. ELSE. lv_icon = 'cloud-upload/blue' ##NO_TEXT. lv_hint = 'On-line repository' ##NO_TEXT. ENDIF. ro_html->add( '' ). ro_html->add( '' ). ro_html->add( '' ). ro_html->add( '
    ' ). " Repo type and name ro_html->add_icon( iv_name = lv_icon iv_hint = lv_hint ). ro_html->add( |{ io_repo->get_name( ) }| ). IF io_repo->is_offline( ) = abap_false. lo_repo_online ?= io_repo. ro_html->add( |{ lo_repo_online->get_url( ) }| ). ENDIF. " News IF io_news IS BOUND AND io_news->has_news( ) = abap_true. IF io_news->has_updates( ) = abap_true. lv_icon = 'arrow-up/warning'. ELSE. lv_icon = 'arrow-up/grey80'. ENDIF. ro_html->add_a( iv_act = 'displayNews()' iv_typ = zif_abapgit_definitions=>gc_action_type-onclick iv_txt = zcl_abapgit_html=>icon( iv_name = lv_icon iv_class = 'pad-sides' iv_hint = 'Display changelog' ) ). ENDIF. ro_html->add( '' ). " Fav IF abap_true = zcl_abapgit_persistence_user=>get_instance( )->is_favorite_repo( io_repo->get_key( ) ). lv_icon = 'star/blue' ##NO_TEXT. ELSE. lv_icon = 'star/grey' ##NO_TEXT. ENDIF. ro_html->add_a( iv_act = |{ zif_abapgit_definitions=>gc_action-repo_toggle_fav }?{ io_repo->get_key( ) }| iv_txt = zcl_abapgit_html=>icon( iv_name = lv_icon iv_class = 'pad-sides' iv_hint = 'Click to toggle favorite' ) ). " BG IF lo_pback->exists( io_repo->get_key( ) ) = abap_true. ro_html->add( 'BG' ). ENDIF. " Write protect IF io_repo->get_local_settings( )-write_protected = abap_true. ro_html->add_icon( iv_name = 'lock/darkgrey' iv_hint = 'Locked from pulls' ). ENDIF. " Branch IF io_repo->is_offline( ) = abap_false. lo_repo_online ?= io_repo. IF iv_show_branch = abap_true. IF iv_branch IS INITIAL. ro_html->add( render_branch_span( iv_branch = lo_repo_online->get_branch_name( ) io_repo = lo_repo_online iv_interactive = iv_interactive_branch ) ). ELSE. ro_html->add( render_branch_span( iv_branch = iv_branch io_repo = lo_repo_online iv_interactive = iv_interactive_branch ) ). ENDIF. ENDIF. ENDIF. " Package IF iv_show_package = abap_true. ro_html->add_icon( iv_name = 'package/darkgrey' iv_hint = 'SAP package' ). ro_html->add( '' ). ro_html->add_a( iv_txt = io_repo->get_package( ) iv_act = |{ zif_abapgit_definitions=>gc_action-jump_pkg }?{ io_repo->get_package( ) }| ). ro_html->add( '' ). ENDIF. ro_html->add( '
    ' ). ENDMETHOD. ENDCLASS.