django-spaghetti-and-meatballs
django-spaghetti-and-meatballs copied to clipboard
Here is how to add search feature
If anyone is interested of searching a certain model, here is how I've done it.
django_spaghetti/plate.html
{% block extra_scripts %}
<script src="//cdnjs.cloudflare.com/ajax/libs/vis/4.7.0/vis.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.7.0/vis.min.css" rel="stylesheet" type="text/css"/>
<script>
function searchNode(inputVal) {
var s = nodes.get({
filter: function (item) {
return item.label.toLowerCase().includes(inputVal.toLowerCase());
}
});
if (s.length > 0) {
let ids = s.map(node => node.id)
timeline.selectNodes(ids);
}
}
document.onkeydown = function (e) {
if ((e.metaKey || e.ctrlKey) && e.keyCode === 70) { // Cmd/Ctrl + F
e.preventDefault();
var inputVal = prompt("Enter node name to search:");
if (inputVal) {
searchNode(inputVal);
}
}
}
</script>
{% endblock %}