Skip to content

Commit a848cea

Browse files
authored
feat: display layers information (created_by, comment) in tree view (#2102)
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent d840db4 commit a848cea

7 files changed

Lines changed: 162 additions & 143 deletions

File tree

scanpipe/templates/scanpipe/resource_tree.html

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,21 @@
2020
<div id="resource-tree-container" class="container is-fluid p-0">
2121
<div class="resizable-container is-flex">
2222
<div id="left-pane" class="left-pane px-2">
23-
{% include "scanpipe/tree/resource_left_pane_header.html" only %}
24-
<div id="resource-tree">
25-
{% include "scanpipe/tree/resource_left_pane_tree.html" with children=children path=path %}
26-
</div>
23+
{% include 'scanpipe/tree/resource_left_pane.html' %}
2724
</div>
2825
<div id="resizer" class="resizer"></div>
2926
<div id="right-pane" class="right-pane px-3">
30-
<div
31-
{% if resource.is_file %}
32-
hx-get="{% url 'resource_detail' project.slug resource.path %}"
33-
{% elif path %}
34-
hx-get="{% url 'project_resource_tree_right_pane' project.slug path %}"
35-
{% else %}
36-
hx-get="{% url 'project_resource_tree_right_pane' project.slug %}"
37-
{% endif %}
38-
hx-trigger="load"
39-
hx-target="this">
40-
</div>
27+
<div
28+
{% if resource.is_file %}
29+
hx-get="{% url 'resource_detail' project.slug resource.path %}"
30+
{% elif path %}
31+
hx-get="{% url 'project_resource_tree_right_pane' project.slug path %}"
32+
{% else %}
33+
hx-get="{% url 'project_resource_tree_right_pane' project.slug %}"
34+
{% endif %}
35+
hx-trigger="load"
36+
hx-target="this">
37+
</div>
4138
</div>
4239
</div>
4340
</div>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% include "scanpipe/tree/resource_left_pane_header.html" only %}
2+
<div id="resource-tree">
3+
{% include "scanpipe/tree/resource_left_pane_tree.html" with children=children path=path %}
4+
</div>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<div class="is-flex is-align-items-center mb-2">
22
<button
33
id="hide-left-pane"
4-
class="button is-light px-2 has-tooltip"
4+
class="button is-borderless px-2 has-tooltip"
55
data-title="Hide resource tree"
66
data-tooltip-position="bottom right">
77
<i class="fa-solid fa-square-caret-left"></i>
88
</button>
9-
<div class="is-size-5 has-text-weight-semibold ml-2">
9+
<div class="is-size-5 has-text-weight-semibold ml-1">
1010
Resources
1111
</div>
1212
</div>

