aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/stores/flowstore.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/js/stores/flowstore.js')
-rw-r--r--web/src/js/stores/flowstore.js26
1 files changed, 17 insertions, 9 deletions
diff --git a/web/src/js/stores/flowstore.js b/web/src/js/stores/flowstore.js
index 60cd2605..37eb40eb 100644
--- a/web/src/js/stores/flowstore.js
+++ b/web/src/js/stores/flowstore.js
@@ -104,38 +104,46 @@ SortByInsertionOrder.prototype.key = function (flow) {
var default_sort = (new SortByInsertionOrder()).key;
-function FlowView(store, filt, sort) {
+function FlowView(store, filt, sortfun) {
EventEmitter.call(this);
filt = filt || function (flow) {
return true;
};
- sort = sort || default_sort;
+ sortfun = sortfun || default_sort;
this.store = store;
this.store._views.push(this);
- this.recalculate(this.store._flow_list, filt, sort);
+ this.recalculate(this.store._flow_list, filt, sortfun);
}
_.extend(FlowView.prototype, EventEmitter.prototype, {
close: function () {
this.store._views = _.without(this.store._views, this);
},
- recalculate: function (flows, filt, sort) {
+ recalculate: function (flows, filt, sortfun) {
if (filt) {
this.filt = filt;
}
- if (sort) {
- this.sort = sort;
+ if (sortfun) {
+ this.sortfun = sortfun;
}
+
+ //Ugly workaround: Call .sortfun() for each flow once in order,
+ //so that SortByInsertionOrder make sense.
+ var i = flows.length;
+ while(i--){
+ this.sortfun(flows[i]);
+ }
+
this.flows = flows.filter(this.filt);
this.flows.sort(function (a, b) {
- return this.sort(a) - this.sort(b);
+ return this.sortfun(b) - this.sortfun(a);
}.bind(this));
this.emit("recalculate");
},
add: function (flow) {
if (this.filt(flow)) {
- var idx = _.sortedIndex(this.flows, flow, this.sort);
+ var idx = _.sortedIndex(this.flows, flow, this.sortfun);
if (idx === this.flows.length) { //happens often, .push is way faster.
this.flows.push(flow);
} else {
@@ -160,7 +168,7 @@ _.extend(FlowView.prototype, EventEmitter.prototype, {
} else if (!this.filt(flow)) {
this.remove(flow.id);
} else {
- if (this.sort(this.flows[idx]) !== this.sort(flow)) { //sortpos has changed
+ if (this.sortfun(this.flows[idx]) !== this.sortfun(flow)) { //sortpos has changed
this.remove(this.flows[idx]);
this.add(flow);
} else {