diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-09 16:54:52 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-12 12:01:51 +0200 |
commit | 2d498443031c1831925d9ba91f8795b7f994677f (patch) | |
tree | 5952a1ae36d41ce20a8257f34c7f9487131203db /assets | |
parent | 1e0ae41f1ec06379a6602613612c085ad053c0fa (diff) |
Split server code and http code
Create multiple instances of Ideez by running NewIdeez(), after creating
they can be added to the Ideezes slice to manage them. NewIdeez() imports
the data and registers the routes. main.go has the code for managing the
instances and server.go has the code coupled to a single instance. For
eg. main.go has the code which checks files with .data extension in data
directory, and imports servers on startup.
- Add import functionality
- Add nginx configuration
- Add style and copy animation
- Check for https with "X-Forwarded-Proto"
- Change assets and templates to reflect the new id change
- Change port to 15118
- Add Id field to Idea
- Do not check for duplicate titles anymore
- Extract ideez_servers into const variable
- Extract documentation in doc.go
- Rename Server -> Ideez
- Rename t_idea/ -> templates/
- Fix cancel not working with form by using javascript instead
- Set logger prefix in different contexts
Diffstat (limited to 'assets')
-rw-r--r-- | assets/index.js | 28 | ||||
-rw-r--r-- | assets/index.ts | 32 | ||||
-rw-r--r-- | assets/main.css | 13 |
3 files changed, 66 insertions, 7 deletions
diff --git a/assets/index.js b/assets/index.js index 6146c01..7905d9c 100644 --- a/assets/index.js +++ b/assets/index.js @@ -1,4 +1,9 @@ "use strict"; +// Get the routeprefix by finding the '/' after the ID +let url = window.location.pathname; +let end = url.indexOf("/", "/server/".length + 1); +let routePrefix = url.substring(0, end); +console.log("routePrefix:", routePrefix); let dels = document.querySelectorAll("form[action=\"/idea/delete/\"]"); for (let el of dels) { el.onsubmit = function (e) { @@ -11,8 +16,25 @@ for (let el of dels) { let eels = document.querySelectorAll("button.edit"); for (let el of eels) { el.onclick = function () { - console.log("clicked"); - let title = el.getAttribute("data-title"); - location.href = "/idea/edit?t=" + title; + let id = el.getAttribute("idea-id"); + location.href = routePrefix + "/idea/edit?id=" + id; }; } +let link = document.getElementById("link"); +if (link !== null) { + link.addEventListener("click", function () { + navigator.clipboard.writeText(window.location.href); + let old_text; + if (link !== null) { + old_text = link.innerHTML; + link.innerHTML = "(copied)"; + link.classList.remove("copied"); + } + setTimeout(function () { + if (link !== null) { + link.innerHTML = old_text; + link.classList.add("copied"); + } + }, 1000); + }); +} diff --git a/assets/index.ts b/assets/index.ts index 70b03b7..8081428 100644 --- a/assets/index.ts +++ b/assets/index.ts @@ -1,3 +1,9 @@ +// Get the routeprefix by finding the '/' after the ID +let url = window.location.pathname +let end = url.indexOf("/", "/server/".length +1) +let routePrefix = url.substring(0, end) +console.log("routePrefix:", routePrefix) + let dels:NodeListOf<HTMLFormElement> = document.querySelectorAll("form[action=\"/idea/delete/\"]"); for (let el of dels) { el.onsubmit = function(e) { @@ -8,11 +14,29 @@ for (let el of dels) { }; } -let eels:NodeListOf<HTMLElement> = document.querySelectorAll("button.edit"); +let eels:NodeListOf<HTMLButtonElement> = document.querySelectorAll("button.edit"); for (let el of eels) { el.onclick = function() { - console.log("clicked") - let title = el.getAttribute("data-title"); - location.href = "/idea/edit?t=" + title; + let id = el.getAttribute("idea-id"); + location.href = routePrefix + "/idea/edit?id=" + id; } } + +let link = document.getElementById("link"); +if (link !== null) { +link.addEventListener("click", function() { + navigator.clipboard.writeText(window.location.href) + let old_text: string; + if (link !== null) { + old_text = link.innerHTML; + link.innerHTML = "(copied)"; + link.classList.remove("copied"); + } + setTimeout(function() { + if (link !== null) { + link.innerHTML = old_text; + link.classList.add("copied"); + } + }, 1000); +}); +} diff --git a/assets/main.css b/assets/main.css index b3d6710..d551829 100644 --- a/assets/main.css +++ b/assets/main.css @@ -49,6 +49,19 @@ textarea[name="text"] { h3 { margin-bottom: 0; } +span#link { + color: #b38eac; +} +span#link:hover { + cursor: grab; + text-decoration: underline; +} +span#link.copied { + color: #b38eac; +} +span.link:hover { + cursor: grab; +} input[type="text"]{ border-radius: 3px; border: solid 1px black; |