commit selected button (#2993)

This commit is contained in:
Alexander Tsybulsky 2019-10-25 07:46:01 +03:00 committed by Lars Hvam
parent 3900842392
commit af97a51fa5
2 changed files with 75 additions and 25 deletions

View File

@ -264,17 +264,21 @@ function StageHelper(params) {
this.pageSeed = params.seed; this.pageSeed = params.seed;
this.formAction = params.formAction; this.formAction = params.formAction;
this.user = params.user; this.user = params.user;
this.choiseCount = 0; this.selectedCount = 0;
this.filteredCount = 0;
this.lastFilterValue = ""; this.lastFilterValue = "";
// DOM nodes // DOM nodes
this.dom = { this.dom = {
stageTab: document.getElementById(params.ids.stageTab), stageTab: document.getElementById(params.ids.stageTab),
commitBtn: document.getElementById(params.ids.commitBtn),
commitAllBtn: document.getElementById(params.ids.commitAllBtn), commitAllBtn: document.getElementById(params.ids.commitAllBtn),
commitSelectedBtn: document.getElementById(params.ids.commitSelectedBtn),
commitFilteredBtn: document.getElementById(params.ids.commitFilteredBtn),
objectSearch: document.getElementById(params.ids.objectSearch), objectSearch: document.getElementById(params.ids.objectSearch),
fileCounter: document.getElementById(params.ids.fileCounter) selectedCounter: null,
filteredCounter: null,
}; };
this.findCounters();
// Table columns (autodetection) // Table columns (autodetection)
this.colIndex = this.detectColumns(); this.colIndex = this.detectColumns();
@ -300,6 +304,11 @@ function StageHelper(params) {
if (this.user) this.injectFilterMe(); if (this.user) this.injectFilterMe();
} }
StageHelper.prototype.findCounters = function() {
this.dom.selectedCounter = this.dom.commitSelectedBtn.querySelector("span.counter");
this.dom.filteredCounter = this.dom.commitFilteredBtn.querySelector("span.counter");
};
StageHelper.prototype.injectFilterMe = function() { StageHelper.prototype.injectFilterMe = function() {
var changedByHead = this.dom.stageTab.tHead.rows[0].cells[this.colIndex.user]; var changedByHead = this.dom.stageTab.tHead.rows[0].cells[this.colIndex.user];
changedByHead.innerText = changedByHead.innerText + " ("; changedByHead.innerText = changedByHead.innerText + " (";
@ -319,7 +328,8 @@ StageHelper.prototype.onFilterMe = function() {
// Hook global click listener on table, load/unload actions // Hook global click listener on table, load/unload actions
StageHelper.prototype.setHooks = function() { StageHelper.prototype.setHooks = function() {
this.dom.stageTab.onclick = this.onTableClick.bind(this); this.dom.stageTab.onclick = this.onTableClick.bind(this);
this.dom.commitBtn.onclick = this.submit.bind(this); this.dom.commitSelectedBtn.onclick = this.submit.bind(this);
this.dom.commitFilteredBtn.onclick = this.submitVisible.bind(this);
this.dom.objectSearch.oninput = this.onFilter.bind(this); this.dom.objectSearch.oninput = this.onFilter.bind(this);
this.dom.objectSearch.onkeypress = this.onFilter.bind(this); this.dom.objectSearch.onkeypress = this.onFilter.bind(this);
window.onbeforeunload = this.onPageUnload.bind(this); window.onbeforeunload = this.onPageUnload.bind(this);
@ -411,7 +421,8 @@ StageHelper.prototype.onFilter = function (e) {
StageHelper.prototype.applyFilterValue = function(sFilterValue) { StageHelper.prototype.applyFilterValue = function(sFilterValue) {
this.lastFilterValue = sFilterValue; this.lastFilterValue = sFilterValue;
this.iterateStageTab(true, this.applyFilterToRow, sFilterValue); this.filteredCount = this.iterateStageTab(true, this.applyFilterToRow, sFilterValue);
this.updateMenu();
}; };
@ -445,6 +456,7 @@ StageHelper.prototype.applyFilterToRow = function (row, filter) {
for (var j = targets.length - 1; j >= 0; j--) { for (var j = targets.length - 1; j >= 0; j--) {
if (targets[j].isChanged) targets[j].elem.innerHTML = targets[j].newHtml; if (targets[j].isChanged) targets[j].elem.innerHTML = targets[j].newHtml;
} }
return isVisible ? 1 : 0;
}; };
// Get how status should affect object counter // Get how status should affect object counter
@ -469,7 +481,7 @@ StageHelper.prototype.updateRow = function (row, newStatus) {
this.updateRowCommand(row, newStatus); // For initial run this.updateRowCommand(row, newStatus); // For initial run
} }
this.choiseCount += this.getStatusImpact(newStatus) - this.getStatusImpact(oldStatus); this.selectedCount += this.getStatusImpact(newStatus) - this.getStatusImpact(oldStatus);
}; };
// Update Status cell (render set of commands) // Update Status cell (render set of commands)
@ -496,9 +508,20 @@ StageHelper.prototype.updateRowCommand = function (row, status) {
// Update menu items visibility // Update menu items visibility
StageHelper.prototype.updateMenu = function () { StageHelper.prototype.updateMenu = function () {
this.dom.commitBtn.style.display = (this.choiseCount > 0) ? "" : "none"; var display;
this.dom.commitAllBtn.style.display = (this.choiseCount > 0) ? "none" : ""; if (this.selectedCount > 0) {
this.dom.fileCounter.innerHTML = this.choiseCount.toString(); display = "selected";
this.dom.selectedCounter.innerText = this.selectedCount.toString();
} else if (this.lastFilterValue) {
display = "filtered";
this.dom.filteredCounter.innerText = this.filteredCount.toString();
} else {
display = "default";
}
this.dom.commitAllBtn.style.display = display === "default" ? "" : "none";
this.dom.commitSelectedBtn.style.display = display === "selected" ? "" : "none";
this.dom.commitFilteredBtn.style.display = display === "filtered" ? "" : "none";
}; };
// Submit stage state to the server // Submit stage state to the server
@ -506,6 +529,11 @@ StageHelper.prototype.submit = function () {
submitSapeventForm(this.collectData(), this.formAction); submitSapeventForm(this.collectData(), this.formAction);
}; };
StageHelper.prototype.submitVisible = function () {
this.markVisiblesAsAdded();
submitSapeventForm(this.collectData(), this.formAction);
};
// Extract data from the table // Extract data from the table
StageHelper.prototype.collectData = function () { StageHelper.prototype.collectData = function () {
var data = {}; var data = {};
@ -515,10 +543,24 @@ StageHelper.prototype.collectData = function () {
return data; return data;
}; };
StageHelper.prototype.markVisiblesAsAdded = function () {
this.iterateStageTab(false, function (row) {
var name = row.cells[this.colIndex["name"]].innerText;
var cellStatus = row.cells[this.colIndex["status"]];
// TODO refacotr, unify updateRow logic
if (row.style.display === "" && row.className === "local") { // visible
this.updateRow(row, this.STATUS.add);
} else {
this.updateRow(row, this.STATUS.reset);
}
});
};
// Table iteration helper // Table iteration helper
StageHelper.prototype.iterateStageTab = function (changeMode, cb /*, ...*/) { StageHelper.prototype.iterateStageTab = function (changeMode, cb /*, ...*/) {
var restArgs = Array.prototype.slice.call(arguments, 2); var restArgs = Array.prototype.slice.call(arguments, 2);
var table = this.dom.stageTab; var table = this.dom.stageTab;
var retTotal = 0;
if (changeMode) { if (changeMode) {
var scrollOffset = window.pageYOffset; var scrollOffset = window.pageYOffset;
@ -529,7 +571,8 @@ StageHelper.prototype.iterateStageTab = function (changeMode, cb /*, ...*/) {
var tbody = table.tBodies[b]; var tbody = table.tBodies[b];
for (var r = 0, rN = tbody.rows.length; r < rN; r++) { for (var r = 0, rN = tbody.rows.length; r < rN; r++) {
var args = [tbody.rows[r]].concat(restArgs); var args = [tbody.rows[r]].concat(restArgs);
cb.apply(this, args); // callback var retVal = cb.apply(this, args); // callback
if (typeof retVal === "number") retTotal += retVal;
} }
} }
@ -537,6 +580,8 @@ StageHelper.prototype.iterateStageTab = function (changeMode, cb /*, ...*/) {
this.dom.stageTab.style.display = ""; this.dom.stageTab.style.display = "";
window.scrollTo(0, scrollOffset); window.scrollTo(0, scrollOffset);
} }
return retTotal;
}; };
/********************************************************** /**********************************************************

View File

@ -301,10 +301,15 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_STAGE IMPLEMENTATION.
ro_html->add( '<td class="indent5em">' ). ro_html->add( '<td class="indent5em">' ).
ro_html->add_a( iv_act = 'errorStub(event)' " Will be reinit by JS ro_html->add_a( iv_act = 'errorStub(event)' " Will be reinit by JS
iv_typ = zif_abapgit_html=>c_action_type-onclick iv_typ = zif_abapgit_html=>c_action_type-onclick
iv_id = 'commitButton' iv_id = 'commitSelectedButton'
iv_style = 'display: none' iv_style = 'display: none'
iv_txt = 'Commit (<span id="fileCounter"></span>)' iv_txt = 'Commit selected (<span class="counter"></span>)'
iv_opt = zif_abapgit_html=>c_html_opt-strong ) ##NO_TEXT. iv_opt = zif_abapgit_html=>c_html_opt-strong ) ##NO_TEXT.
ro_html->add_a( iv_act = 'errorStub(event)' " Will be reinit by JS
iv_typ = zif_abapgit_html=>c_action_type-onclick
iv_id = 'commitFilteredButton'
iv_style = 'display: none'
iv_txt = 'Add <b>filtered</b> and commit (<span class="counter"></span>)' ) ##NO_TEXT.
ro_html->add_a( iv_act = |{ c_action-stage_all }| ro_html->add_a( iv_act = |{ c_action-stage_all }|
iv_id = 'commitAllButton' iv_id = 'commitAllButton'
iv_txt = lv_add_all_txt ) ##NO_TEXT. iv_txt = lv_add_all_txt ) ##NO_TEXT.
@ -510,10 +515,10 @@ CLASS ZCL_ABAPGIT_GUI_PAGE_STAGE IMPLEMENTATION.
ro_html->add( ' ids: {' ). ro_html->add( ' ids: {' ).
ro_html->add( ' stageTab: "stageTab",' ). ro_html->add( ' stageTab: "stageTab",' ).
ro_html->add( ' commitBtn: "commitButton",' ).
ro_html->add( ' commitAllBtn: "commitAllButton",' ). ro_html->add( ' commitAllBtn: "commitAllButton",' ).
ro_html->add( ' commitSelectedBtn: "commitSelectedButton",' ).
ro_html->add( ' commitFilteredBtn: "commitFilteredButton",' ).
ro_html->add( ' objectSearch: "objectSearch",' ). ro_html->add( ' objectSearch: "objectSearch",' ).
ro_html->add( ' fileCounter: "fileCounter"' ).
ro_html->add( ' }' ). ro_html->add( ' }' ).
ro_html->add( '}' ). ro_html->add( '}' ).