Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview images for Issue cards in Project Board view #22112

Merged
merged 28 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e06acf4
Preview images for Issue cards in Project Board view
gnat Dec 12, 2022
0afe784
Preview images for Issue cards in Project Board view
gnat Dec 12, 2022
a3fcf65
More specific selector for cleaned up card CSS.
gnat Dec 15, 2022
3745fc3
Added Project option to change Card Type (Image Previews vs Text Only)
gnat Dec 15, 2022
5f57f97
gofmt
gnat Dec 15, 2022
e07d534
Merge remote-tracking branch 'origin/master' into project_issue_image…
gnat Dec 23, 2022
9397770
Added migration.
gnat Dec 23, 2022
4acf5ba
gofmt
gnat Dec 23, 2022
0489cdb
Only fill issuesAttachmentMap if appropriate CardType is set.
gnat Jan 8, 2023
d901ec7
Removed migration.
gnat Jan 8, 2023
326c5b8
Re-added migration as v238
gnat Jan 8, 2023
3e77920
Merge remote-tracking branch 'origin/master' into project_issue_image…
gnat Jan 8, 2023
5936b56
Update models/migrations/v1_19/v238.go
gnat Feb 8, 2023
3aaf557
Merge branch 'master' into project_issue_image_preview
gnat Feb 8, 2023
5e05bec
Update templates/repo/projects/view.tmpl
gnat Feb 8, 2023
853adca
Update models/repo/attachment.go
gnat Feb 8, 2023
84fe0da
Update models/project/board.go
gnat Feb 8, 2023
8fd107a
Added migration.
gnat Feb 8, 2023
d734698
Cleanup from merge with master.
gnat Feb 8, 2023
a3b449a
Bring new org functionality up to date.
gnat Feb 8, 2023
a5e6e22
Cleanup from merge with master.
gnat Feb 8, 2023
5f52fc7
Merge branch 'main' into project_issue_image_preview
lunny Feb 8, 2023
c93b600
Update templates/repo/projects/view.tmpl
gnat Feb 8, 2023
eac2221
Update models/migrations/v1_19/v241.go
gnat Feb 8, 2023
4ce0594
Fixed linter.
gnat Feb 8, 2023
58ef8b1
Images and Text type was updated.
gnat Feb 8, 2023
1c71eab
Merge branch 'main' into project_issue_image_preview
lunny Feb 11, 2023
1f3c4d3
Merge branch 'main' into project_issue_image_preview
lunny Feb 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions models/repo/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ func GetAttachmentsByIssueID(ctx context.Context, issueID int64) ([]*Attachment,
return attachments, db.GetEngine(ctx).Where("issue_id = ? AND comment_id = 0", issueID).Find(&attachments)
}

// GetAttachmentsByIssueIDImagesLatest returns the latest image attachments of an issue.
func GetAttachmentsByIssueIDImagesLatest(ctx context.Context, issueID int64) ([]*Attachment, error) {
attachments := make([]*Attachment, 0, 10)
gnat marked this conversation as resolved.
Show resolved Hide resolved
return attachments, db.GetEngine(ctx).Where(`issue_id = ? AND (name like '%.apng'
OR name like '%.avif'
OR name like '%.bmp'
OR name like '%.gif'
OR name like '%.jpg'
OR name like '%.jpeg'
OR name like '%.jxl'
OR name like '%.png'
OR name like '%.svg'
OR name like '%.webp')`, issueID).Desc("comment_id").Limit(5).Find(&attachments)
delvh marked this conversation as resolved.
Show resolved Hide resolved
}

// GetAttachmentsByCommentID returns all attachments if comment by given ID.
func GetAttachmentsByCommentID(ctx context.Context, commentID int64) ([]*Attachment, error) {
attachments := make([]*Attachment, 0, 10)
Expand Down
11 changes: 11 additions & 0 deletions routers/web/repo/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/perm"
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"
Expand Down Expand Up @@ -302,6 +303,16 @@ func ViewProject(ctx *context.Context) {
return
}

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 {
gnat marked this conversation as resolved.
Show resolved Hide resolved
issuesAttachmentMap[issue.ID] = issueAttachment
}
}
}
ctx.Data["issuesAttachmentMap"] = issuesAttachmentMap

linkedPrsMap := make(map[int64][]*issues_model.Issue)
for _, issuesList := range issuesMap {
for _, issue := range issuesList {
Expand Down
5 changes: 5 additions & 0 deletions templates/repo/projects/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@

<!-- start issue card -->
<div class="card board-card" data-issue="{{.ID}}">
<div class="card-attachment-images">
{{range (index $.issuesAttachmentMap .ID)}}
<img src="{{.DownloadURL}}" alt="{{.Name}}" />
{{end}}
</div>
<div class="content p-0">
<div class="header">
<span class="dif ac vm {{if .IsClosed}}red{{else}}green{{end}}">
Expand Down
2 changes: 1 addition & 1 deletion web_src/less/_base.less
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ a.commit-statuses-trigger {

.ui.cards > .card > .content,
.ui.card > .content {
border-color: var(--color-secondary);
border: none;
gnat marked this conversation as resolved.
Show resolved Hide resolved
}

.ui.cards > .card > .extra,
Expand Down
19 changes: 19 additions & 0 deletions web_src/less/features/projects.less
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@
font-size: 16px !important;
}

.board-card .card-attachment-images {
display: inline-block;
white-space: nowrap;
overflow: hidden;
text-align: center;
}

.board-card .card-attachment-images img {
display: inline-block;
max-height: 50px;
border-radius: var(--border-radius);
margin-right: 2px;
}

.board-card .card-attachment-images img:only-child {
max-height: 90px;
margin: auto;
}

.card-ghost {
border-style: dashed !important;
background: none !important;
Expand Down