diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index 32b60e995f..b3f6024b60 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -26,10 +26,9 @@ import ( ) const ( - tplProjects base.TplName = "org/projects/list" - tplProjectsNew base.TplName = "org/projects/new" - tplProjectsView base.TplName = "org/projects/view" - tplGenericProjectsNew base.TplName = "user/project" + tplProjects base.TplName = "org/projects/list" + tplProjectsNew base.TplName = "org/projects/new" + tplProjectsView base.TplName = "org/projects/view" ) // MustEnableProjects check if projects are enabled in settings @@ -125,14 +124,15 @@ func canWriteProjects(ctx *context.Context) bool { return ctx.Doer != nil && ctx.ContextUser.ID == ctx.Doer.ID } -// NewProject render creating a project page -func NewProject(ctx *context.Context) { +// RenderNewProject render creating a project page +func RenderNewProject(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.projects.new") ctx.Data["BoardTypes"] = project_model.GetBoardConfig() ctx.Data["CardTypes"] = project_model.GetCardConfig() ctx.Data["CanWriteProjects"] = canWriteProjects(ctx) ctx.Data["PageIsViewProjects"] = true ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink() + ctx.Data["CancelLink"] = ctx.ContextUser.HomeLink() + "/-/projects" shared_user.RenderUserHeader(ctx) ctx.HTML(http.StatusOK, tplProjectsNew) } @@ -144,11 +144,7 @@ func NewProjectPost(ctx *context.Context) { shared_user.RenderUserHeader(ctx) if ctx.HasError() { - ctx.Data["CanWriteProjects"] = canWriteProjects(ctx) - ctx.Data["PageIsViewProjects"] = true - ctx.Data["BoardTypes"] = project_model.GetBoardConfig() - ctx.Data["CardTypes"] = project_model.GetCardConfig() - ctx.HTML(http.StatusOK, tplProjectsNew) + RenderNewProject(ctx) return } @@ -227,8 +223,8 @@ func DeleteProject(ctx *context.Context) { }) } -// EditProject allows a project to be edited -func EditProject(ctx *context.Context) { +// RenderEditProject allows a project to be edited +func RenderEditProject(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.projects.edit") ctx.Data["PageIsEditProjects"] = true ctx.Data["PageIsViewProjects"] = true @@ -257,6 +253,7 @@ func EditProject(ctx *context.Context) { ctx.Data["redirect"] = ctx.FormString("redirect") ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink() ctx.Data["card_type"] = p.CardType + ctx.Data["CancelLink"] = fmt.Sprintf("%s/-/projects/%d", ctx.ContextUser.HomeLink(), p.ID) ctx.HTML(http.StatusOK, tplProjectsNew) } @@ -264,11 +261,13 @@ func EditProject(ctx *context.Context) { // EditProjectPost response for editing a project func EditProjectPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.CreateProjectForm) + projectID := ctx.ParamsInt64(":id") ctx.Data["Title"] = ctx.Tr("repo.projects.edit") ctx.Data["PageIsEditProjects"] = true ctx.Data["PageIsViewProjects"] = true ctx.Data["CanWriteProjects"] = canWriteProjects(ctx) ctx.Data["CardTypes"] = project_model.GetCardConfig() + ctx.Data["CancelLink"] = fmt.Sprintf("%s/-/projects/%d", ctx.ContextUser.HomeLink(), projectID) shared_user.RenderUserHeader(ctx) @@ -277,7 +276,7 @@ func EditProjectPost(ctx *context.Context) { return } - p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id")) + p, err := project_model.GetProjectByID(ctx, projectID) if err != nil { if project_model.IsErrProjectNotExist(err) { ctx.NotFound("", nil) diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index 72f83f8b31..5ee5ead121 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -27,10 +27,9 @@ import ( ) const ( - tplProjects base.TplName = "repo/projects/list" - tplProjectsNew base.TplName = "repo/projects/new" - tplProjectsView base.TplName = "repo/projects/view" - tplGenericProjectsNew base.TplName = "user/project" + tplProjects base.TplName = "repo/projects/list" + tplProjectsNew base.TplName = "repo/projects/new" + tplProjectsView base.TplName = "repo/projects/view" ) // MustEnableProjects check if projects are enabled in settings @@ -121,12 +120,13 @@ func Projects(ctx *context.Context) { ctx.HTML(http.StatusOK, tplProjects) } -// NewProject render creating a project page -func NewProject(ctx *context.Context) { +// RenderNewProject render creating a project page +func RenderNewProject(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.projects.new") ctx.Data["BoardTypes"] = project_model.GetBoardConfig() ctx.Data["CardTypes"] = project_model.GetCardConfig() ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) + ctx.Data["CancelLink"] = ctx.Repo.Repository.Link() + "/projects" ctx.HTML(http.StatusOK, tplProjectsNew) } @@ -136,10 +136,7 @@ func NewProjectPost(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.projects.new") if ctx.HasError() { - ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) - ctx.Data["BoardTypes"] = project_model.GetBoardConfig() - ctx.Data["CardTypes"] = project_model.GetCardConfig() - ctx.HTML(http.StatusOK, tplProjectsNew) + RenderNewProject(ctx) return } @@ -211,8 +208,8 @@ func DeleteProject(ctx *context.Context) { }) } -// EditProject allows a project to be edited -func EditProject(ctx *context.Context) { +// RenderEditProject allows a project to be edited +func RenderEditProject(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.projects.edit") ctx.Data["PageIsEditProjects"] = true ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) @@ -237,6 +234,7 @@ func EditProject(ctx *context.Context) { ctx.Data["content"] = p.Description ctx.Data["card_type"] = p.CardType ctx.Data["redirect"] = ctx.FormString("redirect") + ctx.Data["CancelLink"] = fmt.Sprintf("%s/projects/%d", ctx.Repo.Repository.Link(), p.ID) ctx.HTML(http.StatusOK, tplProjectsNew) } @@ -244,17 +242,20 @@ func EditProject(ctx *context.Context) { // EditProjectPost response for editing a project func EditProjectPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.CreateProjectForm) + projectID := ctx.ParamsInt64(":id") + ctx.Data["Title"] = ctx.Tr("repo.projects.edit") ctx.Data["PageIsEditProjects"] = true ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) ctx.Data["CardTypes"] = project_model.GetCardConfig() + ctx.Data["CancelLink"] = fmt.Sprintf("%s/projects/%d", ctx.Repo.Repository.Link(), projectID) if ctx.HasError() { ctx.HTML(http.StatusOK, tplProjectsNew) return } - p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id")) + p, err := project_model.GetProjectByID(ctx, projectID) if err != nil { if project_model.IsErrProjectNotExist(err) { ctx.NotFound("", nil) diff --git a/routers/web/web.go b/routers/web/web.go index ef47b6679f..da6064257b 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -824,13 +824,13 @@ func registerRoutes(m *web.Route) { m.Get("/{id}", org.ViewProject) }, reqUnitAccess(unit.TypeProjects, perm.AccessModeRead)) m.Group("", func() { //nolint:dupl - m.Get("/new", org.NewProject) + m.Get("/new", org.RenderNewProject) m.Post("/new", web.Bind(forms.CreateProjectForm{}), org.NewProjectPost) m.Group("/{id}", func() { m.Post("", web.Bind(forms.EditProjectBoardForm{}), org.AddBoardToProjectPost) m.Post("/delete", org.DeleteProject) - m.Get("/edit", org.EditProject) + m.Get("/edit", org.RenderEditProject) m.Post("/edit", web.Bind(forms.CreateProjectForm{}), org.EditProjectPost) m.Post("/{action:open|close}", org.ChangeProjectStatus) @@ -1159,13 +1159,13 @@ func registerRoutes(m *web.Route) { m.Get("", repo.Projects) m.Get("/{id}", repo.ViewProject) m.Group("", func() { //nolint:dupl - m.Get("/new", repo.NewProject) + m.Get("/new", repo.RenderNewProject) m.Post("/new", web.Bind(forms.CreateProjectForm{}), repo.NewProjectPost) m.Group("/{id}", func() { m.Post("", web.Bind(forms.EditProjectBoardForm{}), repo.AddBoardToProjectPost) m.Post("/delete", repo.DeleteProject) - m.Get("/edit", repo.EditProject) + m.Get("/edit", repo.RenderEditProject) m.Post("/edit", web.Bind(forms.CreateProjectForm{}), repo.EditProjectPost) m.Post("/{action:open|close}", repo.ChangeProjectStatus) diff --git a/templates/org/projects/new.tmpl b/templates/org/projects/new.tmpl index f550cdc828..7011eb56d7 100644 --- a/templates/org/projects/new.tmpl +++ b/templates/org/projects/new.tmpl @@ -1,5 +1,5 @@ {{template "base/head" .}} -