better error messages for invalid searches

This commit is contained in:
fin444 2022-09-13 14:26:46 -04:00
parent 88808ceb49
commit 10d97039f0
2 changed files with 15 additions and 6 deletions

View file

@ -143,7 +143,7 @@
</button> </button>
</div> </div>
</div> </div>
<div class = "row box-title justify-content-center" id = "summary"> <div class = "row box-title justify-content-center" id = "summary" style = "color: red;">
</div> </div>
<div class = "row" id = "search-results"> <div class = "row" id = "search-results">

View file

@ -144,30 +144,38 @@ function do_item_search() {
} }
// types // types
let allTypes = true; let allTypes = true, noTypes = true;
let typeQuery = "f:(" let typeQuery = "f:("
for (const type of Object.keys(types)) { for (const type of Object.keys(types)) {
if (types[type]) { if (types[type]) {
typeQuery += "type=\"" + type + "\"|"; typeQuery += "type=\"" + type + "\"|";
noTypes = false;
} else { } else {
allTypes = false; allTypes = false;
} }
} }
if (!allTypes) { if (noTypes) {
document.getElementById("summary").innerHTML = "Error: Cannot search without at least 1 type selected!";
return;
} else if (!allTypes) {
queries.push(typeQuery.substring(0, typeQuery.length - 1) + ")"); queries.push(typeQuery.substring(0, typeQuery.length - 1) + ")");
} }
// rarities // rarities
let allRarities = true; let allRarities = true, noRarities = true;
let rarityQuery = "f:(" let rarityQuery = "f:("
for (const rarity of Object.keys(rarities)) { for (const rarity of Object.keys(rarities)) {
if (rarities[rarity]) { if (rarities[rarity]) {
rarityQuery += "tiername=\"" + rarity + "\"|"; rarityQuery += "tiername=\"" + rarity + "\"|";
noRarities = false;
} else { } else {
allRarities = false; allRarities = false;
} }
} }
if (!allRarities) { if (noRarities) {
document.getElementById("summary").innerHTML = "Error: Cannot search without at least 1 rarity selected!";
return;
} else if (!allRarities) {
queries.push(rarityQuery.substring(0, rarityQuery.length - 1) + ")"); queries.push(rarityQuery.substring(0, rarityQuery.length - 1) + ")");
} }
@ -176,7 +184,8 @@ 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) {
continue; // invalid range document.getElementById("summary").innerHTML = "Error: The minimum of filter " + filter.input_elem.value + " (" + min + ") is greater than its maximum (" + max + ")!";
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);