changeset a96bf0b0b065 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset&node=a96bf0b0b065
description:
        Add limit to search count

        issue10967
        review389301002
diffstat:

 CHANGELOG        |   3 +++
 src/common.js    |  18 ++++++++++++++----
 src/sao.less     |   4 ++--
 src/screen.js    |  14 +++++++++++---
 src/tab.js       |  22 ++++++++++++++++------
 src/view/form.js |   9 ++++++---
 src/view/tree.js |   2 +-
 7 files changed, 53 insertions(+), 19 deletions(-)

diffs (189 lines):

diff -r f93ba8359b28 -r a96bf0b0b065 CHANGELOG
--- a/CHANGELOG Sun Jan 23 13:32:59 2022 +0100
+++ b/CHANGELOG Sun Jan 30 01:42:23 2022 +0100
@@ -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
diff -r f93ba8359b28 -r a96bf0b0b065 src/common.js
--- a/src/common.js     Sun Jan 23 13:32:59 2022 +0100
+++ b/src/common.js     Sun Jan 30 01:42:23 2022 +0100
@@ -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;
         }
diff -r f93ba8359b28 -r a96bf0b0b065 src/sao.less
--- a/src/sao.less      Sun Jan 23 13:32:59 2022 +0100
+++ b/src/sao.less      Sun Jan 30 01:42:23 2022 +0100
@@ -264,8 +264,8 @@
 
     .navbar-text {
         .badge {
-            max-width: 5em;
-            min-width: 5em;
+            max-width: 7em;
+            min-width: 7em;
             overflow: hidden;
             text-overflow: ellipsis;
         }
diff -r f93ba8359b28 -r a96bf0b0b065 src/screen.js
--- a/src/screen.js     Sun Jan 23 13:32:59 2022 +0100
+++ b/src/screen.js     Sun Jan 30 01:42:23 2022 +0100
@@ -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));
diff -r f93ba8359b28 -r a96bf0b0b065 src/tab.js
--- a/src/tab.js        Sun Jan 23 13:32:59 2022 +0100
+++ b/src/tab.js        Sun Jan 30 01:42:23 2022 +0100
@@ -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();
diff -r f93ba8359b28 -r a96bf0b0b065 src/view/form.js
--- a/src/view/form.js  Sun Jan 23 13:32:59 2022 +0100
+++ b/src/view/form.js  Sun Jan 30 01:42:23 2022 +0100
@@ -1045,7 +1045,7 @@
                             '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 @@
                     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 @@
             if (current != this._current) {
                 return;
             }
+            if (value > 99) {
+                value = '99+';
+            }
             counter[idx] = value;
             this.set_label(name, domains, counter);
         },
@@ -4188,7 +4191,7 @@
             } 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) || '');
diff -r f93ba8359b28 -r a96bf0b0b065 src/view/tree.js
--- a/src/view/tree.js  Sun Jan 23 13:32:59 2022 +0100
+++ b/src/view/tree.js  Sun Jan 30 01:42:23 2022 +0100
@@ -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) {

Reply via email to