From 5482602ba8fc84f716e4742467bc429037f45f88 Mon Sep 17 00:00:00 2001 From: Hester Gong Date: Wed, 12 Apr 2023 20:23:05 +0800 Subject: [PATCH] Add cardtype to org/user level project on creation, edit and view (#24043) (#24066) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport #24043 Part of #23318 The way to fix the missing cardtype for user/org level projects in this PR is to port the cardtype related part from #22112 to org/user level projects' template and router functions. Before: 截屏2023-04-11 13 55 49 截屏2023-04-11 13 55 59 After: Create 截屏2023-04-11 13 27 16 Edit 截屏2023-04-11 13 27 05 View 截屏2023-04-11 13 26 56 --------- Co-authored-by: silverwind --- routers/web/org/projects.go | 22 ++++++++++++++++++++++ templates/projects/new.tmpl | 18 ++++++++++++++++++ templates/projects/view.tmpl | 7 +++++++ 3 files changed, 47 insertions(+) diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index 080388f01f..129864f9c4 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -13,6 +13,7 @@ import ( issues_model "code.gitea.io/gitea/models/issues" project_model "code.gitea.io/gitea/models/project" + attachment_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -122,6 +123,7 @@ func canWriteProjects(ctx *context.Context) bool { func NewProject(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() @@ -139,6 +141,7 @@ func NewProjectPost(ctx *context.Context) { 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) return } @@ -149,6 +152,7 @@ func NewProjectPost(ctx *context.Context) { Description: form.Content, CreatorID: ctx.Doer.ID, BoardType: form.BoardType, + CardType: form.CardType, Type: project_model.TypeOrganization, }); err != nil { ctx.ServerError("NewProject", err) @@ -216,6 +220,8 @@ func EditProject(ctx *context.Context) { ctx.Data["PageIsEditProjects"] = true ctx.Data["PageIsViewProjects"] = true ctx.Data["CanWriteProjects"] = canWriteProjects(ctx) + ctx.Data["CardTypes"] = project_model.GetCardConfig() + shared_user.RenderUserHeader(ctx) p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id")) @@ -237,6 +243,7 @@ func EditProject(ctx *context.Context) { ctx.Data["content"] = p.Description ctx.Data["redirect"] = ctx.FormString("redirect") ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink() + ctx.Data["card_type"] = p.CardType ctx.HTML(http.StatusOK, tplProjectsNew) } @@ -248,6 +255,8 @@ func EditProjectPost(ctx *context.Context) { ctx.Data["PageIsEditProjects"] = true ctx.Data["PageIsViewProjects"] = true ctx.Data["CanWriteProjects"] = canWriteProjects(ctx) + ctx.Data["CardTypes"] = project_model.GetCardConfig() + shared_user.RenderUserHeader(ctx) if ctx.HasError() { @@ -271,6 +280,7 @@ func EditProjectPost(ctx *context.Context) { p.Title = form.Title p.Description = form.Content + p.CardType = form.CardType if err = project_model.UpdateProject(ctx, p); err != nil { ctx.ServerError("UpdateProjects", err) return @@ -316,6 +326,18 @@ func ViewProject(ctx *context.Context) { return } + if project.CardType != project_model.CardTypeTextOnly { + issuesAttachmentMap := make(map[int64][]*attachment_model.Attachment) + for _, issuesList := range issuesMap { + for _, issue := range issuesList { + if issueAttachment, err := attachment_model.GetAttachmentsByIssueIDImagesLatest(ctx, issue.ID); err == nil { + issuesAttachmentMap[issue.ID] = issueAttachment + } + } + } + ctx.Data["issuesAttachmentMap"] = issuesAttachmentMap + } + linkedPrsMap := make(map[int64][]*issues_model.Issue) for _, issuesList := range issuesMap { for _, issue := range issuesList { diff --git a/templates/projects/new.tmpl b/templates/projects/new.tmpl index 1314884da6..cb3214c49d 100644 --- a/templates/projects/new.tmpl +++ b/templates/projects/new.tmpl @@ -43,6 +43,24 @@ {{end}} + +
+ + +
diff --git a/templates/projects/view.tmpl b/templates/projects/view.tmpl index c815ec4f6a..c1f52cefd4 100644 --- a/templates/projects/view.tmpl +++ b/templates/projects/view.tmpl @@ -175,6 +175,13 @@
+ {{if eq $.Project.CardType 1}}{{/* Images and Text*/}} +
+ {{range (index $.issuesAttachmentMap .ID)}} + {{.Name}} + {{end}} +
+ {{end}}