Added filtering for item types (radical, kanji & vocab)
This commit is contained in:
parent
c5fb8db98c
commit
a9e48abd96
@ -41,12 +41,16 @@ getSrsTypeFilters = () ->
|
|||||||
srs_levels = ['burnedcheck','enlightencheck','mastercheck','gurucheck','apprenticecheck']
|
srs_levels = ['burnedcheck','enlightencheck','mastercheck','gurucheck','apprenticecheck']
|
||||||
return (document.getElementById(s).value for s in srs_levels when document.getElementById(s).checked).toString()
|
return (document.getElementById(s).value for s in srs_levels when document.getElementById(s).checked).toString()
|
||||||
|
|
||||||
|
getItemTypeFilters = () ->
|
||||||
|
item_types = ['radicalcheck', 'kanjicheck', 'vocabcheck']
|
||||||
|
return (document.getElementById(s).value for s in item_types when document.getElementById(s).checked).toString()
|
||||||
|
|
||||||
filterQuestions = () ->
|
filterQuestions = () ->
|
||||||
sessionStorage.removeItem('user_items')
|
sessionStorage.removeItem('user_items')
|
||||||
sessionStorage.removeItem('radical_count')
|
sessionStorage.removeItem('radical_count')
|
||||||
sessionStorage.removeItem('kanji_count')
|
sessionStorage.removeItem('kanji_count')
|
||||||
sessionStorage.removeItem('vocabulary_count')
|
sessionStorage.removeItem('vocabulary_count')
|
||||||
target_url = "/user_items?level_range=" + $('#filter-input').val() + "&item_state=" + getSrsTypeFilters()
|
target_url = "/user_items?level_range=" + $('#filter-input').val() + "&item_state=" + getSrsTypeFilters() + "&item_types=" + getItemTypeFilters()
|
||||||
$.ajax
|
$.ajax
|
||||||
url: target_url,
|
url: target_url,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
@ -55,7 +59,6 @@ filterQuestions = () ->
|
|||||||
document.getElementById('filter-input').value = ''
|
document.getElementById('filter-input').value = ''
|
||||||
$('#error-text').text(e['error'])
|
$('#error-text').text(e['error'])
|
||||||
$('#error-area').show();
|
$('#error-area').show();
|
||||||
filterQuestions()
|
|
||||||
else
|
else
|
||||||
sessionStorage.setItem('user_items', JSON.stringify(e['item_list']))
|
sessionStorage.setItem('user_items', JSON.stringify(e['item_list']))
|
||||||
sessionStorage.setItem('radical_count', e['radical_count'])
|
sessionStorage.setItem('radical_count', e['radical_count'])
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Generated by CoffeeScript 1.10.0
|
// Generated by CoffeeScript 1.10.0
|
||||||
(function() {
|
(function() {
|
||||||
var filterQuestions, getSrsTypeFilters, refreshQuestion, updateQuizItemStats;
|
var filterQuestions, getItemTypeFilters, getSrsTypeFilters, refreshQuestion, updateQuizItemStats;
|
||||||
|
|
||||||
refreshQuestion = function() {
|
refreshQuestion = function() {
|
||||||
var input_element, items, selection;
|
var input_element, items, selection;
|
||||||
@ -65,13 +65,29 @@
|
|||||||
})()).toString();
|
})()).toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getItemTypeFilters = function() {
|
||||||
|
var item_types, s;
|
||||||
|
item_types = ['radicalcheck', 'kanjicheck', 'vocabcheck'];
|
||||||
|
return ((function() {
|
||||||
|
var i, len, results;
|
||||||
|
results = [];
|
||||||
|
for (i = 0, len = item_types.length; i < len; i++) {
|
||||||
|
s = item_types[i];
|
||||||
|
if (document.getElementById(s).checked) {
|
||||||
|
results.push(document.getElementById(s).value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
})()).toString();
|
||||||
|
};
|
||||||
|
|
||||||
filterQuestions = function() {
|
filterQuestions = function() {
|
||||||
var target_url;
|
var target_url;
|
||||||
sessionStorage.removeItem('user_items');
|
sessionStorage.removeItem('user_items');
|
||||||
sessionStorage.removeItem('radical_count');
|
sessionStorage.removeItem('radical_count');
|
||||||
sessionStorage.removeItem('kanji_count');
|
sessionStorage.removeItem('kanji_count');
|
||||||
sessionStorage.removeItem('vocabulary_count');
|
sessionStorage.removeItem('vocabulary_count');
|
||||||
target_url = "/user_items?level_range=" + $('#filter-input').val() + "&item_state=" + getSrsTypeFilters();
|
target_url = "/user_items?level_range=" + $('#filter-input').val() + "&item_state=" + getSrsTypeFilters() + "&item_types=" + getItemTypeFilters();
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
url: target_url,
|
url: target_url,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
@ -79,8 +95,7 @@
|
|||||||
if (e.hasOwnProperty('error')) {
|
if (e.hasOwnProperty('error')) {
|
||||||
document.getElementById('filter-input').value = '';
|
document.getElementById('filter-input').value = '';
|
||||||
$('#error-text').text(e['error']);
|
$('#error-text').text(e['error']);
|
||||||
$('#error-area').show();
|
return $('#error-area').show();
|
||||||
return filterQuestions();
|
|
||||||
} else {
|
} else {
|
||||||
sessionStorage.setItem('user_items', JSON.stringify(e['item_list']));
|
sessionStorage.setItem('user_items', JSON.stringify(e['item_list']));
|
||||||
sessionStorage.setItem('radical_count', e['radical_count']);
|
sessionStorage.setItem('radical_count', e['radical_count']);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% set srs_levels = [ ('burned', 'Burned'), ('enlighten', 'Enlightened'), ('master', 'Master'),
|
{% set srs_levels = ['burned', 'enlighten', 'master', 'guru', 'apprentice'] -%}
|
||||||
('guru', 'Guru'), ('apprentice', 'Apprentice') ] -%}
|
{% set item_types = ['radical', 'kanji', 'vocab'] %}
|
||||||
<div class="modal fade" id="modal-filter" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
|
<div class="modal fade" id="modal-filter" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
|
||||||
<div class="modal-dialog modal-sm">
|
<div class="modal-dialog modal-sm">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
@ -11,10 +11,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<form id="filter-form">
|
<form id="filter-form">
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<input type="text" pattern="\d[\d-,]*\d*" class="form-control" id="filter-input" placeholder="e.g. 1-3,5,8">
|
<label for=filter-input">Level</label><input type="text" pattern="\d[\d-,]*\d*" class="form-control" id="filter-input" placeholder="e.g. 1-3,5,8">
|
||||||
<br />
|
<br />
|
||||||
{% for srs_tag, srs_text in srs_levels %}
|
<p><strong>Progress</strong></p>
|
||||||
<input type="checkbox" id="{{ srs_tag }}check" name="{{ srs_tag }}" value="{{ srs_tag }}" {% if srs_tag == "burned" %}checked{% endif %}><label for="{{ srs_tag }}check">{{ srs_text }}</label>
|
{% for srs_tag in srs_levels %}
|
||||||
|
<input type="checkbox" id="{{ srs_tag }}check" name="{{ srs_tag }}" value="{{ srs_tag }}" {% if srs_tag == "burned" %}checked{% endif %}><label for="{{ srs_tag }}check">{{ srs_tag|capitalize }}</label>
|
||||||
|
<br />
|
||||||
|
{% endfor %}
|
||||||
|
<p><strong>Type</strong></p>
|
||||||
|
{% for item in item_types %}
|
||||||
|
<input type="checkbox" id="{{ item }}check" name="{{ item }}" value="{{ item }}" checked><label for="{{ item }}check">{{ item|capitalize }}</label>
|
||||||
<br />
|
<br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -104,9 +104,10 @@ def parse_range(input_range):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_items_with_level_restriction(level_range, item_state):
|
def get_items_with_level_restriction(level_range, item_state, item_types):
|
||||||
items = []
|
items = []
|
||||||
radical_count = 0
|
radical_count = 0
|
||||||
|
if 'radical' in item_types:
|
||||||
for item in json.loads(current_user.radicals):
|
for item in json.loads(current_user.radicals):
|
||||||
if item['user_specific'] and item['user_specific']['srs'] in item_state and item['level'] in level_range:
|
if item['user_specific'] and item['user_specific']['srs'] in item_state and item['level'] in level_range:
|
||||||
radical_count += 1
|
radical_count += 1
|
||||||
@ -115,6 +116,7 @@ def get_items_with_level_restriction(level_range, item_state):
|
|||||||
else:
|
else:
|
||||||
items.append({'item_type': 'radical', 'question': item['character'], 'answer': item['meaning']})
|
items.append({'item_type': 'radical', 'question': item['character'], 'answer': item['meaning']})
|
||||||
kanji_count = 0
|
kanji_count = 0
|
||||||
|
if 'kanji' in item_types:
|
||||||
for item in json.loads(current_user.kanji):
|
for item in json.loads(current_user.kanji):
|
||||||
made_answer = ""
|
made_answer = ""
|
||||||
if item['user_specific'] and item['user_specific']['srs'] in item_state and item['level'] in level_range:
|
if item['user_specific'] and item['user_specific']['srs'] in item_state and item['level'] in level_range:
|
||||||
@ -128,6 +130,7 @@ def get_items_with_level_restriction(level_range, item_state):
|
|||||||
items.append({'item_type': 'kanji', 'question': item['character'], 'answer': made_answer,
|
items.append({'item_type': 'kanji', 'question': item['character'], 'answer': made_answer,
|
||||||
'answer_meaning': item['meaning']})
|
'answer_meaning': item['meaning']})
|
||||||
vocabulary_count = 0
|
vocabulary_count = 0
|
||||||
|
if 'vocab' in item_types:
|
||||||
for item in json.loads(current_user.vocabulary):
|
for item in json.loads(current_user.vocabulary):
|
||||||
if item['user_specific'] and item['user_specific']['srs'] in item_state and item['level'] in level_range:
|
if item['user_specific'] and item['user_specific']['srs'] in item_state and item['level'] in level_range:
|
||||||
vocabulary_count += 1
|
vocabulary_count += 1
|
||||||
@ -187,7 +190,10 @@ def get_items():
|
|||||||
item_state = ['burned']
|
item_state = ['burned']
|
||||||
if flask.request.args.get('item_state') is not '':
|
if flask.request.args.get('item_state') is not '':
|
||||||
item_state = flask.request.args.get('item_state').split(',')
|
item_state = flask.request.args.get('item_state').split(',')
|
||||||
return get_items_with_level_restriction(level_range, item_state)
|
item_types = ['radical', 'kanji', 'vocab']
|
||||||
|
if flask.request.args.get('item_types') is not '':
|
||||||
|
item_types = flask.request.args.get('item_types').split(',')
|
||||||
|
return get_items_with_level_restriction(level_range, item_state, item_types)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/refresh', methods=['POST'])
|
@app.route('/refresh', methods=['POST'])
|
||||||
|
Loading…
Reference in New Issue
Block a user