diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-11-22 16:16:59 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-11-22 16:16:59 -0500 |
commit | ba7d6a0e5119395933e1fe696944cd175ff68eed (patch) | |
tree | 40963ada47758a799972e61b6c6f9ab4892cba2a /src/SMAPI.Web/wwwroot | |
parent | aeca48c4190afaf64191253446a869019f4557f5 (diff) | |
download | SMAPI-ba7d6a0e5119395933e1fe696944cd175ff68eed.tar.gz SMAPI-ba7d6a0e5119395933e1fe696944cd175ff68eed.tar.bz2 SMAPI-ba7d6a0e5119395933e1fe696944cd175ff68eed.zip |
add compatibility stats to mod page
Diffstat (limited to 'src/SMAPI.Web/wwwroot')
-rw-r--r-- | src/SMAPI.Web/wwwroot/Content/js/mods.js | 77 |
1 files changed, 59 insertions, 18 deletions
diff --git a/src/SMAPI.Web/wwwroot/Content/js/mods.js b/src/SMAPI.Web/wwwroot/Content/js/mods.js index 2cff551f..b4dc6986 100644 --- a/src/SMAPI.Web/wwwroot/Content/js/mods.js +++ b/src/SMAPI.Web/wwwroot/Content/js/mods.js @@ -4,10 +4,19 @@ var smapi = smapi || {}; var app; smapi.modList = function (mods) { // init data + var defaultStats = { + total: 0, + compatible: 0, + workaround: 0, + soon: 0, + broken: 0, + abandoned: 0, + invalid: 0 + }; var data = { mods: mods, - visibleCount: mods.length, showAdvanced: false, + visibleStats: $.extend({}, defaultStats), filters: { source: { open: { @@ -130,27 +139,16 @@ smapi.modList = function (mods) { var words = data.search.toLowerCase().split(" "); // apply criteria - data.visibleCount = data.mods.length; + var stats = data.visibleStats = $.extend({}, defaultStats); for (var i = 0; i < data.mods.length; i++) { var mod = data.mods[i]; mod.Visible = true; // check filters - if (!this.matchesFilters(mod)) { - mod.Visible = false; - data.visibleCount--; - continue; - } - - // check search terms (all search words should match) - if (words.length) { - for (var w = 0; w < words.length; w++) { - if (mod.SearchableText.indexOf(words[w]) === -1) { - mod.Visible = false; - data.visibleCount--; - break; - } - } + mod.Visible = this.matchesFilters(mod, words); + if (mod.Visible) { + stats.total++; + stats[this.getCompatibilityGroup(mod)]++; } } }, @@ -159,9 +157,10 @@ smapi.modList = function (mods) { /** * Get whether a mod matches the current filters. * @param {object} mod The mod to check. + * @param {string[]} searchWords The search words to match. * @returns {bool} Whether the mod matches the filters. */ - matchesFilters: function(mod) { + matchesFilters: function(mod, searchWords) { var filters = data.filters; // check source @@ -198,8 +197,50 @@ smapi.modList = function (mods) { return false; } + // check search terms + for (var w = 0; w < searchWords.length; w++) { + if (mod.SearchableText.indexOf(searchWords[w]) === -1) + return false; + } + return true; + }, + + /** + * Get a mod's compatibility group for mod metrics. + * @param {object} mod The mod to check. + * @returns {string} The compatibility group (one of 'compatible', 'workaround', 'soon', 'broken', 'abandoned', or 'invalid'). + */ + getCompatibilityGroup: function (mod) { + var status = (mod.BetaCompatibility || mod.Compatibility).Status; + switch (status) { + // obsolete + case "abandoned": + case "obsolete": + return "abandoned"; + + // compatible + case "ok": + case "optional": + return "compatible"; + + // workaround + case "workaround": + case "unofficial": + return "workaround"; + + // soon/broken + case "broken": + if (mod.SourceUrl) + return "soon"; + else + return "broken"; + + default: + return "invalid"; + } } } }); + app.applyFilters(); }; |