From 154127e63145eb515b832e7849f31c51aa534b58 Mon Sep 17 00:00:00 2001 From: ned3y2k Date: Sun, 6 Mar 2022 22:13:41 +0900 Subject: [PATCH] Wake On Lan Used Time Feature Improvements --- custom/js/wake_on_lan_hosts.js | 12 +++++++++++- handler/routes_wake_on_lan.go | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/custom/js/wake_on_lan_hosts.js b/custom/js/wake_on_lan_hosts.js index 1b4d5e9..074f6b8 100644 --- a/custom/js/wake_on_lan_hosts.js +++ b/custom/js/wake_on_lan_hosts.js @@ -54,7 +54,10 @@ jQuery(function ($) { jQuery(function ($) { $('.btn-outline-success').click(function () { - $.put('/wake_on_lan_host/' + $(this).data('mac-address')); + const $this = $(this); + $.put('/wake_on_lan_host/' + $this.data('mac-address'), function (result) { + $this.parents('.info-box').find('.latest-used').text(prettyDateTime(result)); + }); }); }); @@ -80,6 +83,13 @@ jQuery(function ($) { }); }); +jQuery(function ($) { + $('.latest-used').each(function () { + const $this = $(this); + $this.text(prettyDateTime($this.text().trim())); + }); +}); + jQuery(function ($) { let $modal_wake_on_lan_host = $("#modal_wake_on_lan_host"); let $name = $('#frm_wake_on_lan_host_name'); diff --git a/handler/routes_wake_on_lan.go b/handler/routes_wake_on_lan.go index df77c98..40cd387 100644 --- a/handler/routes_wake_on_lan.go +++ b/handler/routes_wake_on_lan.go @@ -124,7 +124,7 @@ func WakeOnHost(db store.IStore) echo.HandlerFunc { macAddress := c.Param("mac_address") host, err := db.GetWakeOnLanHost(macAddress) - now := time.Now() + now := time.Now().UTC() host.LatestUsed = &now err = db.SaveWakeOnLanHost(*host) if err != nil { @@ -166,6 +166,6 @@ func WakeOnHost(db store.IStore) echo.HandlerFunc { return createError(c, err, fmt.Sprintf("Network Send Error: %s", macAddress)) } - return c.JSON(http.StatusOK, nil) + return c.JSON(http.StatusOK, host.LatestUsed) } }