summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-08-24 21:35:03 -0700
committerUnknwon <u@gogs.io>2016-08-24 21:35:03 -0700
commitf8a48ffaad481ee9eaa8a42e0e7d64c12c90ef86 (patch)
tree21ee3e7965c77c16fcdaa209f01cebae6a809625 /routers
parent67fb0fe6a5783f772abfb5438a154435dafff4de (diff)
downloadgitea-f8a48ffaad481ee9eaa8a42e0e7d64c12c90ef86.tar.gz
gitea-f8a48ffaad481ee9eaa8a42e0e7d64c12c90ef86.zip
Web editor: improve code quality
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/file.go2
-rw-r--r--routers/repo/commit.go6
-rw-r--r--routers/repo/download.go6
-rw-r--r--routers/repo/editor.go72
-rw-r--r--routers/repo/issue.go14
-rw-r--r--routers/repo/upload.go2
-rw-r--r--routers/repo/view.go2
7 files changed, 48 insertions, 56 deletions
diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go
index 745b444ab9..972dbefac0 100644
--- a/routers/api/v1/repo/file.go
+++ b/routers/api/v1/repo/file.go
@@ -19,7 +19,7 @@ func GetRawFile(ctx *context.APIContext) {
return
}
- blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
+ blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
if err != nil {
if git.IsErrNotExist(err) {
ctx.Status(404)
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index 9cf339ecea..dca7b1f9f8 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -25,9 +25,9 @@ const (
func RefCommits(ctx *context.Context) {
switch {
- case len(ctx.Repo.TreeName) == 0:
+ case len(ctx.Repo.TreePath) == 0:
Commits(ctx)
- case ctx.Repo.TreeName == "search":
+ case ctx.Repo.TreePath == "search":
SearchCommits(ctx)
default:
FileHistory(ctx)
@@ -104,7 +104,7 @@ func SearchCommits(ctx *context.Context) {
func FileHistory(ctx *context.Context) {
ctx.Data["IsRepoToolbarCommits"] = true
- fileName := ctx.Repo.TreeName
+ fileName := ctx.Repo.TreePath
if len(fileName) == 0 {
Commits(ctx)
return
diff --git a/routers/repo/download.go b/routers/repo/download.go
index e9468aa06d..85aa76472b 100644
--- a/routers/repo/download.go
+++ b/routers/repo/download.go
@@ -25,7 +25,7 @@ func ServeData(ctx *context.Context, name string, reader io.Reader) error {
if !isTextFile {
_, isImageFile := base.IsImageFile(buf)
if !isImageFile {
- ctx.Resp.Header().Set("Content-Disposition", "attachment; filename=\""+path.Base(ctx.Repo.TreeName)+"\"")
+ ctx.Resp.Header().Set("Content-Disposition", "attachment; filename=\""+path.Base(ctx.Repo.TreePath)+"\"")
ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
}
} else if !ctx.QueryBool("render") {
@@ -42,11 +42,11 @@ func ServeBlob(ctx *context.Context, blob *git.Blob) error {
return err
}
- return ServeData(ctx, ctx.Repo.TreeName, dataRc)
+ return ServeData(ctx, ctx.Repo.TreePath, dataRc)
}
func SingleDownload(ctx *context.Context) {
- blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
+ blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
if err != nil {
if git.IsErrNotExist(err) {
ctx.Handle(404, "GetBlobByPath", nil)
diff --git a/routers/repo/editor.go b/routers/repo/editor.go
index aaacd8a807..c7ddb8a253 100644
--- a/routers/repo/editor.go
+++ b/routers/repo/editor.go
@@ -32,15 +32,14 @@ func editFile(ctx *context.Context, isNewFile bool) {
ctx.Data["RequireSimpleMDE"] = true
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName
- treeName := ctx.Repo.TreeName
var treeNames []string
- if len(treeName) > 0 {
- treeNames = strings.Split(treeName, "/")
+ if len(ctx.Repo.TreePath) > 0 {
+ treeNames = strings.Split(ctx.Repo.TreePath, "/")
}
if !isNewFile {
- entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treeName)
+ entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
if err != nil {
if git.IsErrNotExist(err) {
ctx.Handle(404, "GetTreeEntryByPath", err)
@@ -83,7 +82,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
buf = append(buf, d...)
if err, content := template.ToUTF8WithErr(buf); err != nil {
if err != nil {
- log.Error(4, "Convert content encoding: %s", err)
+ log.Error(4, "ToUTF8WithErr: %v", err)
}
ctx.Data["FileContent"] = string(buf)
} else {
@@ -93,7 +92,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
treeNames = append(treeNames, "") // Append empty string to allow user name the new file.
}
- ctx.Data["TreeName"] = treeName
+ ctx.Data["TreePath"] = ctx.Repo.TreePath
ctx.Data["TreeNames"] = treeNames
ctx.Data["BranchLink"] = branchLink
ctx.Data["commit_summary"] = ""
@@ -125,7 +124,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
oldBranchName := ctx.Repo.BranchName
branchName := oldBranchName
branchLink := ctx.Repo.RepoLink + "/src/" + branchName
- oldTreeName := ctx.Repo.TreeName
+ oldTreePath := ctx.Repo.TreePath
content := form.Content
commitChoice := form.CommitChoice
lastCommit := form.LastCommit
@@ -135,16 +134,14 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
branchName = form.NewBranchName
}
- treeName := form.TreeName
- treeName = strings.Trim(treeName, " ")
- treeName = strings.Trim(treeName, "/")
+ form.TreePath = strings.Trim(form.TreePath, " /")
var treeNames []string
- if len(treeName) > 0 {
- treeNames = strings.Split(treeName, "/")
+ if len(form.TreePath) > 0 {
+ treeNames = strings.Split(form.TreePath, "/")
}
- ctx.Data["TreeName"] = treeName
+ ctx.Data["TreePath"] = form.TreePath
ctx.Data["TreeNames"] = treeNames
ctx.Data["BranchLink"] = branchLink
ctx.Data["FileContent"] = content
@@ -162,24 +159,24 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
return
}
- if len(treeName) == 0 {
- ctx.Data["Err_Filename"] = true
+ if len(form.TreePath) == 0 {
+ ctx.Data["Err_TreePath"] = true
ctx.RenderWithErr(ctx.Tr("repo.editor.filename_cannot_be_empty"), EDIT, &form)
return
}
if oldBranchName != branchName {
if _, err := ctx.Repo.Repository.GetBranch(branchName); err == nil {
- ctx.Data["Err_Branchname"] = true
+ ctx.Data["Err_NewBranchName"] = true
ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), EDIT, &form)
return
}
}
- var treepath string
+ var newTreePath string
for index, part := range treeNames {
- treepath = path.Join(treepath, part)
- entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treepath)
+ newTreePath = path.Join(newTreePath, part)
+ entry, err := ctx.Repo.Commit.GetTreeEntryByPath(newTreePath)
if err != nil {
if git.IsErrNotExist(err) {
// Means there is no item with that name, so we're good
@@ -191,13 +188,13 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
}
if index != len(treeNames)-1 {
if !entry.IsDir() {
- ctx.Data["Err_Filename"] = true
+ ctx.Data["Err_TreePath"] = true
ctx.RenderWithErr(ctx.Tr("repo.editor.directory_is_a_file", part), EDIT, &form)
return
}
} else {
if entry.IsDir() {
- ctx.Data["Err_Filename"] = true
+ ctx.Data["Err_TreePath"] = true
ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_a_directory", part), EDIT, &form)
return
}
@@ -205,11 +202,11 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
}
if !isNewFile {
- _, err := ctx.Repo.Commit.GetTreeEntryByPath(oldTreeName)
+ _, err := ctx.Repo.Commit.GetTreeEntryByPath(oldTreePath)
if err != nil {
if git.IsErrNotExist(err) {
- ctx.Data["Err_Filename"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", oldTreeName), EDIT, &form)
+ ctx.Data["Err_TreePath"] = true
+ ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), EDIT, &form)
} else {
ctx.Handle(500, "GetTreeEntryByPath", err)
}
@@ -223,7 +220,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
}
for _, file := range files {
- if file == treeName {
+ if file == form.TreePath {
ctx.RenderWithErr(ctx.Tr("repo.editor.file_changed_while_editing", ctx.Repo.RepoLink+"/compare/"+lastCommit+"..."+ctx.Repo.CommitID), EDIT, &form)
return
}
@@ -231,9 +228,9 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
}
}
- if oldTreeName != treeName {
+ if oldTreePath != form.TreePath {
// We have a new filename (rename or completely new file) so we need to make sure it doesn't already exist, can't clobber.
- entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treeName)
+ entry, err := ctx.Repo.Commit.GetTreeEntryByPath(form.TreePath)
if err != nil {
if !git.IsErrNotExist(err) {
ctx.Handle(500, "GetTreeEntryByPath", err)
@@ -241,8 +238,8 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
}
}
if entry != nil {
- ctx.Data["Err_Filename"] = true
- ctx.RenderWithErr(ctx.Tr("repo.editor.file_already_exists", treeName), EDIT, &form)
+ ctx.Data["Err_TreePath"] = true
+ ctx.RenderWithErr(ctx.Tr("repo.editor.file_already_exists", form.TreePath), EDIT, &form)
return
}
}
@@ -252,9 +249,9 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
message = strings.TrimSpace(form.CommitSummary)
} else {
if isNewFile {
- message = ctx.Tr("repo.editor.add", treeName)
+ message = ctx.Tr("repo.editor.add", form.TreePath)
} else {
- message = ctx.Tr("repo.editor.update", treeName)
+ message = ctx.Tr("repo.editor.update", form.TreePath)
}
}
@@ -267,18 +264,18 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
LastCommitID: lastCommit,
OldBranch: oldBranchName,
NewBranch: branchName,
- OldTreeName: oldTreeName,
- NewTreeName: treeName,
+ OldTreeName: oldTreePath,
+ NewTreeName: form.TreePath,
Message: message,
Content: content,
IsNewFile: isNewFile,
}); err != nil {
- ctx.Data["Err_Filename"] = true
+ ctx.Data["Err_TreePath"] = true
ctx.RenderWithErr(ctx.Tr("repo.editor.failed_to_update_file", err), EDIT, &form)
return
}
- ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + treeName)
+ ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + form.TreePath)
}
func EditFilePost(ctx *context.Context, form auth.EditRepoFileForm) {
@@ -290,7 +287,7 @@ func NewFilePost(ctx *context.Context, form auth.EditRepoFileForm) {
}
func DiffPreviewPost(ctx *context.Context, form auth.EditPreviewDiffForm) {
- treeName := ctx.Repo.TreeName
+ treeName := ctx.Repo.TreePath
content := form.Content
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treeName)
@@ -325,7 +322,7 @@ func DiffPreviewPost(ctx *context.Context, form auth.EditPreviewDiffForm) {
func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
branchName := ctx.Repo.BranchName
- treeName := ctx.Repo.TreeName
+ treeName := ctx.Repo.TreePath
if ctx.HasError() {
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + treeName)
@@ -342,5 +339,6 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
return
}
+ ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", treeName))
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName)
}
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 2c23a7bea3..9fe9cee06d 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -331,6 +331,8 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
func NewIssue(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
ctx.Data["PageIsIssueList"] = true
+ ctx.Data["RequireHighlightJS"] = true
+ ctx.Data["RequireSimpleMDE"] = true
setTemplateIfExists(ctx, ISSUE_TEMPLATE_KEY, IssueTemplateCandidates)
renderAttachmentSettings(ctx)
@@ -339,10 +341,6 @@ func NewIssue(ctx *context.Context) {
return
}
- ctx.Data["RequireHighlightJS"] = true
- ctx.Data["RequireSimpleMDE"] = true
- ctx.Data["RepoName"] = ctx.Repo.Repository.Name
-
ctx.HTML(200, ISSUE_NEW)
}
@@ -403,7 +401,6 @@ func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm) ([]int64
func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
ctx.Data["PageIsIssueList"] = true
- ctx.Data["RepoName"] = ctx.Repo.Repository.Name
ctx.Data["RequireHighlightJS"] = true
ctx.Data["RequireSimpleMDE"] = true
renderAttachmentSettings(ctx)
@@ -493,6 +490,8 @@ func UploadIssueAttachment(ctx *context.Context) {
}
func ViewIssue(ctx *context.Context) {
+ ctx.Data["RequireHighlightJS"] = true
+ ctx.Data["RequireSimpleMDE"] = true
ctx.Data["RequireDropzone"] = true
renderAttachmentSettings(ctx)
@@ -637,11 +636,6 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["Issue"] = issue
ctx.Data["IsIssueOwner"] = ctx.Repo.IsWriter() || (ctx.IsSigned && issue.IsPoster(ctx.User.ID))
ctx.Data["SignInLink"] = setting.AppSubUrl + "/user/login?redirect_to=" + ctx.Data["Link"].(string)
-
- ctx.Data["RequireHighlightJS"] = true
- ctx.Data["RequireSimpleMDE"] = true
- ctx.Data["RepoName"] = ctx.Repo.Repository.Name
-
ctx.HTML(200, ISSUE_VIEW)
}
diff --git a/routers/repo/upload.go b/routers/repo/upload.go
index c77bdce81a..5e0f91668f 100644
--- a/routers/repo/upload.go
+++ b/routers/repo/upload.go
@@ -39,7 +39,7 @@ func UploadFile(ctx *context.Context) {
repoName := ctx.Repo.Repository.Name
branchName := ctx.Repo.BranchName
branchLink := ctx.Repo.RepoLink + "/src/" + branchName
- treeName := ctx.Repo.TreeName
+ treeName := ctx.Repo.TreePath
treeNames := []string{""}
if len(treeName) > 0 {
diff --git a/routers/repo/view.go b/routers/repo/view.go
index c7e0003a35..173797cff5 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -56,7 +56,7 @@ func Home(ctx *context.Context) {
uploadFileLink := ctx.Repo.RepoLink + "/upload/" + branchName
// Get tree path
- treename := ctx.Repo.TreeName
+ treename := ctx.Repo.TreePath
if len(treename) > 0 {
if treename[len(treename)-1] == '/' {