Skip to content

Commit 4238641

Browse files
authored
Display the current path location in the "Codebase" panel #1158 (#1173)
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 9375ec0 commit 4238641

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
v34.5.0 (unreleased)
5+
--------------------
6+
7+
- Display the current path location in the "Codebase" panel as a navigation breadcrumbs.
8+
https://github.com/nexB/scancode.io/issues/1158
9+
410
v34.4.0 (2024-04-22)
511
--------------------
612

scanpipe/templates/scanpipe/panels/project_codebase.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
<nav id="codebase-navigation" class="panel is-info">
22
<p class="panel-heading py-2 is-size-6">
33
Codebase
4+
{% if current_dir and current_dir != "." %}
5+
<span class="tag ml-2">
6+
{% for dir_name, full_path in codebase_breadcrumbs.items %}
7+
{% if not forloop.last %}
8+
<a href="#" hx-target="#codebase-navigation" hx-swap="outerHTML" hx-get="{{ project_details_url }}codebase/?current_dir={{ full_path }}">
9+
{{ dir_name }}
10+
</a>
11+
<span class="mr-1">/</span>
12+
{% else %}
13+
{{ dir_name }}/
14+
{% endif %}
15+
{% endfor %}
16+
</span>
17+
{% endif %}
418
</p>
519
{% for node in codebase_tree %}
620
{% if node.is_dir %}
7-
<a class="panel-block" href="#" hx-target="#codebase-navigation" hx-swap="outerHTML" hx-get="{{ project.get_absolute_url }}codebase/?current_dir={{ node.location }}">
21+
<a class="panel-block" href="#" hx-target="#codebase-navigation" hx-swap="outerHTML" hx-get="{{ project_details_url }}codebase/?current_dir={{ node.location }}">
822
<span class="panel-icon"><i class="fa-solid fa-folder"></i></span>
923
{{ node.name }}
1024
</a>

scanpipe/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,19 @@ def get_node(name, is_dir, location):
10331033

10341034
return tree
10351035

1036+
@staticmethod
1037+
def get_breadcrumbs(current_dir):
1038+
breadcrumbs = {}
1039+
path_segments = current_dir.removeprefix("./").split("/")
1040+
last_path = ""
1041+
1042+
for segment in path_segments:
1043+
if segment:
1044+
last_path += f"{segment}/"
1045+
breadcrumbs[segment] = last_path
1046+
1047+
return breadcrumbs
1048+
10361049
def get_context_data(self, **kwargs):
10371050
context = super().get_context_data(**kwargs)
10381051
current_dir = self.request.GET.get("current_dir") or "."
@@ -1046,6 +1059,9 @@ def get_context_data(self, **kwargs):
10461059

10471060
context["current_dir"] = current_dir
10481061
context["codebase_tree"] = codebase_tree
1062+
context["codebase_breadcrumbs"] = self.get_breadcrumbs(current_dir)
1063+
context["project_details_url"] = self.object.get_absolute_url()
1064+
10491065
return context
10501066

10511067

0 commit comments

Comments
 (0)