Refactor filter initialisation

This commit is contained in:
Oliver Hamlet
2016-06-10 22:46:30 +01:00
parent 7669d4f61c
commit a2770d257b
2 changed files with 28 additions and 34 deletions
+26
View File
@@ -97,7 +97,33 @@
}).catch(handlePromiseError);
}
areAnyFiltersActive() {
return this.hideMessagelessPlugins
|| this.hideInactivePlugins
|| this.conflictingPluginNames
|| this.contentSearchString
|| this.hideVersionNumbers
|| this.hideCRCs
|| this.hideBashTags
|| this.hideAllPluginMessages
|| this.hideNotes
|| this.hideDoNotCleanMessages;
}
load(filterSettings) {
if (filterSettings) {
Object.getOwnPropertyNames(filterSettings).forEach((filter) => {
this[filter] = filterSettings[filter];
document.getElementById(filter).checked = this[filter];
});
}
}
apply(plugins) {
if (!this.areAnyFiltersActive()) {
return;
}
const filteredPlugins = plugins.filter(this.pluginFilter, this);
document.getElementById('cardsNav').items = filteredPlugins;
+2 -34
View File
@@ -117,39 +117,6 @@
document.addEventListener('loot-game-plugins-change', Game.onPluginsChange);
}
function applyEnabledFilters(filters, settings, plugins) {
if (!filters) {
return;
}
if (settings.filters) {
Object.getOwnPropertyNames(settings.filters).forEach((filter) => {
filters[filter] = settings.filters[filter];
document.getElementById(filter).checked = filters[filter];
});
}
if (filters.hideMessagelessPlugins
|| filters.hideInactivePlugins
|| filters.hideNotes
|| filters.hideDoNotCleanMessages
|| filters.hideAllPluginMessages) {
filters.apply(plugins);
}
if (filters.hideVersionNumbers) {
document.getElementById('hideVersionNumbers').dispatchEvent(new Event('change'));
}
if (filters.hideCRCs) {
document.getElementById('hideCRCs').dispatchEvent(new Event('change'));
}
if (filters.hideBashTags) {
document.getElementById('hideBashTags').dispatchEvent(new Event('change'));
}
}
function splitVersion(version) {
const lastPeriodIndex = version.lastIndexOf('.');
return {
@@ -211,7 +178,8 @@
document.getElementById('cardsNav').items = appData.game.plugins;
document.getElementById('pluginCardList').items = appData.game.plugins;
appData.Filters.fillConflictsFilterList(appData.game.plugins);
applyEnabledFilters(appData.filters, appData.settings, appData.game.plugins);
appData.filters.load(appData.settings.filters);
appData.filters.apply(appData.game.plugins);
Dialog.closeProgress();
});
}