Skip to content

Commit

Permalink
* Add sorting and filtering to the project page.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgroff committed Jan 13, 2018
1 parent be2b93c commit 557cf77
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 48 deletions.
7 changes: 2 additions & 5 deletions django_kala/projects/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#

class SortForm(forms.Form):
search = forms.ChoiceField(choices=(('DATE', 'Sort by Date'), ('AZ', 'Sort Alphabetically')),
sort = forms.ChoiceField(choices=(('Date', 'Sort by Date'), ('Alphabetically', 'Sort Alphabetically')),
widget=forms.RadioSelect,
initial='DATE')



initial='Date')
100 changes: 62 additions & 38 deletions django_kala/projects/templates/projects/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
{% load static %}

{% block search_bar %}
{% include 'projects/includes/project_search_bar.html' %}
{% include 'projects/includes/project_search_bar.html' %}
{% endblock %}

{% block content %}
<div class="repo ribbon">
<div class="ui container">
<div class="ui big breadcrumb">
<a class="section" href="{% url 'organizations:organization' project.organization.pk %}">{{ project.organization }}</a>
<a class="section"
href="{% url 'organizations:organization' project.organization.pk %}">{{ project.organization }}</a>
<div class="divider"> /</div>
<span class="active section">{{ project }}</span>
</div>
Expand All @@ -21,16 +22,16 @@
<i class="book icon"></i>
Documents
</a>
{# <a class="item">#}
{# <i class="issue opened icon"></i>#}
{# Issues#}
{# <span class="ui small label">593</span>#}
{# </a>#}
{# <a class="item">#}
{# <i class="issue opened icon"></i>#}
{# Issues#}
{# <span class="ui small label">593</span>#}
{# </a>#}
{% if can_change %}
<a class="item" href="{% url 'projects:details' project.pk %}">
<i class="gear icon"></i>
Settings
</a>
<a class="item" href="{% url 'projects:details' project.pk %}">
<i class="gear icon"></i>
Settings
</a>
{% endif %}
</div>
</div>
Expand Down Expand Up @@ -73,10 +74,13 @@
<input type="hidden" value="watching">
<i class="checklist icon"></i> Filter
<i class="dropdown icon"></i>
<div class="menu">
<div class="menu" id="category-menu">
<div class="item">
<h4 data-value="">No Filter</h4>
</div>
{% for category in project.category_set.all %}
<div class="item" data-value="not-watching">
<h4>{{ category }}</h4>
<div class="item">
<h4 data-value="{{ category }}">{{ category }}</h4>
</div>
{% endfor %}
</div>
Expand All @@ -87,24 +91,24 @@ <h4>{{ category }}</h4>
<input type="hidden" value="watching">
<i class="checklist icon"></i> Sort
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="not-watching">
<h4>Alphabetically</h4>
<div class="menu" id="sort-menu">
<div class="item">
<h4 data-value="Alphabetically">Alphabetically</h4>
</div>
<div class="item" data-value="watching">
<h4>Date</h4>
<div class="item">
<h4 data-value="Date">Date</h4>
</div>
</div>
</div>
</div>
</div>
{% if can_create %}
<a class="ui positive compact icon button" href="{% url 'projects:new_document' project.pk %}">
+ New document
</a>
{% else %}
<p>You do not have permission to create new documents for this project.</p>
{% endif %}
{% if can_create %}
<a class="ui positive compact icon button" href="{% url 'projects:new_document' project.pk %}">
+ New document
</a>
{% else %}
<p>You do not have permission to create new documents for this project.</p>
{% endif %}
</div>
<div class="ui divider">
</div>
Expand All @@ -119,10 +123,11 @@ <h4>Date</h4>
alt="{{ document.documentversion_set.all.0.get_alt }}">
<img class="hidden content" src="{% static "images/icons/android-download.png" %}"
alt="{{ document.documentversion_set.all.0.get_alt }}">
</div>
</div>
</a>
<div class="content">
<a class="header" style="word-wrap: break-word;" href="{% url 'projects:document' project.pk document.pk %}">{{ document.name }}</a>
<a class="header" style="word-wrap: break-word;"
href="{% url 'projects:document' project.pk document.pk %}">{{ document.name }}</a>
<div class="meta">
{% if document.documentversion_set.all.count == 1 %}
<span class="date">Created on {{ document.date }}</span>
Expand All @@ -147,22 +152,25 @@ <h4>Date</h4>
<div class="ui divider"></div>
</div>
<div class="item">
<div class="ui relaxed divided list">
{% for document_version in document.documentversion_set.all %}
<div class="item">
<div class="content">
<a class="header" href="{% url 'projects:download' project.pk document_version.document.pk document_version.uuid %}">{{ document_version.name }}</a>
<div class="description">By {{ document_version.user }} on {{ document_version.created|date:"SHORT_DATETIME_FORMAT" }}</div>
<div class="ui relaxed divided list">
{% for document_version in document.documentversion_set.all %}
<div class="item">
<div class="content">
<a class="header"
href="{% url 'projects:download' project.pk document_version.document.pk document_version.uuid %}">{{ document_version.name }}</a>
<div class="description">By {{ document_version.user }} on
{{ document_version.created|date:"SHORT_DATETIME_FORMAT" }}</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
</div>

</div>
</div>
</div>
<div class="ui divider"></div>
<a class="ui compact button primary" href="{% url 'projects:new_version' project.pk document.pk %}">
<a class="ui compact button primary"
href="{% url 'projects:new_version' project.pk document.pk %}">
+ New version
</a>
</div>
Expand Down Expand Up @@ -190,10 +198,26 @@ <h4>Date</h4>

{% block scripts %}
<script>
var queryParameters = {}, queryString = location.search.substring(1),
re = /([^&=]+)=([^&]*)/g, m;

// Creates a map with the query string parameters
while (m = re.exec(queryString)) {
queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}

$('.dropdown')
.dropdown({
direction: 'upward'
})
;
$('#category-menu h4').click(function (item) {
queryParameters['category'] = item.toElement.dataset['value'];
location.search = $.param(queryParameters);
});
$('#sort-menu h4').click(function (item) {
queryParameters['sort'] = item.toElement.dataset['value'];
location.search = $.param(queryParameters);
});
</script>
{% endblock scripts %}
15 changes: 10 additions & 5 deletions django_kala/projects/views/projects/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ def get_context_data(self, **kwargs):
version_ids.append(str(version.uuid))
versions = DocumentVersion.objects.filter(uuid__in=version_ids).order_by('user_id')

if hasattr(self, 'sort_order'):
if self.sort_order == 'AZ':
sort_order = self.request.GET.get('sort', None)
if sort_order:
if sort_order == 'Alphabetically':
self.documents = self.documents.order_by('name')
if hasattr(self, 'category'):
mimes = get_mimes_for_category(self.category)
self.documents = self.documents.filter(mime__in=mimes)
else:
self.documents = self.documents.order_by('date')

category = self.request.GET.get('category', None)
if category:
self.documents = self.documents.filter(category__name=category)

per_page = self.request.GET.get('per_page', 20)
page = self.request.GET.get('page', 1)
paginator = Paginator(self.documents, per_page)
Expand Down

0 comments on commit 557cf77

Please sign in to comment.