Refactor filter application function

This commit is contained in:
Oliver Hamlet
2016-06-10 22:38:13 +01:00
parent e64b110405
commit 7669d4f61c
5 changed files with 35 additions and 38 deletions
-1
View File
@@ -477,7 +477,6 @@
<script src="js/dom.js"></script>
<script src="js/events.js"></script>
<script src="js/game.js"></script>
<script src="js/helpers.js"></script>
<script src="js/translateStaticText.js"></script>
<script src="js/plugin.js"></script>
<script src="js/query.js"></script>
+8 -8
View File
@@ -6,7 +6,7 @@ function onSidebarFilterToggle(evt) {
} else {
loot.filters.contentSearchString = evt.target.value;
}
filterPluginData(loot.game.plugins, loot.filters);
loot.filters.apply(loot.game.plugins);
}
function onJumpToGeneralInfo() {
document.getElementById('pluginCardList').scroll(0, 0);
@@ -38,7 +38,7 @@ function onChangeGame(evt) {
loot.Filters.fillConflictsFilterList(loot.game.plugins);
/* Now update virtual lists. */
filterPluginData(loot.game.plugins, loot.filters);
loot.filters.apply(loot.game.plugins);
loot.Dialog.closeProgress();
}).catch(loot.handlePromiseError);
@@ -74,7 +74,7 @@ function onUpdateMasterlist() {
function onSortPlugins() {
if (loot.filters.deactivateConflictsFilter()) {
/* Conflicts filter was undone, update the displayed cards. */
filterPluginData(loot.game.plugins, loot.filters);
loot.filters.apply(loot.game.plugins);
}
let promise = Promise.resolve();
@@ -129,7 +129,7 @@ function onSortPlugins() {
/* Now update the UI for the new order. */
loot.game.plugins = loot.game.loadOrder;
filterPluginData(loot.game.plugins, loot.filters);
loot.filters.apply(loot.game.plugins);
loot.state.enterSortingState();
@@ -150,7 +150,7 @@ function onCancelSort() {
return loot.query('cancelSort').then(JSON.parse).then((messages) => {
/* Sort UI elements again according to stored old load order. */
loot.game.plugins = loot.game.oldLoadOrder;
filterPluginData(loot.game.plugins, loot.filters);
loot.filters.apply(loot.game.plugins);
delete loot.game.loadOrder;
delete loot.game.oldLoadOrder;
@@ -238,7 +238,7 @@ function onContentRefresh() {
loot.Filters.fillConflictsFilterList(loot.game.plugins);
/* Reapply filters. */
filterPluginData(loot.game.plugins, loot.filters);
loot.filters.apply(loot.game.plugins);
loot.Dialog.closeProgress();
}).catch(loot.handlePromiseError);
@@ -421,12 +421,12 @@ function onConflictsFilter(evt) {
gamePlugin.update(plugin);
}
});
filterPluginData(loot.game.plugins, loot.filters);
loot.filters.apply(loot.game.plugins);
loot.Dialog.closeProgress();
}).catch(loot.handlePromiseError);
} else {
loot.filters.deactivateConflictsFilter();
filterPluginData(loot.game.plugins, loot.filters);
loot.filters.apply(loot.game.plugins);
}
}
function onCopyMetadata(evt) {
+26
View File
@@ -97,6 +97,32 @@
}).catch(handlePromiseError);
}
apply(plugins) {
const filteredPlugins = plugins.filter(this.pluginFilter, this);
document.getElementById('cardsNav').items = filteredPlugins;
document.getElementById('pluginCardList').items = filteredPlugins;
const pluginCards = document.getElementById('pluginCardList').children;
for (let i = 0; i < pluginCards.length; ++i) {
if (pluginCards[i].data) {
pluginCards[i].updateContent(true);
}
}
document.getElementById('cardsNav').notifyResize();
document.getElementById('pluginCardList').notifyResize();
/* Now perform search again. If there is no current search, this won't
do anything. */
document.getElementById('searchBar').search();
/* Re-count all hidden plugins and messages. */
document.getElementById('hiddenPluginNo').textContent = plugins.length - filteredPlugins.length;
document.getElementById('hiddenMessageNo').textContent = plugins.reduce((previousValue, currentValue) => (
previousValue + currentValue.messages.length - currentValue.getCardContent(this).messages.length
), 0);
}
static fillConflictsFilterList(plugins) {
const list = document.getElementById('conflictsFilter');
-28
View File
@@ -1,28 +0,0 @@
'use strict';
function filterPluginData(plugins, filters) {
const filteredPlugins = plugins.filter(filters.pluginFilter, filters);
document.getElementById('cardsNav').items = filteredPlugins;
document.getElementById('pluginCardList').items = filteredPlugins;
const pluginCards = document.getElementById('pluginCardList').children;
for (let i = 0; i < pluginCards.length; ++i) {
if (pluginCards[i].data) {
pluginCards[i].updateContent(true);
}
}
document.getElementById('cardsNav').notifyResize();
document.getElementById('pluginCardList').notifyResize();
/* Now perform search again. If there is no current search, this won't
do anything. */
document.getElementById('searchBar').search();
/* Re-count all hidden plugins and messages. */
document.getElementById('hiddenPluginNo').textContent = plugins.length - filteredPlugins.length;
let hiddenMessageNo = 0;
plugins.forEach((plugin) => {
hiddenMessageNo += plugin.messages.length - plugin.getCardContent(filters).messages.length;
});
document.getElementById('hiddenMessageNo').textContent = hiddenMessageNo;
}
+1 -1
View File
@@ -134,7 +134,7 @@
|| filters.hideNotes
|| filters.hideDoNotCleanMessages
|| filters.hideAllPluginMessages) {
filterPluginData(plugins, filters);
filters.apply(plugins);
}
if (filters.hideVersionNumbers) {