Commit ae4ffb26 authored by Themousaillon's avatar Themousaillon

update config files

parents ed7575b0 7485c9cd
......@@ -222,7 +222,7 @@
"type": {
"label": "type",
"type": "category",
"filter": ["external text", "press", "picture", "video", "cartoon", "letter", "treaty", "sound", "article"],
"filter": ["external-text", "press", "picture", "video", "cartoon", "letter", "treaty", "sound", "article"],
"show": true,
"link": false,
"unique": false
......
......@@ -117,9 +117,11 @@ function start(settings, login, password) {
html += '<button type="button" class="btn btn-light" id="' + id + '-b_none">none</button>';
html += '<button type="button" class="btn btn-light" id="' + id + '-b_invert">invert</button>';
html += '</span>';
default:
break;
default:
}
if (option.label === 'content')
html += '<input id="' + id + '" type="text" value="" aria-label="keyword" placeholder="Enter keyword">'
$('#filters-container').append(html);
}
});
......@@ -161,6 +163,8 @@ function start(settings, login, password) {
});
break;
}
if (option.label === 'content')
document.getElementById(id).addEventListener('input', () => { app.updateFilter(); });
}
});
......
......@@ -192,8 +192,23 @@ module.exports = function () {
};
Frame.prototype.getFilter = function () {
const formatDate = str => {
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
let yearSign = "+"
let [day, month, year] = str.split(" ")
if (year[0] === "-")
yearSign = "-"
year = year.replace("-", "")
// we need to make year a six digit number in order to be able to ECMA strings for negative time (BC)
const ecma = 6 - year.length
const addedZeros = Array(ecma).fill("0").join().replace(/,/g, "")
day = day.length < 2 ? "0" + day: day
month = (months.indexOf(month) + 1).toString()
month = month.length < 2 ? "0" + month: month
return yearSign + addedZeros + year + "-" + month + "-" + day
}
let filter = {};
this.app.settings.source.properties.forEach((property) => {
let option = this.app.settings.source.options[property];
let id = "filter-" + option.label;
......@@ -202,7 +217,7 @@ module.exports = function () {
case "date":
let elem = document.getElementById(id + '-slider');
if (!!elem && !!elem.noUiSlider) {
let dates = elem.noUiSlider.get();
let dates = elem.noUiSlider.get().map(s => formatDate(s));
filter[property] = {
type: "date",
start: new Date(dates[0]),
......@@ -227,6 +242,15 @@ module.exports = function () {
});
break;
}
if (option.label === "content"){
let elem = document.getElementById(id);
if (elem) {
filter["keywords"] = {
type: "content",
keywords: elem.value.split(" ")
}
}
}
}
});
......
......@@ -95,8 +95,7 @@ module.exports = (function () {
Node.prototype.filterResource = function (resource, globalFilter) {
let filter = this.filter()!==undefined? this.filter() : globalFilter;
let filter = this.filter() !== undefined? this.filter() : globalFilter;
let properties = Object.keys(filter);
return properties.every((property) => {
let f = filter[property];
......@@ -105,7 +104,7 @@ module.exports = (function () {
let d0 = f.start;
let d1 = f.end;
let date = new Date(resource[property]);
if (d0.getTime()/1000>date.getTime()/1000 || date.getTime()/1000>=d1.getTime()/1000) {
if (d0.getTime() > date.getTime() || date.getTime() > d1.getTime()) {
return false;
}
break;
......@@ -113,9 +112,12 @@ module.exports = (function () {
let i = f.categories.indexOf(resource[property]);
if (i >= 0 && !f.checked[i]) {
return false;
} else if (i == -1 && !f.checked[f.categories.indexOf('others')]){
} else if (i === -1 && !f.checked[f.categories.indexOf('others')]){
return false;
};
break;
case 'content':
return f.keywords === "" ? true : f.keywords.every(keyword => resource.content.toLowerCase().includes(keyword.toLowerCase()))
default:
break;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment