Start minimalist UI

This commit is contained in:
nemunaire 2021-05-02 16:04:18 +02:00
parent 5598d78e16
commit cce72978bf
8 changed files with 123 additions and 0 deletions

3
app.go
View File

@ -11,6 +11,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/nemunaire/minifaas/engine/docker"
"github.com/nemunaire/minifaas/ui"
)
type App struct {
@ -23,6 +24,8 @@ func NewApp() App {
gin.ForceConsoleColor()
router := gin.Default()
ui.DeclareRoutes(router)
router.GET("/api/version", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"version": 0.1})
})

18
ui/assets.go Normal file
View File

@ -0,0 +1,18 @@
// +build !dev
package ui
import (
"embed"
"net/http"
)
//go:embed *
var _assets embed.FS
var Assets http.FileSystem
func init() {
Assets = http.FS(_assets)
}

9
ui/assets_dev.go Normal file
View File

@ -0,0 +1,9 @@
// +build dev
package ui
import (
"net/http"
)
var Assets = http.Dir("./ui")

7
ui/css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

0
ui/css/vepilepsie.css Normal file
View File

33
ui/index.html Normal file
View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Minifaas</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="/css/bootstrap.min.css" type="text/css" rel="stylesheet">
</head>
<body class="container">
<div class="mt-2 jumbotron">
<h1>This will launch a docker container</h1>
<hr>
<form onsubmit="return runctnr()">
<button type="submit" class="btn btn-primary" id="btnlaunch">
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" id="btnlaunchspinner" style="display: none"></span>
Launch!
</button>
</form>
</div>
<div id="logs-card" class="card" style="display: none;">
<h5 class="card-header">
Here is your container logs output:
</h5>
<pre id="logs" class="card-body bg-dark text-light">
test
test
</pre>
</div>
<script src="/js/minifass.js"></script>
</body>
</html>

26
ui/js/minifass.js Normal file
View File

@ -0,0 +1,26 @@
function getVersion() {
fetch('/api/version')
.then(function(response) {
return response.json();
})
.then(function(version) {
document.getElementById("version").innerHTML = "v" + version.version;
});
}
function runctnr() {
document.getElementById("btnlaunch").disabled = true;
document.getElementById("btnlaunchspinner").style.display = "inline-block";
fetch('/api/run')
.then(function(response) {
document.getElementById("btnlaunch").disabled = false;
document.getElementById("btnlaunchspinner").style.display = "none";
return response.text();
})
.then(function(logs) {
document.getElementById("logs").textContent = logs;
document.getElementById("logs-card").style.display = "block";
})
return false;
}

27
ui/routes.go Normal file
View File

@ -0,0 +1,27 @@
package ui
import (
"github.com/gin-gonic/gin"
)
func DeclareRoutes(router *gin.Engine) {
router.GET("/", serveOrReverse("/"))
router.GET("/favicon.ico", serveOrReverse("/favicon.ico"))
router.GET("/manifest.json", serveOrReverse("/manifest.json"))
router.GET("/css/*path", serveOrReverse(""))
router.GET("/fonts/*path", serveOrReverse(""))
router.GET("/img/*path", serveOrReverse(""))
router.GET("/js/*path", serveOrReverse(""))
}
func serveOrReverse(forced_url string) gin.HandlerFunc {
if forced_url != "" {
return func(c *gin.Context) {
c.FileFromFS(forced_url, Assets)
}
} else {
return func(c *gin.Context) {
c.FileFromFS(c.Request.URL.Path, Assets)
}
}
}