From f129e0ecb57634bc02972b7ff5a3175a829c0534 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 16 Feb 2017 08:34:49 -0500 Subject: [PATCH] repo/editor: fix breadcrumb path cuts parent dirs (#3859) --- gogs.go | 2 +- routers/repo/editor.go | 47 +++++++++++++++++++------------ templates/.VERSION | 2 +- templates/repo/editor/edit.tmpl | 2 +- templates/repo/editor/upload.tmpl | 2 +- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/gogs.go b/gogs.go index 12f4cac63..2a911fdff 100644 --- a/gogs.go +++ b/gogs.go @@ -16,7 +16,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.9.150.0216" +const APP_VER = "0.9.151.0216" func init() { setting.AppVer = APP_VER diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 82a2cb8cf..22e36d966 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -29,16 +29,28 @@ const ( UPLOAD_FILE base.TplName = "repo/editor/upload" ) +// getParentTreeFields returns list of parent tree names and corresponding tree paths +// based on given tree path. +func getParentTreeFields(treePath string) (treeNames []string, treePaths []string) { + if len(treePath) == 0 { + return treeNames, treePaths + } + + treeNames = strings.Split(treePath, "/") + treePaths = make([]string, len(treeNames)) + for i := range treeNames { + treePaths[i] = strings.Join(treeNames[:i+1], "/") + } + return treeNames, treePaths +} + func editFile(ctx *context.Context, isNewFile bool) { ctx.Data["PageIsEdit"] = true ctx.Data["IsNewFile"] = isNewFile ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireSimpleMDE"] = true - var treeNames []string - if len(ctx.Repo.TreePath) > 0 { - treeNames = strings.Split(ctx.Repo.TreePath, "/") - } + treeNames, treePaths := getParentTreeFields(ctx.Repo.TreePath) if !isNewFile { entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath) @@ -88,6 +100,7 @@ func editFile(ctx *context.Context, isNewFile bool) { } ctx.Data["TreeNames"] = treeNames + ctx.Data["TreePaths"] = treePaths ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName ctx.Data["commit_summary"] = "" ctx.Data["commit_message"] = "" @@ -127,14 +140,11 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo } form.TreePath = strings.Trim(form.TreePath, " /") - - var treeNames []string - if len(form.TreePath) > 0 { - treeNames = strings.Split(form.TreePath, "/") - } + treeNames, treePaths := getParentTreeFields(form.TreePath) ctx.Data["TreePath"] = form.TreePath ctx.Data["TreeNames"] = treeNames + ctx.Data["TreePaths"] = treePaths ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + branchName ctx.Data["FileContent"] = form.Content ctx.Data["commit_summary"] = form.CommitSummary @@ -383,13 +393,14 @@ func UploadFile(ctx *context.Context) { ctx.Data["PageIsUpload"] = true renderUploadSettings(ctx) - // We must at least have one element for user to input. - treeNames := []string{""} - if len(ctx.Repo.TreePath) > 0 { - treeNames = strings.Split(ctx.Repo.TreePath, "/") + treeNames, treePaths := getParentTreeFields(ctx.Repo.TreePath) + if len(treeNames) == 0 { + // We must at least have one element for user to input. + treeNames = []string{""} } ctx.Data["TreeNames"] = treeNames + ctx.Data["TreePaths"] = treePaths ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName ctx.Data["commit_summary"] = "" ctx.Data["commit_message"] = "" @@ -411,15 +422,15 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) { } form.TreePath = strings.Trim(form.TreePath, " /") - - // We must at least have one element for user to input. - treeNames := []string{""} - if len(form.TreePath) > 0 { - treeNames = strings.Split(form.TreePath, "/") + treeNames, treePaths := getParentTreeFields(form.TreePath) + if len(treeNames) == 0 { + // We must at least have one element for user to input. + treeNames = []string{""} } ctx.Data["TreePath"] = form.TreePath ctx.Data["TreeNames"] = treeNames + ctx.Data["TreePaths"] = treePaths ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + branchName ctx.Data["commit_summary"] = form.CommitSummary ctx.Data["commit_message"] = form.CommitMessage diff --git a/templates/.VERSION b/templates/.VERSION index 43de04d06..8fcefd697 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.9.150.0216 \ No newline at end of file +0.9.151.0216 \ No newline at end of file diff --git a/templates/repo/editor/edit.tmpl b/templates/repo/editor/edit.tmpl index b189d4f29..64b09c374 100644 --- a/templates/repo/editor/edit.tmpl +++ b/templates/repo/editor/edit.tmpl @@ -18,7 +18,7 @@ {{else}} - {{$v}} + {{$v}} {{end}} {{end}} {{.i18n.Tr "repo.editor.or"}} {{.i18n.Tr "repo.editor.cancel_lower"}} diff --git a/templates/repo/editor/upload.tmpl b/templates/repo/editor/upload.tmpl index e1192ef02..23fdc8baf 100644 --- a/templates/repo/editor/upload.tmpl +++ b/templates/repo/editor/upload.tmpl @@ -17,7 +17,7 @@ {{else}} - {{$v}} + {{$v}} {{end}} {{end}} {{.i18n.Tr "repo.editor.or"}} {{.i18n.Tr "repo.editor.cancel_lower"}}