summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/ViewModels
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-11-24 13:49:30 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-11-24 13:49:30 -0500
commita3f21685049cabf2d824c8060dc0b1de47e9449e (patch)
treead9add30e9da2a50e0ea0245f1546b7378f0d282 /src/SMAPI.Web/ViewModels
parent6521df7b131924835eb797251c1e956fae0d6e13 (diff)
parent277bf082675b98b95bf6184fe3c7a45b969c7ac2 (diff)
downloadSMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.gz
SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.bz2
SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Web/ViewModels')
-rw-r--r--src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs43
-rw-r--r--src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs95
-rw-r--r--src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs15
-rw-r--r--src/SMAPI.Web/ViewModels/LogParserModel.cs19
-rw-r--r--src/SMAPI.Web/ViewModels/ModListModel.cs19
-rw-r--r--src/SMAPI.Web/ViewModels/ModModel.cs22
6 files changed, 201 insertions, 12 deletions
diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs
new file mode 100644
index 00000000..62b95501
--- /dev/null
+++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs
@@ -0,0 +1,43 @@
+using Newtonsoft.Json.Schema;
+
+namespace StardewModdingAPI.Web.ViewModels.JsonValidator
+{
+ /// <summary>The view model for a JSON validator error.</summary>
+ public class JsonValidatorErrorModel
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The line number on which the error occurred.</summary>
+ public int Line { get; set; }
+
+ /// <summary>The field path in the JSON file where the error occurred.</summary>
+ public string Path { get; set; }
+
+ /// <summary>A human-readable description of the error.</summary>
+ public string Message { get; set; }
+
+ /// <summary>The schema error type.</summary>
+ public ErrorType SchemaErrorType { get; set; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public JsonValidatorErrorModel() { }
+
+ /// <summary>Construct an instance.</summary>
+ /// <param name="line">The line number on which the error occurred.</param>
+ /// <param name="path">The field path in the JSON file where the error occurred.</param>
+ /// <param name="message">A human-readable description of the error.</param>
+ /// <param name="schemaErrorType">The schema error type.</param>
+ public JsonValidatorErrorModel(int line, string path, string message, ErrorType schemaErrorType)
+ {
+ this.Line = line;
+ this.Path = path;
+ this.Message = message;
+ this.SchemaErrorType = schemaErrorType;
+ }
+ }
+}
diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs
new file mode 100644
index 00000000..2d13bf23
--- /dev/null
+++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs
@@ -0,0 +1,95 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace StardewModdingAPI.Web.ViewModels.JsonValidator
+{
+ /// <summary>The view model for the JSON validator page.</summary>
+ public class JsonValidatorModel
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The root URL for the log parser controller.</summary>
+ public string SectionUrl { get; set; }
+
+ /// <summary>The paste ID.</summary>
+ public string PasteID { get; set; }
+
+ /// <summary>The schema name with which the JSON was validated.</summary>
+ public string SchemaName { get; set; }
+
+ /// <summary>The supported JSON schemas (names indexed by ID).</summary>
+ public readonly IDictionary<string, string> SchemaFormats;
+
+ /// <summary>The validated content.</summary>
+ public string Content { get; set; }
+
+ /// <summary>The schema validation errors, if any.</summary>
+ public JsonValidatorErrorModel[] Errors { get; set; } = new JsonValidatorErrorModel[0];
+
+ /// <summary>An error which occurred while uploading the JSON to Pastebin.</summary>
+ public string UploadError { get; set; }
+
+ /// <summary>An error which occurred while parsing the JSON.</summary>
+ public string ParseError { get; set; }
+
+ /// <summary>A web URL to the user-facing format documentation.</summary>
+ public string FormatUrl { get; set; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public JsonValidatorModel() { }
+
+ /// <summary>Construct an instance.</summary>
+ /// <param name="sectionUrl">The root URL for the log parser controller.</param>
+ /// <param name="pasteID">The paste ID.</param>
+ /// <param name="schemaName">The schema name with which the JSON was validated.</param>
+ /// <param name="schemaFormats">The supported JSON schemas (names indexed by ID).</param>
+ public JsonValidatorModel(string sectionUrl, string pasteID, string schemaName, IDictionary<string, string> schemaFormats)
+ {
+ this.SectionUrl = sectionUrl;
+ this.PasteID = pasteID;
+ this.SchemaName = schemaName;
+ this.SchemaFormats = schemaFormats;
+ }
+
+ /// <summary>Set the validated content.</summary>
+ /// <param name="content">The validated content.</param>
+ public JsonValidatorModel SetContent(string content)
+ {
+ this.Content = content;
+
+ return this;
+ }
+
+ /// <summary>Set the error which occurred while uploading the log to Pastebin.</summary>
+ /// <param name="error">The error message.</param>
+ public JsonValidatorModel SetUploadError(string error)
+ {
+ this.UploadError = error;
+
+ return this;
+ }
+
+ /// <summary>Set the error which occurred while parsing the JSON.</summary>
+ /// <param name="error">The error message.</param>
+ public JsonValidatorModel SetParseError(string error)
+ {
+ this.ParseError = error;
+
+ return this;
+ }
+
+ /// <summary>Add validation errors to the response.</summary>
+ /// <param name="errors">The schema validation errors.</param>
+ public JsonValidatorModel AddErrors(params JsonValidatorErrorModel[] errors)
+ {
+ this.Errors = this.Errors.Concat(errors).ToArray();
+
+ return this;
+ }
+ }
+}
diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs
new file mode 100644
index 00000000..c8e851bf
--- /dev/null
+++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs
@@ -0,0 +1,15 @@
+namespace StardewModdingAPI.Web.ViewModels.JsonValidator
+{
+ /// <summary>The view model for a JSON validation request.</summary>
+ public class JsonValidatorRequestModel
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The schema name with which to validate the JSON.</summary>
+ public string SchemaName { get; set; }
+
+ /// <summary>The raw content to validate.</summary>
+ public string Content { get; set; }
+ }
+}
diff --git a/src/SMAPI.Web/ViewModels/LogParserModel.cs b/src/SMAPI.Web/ViewModels/LogParserModel.cs
index 41864c99..f4c5214b 100644
--- a/src/SMAPI.Web/ViewModels/LogParserModel.cs
+++ b/src/SMAPI.Web/ViewModels/LogParserModel.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
+using StardewModdingAPI.Toolkit.Utilities;
using StardewModdingAPI.Web.Framework.LogParsing.Models;
namespace StardewModdingAPI.Web.ViewModels
@@ -24,6 +25,9 @@ namespace StardewModdingAPI.Web.ViewModels
/// <summary>The paste ID.</summary>
public string PasteID { get; set; }
+ /// <summary>The viewer's detected OS, if known.</summary>
+ public Platform? DetectedPlatform { get; set; }
+
/// <summary>The parsed log info.</summary>
public ParsedLog ParsedLog { get; set; }
@@ -46,24 +50,25 @@ namespace StardewModdingAPI.Web.ViewModels
/// <summary>Construct an instance.</summary>
/// <param name="sectionUrl">The root URL for the log parser controller.</param>
/// <param name="pasteID">The paste ID.</param>
- public LogParserModel(string sectionUrl, string pasteID)
+ /// <param name="platform">The viewer's detected OS, if known.</param>
+ public LogParserModel(string sectionUrl, string pasteID, Platform? platform)
{
this.SectionUrl = sectionUrl;
this.PasteID = pasteID;
+ this.DetectedPlatform = platform;
this.ParsedLog = null;
this.ShowRaw = false;
}
- /// <summary>Construct an instance.</summary>
- /// <param name="sectionUrl">The root URL for the log parser controller.</param>
- /// <param name="pasteID">The paste ID.</param>
+ /// <summary>Set the log parser result.</summary>
/// <param name="parsedLog">The parsed log info.</param>
/// <param name="showRaw">Whether to show the raw unparsed log.</param>
- public LogParserModel(string sectionUrl, string pasteID, ParsedLog parsedLog, bool showRaw)
- : this(sectionUrl, pasteID)
+ public LogParserModel SetResult(ParsedLog parsedLog, bool showRaw)
{
this.ParsedLog = parsedLog;
this.ShowRaw = showRaw;
+
+ return this;
}
/// <summary>Get all content packs in the log grouped by the mod they're for.</summary>
@@ -81,7 +86,7 @@ namespace StardewModdingAPI.Web.ViewModels
.ToDictionary(group => group.Key, group => group.ToArray());
}
- /// <summary>Get a sanitised mod name that's safe to use in anchors, attributes, and URLs.</summary>
+ /// <summary>Get a sanitized 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)
{
diff --git a/src/SMAPI.Web/ViewModels/ModListModel.cs b/src/SMAPI.Web/ViewModels/ModListModel.cs
index 3b87d393..ff7513bc 100644
--- a/src/SMAPI.Web/ViewModels/ModListModel.cs
+++ b/src/SMAPI.Web/ViewModels/ModListModel.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Linq;
@@ -18,19 +19,35 @@ namespace StardewModdingAPI.Web.ViewModels
/// <summary>The mods to display.</summary>
public ModModel[] Mods { get; set; }
+ /// <summary>When the data was last updated.</summary>
+ public DateTimeOffset LastUpdated { get; set; }
+
+ /// <summary>Whether the data hasn't been updated in a while.</summary>
+ public bool IsStale { get; set; }
+
+ /// <summary>Whether the mod metadata is available.</summary>
+ public bool HasData => this.Mods != null;
+
/*********
** Public methods
*********/
+ /// <summary>Construct an empty instance.</summary>
+ public ModListModel() { }
+
/// <summary>Construct an instance.</summary>
/// <param name="stableVersion">The current stable version of the game.</param>
/// <param name="betaVersion">The current beta version of the game (if any).</param>
/// <param name="mods">The mods to display.</param>
- public ModListModel(string stableVersion, string betaVersion, IEnumerable<ModModel> mods)
+ /// <param name="lastUpdated">When the data was last updated.</param>
+ /// <param name="isStale">Whether the data hasn't been updated in a while.</param>
+ public ModListModel(string stableVersion, string betaVersion, IEnumerable<ModModel> mods, DateTimeOffset lastUpdated, bool isStale)
{
this.StableVersion = stableVersion;
this.BetaVersion = betaVersion;
this.Mods = mods.ToArray();
+ this.LastUpdated = lastUpdated;
+ this.IsStale = isStale;
}
}
}
diff --git a/src/SMAPI.Web/ViewModels/ModModel.cs b/src/SMAPI.Web/ViewModels/ModModel.cs
index 8668f67b..2b478c81 100644
--- a/src/SMAPI.Web/ViewModels/ModModel.cs
+++ b/src/SMAPI.Web/ViewModels/ModModel.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Linq;
using StardewModdingAPI.Toolkit.Framework.Clients.Wiki;
@@ -37,6 +38,12 @@ namespace StardewModdingAPI.Web.ViewModels
/// <summary>The human-readable warnings for players about this mod.</summary>
public string[] Warnings { get; set; }
+ /// <summary>Extra metadata links (usually for open pull requests).</summary>
+ public Tuple<Uri, string>[] MetadataLinks { get; set; }
+
+ /// <summary>Special notes intended for developers who maintain unofficial updates or submit pull requests. </summary>
+ public string DevNote { get; set; }
+
/// <summary>A unique identifier for the mod that can be used in an anchor URL.</summary>
public string Slug { get; set; }
@@ -61,6 +68,8 @@ namespace StardewModdingAPI.Web.ViewModels
this.BetaCompatibility = entry.BetaCompatibility != null ? new ModCompatibilityModel(entry.BetaCompatibility) : null;
this.ModPages = this.GetModPageUrls(entry).ToArray();
this.Warnings = entry.Warnings;
+ this.MetadataLinks = entry.MetadataLinks;
+ this.DevNote = entry.DevNote;
this.Slug = entry.Anchor;
}
@@ -91,15 +100,20 @@ namespace StardewModdingAPI.Web.ViewModels
anyFound = true;
yield return new ModLinkModel($"https://www.nexusmods.com/stardewvalley/mods/{entry.NexusID}", "Nexus");
}
- if (entry.ChucklefishID.HasValue)
+ if (entry.ModDropID.HasValue)
{
anyFound = true;
- yield return new ModLinkModel($"https://community.playstarbound.com/resources/{entry.ChucklefishID}", "Chucklefish");
+ yield return new ModLinkModel($"https://www.moddrop.com/sdv/mod/{entry.ModDropID}", "ModDrop");
}
- if (entry.ModDropID.HasValue)
+ if (!string.IsNullOrWhiteSpace(entry.CurseForgeKey))
{
anyFound = true;
- yield return new ModLinkModel($"https://www.moddrop.com/sdv/mod/{entry.ModDropID}", "ModDrop");
+ yield return new ModLinkModel($"https://www.curseforge.com/stardewvalley/mods/{entry.CurseForgeKey}", "CurseForge");
+ }
+ if (entry.ChucklefishID.HasValue)
+ {
+ anyFound = true;
+ yield return new ModLinkModel($"https://community.playstarbound.com/resources/{entry.ChucklefishID}", "Chucklefish");
}
// fallback