diff --git a/pkg/agecemorg/client.go b/pkg/agecemorg/client.go
index 443a025..9a8e091 100644
--- a/pkg/agecemorg/client.go
+++ b/pkg/agecemorg/client.go
@@ -175,6 +175,22 @@ func (a *API) ListBuckets() (response ListBucketsResponse, err error) {
return response, a.Voki.Unmarshal(http.MethodGet, "/v1/bucket", nil, true, &response)
}
+func (a *API) ReadBucket(bucket string) (response ReadBucketResponse, err error) {
+ return response, a.Voki.Unmarshal(http.MethodGet, fmt.Sprintf("/v1/bucket/%s", bucket), nil, true, &response)
+}
+
+func (a *API) UpdateDocumentKey(bucket, document, newKey string) (response UpdateDocumentKeyResponse, err error) {
+ var buf bytes.Buffer
+ if err := json.NewEncoder(&buf).Encode(newKey); err != nil {
+ return response, fmt.Errorf("handler: %s", err)
+ }
+ return response, a.Voki.Unmarshal(http.MethodPut, fmt.Sprintf("/v1/bucket/%s/%s/key", bucket, document), &buf, true, &response)
+}
+
+func (a *API) DeleteDocument(bucket, document string) (response DeleteDocumentResponse, err error) {
+ return response, a.Voki.Unmarshal(http.MethodDelete, fmt.Sprintf("/v1/bucket/%s/%s", bucket, document), nil, true, &response)
+}
+
func (a *API) Seed() (response ExecuteSeedResponse, err error) {
request, err := NewV1SeedPOST()
if err != nil {
diff --git a/pkg/agecemorg/handler.go b/pkg/agecemorg/handler.go
index 26ce6fe..5f8b886 100644
--- a/pkg/agecemorg/handler.go
+++ b/pkg/agecemorg/handler.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
+ "log"
"net/http"
"net/url"
"sort"
@@ -686,6 +687,151 @@ func HandlePageProcesVerbaux() echo.HandlerFunc {
}
}
+func HandleAdminDocumentsEditDelete(api *API) echo.HandlerFunc {
+ return func(c echo.Context) error {
+ switch c.Request().Method {
+ case http.MethodGet:
+ var data struct {
+ Error string
+ Bucket string
+ Document string
+ }
+
+ data.Bucket = c.Param("bucket")
+ data.Document = c.Param("document")
+
+ return c.Render(http.StatusOK, "dialog-document-delete", data)
+ case http.MethodDelete:
+ var data struct {
+ Error string
+ Bucket string
+ Document string
+ DeleteDocumentResponse DeleteDocumentResponse
+ }
+ if api == nil {
+ errMsg := "Error: HandleAdminDocumentsEditDelete called with nil *API"
+ log.Println(errMsg)
+ data.Error = errMsg
+
+ return c.String(http.StatusOK, data.Error)
+ }
+ data.Bucket = c.Param("bucket")
+ data.Document = c.Param("document")
+
+ deleteDocumentResponse, err := api.DeleteDocument(data.Bucket, data.Document)
+ if err != nil {
+ log.Println(err)
+ data.Error = err.Error()
+ return c.Render(http.StatusOK, "dialog-error", data)
+ }
+ data.DeleteDocumentResponse = deleteDocumentResponse
+
+ return c.Render(http.StatusOK, "dialog-document-delete-result", data)
+ default:
+ return c.String(http.StatusOK, "unsupported method")
+ }
+ }
+}
+
+func HandleAdminDocumentsEditKey(api *API) echo.HandlerFunc {
+ return func(c echo.Context) error {
+ switch c.Request().Method {
+ case http.MethodGet:
+ var data struct {
+ Error string
+ Bucket string
+ Document string
+ }
+
+ data.Bucket = c.Param("bucket")
+ data.Document = c.Param("document")
+
+ return c.Render(http.StatusOK, "dialog-document-rename", data)
+ case http.MethodPut:
+ var data struct {
+ Error string
+ Bucket string
+ Document string
+ UpdateDocumentKeyResponse UpdateDocumentKeyResponse
+ }
+ if api == nil {
+ errMsg := "Error: HandleAdminDocumentsEdit called with nil *API"
+ log.Println(errMsg)
+ data.Error = errMsg
+
+ return c.String(http.StatusOK, data.Error)
+ }
+
+ data.Bucket = c.Param("bucket")
+ data.Document = c.Param("document")
+
+ newKey := c.FormValue("rename-document-form-newkey")
+
+ updateDocumentKeyResponse, err := api.UpdateDocumentKey(data.Bucket, data.Document, newKey)
+ if err != nil {
+ log.Println(err)
+ data.Error = err.Error()
+ return c.Render(http.StatusOK, "dialog-error", data)
+ }
+ data.UpdateDocumentKeyResponse = updateDocumentKeyResponse
+
+ return c.Render(http.StatusOK, "dialog-document-rename-result", data)
+ default:
+ return c.String(http.StatusOK, "unsupported method")
+ }
+ }
+}
+
+func HandleNothing() echo.HandlerFunc {
+ return func(c echo.Context) error {
+ return c.String(http.StatusOK, "")
+ }
+}
+
+func HandleAdminDocumentsEdit(api *API) echo.HandlerFunc {
+ return func(c echo.Context) error {
+ type DataBucket struct {
+ ID string
+ DisplayName string
+ DocumentKeys []string
+ }
+ var data struct {
+ Error string
+ Buckets []DataBucket
+ }
+
+ if api == nil {
+ errMsg := "Error: HandleAdminDocumentsEdit called with nil *API"
+ log.Println(errMsg)
+ data.Error = errMsg
+ return c.Render(http.StatusOK, "admin-edit-html", data)
+ }
+
+ listBucketsResponse, err := api.ListBuckets()
+ if err != nil {
+ log.Println(err)
+ data.Error = err.Error()
+ return c.Render(http.StatusOK, "admin-edit-html", data)
+ }
+ for name, displayName := range listBucketsResponse.Data.Buckets {
+ readBucketResponse, err := api.ReadBucket(name)
+ if err != nil {
+ log.Println(err)
+ }
+
+ dataBucket := DataBucket{
+ ID: name,
+ DisplayName: displayName,
+ DocumentKeys: readBucketResponse.Data.Keys,
+ }
+
+ data.Buckets = append(data.Buckets, dataBucket)
+ }
+
+ return c.Render(http.StatusOK, "admin-edit-html", data)
+ }
+}
+
func (h *WebHandler) HandleAdminDocumentsUpload(c echo.Context) error {
var response HandleAdminDocumentsUploadResponse
diff --git a/pkg/agecemorg/routes.go b/pkg/agecemorg/routes.go
index 73c9f9b..52a73f7 100644
--- a/pkg/agecemorg/routes.go
+++ b/pkg/agecemorg/routes.go
@@ -152,6 +152,8 @@ func RunServer(cfg Config) {
e.GET("/", HandleIndex)
+ e.GET("/nothing", HandleNothing())
+
//e.GET("/a-propos", HandleAPropos)
//e.GET("/actualite", HandleActualite)
@@ -180,6 +182,12 @@ func RunServer(cfg Config) {
groupAdmin.POST("/documents/upload", webHandler.HandleAdminDocumentsUploadPOST)
+ groupAdmin.GET("/documents/edit", HandleAdminDocumentsEdit(webHandler.ApiClient))
+ groupAdmin.GET("/documents/edit/:bucket/:document/delete", HandleAdminDocumentsEditDelete(webHandler.ApiClient))
+ groupAdmin.DELETE("/documents/edit/:bucket/:document", HandleAdminDocumentsEditDelete(webHandler.ApiClient))
+ groupAdmin.GET("/documents/edit/:bucket/:document/key", HandleAdminDocumentsEditKey(webHandler.ApiClient))
+ groupAdmin.PUT("/documents/edit/:bucket/:document/key", HandleAdminDocumentsEditKey(webHandler.ApiClient))
+
e.Logger.Fatal(e.Start(
fmt.Sprintf(":%d", cfg.Server.Port)))
}
diff --git a/ui/admin-edit.html b/ui/admin-edit.html
new file mode 100644
index 0000000..5867bae
--- /dev/null
+++ b/ui/admin-edit.html
@@ -0,0 +1,55 @@
+{{ define "admin-edit-html" }}
+
+
+
+
+
+ AGECEM
+ {{ template "general-html" }}
+
+
+
+
+
+ {{ template "header-html" }}
+ {{ if .Error }}
+ {{ .Error }}
+ {{ end }}
+
+ Modifier les documents
+
+ {{ range .Buckets }}
+ {{ $bucketID := .ID }}
+ {{ .DisplayName }} ({{ .ID }})
+ {{ if not .DocumentKeys }}
+ Aucun document de type {{ .DisplayName }} enregistré, voir le panneau d'administration pour en ajouter.
+ {{ else }}
+
+ | Renommer | Effacer |
+ {{ range .DocumentKeys }}
+
+ {{ . }} |
+
+
+ |
+
+
+ |
+
+ {{ end }}
+
+ {{ end }}
+ {{ end }}
+
+
+ {{ template "footer-html" }}
+
+
+
+{{ end }}
diff --git a/ui/admin.html b/ui/admin.html
index 14245d1..867ab41 100644
--- a/ui/admin.html
+++ b/ui/admin.html
@@ -15,10 +15,11 @@
Admin
{{ template "footer-html" }}