From 2d498443031c1831925d9ba91f8795b7f994677f Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 9 Oct 2024 16:54:52 +0200 Subject: 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 --- assets/index.ts | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'assets/index.ts') 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 = 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 = document.querySelectorAll("button.edit"); +let eels:NodeListOf = 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); +}); +} -- cgit v1.2.3