[TASK] Remove instead of add filter twice

This commit is contained in:
Xaver Maierhofer 2017-03-29 00:45:52 +02:00 committed by Geno
parent b9252c864f
commit 6a3986e588
2 changed files with 21 additions and 5 deletions

View File

@ -54,11 +54,22 @@ define(['filters/nodefilter'], function (NodeFilter) {
} }
function addFilter(d) { function addFilter(d) {
var newItem = true;
filters.forEach(function (f) {
if (f.getKey && f.getKey() === d.getKey()) {
removeFilter(f);
newItem = false;
}
});
if (newItem) {
filters.push(d); filters.push(d);
notifyObservers(); notifyObservers();
d.setRefresh(refresh); d.setRefresh(refresh);
refresh(); refresh();
} }
}
function removeFilter(d) { function removeFilter(d) {
filters = filters.filter(function (e) { filters = filters.filter(function (e) {

View File

@ -49,10 +49,15 @@ define(['helper'], function (helper) {
}; };
} }
function getKey() {
return value.concat(name);
}
return { return {
run: run, run: run,
setRefresh: setRefresh, setRefresh: setRefresh,
render: render render: render,
getKey: getKey
}; };
}; };
}); });