Skip to content

Commit ac6a073

Browse files
authored
Merge pull request #28 from jankapunkt/master
Make use of dburles:mongo-collection-instances
2 parents c733ab7 + 328cd91 commit ac6a073

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ var Images = new FilesCollection({
3434
}
3535
})
3636

37+
// if you want to make use of dburles:mongo-collection-instances
38+
// you need to create a 'parent' reference to the underlying collection
39+
Images.collection.filesCollection = Images;
40+
3741
if (Meteor.isClient) {
3842
Meteor.subscribe('files.images.all');
3943
}
@@ -44,7 +48,8 @@ if (Meteor.isServer) {
4448
});
4549
}
4650
```
47-
__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.
51+
__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.
52+
4853

4954
- Define your schema and set the `autoform` property like in the example below
5055
```javascript

lib/client/fileUpload.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import { Meteor } from 'meteor/meteor';
33
import { AutoForm } from 'meteor/aldeed:autoform';
44
import { Template } from 'meteor/templating';
55
import { ReactiveVar } from 'meteor/reactive-var';
6+
import { Mongo } from 'meteor/mongo';
67

78
Template.afFileUpload.onCreated(function () {
89
if (!this.data) {
910
this.data = {
1011
atts: {}
1112
};
1213
}
13-
14-
this.collection = Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
14+
console.log(this.data);
15+
this.collection = Mongo.Collection.get
16+
? Mongo.Collection.get(this.data.atts.collection).filesCollection
17+
: Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
1518
this.uploadTemplate = this.data.atts.uploadTemplate || null;
1619
this.previewTemplate = this.data.atts.previewTemplate || null;
1720

@@ -44,7 +47,11 @@ Template.afFileUpload.helpers({
4447
return Template.instance().fileId.get() || this.value;
4548
},
4649
uploadedFile() {
47-
return global[Template.instance().collectionName()].findOne({
50+
var collectionName = Template.instance().collectionName();
51+
var collection = Mongo.Collection.get
52+
? Mongo.Collection.get(collectionName).filesCollection
53+
: global[collectionName];
54+
return collection.findOne({
4855
_id: Template.instance().fileId.get() || this.value
4956
});
5057
}
@@ -68,7 +75,13 @@ Template.afFileUpload.events({
6875
},
6976
'change [data-files-collection-upload]'(e, template) {
7077
if (e.currentTarget.files && e.currentTarget.files[0]) {
71-
var upload = global[template.collectionName()].insert({
78+
79+
var collectionName = template.collectionName();
80+
var collection = Mongo.Collection.get
81+
? Mongo.Collection.get(collectionName)
82+
: global[template.collectionName()];
83+
84+
var upload = collection.filesCollection.insert({
7285
file: e.currentTarget.files[0],
7386
streams: 'dynamic',
7487
chunkSize: 'dynamic'

package.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package.describe({
22
name: 'ostrio:autoform-files',
33
summary: 'File upload for AutoForm using ostrio:files',
44
description: 'File upload for AutoForm using ostrio:files',
5-
version: '2.0.1',
5+
version: '2.0.2',
66
git: 'https://github.com/VeliovGroup/meteor-autoform-file.git'
77
});
88

@@ -13,6 +13,7 @@ Package.onUse(function(api) {
1313
'check',
1414
'ecmascript',
1515
'underscore',
16+
'mongo',
1617
'reactive-var',
1718
'templating',
1819
'aldeed:autoform@6.2.0',

0 commit comments

Comments
 (0)