Skip to content
Permalink
Browse files

Add deck filter to history page

refactors old event filter to use util.createSelect and adds a second deck filter selector
  • Loading branch information...
lusbenjamin committed Apr 7, 2019
1 parent b83d664 commit d31043864281de60a7db7e092b891deb41141cfc
Showing with 49 additions and 24 deletions.
  1. +49 −24 window_main/history.js
@@ -12,20 +12,28 @@ globals
setsList,
addHover,
selectAdd,
createSelect,
compare_cards,
getReadableEvent,
getReadableDeckName,
getWinrateClass,
createDivision,
playerData,
tags_colors,
showLoadingBars,
decks,
$$
*/

const RANKS = ["Bronze", "Silver", "Gold", "Platinum", "Diamond", "Mythic"];
const DEFAULT_FORMAT = "All Formats";
const ALL_DRAFTS_FORMAT = "All Draft Modes";
const DRAFT_REPLAYS_FORMAT = "Draft Replays";
const DEFAULT_DECK = "All Decks";

let loadHistory = 0;
let filterEvent = "All";
let filterEvent = DEFAULT_FORMAT;
let filterDeck = DEFAULT_DECK;
let filteredSampleSize = 0;
let viewingLimitSeason = false;

@@ -36,11 +44,17 @@ function isDraftMatch(match) {
}

function filterMatch(match) {
return (
filterEvent == "All" ||
let passesEventFilter = (
filterEvent == DEFAULT_FORMAT ||
match.eventId == filterEvent ||
(filterEvent == "All Draft Modes" && isDraftMatch(match))
(filterEvent == ALL_DRAFTS_FORMAT && isDraftMatch(match)) ||
(filterEvent == DRAFT_REPLAYS_FORMAT && match.type == "draft")
);
let passesDeckFilter = (
filterDeck == DEFAULT_DECK ||
match.playerDeck && match.playerDeck.id == filterDeck
);
return passesEventFilter && passesDeckFilter;
}

function open_history_tab(loadMore) {
@@ -117,6 +131,7 @@ function open_history_tab(loadMore) {
let historyTop = createDivision(["history_top"]);

let historyTopFilter = createDivision(["history_top_filter"]);
historyTopFilter.style.display = "flex";
historyTop.appendChild(historyTopFilter);

let historyTopWinrate = createDivision(["history_top_winrate"]);
@@ -139,27 +154,29 @@ function open_history_tab(loadMore) {

historyTop.appendChild(historyTopWinrate);

let select = $('<select id="query_select"></select>');
if (filterEvent != "All") {
select.append('<option value="All">All</option>');
}

if (filterEvent != "All Draft") {
select.append('<option value="All Draft Modes">All Draft Modes</option>');
}
let formatSelect = createSelect(
historyTopFilter,
[DEFAULT_FORMAT, ALL_DRAFTS_FORMAT, DRAFT_REPLAYS_FORMAT, ...eventsList],
filterEvent,
filterHistoryByEvent,
"history_query_format",
getReadableEvent
);
formatSelect.style.margin = "12px auto auto auto";

let sortedDecks = [...decks];
sortedDecks.sort((a, b) => a.name.localeCompare(b.name));
let deckSelect = createSelect(
historyTopFilter,
[DEFAULT_DECK, ...sortedDecks.map(deck => deck.id)],
filterDeck,
filterHistoryByDeck,
"history_query_deck",
getReadableDeckName
);
deckSelect.style.margin = "12px 4px auto 16px";

eventsList.forEach(evId => {
if (evId === filterEvent) {
return;
}
select.append(
'<option value="' + evId + '">' + getReadableEvent(evId) + "</option>"
);
});
historyTopFilter.appendChild(select[0]);
historyColumn.appendChild(historyTop);
selectAdd(select, filterHistory);
select.next("div.select-styled").text(getReadableEvent(filterEvent));
}

//console.log("loadHistory: ", loadHistory, "loadMore: ", loadMore, "matches.length: ", matchesHistory.matches.length, "filteredSampleSize: ", filteredSampleSize);
@@ -690,8 +707,16 @@ function deleteTag(matchid, tag) {
ipc_send("delete_history_tag", obj);
}

function filterHistory(filter) {
function filterHistoryByEvent(filter) {
filterEvent = filter;
// automatically clear deck filter upon changing format filter
// helps prevent user confusion caused by invalid filter combinations
filterDeck = DEFAULT_DECK;
open_history_tab(0);
}

function filterHistoryByDeck(filter) {
filterDeck = filter;
open_history_tab(0);
}

0 comments on commit d310438

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