From a463a05607c89922af7e908b39aa897b8d23bfbf Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 3 Jun 2018 13:54:26 -0400 Subject: 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. --- src/SMAPI.Web/ViewModels/LogParserModel.cs | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/SMAPI.Web/ViewModels') 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 @@ -5,6 +8,13 @@ namespace StardewModdingAPI.Web.ViewModels /// The view model for the log parser page. public class LogParserModel { + /********* + ** Properties + *********/ + /// A regex pattern matching characters to remove from a mod name to create the slug ID. + private readonly Regex SlugInvalidCharPattern = new Regex("[^a-z0-9]", RegexOptions.Compiled | RegexOptions.IgnoreCase); + + /********* ** Accessors *********/ @@ -17,6 +27,12 @@ namespace StardewModdingAPI.Web.ViewModels /// The parsed log info. public ParsedLog ParsedLog { get; set; } + /// An error which occurred while uploading the log to Pastebin. + public string UploadError { get; set; } + + /// An error which occurred while parsing the log file. + public string ParseError => this.ParsedLog?.Error; + /********* ** Public methods @@ -34,5 +50,27 @@ namespace StardewModdingAPI.Web.ViewModels this.PasteID = pasteID; this.ParsedLog = parsedLog; } + + /// Get all content packs in the log grouped by the mod they're for. + public IDictionary GetContentPacksByMod() + { + // get all mods & content packs + LogModInfo[] mods = this.ParsedLog?.Mods; + if (mods == null || !mods.Any()) + return new Dictionary(); + + // group by mod + return mods + .Where(mod => mod.ContentPackFor != null) + .GroupBy(mod => mod.ContentPackFor) + .ToDictionary(group => group.Key, group => group.ToArray()); + } + + /// Get a sanitised mod name that's safe to use in anchors, attributes, and URLs. + /// The mod name. + public string GetSlug(string modName) + { + return this.SlugInvalidCharPattern.Replace(modName, ""); + } } } -- cgit