Skip to content
Permalink
Browse files

Merge pull request #627 from thoms999/master

Added an Advanced Filter : Owned quantity
  • Loading branch information...
Manuel-777 committed Oct 13, 2019
2 parents b02f8c2 + 24445f2 commit 1beb3d8f63e30d37da634b297a1b262d030c69d6
Showing with 84 additions and 24 deletions.
  1. +84 −24 window_main/collection.js
@@ -430,18 +430,6 @@ function openCollectionTab() {
let main_but_cont = createDiv(["main_buttons_container"]);
let cont = createDiv(["buttons_container"]);

addCheckboxSearch(
cont,
'<div class="icon_search_unowned"></div>Show unowned',
"query_unown",
false
);
addCheckboxSearch(
cont,
'<div class="icon_search_incomplete"></div>Incomplete only',
"query_incomplete",
false
);
addCheckboxSearch(
cont,
'<div class="icon_search_new"></div>Newly acquired only',
@@ -520,6 +508,43 @@ function openCollectionTab() {
main_but_cont.appendChild(cont);
filters.appendChild(main_but_cont);

cont = createDiv(["buttons_container"]);
icd = createDiv(["input_container_inventory", "auto_width"]);

label = document.createElement("label");
label.style.display = "table";
label.innerHTML = "Owned Qty:";
icd.appendChild(label);

let inputQty = document.createElement("input");
inputQty.style.maxWidth = "80px";
inputQty.id = "query_qty";
inputQty.autocomplete = "off";
inputQty.type = "number";
inputQty.min = "0";
inputQty.max = "4";

icd.appendChild(inputQty);
cont.appendChild(icd);
let checkboxQtyHigher = addCheckboxSearch(
cont,
"Higher than",
"query_qtyhigher",
false,
true
);
addCheckboxSearch(cont, "Equal to", "query_qtyequal", true);
let checkboxQtyLower = addCheckboxSearch(
cont,
"Lower than",
"query_qtylower",
false,
true
);

main_but_cont.appendChild(cont);
filters.appendChild(main_but_cont);

searchButton = createDiv(["button_simple", "button_thin"], "Search");
searchButton.style.margin = "24px auto";
filters.appendChild(searchButton);
@@ -544,6 +569,18 @@ function openCollectionTab() {
}
});

checkboxQtyLower.addEventListener("change", () => {
if (document.getElementById("query_qtylower").checked == true) {
document.getElementById("query_qtyhigher").checked = false;
}
});

checkboxQtyHigher.addEventListener("change", () => {
if (document.getElementById("query_qtyhigher").checked == true) {
document.getElementById("query_qtylower").checked = false;
}
});

printCards();
}

@@ -607,8 +644,6 @@ function resetFilters() {

document.getElementById("query_name").value = "";
document.getElementById("query_type").value = "";
document.getElementById("query_unown").checked = false;
document.getElementById("query_incomplete").checked = false;
document.getElementById("query_new").checked = false;
document.getElementById("query_multicolor").checked = false;
document.getElementById("query_exclude").checked = false;
@@ -623,6 +658,10 @@ function resetFilters() {
document.getElementById("query_cmcequal").checked = true;
document.getElementById("query_cmchigher").checked = false;

document.getElementById("query_qtylower").checked = false;
document.getElementById("query_qtyequal").checked = true;
document.getElementById("query_qtyhigher").checked = false;

printCollectionPage();
}

@@ -932,8 +971,6 @@ function printCards() {

let filterName = document.getElementById("query_name").value.toLowerCase();
let filterType = document.getElementById("query_type").value.toLowerCase();
let filterUnown = document.getElementById("query_unown").checked;
let filterIncomplete = document.getElementById("query_incomplete").checked;
let filterNew = document.getElementById("query_new");
let filterMulti = document.getElementById("query_multicolor");
let filterExclude = document.getElementById("query_exclude");
@@ -950,9 +987,14 @@ function printCards() {
let filterCmcEqual = document.getElementById("query_cmcequal").checked;
let filterCmcHigher = document.getElementById("query_cmchigher").checked;

let filterQty = document.getElementById("query_qty").value;
let filterQtyLower = document.getElementById("query_qtylower").checked;
let filterQtyEqual = document.getElementById("query_qtyequal").checked;
let filterQtyHigher = document.getElementById("query_qtyhigher").checked;

let totalCards = 0;
let list;
if (filterUnown) {
if (filterQty == 0 || filterQtyLower) {
list = db.cardIds;
} else {
list = Object.keys(pd.cards.cards);
@@ -997,13 +1039,6 @@ function printCards() {
}
}

if (filterIncomplete) {
const owned = pd.cards.cards[card.id];
if (owned >= 4) {
continue;
}
}

if (filterNew.checked && pd.cardsNew[key] === undefined) {
continue;
}
@@ -1038,6 +1073,31 @@ function printCards() {
}
}

if (filterQty > 0) {
const owned = pd.cards.cards[card.id];
if (filterQtyLower && filterQtyEqual) {
if (owned > filterQty) {
continue;
}
} else if (filterQtyHigher && filterQtyEqual) {
if (owned < filterQty) {
continue;
}
} else if (filterQtyLower && !filterQtyEqual) {
if (owned >= filterQty) {
continue;
}
} else if (filterQtyHigher && !filterQtyEqual) {
if (owned <= filterQty) {
continue;
}
} else if (!filterQtyHigher && !filterQtyLower && filterQtyEqual) {
if (owned != filterQty) {
continue;
}
}
}

if (rarity == "land" && filterAnyRarityChecked && !filterCommon) continue;
if (rarity == "common" && filterAnyRarityChecked && !filterCommon) continue;
if (rarity == "uncommon" && filterAnyRarityChecked && !filterUncommon)

0 comments on commit 1beb3d8

Please sign in to comment.
You can’t perform that action at this time.