Skip to content

Commit 22ff130

Browse files
committed
Merge branch 'dev'
2 parents 2584949 + 3149387 commit 22ff130

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/Serilog.Ui.Web/Extensions/AuthorizationOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class AuthorizationOptions
1616
public enum AuthenticationType
1717
{
1818
Cookie,
19-
Jwt
19+
Jwt,
20+
Windows
2021
}
2122
}

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

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
});
9696
})(jQuery);
9797

98+
let authType;
99+
98100
const routePrefix = {
99101
url: "",
100102
set setUrl(route) {
@@ -103,13 +105,15 @@ const routePrefix = {
103105
}
104106

105107
const init = (config) => {
106-
if (config.authType === "Cookie") {
108+
if (config.authType === "Jwt") {
109+
initTokenUi();
110+
} else {
107111
$("#jwtModalBtn").remove();
108112
sessionStorage.removeItem("serilogui_token");
109-
} else {
110-
initTokenUi();
111113
}
112114

115+
authType = config.authType;
116+
113117
routePrefix.setUrl = config.routePrefix;
114118
fetchData();
115119
}
@@ -120,23 +124,33 @@ const fetchData = () => {
120124
const count = $("#count").children("option:selected").val();
121125
const level = $("#level").children("option:selected").val();
122126
const searchTerm = escape($("#search").val());
123-
const url = `/${routePrefix.url}/api/logs?page=${page}&count=${count}&level=${level}&search=${searchTerm}`;
127+
const url = `${location.pathname.replace("/index.html", "")}/api/logs?page=${page}&count=${count}&level=${level}&search=${searchTerm}`;
124128
const token = sessionStorage.getItem("serilogui_token");
125-
$.ajaxSetup({ headers: { 'Authorization': token } });
126-
$.get(url, function (data) {
127-
$("#totalLogs").html(data.total);
128-
$("#showingItemsStart").html(data.page);
129-
$("#showingItemsEnd").html(data.count);
130-
$(tbody).empty();
131-
data.logs.forEach(function (log) {
132-
let exception = "";
133-
if (log.exception != undefined) {
134-
exception =
135-
`<a href="#" title="Click to view" class="modal-trigger" data-type="text">
129+
let xf = null;
130+
if (authType !== "Windows")
131+
$.ajaxSetup({ headers: { 'Authorization': token } });
132+
else {
133+
xf = {
134+
withCredentials: true
135+
};
136+
}
137+
$.get({
138+
url: url,
139+
xhrFields: xf,
140+
success: function (data) {
141+
$("#totalLogs").html(data.total);
142+
$("#showingItemsStart").html(data.page);
143+
$("#showingItemsEnd").html(data.count);
144+
$(tbody).empty();
145+
data.logs.forEach(function (log) {
146+
let exception = "";
147+
if (log.exception != undefined) {
148+
exception =
149+
`<a href="#" title="Click to view" class="modal-trigger" data-type="text">
136150
View <span style="display: none">${log.exception}</span>
137151
</a>`;
138-
}
139-
const row = `<tr class="${log.level}">
152+
}
153+
const row = `<tr class="${log.level}">
140154
<td class="text-center">${log.rowNo}</td>
141155
<td class="text-center"><span class="log-level text-white ${levelClass(log.level)}">${log.level}</span></td>
142156
<td class="text-center">${formatDate(log.timestamp)}</td>
@@ -153,9 +167,10 @@ const fetchData = () => {
153167
</a>
154168
</td>
155169
</tr>`;
156-
$(tbody).append(row);
157-
});
158-
paging(data.total, data.count, data.currentPage);
170+
$(tbody).append(row);
171+
});
172+
paging(data.total, data.count, data.currentPage);
173+
}
159174
}).fail(function (error) {
160175
if (error.status === 403) {
161176
console.log(error);

0 commit comments

Comments
 (0)