Skip to content

Commit

Permalink
Merge pull request #50 from AceFire6/jethro/add/querystring_filtering
Browse files Browse the repository at this point in the history
Add query string filtering
  • Loading branch information
AceFire6 authored Aug 27, 2018
2 parents 7c4f1a5 + 23e5c50 commit 7cc5e12
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 44 deletions.
23 changes: 0 additions & 23 deletions ordering/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,6 @@
window.open(url, '_blank');
};

var addFilters = function() {
var toFilterList = [];

var selectedOptions = $('#show-filter-select').select2('data');
$.each(selectedOptions, function() {
toFilterList.push(this.id);
});

var url = '';

if (toFilterList.length > 0) {
url = '/hide/' + toFilterList.join('+');
}

url += '/';

if (document.baseURI.match('/newest_first/$')) {
url += 'newest_first/';
}
window.location = url;
};

var disableColours = function() {
$('.episode, thead').addClass('no-color');
$('#episode-list').addClass('table-striped table-hover');
Expand All @@ -44,7 +22,6 @@

var registerListeners = function() {
$('.episode').click(openWiki);
$('#filter-button').click(addFilters);

$('#no-color').click(function() {
if (Cookies.get('colour') === '1') {
Expand Down
37 changes: 21 additions & 16 deletions ordering/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ <h1>Arrowverse Episode Order</h1>
<div class="row">

<div class="col-11">
<select id="show-filter-select"
title="Filter options"
name="shows[]"
multiple="multiple">
{% for show_id, show_data in show_list.items() %}
<option value="{{ show_id }}" {% if show_id in hidden_list %}selected{% endif %}>
{{ show_data.name }}
</option>
{% endfor %}
</select>
<form id="hide-shows-form" method="get" action="{{ url_for('index') }}">
<input name="newest_first" value="{{ newest_first }}" title="Newest First" type="hidden">
<select id="show-filter-select"
title="Filter options"
name="hide_show"
multiple="multiple">
{% for show_id, show_data in show_list.items() %}
<option value="{{ show_id }}" {% if show_id in hidden_show_list %}selected{% endif %}>
{{ show_data.name }}
</option>
{% endfor %}
</select>
</form>
</div>

<div class="col">
<button type="button" id="filter-button" class="btn btn-outline-secondary">
<button type="submit" id="filter-button" class="btn btn-outline-secondary" form="hide-shows-form">
Filter
</button>
</div>
Expand All @@ -65,11 +68,13 @@ <h1>Arrowverse Episode Order</h1>
<div class="col">
<div class="float-right">
<a href="#end" id="top"><small>END</small></a> |
{% if newest_first %}
<a href="{{ oldest_first_url }}"><small>OLDEST FIRST</small></a>
{% else %}
<a href="newest_first"><small>NEWEST FIRST</small></a>
{% endif %}
<a href="{{ url_for('index', newest_first=not newest_first, hide_show=hidden_show_list) }}">
{% if newest_first %}
<small>OLDEST FIRST</small>
{% else %}
<small>NEWEST FIRST</small>
{% endif %}
</a>
| <a href="#" id="no-color"><small class="text">DISABLE COLOR</small></a>
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions ordering/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,10 @@ def get_full_series_episode_list(excluded_series=None):
show_lists.append(show_list)

return sort_episodes(show_lists)


def _get_bool(arg):
if isinstance(arg, bool):
return arg

return arg == 'True'
18 changes: 13 additions & 5 deletions ordering/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
from flask import render_template
from flask import render_template, request

from . import app
from .utils import get_full_series_episode_list
from .utils import _get_bool, get_full_series_episode_list


@app.route('/', methods=['GET'])
def index():
context = {}

episode_list = get_full_series_episode_list()
newest_first = request.args.get('newest_first', default=False, type=_get_bool)
hide_shows_list = request.args.getlist('hide_show')

episode_list = get_full_series_episode_list(excluded_series=hide_shows_list)

if newest_first:
episode_list = episode_list[::-1]

context['table_content'] = episode_list
context['show_list'] = app.config['SHOW_DICT']
context['hidden_show_list'] = hide_shows_list
context['newest_first'] = newest_first

return render_template('index.html', **context)

Expand All @@ -35,7 +43,7 @@ def index_with_hidden(hide_list):

episode_list = get_full_series_episode_list(hide_list)

context['hidden_list'] = hide_list
context['hidden_show_list'] = hide_list
context['table_content'] = episode_list
context['show_list'] = app.config['SHOW_DICT']

Expand All @@ -49,7 +57,7 @@ def index_with_hidden_newest_first(hide_list):
episode_list = get_full_series_episode_list(hide_list)
episode_list = episode_list[::-1]

context['hidden_list'] = hide_list
context['hidden_show_list'] = hide_list
context['table_content'] = episode_list
context['show_list'] = app.config['SHOW_DICT']

Expand Down

0 comments on commit 7cc5e12

Please sign in to comment.