Skip to content

Commit

Permalink
Issue 48715: Limit Data Region "Show all" to a maximum number of rows (
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-nicka authored Dec 20, 2023
1 parent 748f0ab commit 54e372f
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions api/webapp/clientapi/dom/DataRegion.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ if (!LABKEY.DataRegions) {
//
// CONSTANTS
//
// Issue 48715: Limit the number of rows that can be displayed in a data region
var ALL_ROWS_MAX = 5_000;
var CUSTOM_VIEW_PANELID = '~~customizeView~~';
var DEFAULT_TIMEOUT = 30000;
var DEFAULT_TIMEOUT = 30_000;
var PARAM_PREFIX = '.param.';
var SORT_ASC = '+';
var SORT_DESC = '-';
Expand All @@ -31,7 +33,7 @@ if (!LABKEY.DataRegions) {
var SHOW_ROWS_PREFIX = '.showRows';
var VIEWNAME_PREFIX = '.viewName';

// 33536: These prefixes should match the URL parameter key exactly
// Issue 33536: These prefixes should match the URL parameter key exactly
var EXACT_MATCH_PREFIXES = [
COLUMNS_PREFIX,
CONTAINER_FILTER_NAME,
Expand Down Expand Up @@ -213,7 +215,7 @@ if (!LABKEY.DataRegions) {

if (config.buttonBar && config.buttonBar.items && LABKEY.Utils.isArray(config.buttonBar.items)) {
// Be tolerant of the caller passing in undefined items, as pageSize has been removed as an option. Strip
// them out so they don't cause problems downstream. See issue 34562
// them out so they don't cause problems downstream. See Issue 34562.
config.buttonBar.items = config.buttonBar.items.filter(function (value, index, arr) {
return value;
});
Expand Down Expand Up @@ -854,7 +856,7 @@ if (!LABKEY.DataRegions) {
var _selClickLock; // lock to prevent removing a row highlight that was just applied
var _selDocClick; // global (shared across all Data Region instances) click event handler instance

// 32898: Clear row highlights on document click
// Issue 32898: Clear row highlights on document click
var _onDocumentClick = function() {
if (_selClickLock) {
var form = _getFormSelector(_selClickLock);
Expand Down Expand Up @@ -1349,7 +1351,7 @@ if (!LABKEY.DataRegions) {
* Clear the message box contents.
*/
LABKEY.DataRegion.prototype.clearMessage = function() {
if (this.msgbox) this.msgbox.clear();
if (this.msgbox) this.msgbox.removeAll();
};

/**
Expand Down Expand Up @@ -1636,7 +1638,9 @@ if (!LABKEY.DataRegions) {

var offsets = [20, 40, 100, 250];
if (this.maxRows > 0 && offsets.indexOf(this.maxRows) === -1) {
offsets.push(this.maxRows);
if (!_isMaxRowsAllRows(this)) {
offsets.push(this.maxRows);
}
offsets = offsets.sort(function(a, b) { return a - b; });
}

Expand All @@ -1659,7 +1663,11 @@ if (!LABKEY.DataRegions) {
//bind functions to menu items
_getShowFirstSelector(this).click(_firstPage.bind(this));
_getShowLastSelector(this).click(_lastPage.bind(this));
_getShowAllSelector(this).click(_showRows.bind(this, this, 'all'));
_getShowAllSelector(this).click(this.showAllRows.bind(this));

if (_isMaxRowsAllRows(this) && this.totalRows > this.maxRows) {
this.addMessage('<span><b>Show all:</b> Displaying the first ' + ALL_ROWS_MAX.toLocaleString() + ' rows. Use paging to see more results.</span>');
}

for (var key in offsetIds) {
if (offsetIds.hasOwnProperty(key)) {
Expand Down Expand Up @@ -1715,7 +1723,7 @@ if (!LABKEY.DataRegions) {
};

var _showAllEnabled = function(region) {
return _showFirstEnabled(region) || _showLastEnabled(region);
return (_showFirstEnabled(region) || _showLastEnabled(region)) && !_isMaxRowsAllRows(region);
};

var _getPaginationText = function(region) {
Expand Down Expand Up @@ -1764,11 +1772,15 @@ if (!LABKEY.DataRegions) {
return false;
};

var _isMaxRowsAllRows = function(region) {
return region.maxRows === ALL_ROWS_MAX;
};

/**
* Forces the grid to show all rows, without any paging
* Forces the grid to show all rows, up to ALL_ROWS_MAX, without any paging
*/
LABKEY.DataRegion.prototype.showAllRows = function() {
_showRows(this, 'all');
_setMaxRows.bind(this, ALL_ROWS_MAX)();
};

/**
Expand Down Expand Up @@ -1912,7 +1924,7 @@ if (!LABKEY.DataRegions) {
ctxBar.find('.ctx-clear-all').off('click').on('click', $.proxy(this.clearAllFilters, this));
}

// 35396: Support ButtonBarOptions <onRender>
// Issue 35396: Support ButtonBarOptions <onRender>
if (LABKEY.Utils.isArray(this.buttonBarOnRenders)) {
for (var i=0; i < this.buttonBarOnRenders.length; i++) {
var scriptFnName = this.buttonBarOnRenders[i];
Expand Down Expand Up @@ -3212,7 +3224,7 @@ if (!LABKEY.DataRegions) {
return;
}
else if (REQUIRE_NAME_PREFIX.hasOwnProperty(key)) {
// 26686: Block known parameters, should be prefixed by region name
// Issue 26686: Block known parameters, should be prefixed by region name
return;
}

Expand Down Expand Up @@ -3531,7 +3543,7 @@ if (!LABKEY.DataRegions) {

msg += "&nbsp;" + "<span class='labkey-button select-none'>Select None</span>";
var showOpts = [];
if (region.showRows !== 'all')
if (region.showRows !== 'all' && !_isMaxRowsAllRows(region))
showOpts.push("<span class='labkey-button show-all'>Show All</span>");
if (region.showRows !== 'selected')
showOpts.push("<span class='labkey-button show-selected'>Show Selected</span>");
Expand Down Expand Up @@ -3759,7 +3771,7 @@ if (!LABKEY.DataRegions) {

_processButtonBar(region, json);

// 10505: add non-removable sorts and filters to json (not url params).
// Issue 10505: add non-removable sorts and filters to json (not url params).
if (region.sort || region.filters || region.aggregates) {
json.filters = {};

Expand Down Expand Up @@ -3927,9 +3939,7 @@ if (!LABKEY.DataRegions) {

if (newParams) {
newParams.forEach(function(pair) {
//
// Filters may repeat themselves #25337
//
// Issue 25337: Filters may repeat themselves
if (_isFilter(region, pair[0])) {
if (params[pair[0]] == undefined) {
params[pair[0]] = [];
Expand All @@ -3955,10 +3965,7 @@ if (!LABKEY.DataRegions) {
});
}

//
// 40226: Don't include parameters that are being logically excluded
//

// Issue 40226: Don't include parameters that are being logically excluded
if (skipPrefixes) {
skipPrefixes.forEach(function(skipKey) {
if (params.hasOwnProperty(skipKey) && !newParamPrefixes.hasOwnProperty(skipKey)) {
Expand Down Expand Up @@ -4029,7 +4036,7 @@ if (!LABKEY.DataRegions) {
_showSelectMessage(region, msg);
}

// 10566: for javascript perf on IE stash the requires selection buttons
// Issue 10566: for javascript perf on IE stash the requires selection buttons
if (!region._requiresSelectionButtons) {
// escape ', ", and \
var escaped = region.name.replace(/('|"|\\)/g, "\\$1");
Expand Down Expand Up @@ -4294,7 +4301,7 @@ if (!LABKEY.DataRegions) {
.on('resize', resizeTask)
.on('scroll', onScroll);
$(document)
.on('DOMNodeInserted', domTask); // 13121
.on('DOMNodeInserted', domTask); // Issue 13121

// ensure that resize/scroll fire at the end of initialization
domTask();
Expand Down

0 comments on commit 54e372f

Please sign in to comment.