exclude filters from search, improve atlas error display

This commit is contained in:
fin444 2022-09-13 15:11:14 -04:00
parent c85cd3cb5e
commit ec8e0e7003
3 changed files with 75 additions and 18 deletions

View file

@ -93,7 +93,7 @@ input.min-max-input {
cursor: pointer; cursor: pointer;
} }
#filter-container > div > div > * { #filter-container > div > div > *, #exclude-container > div > div > * {
margin: 0 2px; margin: 0 2px;
} }

View file

@ -122,7 +122,8 @@
</div> </div>
</div> </div>
</div> </div>
<div id = "filter-container" class = "col-lg-5"> <div class = "col-lg-5">
<div id = "filter-container" class = "col">
<div class = "col fw-bold">Filters:</div> <div class = "col fw-bold">Filters:</div>
<div class = "row"> <div class = "row">
<div id = "add-filter" class = "col fw-bold" style = "cursor: pointer; padding-top: 5px;"> <div id = "add-filter" class = "col fw-bold" style = "cursor: pointer; padding-top: 5px;">
@ -130,6 +131,16 @@
</div> </div>
</div> </div>
</div> </div>
<br/>
<div id = "exclude-container" class = "col">
<div class = "col fw-bold">Excluded Filters:</div>
<div class = "row">
<div id = "add-exclude" class = "col fw-bold" style = "cursor: pointer; padding-top: 5px;">
+ Add Excluded Filter
</div>
</div>
</div>
</div>
<div class = "row"> <div class = "row">
<div class = "col-auto" style = "width: 12.5%;"></div> <div class = "col-auto" style = "width: 12.5%;"></div>
<div class = "col-auto"> <div class = "col-auto">
@ -143,7 +154,7 @@
</button> </button>
</div> </div>
</div> </div>
<div class = "row box-title justify-content-center" id = "summary" style = "color: red;"> <div class = "row box-title justify-content-center" id = "summary">
</div> </div>
<div class = "row" id = "search-results"> <div class = "row" id = "search-results">

View file

