django-spaghetti-and-meatballs icon indicating copy to clipboard operation
django-spaghetti-and-meatballs copied to clipboard

Here is how to add search feature

Open dc-p8 opened this issue 11 months ago • 0 comments

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 %}

dc-p8 avatar Mar 04 '24 16:03 dc-p8