Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions scanpipe/templates/scanpipe/resource_tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,21 @@
<div id="resource-tree-container" class="container is-fluid p-0">
<div class="resizable-container is-flex">
<div id="left-pane" class="left-pane px-2">
{% include "scanpipe/tree/resource_left_pane_header.html" only %}
<div id="resource-tree">
{% include "scanpipe/tree/resource_left_pane_tree.html" with children=children path=path %}
</div>
{% include 'scanpipe/tree/resource_left_pane.html' %}
</div>
<div id="resizer" class="resizer"></div>
<div id="right-pane" class="right-pane px-3">
<div
{% if resource.is_file %}
hx-get="{% url 'resource_detail' project.slug resource.path %}"
{% elif path %}
hx-get="{% url 'project_resource_tree_right_pane' project.slug path %}"
{% else %}
hx-get="{% url 'project_resource_tree_right_pane' project.slug %}"
{% endif %}
hx-trigger="load"
hx-target="this">
</div>
<div
{% if resource.is_file %}
hx-get="{% url 'resource_detail' project.slug resource.path %}"
{% elif path %}
hx-get="{% url 'project_resource_tree_right_pane' project.slug path %}"
{% else %}
hx-get="{% url 'project_resource_tree_right_pane' project.slug %}"
{% endif %}
hx-trigger="load"
hx-target="this">
</div>
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions scanpipe/templates/scanpipe/tree/resource_left_pane.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% include "scanpipe/tree/resource_left_pane_header.html" only %}
<div id="resource-tree">
{% include "scanpipe/tree/resource_left_pane_tree.html" with children=children path=path %}
</div>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="is-flex is-align-items-center mb-2">
<button
id="hide-left-pane"
class="button is-light px-2 has-tooltip"
class="button is-borderless px-2 has-tooltip"
data-title="Hide resource tree"
data-tooltip-position="bottom right">
<i class="fa-solid fa-square-caret-left"></i>
</button>
<div class="is-size-5 has-text-weight-semibold ml-2">
<div class="is-size-5 has-text-weight-semibold ml-1">
Resources
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav class="breadcrumb is-flex is-align-items-center mb-2" aria-label="breadcrumbs">
<button
id="expand-left-pane"
class="button is-light px-2 mr-2 has-tooltip is-hidden"
class="button is-borderless px-2 mr-1 has-tooltip is-hidden"
data-title="Show resource tree"
data-tooltip-position="bottom right">
<i class="fa-solid fa-square-caret-right"></i>
Expand Down
181 changes: 60 additions & 121 deletions scanpipe/templates/scanpipe/tree/resource_table.html
Original file line number Diff line number Diff line change
@@ -1,124 +1,63 @@
{% if resources %}
<table class="table is-bordered is-hoverable is-fullwidth">
<thead class="is-sticky">
<tr>
<th style="min-width:200px;">Name</th>
<th>Status</th>
<th>Language</th>
<th>License</th>
<th>Alert</th>
</tr>
</thead>
<tbody>
{% if parent_path %}
<tr
class="expand-in-tree is-clickable"
data-path="{{ parent_path }}"
hx-get="{% url 'project_resource_tree_right_pane' project.slug parent_path %}"
hx-target="#right-pane"
hx-push-url="{% url 'project_resource_tree' project.slug parent_path %}">
<td colspan="5">
<div class="is-flex is-align-items-center">
<span class="icon is-small mr-2">
<i class="fas fa-folder"></i>
</span>
<span class="has-text-weight-semibold">..</span>
</div>
</td>
</tr>
{% endif %}
{% for resource in resources %}
<tr>
<td class="break-all" style="min-width: 100px;">
<div class="is-flex is-align-items-center">
<span class="icon is-small mr-2">
{% if resource.is_dir %}
<i class="fas fa-folder"></i>
{% else %}
<i class="far fa-file"></i>
{% endif %}
</span>
{% if resource.is_dir %}
<a
class="expand-in-tree"
href="{% url 'project_resource_tree' project.slug resource.path %}"
data-path="{{ resource.path }}"
hx-get="{% url 'project_resource_tree_right_pane' project.slug resource.path %}"
hx-target="#right-pane"
hx-push-url="{% url 'project_resource_tree' project.slug resource.path %}">
{{ resource.name }}
</a>
{% else %}
<a
href="{% url 'resource_detail' project.slug resource.path %}"
hx-get="{% url 'resource_detail' project.slug resource.path %}"
hx-target="#right-pane"
hx-push-url="{% url 'project_resource_tree' project.slug resource.path %}">
{{ resource.name }}
</a>
{% endif %}
{% if resource.tag %}
<span class="tag is-rounded ml-2">{{ resource.tag }}</span>
{% endif %}
</div>
</td>
<td>
{{ resource.status }}
</td>
<td class="break-all">
{{ resource.programming_language }}
</td>
<td>
{{ resource.detected_license_expression }}
</td>
<td>
{{ resource.compliance_alert }}
</td>
</tr>
{% endfor %}
</tbody>
</table>

