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

10 changes: 10 additions & 0 deletions modules/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,28 @@ func AddUploadContext(ctx *context.Context, uploadType string) {
if uploadType == "release" {
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/releases/attachments"
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/releases/attachments/remove"
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/releases/attachments"
ctx.Data["UploadAccepts"] = strings.Replace(setting.Repository.Release.AllowedTypes, "|", ",", -1)
ctx.Data["UploadMaxFiles"] = setting.Attachment.MaxFiles
ctx.Data["UploadMaxSize"] = setting.Attachment.MaxSize
} else if uploadType == "comment" {
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/issues/attachments"
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/issues/attachments/remove"
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/issues/attachments"
ctx.Data["UploadAccepts"] = strings.Replace(setting.Attachment.AllowedTypes, "|", ",", -1)
ctx.Data["UploadMaxFiles"] = setting.Attachment.MaxFiles
ctx.Data["UploadMaxSize"] = setting.Attachment.MaxSize
} else if uploadType == "editcomment" {
zeripath marked this conversation as resolved.
Show resolved Hide resolved
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/issues/attachments"
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/issues/attachments/remove"
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/issues/" + ctx.Params(":index") + "/attachments"
ctx.Data["UploadAccepts"] = strings.Replace(setting.Attachment.AllowedTypes, "|", ",", -1)
ctx.Data["UploadMaxFiles"] = setting.Attachment.MaxFiles
ctx.Data["UploadMaxSize"] = setting.Attachment.MaxSize
} else if uploadType == "repo" {
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/upload-file"
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/upload-remove"
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/upload-file"
ctx.Data["UploadAccepts"] = strings.Replace(setting.Repository.Upload.AllowedTypes, "|", ",", -1)
ctx.Data["UploadMaxFiles"] = setting.Repository.Upload.MaxFiles
ctx.Data["UploadMaxSize"] = setting.Repository.Upload.FileMaxSize
Expand Down
2 changes: 1 addition & 1 deletion routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["RequireSimpleMDE"] = true
ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(models.UnitTypeProjects)
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
upload.AddUploadContext(ctx, "comment")
upload.AddUploadContext(ctx, "editcomment")

if err = issue.LoadAttributes(); err != nil {
ctx.ServerError("LoadAttributes", err)
Expand Down
8 changes: 5 additions & 3 deletions templates/repo/issue/view_content.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,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 dropzone-attachments">
{{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"}}</span>
<span class="ui image">{{svg "octicon-file"}}</span>
{{else}}
<span class="ui image">{{svg "octicon-desktop-download"}}</span>
{{end}}
Expand Down
1 change: 1 addition & 0 deletions templates/repo/upload.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div
class="ui dropzone"
id="dropzone"
data-link-url="{{.UploadLinkUrl}}"
data-upload-url="{{.UploadUrl}}"
data-remove-url="{{.UploadRemoveUrl}}"
data-accepts="{{.UploadAccepts}}"
Expand Down
30 changes: 19 additions & 11 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ async function initRepository() {
dz.removeAllFiles(true);
$files.empty();
$.each(data, function () {
const imgSrc = `${$dropzone.data('upload-url')}/${this.uuid}`;
const imgSrc = `${$dropzone.data('link-url')}/${this.uuid}`;
dz.emit('addedfile', this);
dz.emit('thumbnail', this, imgSrc);
dz.emit('complete', this);
Expand Down Expand Up @@ -976,7 +976,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 @@ -996,20 +998,26 @@ async function initRepository() {
$renderContent.html(data.content);
}
const $content = $segment.parent();
if (!$content.find('.ui.small.images').length) {
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').parent().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');
renderMarkdownContent();
});
});
Expand Down