From 314193029a246c2498c6d54c085d57f7589c8dbe Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 22 Jun 2014 23:11:12 -0400 Subject: [PATCH] Use constants to name template file --- gogs.go | 2 +- routers/repo/branch.go | 11 ++- routers/repo/commit.go | 92 ++++++++++--------- routers/repo/issue.go | 34 +++++-- routers/repo/pull.go | 7 +- routers/repo/release.go | 19 +++- routers/repo/repo.go | 30 +++--- routers/repo/setting.go | 67 ++++++++------ routers/user/home.go | 18 +++- routers/user/setting.go | 25 +++-- routers/user/user.go | 53 ++++++----- templates/VERSION | 2 +- templates/repo/{branches.tmpl => branch.tmpl} | 0 .../repo/{hooks_add.tmpl => hook_add.tmpl} | 0 .../repo/{hooks_edit.tmpl => hook_edit.tmpl} | 0 templates/user/{issue.tmpl => issues.tmpl} | 0 16 files changed, 226 insertions(+), 134 deletions(-) rename templates/repo/{branches.tmpl => branch.tmpl} (100%) rename templates/repo/{hooks_add.tmpl => hook_add.tmpl} (100%) rename templates/repo/{hooks_edit.tmpl => hook_edit.tmpl} (100%) rename templates/user/{issue.tmpl => issues.tmpl} (100%) diff --git a/gogs.go b/gogs.go index 7719ee0af..03c286016 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.4.5.0621 Alpha" +const APP_VER = "0.4.5.0622 Alpha" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 2e2ae6925..9bad7289b 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -7,22 +7,27 @@ package repo import ( "github.com/go-martini/martini" + "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" ) +const ( + BRANCH base.TplName = "repo/branch" +) + func Branches(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Branches" ctx.Data["IsRepoToolbarBranches"] = true brs, err := ctx.Repo.GitRepo.GetBranches() if err != nil { - ctx.Handle(500, "repo.Branches", err) + ctx.Handle(500, "repo.Branches(GetBranches)", err) return } else if len(brs) == 0 { - ctx.Handle(404, "repo.Branches", nil) + ctx.Handle(404, "repo.Branches(GetBranches)", nil) return } ctx.Data["Branches"] = brs - ctx.HTML(200, "repo/branches") + ctx.HTML(200, BRANCH) } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 09dcaf5ea..aa5c22e41 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -14,6 +14,11 @@ import ( "github.com/gogits/gogs/modules/middleware" ) +const ( + COMMITS base.TplName = "repo/commits" + DIFF base.TplName = "repo/diff" +) + func Commits(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarCommits"] = true @@ -22,10 +27,10 @@ func Commits(ctx *middleware.Context, params martini.Params) { brs, err := ctx.Repo.GitRepo.GetBranches() if err != nil { - ctx.Handle(500, "repo.Commits", err) + ctx.Handle(500, "repo.Commits(GetBranches)", err) return } else if len(brs) == 0 { - ctx.Handle(404, "repo.Commits", nil) + ctx.Handle(404, "repo.Commits(GetBranches)", nil) return } @@ -61,7 +66,43 @@ func Commits(ctx *middleware.Context, params martini.Params) { ctx.Data["CommitCount"] = commitsCount ctx.Data["LastPageNum"] = lastPage ctx.Data["NextPageNum"] = nextPage - ctx.HTML(200, "repo/commits") + ctx.HTML(200, COMMITS) +} + +func SearchCommits(ctx *middleware.Context, params martini.Params) { + ctx.Data["IsSearchPage"] = true + ctx.Data["IsRepoToolbarCommits"] = true + + keyword := ctx.Query("q") + if len(keyword) == 0 { + ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName) + return + } + + userName := params["username"] + repoName := params["reponame"] + + brs, err := ctx.Repo.GitRepo.GetBranches() + if err != nil { + ctx.Handle(500, "repo.SearchCommits(GetBranches)", err) + return + } else if len(brs) == 0 { + ctx.Handle(404, "repo.SearchCommits(GetBranches)", nil) + return + } + + commits, err := ctx.Repo.Commit.SearchCommits(keyword) + if err != nil { + ctx.Handle(500, "repo.SearchCommits(SearchCommits)", err) + return + } + + ctx.Data["Keyword"] = keyword + ctx.Data["Username"] = userName + ctx.Data["Reponame"] = repoName + ctx.Data["CommitCount"] = commits.Len() + ctx.Data["Commits"] = commits + ctx.HTML(200, COMMITS) } func Diff(ctx *middleware.Context, params martini.Params) { @@ -75,7 +116,7 @@ func Diff(ctx *middleware.Context, params martini.Params) { diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId) if err != nil { - ctx.Handle(404, "repo.Diff", err) + ctx.Handle(404, "repo.Diff(GetDiff)", err) return } @@ -119,43 +160,7 @@ func Diff(ctx *middleware.Context, params martini.Params) { ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId) ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId) - ctx.HTML(200, "repo/diff") -} - -func SearchCommits(ctx *middleware.Context, params martini.Params) { - ctx.Data["IsSearchPage"] = true - ctx.Data["IsRepoToolbarCommits"] = true - - keyword := ctx.Query("q") - if len(keyword) == 0 { - ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName) - return - } - - userName := params["username"] - repoName := params["reponame"] - - brs, err := ctx.Repo.GitRepo.GetBranches() - if err != nil { - ctx.Handle(500, "repo.SearchCommits(GetBranches)", err) - return - } else if len(brs) == 0 { - ctx.Handle(404, "repo.SearchCommits(GetBranches)", nil) - return - } - - commits, err := ctx.Repo.Commit.SearchCommits(keyword) - if err != nil { - ctx.Handle(500, "repo.SearchCommits(SearchCommits)", err) - return - } - - ctx.Data["Keyword"] = keyword - ctx.Data["Username"] = userName - ctx.Data["Reponame"] = repoName - ctx.Data["CommitCount"] = commits.Len() - ctx.Data["Commits"] = commits - ctx.HTML(200, "repo/commits") + ctx.HTML(200, DIFF) } func FileHistory(ctx *middleware.Context, params martini.Params) { @@ -184,8 +189,7 @@ func FileHistory(ctx *middleware.Context, params martini.Params) { if err != nil { ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err) return - } - if commitsCount == 0 { + } else if commitsCount == 0 { ctx.Handle(404, "repo.FileHistory", nil) return } @@ -217,5 +221,5 @@ func FileHistory(ctx *middleware.Context, params martini.Params) { ctx.Data["CommitCount"] = commitsCount ctx.Data["LastPageNum"] = lastPage ctx.Data["NextPageNum"] = nextPage - ctx.HTML(200, "repo/commits") + ctx.HTML(200, COMMITS) } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 11c573f5c..cf454bc8f 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -22,6 +22,16 @@ import ( "github.com/gogits/gogs/modules/setting" ) +const ( + ISSUES base.TplName = "repo/issue/list" + ISSUE_CREATE base.TplName = "repo/issue/create" + ISSUE_VIEW base.TplName = "repo/issue/view" + + MILESTONE base.TplName = "repo/issue/milestone" + MILESTONE_NEW base.TplName = "repo/issue/milestone_new" + MILESTONE_EDIT base.TplName = "repo/issue/milestone_edit" +) + func Issues(ctx *middleware.Context) { ctx.Data["Title"] = "Issues" ctx.Data["IsRepoToolbarIssues"] = true @@ -134,7 +144,7 @@ func Issues(ctx *middleware.Context) { } else { ctx.Data["ShowCount"] = issueStats.OpenCount } - ctx.HTML(200, "issue/list") + ctx.HTML(200, ISSUES) } func CreateIssue(ctx *middleware.Context, params martini.Params) { @@ -161,7 +171,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) { return } ctx.Data["Collaborators"] = us - ctx.HTML(200, "issue/create") + ctx.HTML(200, ISSUE_CREATE) } func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { @@ -190,7 +200,7 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C ctx.Data["Collaborators"] = us if ctx.HasError() { - ctx.HTML(200, "issue/create") + ctx.HTML(200, ISSUE_CREATE) return } @@ -392,7 +402,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { ctx.Data["IsIssueOwner"] = ctx.Repo.IsOwner || (ctx.IsSigned && issue.PosterId == ctx.User.Id) ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false - ctx.HTML(200, "issue/view") + ctx.HTML(200, ISSUE_VIEW) } func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { @@ -794,14 +804,14 @@ func Milestones(ctx *middleware.Context) { } else { ctx.Data["State"] = "open" } - ctx.HTML(200, "issue/milestone") + ctx.HTML(200, MILESTONE) } func NewMilestone(ctx *middleware.Context) { ctx.Data["Title"] = "New Milestone" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true - ctx.HTML(200, "issue/milestone_new") + ctx.HTML(200, MILESTONE_NEW) } func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) { @@ -809,6 +819,11 @@ func NewMilestonePost(ctx *middleware.Context, form auth.CreateMilestoneForm) { ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true + if ctx.HasError() { + ctx.HTML(200, MILESTONE_NEW) + return + } + var deadline time.Time var err error if len(form.Deadline) == 0 { @@ -890,7 +905,7 @@ func UpdateMilestone(ctx *middleware.Context, params martini.Params) { } ctx.Data["Milestone"] = mile - ctx.HTML(200, "issue/milestone_edit") + ctx.HTML(200, MILESTONE_EDIT) } func UpdateMilestonePost(ctx *middleware.Context, params martini.Params, form auth.CreateMilestoneForm) { @@ -914,6 +929,11 @@ func UpdateMilestonePost(ctx *middleware.Context, params martini.Params, form au return } + if ctx.HasError() { + ctx.HTML(200, MILESTONE_EDIT) + return + } + var deadline time.Time if len(form.Deadline) == 0 { form.Deadline = "12/31/9999" diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 430c6a815..db208f9fb 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -7,10 +7,15 @@ package repo import ( "github.com/go-martini/martini" + "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" ) +const ( + PULLS base.TplName = "repo/pulls" +) + func Pulls(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarPulls"] = true - ctx.HTML(200, "repo/pulls") + ctx.HTML(200, PULLS) } diff --git a/routers/repo/release.go b/routers/repo/release.go index b6149b63a..a901436fc 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -14,6 +14,12 @@ import ( "github.com/gogits/gogs/modules/middleware" ) +const ( + RELEASES base.TplName = "repo/release/list" + RELEASE_NEW base.TplName = "repo/release/new" + RELEASE_EDIT base.TplName = "repo/release/edit" +) + func Releases(ctx *middleware.Context) { ctx.Data["Title"] = "Releases" ctx.Data["IsRepoToolbarReleases"] = true @@ -100,7 +106,7 @@ func Releases(ctx *middleware.Context) { } models.SortReleases(tags) ctx.Data["Releases"] = tags - ctx.HTML(200, "release/list") + ctx.HTML(200, RELEASES) } func NewRelease(ctx *middleware.Context) { @@ -112,7 +118,7 @@ func NewRelease(ctx *middleware.Context) { ctx.Data["Title"] = "New Release" ctx.Data["IsRepoToolbarReleases"] = true ctx.Data["IsRepoReleaseNew"] = true - ctx.HTML(200, "release/new") + ctx.HTML(200, RELEASE_NEW) } func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) { @@ -126,7 +132,7 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) { ctx.Data["IsRepoReleaseNew"] = true if ctx.HasError() { - ctx.HTML(200, "release/new") + ctx.HTML(200, RELEASE_NEW) return } @@ -187,7 +193,7 @@ func EditRelease(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Edit Release" ctx.Data["IsRepoToolbarReleases"] = true - ctx.HTML(200, "release/edit") + ctx.HTML(200, RELEASE_EDIT) } func EditReleasePost(ctx *middleware.Context, params martini.Params, form auth.EditReleaseForm) { @@ -208,6 +214,11 @@ func EditReleasePost(ctx *middleware.Context, params martini.Params, form auth.E } ctx.Data["Release"] = rel + if ctx.HasError() { + ctx.HTML(200, RELEASE_EDIT) + return + } + ctx.Data["Title"] = "Edit Release" ctx.Data["IsRepoToolbarReleases"] = true diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 6154eede3..2ead24df3 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -25,12 +25,18 @@ import ( "github.com/gogits/gogs/modules/middleware" ) +const ( + CREATE base.TplName = "repo/create" + MIGRATE base.TplName = "repo/migrate" + SINGLE base.TplName = "repo/single" +) + func Create(ctx *middleware.Context) { ctx.Data["Title"] = "Create repository" ctx.Data["PageIsNewRepo"] = true ctx.Data["LanguageIgns"] = models.LanguageIgns ctx.Data["Licenses"] = models.Licenses - ctx.HTML(200, "repo/create") + ctx.HTML(200, CREATE) } func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { @@ -40,7 +46,7 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.Data["Licenses"] = models.Licenses if ctx.HasError() { - ctx.HTML(200, "repo/create") + ctx.HTML(200, CREATE) return } @@ -51,25 +57,25 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { - ctx.RenderWithErr("Repository name has already been used", "repo/create", &form) + ctx.RenderWithErr("Repository name has already been used", CREATE, &form) return } else if err == models.ErrRepoNameIllegal { - ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/create", &form) + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), CREATE, &form) return } if repo != nil { if errDelete := models.DeleteRepository(ctx.User.Id, repo.Id, ctx.User.Name); errDelete != nil { - log.Error("repo.MigratePost(CreatePost): %v", errDelete) + log.Error("repo.CreatePost(DeleteRepository): %v", errDelete) } } - ctx.Handle(500, "repo.Create", err) + ctx.Handle(500, "repo.CreatePost", err) } func Migrate(ctx *middleware.Context) { ctx.Data["Title"] = "Migrate repository" ctx.Data["PageIsNewRepo"] = true - ctx.HTML(200, "repo/migrate") + ctx.HTML(200, MIGRATE) } func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { @@ -77,7 +83,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { ctx.Data["PageIsNewRepo"] = true if ctx.HasError() { - ctx.HTML(200, "repo/migrate") + ctx.HTML(200, MIGRATE) return } @@ -91,10 +97,10 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName) return } else if err == models.ErrRepoAlreadyExist { - ctx.RenderWithErr("Repository name has already been used", "repo/migrate", &form) + ctx.RenderWithErr("Repository name has already been used", MIGRATE, &form) return } else if err == models.ErrRepoNameIllegal { - ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/migrate", &form) + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), MIGRATE, &form) return } @@ -105,7 +111,7 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { } if strings.Contains(err.Error(), "Authentication failed") { - ctx.RenderWithErr(err.Error(), "repo/migrate", &form) + ctx.RenderWithErr(err.Error(), MIGRATE, &form) return } ctx.Handle(500, "repo.Migrate", err) @@ -291,7 +297,7 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Data["Treenames"] = treenames ctx.Data["TreePath"] = treePath ctx.Data["BranchLink"] = branchLink - ctx.HTML(200, "repo/single") + ctx.HTML(200, SINGLE) } func basicEncode(username, password string) string { diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 6313971c2..6479cb304 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -20,10 +20,19 @@ import ( "github.com/gogits/gogs/modules/setting" ) +const ( + SETTING base.TplName = "repo/setting" + COLLABORATION base.TplName = "repo/collaboration" + + HOOKS base.TplName = "repo/hooks" + HOOK_ADD base.TplName = "repo/hook_add" + HOOK_EDIT base.TplName = "repo/hook_edit" +) + func Setting(ctx *middleware.Context) { ctx.Data["IsRepoToolbarSetting"] = true ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - settings" - ctx.HTML(200, "repo/setting") + ctx.HTML(200, SETTING) } func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) { @@ -32,7 +41,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) { switch ctx.Query("action") { case "update": if ctx.HasError() { - ctx.HTML(200, "repo/setting") + ctx.HTML(200, SETTING) return } @@ -44,7 +53,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) { ctx.Handle(500, "setting.SettingPost(update: check existence)", err) return } else if isExist { - ctx.RenderWithErr("Repository name has been taken in your repositories.", "repo/setting", nil) + ctx.RenderWithErr("Repository name has been taken in your repositories.", SETTING, nil) return } else if err = models.ChangeRepositoryName(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newRepoName); err != nil { ctx.Handle(500, "setting.SettingPost(change repository name)", err) @@ -84,7 +93,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) { ctx.Redirect(fmt.Sprintf("/%s/%s/settings", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)) case "transfer": if len(ctx.Repo.Repository.Name) == 0 || ctx.Repo.Repository.Name != ctx.Query("repository") { - ctx.RenderWithErr("Please make sure you entered repository name is correct.", "repo/setting", nil) + ctx.RenderWithErr("Please make sure you entered repository name is correct.", SETTING, nil) return } else if ctx.Repo.Repository.IsMirror { ctx.Error(404) @@ -98,7 +107,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) { ctx.Handle(500, "setting.SettingPost(transfer: check existence)", err) return } else if !isExist { - ctx.RenderWithErr("Please make sure you entered owner name is correct.", "repo/setting", nil) + ctx.RenderWithErr("Please make sure you entered owner name is correct.", SETTING, nil) return } else if err = models.TransferOwnership(ctx.User, newOwner, ctx.Repo.Repository); err != nil { ctx.Handle(500, "setting.SettingPost(transfer repository)", err) @@ -109,7 +118,7 @@ func SettingPost(ctx *middleware.Context, form auth.RepoSettingForm) { ctx.Redirect("/") case "delete": if len(ctx.Repo.Repository.Name) == 0 || ctx.Repo.Repository.Name != ctx.Query("repository") { - ctx.RenderWithErr("Please make sure you entered repository name is correct.", "repo/setting", nil) + ctx.RenderWithErr("Please make sure you entered repository name is correct.", SETTING, nil) return } @@ -156,7 +165,7 @@ func Collaboration(ctx *middleware.Context) { } ctx.Data["Collaborators"] = us - ctx.HTML(200, "repo/collaboration") + ctx.HTML(200, COLLABORATION) } func CollaborationPost(ctx *middleware.Context) { @@ -226,13 +235,13 @@ func WebHooks(ctx *middleware.Context) { } ctx.Data["Webhooks"] = ws - ctx.HTML(200, "repo/hooks") + ctx.HTML(200, HOOKS) } func WebHooksAdd(ctx *middleware.Context) { ctx.Data["IsRepoToolbarWebHooks"] = true ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Add Webhook" - ctx.HTML(200, "repo/hooks_add") + ctx.HTML(200, HOOK_ADD) } func WebHooksAddPost(ctx *middleware.Context, form auth.NewWebhookForm) { @@ -240,7 +249,7 @@ func WebHooksAddPost(ctx *middleware.Context, form auth.NewWebhookForm) { ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Add Webhook" if ctx.HasError() { - ctx.HTML(200, "repo/hooks_add") + ctx.HTML(200, HOOK_ADD) return } @@ -293,40 +302,46 @@ func WebHooksEdit(ctx *middleware.Context, params martini.Params) { w.GetEvent() ctx.Data["Webhook"] = w - ctx.HTML(200, "repo/hooks_edit") + ctx.HTML(200, HOOK_EDIT) } func WebHooksEditPost(ctx *middleware.Context, params martini.Params, form auth.NewWebhookForm) { ctx.Data["IsRepoToolbarWebHooks"] = true ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Webhook" - if ctx.HasError() { - ctx.HTML(200, "repo/hooks_add") - return - } - hookId, _ := base.StrTo(params["id"]).Int64() if hookId == 0 { ctx.Handle(404, "setting.WebHooksEditPost", nil) return } + w, err := models.GetWebhookById(hookId) + if err != nil { + if err == models.ErrWebhookNotExist { + ctx.Handle(404, "setting.WebHooksEditPost(GetWebhookById)", nil) + } else { + ctx.Handle(500, "setting.WebHooksEditPost(GetWebhookById)", err) + } + return + } + + if ctx.HasError() { + ctx.HTML(200, HOOK_EDIT) + return + } + ct := models.JSON if form.ContentType == "2" { ct = models.FORM } - w := &models.Webhook{ - Id: hookId, - RepoId: ctx.Repo.Repository.Id, - Url: form.Url, - ContentType: ct, - Secret: form.Secret, - HookEvent: &models.HookEvent{ - PushOnly: form.PushOnly, - }, - IsActive: form.Active, + w.Url = form.Url + w.ContentType = ct + w.Secret = form.Secret + w.HookEvent = &models.HookEvent{ + PushOnly: form.PushOnly, } + w.IsActive = form.Active if err := w.UpdateEvent(); err != nil { ctx.Handle(500, "setting.WebHooksEditPost(UpdateEvent)", err) return diff --git a/routers/user/home.go b/routers/user/home.go index a9674ac24..7d0333cb4 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -17,6 +17,14 @@ import ( "github.com/gogits/gogs/modules/middleware" ) +const ( + DASHBOARD base.TplName = "user/dashboard" + PROFILE base.TplName = "user/profile" + ISSUES base.TplName = "user/issue" + PULLS base.TplName = "user/pulls" + STARS base.TplName = "user/stars" +) + func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = "Dashboard" ctx.Data["PageIsUserDashboard"] = true @@ -52,7 +60,7 @@ func Dashboard(ctx *middleware.Context) { feeds = append(feeds, act) } ctx.Data["Feeds"] = feeds - ctx.HTML(200, "user/dashboard") + ctx.HTML(200, DASHBOARD) } func Profile(ctx *middleware.Context, params martini.Params) { @@ -87,7 +95,7 @@ func Profile(ctx *middleware.Context, params martini.Params) { } } - ctx.HTML(200, "user/profile") + ctx.HTML(200, PROFILE) } func Email2User(ctx *middleware.Context) { @@ -254,13 +262,13 @@ func Issues(ctx *middleware.Context) { } else { ctx.Data["ShowCount"] = issueStats.OpenCount } - ctx.HTML(200, "user/issue") + ctx.HTML(200, ISSUES) } func Pulls(ctx *middleware.Context) { - ctx.HTML(200, "user/pulls") + ctx.HTML(200, PULLS) } func Stars(ctx *middleware.Context) { - ctx.HTML(200, "user/stars") + ctx.HTML(200, STARS) } diff --git a/routers/user/setting.go b/routers/user/setting.go index 1fae516a4..9075ee0b4 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -14,12 +14,21 @@ import ( "github.com/gogits/gogs/modules/middleware" ) +const ( + SETTING base.TplName = "user/setting" + SOCIAL base.TplName = "user/social" + PASSWORD base.TplName = "user/password" + PUBLICKEY base.TplName = "user/publickey" + NOTIFICATION base.TplName = "user/notification" + SECURITY base.TplName = "user/security" +) + func Setting(ctx *middleware.Context) { ctx.Data["Title"] = "Setting" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSetting"] = true ctx.Data["Owner"] = ctx.User - ctx.HTML(200, "user/setting") + ctx.HTML(200, SETTING) } func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) { @@ -28,7 +37,7 @@ func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) { ctx.Data["IsUserPageSetting"] = true if ctx.HasError() { - ctx.HTML(200, "user/setting") + ctx.HTML(200, SETTING) return } @@ -90,14 +99,14 @@ func SettingSocial(ctx *middleware.Context) { ctx.Handle(500, "user.SettingSocial(GetOauthByUserId)", err) return } - ctx.HTML(200, "user/social") + ctx.HTML(200, SOCIAL) } func SettingPassword(ctx *middleware.Context) { ctx.Data["Title"] = "Password" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingPasswd"] = true - ctx.HTML(200, "user/password") + ctx.HTML(200, PASSWORD) } func SettingPasswordPost(ctx *middleware.Context, form auth.UpdatePasswdForm) { @@ -106,7 +115,7 @@ func SettingPasswordPost(ctx *middleware.Context, form auth.UpdatePasswdForm) { ctx.Data["IsUserPageSettingPasswd"] = true if ctx.HasError() { - ctx.HTML(200, "user/password") + ctx.HTML(200, PASSWORD) return } @@ -207,7 +216,7 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) { } } - ctx.HTML(200, "user/publickey") + ctx.HTML(200, PUBLICKEY) } func SettingNotification(ctx *middleware.Context) { @@ -215,7 +224,7 @@ func SettingNotification(ctx *middleware.Context) { ctx.Data["Title"] = "Notification" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingNotify"] = true - ctx.HTML(200, "user/notification") + ctx.HTML(200, NOTIFICATION) } func SettingSecurity(ctx *middleware.Context) { @@ -223,5 +232,5 @@ func SettingSecurity(ctx *middleware.Context) { ctx.Data["Title"] = "Security" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingSecurity"] = true - ctx.HTML(200, "user/security") + ctx.HTML(200, SECURITY) } diff --git a/routers/user/user.go b/routers/user/user.go index 8fcbeb6a4..8144730e0 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -17,12 +17,21 @@ import ( "github.com/gogits/gogs/modules/setting" ) +const ( + SIGNIN base.TplName = "user/signin" + SIGNUP base.TplName = "user/signup" + DELETE base.TplName = "user/delete" + ACTIVATE base.TplName = "user/activate" + FORGOT_PASSWORD base.TplName = "user/forgot_passwd" + RESET_PASSWORD base.TplName = "user/reset_passwd" +) + func SignIn(ctx *middleware.Context) { ctx.Data["Title"] = "Log In" if _, ok := ctx.Session.Get("socialId").(int64); ok { ctx.Data["IsSocialLogin"] = true - ctx.HTML(200, "user/signin") + ctx.HTML(200, SIGNIN) return } @@ -34,7 +43,7 @@ func SignIn(ctx *middleware.Context) { // Check auto-login. uname := ctx.GetCookie(setting.CookieUserName) if len(uname) == 0 { - ctx.HTML(200, "user/signin") + ctx.HTML(200, SIGNIN) return } @@ -57,7 +66,7 @@ func SignIn(ctx *middleware.Context) { secret := base.EncodeMd5(user.Rands + user.Passwd) value, _ := ctx.GetSecureCookie(secret, setting.CookieRememberName) if value != user.Name { - ctx.HTML(200, "user/signin") + ctx.HTML(200, SIGNIN) return } @@ -86,7 +95,7 @@ func SignInPost(ctx *middleware.Context, form auth.LogInForm) { } if ctx.HasError() { - ctx.HTML(200, "user/signin") + ctx.HTML(200, SIGNIN) return } @@ -94,7 +103,7 @@ func SignInPost(ctx *middleware.Context, form auth.LogInForm) { if err != nil { if err == models.ErrUserNotExist { log.Trace("%s Log in failed: %s", ctx.Req.RequestURI, form.UserName) - ctx.RenderWithErr("Username or password is not correct", "user/signin", &form) + ctx.RenderWithErr("Username or password is not correct", SIGNIN, &form) return } @@ -151,7 +160,7 @@ func SignUp(ctx *middleware.Context) { if setting.Service.DisableRegistration { ctx.Data["DisableRegistration"] = true - ctx.HTML(200, "user/signup") + ctx.HTML(200, SIGNUP) return } @@ -160,7 +169,7 @@ func SignUp(ctx *middleware.Context) { return } - ctx.HTML(200, "user/signup") + ctx.HTML(200, SIGNUP) } func oauthSignUp(ctx *middleware.Context, sid int64) { @@ -180,7 +189,7 @@ func oauthSignUp(ctx *middleware.Context, sid int64) { ctx.Data["username"] = strings.Replace(ctx.Session.Get("socialName").(string), " ", "", -1) ctx.Data["email"] = ctx.Session.Get("socialEmail") log.Trace("user.oauthSignUp(social ID): %v", ctx.Session.Get("socialId")) - ctx.HTML(200, "user/signup") + ctx.HTML(200, SIGNUP) } func SignUpPost(ctx *middleware.Context, form auth.RegisterForm) { @@ -198,14 +207,14 @@ func SignUpPost(ctx *middleware.Context, form auth.RegisterForm) { } if ctx.HasError() { - ctx.HTML(200, "user/signup") + ctx.HTML(200, SIGNUP) return } if form.Password != form.RetypePasswd { ctx.Data["Err_Password"] = true ctx.Data["Err_RetypePasswd"] = true - ctx.RenderWithErr("Password and re-type password are not same.", "user/signup", &form) + ctx.RenderWithErr("Password and re-type password are not same.", SIGNUP, &form) return } @@ -221,12 +230,12 @@ func SignUpPost(ctx *middleware.Context, form auth.RegisterForm) { switch err { case models.ErrUserAlreadyExist: ctx.Data["Err_UserName"] = true - ctx.RenderWithErr("Username has been already taken", "user/signup", &form) + ctx.RenderWithErr("Username has been already taken", SIGNUP, &form) case models.ErrEmailAlreadyUsed: ctx.Data["Err_Email"] = true - ctx.RenderWithErr("E-mail address has been already used", "user/signup", &form) + ctx.RenderWithErr("E-mail address has been already used", SIGNUP, &form) case models.ErrUserNameIllegal: - ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "user/signup", &form) + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), SIGNUP, &form) default: ctx.Handle(500, "user.SignUpPost(RegisterUser)", err) } @@ -265,7 +274,7 @@ func Delete(ctx *middleware.Context) { ctx.Data["Title"] = "Delete Account" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingDelete"] = true - ctx.HTML(200, "user/delete") + ctx.HTML(200, DELETE) } func DeletePost(ctx *middleware.Context) { @@ -321,7 +330,7 @@ func Activate(ctx *middleware.Context) { } else { ctx.Data["ServiceNotEnabled"] = true } - ctx.HTML(200, "user/activate") + ctx.HTML(200, ACTIVATE) return } @@ -343,7 +352,7 @@ func Activate(ctx *middleware.Context) { } ctx.Data["IsActivateFailed"] = true - ctx.HTML(200, "user/activate") + ctx.HTML(200, ACTIVATE) } func ForgotPasswd(ctx *middleware.Context) { @@ -351,12 +360,12 @@ func ForgotPasswd(ctx *middleware.Context) { if setting.MailService == nil { ctx.Data["IsResetDisable"] = true - ctx.HTML(200, "user/forgot_passwd") + ctx.HTML(200, FORGOT_PASSWORD) return } ctx.Data["IsResetRequest"] = true - ctx.HTML(200, "user/forgot_passwd") + ctx.HTML(200, FORGOT_PASSWORD) } func ForgotPasswdPost(ctx *middleware.Context) { @@ -381,7 +390,7 @@ func ForgotPasswdPost(ctx *middleware.Context) { if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) { ctx.Data["ResendLimited"] = true - ctx.HTML(200, "user/forgot_passwd") + ctx.HTML(200, FORGOT_PASSWORD) return } @@ -393,7 +402,7 @@ func ForgotPasswdPost(ctx *middleware.Context) { ctx.Data["Email"] = email ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60 ctx.Data["IsResetSent"] = true - ctx.HTML(200, "user/forgot_passwd") + ctx.HTML(200, FORGOT_PASSWORD) } func ResetPasswd(ctx *middleware.Context) { @@ -406,7 +415,7 @@ func ResetPasswd(ctx *middleware.Context) { } ctx.Data["Code"] = code ctx.Data["IsResetForm"] = true - ctx.HTML(200, "user/reset_passwd") + ctx.HTML(200, RESET_PASSWORD) } func ResetPasswdPost(ctx *middleware.Context) { @@ -443,5 +452,5 @@ func ResetPasswdPost(ctx *middleware.Context) { } ctx.Data["IsResetFailed"] = true - ctx.HTML(200, "user/reset_passwd") + ctx.HTML(200, RESET_PASSWORD) } diff --git a/templates/VERSION b/templates/VERSION index 7d143dcc1..414dc2efe 100644 --- a/templates/VERSION +++ b/templates/VERSION @@ -1 +1 @@ -0.4.5.0621 Alpha \ No newline at end of file +0.4.5.0622 Alpha \ No newline at end of file diff --git a/templates/repo/branches.tmpl b/templates/repo/branch.tmpl similarity index 100% rename from templates/repo/branches.tmpl rename to templates/repo/branch.tmpl diff --git a/templates/repo/hooks_add.tmpl b/templates/repo/hook_add.tmpl similarity index 100% rename from templates/repo/hooks_add.tmpl rename to templates/repo/hook_add.tmpl diff --git a/templates/repo/hooks_edit.tmpl b/templates/repo/hook_edit.tmpl similarity index 100% rename from templates/repo/hooks_edit.tmpl rename to templates/repo/hook_edit.tmpl diff --git a/templates/user/issue.tmpl b/templates/user/issues.tmpl similarity index 100% rename from templates/user/issue.tmpl rename to templates/user/issues.tmpl