Skip to content

Commit

Permalink
Enable sorting project list by name and creation date aboutcode-org#413
Browse files Browse the repository at this point in the history
[x] Increase table rows to 20
[x] Added created date column in project table
[x] Support sorting by name and creation date of the project

Signed-off-by: Akhil Raj <[email protected]>
  • Loading branch information
lf32 committed Jun 15, 2022
1 parent 777167e commit 042c70d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions scanpipe/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def verbose_name_plural(cls):

class ProjectFilterSet(FilterSetUtilsMixin, django_filters.FilterSet):
search = django_filters.CharFilter(field_name="name", lookup_expr="icontains")
sort = django_filters.OrderingFilter(
fields=(("name", "name"), ("created_date", "created_date")),
)

class Meta:
model = Project
Expand Down
3 changes: 2 additions & 1 deletion scanpipe/templates/scanpipe/includes/project_list_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<tr>
<th class="break-all">
<a href="{{ project.get_absolute_url }}">{{ project }}</a>
<span class="has-text-grey is-size-7 is-block" title="{{ project.created_date|date:'N j, Y, P T' }}">Created {{ project.created_date|naturaltime }}</span>
</th>
<td>
{% if project.package_count %}
Expand Down Expand Up @@ -65,4 +66,4 @@
</tr>
{% endfor %}
</tbody>
</table>
</table>
24 changes: 22 additions & 2 deletions scanpipe/templates/scanpipe/project_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,27 @@
</a>
{% endif %}
</div>
<a href="{% url 'project_add' %}" class="button is-link">New Project</a>
<div>
<div class="dropdown is-right is-hoverable">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu">
<span>Sort</span>
<span class="icon is-small">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="dropdown-menu" id="dropdown-sort-filters" role="menu">
<div class="dropdown-content">
<a href="?sort=name" class="dropdown-item">Name (A-Z)</a>
<a href="?sort=-name" class="dropdown-item">Name (Z-A)</a>
<a href="?sort=created_date" class="dropdown-item">Oldest</a>
<a href="?sort=-created_date" class="dropdown-item">Newest</a>
</div>
</div>
</div>
<a href="{% url 'project_add' %}" class="button is-link">New Project</a>
</div>
</div>

{% include 'scanpipe/includes/search_field.html' %}
Expand Down Expand Up @@ -49,4 +69,4 @@
</div>

{% include 'scanpipe/includes/run_modal.html' %}
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ProjectListView(
filterset_class = ProjectFilterSet
template_name = "scanpipe/project_list.html"
prefetch_related = ["runs"]
paginate_by = 10
paginate_by = 20

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down

0 comments on commit 042c70d

Please sign in to comment.