1
1
mirror of https://github.com/go-gitea/gitea synced 2025-12-07 13:28:25 +00:00

add tree sidebar to file view

This commit is contained in:
Kerwin Bryant
2024-12-12 15:20:28 +00:00
parent 22bf2ca6ba
commit 181645f4ed
12 changed files with 436 additions and 3 deletions
+5
View File
@@ -46,6 +46,11 @@ func RefBlame(ctx *context.Context) {
return
}
// ctx.Data["RepoPreferences"] = ctx.Session.Get("repoPreferences")
ctx.Data["RepoPreferences"] = &preferencesForm{
ShowFileViewTreeSidebar: true,
}
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
treeLink := branchLink
rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL()
+45
View File
@@ -0,0 +1,45 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Copyright 2018 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repo
import (
"net/http"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/services/context"
files_service "code.gitea.io/gitea/services/repository/files"
)
// canReadFiles returns true if repository is readable and user has proper access level.
func canReadFiles(r *context.Repository) bool {
return r.Permission.CanRead(unit.TypeCode)
}
// GetContents Get the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir
func GetContents(ctx *context.Context) {
if !canReadFiles(ctx.Repo) {
ctx.NotFound("Invalid FilePath", nil)
return
}
treePath := ctx.PathParam("*")
ref := ctx.FormTrim("ref")
if fileList, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref); err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound("GetContentsOrList", err)
return
}
ctx.ServerError("Repo.GitRepo.GetCommit", err)
} else {
ctx.JSON(http.StatusOK, fileList)
}
}
// GetContentsList Get the metadata of all the entries of the root dir
func GetContentsList(ctx *context.Context) {
GetContents(ctx)
}
+18
View File
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -758,3 +759,20 @@ func PrepareBranchList(ctx *context.Context) {
}
ctx.Data["Branches"] = brs
}
type preferencesForm struct {
ShowFileViewTreeSidebar bool `json:"show_file_view_tree_sidebar"`
}
func UpdatePreferences(ctx *context.Context) {
form := &preferencesForm{}
if err := json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil {
ctx.ServerError("DecodePreferencesForm", err)
return
}
// if err := ctx.Session.Set("repoPreferences", form); err != nil {
// ctx.ServerError("Session.Set", err)
// return
// }
ctx.JSONOK()
}
+5
View File
@@ -305,6 +305,11 @@ func Home(ctx *context.Context) {
return
}
// ctx.Data["RepoPreferences"] = ctx.Session.Get("repoPreferences")
ctx.Data["RepoPreferences"] = &preferencesForm{
ShowFileViewTreeSidebar: true,
}
title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name
if len(ctx.Repo.Repository.Description) > 0 {
title += ": " + ctx.Repo.Repository.Description
+5
View File
@@ -987,6 +987,7 @@ func registerRoutes(m *web.Router) {
m.Get("/migrate", repo.Migrate)
m.Post("/migrate", web.Bind(forms.MigrateRepoForm{}), repo.MigratePost)
m.Get("/search", repo.SearchRepo)
m.Put("/preferences", repo.UpdatePreferences)
}, reqSignIn)
// end "/repo": create, migrate, search
@@ -1161,6 +1162,10 @@ func registerRoutes(m *web.Router) {
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.TreeList)
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.TreeList)
})
m.Group("/contents", func() {
m.Get("", repo.GetContentsList)
m.Get("/*", repo.GetContents)
})
m.Get("/compare", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
m.Combo("/compare/*", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists).
Get(repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff).