Skip to content

Commit

Permalink
Add sorting dropdown in the list #95
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Aug 27, 2024
1 parent 6ee1976 commit 7231576
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
1 change: 0 additions & 1 deletion component_catalog/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ class VulnerabilityFilterSet(DataspacedFilterSet):
fields=[
"max_score",
"min_score",
"vulnerability_id",
"affected_products_count",
"affected_packages_count",
"fixed_packages_length",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@
</div>
</form>
</li>
{% endblock %}

{% block top-right-buttons %}
{{ block.super }}
<div class="btn-group">
{{ filter.form.sort }}
</div>
{% endblock %}
3 changes: 2 additions & 1 deletion component_catalog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2491,7 +2491,8 @@ class VulnerabilityListView(
table_headers = (
Header("vulnerability_id", _("Vulnerability")),
Header("aliases", _("Aliases")),
Header("score_range", _("Score"), help_text="Severity score range", filter="max_score"),
# Keep `max_score` to enable column sorting
Header("max_score", _("Score"), help_text="Severity score range", filter="max_score"),
Header("summary", _("Summary")),
Header("affected_products_count", _("Affected products"), help_text="Affected products"),
Header("affected_packages_count", _("Affected packages"), help_text="Affected packages"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% load crispy_forms_tags %}
<div id="purldb-filterset-modal" class="modal" tabindex="-1" role="dialog">
<div id="filterset-modal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Filters</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form autocomplete="off" method="{{ form_helper.form_method }}" class="{{ form_helper.form_class }}">
<form autocomplete="off" method="{{ filter_form_helper.form_method }}" class="{{ filter_form_helper.form_class }}">
<div class="modal-body bg-body-tertiary">
{% crispy filter.form form_helper %}
{% crispy filter.form filter_form_helper %}
</div>
<div class="modal-footer">
<input type="button" name="close" value="Close" class="btn btn-secondary" data-bs-dismiss="modal">
Expand Down
4 changes: 2 additions & 2 deletions purldb/templates/purldb/purldb_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
{% block top-right-buttons %}
{{ block.super }}
<div class="btn-group">
<button type="button" class="btn btn-outline-dark {% if filter.form.changed_data %}active{% endif %}" data-bs-toggle="modal" data-bs-target="#purldb-filterset-modal"><i class="fas fa-filter"></i> Filters</button>
<button type="button" class="btn btn-outline-dark {% if filter.form.changed_data %}active{% endif %}" data-bs-toggle="modal" data-bs-target="#filterset-modal"><i class="fas fa-filter"></i> Filters</button>
</div>
{% endblock %}

{% block content %}
{{ block.super }}
{% include 'purldb/includes/filterset_modal.html' %}
{% include 'modals/filterset_modal.html' %}
{% endblock %}
4 changes: 2 additions & 2 deletions purldb/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def test_purldb_list_view_filters(self):
self.client.login(username=self.nexb_user.username, password="secret")

response = self.client.get(list_url + "?sort=-name&type=pypi")
self.assertContains(response, 'data-bs-target="#purldb-filterset-modal"')
self.assertContains(response, 'id="purldb-filterset-modal"')
self.assertContains(response, 'data-bs-target="#filterset-modal"')
self.assertContains(response, 'id="filterset-modal"')
self.assertContains(
response, '<option value="-name" selected>Name (descending)</option>', html=True
)
Expand Down
4 changes: 2 additions & 2 deletions purldb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def get_queryset(self):
return self.list_data.get("results", [])

@staticmethod
def get_form_helper():
def get_filter_form_helper():
helper = FormHelper()
helper.form_method = "get"
helper.form_tag = False
Expand All @@ -200,7 +200,7 @@ def get_context_data(self, **kwargs):
)

context["filter"] = self.filterset
context["form_helper"] = self.get_form_helper()
context["filter_form_helper"] = self.get_filter_form_helper()

return context

Expand Down

0 comments on commit 7231576

Please sign in to comment.