Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-esmp committed Feb 2, 2021
2 parents 2584949 + 3149387 commit 22ff130
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/Serilog.Ui.Web/Extensions/AuthorizationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class AuthorizationOptions
public enum AuthenticationType
{
Cookie,
Jwt
Jwt,
Windows
}
}
55 changes: 35 additions & 20 deletions src/Serilog.Ui.Web/wwwroot/dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
});
})(jQuery);

let authType;

const routePrefix = {
url: "",
set setUrl(route) {
Expand All @@ -103,13 +105,15 @@ const routePrefix = {
}

const init = (config) => {
if (config.authType === "Cookie") {
if (config.authType === "Jwt") {
initTokenUi();
} else {
$("#jwtModalBtn").remove();
sessionStorage.removeItem("serilogui_token");
} else {
initTokenUi();
}

authType = config.authType;

routePrefix.setUrl = config.routePrefix;
fetchData();
}
Expand All @@ -120,23 +124,33 @@ const fetchData = () => {
const count = $("#count").children("option:selected").val();
const level = $("#level").children("option:selected").val();
const searchTerm = escape($("#search").val());
const url = `/${routePrefix.url}/api/logs?page=${page}&count=${count}&level=${level}&search=${searchTerm}`;
const url = `${location.pathname.replace("/index.html", "")}/api/logs?page=${page}&count=${count}&level=${level}&search=${searchTerm}`;
const token = sessionStorage.getItem("serilogui_token");
$.ajaxSetup({ headers: { 'Authorization': token } });
$.get(url, function (data) {
$("#totalLogs").html(data.total);
$("#showingItemsStart").html(data.page);
$("#showingItemsEnd").html(data.count);
$(tbody).empty();
data.logs.forEach(function (log) {
let exception = "";
if (log.exception != undefined) {
exception =
`<a href="#" title="Click to view" class="modal-trigger" data-type="text">
let xf = null;
if (authType !== "Windows")
$.ajaxSetup({ headers: { 'Authorization': token } });
else {
xf = {
withCredentials: true
};
}
$.get({
url: url,
xhrFields: xf,
success: function (data) {
$("#totalLogs").html(data.total);
$("#showingItemsStart").html(data.page);
$("#showingItemsEnd").html(data.count);
$(tbody).empty();
data.logs.forEach(function (log) {
let exception = "";
if (log.exception != undefined) {
exception =
`<a href="#" title="Click to view" class="modal-trigger" data-type="text">
View <span style="display: none">${log.exception}</span>
</a>`;
}
const row = `<tr class="${log.level}">
}
const row = `<tr class="${log.level}">
<td class="text-center">${log.rowNo}</td>
<td class="text-center"><span class="log-level text-white ${levelClass(log.level)}">${log.level}</span></td>
<td class="text-center">${formatDate(log.timestamp)}</td>
Expand All @@ -153,9 +167,10 @@ const fetchData = () => {
</a>
</td>
</tr>`;
$(tbody).append(row);
});
paging(data.total, data.count, data.currentPage);
$(tbody).append(row);
});
paging(data.total, data.count, data.currentPage);
}
}).fail(function (error) {
if (error.status === 403) {
console.log(error);
Expand Down

0 comments on commit 22ff130

Please sign in to comment.