changeset f10e3870cc1b in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=f10e3870cc1b
description:
        Use standard Array.sort and do not update search_count when only ids

        The current implementation of Group.sort is not correct because it does 
not
        guarantee to replace all the records if the ordered list does not 
contain all
        the existing records. So it is better to use the standard Array.sort 
method.
        Also the search_count should not be updated when doing a search only 
for ids
        as the number of record does not change.

        issue8042
        review50731002
diffstat:

 src/model.js     |  11 -----------
 src/screen.js    |  28 +++++++++++++++-------------
 src/view/tree.js |  14 +++++++++++++-
 3 files changed, 28 insertions(+), 25 deletions(-)

diffs (84 lines):

diff -r 66081dfaef23 -r f10e3870cc1b src/model.js
--- a/src/model.js      Sun Feb 03 20:19:41 2019 +0100
+++ b/src/model.js      Sun Feb 03 20:29:41 2019 +0100
@@ -465,17 +465,6 @@
             };
             return jQuery.when().then(browse_child);
         };
-        array.sort = function(ids) {
-                var id2record = {};
-                this.forEach(function(record) {
-                    id2record[record.id] = record;
-                });
-                ids.filter(function(id) {
-                    return id in id2record;
-                }).forEach(function(id, i){
-                    this[i] = id2record[id];
-                }.bind(this));
-        };
         return array;
     };
 
diff -r 66081dfaef23 -r f10e3870cc1b src/screen.js
--- a/src/screen.js     Sun Feb 03 20:19:41 2019 +0100
+++ b/src/screen.js     Sun Feb 03 20:29:41 2019 +0100
@@ -921,20 +921,22 @@
                     }.bind(this));
             }.bind(this);
             return search().then(function(ids) {
-                    this.search_count = ids.length;
                     var count_prm = jQuery.when(this.search_count);
-                    if ((!only_ids) &&
-                        ((this.limit !== null) &&
-                            (ids.length == this.limit))) {
-                        count_prm = this.model.execute(
-                            'search_count', [domain], context)
-                            .then(function(count) {
-                                this.search_count = count;
-                                return this.search_count;
-                            }.bind(this), function() {
-                                this.search_count = 0;
-                                return this.search_count;
-                            }.bind(this));
+                    if (!only_ids) {
+                        if ((this.limit !== null) &&
+                            (ids.length == this.limit)) {
+                            count_prm = this.model.execute(
+                                'search_count', [domain], context)
+                                .then(function(count) {
+                                    this.search_count = count;
+                                    return this.search_count;
+                                }.bind(this), function() {
+                                    this.search_count = 0;
+                                    return this.search_count;
+                                }.bind(this));
+                        } else {
+                            this.search_count = ids.length;
+                        }
                     }
                     return count_prm.then(function(count) {
                         this.screen_container.but_next.prop('disabled',
diff -r 66081dfaef23 -r f10e3870cc1b src/view/tree.js
--- a/src/view/tree.js  Sun Feb 03 20:19:41 2019 +0100
+++ b/src/view/tree.js  Sun Feb 03 20:29:41 2019 +0100
@@ -300,7 +300,19 @@
                     (this.screen.group.parent)) {
                 this.screen.search_filter(search_string, true).then(
                 function(ids) {
-                    this.screen.group.sort(ids);
+                    this.screen.group.sort(function(a, b) {
+                        a = ids.indexOf(a.id);
+                        a = a < 0 ? ids.length : a;
+                        b = ids.indexOf(b.id);
+                        b = b < 0 ? ids.length : b;
+                        if (a < b) {
+                            return -1;
+                        } else if (a > b) {
+                            return 1;
+                        } else {
+                            return 0;
+                        }
+                    });
                     this.screen.display();
                 }.bind(this));
             } else {

Reply via email to