2025-03-13 08:25:39 +01:00
|
|
|
package templates
|
|
|
|
|
2025-03-15 01:49:52 +01:00
|
|
|
import "net/http"
|
|
|
|
import "sonarqube-badge/router/utils"
|
|
|
|
import "github.com/golang-jwt/jwt/v5"
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
func isActive(title string, key string) string {
|
|
|
|
if strings.HasPrefix(title, key) {
|
|
|
|
return "active"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2025-03-13 08:25:39 +01:00
|
|
|
templ head(title string) {
|
|
|
|
<head>
|
|
|
|
<title>{ title }</title>
|
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
|
|
|
</head>
|
|
|
|
}
|
|
|
|
|
2025-03-15 01:49:52 +01:00
|
|
|
templ header(loggedIn bool, title string) {
|
|
|
|
<nav class="navbar navbar-expand-lg bg-primary p-2">
|
|
|
|
<a class="navbar-brand" href="/">Sonarqube Badges</a>
|
|
|
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
|
|
|
if loggedIn {
|
|
|
|
<li class="nav-item">
|
|
|
|
<a class={"nav-link " + isActive(title, "Project")} href="/">Projects</a>
|
|
|
|
</li>
|
|
|
|
<li class="nav-item">
|
|
|
|
<a class={"nav-link " + isActive(title, "User Profile")} href="/user">Profile</a>
|
|
|
|
</li>
|
|
|
|
<li class="nav-item">
|
|
|
|
<a class="nav-link" href="/disconnect">Disconnect</a>
|
|
|
|
</li>
|
|
|
|
}
|
|
|
|
</ul>
|
2025-03-13 08:25:39 +01:00
|
|
|
</nav>
|
|
|
|
}
|
|
|
|
|
2025-03-15 01:49:52 +01:00
|
|
|
templ layout(component templ.Component, title string, token *jwt.Token) {
|
|
|
|
<html lang="en" data-bs-theme="dark">
|
2025-03-13 08:25:39 +01:00
|
|
|
@head(title)
|
|
|
|
<body hx-ext="response-targets">
|
2025-03-15 01:49:52 +01:00
|
|
|
@header(token != nil, title)
|
2025-03-13 08:25:39 +01:00
|
|
|
<div class="container-fluid m-4">
|
|
|
|
@component
|
|
|
|
</div>
|
|
|
|
</body>
|
2025-03-15 01:49:52 +01:00
|
|
|
<script src="https://unpkg.com/htmx.org@2.0.4"></script>
|
|
|
|
<script src="https://unpkg.com/htmx-ext-json-enc@2.0.1/json-enc.js"></script>
|
|
|
|
<script src="https://unpkg.com/htmx-ext-response-targets@2.0.3" integrity="sha384-T41oglUPvXLGBVyRdZsVRxNWnOOqCynaPubjUVjxhsjFTKrFJGEMm3/0KGmNQ+Pg" crossorigin="anonymous"></script>
|
|
|
|
<script>htmx.config.responseTargetUnsetsError = false</script>
|
|
|
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
2025-03-13 08:25:39 +01:00
|
|
|
</html>
|
2025-03-15 01:49:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func Layout(component templ.Component, title string, req *http.Request) templ.Component {
|
|
|
|
token, _ := utils.GetToken(req)
|
|
|
|
return layout(component, title, token);
|
2025-03-13 08:25:39 +01:00
|
|
|
}
|