Fix instant rendering & improve styling
authorLanius Trolling <lanius@laniustrolling.dev>
Tue, 9 Apr 2024 18:31:22 +0000 (14:31 -0400)
committerLanius Trolling <lanius@laniustrolling.dev>
Tue, 9 Apr 2024 18:31:22 +0000 (14:31 -0400)
src/jvmMain/kotlin/info/mechyrdia/data/views_files.kt
src/jvmMain/resources/static/admin.css
src/jvmMain/resources/static/admin.js

index a8801cb7d1edef3cb5498b03cc0735a686738c77..dfbad0d22e32525e4da5cec42e5b34be1836a6a9 100644 (file)
@@ -110,87 +110,85 @@ suspend fun ApplicationCall.adminViewVfs(path: StoragePath): HTML.() -> Unit {
        val tree = fileTree(path)!!
        
        return adminPage("VFS - /$path") {
-               main {
-                       h1 { +"/$path" }
-                       
-                       when (tree) {
-                               is TreeNode.FileNode -> table {
-                                       tr {
-                                               th {
-                                                       colSpan = "2"
-                                                       +"/$path"
-                                               }
+               h1 { +"/$path" }
+               
+               when (tree) {
+                       is TreeNode.FileNode -> table {
+                               tr {
+                                       th {
+                                               colSpan = "2"
+                                               +"/$path"
                                        }
-                                       tr {
-                                               td {
-                                                       colSpan = "2"
-                                                       iframe {
-                                                               src = href(Root.Admin.Vfs.Inline(path.elements))
-                                                       }
+                               }
+                               tr {
+                                       td {
+                                               colSpan = "2"
+                                               iframe {
+                                                       src = href(Root.Admin.Vfs.Inline(path.elements))
                                                }
                                        }
-                                       tr {
-                                               th { +"Last updated" }
-                                               td { dateTime(tree.stats.updated) }
-                                       }
-                                       tr {
-                                               th { +"Size (bytes)" }
-                                               td { +"${tree.stats.size}" }
-                                       }
-                                       tr {
-                                               th { +"Actions" }
-                                               td {
-                                                       ul {
-                                                               li {
-                                                                       a(href = href(Root.Admin.Vfs.Download(path.elements))) {
-                                                                               +"Download"
-                                                                       }
+                               }
+                               tr {
+                                       th { +"Last updated" }
+                                       td { dateTime(tree.stats.updated) }
+                               }
+                               tr {
+                                       th { +"Size (bytes)" }
+                                       td { +"${tree.stats.size}" }
+                               }
+                               tr {
+                                       th { +"Actions" }
+                                       td {
+                                               ul {
+                                                       li {
+                                                               a(href = href(Root.Admin.Vfs.Download(path.elements))) {
+                                                                       +"Download"
                                                                }
-                                                               li {
-                                                                       form(action = href(Root.Admin.Vfs.Overwrite(path.elements)), method = FormMethod.post, encType = FormEncType.multipartFormData) {
-                                                                               installCsrfToken()
-                                                                               label {
-                                                                                       fileInput(name = "uploaded")
-                                                                                       +"Upload New Version"
-                                                                               }
-                                                                               submitInput()
+                                                       }
+                                                       li {
+                                                               form(action = href(Root.Admin.Vfs.Overwrite(path.elements)), method = FormMethod.post, encType = FormEncType.multipartFormData) {
+                                                                       installCsrfToken()
+                                                                       label {
+                                                                               fileInput(name = "uploaded")
+                                                                               +"Upload New Version"
                                                                        }
+                                                                       submitInput()
                                                                }
-                                                               li {
-                                                                       a(href = href(Root.Admin.Vfs.DeleteConfirmPage(path.elements))) {
-                                                                               +"Delete"
-                                                                       }
+                                                       }
+                                                       li {
+                                                               a(href = href(Root.Admin.Vfs.DeleteConfirmPage(path.elements))) {
+                                                                       +"Delete"
                                                                }
                                                        }
                                                }
                                        }
-                                       tr {
-                                               th { +"Navigate" }
-                                               td {
-                                                       ul {
-                                                               path.elements.indices.forEach { index ->
-                                                                       val parent = path.elements.take(index)
-                                                                       li {
-                                                                               a(href = href(Root.Admin.Vfs.View(parent))) {
-                                                                                       +"/${StoragePath(parent)}"
-                                                                               }
+                               }
+                               tr {
+                                       th { +"Navigate" }
+                                       td {
+                                               ul {
+                                                       path.elements.indices.forEach { index ->
+                                                               val parent = path.elements.take(index)
+                                                               li {
+                                                                       a(href = href(Root.Admin.Vfs.View(parent))) {
+                                                                               +"/${StoragePath(parent)}"
                                                                        }
                                                                }
                                                        }
                                                }
                                        }
                                }
-                               
-                               is TreeNode.DirNode -> ul {
-                                       if (!path.isRoot)
-                                               li {
-                                                       a(href = href(Root.Admin.Vfs.View(path.elements.dropLast(1)))) {
-                                                               +".."
-                                                       }
+                       }
+                       
+                       is TreeNode.DirNode -> ul {
+                               if (!path.isRoot)
+                                       li {
+                                               a(href = href(Root.Admin.Vfs.View(path.elements.dropLast(1)))) {
+                                                       +".."
                                                }
-                                       
-                                       render(path, tree.children)
-                               }
+                                       }
+                               
+                               render(path, tree.children)
                        }
                }
        }
@@ -244,31 +242,29 @@ suspend fun ApplicationCall.adminConfirmDeleteFile(path: StoragePath) {
                respond(HttpStatusCode.Conflict)
        else
                respondHtml(block = adminPage("Confirm Deletion of /$path") {
-                       main {
-                               p {
-                                       +"Are you sure you want to delete the file at /$path? "
-                                       strong { +"It will be gone forever!" }
-                               }
-                               table {
-                                       tr {
-                                               th { +"Last Updated" }
-                                               td { dateTime(stats.updated) }
-                                       }
-                                       tr {
-                                               th { +"Size (bytes)" }
-                                               td { +"${stats.size}" }
-                                       }
-                               }
-                               
-                               form(method = FormMethod.get, action = href(Root.Admin.Vfs.View(path.elements))) {
-                                       submitInput { value = "No, take me back" }
+                       p {
+                               +"Are you sure you want to delete the file at /$path? "
+                               strong { +"It will be gone forever!" }
+                       }
+                       table {
+                               tr {
+                                       th { +"Last Updated" }
+                                       td { dateTime(stats.updated) }
                                }
-                               +Entities.nbsp
-                               form(method = FormMethod.post, action = href(Root.Admin.Vfs.DeleteConfirmPost(path.elements))) {
-                                       installCsrfToken()
-                                       submitInput(classes = "evil") { value = "Yes, delete it" }
+                               tr {
+                                       th { +"Size (bytes)" }
+                                       td { +"${stats.size}" }
                                }
                        }
+                       
+                       form(method = FormMethod.get, action = href(Root.Admin.Vfs.View(path.elements))) {
+                               submitInput { value = "No, take me back" }
+                       }
+                       +Entities.nbsp
+                       form(method = FormMethod.post, action = href(Root.Admin.Vfs.DeleteConfirmPost(path.elements))) {
+                               installCsrfToken()
+                               submitInput(classes = "evil") { value = "Yes, delete it" }
+                       }
                })
 }
 
@@ -294,28 +290,26 @@ suspend fun ApplicationCall.adminConfirmRemoveDirectory(path: StoragePath) {
                respond(HttpStatusCode.Conflict)
        else
                respondHtml(block = adminPage("Confirm Deletion of /$path") {
-                       main {
-                               p {
-                                       +"Are you sure you want to delete the directory at /$path? "
-                                       strong { +"It, and all of its contents, will be gone forever!" }
-                               }
-                               ul {
-                                       for (entry in entries)
-                                               li {
-                                                       +entry.name
-                                                       if (entry.type == StoredFileType.DIRECTORY)
-                                                               +"/"
-                                               }
-                               }
-                               
-                               form(method = FormMethod.get, action = href(Root.Admin.Vfs.View(path.elements))) {
-                                       submitInput { value = "No, take me back" }
-                               }
-                               +Entities.nbsp
-                               form(method = FormMethod.post, action = href(Root.Admin.Vfs.RmDirConfirmPost(path.elements))) {
-                                       installCsrfToken()
-                                       submitInput(classes = "evil") { value = "Yes, delete it" }
-                               }
+                       p {
+                               +"Are you sure you want to delete the directory at /$path? "
+                               strong { +"It, and all of its contents, will be gone forever!" }
+                       }
+                       ul {
+                               for (entry in entries)
+                                       li {
+                                               +entry.name
+                                               if (entry.type == StoredFileType.DIRECTORY)
+                                                       +"/"
+                                       }
+                       }
+                       
+                       form(method = FormMethod.get, action = href(Root.Admin.Vfs.View(path.elements))) {
+                               submitInput { value = "No, take me back" }
+                       }
+                       +Entities.nbsp
+                       form(method = FormMethod.post, action = href(Root.Admin.Vfs.RmDirConfirmPost(path.elements))) {
+                               installCsrfToken()
+                               submitInput(classes = "evil") { value = "Yes, delete it" }
                        }
                })
 }
index e821bc89cd21d8290828e800de6ce29b3e935e91..61097e1899c03d13ea8f0d0c89313c0de82c6b7e 100644 (file)
@@ -44,6 +44,7 @@ body {
        width: 100vw;
        height: 100vh;
        margin: 0;
+       padding: 1em 20vmin;
 
        background-color: #541;
        box-shadow: inset 0 0 15vmin 10vmin #000;
@@ -68,16 +69,6 @@ body::after {
        pointer-events: none;
 }
 
-main {
-       position: fixed;
-       top: 0;
-       left: 20vmin;
-       right: 20vmin;
-       bottom: 0;
-
-       overflow-y: auto;
-}
-
 div.message {
        position: fixed;
        top: 50vh;
index 000b9fd287a81a243fe4e908088bee7ae7818299..e6ad2416ece1c0671b68c2a9aff4a0cef70e5ce4 100644 (file)
@@ -7,4 +7,14 @@
                        });
                }
        });
+
+       window.addEventListener("load", function () {
+               // Localize dates and times
+               const moments = document.getElementsByClassName("moment");
+               for (const moment of moments) {
+                       let date = new Date(Number(moment.textContent.trim()));
+                       moment.innerHTML = date.toLocaleString();
+                       moment.style.display = "inline";
+               }
+       });
 })();