(I #2624) Add preferences for the the grid's page size (#2626)

* Add preferences for the row display quantity

Be able to control the choices for the quantity of rows displayed.

* Added _checkPaginationSize(gridPageSize, defaultGridPageSize)

Added DataTableView._checkPaginationSize(gridPageSize, defaultGridPageSize), gridPageSize = smallest size.

* Update data-table-view.js

Fix missing semi-comma.

* Fix typeof gridPageSize != "object" not working for null

Fix typeof gridPageSize != "object" not working for null

* Update data-table-view.js

* Fix tableHeader instead of headerTable

Fix tableHeader instead of headerTable
This commit is contained in:
Antoine Beaubien 2020-06-18 04:35:37 -04:00 committed by GitHub
parent 69d6048c0e
commit 7793ffbbe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 9 deletions

View File

@ -32,6 +32,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
var theProject;
var thePreferences;
var ui = {};
var lang = (navigator.language|| navigator.userLanguage).split("-")[0];
@ -205,12 +206,35 @@ Refine.reinitializeProjectData = function(f, fError) {
$.getJSON(
"command/core/get-models?" + $.param({ project: theProject.id }), null,
function(data) {
for (var n in data) {
if (data.hasOwnProperty(n)) {
theProject[n] = data[n];
if (data.status == "error") {
alert(data.message);
if (fError) {
fError();
}
} else {
for (var n in data) {
if (data.hasOwnProperty(n)) {
theProject[n] = data[n];
}
}
$.post(
"command/core/get-all-preferences", null,
function(preferences) {
if (preferences.status == "error") {
alert(preferences.message);
if (fError) {
fError();
}
} else {
if (preferences != null) {
thePreferences = preferences;
}
f();
}
},
'json'
);
}
f();
},
'json'
);
@ -220,6 +244,30 @@ Refine.reinitializeProjectData = function(f, fError) {
);
};
Refine.getPreference = function(key, defaultValue) {
if(!thePreferences.hasOwnProperty(key)) { return defaultValue; }
return thePreferences[key];
}
Refine.setPreference = function(key, newValue) {
thePreferences[key] = newValue;
Refine.wrapCSRF(function(token) {
$.ajax({
async: false,
type: "POST",
url: "command/core/set-preference?" + $.param({ name: key }),
data: {
"value" : JSON.stringify(newValue),
csrf_token: token
},
success: function(data) { },
dataType: "json"
});
});
}
Refine._renameProject = function() {
var name = window.prompt($.i18n('core-index/new-proj-name'), theProject.metadata.name);
if (name === null) {

View File

@ -34,7 +34,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function DataTableView(div) {
this._div = div;
this._pageSize = 10;
this._gridPagesSizes = JSON.parse(Refine.getPreference("ui.gridPaginationSize", null));
this._gridPagesSizes = this._checkPaginationSize(this._gridPagesSizes, [ 5, 10, 25, 50 ]);
this._pageSize = ( this._gridPagesSizes[0] < 10 ) ? 10 : this._gridPagesSizes[0];
this._showRecon = true;
this._collapsedColumnNames = {};
this._sorting = { criteria: [] };
@ -214,9 +217,9 @@ DataTableView.prototype._renderPagingControls = function(pageSizeControls, pagin
}
$('<span>'+$.i18n('core-views/show')+': </span>').appendTo(pageSizeControls);
var sizes = [ 5, 10, 25, 50 ];
var renderPageSize = function(index) {
var pageSize = sizes[index];
var pageSize = self._gridPagesSizes[index];
var a = $('<a href="javascript:{}"></a>')
.addClass("viewPanel-pagingControls-page")
.appendTo(pageSizeControls);
@ -229,15 +232,37 @@ DataTableView.prototype._renderPagingControls = function(pageSizeControls, pagin
});
}
};
for (var i = 0; i < sizes.length; i++) {
for (var i = 0; i < self._gridPagesSizes.length; i++) {
renderPageSize(i);
}
$('<span>')
.text(theProject.rowModel.mode == "record-based" ? ' '+$.i18n('core-views/records') : ' '+$.i18n('core-views/rows'))
.appendTo(pageSizeControls);
};
DataTableView.prototype._checkPaginationSize = function(gridPageSize, defaultGridPageSize) {
var self = this;
var newGridPageSize = [];
if(gridPageSize == null || typeof gridPageSize != "object") return defaultGridPageSize;
for (var i = 0; i < gridPageSize.length; i++) {
if(typeof gridPageSize[i] == "number" && gridPageSize[i] > 0 && gridPageSize[i] < 10000)
newGridPageSize.push(gridPageSize[i]);
}
if(newGridPageSize.length < 2) return defaultGridPageSize;
var distinctValueFilter = (value, index, selfArray) => (selfArray.indexOf(value) == index);
newGridPageSize.filter(distinctValueFilter);
newGridPageSize.sort((a, b) => (a - b));
return newGridPageSize;
};
DataTableView.prototype._renderDataTables = function(table, tableHeader) {
var self = this;