From 6cdd464f54fca423876a27ec2a4269ae5841cdb0 Mon Sep 17 00:00:00 2001 From: Romulus Urakagi Tsai Date: Wed, 27 Nov 2019 09:40:19 +0000 Subject: Uploaded done, but uploading not --- client/components/cards/attachments.jade | 2 +- client/components/cards/attachments.js | 26 ++++++++++++++------------ client/components/cards/minicard.jade | 2 +- client/components/cards/minicard.js | 3 +++ client/lib/utils.js | 16 ++-------------- 5 files changed, 21 insertions(+), 28 deletions(-) (limited to 'client') diff --git a/client/components/cards/attachments.jade b/client/components/cards/attachments.jade index 2a96f4f4..3ce639bc 100644 --- a/client/components/cards/attachments.jade +++ b/client/components/cards/attachments.jade @@ -23,7 +23,7 @@ template(name="attachmentsGalery") each attachments .attachment-item a.attachment-thumbnail.swipebox(href="{{url}}" title="{{name}}") - if isUploaded + if isUploaded if isImage img.attachment-thumbnail-img(src="{{url}}") else diff --git a/client/components/cards/attachments.js b/client/components/cards/attachments.js index f24a7f82..7346e943 100644 --- a/client/components/cards/attachments.js +++ b/client/components/cards/attachments.js @@ -13,10 +13,10 @@ Template.attachmentsGalery.events({ event.stopPropagation(); }, 'click .js-add-cover'() { - Cards.findOne(this.cardId).setCover(this._id); + Cards.findOne(this.meta.cardId).setCover(this._id); }, 'click .js-remove-cover'() { - Cards.findOne(this.cardId).unsetCover(); + Cards.findOne(this.meta.cardId).unsetCover(); }, 'click .js-preview-image'(event) { Popup.open('previewAttachedImage').call(this, event); @@ -47,8 +47,11 @@ Template.attachmentsGalery.events({ Template.attachmentsGalery.helpers({ url() { - return Attachments.link(this); - } + return Attachments.link(this); + }, + isUploaded() { + return !!this.meta.uploaded; + }, }); Template.previewAttachedImagePopup.events({ @@ -67,13 +70,14 @@ Template.cardAttachmentsPopup.events({ 'change .js-attach-file'(event) { const card = this; const processFile = f => { - Utils.processUploadedAttachment(card, f, attachment => { - console.log('attachment', attachment); - if (attachment && attachment._id && attachment.isImage) { - card.setCover(attachment._id); + Utils.processUploadedAttachment(card, f, + (err, attachment) => { + if (attachment && attachment._id && attachment.isImage) { + card.setCover(attachment._id); + } + Popup.close(); } - Popup.close(); - }); + ); }; FS.Utility.eachFile(event, f => { @@ -169,7 +173,6 @@ Template.previewClipboardImagePopup.events({ }; if (!results.name) { // if no filename, it's from clipboard. then we give it a name, with ext name from MIME type - // FIXME: Check this behavior if (typeof results.file.type === 'string') { settings.fileName = new Date().getTime() + results.file.type.replace('.+/', ''); @@ -182,7 +185,6 @@ Template.previewClipboardImagePopup.events({ settings.meta.userId = Meteor.userId(); const attachment = Attachments.insert(settings); - // TODO: Check image cover behavior if (attachment && attachment._id && attachment.isImage) { card.setCover(attachment._id); } diff --git a/client/components/cards/minicard.jade b/client/components/cards/minicard.jade index 79672f8c..0a35bd3a 100644 --- a/client/components/cards/minicard.jade +++ b/client/components/cards/minicard.jade @@ -11,7 +11,7 @@ template(name="minicard") .handle .fa.fa-arrows if cover - .minicard-cover(style="background-image: url('{{cover.url}}');") + .minicard-cover(style="background-image: url('{{coverUrl}}');") if labels .minicard-labels each labels diff --git a/client/components/cards/minicard.js b/client/components/cards/minicard.js index 4c76db46..3ddb7e97 100644 --- a/client/components/cards/minicard.js +++ b/client/components/cards/minicard.js @@ -32,4 +32,7 @@ Template.minicard.helpers({ hiddenMinicardLabelText() { return Meteor.user().hasHiddenMinicardLabelText(); }, + coverUrl() { + return Attachments.findOne(this.coverId).link(); + }, }); diff --git a/client/lib/utils.js b/client/lib/utils.js index d667382d..8503b035 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -32,20 +32,12 @@ Utils = { } }; if (!card) { - return next(); + return onUploaded(); } let settings = { file: fileObj, streams: 'dynamic', chunkSize: 'dynamic', - onUploaded: function(error, fileObj) { - console.log('after insert', Attachments.find({}).fetch()); - if (error) { - console.log('Error while upload', error); - } else { - next(fileObj); - } - }, }; settings.meta = {}; if (card.isLinkedCard()) { @@ -58,11 +50,7 @@ Utils = { settings.meta.cardId = card._id; } settings.meta.userId = Meteor.userId(); - // FIXME: What is this? - /* if (file.original) { - file.original.name = fileObj.name; - }*/ - Attachments.insert(settings); + Attachments.insert(settings).on('end', next); }, shrinkImage(options) { // shrink image to certain size -- cgit v1.2.3-1-g7c22