Files
karma/assets/static/autocomplete.js
Łukasz Mierzwa 8a77d620fd Rename @status to @state
Fixes #104

@status filter was added to the master branch to support new status key from Alertmanager >=0.6.1
status ended up being nested in Alertmanager (it was added to solve AM issue 609 and that was a long PR with lots of changes), current unsee implementation ended being slightly off with how Alertmanager is naming this, it should actually be @state rather than @status.
2017-05-23 21:52:08 +01:00

74 lines
2.1 KiB
JavaScript

/* globals Bloodhound */ // typeahead.js
/* exported Autocomplete */
var Autocomplete = (function() {
var autocomplete;
var init = function() {
autocomplete = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "autocomplete.json?term=%QUERY",
wildcard: "%QUERY",
rateLimitBy: "throttle",
rateLimitWait: 300
},
sufficient: 12
});
};
var reset = function() {
autocomplete.clear();
};
var getAutocomplete = function() {
return autocomplete;
};
// this is used to generate quick filters for label modal
var generateHints = function(label_key, label_val) {
var hints = [];
if (label_key == "@state") {
// static list of hints for @silenced label
hints.push("@state=active");
hints.push("@state=suppressed");
hints.push("@state=unprocessed");
hints.push("@state!=active");
hints.push("@state!=suppressed");
hints.push("@state!=unprocessed");
} else {
// equal and non-equal hints for everything else
hints.push(label_key + "=" + label_val);
hints.push(label_key + "!=" + label_val);
// if there's space in the label generate regexp hints for partials
if (label_val.toString().indexOf(" ") >= 0) {
$.each(label_val.toString().split(" "), function(l, label_part){
hints.push(label_key + "=~" + label_part);
hints.push(label_key + "!~" + label_part);
});
}
// if value is an int generate less / more hints
if ($.isNumeric(label_val)) {
var valAsNumber = parseInt(label_val);
if (!isNaN(valAsNumber)) {
hints.push(label_key + ">" + label_val);
hints.push(label_key + "<" + label_val);
}
}
}
return hints;
};
return {
Init: init,
Reset: reset,
Autocomplete: getAutocomplete,
GenerateHints: generateHints
};
}());