From b35c1b5784b99fa71d0ea3ddf8ac253dc44c0d82 Mon Sep 17 00:00:00 2001 From: bobemoe Date: Sun, 13 Dec 2020 19:12:27 +0000 Subject: [PATCH] add thumbnail preview section to issue attachments (#13826) * add thumbnail preview section to attachments * dont show thumbnail if the image is already shown inline * update router to pass the `content` to the attachemnts template * limit attachment preview height to 150px (same as width) * remove unused css (referance removed in https://github.com/go-gitea/gitea/pull/11141/files#diff-9faae32445ed9673de2830c9fc35e93f44487f0a0068202988adaf00a5bac850L66 ) * dont show divider after edit if no attachemnts Co-authored-by: James Co-authored-by: 6543 <6543@obermui.de> --- routers/repo/issue.go | 7 ++- templates/repo/issue/view_content.tmpl | 11 +--- .../repo/issue/view_content/attachments.tmpl | 55 ++++++++++++++----- .../repo/issue/view_content/comments.tmpl | 11 +--- web_src/js/index.js | 7 +-- web_src/less/_repository.less | 46 +--------------- 6 files changed, 56 insertions(+), 81 deletions(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 6ebc5d6ec..e350f74de 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -1649,7 +1649,7 @@ func UpdateIssueContent(ctx *context.Context) { ctx.JSON(200, map[string]interface{}{ "content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())), - "attachments": attachmentsHTML(ctx, issue.Attachments), + "attachments": attachmentsHTML(ctx, issue.Attachments, issue.Content), }) } @@ -2065,7 +2065,7 @@ func UpdateCommentContent(ctx *context.Context) { ctx.JSON(200, map[string]interface{}{ "content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())), - "attachments": attachmentsHTML(ctx, comment.Attachments), + "attachments": attachmentsHTML(ctx, comment.Attachments, comment.Content), }) } @@ -2399,10 +2399,11 @@ func updateAttachments(item interface{}, files []string) error { return err } -func attachmentsHTML(ctx *context.Context, attachments []*models.Attachment) string { +func attachmentsHTML(ctx *context.Context, attachments []*models.Attachment, content string) string { attachHTML, err := ctx.HTMLString(string(tplAttachment), map[string]interface{}{ "ctx": ctx.Data, "Attachments": attachments, + "Content": content, }) if err != nil { ctx.ServerError("attachmentsHTML.HTMLString", err) diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 355ba0ea2..37628a74e 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -66,14 +66,9 @@
{{.Issue.Content}}
- {{if .Issue.Attachments}} -
-
-
- {{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Issue.Attachments}} -
-
- {{end}} + {{if .Issue.Attachments}} + {{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Issue.Attachments "Content" .Issue.RenderedContent}} + {{end}} {{$reactions := .Issue.Reactions.GroupByType}} {{if $reactions}} diff --git a/templates/repo/issue/view_content/attachments.tmpl b/templates/repo/issue/view_content/attachments.tmpl index d76c0bbfa..16d77847d 100644 --- a/templates/repo/issue/view_content/attachments.tmpl +++ b/templates/repo/issue/view_content/attachments.tmpl @@ -1,15 +1,42 @@ -{{- range .Attachments -}} -
- - {{if FilenameIsImage .Name}} - {{svg "octicon-file"}} - {{else}} - {{svg "octicon-desktop-download"}} - {{end}} - {{.Name}} - +
+ {{if .Attachments}} +
+ {{end}} + + + {{if $hasThumbnails}} +
+
+ {{- range .Attachments -}} + {{if FilenameIsImage .Name}} + {{if not (containGeneric $.Content .UUID)}} + + + + {{end}} + {{end}} + {{end -}} +
+ {{end}} +
-
- {{.Size | FileSize}} -
-{{end -}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 698e4698d..2c413b3c4 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -72,14 +72,9 @@
{{.Content}}
- {{if .Attachments}} -
-
-
- {{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Attachments}} -
-
- {{end}} + {{if .Attachments}} + {{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Attachments "Content" .RenderedContent}} + {{end}} {{$reactions := .Reactions.GroupByType}} {{if $reactions}} diff --git a/web_src/js/index.js b/web_src/js/index.js index 55cf08cb6..d4928a01a 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -1048,17 +1048,14 @@ async function initRepository() { if (data.attachments !== '') { $content.append(`
-
-
-
`); - $content.find('.dropzone-attachments .grid').html(data.attachments); + $content.find('.dropzone-attachments').replaceWith(data.attachments); } } else if (data.attachments === '') { $content.find('.dropzone-attachments').remove(); } else { - $content.find('.dropzone-attachments .grid').html(data.attachments); + $content.find('.dropzone-attachments').replaceWith(data.attachments); } if (dz) { dz.emit('submit'); diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 8876dcdcb..b35718c29 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -1016,50 +1016,10 @@ font-style: italic; } - > .bottom.segment { - background: var(--color-box-body); - - .ui.images::after { - clear: both; - content: ' '; - display: block; - } - - a { - display: block; - float: left; - margin: 5px; - padding: 5px; - height: 150px; - border: solid 1px var(--color-secondary); - border-radius: 3px; - max-width: 150px; - background-color: var(--color-body); - - &::before { - content: ' '; - display: inline-block; - height: 100%; - vertical-align: middle; - } - } - - .ui.image { - max-height: 100%; - width: auto; - margin: 0; - vertical-align: middle; - } - - span.ui.image { - font-size: 128px; - color: var(--color-text); - } - - span.ui.image:hover { - color: var(--color-text); - } + .dropzone-attachments .thumbnails .ui.image { + max-height: 150px; } + } .ui.form {