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
4 changes: 4 additions & 0 deletions .docs/angular-meteor/client/scripts/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ angular.module("meteor-angular-docs").config(['$urlRouterProvider', '$stateProvi
url: '/meteor-include',
template: UiRouter.template('api.meteor-include.html')
})
.state('api.collectionfs', {
url: '/collectionfs',
template: UiRouter.template('api.collectionfs.html')
})
.state('api.utils', {
url: '/utils',
template: UiRouter.template('api.utils.html')
Expand Down
1 change: 1 addition & 0 deletions .docs/angular-meteor/client/views/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ <h2><a href="/api">API</a></h2>
<li><a href="/api/auth">User Authentication</a></li>
<li><a href="/api/getReactively">$scope.getReactively</a></li>
<li><a href="/api/meteor-include">meteor-include directive</a></li>
<li><a href="/api/collectionfs">CollectionFS</a></li>
<li><a href="/api/utils">$meteorUtils</a></li>
<li><a href="/api/camera">$meteorCamera</a></li>
<li><a href="/api/session">$meteor.session.bind</a></li>
Expand Down
37 changes: 37 additions & 0 deletions .docs/angular-meteor/client/views/api/api.collectionfs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template name="api.collectionfs.html">
<div>
<a href="https://github.com/Urigo/angular-meteor/edit/master/.docs/angular-meteor/client/views/api/api.collectionfs.html"
class="btn btn-default btn-lg improve-button">
<i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this doc
</a>

<do-nothing>
{{#markdown}}

# CollectionFS

When working with CollectionFS we need to work differently with the `$meteor.collection` because
collectionFS collection is a bit different than `Mongo.Collection`.

To work with collectionFS we send a third argument to `$meteor.collection` which is the CollectionFS
collection so that angular-meteor can use it to save and remove files.

----

## Usage

$meteorCollection(function() {
return Images.find();
}, false, Images);

// Or

$meteorCollection(Images, false);

----

{{/markdown}}
</do-nothing>

</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
<td><a href="" class="label type-hint type-hint-object">No</a></td>
<td><a href="" class="label type-hint type-hint-boolean">True</a></td>
</tr>
<tr>
<td>updateCollection</td>
<td><a href="http://docs.meteor.com/#/full/collections" class="label type-hint type-hint-string">Meteor Collection Object</a></td>
<td><p>A collection object which will be used for updates (insert, update, delete).</p></td>
<td><a href="" class="label type-hint type-hint-object">No</a></td>
<td></td>
</tr>
</tbody>
</table>

Expand Down
4 changes: 4 additions & 0 deletions .docs/angular-meteor/public/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@
<loc>http://angularjs.meteor.com/api/utils</loc>
<priority>0.5</priority>
</url>
<url>
<loc>http://angularjs.meteor.com/api/collectionfs</loc>
<priority>0.5</priority>
</url>
</urlset>
22 changes: 11 additions & 11 deletions modules/angular-meteor-meteorCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var angularMeteorCollections = angular.module('angular-meteor.meteor-collection'
['angular-meteor.subscribe', 'angular-meteor.utils', 'diffArray']);


var AngularMeteorCollection = function (cursor, $q, $meteorSubscribe, $meteorUtils, $rootScope, $timeout) {
var AngularMeteorCollection = function (cursor, collection, $q, $meteorSubscribe, $meteorUtils, $rootScope, $timeout) {

var self = [];

Expand All @@ -14,7 +14,7 @@ var AngularMeteorCollection = function (cursor, $q, $meteorSubscribe, $meteorUti
self.__proto__.$rootScope = $rootScope;
self.__proto__.$timeout = $timeout;

self.$$collection = $meteorUtils.getCollectionByName(cursor.collection.name);
self.$$collection = angular.isDefined(collection) ? collection : $meteorUtils.getCollectionByName(cursor.collection.name);

return self;
};
Expand All @@ -41,8 +41,6 @@ AngularMeteorCollection.prototype.save = function save(docs, useUnsetModifier) {
function upsertObject(item, $q) {
var deferred = $q.defer();

item = angular.copy(item);

if (item._id) { // Performs an update if the _id property is set.
var item_id = item._id; // Store the _id in temporary variable
delete item._id; // Remove the _id property so that it can be $set using update.
Expand Down Expand Up @@ -215,24 +213,26 @@ AngularMeteorCollection.prototype.stop = function () {

angularMeteorCollections.factory('$meteorCollection', ['$q', '$meteorSubscribe', '$meteorUtils', '$rootScope', '$timeout', 'diffArray',
function ($q, $meteorSubscribe, $meteorUtils, $rootScope, $timeout, diffArray) {
return function (reactiveFunc, auto) {
return function (reactiveFunc, auto, collection) {
// Validate parameters
if (!reactiveFunc) {
throw new TypeError("The first argument of $meteorCollection is undefined.");
}
if (!(typeof reactiveFunc == "function" || reactiveFunc instanceof Mongo.Collection)) {
throw new TypeError("The first argument of $meteorCollection must be a function or a Mongo.Collection.");
if (!(typeof reactiveFunc == "function" || angular.isFunction(reactiveFunc.find))) {
throw new TypeError("The first argument of $meteorCollection must be a function or a have a find function property.");
}
auto = auto !== false;

if (reactiveFunc instanceof Mongo.Collection) {
var collection = reactiveFunc;
if (!(typeof reactiveFunc == "function")) {
var cursorFunc = reactiveFunc.find;
collection = angular.isDefined(collection) ? collection : reactiveFunc;
var originalCollection = reactiveFunc;
reactiveFunc = function() {
return collection.find({});
return cursorFunc.apply(originalCollection, [{}]);
}
}

var ngCollection = new AngularMeteorCollection(reactiveFunc(), $q, $meteorSubscribe, $meteorUtils, $rootScope, $timeout);
var ngCollection = new AngularMeteorCollection(reactiveFunc(), collection, $q, $meteorSubscribe, $meteorUtils, $rootScope, $timeout);
var realOldItems;

function setAutoBind() {
Expand Down