Skip to content

Commit

Permalink
Add filtering by applicants in bounties explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal Kowalski committed Jun 24, 2019
1 parent 60ed0a0 commit 7d3c5db
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
34 changes: 28 additions & 6 deletions app/assets/v2/js/pages/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var filters = [
'idx_status',
'project_type',
'permission_type',
'misc'
'misc',
'applicants'
];
var local_storage_keys = JSON.parse(JSON.stringify(filters));

Expand Down Expand Up @@ -129,10 +130,13 @@ var save_sidebar_latest = function() {

filters.forEach((filter) => {
localStorage[filter] = '';

$('input[name="' + filter + '"]:checked').each(function() {
localStorage[filter] += $(this).val() + ',';
});
if (filter === 'applicants') {
localStorage[filter] = $('#applicants_box').val();
} else {
$('input[name="' + filter + '"]:checked').each(function() {
localStorage[filter] += $(this).val() + ',';
});
}

localStorage[filter] = localStorage[filter].replace(/^,|,\s*$/g, '');
});
Expand Down Expand Up @@ -178,6 +182,10 @@ const set_sidebar_defaults = () => {

filters.forEach((filter) => {
if (localStorage[filter]) {
if (filter === 'applicants') {
$('#applicants_box').val(localStorage[filter]).trigger('change');
}

localStorage[filter].split(',').forEach(function(val) {
$('input[name="' + filter + '"][value="' + val + '"]').prop('checked', true);
});
Expand Down Expand Up @@ -295,7 +303,6 @@ var get_search_URI = function(offset, order) {
var keywords = '';
var org = '';


filters.forEach((filter) => {
var active_filters = [];

Expand Down Expand Up @@ -337,6 +344,9 @@ var get_search_URI = function(offset, order) {
val = 'myself';
}
}
if (filter === 'applicants') {
val = $('#applicants_box').val();
}

if (val && val !== 'any' &&
filter !== 'bounty_filter' &&
Expand Down Expand Up @@ -594,6 +604,12 @@ var resetFilters = function(resetKeyword) {
$('input[name="' + filter + '"][value="' + tag[j].value + '"]').prop('checked', false);
}

if (filter === 'applicants' && !document.hackathon) {
$('#applicants_box').val('ALL').trigger('change');
} else if (resetKeyword && filter === 'applicants' && document.hackathon) {
localStorage.setItem(filter, '');
}

// Defaults to mainnet on clear filters to make it less confusing
$('input[name="network"][value="mainnet"]').prop('checked', true);
});
Expand Down Expand Up @@ -650,6 +666,12 @@ var resetFilters = function(resetKeyword) {

$(document).ready(function() {

$('.js-select2').each(function() {
$(this).select2({
minimumResultsForSearch: Infinity
});
});

$('#expand').on('click', () => {
$('#expand').hide();
$('#minimize').show();
Expand Down
12 changes: 12 additions & 0 deletions app/dashboard/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import time
from datetime import datetime

from django.db.models import Count

import django_filters.rest_framework
from kudos.models import KudosTransfer
from rest_framework import routers, serializers, viewsets
Expand Down Expand Up @@ -267,6 +269,16 @@ def get_queryset(self):
statuses = self.request.query_params.get('status__in').split(',')
queryset = queryset.filter(idx_status__in=statuses)

applicants = self.request.query_params.get('applicants')
if applicants == '0':
queryset = queryset.annotate(
interested_count=Count("interested")
).filter(interested_count=0)
elif applicants == '1-5':
queryset = queryset.annotate(
interested_count=Count("interested")
).filter(interested_count__gte=1).filter(interested_count__lte=5)

# filter by who is interested
if 'started' in param_keys:
queryset = queryset.filter(interested__profile__handle__in=[self.request.query_params.get('started')])
Expand Down
13 changes: 13 additions & 0 deletions app/dashboard/templates/dashboard/sidebar_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@
</div>
</div>

<div class="col">
<div class="col-12 subheading">
Applicants
</div>
<div class="col-12 options">
<select class="w-100 js-select2" name="applicants" id="applicants_box">
<option value="ALL">ALL</option>
<option value="0">0</option>
<option value="1-5">1-5</option>
</select>
</div>
</div>

<div class="col">
<div class="col-12 subheading accordion">
{% trans "Advanced Filters" %}
Expand Down

0 comments on commit 7d3c5db

Please sign in to comment.