All files / src/ui/pages zcl_abapgit_gui_page_ref_sel.clas.abap

26.95% Statements 62/230
50% Branches 1/2
50% Functions 1/2
26.95% Lines 62/230

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 2311x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                                                                                                                                                                                                                                                                                                                  
CLASS zcl_abapgit_gui_page_ref_sel DEFINITION
  PUBLIC
  INHERITING FROM zcl_abapgit_gui_component
  FINAL
  CREATE PRIVATE.
 
  PUBLIC SECTION.
 
    INTERFACES zif_abapgit_gui_event_handler.
    INTERFACES zif_abapgit_gui_renderable.
    INTERFACES zif_abapgit_gui_page_title.
 
    CLASS-METHODS create
      IMPORTING
        !iv_key        TYPE zif_abapgit_persistence=>ty_repo-key
        !iv_action     TYPE string
      RETURNING
        VALUE(ri_page) TYPE REF TO zif_abapgit_gui_renderable
      RAISING
        zcx_abapgit_exception.
 
    CLASS-METHODS create_in_page
      IMPORTING
        !iv_key             TYPE zif_abapgit_persistence=>ty_repo-key
        !iv_action          TYPE string
      RETURNING
        VALUE(ro_component) TYPE REF TO zcl_abapgit_gui_page_ref_sel
      RAISING
        zcx_abapgit_exception.
 
    METHODS constructor
      IMPORTING
        !iv_key     TYPE zif_abapgit_persistence=>ty_repo-key
        !iv_action  TYPE string
        !iv_in_page TYPE abap_bool DEFAULT abap_false
      RAISING
        zcx_abapgit_exception.
 
    METHODS is_fulfilled
      RETURNING
        VALUE(rv_yes) TYPE abap_bool.
 
  PROTECTED SECTION.
  PRIVATE SECTION.
 
    DATA mv_key TYPE zif_abapgit_persistence=>ty_repo-key.
    DATA mv_action TYPE string.
    DATA mv_in_page TYPE abap_bool.
    DATA mo_picklist TYPE REF TO zcl_abapgit_gui_picklist.
 
    METHODS create_picklist
      RAISING
        zcx_abapgit_exception.
 
    METHODS execute_selection
      RAISING
        zcx_abapgit_exception.
 
ENDCLASS.
 
 
 
