From 5518a94a856c78715907a4ba0d8de1cd33d250cb Mon Sep 17 00:00:00 2001 From: tdruez <489057+tdruez@users.noreply.github.com> Date: Mon, 11 Sep 2023 14:31:37 +0200 Subject: [PATCH] Add resources license summary panel in the project details view #355 (#916) Signed-off-by: Thomas Druez --- CHANGELOG.rst | 5 +++++ scanpipe/templates/scanpipe/base.html | 6 ++--- .../includes/project_summary_level.html | 2 +- .../includes/resource_chart_column.html | 2 +- .../includes/resource_licenses_summary.html | 12 ++++++++++ .../includes/resource_status_summary.html | 10 +++------ .../templates/scanpipe/project_detail.html | 22 +++++++++++++------ scanpipe/views.py | 12 ++++++++++ 8 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 scanpipe/templates/scanpipe/includes/resource_licenses_summary.html diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e8bdbfce7..123294fc8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) -------------------- diff --git a/scanpipe/templates/scanpipe/base.html b/scanpipe/templates/scanpipe/base.html index 91b98aeb6..3c99b1c39 100644 --- a/scanpipe/templates/scanpipe/base.html +++ b/scanpipe/templates/scanpipe/base.html @@ -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;} diff --git a/scanpipe/templates/scanpipe/includes/project_summary_level.html b/scanpipe/templates/scanpipe/includes/project_summary_level.html index d847cdeb3..2dad4e586 100644 --- a/scanpipe/templates/scanpipe/includes/project_summary_level.html +++ b/scanpipe/templates/scanpipe/includes/project_summary_level.html @@ -45,7 +45,7 @@

Resources

{% if project.resource_count %} - + {{ project.resource_count|intcomma }} {% else %} diff --git a/scanpipe/templates/scanpipe/includes/resource_chart_column.html b/scanpipe/templates/scanpipe/includes/resource_chart_column.html index aea01f97a..7358aa89e 100644 --- a/scanpipe/templates/scanpipe/includes/resource_chart_column.html +++ b/scanpipe/templates/scanpipe/includes/resource_chart_column.html @@ -1,6 +1,6 @@

+

+ Resources detected license expressions +

+ {% for license_expression, count in resource_licenses_summary.items %} + + {{ license_expression|default:'no licenses' }} + {{ count|intcomma }} + + {% endfor %} + \ No newline at end of file diff --git a/scanpipe/templates/scanpipe/includes/resource_status_summary.html b/scanpipe/templates/scanpipe/includes/resource_status_summary.html index e5a27e266..c0abf8a1d 100644 --- a/scanpipe/templates/scanpipe/includes/resource_status_summary.html +++ b/scanpipe/templates/scanpipe/includes/resource_status_summary.html @@ -4,13 +4,9 @@ Resources status

{% for status, count in resource_status_summary.items %} - - {% if status %} - {{ status }} - {% else %} - (no status) - {% endif %} - : {{ count|intcomma }} + + {{ status|default:'no status' }} + {{ count|intcomma }} {% endfor %} \ No newline at end of file diff --git a/scanpipe/templates/scanpipe/project_detail.html b/scanpipe/templates/scanpipe/project_detail.html index 809101a13..b31df3d96 100644 --- a/scanpipe/templates/scanpipe/project_detail.html +++ b/scanpipe/templates/scanpipe/project_detail.html @@ -85,20 +85,28 @@
- {% if codebase_root or resource_status_summary %} + {% if codebase_root %}
- {% if codebase_root %} -
-
- -
+
+
+
- {% endif %} +
+
+ {% endif %} + + {% if resource_status_summary or resource_licenses_summary %} +
{% if resource_status_summary %}
{% include "scanpipe/includes/resource_status_summary.html" %}
{% endif %} + {% if resource_licenses_summary %} +
+ {% include "scanpipe/includes/resource_licenses_summary.html" %} +
+ {% endif %}
{% endif %} diff --git a/scanpipe/views.py b/scanpipe/views.py index 0a5785261..c12f58563 100644 --- a/scanpipe/views.py +++ b/scanpipe/views.py @@ -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 @@ -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: @@ -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) @@ -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,