add data-* attributes to log parser for external tools

This commit is contained in:
Jesse Plamondon-Willard 2022-02-12 12:07:13 -05:00
parent 4a1174cd50
commit b0cc403098
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
4 changed files with 38 additions and 21 deletions

View File

@ -13,6 +13,7 @@
* Fixed `player_add` with Journal Scraps and Secret Notes.
* For the web UI:
* Added `data-*` attributes to log parser page for external tools.
* Fixed JSON validator warning for update keys without a subkey.
## 3.13.4

View File

@ -35,5 +35,8 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models
/// <summary>Whether the mod has an update available.</summary>
public bool HasUpdate => this.UpdateVersion != null && this.Version != this.UpdateVersion;
/// <summary>Whether the mod is a content pack for another mod.</summary>
public bool IsContentPack => !string.IsNullOrWhiteSpace(this.ContentPackFor);
}
}

View File

@ -83,7 +83,7 @@ namespace StardewModdingAPI.Web.ViewModels
// group by mod
return mods
.Where(mod => mod.ContentPackFor != null)
.Where(mod => mod.IsContentPack)
.GroupBy(mod => mod.ContentPackFor)
.ToDictionary(group => group.Key, group => group.ToArray());
}

View File

@ -7,6 +7,9 @@
@{
ViewData["Title"] = "SMAPI log parser";
ParsedLog log = Model!.ParsedLog;
IDictionary<string, LogModInfo[]> contentPacks = Model.GetContentPacksByMod();
IDictionary<string, bool> defaultFilters = Enum
.GetValues(typeof(LogLevel))
@ -15,7 +18,7 @@
string curPageUrl = this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID }, absoluteUrl: true);
ISet<int> screenIds = new HashSet<int>(Model.ParsedLog?.Messages?.Select(p => p.ScreenId) ?? Array.Empty<int>());
ISet<int> screenIds = new HashSet<int>(log?.Messages?.Select(p => p.ScreenId) ?? Array.Empty<int>());
}
@section Head {
@ -35,9 +38,9 @@
<script>
$(function() {
smapi.logParser({
logStarted: new Date(@this.ForJson(Model.ParsedLog?.Timestamp)),
showPopup: @this.ForJson(Model.ParsedLog == null),
showMods: @this.ForJson(Model.ParsedLog?.Mods?.Select(p => Model.GetSlug(p.Name)).Distinct().ToDictionary(slug => slug, slug => true)),
logStarted: new Date(@this.ForJson(log?.Timestamp)),
showPopup: @this.ForJson(log == null),
showMods: @this.ForJson(log?.Mods?.Select(p => Model.GetSlug(p.Name)).Distinct().ToDictionary(slug => slug, slug => true)),
showSections: @this.ForJson(Enum.GetNames(typeof(LogSection)).ToDictionary(section => section, section => false)),
showLevels: @this.ForJson(defaultFilters),
enableFilters: @this.ForJson(!Model.ShowRaw),
@ -67,7 +70,7 @@ else if (Model.ParseError != null)
<small v-pre>Error details: @Model.ParseError</small>
</div>
}
else if (Model.ParsedLog?.IsValid == true)
else if (log?.IsValid == true)
{
<div class="banner success" v-pre>
<strong>Share this link to let someone else see the log:</strong> <code>@curPageUrl</code><br />
@ -92,7 +95,7 @@ else if (Model.ParsedLog?.IsValid == true)
}
@* upload new log *@
@if (Model.ParsedLog == null)
@if (log == null)
{
<h2>Where do I find my SMAPI log?</h2>
<div id="os-instructions">
@ -157,7 +160,7 @@ else if (Model.ParsedLog?.IsValid == true)
</div>
<h2>How do I share my log?</h2>
<form action="@this.Url.PlainAction("PostAsync", "LogParser")" method="post">
<form action="@this.Url.PlainAction("Post", "LogParser")" method="post">
<input id="inputFile" type="file" />
<ol>
<li>
@ -174,10 +177,10 @@ else if (Model.ParsedLog?.IsValid == true)
}
@* parsed log *@
@if (Model.ParsedLog?.IsValid == true)
@if (log?.IsValid == true)
{
<div id="output">
@if (Model.ParsedLog.Mods.Any(mod => mod.HasUpdate))
@if (log.Mods.Any(mod => mod.HasUpdate))
{
<h2>Suggested fixes</h2>
<ul id="fix-list">
@ -185,7 +188,7 @@ else if (Model.ParsedLog?.IsValid == true)
Consider updating these mods to fix problems:
<table id="updates" class="table">
@foreach (LogModInfo mod in Model.ParsedLog.Mods.Where(mod => (mod.HasUpdate && mod.ContentPackFor == null) || (contentPacks != null && contentPacks.TryGetValue(mod.Name, out LogModInfo[] contentPackList) && contentPackList.Any(pack => pack.HasUpdate))))
@foreach (LogModInfo mod in log.Mods.Where(mod => (mod.HasUpdate && !mod.IsContentPack) || (contentPacks.TryGetValue(mod.Name, out LogModInfo[] contentPackList) && contentPackList.Any(pack => pack.HasUpdate))))
{
<tr class="mod-entry">
<td>
@ -230,23 +233,33 @@ else if (Model.ParsedLog?.IsValid == true)
}
<h2>Log info</h2>
<table id="metadata" class="table">
<table
id="metadata"
class="table"
data-code-mods="@log.Mods.Count(p => !p.IsContentPack)"
data-content-packs="@log.Mods.Count(p => p.IsContentPack)"
data-os="@log.OperatingSystem"
data-game-version="@log.GameVersion"
data-game-path="@log.GamePath"
data-smapi-version="@log.ApiVersion"
data-log-started="@log.Timestamp.UtcDateTime.ToString("O")"
>
<caption>Game info:</caption>
<tr>
<th>Stardew Valley:</th>
<td v-pre>@Model.ParsedLog.GameVersion on @Model.ParsedLog.OperatingSystem</td>
<td v-pre>@log.GameVersion on @log.OperatingSystem</td>
</tr>
<tr>
<th>SMAPI:</th>
<td v-pre>@Model.ParsedLog.ApiVersion</td>
<td v-pre>@log.ApiVersion</td>
</tr>
<tr>
<th>Folder:</th>
<td v-pre>@Model.ParsedLog.GamePath</td>
<td v-pre>@log.GamePath</td>
</tr>
<tr>
<th>Log started:</th>
<td>@Model.ParsedLog.Timestamp.UtcDateTime.ToString("yyyy-MM-dd HH:mm") UTC ({{localTimeStarted}} your time)</td>
<td>@log.Timestamp.UtcDateTime.ToString("yyyy-MM-dd HH:mm") UTC ({{localTimeStarted}} your time)</td>
</tr>
</table>
<br />
@ -260,7 +273,7 @@ else if (Model.ParsedLog?.IsValid == true)
<span class="notice btn txt" v-on:click="hideAllMods" v-bind:class="{ invisible: !anyModsShown || !anyModsHidden }">hide all</span>
}
</caption>
@foreach (var mod in Model.ParsedLog.Mods.Where(p => p.Loaded && p.ContentPackFor == null))
@foreach (var mod in log.Mods.Where(p => p.Loaded && !p.IsContentPack))
{
<tr v-on:click="toggleMod('@Model.GetSlug(mod.Name)')" class="mod-entry" v-bind:class="{ hidden: !showMods['@Model.GetSlug(mod.Name)'] }">
<td><input type="checkbox" v-bind:checked="showMods['@Model.GetSlug(mod.Name)']" v-bind:class="{ invisible: !anyModsHidden }" /></td>
@ -317,7 +330,7 @@ else if (Model.ParsedLog?.IsValid == true)
</div>
<table id="log">
@foreach (var message in Model.ParsedLog.Messages)
@foreach (var message in log.Messages)
{
string levelStr = message.Level.ToString().ToLower();
string sectionStartClass = message.IsStartOfSection ? "section-start" : null;
@ -360,7 +373,7 @@ else if (Model.ParsedLog?.IsValid == true)
}
else
{
<pre v-pre>@Model.ParsedLog.RawText</pre>
<pre v-pre>@log.RawText</pre>
}
<small>
@ -377,8 +390,8 @@ else if (Model.ParsedLog?.IsValid == true)
</small>
</div>
}
else if (Model.ParsedLog?.IsValid == false)
else if (log?.IsValid == false)
{
<h3>Raw log</h3>
<pre v-pre>@Model.ParsedLog.RawText</pre>
<pre v-pre>@log.RawText</pre>
}