feature(ui): permettre la modification de fichiers par UI

This commit is contained in:
Victor Lacasse-Beaudoin 2024-10-31 19:18:45 -04:00
parent 5943791364
commit f6a8dfe2f4
9 changed files with 315 additions and 1 deletions

55
ui/admin-edit.html Normal file
View file

@ -0,0 +1,55 @@
{{ define "admin-edit-html" }}
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>AGECEM</title>
{{ template "general-html" }}
<link rel="stylesheet" href="/public/css/admin-edit.css">
<script src="https://unpkg.com/htmx.org@2.0.3"></script>
</head>
<body>
{{ template "header-html" }}
{{ if .Error }}
<b>{{ .Error }}</b>
{{ end }}
<article id="moduleAdminEdit">
<h2>Modifier les documents</h2>
{{ range .Buckets }}
{{ $bucketID := .ID }}
<h3>{{ .DisplayName }} ({{ .ID }})</h3>
{{ if not .DocumentKeys }}
<p><i>Aucun document de type {{ .DisplayName }} enregistré, voir le <a href="/admin">panneau d'administration</a> pour en ajouter.</i></p>
{{ else }}
<table>
<tr><th></th><th>Renommer</th><th>Effacer</th></tr>
{{ range .DocumentKeys }}
<tr>
<td>{{ . }}</td>
<td><a
hx-get="/admin/documents/edit/{{$bucketID}}/{{.}}/key"
hx-target="#app-dialog"
hx-on:click="document.getElementById('app-dialog').style.display = 'block';">
<button>🖉</button>
</a></td>
<td><a
hx-get="/admin/documents/edit/{{$bucketID}}/{{.}}/delete"
hx-target="#app-dialog"
hx-on:click="document.getElementById('app-dialog').style.display = 'block';">
<button>🗑</button>
</a></td>
</tr>
{{ end }}
</table>
{{ end }}
{{ end }}
<div id="app-dialog" style="display: none;"> </div>
</article>
{{ template "footer-html" }}
</body>
</html>
{{ end }}

View file

@ -15,10 +15,11 @@
<h1 class="heading1">Admin</h1>
<div class="adminOptions">
<button class="adminOption" onclick="location.href = '/admin/documents/upload'">Ajout de documents</a>
<button class="adminOption" onclick="location.href = '/admin/documents/edit'">Modification des documents</a>
</div>
</div>
{{ template "footer-html" }}
</body>
</html>
{{ end }}
{{ end }}

View file

@ -0,0 +1,23 @@
{{ define "dialog-document-delete" }}
{{ if .Error }}
{{ .Error }}
{{ else }}
<form
action=""
id="delete-document-form"
hx-delete="/admin/documents/edit/{{.Bucket}}/{{.Document}}"
hx-target="#app-dialog">
<label>
Effacer fichier <code>{{ .Bucket }}</code> / <code>{{ .Document }}</code>?
</label>
<br>
<input type="submit" id="delete-document-apply" value="Confirmer"/>
{{ template "dialog-button-clear" }}
</form>
{{ end }}
{{ end }}
{{ define "dialog-document-delete-result" }}
{{ . }}
{{ template "dialog-button-clear" "ok" }}
{{ end }}

View file

@ -0,0 +1,32 @@
{{ define "dialog-document-rename" }}
{{ if .Error }}
{{ .Error }}
{{ else }}
<form
action=""
id="rename-document-form"
hx-put="/admin/documents/edit/{{.Bucket}}/{{.Document}}/key"
hx-target="#app-dialog">
<label for="rename-document-form-newkey">
Nouveau nom de fichier pour <code>{{.Bucket}}</code> / <code>{{.Document}}</code>:
</label>
<input
type="text"
id="rename-document-form-newkey"
name="rename-document-form-newkey"
required
selected/>
<br>
<input
type="submit"
id="rename-document-form-apply"
value="Confirmer"/>
{{ template "dialog-button-clear" }}
</form>
{{ end }}
{{ end }}
{{ define "dialog-document-rename-result" }}
{{ . }}
{{ template "dialog-button-clear" "ok" }}
{{ end }}

13
ui/dialog.html Normal file
View file

@ -0,0 +1,13 @@
{{ define "dialog-button-clear" }}
<button
hx-get="/nothing"
hx-target="#app-dialog"
hx-on:click="document.getElementById('app-dialog').style.display = 'none';">
{{ if not . }}Annuler{{ else }}{{ . }}{{ end }}
</button>
{{ end }}
{{ define "dialog-error" }}
<p>Error: {{ .Error }}</p>
{{ template "dialog-button-clear" }}
{{ end }}

View file

@ -0,0 +1,20 @@
table {
border: 1px solid;
border-collapse: collapse;
}
td, th {
border: 1px solid;
}
#app-dialog {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
border: 1px solid #ccc;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
padding: 20px;
z-index: 555;
}