diff --git a/lute/templates/term/index.html b/lute/templates/term/index.html index d3db240d..666ed5ff 100644 --- a/lute/templates/term/index.html +++ b/lute/templates/term/index.html @@ -11,6 +11,15 @@
Language | ++ + |
Parent terms only |
@@ -163,6 +172,7 @@
// data sent to the controller, and are used by the
// TermRepository.
data: {
+ filtLanguage: () => $('#filtLanguage').val(),
filtParentsOnly: () => $('#filtParentsOnly').prop('checked'),
filtAgeMin: () => $('#filtAgeMin').val(),
filtAgeMax: () => $('#filtAgeMax').val(),
@@ -283,6 +293,7 @@
let handle_filter_update = function() {
const store = {
+ filtLanguage: $('#filtLanguage').val(),
filtDisplay: $('#filterControls').css('display'),
filtParentsOnly: $('#filtParentsOnly').prop('checked'),
filtAgeMin: $('#filtAgeMin').val(),
@@ -309,10 +320,11 @@
return;
$('#showHideFilters').prop('src', "{{ url_for('static', filename='icn/minus-button.png') }}");
- $('#filtParentsOnly').prop('checked', store.filtParentsOnly);
- if (store.filtAgeMin != '')
+ $('#filtLanguage').val(parseInt(store.filtLanguage ?? '0'));
+ $('#filtParentsOnly').prop('checked', store.filtParentsOnly ?? false);
+ if ((store.filtAgeMin ?? '') != '')
$('#filtAgeMin').val(parseInt(store.filtAgeMin));
- if (store.filtAgeMax != '')
+ if ((store.filtAgeMax ?? '') != '')
$('#filtAgeMax').val(parseInt(store.filtAgeMax));
$('#filtStatusMin').val(parseInt(store.filtStatusMin));
$('#filtStatusMax').val(parseInt(store.filtStatusMax));
@@ -334,6 +346,7 @@
};
let handle_clear_filters = function() {
+ $('#filtLanguage').val(0);
$('#filtParentsOnly').prop('checked', false);
$('#filtAgeMin').val('');
$('#filtAgeMax').val('');
@@ -348,7 +361,8 @@
set_up_parent_autocomplete();
$('#btnSetParent').click(handle_set_parent_click);
$('#showHideFilters').click(handle_show_hide_filter_click);
-
+
+ $('#filtLanguage').change(handle_filter_update);
$('#filtParentsOnly').change(handle_filter_update);
$('#filtAgeMin').keyup(handle_filter_update);
$('#filtAgeMax').keyup(handle_filter_update);
diff --git a/lute/term/datatables.py b/lute/term/datatables.py
index 009ac17b..bef161d8 100644
--- a/lute/term/datatables.py
+++ b/lute/term/datatables.py
@@ -44,43 +44,50 @@ def get_data_tables_list(parameters):
LEFT OUTER JOIN wordimages wi on wi.WiWoID = w.WoID
"""
- filt_parents_only = parameters["filtParentsOnly"]
- filt_age_min = parameters["filtAgeMin"].strip()
- filt_age_max = parameters["filtAgeMax"].strip()
- filt_status_min = int(parameters["filtStatusMin"])
- filt_status_max = int(parameters["filtStatusMax"])
- filt_include_ignored = parameters["filtIncludeIgnored"]
-
typecrit = supported_parser_type_criteria()
wheres = [f"L.LgParserType in ({typecrit})"]
- if filt_parents_only == "true":
+
+ # Add "where" criteria for all the filters.
+
+ # Have to check for 'null' for language filter.
+ # A new user may filter the language when the demo data is loaded,
+ # but on "wipe database" the filtLanguage value stored in localdata
+ # may be invalid, resulting in the filtLanguage form control actually
+ # sending the **string value** "null" here.
+ # The other filter values don't change with the data,
+ # so we don't need to check for null.
+ # Tricky tricky.
+ language_id = parameters["filtLanguage"]
+ if language_id == "null" or language_id is None:
+ language_id = "0"
+ language_id = int(language_id)
+ if language_id != 0:
+ wheres.append(f"L.LgID == {language_id}")
+
+ if parameters["filtParentsOnly"] == "true":
wheres.append("parents.parentlist IS NULL")
- if filt_age_min:
- filt_age_min = int(filt_age_min)
- wheres.append(
- f"cast(julianday('now') - julianday(w.wocreated) as int) >= {filt_age_min}"
- )
- if filt_age_max:
- filt_age_max = int(filt_age_max)
- wheres.append(
- f"cast(julianday('now') - julianday(w.wocreated) as int) <= {filt_age_max}"
- )
- status_wheres = ["StID <> 98"]
- if filt_status_min > 0:
- status_wheres.append(f"StID >= {filt_status_min}")
- if filt_status_max > 0:
- status_wheres.append(f"StID <= {filt_status_max}")
+ sql_age_calc = "cast(julianday('now') - julianday(w.wocreated) as int)"
+ age_min = parameters["filtAgeMin"].strip()
+ if age_min:
+ wheres.append(f"{sql_age_calc} >= {int(age_min)}")
+ age_max = parameters["filtAgeMax"].strip()
+ if age_max:
+ wheres.append(f"{sql_age_calc} <= {int(age_max)}")
+ status_wheres = ["StID <> 98"]
+ status_min = int(parameters["filtStatusMin"])
+ status_max = int(parameters["filtStatusMax"])
+ if status_min > 0:
+ status_wheres.append(f"StID >= {status_min}")
+ if status_max > 0:
+ status_wheres.append(f"StID <= {status_max}")
status_wheres = " AND ".join(status_wheres)
- if filt_include_ignored == "true":
+ if parameters["filtIncludeIgnored"] == "true":
status_wheres = f"({status_wheres} OR StID = 98)"
wheres.append(status_wheres)
- where = " AND ".join(wheres)
- full_base_sql = base_sql + " WHERE " + where
-
- session = db.session
- connection = session.connection()
-
- return DataTablesSqliteQuery.get_data(full_base_sql, parameters, connection)
+ # Phew.
+ return DataTablesSqliteQuery.get_data(
+ base_sql + " WHERE " + " AND ".join(wheres), parameters, db.session.connection()
+ )
diff --git a/lute/term/routes.py b/lute/term/routes.py
index 90379773..dc470d75 100644
--- a/lute/term/routes.py
+++ b/lute/term/routes.py
@@ -18,7 +18,12 @@
@bp.route("/index/ |