Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
85 lines
1.5 KiB
Go
85 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
type TreeViewNode struct {
|
|
Href string
|
|
Name string
|
|
Path string
|
|
Depth int
|
|
IsDir bool
|
|
IsDraft bool
|
|
ChildCount int
|
|
}
|
|
|
|
func (s *Server) handleTree(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
|
|
rootPath := path.Clean("/" + strings.TrimPrefix(r.URL.Path, "/v/tree"))
|
|
readable, err := s.readableNavigation(r)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(
|
|
w,
|
|
err.Error(),
|
|
500,
|
|
)
|
|
|
|
return
|
|
}
|
|
|
|
var nodes []TreeViewNode
|
|
visible := []publicTreeNode{}
|
|
for _, n := range publicTreeNodes(readable, rootPath) {
|
|
if n.Path != "/u" && !strings.HasPrefix(n.Path, "/u/") {
|
|
visible = append(visible, n)
|
|
}
|
|
}
|
|
visibleChildren := make(map[string]int)
|
|
for _, n := range visible {
|
|
if n.Path != "/" {
|
|
visibleChildren[parentPath(n.Path)]++
|
|
}
|
|
}
|
|
for _, n := range visible {
|
|
nodes = append(
|
|
nodes,
|
|
TreeViewNode{
|
|
Href: n.Href,
|
|
Name: n.Name,
|
|
Path: n.Path,
|
|
Depth: n.Depth + 1,
|
|
IsDir: n.IsDir || visibleChildren[n.Path] > 0,
|
|
ChildCount: visibleChildren[n.Path],
|
|
|
|
IsDraft: strings.HasPrefix(
|
|
n.Path,
|
|
"/draft/",
|
|
),
|
|
},
|
|
)
|
|
}
|
|
|
|
s.renderWithContext(
|
|
w,
|
|
r,
|
|
"tree.gohtml",
|
|
map[string]any{
|
|
"NavItems": resolveNavItems(
|
|
s.getSystemNavItems(s.domainUUIDForRequest(r)),
|
|
NavContext{Path: rootPath},
|
|
),
|
|
"Nodes": nodes,
|
|
"Path": rootPath,
|
|
"Breadcrumbs": buildBreadcrumbs(rootPath),
|
|
},
|
|
)
|
|
}
|