Skip to content
Browse files

User notifications about matched/unmatched topics.

  • Loading branch information...
1 parent 046e825 commit 815490342cc49fa66605b9364c1e85eb32ca55f2 @ralphbean committed
Showing with 23 additions and 1 deletion.
  1. +23 −1 busmon/public/javascript/busmon.js
View
24 busmon/public/javascript/busmon.js
@@ -12,19 +12,41 @@ $.extend(busmon, {
},
apply_new_regex: function(value) {
- // Take in the new value
+ // Take in the new value. This will affect all callbacks passed
+ // through busmon.filter(callback, json);
var re = new RegExp(value);
busmon.regex = re;
// Hard-coded id here... :/
var selector = "topics-bar-chart";
+ // We're going to run through all the items in the bar chart and remove
+ // any that are not matched by the new regular expr.
+ var removed = [];
+ var kept = [];
var keys = tw2.d3.util.keys(selector);
for (var i = 0; i < keys.length; i++) {
if (!busmon.regex.test(keys[i])) {
tw2.d3.util.remove_key(selector, keys[i]);
+ removed.push(keys[i]);
+ } else {
+ kept.push(keys[i]);
}
}
+
+ // Notify the user about matches
+ if ( value == "" ) {
+ $.gritter.add({title: "busmon", text: "Filter removed.",});
+ } else {
+ $.gritter.add({
+ title: "busmon",
+ text: "Matched " + kept.join(", "),
+ });
+ $.gritter.add({
+ title: "busmon",
+ text: "Removed " + removed.join(", "),
+ });
+ }
},
});

0 comments on commit 8154903

Please sign in to comment.
Something went wrong with that request. Please try again.