Add limit to search count

issue10967
review389301002
This commit is contained in:
Cédric Krier
2022-01-30 01:42:23 +01:00
parent 868547be3d
commit b205a82250
7 changed files with 53 additions and 19 deletions
+3
View File
@@ -1,3 +1,6 @@
* Display the number of selected records
* Humanize the count result
* Add limit to search_count
* Call view_get for board view
* Limit board action domain to active id and ids
* Manage creatable attribute of view
+14 -4
View File
@@ -605,11 +605,21 @@
});
Sao.common.VIEW_SEARCH = new Sao.common.ViewSearch();
Sao.common.humanize = function(size) {
var sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
Sao.common.humanize = function(size, suffix) {
suffix = suffix || '';
var sizes = ['', 'K', 'M', 'G', 'T', 'P'];
for (var i =0, len = sizes.length; i < len; i++) {
if (size < 1000) {
return size.toPrecision(4) + ' ' + sizes[i];
if (size <= 1000) {
if (size % 1 === 0) {
size = '' + size;
} else {
size = size.toLocaleString(
Sao.i18n.BC47(Sao.i18n.getlang()), {
'minimumFractionDigits': 0,
'maximumFractionDigits': 2,
});
}
return size + sizes[i] + suffix;
}
size /= 1000;
}
+2 -2
View File
@@ -264,8 +264,8 @@ html.accesskey {
.navbar-text {
.badge {
max-width: 5em;
min-width: 5em;
max-width: 7em;
min-width: 7em;
overflow: hidden;
text-overflow: ellipsis;
}
+11 -3
View File
@@ -376,7 +376,11 @@
counter.html('&nbsp;');
counter.css('visibility', 'hidden');
} else {
counter.attr('title', count);
var title = Sao.common.humanize(count);
if (count >= 1000) {
title += '+';
}
counter.attr('title', title);
var text = count;
if (count > 99) {
text = '99+';
@@ -879,6 +883,9 @@
return r.deletable;
});
},
get count_limit() {
return this.limit * 100 + this.offset;
},
load_next_view: function() {
if (!jQuery.isEmptyObject(this.view_to_load)) {
var view_id;
@@ -1077,7 +1084,8 @@
if ((this.limit !== null) &&
(ids.length == this.limit)) {
count_prm = this.model.execute(
'search_count', [domain], context)
'search_count',
[domain, 0, this.count_limit], context)
.then(function(count) {
this.search_count = count;
return this.search_count;
@@ -1176,7 +1184,7 @@
var domain = ['AND', tab_domain[1], screen_domain];
this.screen_container.set_tab_counter(null, i);
this.group.model.execute(
'search_count', [domain], this.context)
'search_count', [domain, 0, 1000], this.context)
.then(function(count) {
this.screen_container.set_tab_counter(count, i);
}.bind(this));
+16 -6
View File
@@ -1452,7 +1452,11 @@
record_message: function(position, size, max_size, record_id) {
var name = "_";
if (position) {
name = position;
var selected = this.screen.selected_records.length;
name = '' + position;
if (selected > 1) {
name += '#' + selected;
}
}
var buttons = ['print', 'relate', 'email', 'save', 'attach'];
buttons.forEach(function(button_id){
@@ -1483,11 +1487,17 @@
'disabled', this.screen.readonly);
this.buttons.save.prop('disabled', this.screen.readonly);
var msg = name + ' / ' + size;
if ((size < max_size) &&
this.screen.limit !== null &&
(max_size > this.screen.limit)) {
msg += Sao.i18n.gettext(' of ') + max_size;
var msg;
if (size < max_size) {
msg = (
name + '@' +
Sao.common.humanize(size) + '/' +
Sao.common.humanize(max_size));
if (max_size >= this.screen.count_limit) {
msg += '+';
}
} else {
msg = name + '/' + Sao.common.humanize(size);
}
this.status_label.text(msg).attr('title', msg);
this.info_bar.message();
+6 -3
View File
@@ -1045,7 +1045,7 @@ function eval_pyson(value){
'method': (
'model.' + action.res_model + '.search_count'),
'params': [
['AND', domain, tab_domain], context],
['AND', domain, 0, tab_domain], 100, context],
}, Sao.Session.current_session).then(function(value) {
this._set_count(
value, i, current, counter,
@@ -1056,7 +1056,7 @@ function eval_pyson(value){
Sao.rpc({
'method': (
'model.' + action.res_model + '.search_count'),
'params': [domain, context],
'params': [domain, 0, 100, context],
}, Sao.Session.current_session).then(function(value) {
this._set_count(
value, 0, current, counter,
@@ -1069,6 +1069,9 @@ function eval_pyson(value){
if (current != this._current) {
return;
}
if (value > 99) {
value = '99+';
}
counter[idx] = value;
this.set_label(name, domains, counter);
},
@@ -4188,7 +4191,7 @@ function eval_pyson(value){
} else {
size = field.get(record).length;
}
this.size.val(Sao.common.humanize(size));
this.size.val(Sao.common.humanize(size, 'B'));
if (this.text) {
this.text.val(this.filename_field.get(record) || '');
+1 -1
View File
@@ -2573,7 +2573,7 @@
} else {
size = this.field.get(record).length;
}
var text = size? Sao.common.humanize(size) : '';
var text = size? Sao.common.humanize(size, 'B') : '';
cell.children('span').text(text).attr('title', text);
var button = cell.children('button');
if (!button.length) {