From 0946e86f6e31eafb752b4b5d6b33a4df99c31b3c Mon Sep 17 00:00:00 2001 From: atsy Date: Sat, 14 May 2016 13:28:56 +0300 Subject: [PATCH] diff page design iteration 1 --- zabapgit.prog.abap | 345 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 271 insertions(+), 74 deletions(-) diff --git a/zabapgit.prog.abap b/zabapgit.prog.abap index 071042a72..77f53b022 100644 --- a/zabapgit.prog.abap +++ b/zabapgit.prog.abap @@ -14717,6 +14717,129 @@ CLASS lcl_git_porcelain DEFINITION FINAL. ENDCLASS. "lcl_porcelain DEFINITION +*----------------------------------------------------------------------* +* CLASS lcl_html_helper DEFINITION +*----------------------------------------------------------------------* +CLASS lcl_html_helper DEFINITION FINAL. + PUBLIC SECTION. + CONSTANTS mc_indent_size TYPE i VALUE 2. + + DATA mv_html TYPE string READ-ONLY. + DATA mv_indent TYPE i READ-ONLY. + + METHODS add IMPORTING iv_chunk TYPE any. + METHODS div IMPORTING iv_class TYPE string OPTIONAL + iv_id TYPE string OPTIONAL + iv_chunk TYPE any. + METHODS reset. + + PRIVATE SECTION. + METHODS _add_str IMPORTING iv_str TYPE csequence. + METHODS _add_htm IMPORTING io_html TYPE REF TO lcl_html_helper. + +endclass. "lcl_html_helper DEFINITION + +*----------------------------------------------------------------------* +* CLASS lcl_html_helper IMPLEMENTATION +*----------------------------------------------------------------------* +CLASS lcl_html_helper IMPLEMENTATION. + METHOD add. + DATA lo_type TYPE REF TO cl_abap_typedescr. + DATA lo_html TYPE REF TO lcl_html_helper. + + lo_type = cl_abap_typedescr=>describe_by_data( iv_chunk ). + + CASE lo_type->type_kind. + WHEN cl_abap_typedescr=>typekind_char OR cl_abap_typedescr=>typekind_string. + _add_str( iv_chunk ). + WHEN cl_abap_typedescr=>typekind_oref. + ASSERT iv_chunk IS BOUND. + TRY. + lo_html ?= iv_chunk. + CATCH cx_sy_move_cast_error. + ASSERT 1 = 0. " Dev mistake + ENDTRY. + _add_htm( lo_html ). + WHEN OTHERS. + ASSERT 1 = 0. " Dev mistake + ENDCASE. + + ENDMETHOD. " add + + METHOD div. + DATA lv_tag TYPE string. + + lv_tag = ''. + + add( lv_tag ). + add( iv_chunk ). + add( '' ). + + ENDMETHOD. "div + + METHOD reset. + CLEAR: me->mv_html, me->mv_indent. + ENDMETHOD. "reset + + METHOD _add_str. + DATA lv_tags TYPE i. + DATA lv_tags_open TYPE i. + DATA lv_tags_close TYPE i. + DATA lv_close_offs TYPE i. + DATA lv_shift_back TYPE i. + + FIND FIRST OCCURRENCE OF ' 0. " Found close tag @beginning + lv_shift_back = 1. + ENDIF. + + mv_html = mv_html + && repeat( val = ` ` occ = ( mv_indent - lv_shift_back ) * mc_indent_size ) + && iv_str + && gc_newline. + + FIND ALL OCCURRENCES OF '<' IN iv_str MATCH COUNT lv_tags. + FIND ALL OCCURRENCES OF ' lv_tags_close. " This logic chosen due to possible double tags in a line '' + mv_indent = mv_indent + 1. + ELSEIF lv_tags_open < lv_tags_close AND mv_indent > 0. + mv_indent = mv_indent - 1. + ENDIF. + + ENDMETHOD. "_add_str + + METHOD _add_htm. + DATA lv_indent_str TYPE string. + DATA lv_temp_str TYPE string. + + lv_indent_str = repeat( val = ` ` occ = mv_indent * mc_indent_size ). + lv_temp_str = io_html->mv_html. + + IF me->mv_indent > 0. + REPLACE ALL OCCURRENCES OF gc_newline IN lv_temp_str WITH gc_newline && lv_indent_str. + SHIFT lv_temp_str RIGHT DELETING TRAILING space. + SHIFT lv_temp_str LEFT DELETING LEADING space. + ENDIF. + + mv_html = mv_html && lv_indent_str && lv_temp_str. + mv_indent = mv_indent + io_html->mv_indent. + + ENDMETHOD. "_add_htm + +ENDCLASS. "lcl_html_helper IMPLEMENTATION + +*----------------------------------------------------------------------* +* INTERFACE lif_gui_page DEFINITION +*----------------------------------------------------------------------* INTERFACE lif_gui_page. METHODS: @@ -17088,13 +17211,90 @@ CLASS lcl_gui_page_diff DEFINITION FINAL. DATA: ms_result TYPE lcl_file_status=>ty_result, mo_diff TYPE REF TO lcl_diff. + METHODS styles RETURNING VALUE(rv_html) TYPE string. + ENDCLASS. CLASS lcl_gui_page_diff IMPLEMENTATION. METHOD constructor. ms_result = is_result. - mo_diff = io_diff. + mo_diff = io_diff. + ENDMETHOD. + + METHOD styles. + DATA h TYPE REF TO lcl_html_helper. + CREATE OBJECT h. + + h->add( '' ). + + rv_html = h->mv_html. ENDMETHOD. METHOD lif_gui_page~on_event. @@ -17113,106 +17313,103 @@ CLASS lcl_gui_page_diff IMPLEMENTATION. DATA: lv_html TYPE string, lv_local TYPE string, lv_remote TYPE string, - lv_clocal TYPE string, - lv_cremote TYPE string, + lv_attr_local TYPE string, + lv_attr_remote TYPE string, ls_count TYPE lcl_diff=>ty_count, lt_diffs TYPE lcl_diff=>ty_diffs_tt, lv_anchor_count LIKE sy-tabix, lv_anchor_name TYPE string. + DATA h_main TYPE REF TO lcl_html_helper. + DATA h_head TYPE REF TO lcl_html_helper. + DATA h_cont TYPE REF TO lcl_html_helper. + DATA lv_cnt TYPE i. + FIELD-SYMBOLS: LIKE LINE OF lt_diffs. + CREATE OBJECT h_main. + CREATE OBJECT h_head. + CREATE OBJECT h_cont. - lv_html = lcl_gui=>header( ) && - '' && - '
' && - '

