diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-06-03 13:54:26 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-06-03 13:54:26 -0400 |
commit | a463a05607c89922af7e908b39aa897b8d23bfbf (patch) | |
tree | 4d3bb17a499357ac99d929bee695dd316e7e772f /src/SMAPI.Web/ViewModels | |
parent | 045891131ccfdb980fcd84b3d3e52a2b2fcd94e2 (diff) | |
download | SMAPI-a463a05607c89922af7e908b39aa897b8d23bfbf.tar.gz SMAPI-a463a05607c89922af7e908b39aa897b8d23bfbf.tar.bz2 SMAPI-a463a05607c89922af7e908b39aa897b8d23bfbf.zip |
redesign log parser upload page
This makes the instructions much more clear and prominent, so it should be more intuitive for players. The previous design often confused users because they saw the big textbox and ignored the little instructions above it.
Diffstat (limited to 'src/SMAPI.Web/ViewModels')
-rw-r--r-- | src/SMAPI.Web/ViewModels/LogParserModel.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/SMAPI.Web/ViewModels/LogParserModel.cs b/src/SMAPI.Web/ViewModels/LogParserModel.cs index 8c026536..0fbd8ad5 100644 --- a/src/SMAPI.Web/ViewModels/LogParserModel.cs +++ b/src/SMAPI.Web/ViewModels/LogParserModel.cs @@ -1,3 +1,6 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; using StardewModdingAPI.Web.Framework.LogParsing.Models; namespace StardewModdingAPI.Web.ViewModels @@ -6,6 +9,13 @@ namespace StardewModdingAPI.Web.ViewModels public class LogParserModel { /********* + ** Properties + *********/ + /// <summary>A regex pattern matching characters to remove from a mod name to create the slug ID.</summary> + private readonly Regex SlugInvalidCharPattern = new Regex("[^a-z0-9]", RegexOptions.Compiled | RegexOptions.IgnoreCase); + + + /********* ** Accessors *********/ /// <summary>The root URL for the log parser controller.</summary> @@ -17,6 +27,12 @@ namespace StardewModdingAPI.Web.ViewModels /// <summary>The parsed log info.</summary> public ParsedLog ParsedLog { get; set; } + /// <summary>An error which occurred while uploading the log to Pastebin.</summary> + public string UploadError { get; set; } + + /// <summary>An error which occurred while parsing the log file.</summary> + public string ParseError => this.ParsedLog?.Error; + /********* ** Public methods @@ -34,5 +50,27 @@ namespace StardewModdingAPI.Web.ViewModels this.PasteID = pasteID; this.ParsedLog = parsedLog; } + + /// <summary>Get all content packs in the log grouped by the mod they're for.</summary> + public IDictionary<string, LogModInfo[]> GetContentPacksByMod() + { + // get all mods & content packs + LogModInfo[] mods = this.ParsedLog?.Mods; + if (mods == null || !mods.Any()) + return new Dictionary<string, LogModInfo[]>(); + + // group by mod + return mods + .Where(mod => mod.ContentPackFor != null) + .GroupBy(mod => mod.ContentPackFor) + .ToDictionary(group => group.Key, group => group.ToArray()); + } + + /// <summary>Get a sanitised mod name that's safe to use in anchors, attributes, and URLs.</summary> + /// <param name="modName">The mod name.</param> + public string GetSlug(string modName) + { + return this.SlugInvalidCharPattern.Replace(modName, ""); + } } } |