Fixed the problem that Wake On Lan does not work when BASE_PATH is set. (#229)

Fix time display issue in iOS WebKit.
This commit is contained in:
ned3y2k 2022-09-30 17:39:12 +09:00 committed by GitHub
parent 63d6e1f391
commit 887bc778df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 12 deletions

View file

@ -1,3 +1,8 @@
var base_url = jQuery(".brand-link").attr('href');
if (base_url.substring(base_url.length - 1, base_url.length) != "/")
base_url = base_url + "/";
const wake_on_lan_new_template = '<div class="col-sm-4" id="{{ .Id }}">\n' + const wake_on_lan_new_template = '<div class="col-sm-4" id="{{ .Id }}">\n' +
'\t<div class="info-box">\n' + '\t<div class="info-box">\n' +
'\t\t<div class="info-box-content">\n' + '\t\t<div class="info-box-content">\n' +
@ -24,9 +29,9 @@ const wake_on_lan_new_template = '<div class="col-sm-4" id="{{ .Id }}">\n' +
'</div>'; '</div>';
jQuery(function ($) { jQuery(function ($) {
$.validator.addMethod('mac', function (value, element) { $.validator.addMethod('mac', function (value, element) {
return this.optional(element) || /^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$/.test(value); return this.optional(element) || /^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$/.test(value);
}, 'Please enter a valid MAC Address.(uppercase letters and numbers, : only) ex: 00:AB:12:EF:DD:AA'); }, 'Please enter a valid MAC Address.(uppercase letters and numbers, : only) ex: 00:AB:12:EF:DD:AA');
}); });
jQuery.each(["put", "delete"], function (i, method) { jQuery.each(["put", "delete"], function (i, method) {
@ -42,7 +47,8 @@ jQuery.each(["put", "delete"], function (i, method) {
type: method, type: method,
dataType: type, dataType: type,
data: data, data: data,
success: callback success: callback,
contentType: 'application/json'
}); });
}; };
}); });
@ -55,7 +61,7 @@ jQuery(function ($) {
jQuery(function ($) { jQuery(function ($) {
$('.btn-outline-success').click(function () { $('.btn-outline-success').click(function () {
const $this = $(this); const $this = $(this);
$.put('/wake_on_lan_host/' + $this.data('mac-address'), function (result) { $.put(base_url + 'wake_on_lan_host/' + $this.data('mac-address'), function (result) {
$this.parents('.info-box').find('.latest-used').text(prettyDateTime(result)); $this.parents('.info-box').find('.latest-used').text(prettyDateTime(result));
}); });
}); });
@ -76,7 +82,7 @@ jQuery(function ($) {
$remove_client_confirm.click(function () { $remove_client_confirm.click(function () {
const macAddress = $remove_client_confirm.val().replaceAll(":", "-"); const macAddress = $remove_client_confirm.val().replaceAll(":", "-");
$.delete('/wake_on_lan_host/' + macAddress); $.delete(base_url + 'wake_on_lan_host/' + macAddress);
$('#' + macAddress).remove(); $('#' + macAddress).remove();
$modal_remove_wake_on_lan_host.modal('hide'); $modal_remove_wake_on_lan_host.modal('hide');
@ -84,10 +90,18 @@ jQuery(function ($) {
}); });
jQuery(function ($) { jQuery(function ($) {
$('.latest-used').each(function () { $('.latest-used').each(function () {
const $this = $(this); const $this = $(this);
$this.text(prettyDateTime($this.text().trim())); const timeText = $this.text().trim();
}); try {
if (timeText != "Unused") {
$this.text(prettyDateTime(timeText));
}
} catch (ex) {
console.log(timeText);
throw ex;
}
});
}); });
jQuery(function ($) { jQuery(function ($) {
@ -109,7 +123,7 @@ jQuery(function ($) {
$.ajax({ $.ajax({
cache: false, cache: false,
method: 'POST', method: 'POST',
url: '/wake_on_lan_host', url: base_url + 'wake_on_lan_host',
dataType: 'json', dataType: 'json',
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(data), data: JSON.stringify(data),

View file

@ -103,7 +103,7 @@
<span class="info-box-text"><i class="fas fa-clock"></i> <span class="info-box-text"><i class="fas fa-clock"></i>
<span class="latest-used"> <span class="latest-used">
{{ if .LatestUsed }} {{ if .LatestUsed }}
{{ .LatestUsed }} {{ .LatestUsed.Format "2006-01-02T15:04:05Z07:00"}}
{{ else }} {{ else }}
Unused Unused
{{ end }} {{ end }}