@ -5,9 +5,9 @@ const translate_mappings = {
//"Set": "set", //"Set": "set",
"Powder Slots": "slots", "Powder Slots": "slots",
//"Type": "type", //"Type": "type",
"Drop type": "drop", //"Drop type": "drop", BROKEN
"Quest requirement": "quest", //"Quest requirement": "quest", BROKEN
"Restriction": "restrict", //"Restriction": "restrict", BROKEN
//"Base Neutral Damage": "nDam", //"Base Neutral Damage": "nDam",
//"Base Fire Damage": "fDam", //"Base Fire Damage": "fDam",
//"Base Water Damage": "wDam", //"Base Water Damage": "wDam",
@ -98,7 +98,7 @@ const special_mappings = {
// "No Defense Req": "defReq=0", // "No Defense Req": "defReq=0",
}; };
let item_filters = [] let item_filters = [];
for (let x in translate_mappings) { for (let x in translate_mappings) {
item_filters.push(x); item_filters.push(x);
} }
@ -110,7 +110,7 @@ let item_categories = ["armor", "accessory", "weapon"];
const types = {bow: false, spear: false, wand: false, dagger: false, relik: false, helmet: false, chestplate: false, leggings: false, boots: false, ring: false, bracelet: false, necklace: false}; const types = {bow: false, spear: false, wand: false, dagger: false, relik: false, helmet: false, chestplate: false, leggings: false, boots: false, ring: false, bracelet: false, necklace: false};
const rarities = {normal: true, unique: true, set: true, rare: true, legendary: true, fabled: true, mythic: true}; const rarities = {normal: true, unique: true, set: true, rare: true, legendary: true, fabled: true, mythic: true};
const filters = []; const filters = [], excludes = [];
let filter_id_counter = 0; let filter_id_counter = 0;
function displayItems(items_copy) { function displayItems(items_copy) {
@ -135,6 +135,7 @@ let search_db;
let expr_parser; let expr_parser;
function do_item_search() { function do_item_search() {
document.getElementById("summary").style.color = "red"; // to display errors, changed to white if search successful
window.scrollTo(0, 0); window.scrollTo(0, 0);
let queries = []; let queries = [];
@ -155,7 +156,7 @@ function do_item_search() {
} }
} }
if (noTypes) { if (noTypes) {
document.getElementById("summary").innerHTML = "Error: Cannot search without at least 1 type selected!"; document.getElementById("summary").innerHTML = "Error: Cannot search without at least 1 type selected";
return; return;
} else if (!allTypes) { } else if (!allTypes) {
queries.push(typeQuery.substring(0, typeQuery.length - 1) + ")"); queries.push(typeQuery.substring(0, typeQuery.length - 1) + ")");
@ -173,7 +174,7 @@ function do_item_search() {
} }
} }
if (noRarities) { if (noRarities) {
document.getElementById("summary").innerHTML = "Error: Cannot search without at least 1 rarity selected!"; document.getElementById("summary").innerHTML = "Error: Cannot search without at least 1 rarity selected";
return; return;
} else if (!allRarities) { } else if (!allRarities) {
queries.push(rarityQuery.substring(0, rarityQuery.length - 1) + ")"); queries.push(rarityQuery.substring(0, rarityQuery.length - 1) + ")");
@ -184,7 +185,7 @@ function do_item_search() {
let min = parseInt(filter.min_elem.value); let min = parseInt(filter.min_elem.value);
let max = parseInt(filter.max_elem.value); let max = parseInt(filter.max_elem.value);
if (min > max) { if (min > max) {
document.getElementById("summary").innerHTML = "Error: The minimum of filter " + filter.input_elem.value + " (" + min + ") is greater than its maximum (" + max + ")!"; document.getElementById("summary").innerHTML = "Error: The minimum of filter " + filter.input_elem.value + " (" + min + ") is greater than its maximum (" + max + ")";
return; return;
} }
let zero_in_min_max = (isNaN(min) || min < 0) && (isNaN(max) || max > 0); let zero_in_min_max = (isNaN(min) || min < 0) && (isNaN(max) || max > 0);
@ -194,7 +195,8 @@ function do_item_search() {
if (filter_name === undefined) { if (filter_name === undefined) {
filter_name = special_mappings[raw_name]; filter_name = special_mappings[raw_name];
if (filter_name === undefined) { if (filter_name === undefined) {
continue; // not a valid filter document.getElementById("summary").innerHTML = "Error: The filter \"" + filter.input_elem.value + "\" is not recognized";
return;
} }
filter_name = "(" + filter_name + ")"; filter_name = "(" + filter_name + ")";
} }
@ -211,6 +213,21 @@ function do_item_search() {
queries.push("s:" + (filter.ascending ? "0-" : "") + filter_name); queries.push("s:" + (filter.ascending ? "0-" : "") + filter_name);
} }
// excludes
for (const exclude of excludes) {
let raw_name = exclude.input_elem.value;
let filter_name = translate_mappings[raw_name];
if (filter_name === undefined) {
filter_name = special_mappings[raw_name];
if (filter_name === undefined) {
document.getElementById("summary").innerHTML = "Error: The excluded filter \"" + exclude.input_elem.value + "\" is not recognized";
return;
}
filter_name = "(" + filter_name + ")";
}
queries.push("f:" + filter_name + "!=0");
}
let filter_query = "true"; let filter_query = "true";
let sort_queries = []; let sort_queries = [];
console.log(queries); console.log(queries);
@ -241,7 +258,8 @@ function do_item_search() {
document.getElementById("summary").textContent = e.message; document.getElementById("summary").textContent = e.message;
return; return;
} }
document.getElementById("summary").textContent = results.length + " results:" document.getElementById("summary").textContent = results.length + " results:";
document.getElementById("summary").style.color = "white";
displayItems(results); displayItems(results);
} }
@ -291,6 +309,7 @@ function init_items() {
// filters // filters
document.getElementById("add-filter").addEventListener("click", create_filter); document.getElementById("add-filter").addEventListener("click", create_filter);
document.getElementById("add-exclude").addEventListener("click", create_exclude);
create_filter(); create_filter();
filters[0].input_elem.value = "Combat Level"; filters[0].input_elem.value = "Combat Level";
init_filter_drag(); init_filter_drag();
@ -356,7 +375,6 @@ function create_filter() {
col.appendChild(trash); col.appendChild(trash);
document.getElementById("filter-container").insertBefore(row, document.getElementById("add-filter").parentElement); document.getElementById("filter-container").insertBefore(row, document.getElementById("add-filter").parentElement);
filters.push(data); filters.push(data);
init_filter_dropdown(data); init_filter_dropdown(data);
} }
@ -426,6 +444,34 @@ function init_filter_drag() {
}); });
} }
function create_exclude() {
let data = {};
let row = make_elem("div", ["row", "filter-row"], {});
let col = make_elem("div", ["col"], {});
row.appendChild(col);
data.div = row;
let filter_input = make_elem("input",
["col", "border-dark", "text-light", "dark-5", "rounded", "scaled-font", "form-control", "form-control-sm", "filter-input"],
{id: "filter-input-" + filter_id_counter, type: "text", placeholder: "Excluded Filter"}
);
filter_id_counter++;
col.appendChild(filter_input);
data.input_elem = filter_input;
let trash = make_elem("img", ["delete-filter"], {src: "../media/icons/trash.svg"});
trash.addEventListener("click", function() {
excludes.splice(Array.from(row.parentElement.children).indexOf(row) - 1, 1);
row.remove();
});
col.appendChild(trash);
document.getElementById("exclude-container").insertBefore(row, document.getElementById("add-exclude").parentElement);
excludes.push(data);
init_filter_dropdown(data);
}
function init_filter_dropdown(filter) { function init_filter_dropdown(filter) {
let field_choice = filter.input_elem; let field_choice = filter.input_elem;
field_choice.onclick = function() {field_choice.dispatchEvent(new Event('input', {bubbles:true}));}; field_choice.onclick = function() {field_choice.dispatchEvent(new Event('input', {bubbles:true}));};