From d4af0df96729c5f5c7b22f0af29b6e97ba78add0 Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 12 Oct 2020 05:05:21 +0100 Subject: [PATCH] Fix attachments list in edit comment (#13036) (#13097) Backport #13036 #11141 broke the appearance of dropzone attachments when editting comments causing poorly updating lists. This PR fixes this. Fix #12583 Signed-off-by: Andrew Thornton art27@cantab.net Co-authored-by: techknowlogick --- templates/repo/issue/view_content.tmpl | 8 +++-- .../repo/issue/view_content/attachments.tmpl | 2 +- .../repo/issue/view_content/comments.tmpl | 8 +++-- web_src/js/index.js | 32 ++++++++++++------- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index a61832dd3c..cf0c84cfe5 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -56,9 +56,11 @@
{{.Issue.Content}}
{{if .Issue.Attachments}} -
-
- {{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Issue.Attachments}} +
+
+
+ {{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Issue.Attachments}} +
{{end}}
diff --git a/templates/repo/issue/view_content/attachments.tmpl b/templates/repo/issue/view_content/attachments.tmpl index 3c69dbc2ba..f42027d795 100644 --- a/templates/repo/issue/view_content/attachments.tmpl +++ b/templates/repo/issue/view_content/attachments.tmpl @@ -2,7 +2,7 @@
{{if FilenameIsImage .Name}} - {{svg "octicon-file-media" 16}} + {{svg "octicon-file" 16}} {{else}} {{svg "octicon-desktop-download" 16}} {{end}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index e52b4979fc..87dc490043 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -53,9 +53,11 @@
{{.Content}}
{{if .Attachments}} -
-
- {{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Attachments}} +
+
+
+ {{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Attachments}} +
{{end}}
diff --git a/web_src/js/index.js b/web_src/js/index.js index 6fe6d3777f..a6a840b1ae 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -980,7 +980,9 @@ async function initRepository() { $editContentZone.find('.cancel.button').on('click', () => { $renderContent.show(); $editContentZone.hide(); - dz.emit('reload'); + if (dz) { + dz.emit('reload'); + } }); $editContentZone.find('.save.button').on('click', () => { $renderContent.show(); @@ -994,7 +996,7 @@ async function initRepository() { context: $editContentZone.data('context'), files: $attachments }, (data) => { - if (data.length === 0) { + if (data.length === 0 || data.content.length === 0) { $renderContent.html($('#no-content').html()); } else { $renderContent.html(data.content); @@ -1002,21 +1004,27 @@ async function initRepository() { highlight(this); }); } - const $content = $segment.parent(); - if (!$content.find('.ui.small.images').length) { + const $content = $segment; + if (!$content.find('.dropzone-attachments').length) { if (data.attachments !== '') { - $content.append( - '
' - ); - $content.find('.ui.small.images').html(data.attachments); + $content.append(` +
+
+
+
+
+ `); + $content.find('.dropzone-attachments .grid').html(data.attachments); } } else if (data.attachments === '') { - $content.find('.ui.small.images').parent().remove(); + $content.find('.dropzone-attachments').remove(); } else { - $content.find('.ui.small.images').html(data.attachments); + $content.find('.dropzone-attachments .grid').html(data.attachments); + } + if (dz) { + dz.emit('submit'); + dz.emit('reload'); } - dz.emit('submit'); - dz.emit('reload'); }); }); } else {