Skip to content

Commit

Permalink
Reduced number of service calls when loading datatables.
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigo17 committed Jun 17, 2024
1 parent a806381 commit 0ff8d81
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 68 deletions.
15 changes: 2 additions & 13 deletions source/src/main/webapp/js/global/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ function showUnexpectedError(jqXHR, textStatus, errorThrown) {
* @param {Function} createdRowCallback callback function to be called after each row
* @return {Object} Return the dataTable object to use the api
*/
function createDataTableWithPermissions(tableConfigurations, callbackFunction, objectWaitingLayer, filtrableColumns, checkPermissions, userCallbackFunction, createdRowCallback, async) {
function createDataTableWithPermissions(tableConfigurations, callbackFunction, objectWaitingLayer, filtrableColumns, checkPermissions, userCallbackFunction, createdRowCallback, async = true) {
/**
* Define datatable config with tableConfiguration object received
*/
Expand Down Expand Up @@ -1711,18 +1711,7 @@ function createDataTableWithPermissions(tableConfigurations, callbackFunction, o
$("#" + tableConfigurations.divId).DataTable().ajax.reload();
}
} : false;
filtrableColumns = undefined;
if (filtrableColumns !== undefined) {
configs["fnServerParams"] = function (aoData) {

var filters = generateFiltersOnMultipleColumns(tableConfigurations.divId, filtrableColumns);
for (var f = 0; f < filters.length; f++) {
aoData.push(filters[f]);
}
aoData.push({name: "iSortCol_0", value: configs["aaSorting"][0][0]});
aoData.push({name: "sSortDir_0", value: configs["aaSorting"][0][1]});
};
}
configs["fnServerData"] = function (sSource, aoData, fnCallback, oSettings) {

var like = "";
Expand Down Expand Up @@ -2595,7 +2584,7 @@ function getHumanReadableDuration(durInSec, nbUnits = 2) {
return cnt1 + " " + unit + " " + getHumanReadableDuration(cnt2, (nbUnits - 1));
} else {
return cnt1 + " " + unit;
}
}
}


Expand Down
83 changes: 43 additions & 40 deletions source/src/main/webapp/js/global/table-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
/**
* Function that allow to reset the filter selected
* @param {type} oTable datatable object
* @param {columnNumber} columnNumber. If empty, reset all the column's filter
* @param {clearGlobalSearch} boolean. true if global search should be cleared.
* @param {int} columnNumber If empty, reset all the column's filter
* @param {boolean} clearGlobalSearch true if global search should be cleared.
* @param {boolean} doRedraw true if draw should be triggeres.
* @returns {undefined}
*/
function resetFilters(oTable, columnNumber, clearGlobalSearch) {
function resetFilters(oTable, columnNumber, clearGlobalSearch = false, doRedraw = true) {
var oSettings = oTable.fnSettings();
for (iCol = 0; iCol < oSettings.aoPreSearchCols.length; iCol++) {
/**
Expand All @@ -49,7 +50,9 @@ function resetFilters(oTable, columnNumber, clearGlobalSearch) {
if (clearGlobalSearch) {
oSettings.oPreviousSearch.sSearch = '';
}
oTable.fnDraw();
if (doRedraw) {
oTable.fnDraw();
}
}

function resetTooltip() {
Expand All @@ -66,7 +69,7 @@ function resetTooltip() {
*/
function filterOnColumn(tableId, column, value) {
var oTable = $('#' + tableId).dataTable();
resetFilters(oTable);
resetFilters(oTable, undefined, undefined, false);
var oSettings = oTable.fnSettings();
for (iCol = 0; iCol < oSettings.aoPreSearchCols.length; iCol++) {
if (oSettings.aoColumns[iCol].data === column) {
Expand All @@ -82,40 +85,40 @@ function filterOnColumn(tableId, column, value) {
* @param {type} searchColums > Array of columns
* @returns {undefined}
*/
function generateFiltersOnMultipleColumns(tableId, searchColumns) {
var filterConfiguration = Array();
/**
* Loop on searchColumns and get Parameter values >> Build an array of object
*/
var searchArray = new Array;
for (var searchColumn = 0; searchColumn < searchColumns.length; searchColumn++) {
var param = GetURLParameters(searchColumns[searchColumn]);
var searchObject = {
param: searchColumns[searchColumn],
values: param};
searchArray.push(searchObject);
}
/**
* Apply the filter to the table
*/
var oTable = $('#' + tableId).dataTable();
//resetFilters(oTable);
var oSettings = oTable.fnSettings();
for (iCol = 0; iCol < oSettings.aoPreSearchCols.length; iCol++) {
for (sCol = 0; sCol < searchArray.length; sCol++) {
if (oSettings.aoColumns[iCol].data === searchArray[sCol].param
&& searchArray[sCol].values.length !== 0) {
var filter = {
name: "sSearch_" + iCol,
value: searchArray[sCol].values.join(", ")};
filterConfiguration.push(filter);
}
}

}

return (filterConfiguration);
}
//function generateFiltersOnMultipleColumns(tableId, searchColumns) {
// var filterConfiguration = Array();
// /**
// * Loop on searchColumns and get Parameter values >> Build an array of object
// */
// var searchArray = new Array;
// for (var searchColumn = 0; searchColumn < searchColumns.length; searchColumn++) {
// var param = GetURLParameters(searchColumns[searchColumn]);
// var searchObject = {
// param: searchColumns[searchColumn],
// values: param};
// searchArray.push(searchObject);
// }
// /**
// * Apply the filter to the table
// */
// var oTable = $('#' + tableId).dataTable();
// //resetFilters(oTable);
// var oSettings = oTable.fnSettings();
// for (iCol = 0; iCol < oSettings.aoPreSearchCols.length; iCol++) {
// for (sCol = 0; sCol < searchArray.length; sCol++) {
// if (oSettings.aoColumns[iCol].data === searchArray[sCol].param
// && searchArray[sCol].values.length !== 0) {
// var filter = {
// name: "sSearch_" + iCol,
// value: searchArray[sCol].values.join(", ")};
// filterConfiguration.push(filter);
// }
// }
//
// }
//
// return (filterConfiguration);
//}

/**
* Function that apply filters on given datatable's columns
Expand All @@ -142,7 +145,7 @@ function applyFiltersOnMultipleColumns(tableId, searchColumns, fromURL) {

// Apply filter on table
var oTable = $('#' + tableId).dataTable();
resetFilters(oTable);
resetFilters(oTable, undefined, undefined, false);
var oSettings = oTable.fnSettings();
for (iCol = 0; iCol < oSettings.aoPreSearchCols.length; iCol++) {
for (sCol = 0; sCol < searchArray.length; sCol++) {
Expand Down
3 changes: 1 addition & 2 deletions source/src/main/webapp/js/pages/AppServiceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ function initPage() {
var configurations = new TableConfigurationsServerSide("soapLibrarysTable",
"ReadAppService", "contentTable",
aoColumnsFunc("soapLibrarysTable"), [1, 'asc']);
createDataTableWithPermissions(configurations, renderOptionsForAppService,
"#soapLibraryList", undefined, true);
createDataTableWithPermissions(configurations, renderOptionsForAppService, "#soapLibraryList", undefined, true);

$('#testCaseListModal').on('hidden.bs.modal', getTestCasesUsingModalCloseHandler);
}
Expand Down
4 changes: 3 additions & 1 deletion source/src/main/webapp/js/pages/Environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ function loadEnvTable(selectCountry, selectEnvironment, selectBuild, selectRevis
searchObject = {param: "system", values: selectSystem};
searchArray.push(searchObject);
}
applyFiltersOnMultipleColumns("environmentsTable", searchArray, false);
if (searchArray.length > 0) {
applyFiltersOnMultipleColumns("environmentsTable", searchArray, false);
}

return table;
}
Expand Down
18 changes: 7 additions & 11 deletions source/src/main/webapp/js/pages/TestCaseExecutionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ function initPage() {
searchArray.push(searchObject);
}

$.when(loadTable()).then(function () {
applyFiltersOnMultipleColumns("testCaseExecutionTable", searchArray, false);
});
loadTable(searchArray);
}

function loadTable() {
function loadTable(searchArray) {
//clear the old report content before reloading it
$("#testCaseExecution").empty();
$("#testCaseExecution").html('<table id="testCaseExecutionTable" class="table table-bordered table-hover display" name="testCaseExecutionTable">\n\
Expand All @@ -72,14 +70,12 @@ function loadTable() {

//configure and create the dataTable
var lengthMenu = [10, 25, 50, 100, 500, 1000];
var configurations = new TableConfigurationsServerSide("testCaseExecutionTable", contentUrl, "contentTable", aoColumnsFunc(), [3, 'desc'], lengthMenu);
configurations.aaSorting = [2, 'desc'];

var filtrableColumns = new Array("test", "testcase", "application", "country", "environment");
var configurations = new TableConfigurationsServerSide("testCaseExecutionTable", contentUrl, "contentTable", aoColumnsFunc(), [2, 'desc'], lengthMenu);
var table = createDataTableWithPermissions(configurations, undefined, "#testCaseExecution", searchArray, true, undefined, undefined);

$.when(createDataTableWithPermissions(configurations, undefined, "#testCaseExecution", filtrableColumns, undefined ,undefined, undefined, false)).then(function () {
return true;
});
if (searchArray.length > 0) {
applyFiltersOnMultipleColumns("testCaseExecutionTable", searchArray, false);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ function renderOptionsForExeQueue(data) {
var doc = new Doc();
var contentToAdd = "<div class='marginBottom10' id='blankSpace'>";
contentToAdd += "<button id='createBrpMassButton' type='button' class='btn btn-default margin-right5'><span class='glyphicon glyphicon-th-list'></span> " + doc.getDocLabel("page_global", "button_massAction") + "</button>";
contentToAdd += "<button id='refreshExecutionButton' type='button' class='btn btn-default margin-right5'><span class='glyphicon glyphicon-refresh'></span> " + doc.getDocLabel("page_global", "refresh") + "</button>";
contentToAdd += "<button id='selectDepButton' type='button' class='btn btn-default margin-right5'>" + doc.getDocLabel("page_testcaseexecutionqueue", "button_filterPendingWithDep") + "</button>";
contentToAdd += "<button id='selectPendingButton' type='button' class='btn btn-default margin-right5'>" + doc.getDocLabel("page_testcaseexecutionqueue", "button_filterPending") + "</button>";
contentToAdd += "<button id='selectRunningButton' type='button' class='btn btn-default margin-right5'>" + doc.getDocLabel("page_testcaseexecutionqueue", "button_filterExecuting") + "</button>";
Expand Down

0 comments on commit 0ff8d81

Please sign in to comment.