Skip to content

Commit

Permalink
Enhanced Project list view page
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

Fixes aboutcode-org#413

Signed-off-by: Akhil Raj <[email protected]>
  • Loading branch information
lf32 committed Jun 12, 2022
1 parent 777167e commit da55b7e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
3 changes: 0 additions & 3 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,6 @@ class Project(UUIDPKModel, ExtraDataFieldMixin, models.Model):
),
)

class Meta:
ordering = ["-created_date"]

def __str__(self):
return self.name

Expand Down
4 changes: 4 additions & 0 deletions scanpipe/templates/scanpipe/includes/project_list_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<thead>
<tr>
<th>Name</th>
<th>Date Created</th>
<th>Packages</th>
<th>Resources</th>
<th>Errors</th>
Expand All @@ -16,6 +17,9 @@
<th class="break-all">
<a href="{{ project.get_absolute_url }}">{{ project }}</a>
</th>
<td>
{{ project.created_date| date:"d-m-Y" }}
</td>
<td>
{% if project.package_count %}
<a href="{% url 'project_packages' project.uuid %}">
Expand Down
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 By</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-menu" 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">Date Created (0-9)</a>
<a href="?sort=-created_date" class="dropdown-item">Date Created (9-0)</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 %}
10 changes: 9 additions & 1 deletion scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,22 @@ 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)
context["active_count"] = Project.objects.filter(is_archived=False).count()
context["archived_count"] = Project.objects.filter(is_archived=True).count()
return context

def get_ordering(self):
ordering = self.request.GET.get("sort")
return (
ordering
if ordering in ("created_date", "-created_date", "name", "-name")
else "-created_date"
)


class ProjectCreateView(ConditionalLoginRequired, generic.CreateView):
model = Project
Expand Down

0 comments on commit da55b7e

Please sign in to comment.