Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve display of job result and properties (followup) #2396

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Hangfire.Core/Common/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace Hangfire.Common
{
internal static class StringExtensions
{
/// <summary>
/// Returns the deserialized JSON <paramref name="text"/> if the text is a serialized JSON string,
/// or the specified text without any transformation if the text is not a serialized JSON string.
/// </summary>
/// <param name="text">The text to prettify.</param>
public static string PrettyJsonString(this string text)
{
if (text.StartsWith("\"", StringComparison.Ordinal))
{
try
{
return SerializationHelper.Deserialize<string>(text, SerializationOption.User);
}
catch
{
// Ignore
}
}

return text;
}
}
}
4 changes: 2 additions & 2 deletions src/Hangfire.Core/Dashboard/JobHistoryRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ public static NonEscapedString SucceededRenderer(HtmlHelper html, IDictionary<st

if (stateData.TryGetValue("Result", out var resultString) && !String.IsNullOrWhiteSpace(resultString))
{
var result = stateData["Result"];
builder.Append($"<dt>Result:</dt><dd>{html.HtmlEncode(result)}</dd>");
var result = stateData["Result"].PrettyJsonString();
builder.Append($"<dt>Result:</dt><dd>{html.HtmlEncode(result).Replace("\n", "<br>")}</dd>");

itemsAdded = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Hangfire.Core/Dashboard/Pages/JobDetailsPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
{
<tr>
<td class="width-20 word-break">@parameter.Key</td>
<td><pre><code>@parameter.Value</code></pre></td>
<td><pre><code>@parameter.Value.PrettyJsonString()</code></pre></td>
</tr>
}
</table>
Expand Down
2 changes: 1 addition & 1 deletion src/Hangfire.Core/Dashboard/Pages/JobDetailsPage.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public override void Execute()


#line 121 "..\..\Dashboard\Pages\JobDetailsPage.cshtml"
Write(parameter.Value);
Write(parameter.Value.PrettyJsonString());


#line default
Expand Down