Skip to content

Commit c4e2e94

Browse files
committed
add option to edit & reupload in the JSON validator
1 parent f692af2 commit c4e2e94

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

docs/release-notes.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
* Internal optimizations.
1212
* Updated translations. Thanks to PlussRolf (added Spanish)!
1313

14+
* For the web UI:
15+
* Added option to edit & reupload in the JSON validator.
16+
* If a JSON validator upload can't be saved to Pastebin (e.g. due to rate limits), it's now uploaded to Amazon S3 instead. Files uploaded to S3 expire after one month.
17+
* Updated the JSON validator for Content Patcher 1.10.0.
18+
* Fixed JSON validator no longer letting you change format when viewing results.
19+
1420
* For modders:
1521
* Added asset propagation for grass textures.
1622
* Added asset propagation for `Data\Bundles` changes (for added bundles only).
1723
* Improved error messages for `TargetParameterCountException` when using the reflection API.
1824
* `helper.Read/WriteSaveData` can now be used while a save is being loaded (e.g. within a `Specialized.LoadStageChanged` event).
1925
* Fixed private textures loaded from content packs not having their `Name` field set.
2026

21-
* For the web UI:
22-
* If a JSON validator upload can't be saved to Pastebin (e.g. due to rate limits), it's now uploaded to Amazon S3 instead. Files uploaded to S3 expire after one month.
23-
* Updated the JSON validator for Content Patcher 1.10.0.
24-
* Fixed JSON validator no longer letting you change format when viewing results.
25-
2627
## 3.0.1
2728
Released 02 December 2019 for Stardew Valley 1.4.0.1.
2829

src/SMAPI.Web/Controllers/JsonValidatorController.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public JsonValidatorController(IStorageProvider storage)
5555
** Web UI
5656
***/
5757
/// <summary>Render the schema validator UI.</summary>
58-
/// <param name="schemaName">The schema name with which to validate the JSON.</param>
58+
/// <param name="schemaName">The schema name with which to validate the JSON, or 'edit' to return to the edit screen.</param>
5959
/// <param name="id">The stored file ID.</param>
6060
[HttpGet]
6161
[Route("json")]
@@ -75,6 +75,10 @@ public async Task<ViewResult> Index(string schemaName = null, string id = null)
7575
return this.View("Index", result.SetUploadError("The JSON file seems to be empty."));
7676
result.SetContent(file.Content, expiry: file.Expiry, uploadWarning: file.Warning);
7777

78+
// skip parsing if we're going to the edit screen
79+
if (schemaName?.ToLower() == "edit")
80+
return this.View("Index", result);
81+
7882
// parse JSON
7983
JToken parsed;
8084
try

src/SMAPI.Web/Views/JsonValidator/Index.cshtml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
string curPageUrl = this.Url.PlainAction("Index", "JsonValidator", new { schemaName = Model.SchemaName, id = Model.PasteID });
99
string newUploadUrl = this.Url.PlainAction("Index", "JsonValidator", new { schemaName = Model.SchemaName });
1010
string schemaDisplayName = null;
11-
bool isValidSchema = Model.SchemaName != null && Model.SchemaFormats.TryGetValue(Model.SchemaName, out schemaDisplayName) && schemaDisplayName != "None";
11+
bool isValidSchema = Model.SchemaName != null && Model.SchemaFormats.TryGetValue(Model.SchemaName, out schemaDisplayName) && schemaDisplayName?.ToLower() != "none";
12+
bool isEditView = Model.Content == null || Model.SchemaName?.ToLower() == "edit";
1213

1314
// build title
1415
ViewData["Title"] = "JSON validator";
@@ -60,7 +61,7 @@ else if (Model.ParseError != null)
6061
<small v-pre>Error details: @Model.ParseError</small>
6162
</div>
6263
}
63-
else if (Model.PasteID != null)
64+
else if (!isEditView && Model.PasteID != null)
6465
{
6566
<div class="banner success">
6667
<strong>Share this link to let someone else see this page:</strong> <code>@curPageUrl</code><br />
@@ -81,7 +82,7 @@ else if (Model.PasteID != null)
8182
}
8283

8384
@* upload new file *@
84-
@if (Model.Content == null)
85+
@if (isEditView)
8586
{
8687
<h2>Upload a JSON file</h2>
8788
<form action="@this.Url.PlainAction("PostAsync", "JsonValidator")" method="post">
@@ -97,7 +98,7 @@ else if (Model.PasteID != null)
9798
</li>
9899
<li>
99100
Drag the file onto this textbox (or paste the text in):<br />
100-
<textarea id="input" name="Content" placeholder="paste file here"></textarea>
101+
<textarea id="input" name="Content" placeholder="paste file here">@Model.Content</textarea>
101102
</li>
102103
<li>
103104
Click this button:<br />
@@ -108,26 +109,23 @@ else if (Model.PasteID != null)
108109
}
109110

110111
@* validation results *@
111-
@if (Model.Content != null)
112+
@if (!isEditView)
112113
{
113114
<div id="output">
114115
@if (Model.UploadError == null)
115116
{
116-
<div>
117-
Change JSON format:
118-
<select id="format" name="format">
119-
@foreach (var pair in Model.SchemaFormats)
120-
{
121-
<option value="@pair.Key" selected="@(Model.SchemaName == pair.Key)">@pair.Value</option>
122-
}
123-
</select>
124-
</div>
125-
126-
<h2>Validation errors</h2>
127-
@if (Model.FormatUrl != null)
128-
{
129-
<p>See <a href="@Model.FormatUrl">format documentation</a>.</p>
130-
}
117+
<h2>Validation</h2>
118+
<p>
119+
@(Model.Errors.Any() ? "Oops, found some issues with your JSON." : "No errors found!")
120+
@if (!isValidSchema)
121+
{
122+
<text>(You have no schema selected, so only the basic JSON syntax was checked.)</text>
123+
}
124+
else if (Model.FormatUrl != null)
125+
{
126+
<text>See <a href="@Model.FormatUrl">format documentation</a> for more info.</text>
127+
}
128+
</p>
131129

132130
@if (Model.Errors.Any())
133131
{
@@ -148,13 +146,17 @@ else if (Model.PasteID != null)
148146
}
149147
</table>
150148
}
151-
else
152-
{
153-
<p>No errors found.</p>
154-
}
155149
}
156150

157151
<h2>Content</h2>
152+
<div>
153+
You can change JSON format (<select id="format" name="format">
154+
@foreach (var pair in Model.SchemaFormats)
155+
{
156+
<option value="@pair.Key" selected="@(Model.SchemaName == pair.Key)">@pair.Value</option>
157+
}
158+
</select>) or <a href="@(this.Url.PlainAction("Index", "JsonValidator", new { id = this.Model.PasteID, schemaName = "edit" }))">edit this file</a>.
159+
</div>
158160
<pre id="raw-content" class="sunlight-highlight-javascript">@Model.Content</pre>
159161

160162
@if (isValidSchema)

0 commit comments

Comments
 (0)