Skip to content

Commit

Permalink
Display the current path location in the "Codebase" panel #1158
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Apr 22, 2024
1 parent 9375ec0 commit 10ef81b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

v34.5.0 (unreleased)
--------------------

- Display the current path location in the "Codebase" panel as a navigation breadcrumbs.
https://github.com/nexB/scancode.io/issues/1158

v34.4.0 (2024-04-22)
--------------------

Expand Down
16 changes: 15 additions & 1 deletion scanpipe/templates/scanpipe/panels/project_codebase.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
<nav id="codebase-navigation" class="panel is-info">
<p class="panel-heading py-2 is-size-6">
Codebase
{% if current_dir and current_dir != "." %}
<span class="tag ml-2">
{% for dir_name, full_path in codebase_breadcrumbs.items %}
{% if not forloop.last %}
<a href="#" hx-target="#codebase-navigation" hx-swap="outerHTML" hx-get="{{ project_details_url }}codebase/?current_dir={{ full_path }}">
{{ dir_name }}
</a>
<span class="mr-1">/</span>
{% else %}
{{ dir_name }}/
{% endif %}
{% endfor %}
</span>
{% endif %}
</p>
{% for node in codebase_tree %}
{% if node.is_dir %}
<a class="panel-block" href="#" hx-target="#codebase-navigation" hx-swap="outerHTML" hx-get="{{ project.get_absolute_url }}codebase/?current_dir={{ node.location }}">
<a class="panel-block" href="#" hx-target="#codebase-navigation" hx-swap="outerHTML" hx-get="{{ project_details_url }}codebase/?current_dir={{ node.location }}">
<span class="panel-icon"><i class="fa-solid fa-folder"></i></span>
{{ node.name }}
</a>
Expand Down
16 changes: 16 additions & 0 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,19 @@ def get_node(name, is_dir, location):

return tree

@staticmethod
def get_breadcrumbs(current_dir):
breadcrumbs = {}
path_segments = current_dir.removeprefix("./").split("/")
last_path = ""

for segment in path_segments:
if segment:
last_path += f"{segment}/"
breadcrumbs[segment] = last_path

return breadcrumbs

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
current_dir = self.request.GET.get("current_dir") or "."
Expand All @@ -1046,6 +1059,9 @@ def get_context_data(self, **kwargs):

context["current_dir"] = current_dir
context["codebase_tree"] = codebase_tree
context["codebase_breadcrumbs"] = self.get_breadcrumbs(current_dir)
context["project_details_url"] = self.object.get_absolute_url()

return context


Expand Down

0 comments on commit 10ef81b

Please # to comment.