Skip to content

Commit 6a4be2c

Browse files
HesterGGiteaBot
andauthored
Add cardtype to org/user level project on creation, edit and view (#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: <img width="1135" alt="截屏2023-04-11 13 55 49" src="https://user-images.githubusercontent.com/17645053/231069068-ba897129-ae90-4aa0-9b0f-468bf5c65375.png"> <img width="1131" alt="截屏2023-04-11 13 55 59" src="https://user-images.githubusercontent.com/17645053/231069084-279f6681-5a10-42da-b5a8-2b0ba47c7078.png"> After: Create <img width="835" alt="截屏2023-04-11 13 27 16" src="https://user-images.githubusercontent.com/17645053/231064445-0d6e12bd-5725-48db-a102-80e7472757c2.png"> Edit <img width="852" alt="截屏2023-04-11 13 27 05" src="https://user-images.githubusercontent.com/17645053/231064503-c70525cd-1038-43ec-8d93-8b8d95d183d4.png"> View <img width="1329" alt="截屏2023-04-11 13 26 56" src="https://user-images.githubusercontent.com/17645053/231064529-26023c85-698b-4b2e-af02-45f9820c77ec.png"> Co-authored-by: Giteabot <[email protected]>
1 parent 0536712 commit 6a4be2c

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

routers/web/org/projects.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
issues_model "code.gitea.io/gitea/models/issues"
1515
project_model "code.gitea.io/gitea/models/project"
16+
attachment_model "code.gitea.io/gitea/models/repo"
1617
"code.gitea.io/gitea/models/unit"
1718
"code.gitea.io/gitea/modules/base"
1819
"code.gitea.io/gitea/modules/context"
@@ -128,6 +129,7 @@ func canWriteProjects(ctx *context.Context) bool {
128129
func NewProject(ctx *context.Context) {
129130
ctx.Data["Title"] = ctx.Tr("repo.projects.new")
130131
ctx.Data["BoardTypes"] = project_model.GetBoardConfig()
132+
ctx.Data["CardTypes"] = project_model.GetCardConfig()
131133
ctx.Data["CanWriteProjects"] = canWriteProjects(ctx)
132134
ctx.Data["PageIsViewProjects"] = true
133135
ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink()
@@ -145,6 +147,7 @@ func NewProjectPost(ctx *context.Context) {
145147
ctx.Data["CanWriteProjects"] = canWriteProjects(ctx)
146148
ctx.Data["PageIsViewProjects"] = true
147149
ctx.Data["BoardTypes"] = project_model.GetBoardConfig()
150+
ctx.Data["CardTypes"] = project_model.GetCardConfig()
148151
ctx.HTML(http.StatusOK, tplProjectsNew)
149152
return
150153
}
@@ -155,6 +158,7 @@ func NewProjectPost(ctx *context.Context) {
155158
Description: form.Content,
156159
CreatorID: ctx.Doer.ID,
157160
BoardType: form.BoardType,
161+
CardType: form.CardType,
158162
}
159163

160164
if ctx.ContextUser.IsOrganization() {
@@ -229,6 +233,8 @@ func EditProject(ctx *context.Context) {
229233
ctx.Data["PageIsEditProjects"] = true
230234
ctx.Data["PageIsViewProjects"] = true
231235
ctx.Data["CanWriteProjects"] = canWriteProjects(ctx)
236+
ctx.Data["CardTypes"] = project_model.GetCardConfig()
237+
232238
shared_user.RenderUserHeader(ctx)
233239

234240
p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
@@ -250,6 +256,7 @@ func EditProject(ctx *context.Context) {
250256
ctx.Data["content"] = p.Description
251257
ctx.Data["redirect"] = ctx.FormString("redirect")
252258
ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink()
259+
ctx.Data["card_type"] = p.CardType
253260

254261
ctx.HTML(http.StatusOK, tplProjectsNew)
255262
}
@@ -261,6 +268,8 @@ func EditProjectPost(ctx *context.Context) {
261268
ctx.Data["PageIsEditProjects"] = true
262269
ctx.Data["PageIsViewProjects"] = true
263270
ctx.Data["CanWriteProjects"] = canWriteProjects(ctx)
271+
ctx.Data["CardTypes"] = project_model.GetCardConfig()
272+
264273
shared_user.RenderUserHeader(ctx)
265274

266275
if ctx.HasError() {
@@ -284,6 +293,7 @@ func EditProjectPost(ctx *context.Context) {
284293

285294
p.Title = form.Title
286295
p.Description = form.Content
296+
p.CardType = form.CardType
287297
if err = project_model.UpdateProject(ctx, p); err != nil {
288298
ctx.ServerError("UpdateProjects", err)
289299
return
@@ -329,6 +339,18 @@ func ViewProject(ctx *context.Context) {
329339
return
330340
}
331341

342+
if project.CardType != project_model.CardTypeTextOnly {
343+
issuesAttachmentMap := make(map[int64][]*attachment_model.Attachment)
344+
for _, issuesList := range issuesMap {
345+
for _, issue := range issuesList {
346+
if issueAttachment, err := attachment_model.GetAttachmentsByIssueIDImagesLatest(ctx, issue.ID); err == nil {
347+
issuesAttachmentMap[issue.ID] = issueAttachment
348+
}
349+
}
350+
}
351+
ctx.Data["issuesAttachmentMap"] = issuesAttachmentMap
352+
}
353+
332354
linkedPrsMap := make(map[int64][]*issues_model.Issue)
333355
for _, issuesList := range issuesMap {
334356
for _, issue := range issuesList {

templates/projects/new.tmpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@
4545
</div>
4646
</div>
4747
{{end}}
48+
49+
<div class="field">
50+
<label>{{.locale.Tr "repo.projects.card_type.desc"}}</label>
51+
<div class="ui selection dropdown">
52+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
53+
{{range $element := .CardTypes}}
54+
{{if or (eq $.card_type $element.CardType) (and (not $.PageIsEditProjects) (eq $element.CardType 1))}}
55+
<input type="hidden" name="card_type" value="{{$element.CardType}}">
56+
<div class="default text">{{$.locale.Tr $element.Translation}}</div>
57+
{{end}}
58+
{{end}}
59+
<div class="menu">
60+
{{range $element := .CardTypes}}
61+
<div class="item" data-id="{{$element.CardType}}" data-value="{{$element.CardType}}">{{$.locale.Tr $element.Translation}}</div>
62+
{{end}}
63+
</div>
64+
</div>
65+
</div>
4866
</div>
4967
<div class="ui container">
5068
<div class="ui divider"></div>

templates/projects/view.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@
175175

176176
<!-- start issue card -->
177177
<div class="card board-card" data-issue="{{.ID}}">
178+
{{if eq $.Project.CardType 1}}{{/* Images and Text*/}}
179+
<div class="card-attachment-images">
180+
{{range (index $.issuesAttachmentMap .ID)}}
181+
<img src="{{.DownloadURL}}" alt="{{.Name}}" />
182+
{{end}}
183+
</div>
184+
{{end}}
178185
<div class="content gt-p-0">
179186
<div class="header">
180187
<span class="gt-dif gt-ac gt-vm {{if .IsClosed}}red{{else}}green{{end}}">

0 commit comments

Comments
 (0)