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/Controllers/LogParserController.cs | 31 ++++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/SMAPI.Web/Controllers/LogParserController.cs') diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs index 62547deb..2bff1392 100644 --- a/src/SMAPI.Web/Controllers/LogParserController.cs +++ b/src/SMAPI.Web/Controllers/LogParserController.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.IO.Compression; +using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -72,13 +73,27 @@ namespace StardewModdingAPI.Web.Controllers ** JSON ***/ /// Save raw log data. - /// The log content to save. - [HttpPost, Produces("application/json"), AllowLargePosts] - [Route("log/save")] - public async Task PostAsync([FromBody] string content) + [HttpPost, AllowLargePosts] + [Route("log")] + public async Task PostAsync() { - content = this.CompressString(content); - return await this.Pastebin.PostAsync(content); + // get raw log text + string input = this.Request.Form["input"].FirstOrDefault(); + if (string.IsNullOrWhiteSpace(input)) + return this.View("Index", new LogParserModel(this.Config.LogParserUrl, null, null) { UploadError = "The log file seems to be empty." }); + + // upload log + input = this.CompressString(input); + SavePasteResult result = await this.Pastebin.PostAsync(input); + + // handle errors + if (!result.Success) + return this.View("Index", new LogParserModel(this.Config.LogParserUrl, result.ID, null) { UploadError = $"Pastebin error: {result.Error ?? "unknown error"}" }); + + // redirect to view + UriBuilder uri = new UriBuilder(new Uri(this.Config.LogParserUrl)); + uri.Path = uri.Path.TrimEnd('/') + '/' + result.ID; + return this.Redirect(uri.Uri.ToString()); } @@ -115,7 +130,7 @@ namespace StardewModdingAPI.Web.Controllers } // prefix length - var zipBuffer = new byte[compressedData.Length + 4]; + byte[] zipBuffer = new byte[compressedData.Length + 4]; Buffer.BlockCopy(compressedData, 0, zipBuffer, 4, compressedData.Length); Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, zipBuffer, 0, 4); @@ -151,7 +166,7 @@ namespace StardewModdingAPI.Web.Controllers memoryStream.Write(zipBuffer, 4, zipBuffer.Length - 4); // read data - var buffer = new byte[dataLength]; + byte[] buffer = new byte[dataLength]; memoryStream.Position = 0; using (GZipStream gZipStream = new GZipStream(memoryStream, CompressionMode.Decompress)) gZipStream.Read(buffer, 0, buffer.Length); -- cgit From 3e5c109df1f90904c2dcb177e35b35f003e90fd9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 27 Jun 2018 09:47:31 -0400 Subject: add log parser option to view raw log --- docs/release-notes.md | 1 + src/SMAPI.Web/Controllers/LogParserController.cs | 11 ++-- src/SMAPI.Web/ViewModels/LogParserModel.cs | 19 +++++- src/SMAPI.Web/Views/LogParser/Index.cshtml | 79 ++++++++++++++---------- src/SMAPI.Web/wwwroot/Content/css/log-parser.css | 4 ++ src/SMAPI.Web/wwwroot/Content/js/log-parser.js | 14 ++++- 6 files changed, 88 insertions(+), 40 deletions(-) (limited to 'src/SMAPI.Web/Controllers/LogParserController.cs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 5a9e4e92..329ea3ad 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -65,6 +65,7 @@ * Redesigned UI to be more mobile-friendly. * Added option to download from Nexus. * Changed log parser filters to show `DEBUG` messages by default. + * Added log parser option to view raw log. * Fixed log parser issue when content packs have no description. * Fixed log parser mangling crossplatform paths in some cases. diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs index 2bff1392..354bdb06 100644 --- a/src/SMAPI.Web/Controllers/LogParserController.cs +++ b/src/SMAPI.Web/Controllers/LogParserController.cs @@ -52,21 +52,22 @@ namespace StardewModdingAPI.Web.Controllers ***/ /// Render the log parser UI. /// The paste ID. + /// Whether to display the raw unparsed log. [HttpGet] [Route("log")] [Route("log/{id}")] - public async Task Index(string id = null) + public async Task Index(string id = null, bool raw = false) { // fresh page if (string.IsNullOrWhiteSpace(id)) - return this.View("Index", new LogParserModel(this.Config.LogParserUrl, id, null)); + return this.View("Index", new LogParserModel(this.Config.LogParserUrl, id)); // log page PasteInfo paste = await this.GetAsync(id); ParsedLog log = paste.Success ? new LogParser().Parse(paste.Content) : new ParsedLog { IsValid = false, Error = "Pastebin error: " + paste.Error }; - return this.View("Index", new LogParserModel(this.Config.LogParserUrl, id, log)); + return this.View("Index", new LogParserModel(this.Config.LogParserUrl, id, log, raw)); } /*** @@ -80,7 +81,7 @@ namespace StardewModdingAPI.Web.Controllers // get raw log text string input = this.Request.Form["input"].FirstOrDefault(); if (string.IsNullOrWhiteSpace(input)) - return this.View("Index", new LogParserModel(this.Config.LogParserUrl, null, null) { UploadError = "The log file seems to be empty." }); + return this.View("Index", new LogParserModel(this.Config.LogParserUrl, null) { UploadError = "The log file seems to be empty." }); // upload log input = this.CompressString(input); @@ -88,7 +89,7 @@ namespace StardewModdingAPI.Web.Controllers // handle errors if (!result.Success) - return this.View("Index", new LogParserModel(this.Config.LogParserUrl, result.ID, null) { UploadError = $"Pastebin error: {result.Error ?? "unknown error"}" }); + return this.View("Index", new LogParserModel(this.Config.LogParserUrl, result.ID) { UploadError = $"Pastebin error: {result.Error ?? "unknown error"}" }); // redirect to view UriBuilder uri = new UriBuilder(new Uri(this.Config.LogParserUrl)); diff --git a/src/SMAPI.Web/ViewModels/LogParserModel.cs b/src/SMAPI.Web/ViewModels/LogParserModel.cs index 0fbd8ad5..df36ca73 100644 --- a/src/SMAPI.Web/ViewModels/LogParserModel.cs +++ b/src/SMAPI.Web/ViewModels/LogParserModel.cs @@ -27,6 +27,9 @@ namespace StardewModdingAPI.Web.ViewModels /// The parsed log info. public ParsedLog ParsedLog { get; set; } + /// Whether to show the raw unparsed log. + public bool ShowRaw { get; set; } + /// An error which occurred while uploading the log to Pastebin. public string UploadError { get; set; } @@ -43,12 +46,24 @@ namespace StardewModdingAPI.Web.ViewModels /// Construct an instance. /// The root URL for the log parser controller. /// The paste ID. - /// The parsed log info. - public LogParserModel(string sectionUrl, string pasteID, ParsedLog parsedLog) + public LogParserModel(string sectionUrl, string pasteID) { this.SectionUrl = sectionUrl; this.PasteID = pasteID; + this.ParsedLog = null; + this.ShowRaw = false; + } + + /// Construct an instance. + /// The root URL for the log parser controller. + /// The paste ID. + /// The parsed log info. + /// Whether to show the raw unparsed log. + public LogParserModel(string sectionUrl, string pasteID, ParsedLog parsedLog, bool showRaw) + : this(sectionUrl, pasteID) + { this.ParsedLog = parsedLog; + this.ShowRaw = showRaw; } /// Get all content packs in the log grouped by the mod they're for. diff --git a/src/SMAPI.Web/Views/LogParser/Index.cshtml b/src/SMAPI.Web/Views/LogParser/Index.cshtml index 8151c502..f5501fed 100644 --- a/src/SMAPI.Web/Views/LogParser/Index.cshtml +++ b/src/SMAPI.Web/Views/LogParser/Index.cshtml @@ -17,17 +17,18 @@ { } - + - + @@ -138,12 +139,15 @@ else if (Model.ParsedLog?.IsValid == true)
- +
@foreach (var mod in Model.ParsedLog.Mods.Where(p => p.ContentPackFor == null)) { @@ -177,36 +181,47 @@ else if (Model.ParsedLog?.IsValid == true) }
Installed mods: - click any mod to filter - show all - hide all + @if (!Model.ShowRaw) + { + click any mod to filter + show all + hide all + }
-
- Filter messages: - TRACE | - DEBUG | - INFO | - ALERT | - WARN | - ERROR -
- - @foreach (var message in Model.ParsedLog.Messages) - { - string levelStr = message.Level.ToString().ToLower(); + @if (!Model.ShowRaw) + { +
+ Filter messages: + TRACE | + DEBUG | + INFO | + ALERT | + WARN | + ERROR +
- - - - - - - if (message.Repeated > 0) +
@message.Time@message.Level.ToString().ToUpper()@message.Mod@message.Text
+ @foreach (var message in Model.ParsedLog.Messages) { - - - + string levelStr = message.Level.ToString().ToLower(); + + + + + + + if (message.Repeated > 0) + { + + + + + } } - } -
repeats [@message.Repeated] times.
@message.Time@message.Level.ToString().ToUpper()@message.Mod@message.Text
repeats [@message.Repeated] times.
+ + + view raw log + } + else + { +
@Model.ParsedLog.RawText
+ view parsed log + } } else if (Model.ParsedLog?.IsValid == false) diff --git a/src/SMAPI.Web/wwwroot/Content/css/log-parser.css b/src/SMAPI.Web/wwwroot/Content/css/log-parser.css index 09bb97f5..1fcd1bff 100644 --- a/src/SMAPI.Web/wwwroot/Content/css/log-parser.css +++ b/src/SMAPI.Web/wwwroot/Content/css/log-parser.css @@ -79,6 +79,10 @@ table#metadata, table#mods { cursor: pointer; } +#mods.filters-disabled tr { + cursor: default; +} + #metadata tr, #mods tr { background: #eee diff --git a/src/SMAPI.Web/wwwroot/Content/js/log-parser.js b/src/SMAPI.Web/wwwroot/Content/js/log-parser.js index 44c3ad5d..0c654205 100644 --- a/src/SMAPI.Web/wwwroot/Content/js/log-parser.js +++ b/src/SMAPI.Web/wwwroot/Content/js/log-parser.js @@ -39,11 +39,17 @@ smapi.logParser = function (data, sectionUrl) { } }, methods: { - toggleLevel: function(id) { + toggleLevel: function (id) { + if (!data.enableFilters) + return; + this.showLevels[id] = !this.showLevels[id]; }, toggleMod: function (id) { + if (!data.enableFilters) + return; + var curShown = this.showMods[id]; // first filter: only show this by default @@ -64,6 +70,9 @@ smapi.logParser = function (data, sectionUrl) { }, showAllMods: function () { + if (!data.enableFilters) + return; + for (var key in this.showMods) { if (this.showMods.hasOwnProperty(key)) { this.showMods[key] = true; @@ -73,6 +82,9 @@ smapi.logParser = function (data, sectionUrl) { }, hideAllMods: function () { + if (!data.enableFilters) + return; + for (var key in this.showMods) { if (this.showMods.hasOwnProperty(key)) { this.showMods[key] = false; -- cgit From 84d52b1735204550c6369270c03f61944c2c88bd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 29 Jul 2018 12:43:04 -0400 Subject: make beta version on smapi.io optional (#569) --- src/SMAPI.Web/Controllers/IndexController.cs | 11 +++++++++-- src/SMAPI.Web/Controllers/LogParserController.cs | 10 +++++----- src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs | 15 --------------- src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs | 18 ++++++++++++++++++ src/SMAPI.Web/Startup.cs | 2 +- src/SMAPI.Web/Views/Shared/_Layout.cshtml | 6 +++--- src/SMAPI.Web/appsettings.Development.json | 7 +++++-- src/SMAPI.Web/appsettings.json | 9 ++++++--- 8 files changed, 47 insertions(+), 31 deletions(-) delete mode 100644 src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs create mode 100644 src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs (limited to 'src/SMAPI.Web/Controllers/LogParserController.cs') diff --git a/src/SMAPI.Web/Controllers/IndexController.cs b/src/SMAPI.Web/Controllers/IndexController.cs index 09bad112..8c4a0332 100644 --- a/src/SMAPI.Web/Controllers/IndexController.cs +++ b/src/SMAPI.Web/Controllers/IndexController.cs @@ -6,8 +6,10 @@ using System.Threading.Tasks; using HtmlAgilityPack; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Options; using StardewModdingAPI.Toolkit; using StardewModdingAPI.Web.Framework.Clients.GitHub; +using StardewModdingAPI.Web.Framework.ConfigModels; using StardewModdingAPI.Web.ViewModels; namespace StardewModdingAPI.Web.Controllers @@ -20,6 +22,9 @@ namespace StardewModdingAPI.Web.Controllers /********* ** Properties *********/ + /// The site config settings. + private readonly SiteConfig SiteConfig; + /// The cache in which to store release data. private readonly IMemoryCache Cache; @@ -39,10 +44,12 @@ namespace StardewModdingAPI.Web.Controllers /// Construct an instance. /// The cache in which to store release data. /// The GitHub API client. - public IndexController(IMemoryCache cache, IGitHubClient github) + /// The context config settings. + public IndexController(IMemoryCache cache, IGitHubClient github, IOptions siteConfig) { this.Cache = cache; this.GitHub = github; + this.SiteConfig = siteConfig.Value; } /// Display the index page. @@ -60,7 +67,7 @@ namespace StardewModdingAPI.Web.Controllers IndexVersionModel stableVersionModel = stableVersion != null ? new IndexVersionModel(stableVersion.Version.ToString(), stableVersion.Release.Body, stableVersion.Asset.DownloadUrl, stableVersionForDevs?.Asset.DownloadUrl) : new IndexVersionModel("unknown", "", "https://github.com/Pathoschild/SMAPI/releases", null); // just in case something goes wrong) - IndexVersionModel betaVersionModel = betaVersion != null + IndexVersionModel betaVersionModel = betaVersion != null && this.SiteConfig.EnableSmapiBeta ? new IndexVersionModel(betaVersion.Version.ToString(), betaVersion.Release.Body, betaVersion.Asset.DownloadUrl, betaVersionForDevs?.Asset.DownloadUrl) : null; diff --git a/src/SMAPI.Web/Controllers/LogParserController.cs b/src/SMAPI.Web/Controllers/LogParserController.cs index 354bdb06..17f8d3aa 100644 --- a/src/SMAPI.Web/Controllers/LogParserController.cs +++ b/src/SMAPI.Web/Controllers/LogParserController.cs @@ -21,8 +21,8 @@ namespace StardewModdingAPI.Web.Controllers /********* ** Properties *********/ - /// The log parser config settings. - private readonly ContextConfig Config; + /// The site config settings. + private readonly SiteConfig Config; /// The underlying Pastebin client. private readonly IPastebinClient Pastebin; @@ -39,11 +39,11 @@ namespace StardewModdingAPI.Web.Controllers ** Constructor ***/ /// Construct an instance. - /// The context config settings. + /// The context config settings. /// The Pastebin API client. - public LogParserController(IOptions contextProvider, IPastebinClient pastebin) + public LogParserController(IOptions siteConfig, IPastebinClient pastebin) { - this.Config = contextProvider.Value; + this.Config = siteConfig.Value; this.Pastebin = pastebin; } diff --git a/src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs deleted file mode 100644 index 117462f4..00000000 --- a/src/SMAPI.Web/Framework/ConfigModels/ContextConfig.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace StardewModdingAPI.Web.Framework.ConfigModels -{ - /// The config settings for the app context. - public class ContextConfig // must be public to pass into views - { - /********* - ** Accessors - *********/ - /// The root URL for the app. - public string RootUrl { get; set; } - - /// The root URL for the log parser. - public string LogParserUrl { get; set; } - } -} diff --git a/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs b/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs new file mode 100644 index 00000000..3d428015 --- /dev/null +++ b/src/SMAPI.Web/Framework/ConfigModels/SiteConfig.cs @@ -0,0 +1,18 @@ +namespace StardewModdingAPI.Web.Framework.ConfigModels +{ + /// The site config settings. + public class SiteConfig // must be public to pass into views + { + /********* + ** Accessors + *********/ + /// The root URL for the app. + public string RootUrl { get; set; } + + /// The root URL for the log parser. + public string LogParserUrl { get; set; } + + /// Whether to show SMAPI beta versions on the main page, if any. + public bool EnableSmapiBeta { get; set; } + } +} diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index ced6e1c7..bf3ec9a1 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -50,7 +50,7 @@ namespace StardewModdingAPI.Web // init configuration services .Configure(this.Configuration.GetSection("ModUpdateCheck")) - .Configure(this.Configuration.GetSection("Context")) + .Configure(this.Configuration.GetSection("Site")) .Configure(options => options.ConstraintMap.Add("semanticVersion", typeof(VersionConstraint))) .AddMemoryCache() .AddMvc() diff --git a/src/SMAPI.Web/Views/Shared/_Layout.cshtml b/src/SMAPI.Web/Views/Shared/_Layout.cshtml index d435e760..29da9100 100644 --- a/src/SMAPI.Web/Views/Shared/_Layout.cshtml +++ b/src/SMAPI.Web/Views/Shared/_Layout.cshtml @@ -1,6 +1,6 @@ @using Microsoft.Extensions.Options @using StardewModdingAPI.Web.Framework.ConfigModels -@inject IOptions ContextConfig +@inject IOptions SiteConfig @@ -15,8 +15,8 @@ diff --git a/src/SMAPI.Web/appsettings.Development.json b/src/SMAPI.Web/appsettings.Development.json index 495af120..67bb7748 100644 --- a/src/SMAPI.Web/appsettings.Development.json +++ b/src/SMAPI.Web/appsettings.Development.json @@ -16,10 +16,13 @@ "Microsoft": "Information" } }, - "Context": { + + "Site": { "RootUrl": "http://localhost:59482/", - "LogParserUrl": "http://localhost:59482/log/" + "LogParserUrl": "http://localhost:59482/log/", + "EnableSmapiBeta": false }, + "ApiClients": { "GitHubUsername": null, "GitHubPassword": null, diff --git a/src/SMAPI.Web/appsettings.json b/src/SMAPI.Web/appsettings.json index 837ba536..9e3270ae 100644 --- a/src/SMAPI.Web/appsettings.json +++ b/src/SMAPI.Web/appsettings.json @@ -13,10 +13,13 @@ "Default": "Warning" } }, - "Context": { - "RootUrl": null, // see top note - "LogParserUrl": null // see top note + + "Site": { + "RootUrl": null, // see top note + "LogParserUrl": null, // see top note + "EnableSmapiBeta": null // see top note }, + "ApiClients": { "UserAgent": "SMAPI/{0} (+https://smapi.io)", -- cgit