Skip to content

Commit 5065b58

Browse files
committed
replace popover with modal
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 584ee9d commit 5065b58

2 files changed

Lines changed: 42 additions & 38 deletions

File tree

product_portfolio/templates/product_portfolio/compliance/compliance_panels.html

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,51 @@
99
<div class="d-flex align-items-center gap-2">
1010
<h3 class="fs-6 fw-medium mb-0">{% trans "Policy violations" %}</h3>
1111
<button type="button"
12-
id="rules-overview-btn"
1312
class="btn btn-link p-0 text-body-tertiary lh-1"
13+
data-bs-toggle="modal"
14+
data-bs-target="#active-rules-modal"
1415
aria-label="{% trans 'View active rules' %}">
1516
<i class="fas fa-circle-info small"></i>
1617
</button>
1718
</div>
19+
20+
<div class="modal fade" id="active-rules-modal" tabindex="-1" aria-labelledby="active-rules-modal-label" aria-hidden="true">
21+
<div class="modal-dialog">
22+
<div class="modal-content">
23+
<div class="modal-header">
24+
<h5 class="modal-title fs-6 fw-medium" id="active-rules-modal-label">{% trans "Active rules" %}</h5>
25+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{% trans 'Close' %}"></button>
26+
</div>
27+
<div class="modal-body p-0">
28+
{% for rule in all_rules %}
29+
<div class="d-flex align-items-start justify-content-between px-3 py-3 {% if not forloop.last %}border-bottom{% endif %}">
30+
<div class="me-3">
31+
{% if rule.severity == "error" %}
32+
<span class="badge bg-danger-subtle text-danger-emphasis mb-1">{{ rule.label }}</span>
33+
{% else %}
34+
<span class="badge bg-warning-subtle text-warning-emphasis mb-1">{{ rule.label }}</span>
35+
{% endif %}
36+
<div class="text-body-secondary small">{{ rule.description }}</div>
37+
</div>
38+
<div class="flex-shrink-0">
39+
{% if not rule.is_active %}
40+
<span class="badge text-bg-secondary">{% trans "Disabled" %}</span>
41+
{% elif rule.is_violated %}
42+
{% if rule.severity == "error" %}
43+
<span class="badge bg-danger-subtle text-danger-emphasis">{% trans "Triggered" %}</span>
44+
{% else %}
45+
<span class="badge bg-warning-subtle text-warning-emphasis">{% trans "Triggered" %}</span>
46+
{% endif %}
47+
{% else %}
48+
<span class="badge bg-success-subtle text-success-emphasis">{% trans "OK" %}</span>
49+
{% endif %}
50+
</div>
51+
</div>
52+
{% endfor %}
53+
</div>
54+
</div>
55+
</div>
56+
</div>
1857
<span class="badge bg-danger-subtle text-danger-emphasis">
1958
{{ policy_violation_count }} {% trans "active" %}
2059
</span>
@@ -54,42 +93,6 @@ <h3 class="fs-6 fw-medium mb-0">{% trans "Policy violations" %}</h3>
5493
</div>
5594
</div>
5695

57-
{# Hidden popover content -- not data-bs-toggle so the global init doesn't conflict #}
58-
<div id="rules-overview-content" class="d-none">
59-
{% for rule in all_rules %}
60-
<div class="d-flex align-items-center justify-content-between {% if not forloop.last %}mb-2{% endif %}">
61-
<span class="small me-3">{{ rule.label }}</span>
62-
{% if not rule.is_active %}
63-
<span class="badge text-bg-secondary">{% trans "Disabled" %}</span>
64-
{% elif rule.is_violated %}
65-
{% if rule.severity == "error" %}
66-
<span class="badge bg-danger-subtle text-danger-emphasis">{% trans "Triggered" %}</span>
67-
{% else %}
68-
<span class="badge bg-warning-subtle text-warning-emphasis">{% trans "Triggered" %}</span>
69-
{% endif %}
70-
{% else %}
71-
<span class="badge bg-success-subtle text-success-emphasis">{% trans "OK" %}</span>
72-
{% endif %}
73-
</div>
74-
{% endfor %}
75-
</div>
76-
<script>
77-
(function () {
78-
const btn = document.getElementById("rules-overview-btn");
79-
const content = document.getElementById("rules-overview-content");
80-
const popover = new bootstrap.Popover(btn, {
81-
html: true,
82-
container: "body",
83-
placement: "right",
84-
trigger: "click",
85-
title: "{% trans 'Active rules' %}",
86-
content: content.innerHTML,
87-
});
88-
document.addEventListener("click", function (event) {
89-
if (!btn.contains(event.target)) popover.hide();
90-
});
91-
})();
92-
</script>
9396
{% endif %}
9497

9598
<div class="row g-4 mb-4">
@@ -262,7 +265,7 @@ <h3 class="fs-6 fw-medium mb-0">{% trans "Security compliance" %}</h3>
262265
{% else %}
263266
{{ vulnerability_count }}
264267
{% trans "vulnerabilit" %}{{ vulnerability_count|pluralize:"y,ies" }}
265-
{% trans "no risk threshold set" %}
268+
- {% trans "no risk threshold set" %}
266269
{% endif %}
267270
</p>
268271
{% endif %}

product_portfolio/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,7 @@ def get_policy_compliance_context(product):
28552855
all_rules = [
28562856
{
28572857
"label": handler.label,
2858+
"description": handler.description,
28582859
"rule_type": rule_type,
28592860
"severity": handler.severity,
28602861
"is_active": get_effective_config(rule_type, product.dataspace)["is_active"],

0 commit comments

Comments
 (0)