Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ var Images = new FilesCollection({
}
})

// if you want to make use of dburles:mongo-collection-instances
// you need to create a 'parent' reference to the underlying collection
Images.collection.filesCollection = Images;

if (Meteor.isClient) {
Meteor.subscribe('files.images.all');
}
Expand All @@ -44,7 +48,8 @@ if (Meteor.isServer) {
});
}
```
__Note:__ `Images` variable must be attached to *Global* scope. And has same name (*case-sensitive*) as `collectionName` option passed into `FilesCollectio#insert({collectionName: 'Images'})` method, `Images` in our case.
__Note:__ If you don't use Mongo Collection instances, then the `Images` variable must be attached to *Global* scope. And has same name (*case-sensitive*) as `collectionName` option passed into `FilesCollection#insert({collectionName: 'Images'})` method, `Images` in our case.


- Define your schema and set the `autoform` property like in the example below
```javascript
Expand Down
21 changes: 17 additions & 4 deletions lib/client/fileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import { Meteor } from 'meteor/meteor';
import { AutoForm } from 'meteor/aldeed:autoform';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { Mongo } from 'meteor/mongo';

Template.afFileUpload.onCreated(function () {
if (!this.data) {
this.data = {
atts: {}
};
}

this.collection = Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
console.log(this.data);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sry for this, removed all others but that :-/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove it by additional commit, no need to send PR, it will go to this PR

this.collection = Mongo.Collection.get
? Mongo.Collection.get(this.data.atts.collection).filesCollection
: Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
this.uploadTemplate = this.data.atts.uploadTemplate || null;
this.previewTemplate = this.data.atts.previewTemplate || null;

Expand Down Expand Up @@ -44,7 +47,11 @@ Template.afFileUpload.helpers({
return Template.instance().fileId.get() || this.value;
},
uploadedFile() {
return global[Template.instance().collectionName()].findOne({
var collectionName = Template.instance().collectionName();
var collection = Mongo.Collection.get
? Mongo.Collection.get(collectionName).filesCollection
: global[collectionName];
return collection.findOne({
_id: Template.instance().fileId.get() || this.value
});
}
Expand All @@ -68,7 +75,13 @@ Template.afFileUpload.events({
},
'change [data-files-collection-upload]'(e, template) {
if (e.currentTarget.files && e.currentTarget.files[0]) {
var upload = global[template.collectionName()].insert({

var collectionName = template.collectionName();
var collection = Mongo.Collection.get
? Mongo.Collection.get(collectionName)
: global[template.collectionName()];

var upload = collection.filesCollection.insert({
file: e.currentTarget.files[0],
streams: 'dynamic',
chunkSize: 'dynamic'
Expand Down
3 changes: 2 additions & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package.describe({
name: 'ostrio:autoform-files',
summary: 'File upload for AutoForm using ostrio:files',
description: 'File upload for AutoForm using ostrio:files',
version: '2.0.1',
version: '2.0.2',
git: 'https://github.com/VeliovGroup/meteor-autoform-file.git'
});

Expand All @@ -13,6 +13,7 @@ Package.onUse(function(api) {
'check',
'ecmascript',
'underscore',
'mongo',
'reactive-var',
'templating',
'aldeed:[email protected]',
Expand Down