CLASS zcl_abapgit_gui_page_ref_sel IMPLEMENTATION.


  METHOD constructor.

    super->constructor( ).

    mv_key     = iv_key.
    mv_action  = iv_action.
    mv_in_page = iv_in_page.

    create_picklist( ).

  ENDMETHOD.


  METHOD create_in_page.

    CREATE OBJECT ro_component
      EXPORTING
        iv_key     = iv_key
        iv_action  = iv_action
        iv_in_page = abap_true.

  ENDMETHOD.


  METHOD create.

    DATA lo_component TYPE REF TO zcl_abapgit_gui_page_ref_sel.

    CREATE OBJECT lo_component
      EXPORTING
        iv_key    = iv_key
        iv_action = iv_action.

    ri_page = zcl_abapgit_gui_page_hoc=>create(
      ii_child_component = lo_component
      iv_show_as_modal   = abap_true ).

  ENDMETHOD.


  METHOD create_picklist.

    DATA li_repo_online TYPE REF TO zif_abapgit_repo_online.
    DATA lv_url TYPE string.

    li_repo_online ?= zcl_abapgit_repo_srv=>get_instance( )->get( mv_key ).
    lv_url = li_repo_online->get_url( ).

    CASE mv_action.
      WHEN zif_abapgit_definitions=>c_action-git_branch_switch.
        mo_picklist = zcl_abapgit_popup_branch_list=>create(
          iv_url             = lv_url
          iv_default_branch  = zcl_abapgit_git_branch_utils=>get_display_name(
                                 li_repo_online->get_selected_branch( ) )
          iv_show_new_option = abap_true )->create_picklist( ).
      WHEN zif_abapgit_definitions=>c_action-git_branch_delete.
        mo_picklist = zcl_abapgit_popup_branch_list=>create(
          iv_url         = lv_url
          iv_hide_branch = li_repo_online->get_selected_branch( )
          iv_hide_head   = abap_true )->create_picklist( ).
      WHEN zif_abapgit_definitions=>c_action-git_tag_switch
        OR zif_abapgit_definitions=>c_action-git_tag_delete.
        mo_picklist = zcl_abapgit_popup_tag_list=>create( lv_url )->create_picklist( ).
      WHEN OTHERS.
        zcx_abapgit_exception=>raise( |Unexpected ref selection action { mv_action }| ).
    ENDCASE.

    mo_picklist->set_id( mv_action )->set_in_page( mv_in_page ).

  ENDMETHOD.


  METHOD is_fulfilled.

    rv_yes = mo_picklist->is_fulfilled( ).

  ENDMETHOD.


  METHOD execute_selection.

    DATA ls_selected TYPE zif_abapgit_git_definitions=>ty_git_branch.
    DATA ls_tag      TYPE zif_abapgit_git_definitions=>ty_git_tag.

    mo_picklist->get_result_item( CHANGING cs_selected = ls_selected ).
    IF ls_selected IS INITIAL.
      RETURN.
    ENDIF.

    CASE mv_action.
      WHEN zif_abapgit_definitions=>c_action-git_branch_switch.
        zcl_abapgit_services_git=>switch_branch(
          iv_key    = mv_key
          is_branch = ls_selected ).
      WHEN zif_abapgit_definitions=>c_action-git_branch_delete.
        zcl_abapgit_services_git=>delete_branch(
          iv_key    = mv_key
          is_branch = ls_selected ).
      WHEN zif_abapgit_definitions=>c_action-git_tag_switch.
        MOVE-CORRESPONDING ls_selected TO ls_tag.
        zcl_abapgit_services_git=>switch_tag(
          iv_key = mv_key
          is_tag = ls_tag ).
      WHEN zif_abapgit_definitions=>c_action-git_tag_delete.
        MOVE-CORRESPONDING ls_selected TO ls_tag.
        zcl_abapgit_services_git=>delete_tag(
          iv_key = mv_key
          is_tag = ls_tag ).
        zcl_abapgit_services_repo=>refresh( mv_key ).
    ENDCASE.

  ENDMETHOD.


  METHOD zif_abapgit_gui_event_handler~on_event.

    DATA lv_was_fulfilled TYPE abap_bool.

    " The picklist handles its own events (it is registered after this
    " component, see render). Delegate explicitly and evaluate the outcome.
    " Act only on the transition to fulfilled - the flag stays set afterwards,
    " and if the selection fails the error box is rendered on this very page,
    " so its events must not run the selection a second time
    lv_was_fulfilled = mo_picklist->is_fulfilled( ).

    rs_handled = mo_picklist->zif_abapgit_gui_event_handler~on_event( ii_event ).

    IF lv_was_fulfilled = abap_false
        AND mo_picklist->is_fulfilled( ) = abap_true
        AND mo_picklist->was_cancelled( ) = abap_false.
      TRY.
          execute_selection( ).
        CATCH zcx_abapgit_cancel ##NO_HANDLER.
      ENDTRY.
    ENDIF.

  ENDMETHOD.


  METHOD zif_abapgit_gui_page_title~get_page_title.

    CASE mv_action.
      WHEN zif_abapgit_definitions=>c_action-git_branch_switch.
        rv_title = 'Switch Branch'.
      WHEN zif_abapgit_definitions=>c_action-git_branch_delete.
        rv_title = 'Delete Branch'.
      WHEN zif_abapgit_definitions=>c_action-git_tag_switch.
        rv_title = 'Switch Tag'.
      WHEN zif_abapgit_definitions=>c_action-git_tag_delete.
        rv_title = 'Delete Tag'.
    ENDCASE.

  ENDMETHOD.


  METHOD zif_abapgit_gui_renderable~render.

    ri_html = mo_picklist->zif_abapgit_gui_renderable~render( ).

    " Register this component after the picklist so that on_event above
    " is called first and can post-process the picklist result
    register_handlers( ).

  ENDMETHOD.
ENDCLASS.