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

92.19% Statements 709/769
100% Branches 0/0
0% Functions 0/3
92.19% Lines 709/769

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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 7701x 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 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 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 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 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 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 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 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 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 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 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 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_stage DEFINITION
  PUBLIC
  INHERITING FROM zcl_abapgit_gui_component
  FINAL
  CREATE PRIVATE.
 
  PUBLIC SECTION.
 
    INTERFACES:
      zif_abapgit_gui_event_handler,
      zif_abapgit_gui_hotkeys,
      zif_abapgit_gui_menu_provider,
      zif_abapgit_gui_renderable.
 
    CONSTANTS: BEGIN OF c_action,
                 stage_refresh TYPE string VALUE 'stage_refresh',
                 stage_all     TYPE string VALUE 'stage_all',
                 stage_commit  TYPE string VALUE 'stage_commit',
                 stage_filter  TYPE string VALUE 'stage_filter',
               END OF c_action.
 
    CLASS-METHODS create
      IMPORTING
        ii_repo_online   TYPE REF TO zif_abapgit_repo_online
        iv_seed          TYPE string OPTIONAL
        iv_sci_result    TYPE zif_abapgit_definitions=>ty_sci_result DEFAULT zif_abapgit_definitions=>c_sci_result-no_run
        ii_obj_filter    TYPE REF TO zif_abapgit_object_filter OPTIONAL
        iv_changed_by    TYPE syuname OPTIONAL
        ii_force_refresh TYPE abap_bool
      RETURNING
        VALUE(ri_page)   TYPE REF TO zif_abapgit_gui_renderable
      RAISING
        zcx_abapgit_exception.
 
    METHODS constructor
      IMPORTING
        ii_repo_online   TYPE REF TO zif_abapgit_repo_online
        iv_seed          TYPE string OPTIONAL
        iv_sci_result    TYPE zif_abapgit_definitions=>ty_sci_result DEFAULT zif_abapgit_definitions=>c_sci_result-no_run
        ii_obj_filter    TYPE REF TO zif_abapgit_object_filter OPTIONAL
        iv_changed_by    TYPE syuname OPTIONAL
        ii_force_refresh TYPE abap_bool
      RAISING
        zcx_abapgit_exception.
 
  PROTECTED SECTION.
 
  PRIVATE SECTION.
 
    DATA mi_repo TYPE REF TO zif_abapgit_repo.
    DATA mi_repo_online TYPE REF TO zif_abapgit_repo_online.
    DATA ms_files TYPE zif_abapgit_definitions=>ty_stage_files .
    DATA mv_seed TYPE string .               " Unique page id to bind JS sessionStorage
    DATA mv_filter_value TYPE string .
    DATA mv_sci_result TYPE zif_abapgit_definitions=>ty_sci_result.
    DATA mi_obj_filter TYPE REF TO zif_abapgit_object_filter.
    DATA mo_popup_picklist TYPE REF TO zcl_abapgit_gui_picklist.
 
    METHODS render_list
      RETURNING
        VALUE(ri_html) TYPE REF TO zif_abapgit_html
      RAISING
        zcx_abapgit_exception .
    METHODS render_file
      IMPORTING
        !iv_context    TYPE string
        !is_file       TYPE zif_abapgit_git_definitions=>ty_file
        !is_item       TYPE zif_abapgit_definitions=>ty_item OPTIONAL
        !is_status     TYPE zif_abapgit_definitions=>ty_result
        !iv_changed_by TYPE syuname OPTIONAL
        !iv_transport  TYPE trkorr OPTIONAL
      RETURNING
        VALUE(ri_html) TYPE REF TO zif_abapgit_html
      RAISING
        zcx_abapgit_exception .
    METHODS render_actions
      RETURNING
        VALUE(ri_html) TYPE REF TO zif_abapgit_html .
    METHODS stage_selected
      IMPORTING
        !ii_event       TYPE REF TO zif_abapgit_gui_event
      RETURNING
        VALUE(ro_stage) TYPE REF TO zcl_abapgit_stage
      RAISING
        zcx_abapgit_exception .
    METHODS stage_all
      RETURNING
        VALUE(ro_stage) TYPE REF TO zcl_abapgit_stage
      RAISING
        zcx_abapgit_exception .
    METHODS get_page_patch
      IMPORTING
        !io_stage      TYPE REF TO zcl_abapgit_stage
      RETURNING
        VALUE(ri_page) TYPE REF TO zif_abapgit_gui_renderable
      RAISING
        zcx_abapgit_exception .
    METHODS count_default_files_to_commit
      RETURNING
        VALUE(rv_count) TYPE i .
    METHODS render_scripts
      RETURNING
        VALUE(ri_html) TYPE REF TO zif_abapgit_html
      RAISING
        zcx_abapgit_exception .
    METHODS init_files
      RAISING
        zcx_abapgit_exception .
    METHODS switch_branch
      IMPORTING
        !io_picklist TYPE REF TO zcl_abapgit_gui_picklist OPTIONAL
      RAISING
        zcx_abapgit_exception .
    METHODS handle_picklist_state
      RAISING
        zcx_abapgit_exception .
