Ref: original & and use fileObj.meta

fileObj.meta is part of the ostrio:files API and be passed to the
constructor. This is less hacky than trying tu update a persistet object
after the fact.
This commit is contained in:
David Arnold 2020-09-14 01:07:17 -05:00 committed by Denis Perov
parent 16506e7a6a
commit e702f17c7b
10 changed files with 124 additions and 159 deletions

View file

@ -67,19 +67,19 @@ Template.cardAttachmentsPopup.events({
const uploader = Attachments.insert(
{
file: event.currentTarget.files[0],
meta: Utils.getCommonAttachmentMetaFrom(card),
chunkSize: 'dynamic',
},
false,
);
uploader.on('uploaded', (error, fileObj) => {
uploader.on('uploaded', (error, fileRef) => {
if (!error) {
if (fileObj.isImage) {
card.setCover(fileObj._id);
if (fileRef.isImage) {
card.setCover(fileRef._id);
}
Utils.addCommonMetaToAttachment(card, fileObj);
}
});
uploader.on('end', (error, fileObj) => {
uploader.on('end', (error, fileRef) => {
Popup.back();
});
uploader.start();
@ -131,28 +131,27 @@ Template.previewClipboardImagePopup.onRendered(() => {
Template.previewClipboardImagePopup.events({
'click .js-upload-pasted-image'() {
const results = pastedResults;
if (results && results.file) {
const card = this;
if (pastedResults && pastedResults.file) {
const file = pastedResults.file;
window.oPasted = pastedResults;
const card = this;
const uploader = Attachments.insert(
{
file: results.file,
fileName:
results.name || results.file.type.replace('image/', 'clipboard.'),
file,
meta: Utils.getCommonAttachmentMetaFrom(card),
fileName: file.name || file.type.replace('image/', 'clipboard.'),
chunkSize: 'dynamic',
},
false,
);
uploader.on('uploaded', (error, fileObj) => {
uploader.on('uploaded', (error, fileRef) => {
if (!error) {
if (fileObj.isImage) {
card.setCover(fileObj._id);
if (fileRef.isImage) {
card.setCover(fileRef._id);
}
Utils.addCommonMetaToAttachment(card, fileObj);
}
});
uploader.on('end', (error, fileObj) => {
uploader.on('end', (error, fileRef) => {
pastedResults = null;
$(document.body).pasteImageReader(() => {});
Popup.back();

View file

@ -160,28 +160,23 @@ BlazeComponent.extendComponent({
const currentCard = Utils.getCurrentCard();
const MAX_IMAGE_PIXEL = Utils.MAX_IMAGE_PIXEL;
const COMPRESS_RATIO = Utils.IMAGE_COMPRESS_RATIO;
const insertImage = src => {
const img = document.createElement('img');
img.src = src;
img.setAttribute('width', '100%');
$summernote.summernote('insertNode', img);
};
const processUpload = function(file) {
const uploader = Attachments.insert(
{
file,
meta: Utils.getCommonAttachmentMetaFrom(card),
chunkSize: 'dynamic',
},
false,
);
uploader.on('uploaded', (error, fileObj) => {
uploader.on('uploaded', (error, fileRef) => {
if (!error) {
if (fileObj.isImage) {
insertImage(
`${location.protocol}//${location.host}${fileObj.path}`,
);
if (fileRef.isImage) {
const img = document.createElement('img');
img.src = fileRef.link();
img.setAttribute('width', '100%');
$summernote.summernote('insertNode', img);
}
Utils.addCommonMetaToAttachment(currentCard, fileObj);
}
});
uploader.start();

View file

@ -93,7 +93,7 @@ template(name="changeAvatarPopup")
unless isSelected
a.js-delete-avatar {{_ 'delete'}}
| -
= original.name
= name
li: a.js-select-initials
.member
+userAvatarInitials(userId=currentUser._id)

View file

@ -229,13 +229,13 @@ BlazeComponent.extendComponent({
},
false,
);
uploader.on('uploaded', (error, fileObj) => {
uploader.on('uploaded', (error, fileRef) => {
if (!error) {
self.setAvatar(fileObj.path);
self.setAvatar(fileRef.path);
// self.setAvatar(this.currentData().url(this.avatarUrlOptions()));
}
});
uploader.on('error', (error, fileObj) => {
uploader.on('error', (error, fileData) => {
// XXX check for actually returned error
self.setError('avatar-too-big');
});

View file

@ -162,23 +162,21 @@ Utils = {
})
);
},
getCommonAttachmentMetaFrom(card) {
let meta;
if (card.isLinkedCard()) {
meta.boardId = Cards.findOne(card.linkedId).boardId;
meta.cardId = card.linkedId;
} else {
meta.boardId = card.boardId;
meta.swimlaneId = card.swimlaneId;
meta.listId = card.listId;
meta.cardId = card._id;
}
return meta;
},
MAX_IMAGE_PIXEL: Meteor.settings.public.MAX_IMAGE_PIXEL,
COMPRESS_RATIO: Meteor.settings.public.IMAGE_COMPRESS_RATIO,
addCommonMetaToAttachment(card, file) {
if (card.isLinkedCard()) {
file.boardId = Cards.findOne(card.linkedId).boardId;
file.cardId = card.linkedId;
} else {
file.boardId = card.boardId;
file.swimlaneId = card.swimlaneId;
file.listId = card.listId;
file.cardId = card._id;
}
file.userId = Meteor.userId();
if (file.original) {
file.original.name = file.name;
}
},
shrinkImage(options) {
// shrink image to certain size
const dataurl = options.dataurl,