Skip to content

Commit 692c62a

Browse files
committed
clean up
1 parent b63ceb3 commit 692c62a

File tree

3 files changed

+12
-35
lines changed

3 files changed

+12
-35
lines changed

routers/web/repo/treelist.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package repo
55

66
import (
7-
"errors"
87
"net/http"
98

109
pull_model "code.gitea.io/gitea/models/pull"
@@ -87,24 +86,11 @@ func transformDiffTreeForUI(diffTree *gitdiff.DiffTree, filesViewedState map[str
8786
return files
8887
}
8988

90-
func Tree(ctx *context.Context) {
91-
recursive := ctx.FormBool("recursive")
92-
93-
if ctx.Repo.RefFullName == "" {
94-
ctx.ServerError("RefFullName", errors.New("ref_name is invalid"))
95-
return
96-
}
97-
98-
var results []*files_service.TreeViewNode
99-
var err error
100-
if !recursive {
101-
results, err = files_service.GetTreeViewNodes(ctx, ctx.Repo.Commit, ctx.Repo.TreePath, "")
102-
} else {
103-
results, err = files_service.GetTreeViewNodes(ctx, ctx.Repo.Commit, "", ctx.Repo.TreePath)
104-
}
89+
func TreeViewNodes(ctx *context.Context) {
90+
results, err := files_service.GetTreeViewNodes(ctx, ctx.Repo.Commit, ctx.Repo.TreePath, ctx.FormString("sub_path"))
10591
if err != nil {
106-
ctx.ServerError("GetTreeInformation", err)
92+
ctx.ServerError("GetTreeViewNodes", err)
10793
return
10894
}
109-
ctx.JSON(http.StatusOK, results)
95+
ctx.JSON(http.StatusOK, map[string]any{"fileTreeNodes": results})
11096
}

routers/web/web.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,9 @@ func registerRoutes(m *web.Router) {
11771177
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.TreeList)
11781178
})
11791179
m.Group("/tree", func() {
1180-
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.Tree)
1181-
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.Tree)
1182-
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.Tree)
1180+
m.Get("/branch/*", context.RepoRefByType(git.RefTypeBranch), repo.TreeViewNodes)
1181+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.TreeViewNodes)
1182+
m.Get("/commit/*", context.RepoRefByType(git.RefTypeCommit), repo.TreeViewNodes)
11831183
})
11841184
m.Get("/compare", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
11851185
m.Combo("/compare/*", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists).

web_src/js/features/repo-view-file-tree-sidebar.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,13 @@ async function toggleSidebar(sidebarEl: HTMLElement, shouldShow: boolean) {
2727
}
2828

2929
function childrenLoader(sidebarEl: HTMLElement) {
30-
return async (path: string, recursive?: boolean) => {
30+
return async (treePath: string, subPath: string = '') => {
3131
const fileTree = sidebarEl.querySelector('#view-file-tree');
32-
const apiBaseUrl = fileTree.getAttribute('data-api-base-url');
32+
const baseUrl = fileTree.getAttribute('data-api-base-url');
3333
const refTypeNameSubURL = fileTree.getAttribute('data-current-ref-type-name-sub-url');
34-
const response = await GET(`${apiBaseUrl}/tree/${refTypeNameSubURL}/${pathEscapeSegments(path ?? '')}?recursive=${recursive ?? false}`);
34+
const response = await GET(`${baseUrl}/tree/${refTypeNameSubURL}/${pathEscapeSegments(treePath)}?sub_path=${encodeURIComponent(subPath)}`);
3535
const json = await response.json();
36-
if (json instanceof Array) {
37-
return json.map((i) => ({
38-
name: i.name,
39-
type: i.type,
40-
path: i.path,
41-
sub_module_url: i.sub_module_url,
42-
children: i.children,
43-
}));
44-
}
45-
return null;
36+
return json.fileTreeNodes ?? null;
4637
};
4738
}
4839

@@ -80,7 +71,7 @@ export async function initViewFileTreeSidebar() {
8071

8172
const selectedItem = ref(getSelectedPath(refString));
8273

83-
const files = await childrenLoader(sidebarEl)(treePath, true);
74+
const files = await childrenLoader(sidebarEl)('', treePath);
8475

8576
fileTree.classList.remove('is-loading');
8677
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren: childrenLoader(sidebarEl), loadContent: (path: string) => {

0 commit comments

Comments
 (0)