Skip to content

Commit 03e62f4

Browse files
committed
Add json formatter.
1 parent 45b1a33 commit 03e62f4

File tree

4 files changed

+25
-35
lines changed

4 files changed

+25
-35
lines changed

src/Serilog.Ui.Web/wwwroot/css/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,8 @@ a[data-toggle="collapse"] {
376376

377377
.log-message {
378378
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
379+
}
380+
381+
.modal-body.wrapped pre {
382+
white-space: pre-wrap;
379383
}

src/Serilog.Ui.Web/wwwroot/css/main.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Serilog.Ui.Web/wwwroot/js/main.js

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function ($) {
22
"use strict";
33

4-
let fullHeight = function () {
4+
const fullHeight = function () {
55
$(".js-fullheight").css("height", $(window).height());
66
$(window).resize(function () {
77
$(".js-fullheight").css("height", $(window).height());
@@ -16,17 +16,17 @@
1616
$(".page-link").on("click", function (e) {
1717
e.preventDefault();
1818
$("#page").val($(this).attr("data-val"));
19-
$("form").submit()
19+
$("form").submit();
2020
});
2121

2222
$("#logCount").on("change", function () {
2323
$("#page").val("1");
24-
$("form").submit()
24+
$("form").submit();
2525
});
2626

2727
$("#logFilter").on("change", function () {
2828
$("#page").val("1");
29-
$("form").submit()
29+
$("form").submit();
3030
});
3131

3232
$("#search").on("keypress", function (e) {
@@ -38,38 +38,24 @@
3838

3939
$(".modal-trigger").on("click", function (e) {
4040
e.preventDefault();
41+
42+
const modal = $("#messageModal");
43+
const modalBody = modal.find('.modal-body');
44+
const dataType = $(this).attr("data-type");
4145
let message = $(this).find("span").text();
42-
const isXml = $(this).attr("data-type") === "xml";
43-
if (isXml)
46+
47+
if (dataType === "xml") {
4448
message = formatXml(message);
49+
$(modalBody).removeClass('wrapped');
50+
} else if (dataType === "json") {
51+
const prop = JSON.parse(message);
52+
message = JSON.stringify(prop, null, 2);
53+
$(modalBody).removeClass('wrapped');
54+
} else {
55+
$(modalBody).addClass('wrapped');
56+
}
4557

46-
const modal = $("#messageModal");
47-
modal.find('.modal-body pre').text(message);
58+
modalBody.find('pre').text(message);
4859
modal.modal("show");
4960
});
50-
51-
function formatXml(xml) {
52-
const xmlDoc = new DOMParser().parseFromString(xml, 'application/xml');
53-
const xsltDoc = new DOMParser().parseFromString([
54-
// describes how we want to modify the XML - indent everything
55-
'<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">',
56-
' <xsl:strip-space elements="*"/>',
57-
' <xsl:template match="para[content-style][not(text())]">', // change to just text() to strip space in text nodes
58-
' <xsl:value-of select="normalize-space(.)"/>',
59-
' </xsl:template>',
60-
' <xsl:template match="node()|@*">',
61-
' <xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>',
62-
' </xsl:template>',
63-
' <xsl:output indent="yes"/>',
64-
'</xsl:stylesheet>',
65-
].join('\n'), 'application/xml');
66-
67-
const xsltProcessor = new XSLTProcessor();
68-
xsltProcessor.importStylesheet(xsltDoc);
69-
70-
const resultDoc = xsltProcessor.transformToDocument(xmlDoc);
71-
const resultXml = new XMLSerializer().serializeToString(resultDoc);
72-
73-
return resultXml;
74-
}
7561
})(jQuery);

src/Serilog.Ui.Web/wwwroot/js/main.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)