sonarqube-badges/templates/index.templ

35 lines
1.1 KiB
Text
Raw Permalink Normal View History

2025-03-13 08:25:39 +01:00
package templates
2025-03-15 01:49:52 +01:00
import "github.com/golang-jwt/jwt/v5"
templ Index(token *jwt.Token) {
{{
username := ""
if claims, ok := token.Claims.(jwt.MapClaims); ok {
username = claims["username"].(string)
}
}}
<div class="container">
<h2 class="my-4">Welcome {username}</h2>
<div class="container">
<h3 class="my-2">Projects</h3>
<div hx-get="/project" hx-trigger="load"></div>
<a hx-post="/api/project" id="projectAdder">
<button class="btn btn-primary" type="button" >Create project</button>
</a>
</div>
</div>
<script type="application/javascript">
document.getElementById('projectAdder').addEventListener('htmx:beforeSwap', function (ev) {
ev.detail.shouldSwap = false;
});
document.getElementById('projectAdder').addEventListener('htmx:afterRequest', function (ev) {
if (ev.detail.successful) {
const id = JSON.parse(ev.detail.xhr.response).ID;
location.href = `/project/${id}`;
}
});
</script>
}