add a bit more polish
This commit is contained in:
parent
63dc9125c0
commit
a5b6232c77
6 changed files with 63 additions and 8 deletions
|
@ -57,7 +57,7 @@ func SetupFiber() error {
|
||||||
fiberapp.Post("/admin/login", web.HandleAdminLoginPost)
|
fiberapp.Post("/admin/login", web.HandleAdminLoginPost)
|
||||||
|
|
||||||
fiberapp.Get("/admin/", web.HandleAdminLinkIndexGet)
|
fiberapp.Get("/admin/", web.HandleAdminLinkIndexGet)
|
||||||
fiberapp.Get("/admin/links/add", web.HandleAdminLinkAddGet)
|
fiberapp.Get("/admin/links/new", web.HandleAdminLinkNewGet)
|
||||||
|
|
||||||
fiberapp.Static("/admin/", "./web")
|
fiberapp.Static("/admin/", "./web")
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleAdminLinkAddGet(c *fiber.Ctx) error {
|
func HandleAdminLinkNewGet(c *fiber.Ctx) error {
|
||||||
return c.Render("add_link", nil)
|
return c.Render("add_link", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<a href="/admin/links/new"><button type="button" id="add-new-button">Add new Shortlink</button></a>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -24,8 +26,8 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{.ID}}</td>
|
<td><a href="#" onclick="HandleCopy('{{.ID}}')">{{.ID}}</a></td>
|
||||||
<td>{{.URL}}</td>
|
<td><a href="{{.URL}}" target="_blank">{{.URL}}</a></td>
|
||||||
<td style="text-align: right;">
|
<td style="text-align: right;">
|
||||||
<button type="button" id="edit-button" onclick="HandleEdit('{{.ID}}')">
|
<button type="button" id="edit-button" onclick="HandleEdit('{{.ID}}')">
|
||||||
Edit
|
Edit
|
||||||
|
@ -43,13 +45,13 @@
|
||||||
|
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<p>go-urlsh - <a href="/">Home</a> -
|
<p>go-urlsh - <a href="/admin/">Home</a> -
|
||||||
<a href="https://codeberg.org/lauralani/go-urlsh" target="_blank">Source Code</a> -
|
<a href="https://codeberg.org/lauralani/go-urlsh" target="_blank">Source Code</a> -
|
||||||
<a href="https://codeberg.org/lauralani/go-urlsh/src/branch/main/LICENSE" target="_blank">License</a>
|
<a href="https://codeberg.org/lauralani/go-urlsh/src/branch/main/LICENSE" target="_blank">License</a>
|
||||||
</p>
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<script src="/admin/link_add.js"></script>
|
<script src="/admin/links.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
37
web/link_add.js
Normal file
37
web/link_add.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
async function HandleSubmit() {
|
||||||
|
document.getElementById("submit").active = false
|
||||||
|
let slug = document.getElementById("linkname").value
|
||||||
|
let url = document.getElementById("link").value
|
||||||
|
let description = document.getElementById("description").value
|
||||||
|
let body = {
|
||||||
|
"id" : slug,
|
||||||
|
"url" : url,
|
||||||
|
"description" : description
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = await fetch("/api/v1/links", {
|
||||||
|
credentials: "include",
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
mode: "same-origin",
|
||||||
|
method: "POST"
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
document.getElementById("dialog-heading").textContent = "Error"
|
||||||
|
document.getElementById("dialog-text").textContent = "The following error occured during the request: " + response.statusText
|
||||||
|
document.getElementById('dialog-info').showModal()
|
||||||
|
|
||||||
|
document.getElementById("submit").active = true
|
||||||
|
}
|
||||||
|
document.location = "/admin/"
|
||||||
|
}
|
||||||
|
|
||||||
|
async function HandleChange() {
|
||||||
|
console.log("HandleChange")
|
||||||
|
let buttonactive = true
|
||||||
|
if (document.getElementById("link").value === "")
|
||||||
|
{
|
||||||
|
buttonactive = false
|
||||||
|
}
|
||||||
|
document.getElementById("submit").active = buttonactive
|
||||||
|
}
|
|
@ -22,8 +22,8 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{.ID}}</td>
|
<td><a onclick="HandleCopy('{{.id}}')">{{.ID}}</a></td>
|
||||||
<td>{{.URL}}</td>
|
<td><a href="{{.URL}}" target="_blank">{{.URL}}</a></td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<button type="button" id="edit-button" onclick="HandleEdit('{{.ID}}')">
|
<button type="button" id="edit-button" onclick="HandleEdit('{{.ID}}')">
|
||||||
|
|
16
web/links.js
16
web/links.js
|
@ -0,0 +1,16 @@
|
||||||
|
async function HandleDelete(id){
|
||||||
|
let response = await fetch("/api/v1/links/" + id, {
|
||||||
|
credentials: "include",
|
||||||
|
mode: "same-origin",
|
||||||
|
method: "DELETE"
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
console.log("error deleting " + id + ": " + response.statusText)
|
||||||
|
}
|
||||||
|
document.location = "/admin/"
|
||||||
|
}
|
||||||
|
|
||||||
|
async function HandleCopy(id) {
|
||||||
|
let host = window.location.protocol + "//" + window.location.host;
|
||||||
|
await navigator.clipboard.writeText(host + "/" + id);
|
||||||
|
}
|
Loading…
Reference in a new issue