Skip to content

Commit 9003100

Browse files
committed
Add the ability to delete a Scan from Product inventory #230
Signed-off-by: tdruez <[email protected]>
1 parent c260cce commit 9003100

File tree

6 files changed

+39
-9
lines changed

6 files changed

+39
-9
lines changed

component_catalog/templates/component_catalog/includes/scan_delete_modal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h5 class="modal-title">Delete {% trans 'Scan' %}</h5>
1010
<p><strong>Are you sure you want to delete this Scan?</strong></p>
1111
<p>
1212
All data and results related to the Scan will be deleted.<br>
13-
If the Scan is in progress, it will be cancel.
13+
If the Scan is in progress, it will be canceled.
1414
</p>
1515
</div>
1616
<div class="modal-footer">

component_catalog/templates/component_catalog/includes/scan_progress.html

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@
22
{% include 'component_catalog/includes/scan_status.html' with status=scan.runs.0.status only %}
33

44
{% if compact_mode %}
5-
<div class="mt-1">
5+
<ul class="list-inline mt-1 mb-0">
66
{% if view_url %}
7-
<a class="text-dark" href="{{ view_url }}#scan" target="_blank" data-bs-toggle="tooltip" data-bs-title="View Scan results"><i class="far fa-file-alt"></i></a>&nbsp;
7+
<li class="list-inline-item" data-bs-toggle="tooltip" data-bs-title="View Scan results">
8+
<a class="text-dark" href="{{ view_url }}#scan" target="_blank">
9+
<i class="far fa-file-alt"></i>
10+
</a>
11+
</li>
812
{% endif %}
913
{% if scan.download_result_url %}
10-
<a class="text-dark" href="{{ scan.download_result_url }}" target="_blank" data-bs-toggle="tooltip" data-bs-title="Download Scan results"><i class="fas fa-download"></i></a>
14+
<li class="list-inline-item" data-bs-toggle="tooltip" data-bs-title="Download Scan results">
15+
<a class="text-dark" href="{{ scan.download_result_url }}" target="_blank">
16+
<i class="fas fa-download"></i>
17+
</a>
18+
</li>
1119
{% endif %}
12-
</div>
20+
{% if scan.delete_url %}
21+
<li class="list-inline-item" data-bs-toggle="tooltip" data-bs-title="Delete Scan">
22+
<a class="text-dark scan_delete_link" href="#scan-delete-modal" role="button" data-delete-url="{{ scan.delete_url }}" data-bs-toggle="modal">
23+
<i class="far fa-trash-alt"></i>
24+
</a>
25+
</li>
26+
{% endif %}
27+
</ul>
1328
{% else %}
1429
<div class="text-center">
1530
{% if scan.download_result_url %}

component_catalog/templates/component_catalog/scan_list.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
{{ block.super }}
3737
<script>
3838
document.addEventListener('DOMContentLoaded', function () {
39-
$('.scan_delete_link').on('click', function() {
40-
let delete_url = $(this).data('delete-url');
41-
$('#scan-delete-modal a.delete-confirm').attr('href', delete_url);
39+
document.querySelectorAll('.scan_delete_link').forEach(link => {
40+
link.addEventListener('click', function() {
41+
let deleteUrl = this.getAttribute('data-delete-url');
42+
document.querySelector('#scan-delete-modal a.delete-confirm').setAttribute('href', deleteUrl);
43+
});
4244
});
4345
});
4446
</script>

product_portfolio/templates/product_portfolio/product_details.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
{% endif %}
114114
{% if display_scan_features %}
115115
{% include 'component_catalog/includes/scan_package_modal.html' %}
116+
{% include 'component_catalog/includes/scan_delete_modal.html' %}
116117
{% endif %}
117118
{% if pull_project_data_form %}
118119
{% include 'product_portfolio/includes/pull_project_data_modal.html' %}

product_portfolio/templates/product_portfolio/tabs/tab_inventory.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
{% if relation.package and display_scan_features %}
143143
<tr class="{{ rowcolors }} extra-details">
144144
<td colspan="100" class="ps-4">
145-
<div class="col-4 p-0">
145+
<div class="col-2 p-0">
146146
{% if relation.scan %}
147147
<strong>{% trans 'Scan' %}:</strong> {% include 'component_catalog/includes/scan_progress.html' with scan=relation.scan view_url=relation.package.get_absolute_url compact_mode=True only %}
148148
{% else %}
@@ -311,4 +311,13 @@
311311
new bootstrap.Tooltip(iconElement, {container: 'body'});
312312
}
313313
{% endif %}
314+
315+
{% if display_scan_features %}
316+
document.querySelectorAll('.scan_delete_link').forEach(link => {
317+
link.addEventListener('click', function() {
318+
let deleteUrl = this.getAttribute('data-delete-url');
319+
document.querySelector('#scan-delete-modal a.delete-confirm').setAttribute('href', deleteUrl);
320+
});
321+
});
322+
{% endif %}
314323
</script>

product_portfolio/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,9 @@ def inject_scan_data(scancodeio, feature_grouped, dataspace_uuid):
950950
scan = scans_by_uri.get(productpackage.package.download_url)
951951
if scan:
952952
scan["download_result_url"] = get_scan_results_as_file_url(scan)
953+
scan["delete_url"] = reverse(
954+
"component_catalog:scan_delete", args=[scan.get("uuid")]
955+
)
953956
productpackage.scan = scan
954957
injected_productpackages.append(productpackage)
955958

0 commit comments

Comments
 (0)