Uploaded done, but uploading not

reviewable/pr3090/r1
Romulus Urakagi Tsai 6 years ago
parent 4dcdec0084
commit 6cdd464f54
  1. 2
      client/components/cards/attachments.jade
  2. 26
      client/components/cards/attachments.js
  3. 2
      client/components/cards/minicard.jade
  4. 3
      client/components/cards/minicard.js
  5. 16
      client/lib/utils.js
  6. 6
      models/attachments.js
  7. 3
      models/cards.js

@ -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

@ -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);
}

@ -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

@ -32,4 +32,7 @@ Template.minicard.helpers({
hiddenMinicardLabelText() {
return Meteor.user().hasHiddenMinicardLabelText();
},
coverUrl() {
return Attachments.findOne(this.coverId).link();
},
});

@ -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

@ -2,9 +2,12 @@ import { FilesCollection } from 'meteor/ostrio:files';
Attachments = new FilesCollection({
storagePath: storagePath(),
debug: true, // FIXME: Remove debug mode
debug: false, // FIXME: Remove debug mode
collectionName: 'attachments2',
allowClientCode: true, // FIXME: Permissions
onAfterUpload: (fileRef) => {
Attachments.update({_id:fileRef._id}, {$set: {"meta.uploaded": true}});
}
});
if (Meteor.isServer) {
@ -15,6 +18,7 @@ if (Meteor.isServer) {
// TODO: Permission related
// TODO: Add Activity update
// TODO: publish and subscribe
Meteor.publish('attachments', function() {
return Attachments.find().cursor;
});

@ -460,11 +460,10 @@ Cards.helpers({
{ sort: { uploadedAt: -1 } },
);
} else {
const ret = Attachments.find(
let ret = Attachments.find(
{ 'meta.cardId': this._id },
{ sort: { uploadedAt: -1 } },
);
if (ret.first()) console.log('link', Attachments.link(ret.first()));
return ret;
}
},

Loading…
Cancel
Save