Skip to content

Commit

Permalink
Add resources license summary panel in the project details view #355 (#…
Browse files Browse the repository at this point in the history
…916)

Signed-off-by: Thomas Druez <[email protected]>
  • Loading branch information
tdruez authored Sep 11, 2023
1 parent ade2953 commit 5518a94
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ v32.6.1 (unreleased)
- Add support for webhook subscriptions in project clone.
https://github.com/nexB/scancode.io/pull/910

- Add resources license expression summary panel in the project details view.
This panel displays the list of licenses detected in the project and include links
to the resources list.
https://github.com/nexB/scancode.io/pull/355

v32.6.0 (2023-08-29)
--------------------

Expand Down
6 changes: 3 additions & 3 deletions scanpipe/templates/scanpipe/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
.is-tooltip .dropdown-content {background-color: #363636;}
.is-tooltip .dropdown-item {font-weight: normal; color: #fff;}
.ace-marker {position: absolute; z-index: 3; background: #ffe9b3;}
.break-all {word-break: break-all;}
.break-word {word-break: break-word;}
.break-normal {word-break: normal;}
.break-all {word-break: break-all !important;}
.break-word {word-break: break-word !important;}
.break-normal {word-break: normal !important;}
.nowrap {white-space: nowrap;}
#content-header input[name="search"] {width: 225px;}
button.as-link {height: auto; line-height: initial; font-size: inherit;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<p class="heading">Resources</p>
<p class="{{ title_class }}">
{% if project.resource_count %}
<a href="{% url 'project_resources' project.slug %}">
<a href="{{ project_resources_url }}">
{{ project.resource_count|intcomma }}
</a>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="column">
<div id="{{ field_name }}_chart"
data-url="{% url 'project_resources' project.slug %}"
data-url="{{ project_resources_url }}"
data-lookup_field="{% if lookup_field %}{{ lookup_field }}{% else %}{{ field_name }}{% endif %}"
{% if file_filter %}
data-in_package="{% if file_filter == 'in-a-package' %}true{% elif file_filter == 'not-in-a-package' %}false{% endif %}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% load humanize %}
<nav class="panel is-info">
<p class="panel-heading py-2 is-size-6">
Resources detected license expressions
</p>
{% for license_expression, count in resource_licenses_summary.items %}
<a class="panel-block is-align-items-flex-start break-word" href="{{ project_resources_url }}?type=file&detected_license_expression={{ license_expression|default:'_EMPTY_' }}" target="_blank">
{{ license_expression|default:'<i>no licenses</i>' }}
<span class="tag is-rounded ml-1">{{ count|intcomma }}</span>
</a>
{% endfor %}
</nav>
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
Resources status
</p>
{% for status, count in resource_status_summary.items %}
<a class="panel-block" href="{% url 'project_resources' project.slug %}?status={{ status|default:'_EMPTY_' }}" target="_blank">
{% if status %}
{{ status }}
{% else %}
<i>(no status)</i>
{% endif %}
: {{ count|intcomma }}
<a class="panel-block is-align-items-flex-start break-word" href="{{ project_resources_url }}?status={{ status|default:'_EMPTY_' }}" target="_blank">
{{ status|default:'<i>no status</i>' }}
<span class="tag is-rounded ml-1">{{ count|intcomma }}</span>
</a>
{% endfor %}
</nav>
22 changes: 15 additions & 7 deletions scanpipe/templates/scanpipe/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,28 @@
</div>
</div>

{% if codebase_root or resource_status_summary %}
{% if codebase_root %}
<div class="columns">
{% if codebase_root %}
<div class="column">
<div hx-get="{% url 'project_codebase' project.slug %}" hx-trigger="load">
<i class="fa-solid fa-spinner fa-pulse" aria-hidden="true"></i>
</div>
<div class="column">
<div hx-get="{% url 'project_codebase' project.slug %}" hx-trigger="load">
<i class="fa-solid fa-spinner fa-pulse" aria-hidden="true"></i>
</div>
{% endif %}
</div>
</div>
{% endif %}

{% if resource_status_summary or resource_licenses_summary %}
<div class="columns">
{% if resource_status_summary %}
<div class="column is-half">
{% include "scanpipe/includes/resource_status_summary.html" %}
</div>
{% endif %}
{% if resource_licenses_summary %}
<div class="column is-half">
{% include "scanpipe/includes/resource_licenses_summary.html" %}
</div>
{% endif %}
</div>
{% endif %}

Expand Down
12 changes: 12 additions & 0 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from django.shortcuts import redirect
from django.shortcuts import render
from django.template.defaultfilters import filesizeformat
from django.urls import reverse
from django.urls import reverse_lazy
from django.views import generic
from django.views.decorators.http import require_POST
Expand Down Expand Up @@ -616,6 +617,7 @@ def check_run_scancode_version(self, pipeline_runs, version_limit="32.2.0"):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
project = self.object
project_resources_url = reverse("project_resources", args=[project.slug])

inputs, missing_inputs = project.inputs_with_source
if missing_inputs:
Expand Down Expand Up @@ -647,6 +649,14 @@ def get_context_data(self, **kwargs):
codebase_root.sort(key=operator.methodcaller("is_file"))

resource_status_summary = count_group_by(project.codebaseresources, "status")
if list(resource_status_summary.keys()) == [""]:
resource_status_summary = None

resource_licenses_summary = count_group_by(
project.codebaseresources.files(), "detected_license_expression"
)
if list(resource_licenses_summary.keys()) == [""]:
resource_licenses_summary = None

pipeline_runs = project.runs.all()
self.check_run_scancode_version(pipeline_runs)
Expand All @@ -660,7 +670,9 @@ def get_context_data(self, **kwargs):
"add_labels_form": AddLabelsForm(),
"project_clone_form": ProjectCloneForm(project),
"archive_form": ArchiveProjectForm(),
"project_resources_url": project_resources_url,
"resource_status_summary": resource_status_summary,
"resource_licenses_summary": resource_licenses_summary,
"license_clarity": license_clarity,
"scan_summary": scan_summary,
"pipeline_runs": pipeline_runs,
Expand Down

0 comments on commit 5518a94

Please sign in to comment.