Skip to content

Commit

Permalink
feat: Add a base route for a Contentstack dashboard extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Jan 25, 2025
1 parent 461b666 commit af217df
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/server/handle-routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func HandleRoutes(mux *http.ServeMux, apiPath string) {
apiRoute(mux, apiPath, "/translations", "GET", v1.GetTranslations)
apiRoute(mux, apiPath, "/sitemap-data", "GET", v1.GetSitemapData)
apiRoute(mux, apiPath, "/sync", "POST", v1.Sync)

mux.HandleFunc("GET /dashboard-entries-tree", func(w http.ResponseWriter, r *http.Request) {
routes.DashboardEntriesTree(w, r)
})
}

func apiRoute(
Expand Down
48 changes: 48 additions & 0 deletions cmd/server/routes/dashboard-entries-tree.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package routes

import (
"bytes"
"embed"
"fmt"
"io/fs"
"net/http"
"text/template"

"github.com/Dobefu/csb/cmd/logger"
)

type FS interface {
fs.FS
ReadDir(string) ([]fs.DirEntry, error)
ReadFile(string) ([]byte, error)
}

//go:embed templates/*
var content embed.FS
var getFs = func() FS { return content }

func DashboardEntriesTree(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/html")
w.Header().Add("X-Content-Type-Options", "nosniff")

data := make(map[string]interface{})

templates := []string{
"templates/dashboard-entries-tree.html.tmpl",
}

tpl := template.Must(template.ParseFS(getFs(), templates...))
var buf bytes.Buffer
err := tpl.Execute(&buf, data)

if err != nil {
logger.Error(err.Error())
http.NotFound(w, r)
return
}

w.WriteHeader(http.StatusOK)

output := buf.Bytes()
fmt.Fprint(w, string(output))
}
35 changes: 35 additions & 0 deletions cmd/server/routes/templates/dashboard-entries-tree.html.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Entries Tree View</title>

<link
rel="stylesheet"
type="text/css"
href="https://unpkg.com/@contentstack/[email protected]/dist/ui-extension-sdk.css"
crossorigin="anonymous"
>

<style>
html {
height: 100%;
}

.DashboardItem {
min-height: 100%;
padding: 1.875rem;
padding-top: 0;
}
</style>
</head>

<body class="DashboardItem">
PLACEHOLDER
</body>

</html>

0 comments on commit af217df

Please sign in to comment.