Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here is how to add search feature #38

Open
dc-p8 opened this issue Mar 4, 2024 · 0 comments
Open

Here is how to add search feature #38

dc-p8 opened this issue Mar 4, 2024 · 0 comments

Comments

@dc-p8
Copy link

dc-p8 commented Mar 4, 2024

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 %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant