catbase/plugins/admin/admin.templ

75 lines
2.0 KiB
Plaintext

package admin
import "fmt"
templ (a *AdminPlugin) page() {
<form>
<h2>App Pass</h2>
<label for="password">Password:
<input type="text" name="password"></input>
</label>
<label for="secret">Secret:
<input type="text" name="secret"></input>
</label>
<button hx-post="/apppass/api" hx-target="#data" class="button">List</button>
<button hx-put="/apppass/api" hx-target="#data" class="submit success button">New</button>
<div style="margin-top: 2em" class="cell" id="data"></div>
</form>
}
templ (a *AdminPlugin) showPassword(entry PassEntry) {
<h2>New Entry</h2>
<p>ID: { fmt.Sprintf(" %d", entry.ID) }</p>
<p>Password: { entry.Secret }:{ entry.Pass }</p>
}
templ (a *AdminPlugin) entries(items []PassEntry) {
<h2>Entry List</h2>
if len(items) == 0 {
<p>No items</p>
}
<ul>
for _, entry := range items {
<li>
<button href="#"
class="button alert tiny"
style="vertical-align: baseline"
hx-delete="/apppass/api"
hx-confirm={ fmt.Sprintf("Are you sure you want to delete %d?", entry.ID) }
hx-target="#data"
name="id" value={ fmt.Sprintf("%d", entry.ID) }>X</button>
{ fmt.Sprintf("%d", entry.ID) }
</li>
}
</ul>
}
templ renderError(err error) {
<div>{ err.Error() }</div>
}
templ vars(items []configEntry) {
<h2>Variables</h2>
<table class="hover striped">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
for _, item := range items {
<tr>
<td>{ item.Key }</td><td>{ item.Value }</td>
</tr>
}
if len(items) == 0 {
<tr>
<td colspan="2">No data</td>
</tr>
}
</tbody>
</table>
}