{% if is_paginated %}
<nav class="pagination is-centered mt-4" role="navigation">
{% if page_obj.has_previous %}
<a
class="pagination-previous"
hx-get="{% url 'project_resource_tree_right_pane' project.slug path %}?page={{ page_obj.previous_page_number }}"
hx-target="#right-pane"
hx-push-url="{% url 'project_resource_tree' project.slug path %}?page={{ page_obj.previous_page_number }}">
Previous
</a>
{% endif %}
{% if page_obj.has_next %}
<a
class="pagination-next"
hx-get="{% url 'project_resource_tree_right_pane' project.slug path%}?page={{ page_obj.next_page_number }}"
<table class="table is-bordered is-hoverable is-fullwidth">
<thead class="is-sticky">
<tr>
<th style="min-width:200px;">Name</th>
<th>Status</th>
<th>Language</th>
<th>License</th>
<th>Alert</th>
</tr>
</thead>
<tbody>
{% if parent_path %}
<tr
class="expand-in-tree is-clickable"
data-path="{{ parent_path }}"
hx-get="{% url 'project_resource_tree_right_pane' project.slug parent_path %}"
hx-target="#right-pane"
hx-push-url="{% url 'project_resource_tree' project.slug path %}?page={{ page_obj.next_page_number }}">
Next page
</a>
{% endif %}
<ul class="pagination-list">
<li>
<span class="pagination-ellipsis">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
</span>
</li>
</ul>
</nav>
{% endif %}
{% else %}
<div class="has-text-centered p-6">
<div class="icon is-large has-text-grey-light mb-3">
<i class="fas fa-folder-open fa-3x"></i>
</div>
<p class="has-text-grey">
{% if path %}
No resources found in this directory.
{% else %}
Select a file or folder from the tree to view its contents.
hx-push-url="{% url 'project_resource_tree' project.slug parent_path %}">
<td colspan="5">
<div class="is-flex is-align-items-center">
<span class="icon is-small mr-2">
<i class="fas fa-folder"></i>
</span>
<span class="has-text-weight-semibold">..</span>
</div>
</td>
</tr>
{% endif %}
</p>
</div>
{% for resource in resources %}
{% include 'scanpipe/tree/resource_table_resource_row.html' %}
{% endfor %}
</tbody>
</table>

