Files
karma/assets/static/autocomplete.js
Łukasz Mierzwa 0d55311a9d Replace @silenced & @inhibited filters with @status
Now that Alertmanager provides status=(unprocessed|suppressed|active) in the API it doesn't make sense to keep having separate filters for each value, merge @silenced & @inhibited into a single filter, update docs and UI
2017-05-05 13:56:48 +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 == "@status") {
// static list of hints for @silenced label
hints.push("@status=active");
hints.push("@status=suppressed");
hints.push("@status=unprocessed");
hints.push("@status!=active");
hints.push("@status!=suppressed");
hints.push("@status!=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
};
}());