✨ Adds deleting trackers and hits
This commit is contained in:
@@ -162,7 +162,7 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>Setra</h1>
|
<h1>Setra</h1>
|
||||||
|
|
||||||
<form onsubmit="createTrigger(event)" class="create-form">
|
<form onsubmit="createTracker(event)" class="create-form">
|
||||||
<label for="name-input">Name:</label>
|
<label for="name-input">Name:</label>
|
||||||
<input id="name-input" type="text">
|
<input id="name-input" type="text">
|
||||||
|
|
||||||
@@ -174,6 +174,7 @@
|
|||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Created at</th>
|
<th>Created at</th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@@ -185,6 +186,7 @@
|
|||||||
<th>Agent</th>
|
<th>Agent</th>
|
||||||
<th>Language</th>
|
<th>Language</th>
|
||||||
<th>Created at</th>
|
<th>Created at</th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@@ -204,17 +206,17 @@
|
|||||||
const input = document.getElementById("api-key-input");
|
const input = document.getElementById("api-key-input");
|
||||||
localStorage.setItem("api-key", input.value);
|
localStorage.setItem("api-key", input.value);
|
||||||
document.getElementById("dialog").style.display = "none";
|
document.getElementById("dialog").style.display = "none";
|
||||||
loadTriggers();
|
loadTrackers();
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (localStorage.getItem("api-key")) {
|
if (localStorage.getItem("api-key")) {
|
||||||
document.getElementById("dialog").style.display = "none";
|
document.getElementById("dialog").style.display = "none";
|
||||||
loadTriggers();
|
loadTrackers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadTriggers() {
|
function loadTrackers() {
|
||||||
const apiKey = localStorage.getItem("api-key");
|
const apiKey = localStorage.getItem("api-key");
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
return;
|
return;
|
||||||
@@ -232,6 +234,7 @@
|
|||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Created at</th>
|
<th>Created at</th>
|
||||||
|
<th></th>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
|
|
||||||
trackers.forEach((tracker) => {
|
trackers.forEach((tracker) => {
|
||||||
@@ -241,12 +244,16 @@
|
|||||||
<td>${tracker.name}</td>
|
<td>${tracker.name}</td>
|
||||||
<td>${tracker.created_at}</td>
|
<td>${tracker.created_at}</td>
|
||||||
<td>
|
<td>
|
||||||
<button onclick="loadTrigger('${tracker.id}')">
|
<button onclick="loadTracker('${tracker.id}')">
|
||||||
Show more
|
Show
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button onclick="copyLink('${tracker.id}')">
|
<button onclick="copyLink('${tracker.id}')">
|
||||||
Copy link
|
Copy
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button onclick="deleteTracker('${tracker.id}')">
|
||||||
|
Delete
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
@@ -255,7 +262,7 @@
|
|||||||
}).catch((err) => alert(`Couldn't fetch trackers: ${err}`));
|
}).catch((err) => alert(`Couldn't fetch trackers: ${err}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadTrigger(id) {
|
function loadTracker(id) {
|
||||||
const apiKey = localStorage.getItem("api-key");
|
const apiKey = localStorage.getItem("api-key");
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
return;
|
return;
|
||||||
@@ -276,6 +283,7 @@
|
|||||||
<th>Agent</th>
|
<th>Agent</th>
|
||||||
<th>Language</th>
|
<th>Language</th>
|
||||||
<th>Created at</th>
|
<th>Created at</th>
|
||||||
|
<th></th>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
|
|
||||||
hits.forEach((hit) => {
|
hits.forEach((hit) => {
|
||||||
@@ -286,13 +294,18 @@
|
|||||||
<td>${hit.agent}</td>
|
<td>${hit.agent}</td>
|
||||||
<td>${hit.language}</td>
|
<td>${hit.language}</td>
|
||||||
<td>${hit.created_at}</td>
|
<td>${hit.created_at}</td>
|
||||||
|
<td>
|
||||||
|
<button onclick="deleteHit('${hit.id}', '${id}')">
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
});
|
});
|
||||||
}).catch((err) => alert(`Couldn't unwrap json: ${err}`));
|
}).catch((err) => alert(`Couldn't unwrap json: ${err}`));
|
||||||
}).catch((err) => alert(`Couldn't fetch hits: ${err}`));
|
}).catch((err) => alert(`Couldn't fetch hits: ${err}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTrigger(event) {
|
function createTracker(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const apiKey = localStorage.getItem("api-key");
|
const apiKey = localStorage.getItem("api-key");
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
@@ -307,10 +320,37 @@
|
|||||||
Authorization: apiKey,
|
Authorization: apiKey,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
}).then(async (res) => {
|
}).then(loadTrackers).catch((err) => alert(`Couldn't create tracker: ${err}`));
|
||||||
console.log(await res.text());
|
}
|
||||||
loadTriggers();
|
|
||||||
}).catch((err) => alert(`Couldn't create trigger: ${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) {
|
function copyLink(id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user