{% if is_paginated %}
<nav class="pagination is-centered mt-4" role="navigation">
{% if page_obj.has_previous %}
<a
class="pagination-previous"
hx-get="{% url 'project_resource_tree_right_pane' project.slug path %}?page={{ page_obj.previous_page_number }}"
hx-target="#right-pane"
hx-push-url="{% url 'project_resource_tree' project.slug path %}?page={{ page_obj.previous_page_number }}">
Previous
</a>
{% endif %}
{% if page_obj.has_next %}
<a
class="pagination-next"
hx-get="{% url 'project_resource_tree_right_pane' project.slug path%}?page={{ page_obj.next_page_number }}"
hx-target="#right-pane"
hx-push-url="{% url 'project_resource_tree' project.slug path %}?page={{ page_obj.next_page_number }}">
Next page
</a>
{% endif %}
<ul class="pagination-list">
<li>
<span class="pagination-ellipsis">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
</span>
</li>
</ul>
</nav>
{% endif %}
78 changes: 78 additions & 0 deletions scanpipe/templates/scanpipe/tree/resource_table_resource_row.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<tr>
<td class="break-all" style="min-width: 100px;">
<div class="is-flex is-align-items-center">
<span class="icon is-small mr-2">
{% if resource.is_dir %}
<i class="fas fa-folder"></i>
{% else %}
<i class="far fa-file"></i>
{% endif %}
</span>
{% if resource.is_dir %}
<a
class="expand-in-tree"
href="{% url 'project_resource_tree' project.slug resource.path %}"
data-path="{{ resource.path }}"
hx-get="{% url 'project_resource_tree_right_pane' project.slug resource.path %}"
hx-target="#right-pane"
hx-push-url="{% url 'project_resource_tree' project.slug resource.path %}">
{{ resource.name }}
</a>
{% else %}
<a
href="{% url 'resource_detail' project.slug resource.path %}"
hx-get="{% url 'resource_detail' project.slug resource.path %}"
hx-target="#right-pane"
hx-push-url="{% url 'project_resource_tree' project.slug resource.path %}">
{{ resource.name }}
</a>
{% endif %}
{% if resource.tag %}
<span class="tag is-rounded ml-2">{{ resource.tag }}</span>
{% endif %}
{% if resource.extra_data.layer %}
<div class="dropdown is-hoverable is-right is-wider-x2">
<i class="fa-solid fa-circle-info dropdown-trigger is-cursor-help"></i>
<div class="dropdown-menu" role="menu">
<div class="dropdown-content">
<div class="dropdown-item">
<dl>
<dt class="has-text-weight-bold">
Created by:
</dt>
<dd>
<code>
{{ resource.extra_data.layer.created_by|truncatechars:100 }}
</code>
</dd>
{% if resource.extra_data.layer.comment %}
<dt class="has-text-weight-semibold mt-2">
Comment:
</dt>
<dd>
<code>
{{ resource.extra_data.layer.comment|truncatechars:100 }}
</code>
</dd>
{% endif %}
</dl>
</div>
</div>
</div>
</div>
{% endif %}
</div>
</td>
<td>
{{ resource.status }}
</td>
<td class="break-all">
{{ resource.programming_language }}
</td>
<td>
{{ resource.detected_license_expression }}
</td>
<td>
{{ resource.compliance_alert }}
</td>
</tr>
9 changes: 5 additions & 4 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2759,13 +2759,14 @@ def get_node(self, package):


class ProjectResourceTreeView(ConditionalLoginRequired, generic.DetailView):
model = Project
template_name = "scanpipe/resource_tree.html"

def get(self, request, *args, **kwargs):
slug = self.kwargs.get("slug")
project = get_object_or_404(Project, slug=slug)
project = self.get_object()
path = self.kwargs.get("path", "")
parent_path = path if request.GET.get("tree_panel") == "true" else ""
is_tree_panel = request.GET.get("tree_panel") == "true"
parent_path = path if is_tree_panel else ""

children = (
project.codebaseresources.filter(parent_path=parent_path)
Expand All @@ -2786,7 +2787,7 @@ def get(self, request, *args, **kwargs):
"resource": resource,
}

if request.GET.get("tree_panel") == "true":
if is_tree_panel:
return render(
request, "scanpipe/tree/resource_left_pane_tree.html", context
)
Expand Down
Loading