|
|
@ -40,6 +40,21 @@ func renderCommitRights(ctx *context.Context) bool { |
|
|
|
return canCommit |
|
|
|
return canCommit |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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) { |
|
|
|
func editFile(ctx *context.Context, isNewFile bool) { |
|
|
|
ctx.Data["PageIsEdit"] = true |
|
|
|
ctx.Data["PageIsEdit"] = true |
|
|
|
ctx.Data["IsNewFile"] = isNewFile |
|
|
|
ctx.Data["IsNewFile"] = isNewFile |
|
|
@ -47,10 +62,7 @@ func editFile(ctx *context.Context, isNewFile bool) { |
|
|
|
ctx.Data["RequireSimpleMDE"] = true |
|
|
|
ctx.Data["RequireSimpleMDE"] = true |
|
|
|
canCommit := renderCommitRights(ctx) |
|
|
|
canCommit := renderCommitRights(ctx) |
|
|
|
|
|
|
|
|
|
|
|
var treeNames []string |
|
|
|
treeNames, treePaths := getParentTreeFields(ctx.Repo.TreePath) |
|
|
|
if len(ctx.Repo.TreePath) > 0 { |
|
|
|
|
|
|
|
treeNames = strings.Split(ctx.Repo.TreePath, "/") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !isNewFile { |
|
|
|
if !isNewFile { |
|
|
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath) |
|
|
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath) |
|
|
@ -100,6 +112,7 @@ func editFile(ctx *context.Context, isNewFile bool) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["TreeNames"] = treeNames |
|
|
|
ctx.Data["TreeNames"] = treeNames |
|
|
|
|
|
|
|
ctx.Data["TreePaths"] = treePaths |
|
|
|
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName |
|
|
|
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName |
|
|
|
ctx.Data["commit_summary"] = "" |
|
|
|
ctx.Data["commit_summary"] = "" |
|
|
|
ctx.Data["commit_message"] = "" |
|
|
|
ctx.Data["commit_message"] = "" |
|
|
@ -146,14 +159,11 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
form.TreePath = strings.Trim(form.TreePath, " /") |
|
|
|
form.TreePath = strings.Trim(form.TreePath, " /") |
|
|
|
|
|
|
|
treeNames, treePaths := getParentTreeFields(form.TreePath) |
|
|
|
var treeNames []string |
|
|
|
|
|
|
|
if len(form.TreePath) > 0 { |
|
|
|
|
|
|
|
treeNames = strings.Split(form.TreePath, "/") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["TreePath"] = form.TreePath |
|
|
|
ctx.Data["TreePath"] = form.TreePath |
|
|
|
ctx.Data["TreeNames"] = treeNames |
|
|
|
ctx.Data["TreeNames"] = treeNames |
|
|
|
|
|
|
|
ctx.Data["TreePaths"] = treePaths |
|
|
|
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + branchName |
|
|
|
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + branchName |
|
|
|
ctx.Data["FileContent"] = form.Content |
|
|
|
ctx.Data["FileContent"] = form.Content |
|
|
|
ctx.Data["commit_summary"] = form.CommitSummary |
|
|
|
ctx.Data["commit_summary"] = form.CommitSummary |
|
|
@ -428,13 +438,14 @@ func UploadFile(ctx *context.Context) { |
|
|
|
renderUploadSettings(ctx) |
|
|
|
renderUploadSettings(ctx) |
|
|
|
canCommit := renderCommitRights(ctx) |
|
|
|
canCommit := renderCommitRights(ctx) |
|
|
|
|
|
|
|
|
|
|
|
// We must at least have one element for user to input.
|
|
|
|
treeNames, treePaths := getParentTreeFields(ctx.Repo.TreePath) |
|
|
|
treeNames := []string{""} |
|
|
|
if len(treeNames) == 0 { |
|
|
|
if len(ctx.Repo.TreePath) > 0 { |
|
|
|
// We must at least have one element for user to input.
|
|
|
|
treeNames = strings.Split(ctx.Repo.TreePath, "/") |
|
|
|
treeNames = []string{""} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["TreeNames"] = treeNames |
|
|
|
ctx.Data["TreeNames"] = treeNames |
|
|
|
|
|
|
|
ctx.Data["TreePaths"] = treePaths |
|
|
|
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName |
|
|
|
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName |
|
|
|
ctx.Data["commit_summary"] = "" |
|
|
|
ctx.Data["commit_summary"] = "" |
|
|
|
ctx.Data["commit_message"] = "" |
|
|
|
ctx.Data["commit_message"] = "" |
|
|
@ -462,15 +473,15 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
form.TreePath = strings.Trim(form.TreePath, " /") |
|
|
|
form.TreePath = strings.Trim(form.TreePath, " /") |
|
|
|
|
|
|
|
treeNames, treePaths := getParentTreeFields(form.TreePath) |
|
|
|
// We must at least have one element for user to input.
|
|
|
|
if len(treeNames) == 0 { |
|
|
|
treeNames := []string{""} |
|
|
|
// We must at least have one element for user to input.
|
|
|
|
if len(form.TreePath) > 0 { |
|
|
|
treeNames = []string{""} |
|
|
|
treeNames = strings.Split(form.TreePath, "/") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["TreePath"] = form.TreePath |
|
|
|
ctx.Data["TreePath"] = form.TreePath |
|
|
|
ctx.Data["TreeNames"] = treeNames |
|
|
|
ctx.Data["TreeNames"] = treeNames |
|
|
|
|
|
|
|
ctx.Data["TreePaths"] = treePaths |
|
|
|
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + branchName |
|
|
|
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + branchName |
|
|
|
ctx.Data["commit_summary"] = form.CommitSummary |
|
|
|
ctx.Data["commit_summary"] = form.CommitSummary |
|
|
|
ctx.Data["commit_message"] = form.CommitMessage |
|
|
|
ctx.Data["commit_message"] = form.CommitMessage |
|
|
|