diff --git a/appview/filetree/filetree.go b/appview/filetree/filetree.go new file mode 100644 index 00000000..01fb56b3 --- /dev/null +++ b/appview/filetree/filetree.go @@ -0,0 +1,62 @@ +package filetree + +import ( + "path/filepath" + "sort" + "strings" +) + +type FileTreeNode struct { + Name string + Path string + IsDirectory bool + Children map[string]*FileTreeNode +} + +// NewNode creates a new node +func newNode(name, path string, isDir bool) *FileTreeNode { + return &FileTreeNode{ + Name: name, + Path: path, + IsDirectory: isDir, + Children: make(map[string]*FileTreeNode), + } +} + +func FileTree(files []string) *FileTreeNode { + rootNode := newNode("", "", true) + + sort.Strings(files) + + for _, file := range files { + if file == "" { + continue + } + + parts := strings.Split(filepath.Clean(file), "/") + if len(parts) == 0 { + continue + } + + currentNode := rootNode + currentPath := "" + + for i, part := range parts { + if currentPath == "" { + currentPath = part + } else { + currentPath = filepath.Join(currentPath, part) + } + + isDir := i < len(parts)-1 + + if _, exists := currentNode.Children[part]; !exists { + currentNode.Children[part] = newNode(part, currentPath, isDir) + } + + currentNode = currentNode.Children[part] + } + } + + return rootNode +} diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index ed2399ab..490b98ab 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -13,6 +13,7 @@ import ( "time" "github.com/dustin/go-humanize" + "tangled.sh/tangled.sh/core/appview/filetree" "tangled.sh/tangled.sh/core/appview/pages/markup" ) @@ -174,6 +175,7 @@ func funcMap() template.FuncMap { return template.HTML(data) }, "cssContentHash": CssContentHash, + "fileTree": filetree.FileTree, } } diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 3f32e0a7..190d8cd0 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -505,11 +505,12 @@ func (p *Pages) RepoLog(w io.Writer, params RepoLogParams) error { } type RepoCommitParams struct { - LoggedInUser *auth.User - RepoInfo RepoInfo - Active string - types.RepoCommitResponse + LoggedInUser *auth.User + RepoInfo RepoInfo + Active string EmailToDidOrHandle map[string]string + + types.RepoCommitResponse } func (p *Pages) RepoCommit(w io.Writer, params RepoCommitParams) error { @@ -784,7 +785,7 @@ type RepoPullPatchParams struct { DidHandleMap map[string]string RepoInfo RepoInfo Pull *db.Pull - Diff types.NiceDiff + Diff *types.NiceDiff Round int Submission *db.PullSubmission } diff --git a/appview/pages/templates/repo/fragments/diff.html b/appview/pages/templates/repo/fragments/diff.html index e237f56b..605c2477 100644 --- a/appview/pages/templates/repo/fragments/diff.html +++ b/appview/pages/templates/repo/fragments/diff.html @@ -3,6 +3,7 @@ {{ $diff := index . 1 }} {{ $commit := $diff.Commit }} {{ $stat := $diff.Stat }} +{{ $fileTree := fileTree $diff.ChangedFiles }} {{ $diff := $diff.Diff }} {{ $this := $commit.This }} @@ -14,17 +15,7 @@ Changed files {{ block "statPill" $stat }} {{ end }} -
This file has been copied.
- {{ else if .IsRename }} -- This file has been renamed. -
{{ else if .IsBinary }}
This is a binary file and will not be displayed.
diff --git a/appview/pages/templates/repo/fragments/filetree.html b/appview/pages/templates/repo/fragments/filetree.html
new file mode 100644
index 00000000..9268610a
--- /dev/null
+++ b/appview/pages/templates/repo/fragments/filetree.html
@@ -0,0 +1,27 @@
+{{ define "fileTree" }}
+ {{ if and .Name .IsDirectory }}
+
+
+ {{ i "folder" "w-3 h-3 fill-current" }}
+ {{ .Name }}
+
+
+