-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.templ
151 lines (137 loc) · 6.63 KB
/
main.templ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import "fmt"
templ Header(){
<header class="d-flex justify-content-center m-2 p-1 border-bottom">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="/"><i class="bi bi-gitlab"></i></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
@NavbarLoggedOut()
</div>
</nav>
</header>
}
templ NavbarLoggedIn(){
<div id="nav" class="navbar-nav" hx-get="/nav/logout" hx-trigger="logged-out from:body" hx-swap="outerHTML">
<div class="nav-item nav-link" hx-get="/sessionstore" hx-target="#content" hx-swap="outerHTML">SessionStore</div>
<div class="nav-item nav-link" hx-get="/serviceaccount" hx-target="#content" hx-swap="outerHTML">ServiceAccounts</div>
<div class="nav-item nav-link" hx-get="/token" hx-target="#content" hx-swap="outerHTML">PersonalAccessTokens</div>
<div class="nav-item nav-link" hx-get="/logout" hx-target="#content" hx-swap="outerHTML">Logout</div>
</div>
}
templ NavbarLoggedOut(){
<div id="nav" class="navbar-nav" hx-get="/nav/login" hx-trigger="logged-in from:body" hx-swap="outerHTML">
<div class="nav-item nav-link" hx-get="/login" hx-target="#content" hx-swap="outerHTML">Login</div>
<div class="nav-item nav-link" hx-get="/register" hx-target="#content" hx-swap="outerHTML">Register</div>
</div>
}
templ Home(){
<div id="content" class="d-flex justify-content-center m-2 p-1">
Simple SPA to have an UI for gitlab serviceaccount management.
</div>
}
templ Footer(year int){
<footer class="d-flex pt-3 my-3 justify-content-center border-top">
<div>Created with
<i class="bi bi-heart-fill"></i>
by Kai Ehrhardt
<i class="bi bi-c-circle"></i>
{ fmt.Sprintf("%d", year) }
</div>
</footer>
}
templ Auth(mode string){
<div id="content" class="d-flex justify-content-center">
<form id="login" class="w-25 m-2 p-1" hx-post={ mode } hx-target="#content" hx-swap="outerHTML">
<input type="username" class="form-control m-2" name="name" placeholder="username" required>
<input type="password" class="form-control m-2" name="pass" placeholder="password" required>
<input type="submit" class="btn btn-primary rounded-pill m-2" value={ mode }>
</form>
</div>
}
templ LogoutComponent(){
<div id="content" class="d-flex justify-content-center">
<form class="w-25 m-2 p-1" hx-post="/logout" hx-target="#content" hx-swap="outerHTML">
<input class="btn btn-primary rounded-pill m-2" type="submit" value="Logout">
</form>
</div>
}
templ SessionComponent(){
<div id="content" class="d-flex justify-content-center">
<form class="w-25 m-2 p-1" hx-post="/sessionstore" hx-target="#content" hx-swap="outerHTML">
<input type="url" class="form-control m-2" name="glUrl" placeholder="Gitlab Url e.g. https://gitlab.example.com" required>
<input type="password" class="form-control m-2" name="glToken" placeholder="Gitlab Token e.g. glpat-..." required>
<input class="btn btn-primary rounded-pill m-2" type="submit" value="Store in Session">
</form>
</div>
}
templ CreateServiceUser(){
<div id="content" class="d-flex justify-content-center">
<form class="w-25 m-2 p-1" hx-post="/serviceaccount" hx-target="#content" hx-swap="outerHTML">
<input type="text" class="form-control m-2" name="saName" placeholder="Service Account Name">
<input type="text" class="form-control m-2" name="saDisplayName" placeholder="Service Account Display Name">
<input class="btn btn-primary rounded-pill m-2" type="submit" value="Create">
</form>
</div>
}
templ CreatePersonalAccessToken(Scopes []string){
<div id="content" class="d-flex justify-content-center">
<form class="w-25 m-2 p-1" hx-post="/token" hx-target="#content" hx-swap="outerHTML">
<input type="text" class="form-control m-2" name="UserID" placeholder="ID of the user" required>
<input type="text" class="form-control m-2" name="Name" placeholder="Name of the personal access token" required>
<input type="date" class="form-control m-2" name="ExpiresAt" placeholder="Expiration date of the access token in ISO format (YYYY-MM-DD)" required>
<select class="form-select m-2 p-1" name="Scopes" id="scopes" multiple>
for _, s :=range Scopes {
<option value={s}>{s}</option>
}
</select>
<input class="btn btn-primary rounded-pill m-2" type="submit" value="Create">
</form>
</div>
}
templ Output(output string){
<div id="content" class="d-flex justify-content-center">
<div class="w-50 m-2 p-1">
{ output }
<form hx-get="/home" hx-target="#content" hx-swap="outerHTML">
<input class="btn btn-primary rounded-pill m-2" type="submit" value="Back to Start">
</form>
</div>
</div>
}
templ OutputToken(token string){
<div id="content" class="d-flex justify-content-center">
<div class="w-25 m-2 p-1">
<div class="input-group m-2">
<input id="pass" type="password" class="form-control" name="pat" value={ token } aria-label="pat">
<span class="input-group-text" _="on click if #pass's [@type] is 'password' set #pass's [@type] to 'text' else set #pass's [@type] to 'password'"><i class="bi bi-eye"></i></span>
</div>
Make sure you save it - you won't be able to access it again.
<form hx-get="/home" hx-target="#content" hx-swap="outerHTML">
<input class="btn btn-primary rounded-pill m-2" type="submit" value="Back to Start">
</form>
</div>
</div>
}
templ Site(year int){
<!doctype html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<script src="https://unpkg.com/[email protected]/dist/htmx.js" integrity="sha384-qbtR4rS9RrUMECUWDWM2+YGgN3U4V4ZncZ0BvUcg9FGct0jqXz3PUdVpU1p0yrXS" crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]"></script>
<title>Gitlab ServiceAccount Management SPA</title>
</head>
<body>
<div class="container-fluid text-center">
@Header()
@Home()
@Footer(year)
</div>
</body>
</html>
}