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

Fix attachments list in edit comment (#13036) #13097

Merged
merged 3 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
8 changes: 5 additions & 3 deletions templates/repo/issue/view_content.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
<div id="comment-{{.Issue.ID}}" class="raw-content hide">{{.Issue.Content}}</div>
<div class="edit-content-zone hide" data-write="issue-{{.Issue.ID}}-write" data-preview="issue-{{.Issue.ID}}-preview" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/content" data-context="{{.RepoLink}}" data-attachment-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/attachments" data-view-attachment-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/view-attachments"></div>
{{if .Issue.Attachments}}
<div class="ui clearing divider"></div>
<div class="ui middle aligned padded grid">
{{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Issue.Attachments}}
<div class="dropzone-attachments">
<div class="ui clearing divider"></div>
<div class="ui middle aligned padded grid">
{{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Issue.Attachments}}
</div>
</div>
{{end}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/view_content/attachments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="twelve wide column" style="padding: 6px;">
<a target="_blank" rel="noopener noreferrer" href="{{.DownloadURL}}" title='{{$.ctx.i18n.Tr "repo.issues.attachment.open_tab" .Name}}'>
{{if FilenameIsImage .Name}}
<span class="ui image">{{svg "octicon-file-media" 16}}</span>
<span class="ui image">{{svg "octicon-file" 16}}</span>
{{else}}
<span class="ui image">{{svg "octicon-desktop-download" 16}}</span>
{{end}}
Expand Down
8 changes: 5 additions & 3 deletions templates/repo/issue/view_content/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@
<div id="comment-{{.ID}}" class="raw-content hide">{{.Content}}</div>
<div class="edit-content-zone hide" data-write="issuecomment-{{.ID}}-write" data-preview="issuecomment-{{.ID}}-preview" data-update-url="{{$.RepoLink}}/comments/{{.ID}}" data-context="{{$.RepoLink}}" data-attachment-url="{{$.RepoLink}}/comments/{{.ID}}/attachments"></div>
{{if .Attachments}}
<div class="ui clearing divider"></div>
<div class="ui middle aligned padded grid">
{{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Attachments}}
<div class="dropzone-attachments">
<div class="ui clearing divider"></div>
<div class="ui middle aligned padded grid">
{{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Attachments}}
</div>
</div>
{{end}}
</div>
Expand Down
32 changes: 20 additions & 12 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -994,29 +996,35 @@ 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);
$('pre code', $renderContent[0]).each(function () {
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(
'<div class="ui bottom attached segment"><div class="ui small images"></div></div>'
);
$content.find('.ui.small.images').html(data.attachments);
$content.append(`
<div class="dropzone-attachments">
<div class="ui clearing divider"></div>
<div class="ui middle aligned padded grid">
</div>
</div>
`);
$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 {
Expand Down