ENDCLASS.
 
 
 
CLASS zcl_abapgit_gui_page_stage IMPLEMENTATION.
 
 
  METHOD constructor.
 
    DATA lv_ts TYPE timestamp.
 
    super->constructor( ).
 
    mi_repo        = ii_repo_online.
    mi_repo_online = ii_repo_online.
    mv_seed        = iv_seed.
    mv_sci_result  = iv_sci_result.
    mi_obj_filter  = ii_obj_filter.
    " Same as the "me" link in the "Changed by" column: a filter the user can clear
    mv_filter_value = to_lower( iv_changed_by ).
 
    " force refresh on stage, to make sure the latest local and remote files are used
    IF ii_force_refresh = abap_true.
      ii_repo_online->zif_abapgit_repo~refresh( ).
    ENDIF.
 
    IF mv_seed IS INITIAL. " Generate based on time unless obtained from diff page
      GET TIME STAMP FIELD lv_ts.
      mv_seed = |stage{ lv_ts }|.
    ENDIF.
 
    init_files( ).
 
  ENDMETHOD.
 
 
  METHOD count_default_files_to_commit.
 
    FIELD-SYMBOLS <ls_status> LIKE LINE OF ms_files-status.
    FIELD-SYMBOLS <ls_remote> LIKE LINE OF ms_files-remote.
 
    rv_count = lines( ms_files-local ).
 
    LOOP AT ms_files-remote ASSIGNING <ls_remote>.
      READ TABLE ms_files-status ASSIGNING <ls_status>
        WITH TABLE KEY
          path     = <ls_remote>-path
          filename = <ls_remote>-filename.
      ASSERT sy-subrc = 0.
 
      IF <ls_status>-lstate = zif_abapgit_definitions=>c_state-deleted
        AND <ls_status>-rstate = zif_abapgit_definitions=>c_state-unchanged.
        rv_count = rv_count + 1.
      ENDIF.
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD create.
 
    DATA lo_component TYPE REF TO zcl_abapgit_gui_page_stage.
 
    CREATE OBJECT lo_component
      EXPORTING
        ii_repo_online   = ii_repo_online
        iv_seed          = iv_seed
        iv_sci_result    = iv_sci_result
        ii_force_refresh = ii_force_refresh
        ii_obj_filter    = ii_obj_filter
        iv_changed_by    = iv_changed_by.
 
    ri_page = zcl_abapgit_gui_page_hoc=>create(
      iv_page_title         = 'Stage'
      ii_page_menu_provider = lo_component
      ii_child_component    = lo_component ).
 
  ENDMETHOD.
 
 
  METHOD get_page_patch.
 
    DATA: lv_key   TYPE zif_abapgit_persistence=>ty_repo-key,
          lt_files TYPE zif_abapgit_definitions=>ty_stage_tt.
 
    lv_key = mi_repo->get_key( ).
    lt_files = io_stage->get_all( ).
 
    DELETE lt_files WHERE method <> zif_abapgit_definitions=>c_method-add
                      AND method <> zif_abapgit_definitions=>c_method-rm.
 
    IF lt_files IS INITIAL.
      " No selection: patch the same file set as the default commit (stage_all)
      lt_files = stage_all( )->get_all( ).
      DELETE lt_files WHERE method <> zif_abapgit_definitions=>c_method-add
                        AND method <> zif_abapgit_definitions=>c_method-rm.
    ENDIF.
 
    ri_page  = zcl_abapgit_gui_page_patch=>create(
      iv_key        = lv_key
      it_files      = lt_files
      iv_sci_result = mv_sci_result ).
 
  ENDMETHOD.
 
 
  METHOD handle_picklist_state.

    DATA lo_picklist TYPE REF TO zcl_abapgit_gui_picklist.

    IF mo_popup_picklist IS BOUND AND
      ( mo_popup_picklist->is_fulfilled( ) = abap_true OR mo_popup_picklist->is_in_page( ) = abap_false ).
      " Picklist is either fulfilled OR
      " it was on its own page and user went back from it via F3/ESC and the picklist had no "graceful back" handler
      " Consume the picklist before dispatching. The handlers below run during
      " rendering and may fail or be cancelled, and the GUI re-renders the page
      " to display the error - the action must not be replayed then
      lo_picklist = mo_popup_picklist.
      CLEAR mo_popup_picklist.

      CASE lo_picklist->id( ).
        WHEN zif_abapgit_definitions=>c_action-git_branch_switch.
          switch_branch( lo_picklist ).
        WHEN OTHERS.
          zcx_abapgit_exception=>raise( |Unexpected picklist id { lo_picklist->id( ) }| ).
      ENDCASE.
    ENDIF.

  ENDMETHOD.
 
 
  METHOD init_files.
    ms_files = zcl_abapgit_stage_logic=>get_stage_logic( )->get( ii_repo_online = mi_repo_online
                                                                 ii_obj_filter  = mi_obj_filter ).

    IF lines( ms_files-local ) = 0 AND lines( ms_files-remote ) = 0.
      mi_repo->refresh( ).
      zcx_abapgit_exception=>raise( 'There are no changes that could be staged' ).
    ENDIF.
  ENDMETHOD.
 
 
  METHOD render_actions.
 
    CREATE OBJECT ri_html TYPE zcl_abapgit_html.
 
    " Commit and Patch actions live in the page toolbar (commitBtn / patchBtn,
    " labels managed by StageHelper.updateMenu)
 
    ri_html->add( '<table class="w100 margin-v5"><tr>' ).
 
    " Filter bar
    ri_html->add( '<td class="right">' ).
    ri_html->add( '<input class="stage-filter" id="objectSearch"' &&
                  ' type="search" placeholder="Filter Objects"' &&
                  | value="{ mv_filter_value }">| ).
    ri_html->add( '</td>' ).
 
    ri_html->add( '</tr>' ).
    ri_html->add( '</table>' ).
 
  ENDMETHOD.
 
 
  METHOD render_file.
 
    DATA: lv_param    TYPE string,
          lv_filename TYPE string.
 
    CREATE OBJECT ri_html TYPE zcl_abapgit_html.
 
    lv_filename = is_file-path && is_file-filename.
    " make sure whitespace is preserved in the DOM
    REPLACE ALL OCCURRENCES OF ` ` IN lv_filename WITH '&nbsp;'.
 
    ri_html->add( |<tr class="{ iv_context }">| ).
    ri_html->add( '<td>' ).
    ri_html->add( zcl_abapgit_gui_chunk_lib=>render_item_state(
      iv_lstate = is_status-lstate
      iv_rstate = is_status-rstate ) ).
    ri_html->add( '</td>' ).
 
    CASE iv_context.
      WHEN 'local'.
        lv_param = zcl_abapgit_html_action_utils=>file_encode(
          iv_key  = mi_repo->get_key( )
          ig_file = is_file ).
 
        lv_filename = ri_html->a(
          iv_txt = lv_filename
          iv_act = |{ zif_abapgit_definitions=>c_action-go_file_diff }?{ lv_param }| ).
 
        ri_html->add( |<td class="type">{ is_item-obj_type }</td>| ).
        ri_html->add( |<td class="name">{ lv_filename }</td>| ).
      WHEN 'remote'.
        ri_html->add( |<td class="type">{ is_item-obj_type }</td>| ).
        ri_html->add( |<td class="name">{ lv_filename }</td>| ).
    ENDCASE.
 
    ri_html->add( '<td class="user">' ).
    ri_html->add( zcl_abapgit_gui_chunk_lib=>render_user_name( iv_changed_by ) ).
    ri_html->add( '</td>' ).
 
    ri_html->add( '<td class="transport">' ).
    ri_html->add( zcl_abapgit_gui_chunk_lib=>render_transport(
      iv_transport = iv_transport
      iv_obj_type  = is_item-obj_type
      iv_obj_name  = is_item-obj_name ) ).
    ri_html->add( '</td>' ).
 
    ri_html->add( '<td class="status">?</td>' ).
    ri_html->add( '<td class="cmd"></td>' ). " Command added in JS
 
    ri_html->add( '</tr>' ).
 
  ENDMETHOD.
 
 
  METHOD render_list.
 
    DATA: lt_changed_by  TYPE zcl_abapgit_stage_changed_by=>ty_changed_by_tt,
          lv_changed_by  TYPE syuname,
          lo_dot         TYPE REF TO zcl_abapgit_dot_abapgit,
          lt_transports  TYPE zif_abapgit_cts_api=>ty_transport_list,
          ls_transport   LIKE LINE OF lt_transports,
          ls_item_remote TYPE zif_abapgit_definitions=>ty_item.
 
    FIELD-SYMBOLS: <ls_remote> LIKE LINE OF ms_files-remote,
                   <ls_status> LIKE LINE OF ms_files-status,
                   <ls_local>  LIKE LINE OF ms_files-local.
 
    CREATE OBJECT ri_html TYPE zcl_abapgit_html.
 
    ri_html->add( '<table id="stageTab" class="stage_tab w100">' ).
 
    lo_dot = mi_repo->get_dot_abapgit( ).
    lt_transports = zcl_abapgit_stage_changed_by=>find_transports(
      it_files = ms_files
      io_dot   = lo_dot ).
    lt_changed_by = zcl_abapgit_stage_changed_by=>find_changed_by(
      it_files      = ms_files
      io_dot        = lo_dot
      it_transports = lt_transports ).
 
    " Local changes
    LOOP AT ms_files-local ASSIGNING <ls_local>.
      AT FIRST.
        ri_html->add( '<thead>' ).
        ri_html->add( '<tr class="local">' ).
        ri_html->add( '<th class="stage-status"></th>' ). " Diff state
        ri_html->add( '<th class="stage-objtype">Type</th>' ).
        ri_html->add( '<th title="Click filename to see diff">File</th>' ).
        ri_html->add( '<th>Changed by</th>' ).
        ri_html->add( '<th>Transport</th>' ).
        ri_html->add( '<th></th>' ). " Status
        ri_html->add( '<th class="cmd">' ).
        ri_html->add( '<a>add</a>&#x2193; <a>reset</a>&#x2193;' ).
        ri_html->add( '</th>' ).
        ri_html->add( '</tr>' ).
        ri_html->add( '</thead>' ).
        ri_html->add( '<tbody>' ).
      ENDAT.
 
      lv_changed_by = zcl_abapgit_stage_changed_by=>get_name(
        it_changed_by = lt_changed_by
        is_item       = <ls_local>-item
        iv_path       = <ls_local>-file-path
        iv_filename   = <ls_local>-file-filename ).
 
      READ TABLE lt_transports INTO ls_transport WITH KEY
        obj_type = <ls_local>-item-obj_type
        obj_name = <ls_local>-item-obj_name.              "#EC CI_SUBRC
      READ TABLE ms_files-status ASSIGNING <ls_status>
        WITH TABLE KEY
          path     = <ls_local>-file-path
          filename = <ls_local>-file-filename.
      ASSERT sy-subrc = 0.
 
      ri_html->add( render_file(
        iv_context    = 'local'
        is_file       = <ls_local>-file
        is_item       = <ls_local>-item
        is_status     = <ls_status>
        iv_changed_by = lv_changed_by
        iv_transport  = ls_transport-trkorr ) ).
 
      CLEAR ls_transport.
 
      AT LAST.
        ri_html->add( '</tbody>' ).
      ENDAT.
    ENDLOOP.
 
    " Remote changes
    LOOP AT ms_files-remote ASSIGNING <ls_remote>.
      AT FIRST.
        ri_html->add( '<thead>' ).
        ri_html->add( '<tr class="remote">' ).
        ri_html->add( '<th></th>' ). " Diff state
        ri_html->add( '<th></th>' ). " Type
        ri_html->add( '<th colspan="3">Files to remove or non-code</th>' ).
        ri_html->add( '<th></th>' ). " Transport
        ri_html->add( '<th class="cmd">' ).
        ri_html->add( '<a>ignore</a>&#x2193; <a>remove</a>&#x2193; <a>reset</a>&#x2193;' ).
        ri_html->add( '</th>' ).
        ri_html->add( '</tr>' ).
        ri_html->add( '</thead>' ).
        ri_html->add( '<tbody>' ).
      ENDAT.
 
      READ TABLE ms_files-status ASSIGNING <ls_status>
        WITH TABLE KEY
          path     = <ls_remote>-path
          filename = <ls_remote>-filename.
      ASSERT sy-subrc = 0.
 
      TRY.
          zcl_abapgit_filename_logic=>file_to_object(
            EXPORTING
              iv_filename = <ls_remote>-filename
              iv_path     = <ls_remote>-path
              io_dot      = lo_dot
            IMPORTING
              es_item     = ls_item_remote ).
          READ TABLE lt_transports INTO ls_transport WITH KEY
            obj_type = ls_item_remote-obj_type
            obj_name = ls_item_remote-obj_name.
 
          lv_changed_by = zcl_abapgit_stage_changed_by=>get_name(
            it_changed_by = lt_changed_by
            is_item       = ls_item_remote
            iv_path       = <ls_remote>-path
            iv_filename   = <ls_remote>-filename ).
        CATCH zcx_abapgit_exception.
          CLEAR: ls_transport, lv_changed_by.
      ENDTRY.
 
      ri_html->add( render_file(
        iv_context    = 'remote'
        is_status     = <ls_status>
        is_file       = <ls_remote>
        is_item       = ls_item_remote
        iv_changed_by = lv_changed_by
        iv_transport  = ls_transport-trkorr ) ).
 
      CLEAR ls_transport.
 
      AT LAST.
        ri_html->add( '</tbody>' ).
      ENDAT.
    ENDLOOP.
 
    ri_html->add( '</table>' ).
 
  ENDMETHOD.
 
 
  METHOD render_scripts.
 
    CREATE OBJECT ri_html TYPE zcl_abapgit_html.
 
    ri_html->set_title( cl_abap_typedescr=>describe_by_object_ref( me )->get_relative_name( ) ).
 
    ri_html->add( 'var gStageParams = {' ).
    ri_html->add( |  seed:            "{ mv_seed }",| ). " Unique page id
    ri_html->add( |  user:            "{ to_lower( sy-uname ) }",| ).
    ri_html->add( |  formAction:      "{ c_action-stage_commit }",| ).
    ri_html->add( |  patchAction:     "{ zif_abapgit_definitions=>c_action-go_patch }",| ).
    ri_html->add( |  stageAllAction:  "{ c_action-stage_all }",| ).
    ri_html->add( '  focusFilterKey:  "f",' ).
 
    ri_html->add( '  ids: {' ).
    ri_html->add( '    stageTab:          "stageTab",' ).
    ri_html->add( '    commitBtn:         "commitBtn",' ).
    ri_html->add( '    patchBtn:          "patchBtn",' ).
    ri_html->add( '    objectSearch:      "objectSearch",' ).
    ri_html->add( '  }' ).
 
    ri_html->add( '}' ).
    ri_html->add( 'var gHelper = new StageHelper(gStageParams);' ).
 
  ENDMETHOD.
 
 
  METHOD stage_all.
 
    FIELD-SYMBOLS <ls_local> LIKE LINE OF ms_files-local.
    FIELD-SYMBOLS <ls_remote> LIKE LINE OF ms_files-remote.
    FIELD-SYMBOLS <ls_status> LIKE LINE OF ms_files-status.
 
    CREATE OBJECT ro_stage.
 
    LOOP AT ms_files-local ASSIGNING <ls_local>.
      READ TABLE ms_files-status ASSIGNING <ls_status>
        WITH TABLE KEY
          path     = <ls_local>-file-path
          filename = <ls_local>-file-filename.
      ASSERT sy-subrc = 0.
 
      ro_stage->add(
        iv_path     = <ls_local>-file-path
        iv_filename = <ls_local>-file-filename
        is_status   = <ls_status>
        iv_data     = <ls_local>-file-data ).
    ENDLOOP.
 
    LOOP AT ms_files-remote ASSIGNING <ls_remote>.
      READ TABLE ms_files-status ASSIGNING <ls_status>
        WITH TABLE KEY
          path     = <ls_remote>-path
          filename = <ls_remote>-filename.
      ASSERT sy-subrc = 0.
 
      IF <ls_status>-lstate = zif_abapgit_definitions=>c_state-deleted
        AND <ls_status>-rstate = zif_abapgit_definitions=>c_state-unchanged.
 
        ro_stage->rm(
          iv_path     = <ls_remote>-path
          iv_filename = <ls_remote>-filename
          is_status   = <ls_status> ).
      ENDIF.
 
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD stage_selected.
 
    ro_stage = lcl_selected=>get_instance( )->stage_selected(
                     ii_event  = ii_event
                     it_status = ms_files-status
                     it_local  = ms_files-local ).
 
  ENDMETHOD.
 
 
  METHOD switch_branch.

    DATA ls_branch TYPE zif_abapgit_git_definitions=>ty_git_branch.

    IF io_picklist IS NOT BOUND.

      mo_popup_picklist = zcl_abapgit_popup_branch_list=>create(
        iv_url             = mi_repo_online->get_url( )
        iv_default_branch  = zcl_abapgit_git_branch_utils=>get_display_name(
                               mi_repo_online->get_selected_branch( ) )
        iv_show_new_option = abap_true
        iv_description     = 'Select the branch to switch to'
        iv_button_label    = 'Switch to'
        )->create_picklist(
        )->set_id( zif_abapgit_definitions=>c_action-git_branch_switch
        )->set_in_page( ).

    ELSEIF io_picklist->was_cancelled( ) = abap_false.

      io_picklist->get_result_item( CHANGING cs_selected = ls_branch ).
      IF ls_branch IS NOT INITIAL.
        zcl_abapgit_services_git=>switch_branch(
          iv_key    = mi_repo->get_key( )
          is_branch = ls_branch ).
        mi_repo->refresh( abap_true ).
        init_files( ).
      ENDIF.

    ENDIF.

  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_event_handler~on_event.
 
    DATA: lo_stage  TYPE REF TO zcl_abapgit_stage.
 
    CASE ii_event->mv_action.
      WHEN c_action-stage_all.
 
        lo_stage = stage_all( ).
 
        rs_handled-page = zcl_abapgit_gui_page_commit=>create(
          ii_repo_online = mi_repo_online
          io_stage       = lo_stage
          iv_sci_result  = mv_sci_result ).
 
        rs_handled-state = zcl_abapgit_gui=>c_event_state-new_page.
 
      WHEN c_action-stage_commit.
 
        lo_stage = stage_selected( ii_event ).
 
        rs_handled-page = zcl_abapgit_gui_page_commit=>create(
          ii_repo_online = mi_repo_online
          io_stage       = lo_stage
          iv_sci_result  = mv_sci_result ).
 
        rs_handled-state = zcl_abapgit_gui=>c_event_state-new_page.
 
      WHEN c_action-stage_filter.
 
        mv_filter_value = ii_event->form_data( )->get( 'filterValue' ).
        rs_handled-state = zcl_abapgit_gui=>c_event_state-no_more_act.
 
      WHEN zif_abapgit_definitions=>c_action-go_patch.                         " Go Patch page
 
        lo_stage = stage_selected( ii_event ).
        rs_handled-page  = get_page_patch( lo_stage ).
        rs_handled-state = zcl_abapgit_gui=>c_event_state-new_page.
 
      WHEN c_action-stage_refresh.
        mi_repo->refresh( abap_true ).
        init_files( ).
        rs_handled-state = zcl_abapgit_gui=>c_event_state-re_render.
      WHEN zif_abapgit_definitions=>c_action-git_branch_switch.
        switch_branch( ). " Uniformly handle state below
        rs_handled-state = zcl_abapgit_gui=>c_event_state-re_render.
    ENDCASE.
 
    IF mo_popup_picklist IS BOUND. " Uniform popup state handling
      " This should happen only for a new popup because
      " on the first re-render main component event handling is blocked
      " and not called again until the popup destruction
      IF mo_popup_picklist->is_in_page( ) = abap_true.
        rs_handled-state = zcl_abapgit_gui=>c_event_state-re_render.
      ELSE.
        rs_handled-state = zcl_abapgit_gui=>c_event_state-new_page.
        rs_handled-page  = zcl_abapgit_gui_page_hoc=>create(
          ii_child_component = mo_popup_picklist
          iv_show_as_modal   = abap_true ).
      ENDIF.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_hotkeys~get_hotkey_actions.
 
    DATA ls_hotkey_action LIKE LINE OF rt_hotkey_actions.
 
    ls_hotkey_action-ui_component = 'Stage'.
    ls_hotkey_action-description  = |Commit|.
    ls_hotkey_action-action       = 'submitCommit'. " JS function in StageHelper
    ls_hotkey_action-hotkey       = |c|.
    INSERT ls_hotkey_action INTO TABLE rt_hotkey_actions.
 
    ls_hotkey_action-description  = |Patch|.
    ls_hotkey_action-action       = 'submitPatch'. " JS function in StageHelper
    ls_hotkey_action-hotkey       = |p|.
    INSERT ls_hotkey_action INTO TABLE rt_hotkey_actions.
 
    ls_hotkey_action-description  = |Diff|.
    ls_hotkey_action-action       = zif_abapgit_definitions=>c_action-go_repo_diff.
    ls_hotkey_action-hotkey       = |d|.
    INSERT ls_hotkey_action INTO TABLE rt_hotkey_actions.
 
    ls_hotkey_action-description  = |Refresh|.
    ls_hotkey_action-action       = c_action-stage_refresh.
    ls_hotkey_action-hotkey       = |r|.
    INSERT ls_hotkey_action INTO TABLE rt_hotkey_actions.
 
    " registered/handled in js
    ls_hotkey_action-description = |Focus filter|.
    ls_hotkey_action-action = `#`.
    ls_hotkey_action-hotkey = |f|.
    INSERT ls_hotkey_action INTO TABLE rt_hotkey_actions.
 
    ls_hotkey_action-description = |Filter changed by me|.
    ls_hotkey_action-action      = 'onFilterMe'. " JS function in StageHelper
    ls_hotkey_action-hotkey      = |m|.
    INSERT ls_hotkey_action INTO TABLE rt_hotkey_actions.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_menu_provider~get_menu.
 
    DATA: lv_local_count    TYPE i,
          lv_commit_all_txt TYPE string,
          lv_patch_all_txt  TYPE string.
 
    ro_toolbar = zcl_abapgit_html_toolbar=>create( 'toolbar-staging' ).
 
    IF lines( ms_files-local ) > 0 OR lines( ms_files-remote ) > 0.
      lv_local_count = count_default_files_to_commit( ).
      lv_patch_all_txt = |Patch|.
      IF lv_local_count > 0.
        lv_commit_all_txt = |Add All and Commit ({ lv_local_count })|.
        lv_patch_all_txt  = |Patch All ({ lv_local_count })|.
        " Otherwise commit is empty, but the element (id) is preserved for JS
      ENDIF.
 
      ro_toolbar->add(
        iv_txt = lv_commit_all_txt
        iv_typ = zif_abapgit_html=>c_action_type-onclick
        iv_id  = |commitBtn|
        iv_opt = zif_abapgit_html=>c_html_opt-strong
      )->add(
        iv_txt = ``
        iv_typ = zif_abapgit_html=>c_action_type-separator
      )->add(
        iv_txt = lv_patch_all_txt
        iv_typ = zif_abapgit_html=>c_action_type-onclick
        iv_id  = |patchBtn|
        iv_opt = zif_abapgit_html=>c_html_opt-strong
      )->add(
        iv_txt = ``
        iv_typ = zif_abapgit_html=>c_action_type-separator
      )->add(
        iv_txt = |Diff|
        iv_act = |{ zif_abapgit_definitions=>c_action-go_repo_diff }?key={ mi_repo->get_key( ) }|
      )->add(
        iv_txt = 'Refresh'
        iv_act = |{ c_action-stage_refresh }|
      )->add(
        iv_txt = |Back|
        iv_act = zif_abapgit_definitions=>c_action-go_back ).
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_renderable~render.
 
    handle_picklist_state( ).
 
    CREATE OBJECT ri_html TYPE zcl_abapgit_html.
 
    ri_html->add( '<div class="repo">' ).
    ri_html->add( zcl_abapgit_gui_chunk_lib=>render_repo_top(
      ii_repo               = mi_repo
      iv_show_commit        = abap_false
      iv_interactive_branch = abap_true
      iv_sci_result         = mv_sci_result ) ).
    ri_html->add( zcl_abapgit_gui_chunk_lib=>render_main_language_warning(
      mi_repo->get_dot_abapgit( )->get_main_language( ) ) ).
 
    ri_html->add( '<div class="stage-container">' ).
    ri_html->add( render_actions( ) ).
    ri_html->add( render_list( ) ).
    ri_html->add( '</div>' ).
 
    ri_html->add( '</div>' ).
 
    register_deferred_script( render_scripts( ) ).
 
    IF mo_popup_picklist IS NOT BOUND OR mo_popup_picklist->is_in_page( ) = abap_false.
      register_handlers( ).
    ELSEIF mo_popup_picklist->is_in_page( ) = abap_true.
      " Block usual page events if the popup is an in-page popup
      ri_html->add( zcl_abapgit_gui_in_page_modal=>create( mo_popup_picklist ) ).
    ENDIF.
 
  ENDMETHOD.
ENDCLASS.