' && - ms_result-obj_type && ' ' && - ms_result-obj_name && ' ' && - ms_result-filename && '



'. - + " Diff header ls_count = mo_diff->stats( ). - lv_html = lv_html && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - '
Insert' && - ls_count-insert && - '
Delete' && - ls_count-delete && - '
Update' && - ls_count-update && - '

' && gc_newline. - lv_html = lv_html && - '' && gc_newline && - '' && gc_newline && - '' && gc_newline && - || && gc_newline && - '' && gc_newline && - ''. + h_head->add( '
' ). + h_head->add( |+ { ls_count-insert }| ). + h_head->add( |- { ls_count-delete }| ). + h_head->add( |~ { ls_count-update }| ). + h_head->add( '' ). + h_head->add( ms_result-obj_type ). + h_head->add( |{ ms_result-obj_name }| ). + h_head->add( |({ ms_result-filename })| ). + h_head->add( '' ). + h_head->add( '
' ). + " Diff content lt_diffs = mo_diff->get( ). + h_cont->add( '
' ). + h_cont->add( '

Local

<>

Remote

' ). + h_cont->add( '' ). + h_cont->add( '' ). + h_cont->add( '' ). + h_cont->add( '' ). + h_cont->add( '' ). + h_cont->add( '' ). + LOOP AT lt_diffs ASSIGNING . - lv_local = escape( val = -local - format = cl_abap_format=>e_html_attr ). + lv_cnt = sy-tabix. + lv_local = escape( val = -local + format = cl_abap_format=>e_html_attr ). lv_remote = escape( val = -remote format = cl_abap_format=>e_html_attr ). CASE -result. WHEN lcl_diff=>c_diff-insert. - lv_clocal = ' style="background:lightgreen;"'. "#EC NOTEXT - lv_cremote = ''. + lv_attr_local = ' class="diff_ins"'. "#EC NOTEXT + lv_attr_remote = ''. WHEN lcl_diff=>c_diff-delete. - lv_clocal = ''. - lv_cremote = ' style="background:lightpink;"'. "#EC NOTEXT + lv_attr_local = ''. + lv_attr_remote = ' class="diff_del"'. "#EC NOTEXT WHEN lcl_diff=>c_diff-update. - lv_clocal = ' style="background:lightgreen;"'. "#EC NOTEXT - lv_cremote = ' style="background:lightpink;"'. "#EC NOTEXT + lv_attr_local = ' class="diff_ins"'. "#EC NOTEXT + lv_attr_remote = ' class="diff_del"'. "#EC NOTEXT WHEN OTHERS. - lv_clocal = ''. - lv_cremote = ''. + lv_attr_local = ''. + lv_attr_remote = ''. ENDCASE. - IF -result = lcl_diff=>c_diff-delete - OR -result = lcl_diff=>c_diff-insert - OR -result = lcl_diff=>c_diff-update. - lv_anchor_count = lv_anchor_count + 1. - lv_anchor_name = | name="diff_{ lv_anchor_count }"|. - ELSE. - CLEAR lv_anchor_name. - ENDIF. + h_cont->add( '' ). + h_cont->add( || ). + h_cont->add( |{ lv_local }| ). + h_cont->add( || ). " TODO, ANCHOR ???? + h_cont->add( |{ lv_remote }| ). + h_cont->add( '' ). - lv_html = lv_html && - || && gc_newline && - '
' && lv_local && '
' && - gc_newline && - '
' && - gc_newline && - '
' && lv_remote && '
' && - gc_newline && - '
' && gc_newline. ENDLOOP. - rv_html = lv_html && gc_newline && - '
@LOCAL@REMOTE
{ lv_cnt }
 ' && - |{ -result }| && - ' 
' && gc_newline && - '
' && gc_newline && - lcl_gui=>footer( ). + h_cont->add( '' ). + h_cont->add( '' ). + + " Build all together all +* REDO + lv_html = lcl_gui=>header( ). + + replace first occurrence of '' in lv_html + with '' && styles( ). "TODO: crutch, redo later after unification + + "TODO: crutch, move to SAP back button (code almost ready) + lv_html = lv_html && '
' && 'Back' && '
'. + h_main->add( lv_html ). +* ^^^ REDO + + h_main->add( '
' ). + h_main->add( h_head ). + h_main->add( h_cont ). + h_main->add( '
' ). + h_main->add( lcl_gui=>footer( ) ). + + rv_html = h_main->mv_html. ENDMETHOD.