scanpipe/templates/scanpipe/tree/resource_path_breadcrumb.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<nav class="breadcrumb is-flex is-align-items-center mb-2" aria-label="breadcrumbs">
22
<button
33
id="expand-left-pane"
4-
class="button is-light px-2 mr-2 has-tooltip is-hidden"
4+
class="button is-borderless px-2 mr-1 has-tooltip is-hidden"
55
data-title="Show resource tree"
66
data-tooltip-position="bottom right">
77
<i class="fa-solid fa-square-caret-right"></i>
Lines changed: 60 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,63 @@
1-
{% if resources %}
2-
<table class="table is-bordered is-hoverable is-fullwidth">
3-
<thead class="is-sticky">
4-
<tr>
5-
<th style="min-width:200px;">Name</th>
6-
<th>Status</th>
7-
<th>Language</th>
8-
<th>License</th>
9-
<th>Alert</th>
10-
</tr>
11-
</thead>
12-
<tbody>
13-
{% if parent_path %}
14-
<tr
15-
class="expand-in-tree is-clickable"
16-
data-path="{{ parent_path }}"
17-
hx-get="{% url 'project_resource_tree_right_pane' project.slug parent_path %}"
18-
hx-target="#right-pane"
19-
hx-push-url="{% url 'project_resource_tree' project.slug parent_path %}">
20-
<td colspan="5">
21-
<div class="is-flex is-align-items-center">
22-
<span class="icon is-small mr-2">
23-
<i class="fas fa-folder"></i>
24-
</span>
25-
<span class="has-text-weight-semibold">..</span>
26-
</div>
27-
</td>
28-
</tr>
29-
{% endif %}
30-
{% for resource in resources %}
31-
<tr>
32-
<td class="break-all" style="min-width: 100px;">
33-
<div class="is-flex is-align-items-center">
34-
<span class="icon is-small mr-2">
35-
{% if resource.is_dir %}
36-
<i class="fas fa-folder"></i>
37-
{% else %}
38-
<i class="far fa-file"></i>
39-
{% endif %}
40-
</span>
41-
{% if resource.is_dir %}
42-
<a
43-
class="expand-in-tree"
44-
href="{% url 'project_resource_tree' project.slug resource.path %}"
45-
data-path="{{ resource.path }}"
46-
hx-get="{% url 'project_resource_tree_right_pane' project.slug resource.path %}"
47-
hx-target="#right-pane"
48-
hx-push-url="{% url 'project_resource_tree' project.slug resource.path %}">
49-
{{ resource.name }}
50-
</a>
51-
{% else %}
52-
<a
53-
href="{% url 'resource_detail' project.slug resource.path %}"
54-
hx-get="{% url 'resource_detail' project.slug resource.path %}"
55-
hx-target="#right-pane"
56-
hx-push-url="{% url 'project_resource_tree' project.slug resource.path %}">
57-
{{ resource.name }}
58-
</a>
59-
{% endif %}
60-
{% if resource.tag %}
61-
<span class="tag is-rounded ml-2">{{ resource.tag }}</span>
62-
{% endif %}
63-
</div>
64-
</td>
65-
<td>
66-
{{ resource.status }}
67-
</td>
68-
<td class="break-all">
69-
{{ resource.programming_language }}
70-
</td>
71-
<td>
72-
{{ resource.detected_license_expression }}
73-
</td>
74-
<td>
75-
{{ resource.compliance_alert }}
76-
</td>
77-
</tr>
78-
{% endfor %}
79-
</tbody>
80-
</table>
81-
82-
{% if is_paginated %}
83-
<nav class="pagination is-centered mt-4" role="navigation">
84-
{% if page_obj.has_previous %}
85-
<a
86-
class="pagination-previous"
87-
hx-get="{% url 'project_resource_tree_right_pane' project.slug path %}?page={{ page_obj.previous_page_number }}"
88-
hx-target="#right-pane"
89-
hx-push-url="{% url 'project_resource_tree' project.slug path %}?page={{ page_obj.previous_page_number }}">
90-
Previous
91-
</a>
92-
{% endif %}
93-
{% if page_obj.has_next %}
94-
<a
95-
class="pagination-next"
96-
hx-get="{% url 'project_resource_tree_right_pane' project.slug path%}?page={{ page_obj.next_page_number }}"
1+
<table class="table is-bordered is-hoverable is-fullwidth">
2+
<thead class="is-sticky">
3+
<tr>
4+
<th style="min-width:200px;">Name</th>
5+
<th>Status</th>
6+
<th>Language</th>
7+
<th>License</th>
8+
<th>Alert</th>
9+
</tr>
10+
</thead>
11+
<tbody>
12+
{% if parent_path %}
13+
<tr
14+
class="expand-in-tree is-clickable"
15+
data-path="{{ parent_path }}"
16+
hx-get="{% url 'project_resource_tree_right_pane' project.slug parent_path %}"
9717
hx-target="#right-pane"
98-
hx-push-url="{% url 'project_resource_tree' project.slug path %}?page={{ page_obj.next_page_number }}">
99-
Next page
100-
</a>
101-
{% endif %}
102-
<ul class="pagination-list">
103-
<li>
104-
<span class="pagination-ellipsis">
105-
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
106-
</span>
107-
</li>
108-
</ul>
109-
</nav>
110-
{% endif %}
111-
{% else %}
112-
<div class="has-text-centered p-6">
113-
<div class="icon is-large has-text-grey-light mb-3">
114-
<i class="fas fa-folder-open fa-3x"></i>
115-
</div>
116-
<p class="has-text-grey">
117-
{% if path %}
118-
No resources found in this directory.
119-
{% else %}
120-
Select a file or folder from the tree to view its contents.
18+
hx-push-url="{% url 'project_resource_tree' project.slug parent_path %}">
19+
<td colspan="5">
20+
<div class="is-flex is-align-items-center">
21+
<span class="icon is-small mr-2">
22+
<i class="fas fa-folder"></i>
23+
</span>
24+
<span class="has-text-weight-semibold">..</span>
25+
</div>
26+
</td>
27+
</tr>
12128
{% endif %}
122-
</p>
123-
</div>
29+
{% for resource in resources %}
30+
{% include 'scanpipe/tree/resource_table_resource_row.html' %}
31+
{% endfor %}
32+
</tbody>
33+
</table>
34+
35+
{% if is_paginated %}
36+
<nav class="pagination is-centered mt-4" role="navigation">
37+
{% if page_obj.has_previous %}
38+
<a
39+
class="pagination-previous"
40+
hx-get="{% url 'project_resource_tree_right_pane' project.slug path %}?page={{ page_obj.previous_page_number }}"
41+
hx-target="#right-pane"
42+
hx-push-url="{% url 'project_resource_tree' project.slug path %}?page={{ page_obj.previous_page_number }}">
43+
Previous
44+
</a>
45+
{% endif %}
46+
{% if page_obj.has_next %}
47+
<a
48+
class="pagination-next"
49+
hx-get="{% url 'project_resource_tree_right_pane' project.slug path%}?page={{ page_obj.next_page_number }}"
50+
hx-target="#right-pane"
51+
hx-push-url="{% url 'project_resource_tree' project.slug path %}?page={{ page_obj.next_page_number }}">
52+
Next page
53+
</a>
54+
{% endif %}
55+
<ul class="pagination-list">
56+
<li>
57+
<span class="pagination-ellipsis">
58+
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
59+
</span>
60+
</li>
61+
</ul>
62+
</nav>
12463
{% endif %}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<tr>
2+
<td class="break-all" style="min-width: 100px;">
3+
<div class="is-flex is-align-items-center">
4+
<span class="icon is-small mr-2">
5+
{% if resource.is_dir %}
6+
<i class="fas fa-folder"></i>
7+
{% else %}
8+
<i class="far fa-file"></i>
9+
{% endif %}
10+
</span>
11+
{% if resource.is_dir %}
12+
<a
13+
class="expand-in-tree"
14+
href="{% url 'project_resource_tree' project.slug resource.path %}"
15+
data-path="{{ resource.path }}"
16+
hx-get="{% url 'project_resource_tree_right_pane' project.slug resource.path %}"
17+
hx-target="#right-pane"
18+
hx-push-url="{% url 'project_resource_tree' project.slug resource.path %}">
19+
{{ resource.name }}
20+
</a>
21+
{% else %}
22+
<a
23+
href="{% url 'resource_detail' project.slug resource.path %}"
24+
hx-get="{% url 'resource_detail' project.slug resource.path %}"
25+
hx-target="#right-pane"
26+
hx-push-url="{% url 'project_resource_tree' project.slug resource.path %}">
27+
{{ resource.name }}
28+
</a>
29+
{% endif %}
30+
{% if resource.tag %}
31+
<span class="tag is-rounded ml-2">{{ resource.tag }}</span>
32+
{% endif %}
33+
{% if resource.extra_data.layer %}
34+
<div class="dropdown is-hoverable is-right is-wider-x2">
35+
<i class="fa-solid fa-circle-info dropdown-trigger is-cursor-help"></i>
36+
<div class="dropdown-menu" role="menu">
37+
<div class="dropdown-content">
38+
<div class="dropdown-item">
39+
<dl>
40+
<dt class="has-text-weight-bold">
41+
Created by:
42+
</dt>
43+
<dd>
44+
<code>
45+
{{ resource.extra_data.layer.created_by|truncatechars:100 }}
46+
</code>
47+
</dd>
48+
{% if resource.extra_data.layer.comment %}
49+
<dt class="has-text-weight-semibold mt-2">
50+
Comment:
51+
</dt>
52+
<dd>
53+
<code>
54+
{{ resource.extra_data.layer.comment|truncatechars:100 }}
55+
</code>
56+
</dd>
57+
{% endif %}
58+
</dl>
59+
</div>
60+
</div>
61+
</div>
62+
</div>
63+
{% endif %}
64+
</div>
65+
</td>
66+
<td>
67+
{{ resource.status }}
68+
</td>
69+
<td class="break-all">
70+
{{ resource.programming_language }}
71+
</td>
72+
<td>
73+
{{ resource.detected_license_expression }}
74+
</td>
75+
<td>
76+
{{ resource.compliance_alert }}
77+
</td>
78+
</tr>

scanpipe/views.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,13 +2759,14 @@ def get_node(self, package):
27592759

27602760

27612761
class ProjectResourceTreeView(ConditionalLoginRequired, generic.DetailView):
2762+
model = Project
27622763
template_name = "scanpipe/resource_tree.html"
27632764

27642765
def get(self, request, *args, **kwargs):
2765-
slug = self.kwargs.get("slug")
2766-
project = get_object_or_404(Project, slug=slug)
2766+
project = self.get_object()
27672767
path = self.kwargs.get("path", "")
2768-
parent_path = path if request.GET.get("tree_panel") == "true" else ""
2768+
is_tree_panel = request.GET.get("tree_panel") == "true"
2769+
parent_path = path if is_tree_panel else ""
27692770

27702771
children = (
27712772
project.codebaseresources.filter(parent_path=parent_path)
@@ -2786,7 +2787,7 @@ def get(self, request, *args, **kwargs):
27862787
"resource": resource,
27872788
}
27882789

2789-
if request.GET.get("tree_panel") == "true":
2790+
if is_tree_panel:
27902791
return render(
27912792
request, "scanpipe/tree/resource_left_pane_tree.html", context
27922793
)

0 commit comments

Comments
 (0)