From 2b4ff9529b30e945edcfd5f7b44cb83542fb905f Mon Sep 17 00:00:00 2001 From: Christian Guenter Date: Sat, 15 Sep 2018 14:30:50 +0200 Subject: [PATCH] Page Stage: Preserve filter value On page stage the filter value is preserved while navigating to diff or commit page and navigate back. --- src/ui/zcl_abapgit_gui_page_stage.clas.abap | 23 +++++++++++++--- src/zabapgit_js_common.w3mi.data.js | 30 ++++++++++++++------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/ui/zcl_abapgit_gui_page_stage.clas.abap b/src/ui/zcl_abapgit_gui_page_stage.clas.abap index fc7166ae1..0b08686c5 100644 --- a/src/ui/zcl_abapgit_gui_page_stage.clas.abap +++ b/src/ui/zcl_abapgit_gui_page_stage.clas.abap @@ -9,6 +9,7 @@ CLASS zcl_abapgit_gui_page_stage DEFINITION CONSTANTS: BEGIN OF c_action, 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. METHODS: @@ -36,7 +37,8 @@ CLASS zcl_abapgit_gui_page_stage DEFINITION DATA mo_repo TYPE REF TO zcl_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_seed TYPE string . " Unique page id to bind JS sessionStorage + DATA mv_filter_value TYPE string. METHODS find_changed_by IMPORTING @@ -227,7 +229,8 @@ CLASS zcl_abapgit_gui_page_stage IMPLEMENTATION. " Filter bar ro_html->add( '' ). ro_html->add( '' ). + ' type="search" placeholder="Filter objects"' && + | value={ mv_filter_value }>| ). ro_html->add( '' ). ro_html->add( '' ). @@ -399,7 +402,9 @@ CLASS zcl_abapgit_gui_page_stage IMPLEMENTATION. METHOD zif_abapgit_gui_page~on_event. - DATA lo_stage TYPE REF TO zcl_abapgit_stage. + DATA: lo_stage TYPE REF TO zcl_abapgit_stage, + lv_string TYPE string, + lt_fields TYPE tihttpnvp. FIELD-SYMBOLS: LIKE LINE OF ms_files-local. @@ -435,6 +440,18 @@ CLASS zcl_abapgit_gui_page_stage IMPLEMENTATION. io_stage = lo_stage. ev_state = zif_abapgit_definitions=>c_event_state-new_page. + WHEN c_action-stage_filter. + + CONCATENATE LINES OF it_postdata INTO lv_string. + + lt_fields = zcl_abapgit_html_action_utils=>parse_fields( lv_string ). + + zcl_abapgit_html_action_utils=>get_field( EXPORTING iv_name = 'filterValue' + it_field = lt_fields + CHANGING cg_field = mv_filter_value ). + + ev_state = zif_abapgit_definitions=>c_event_state-no_more_act. + WHEN zif_abapgit_definitions=>c_action-go_patch. " Go Patch page ei_page = get_page_patch( diff --git a/src/zabapgit_js_common.w3mi.data.js b/src/zabapgit_js_common.w3mi.data.js index b67e83640..07772ed47 100644 --- a/src/zabapgit_js_common.w3mi.data.js +++ b/src/zabapgit_js_common.w3mi.data.js @@ -180,7 +180,7 @@ function StageHelper(params) { this.pageSeed = params.seed; this.formAction = params.formAction; this.choiseCount = 0; - this.lastSearchValue = ""; + this.lastFilterValue = ""; // DOM nodes this.dom = { @@ -218,8 +218,8 @@ function StageHelper(params) { StageHelper.prototype.setHooks = function() { this.dom.stageTab.onclick = this.onTableClick.bind(this); this.dom.commitBtn.onclick = this.submit.bind(this); - this.dom.objectSearch.oninput = this.onSearch.bind(this); - this.dom.objectSearch.onkeypress = this.onSearch.bind(this); + this.dom.objectSearch.oninput = this.onFilter.bind(this); + this.dom.objectSearch.onkeypress = this.onFilter.bind(this); window.onbeforeunload = this.onPageUnload.bind(this); window.onload = this.onPageLoad.bind(this); } @@ -242,7 +242,7 @@ StageHelper.prototype.onPageUnload = function() { var data = this.collectData(); window.sessionStorage.setItem(this.pageSeed, JSON.stringify(data)); -} +}; // Re-store table state on entering the page StageHelper.prototype.onPageLoad = function() { @@ -254,8 +254,11 @@ StageHelper.prototype.onPageLoad = function() { }); this.updateMenu(); + if (this.dom.objectSearch.value) { + this.applyFilterValue(this.dom.objectSearch.value); + } debugOutput("StageHelper.onPageLoad: " + ((data) ? "from Storage" : "initial state")); -} +}; // Table event handler, change status StageHelper.prototype.onTableClick = function (event) { @@ -292,15 +295,22 @@ StageHelper.prototype.onTableClick = function (event) { }; // Search object -StageHelper.prototype.onSearch = function (e) { +StageHelper.prototype.onFilter = function (e) { if ( // Enter hit or clear, IE SUCKS ! - e.type === "input" && !e.target.value && this.lastSearchValue + e.type === "input" && !e.target.value && this.lastFilterValue || e.type === "keypress" && e.which === 13 ) { - this.lastSearchValue = e.target.value; - this.iterateStageTab(true, this.applyFilterToRow, e.target.value); + this.applyFilterValue(e.target.value); + submitSapeventForm({ 'filterValue': e.target.value }, "stage_filter", "post"); } -} +}; + +StageHelper.prototype.applyFilterValue = function(sFilterValue) { + + this.lastFilterValue = sFilterValue; + this.iterateStageTab(true, this.applyFilterToRow, sFilterValue); + +}; // Apply filter to a single stage line - hide or show StageHelper.prototype.applyFilterToRow = function (row, filter) {