Multi-File Storage.

Thanks to mfilser !

Related https://github.com/wekan/wekan/pull/4484

Merge branch 'master' into upgrade-meteor
This commit is contained in:
Lauri Ojansivu 2022-04-22 00:55:42 +03:00
commit 68e8155805
29 changed files with 921 additions and 276 deletions

View file

@ -49,17 +49,7 @@ template(name="attachmentsGalery")
if currentUser.isBoardMember
unless currentUser.isCommentOnly
unless currentUser.isWorker
if isImage
a(class="{{#if $eq ../coverId _id}}js-remove-cover{{else}}js-add-cover{{/if}}")
i.fa.fa-thumb-tack
if($eq ../coverId _id)
| {{_ 'remove-cover'}}
else
| {{_ 'add-cover'}}
if currentUser.isBoardAdmin
a.js-confirm-delete
i.fa.fa-close
| {{_ 'delete'}}
a.fa.fa-navicon.attachment-details-menu.js-open-attachment-menu(title="{{_ 'attachmentActionsPopup-title'}}")
if currentUser.isBoardMember
unless currentUser.isCommentOnly
@ -67,3 +57,31 @@ template(name="attachmentsGalery")
//li.attachment-item.add-attachment
a.js-add-attachment(title="{{_ 'add-attachment' }}")
i.fa.fa-plus
template(name="attachmentActionsPopup")
ul.pop-over-list
li
if isImage
a(class="{{#if isCover}}js-remove-cover{{else}}js-add-cover{{/if}}")
i.fa.fa-thumb-tack
if isCover
| {{_ 'remove-cover'}}
else
| {{_ 'add-cover'}}
if currentUser.isBoardAdmin
a.js-confirm-delete
i.fa.fa-close
| {{_ 'delete'}}
p.attachment-storage
| {{versions.original.storage}}
if $neq versions.original.storage "fs"
a.js-move-storage-fs
i.fa.fa-arrow-right
| {{_ 'attachment-move-storage-fs'}}
if $neq versions.original.storage "gridfs"
if versions.original.storage
a.js-move-storage-gridfs
i.fa.fa-arrow-right
| {{_ 'attachment-move-storage-gridfs'}}

View file

@ -1,23 +1,11 @@
Template.attachmentsGalery.events({
'click .js-add-attachment': Popup.open('cardAttachments'),
'click .js-confirm-delete': Popup.afterConfirm(
'attachmentDelete',
function() {
Attachments.remove(this._id);
Popup.back();
},
),
// If we let this event bubble, FlowRouter will handle it and empty the page
// content, see #101.
'click .js-download'(event) {
event.stopPropagation();
},
'click .js-add-cover'() {
Cards.findOne(this.meta.cardId).setCover(this._id);
},
'click .js-remove-cover'() {
Cards.findOne(this.meta.cardId).unsetCover();
},
'click .js-open-attachment-menu': Popup.open('attachmentActions'),
});
Template.attachmentsGalery.helpers({
@ -33,12 +21,16 @@ Template.cardAttachmentsPopup.events({
'change .js-attach-file'(event) {
const card = this;
if (event.currentTarget.files && event.currentTarget.files[0]) {
const fileId = Random.id();
const config = {
file: event.currentTarget.files[0],
fileId: fileId,
meta: Utils.getCommonAttachmentMetaFrom(card),
chunkSize: 'dynamic',
};
config.meta.fileId = fileId;
const uploader = Attachments.insert(
{
file: event.currentTarget.files[0],
meta: Utils.getCommonAttachmentMetaFrom(card),
chunkSize: 'dynamic',
},
config,
false,
);
uploader.on('uploaded', (error, fileRef) => {
@ -104,13 +96,17 @@ Template.previewClipboardImagePopup.events({
if (pastedResults && pastedResults.file) {
const file = pastedResults.file;
window.oPasted = pastedResults;
const fileId = Random.id();
const config = {
file,
fileId: fileId,
meta: Utils.getCommonAttachmentMetaFrom(card),
fileName: file.name || file.type.replace('image/', 'clipboard.'),
chunkSize: 'dynamic',
};
config.meta.fileId = fileId;
const uploader = Attachments.insert(
{
file,
meta: Utils.getCommonAttachmentMetaFrom(card),
fileName: file.name || file.type.replace('image/', 'clipboard.'),
chunkSize: 'dynamic',
},
config,
false,
);
uploader.on('uploaded', (error, fileRef) => {
@ -129,3 +125,36 @@ Template.previewClipboardImagePopup.events({
}
},
});
BlazeComponent.extendComponent({
isCover() {
const ret = Cards.findOne(this.data().meta.cardId).coverId == this.data()._id;
return ret;
},
events() {
return [
{
'click .js-confirm-delete': Popup.afterConfirm('attachmentDelete', function() {
Attachments.remove(this._id);
Popup.back(2);
}),
'click .js-add-cover'() {
Cards.findOne(this.data().meta.cardId).setCover(this.data()._id);
Popup.back();
},
'click .js-remove-cover'() {
Cards.findOne(this.data().meta.cardId).unsetCover();
Popup.back();
},
'click .js-move-storage-fs'() {
Meteor.call('moveAttachmentToStorage', this.data()._id, "fs");
Popup.back();
},
'click .js-move-storage-gridfs'() {
Meteor.call('moveAttachmentToStorage', this.data()._id, "gridfs");
Popup.back();
},
}
]
}
}).register('attachmentActionsPopup');

View file

@ -46,6 +46,9 @@
.attachment-details-actions a
display: block
&.attachment-details-menu
padding-top: 10px
.attachment-image-preview
max-width: 100px
display: block