diff --git a/static/index.html b/static/index.html index 2f0819f..aa9c08b 100644 --- a/static/index.html +++ b/static/index.html @@ -162,7 +162,7 @@

Setra

-
+ @@ -174,6 +174,7 @@ ID Name Created at + @@ -185,6 +186,7 @@ Agent Language Created at + @@ -204,17 +206,17 @@ const input = document.getElementById("api-key-input"); localStorage.setItem("api-key", input.value); document.getElementById("dialog").style.display = "none"; - loadTriggers(); + loadTrackers(); } function init() { if (localStorage.getItem("api-key")) { document.getElementById("dialog").style.display = "none"; - loadTriggers(); + loadTrackers(); } } - function loadTriggers() { + function loadTrackers() { const apiKey = localStorage.getItem("api-key"); if (!apiKey) { return; @@ -232,6 +234,7 @@ ID Name Created at + `; trackers.forEach((tracker) => { @@ -241,12 +244,16 @@ ${tracker.name} ${tracker.created_at} - + + `; @@ -255,7 +262,7 @@ }).catch((err) => alert(`Couldn't fetch trackers: ${err}`)); } - function loadTrigger(id) { + function loadTracker(id) { const apiKey = localStorage.getItem("api-key"); if (!apiKey) { return; @@ -276,6 +283,7 @@ Agent Language Created at + `; hits.forEach((hit) => { @@ -286,13 +294,18 @@ ${hit.agent} ${hit.language} ${hit.created_at} + + + `; }); }).catch((err) => alert(`Couldn't unwrap json: ${err}`)); }).catch((err) => alert(`Couldn't fetch hits: ${err}`)); } - function createTrigger(event) { + function createTracker(event) { event.preventDefault(); const apiKey = localStorage.getItem("api-key"); if (!apiKey) { @@ -307,10 +320,37 @@ Authorization: apiKey, "Content-Type": "application/json", } - }).then(async (res) => { - console.log(await res.text()); - loadTriggers(); - }).catch((err) => alert(`Couldn't create trigger: ${err}`)); + }).then(loadTrackers).catch((err) => alert(`Couldn't create tracker: ${err}`)); + } + + function deleteTracker(id) { + const apiKey = localStorage.getItem("api-key"); + if (!apiKey) { + return; + } + + if (!confirm("Are you sure you want to delete this tracker?")) return; + fetch(`${window.location.origin}/tracker/${id}`, { + method: "DELETE", + headers: { + Authorization: apiKey, + } + }).then(loadTrackers).catch((err) => alert(`Couldn't fetch tracker: ${err}`)); + } + + function deleteHit(id, trackerId) { + const apiKey = localStorage.getItem("api-key"); + if (!apiKey) { + return; + } + + if (!confirm("Are you sure you want to delete this hit?")) return; + fetch(`${window.location.origin}/hit/${id}`, { + method: "DELETE", + headers: { + Authorization: apiKey, + } + }).then(() => loadTracker(trackerId)).catch((err) => alert(`Couldn't delete hit: ${err}`)); } function copyLink(id) {