Not possible to use the same collection in another template?
When i want to use my collection "Sites" on another page (template) but i get: Uncaught Error: There is already a collection named 'sitesCountFC'
template 1 javascript file:
SitesFilter = new Meteor.FilterCollections(Sites, { template: 'siteList', pager: { itemsPerPage: 40 }, sort: { order: ['asc', 'desc'], defaults: [ ['siteid', 'asc'] ] }, filters: { siteid: { title: 'Site ID', operator: ['$regex', 'i'], condition: '$or', searchable: 'required' }, site: { title: 'Site Naam', operator: ['$regex', 'i'], condition: '$or', searchable: 'required' }, plaats: { title: 'Plaats', operator: ['$regex', 'i'], condition: '$or', searchable: 'required' } }, callbacks: { beforeSubscribe: function (query) { NProgress.start(); }, afterSubscribe: function (subscription) { NProgress.done(); } } });
template 2 javascript file:
rfcFilter = new Meteor.FilterCollections(Sites, { template: 'rfcAdd', pager: { itemsPerPage: 40 }, sort: { order: ['asc', 'desc'], defaults: [ ['siteid', 'asc'] ] }, filters: { siteid: { title: 'Site ID', operator: ['$regex', 'i'], condition: '$or', searchable: 'required' }, site: { title: 'Site Naam', operator: ['$regex', 'i'], condition: '$or', searchable: 'required' }, plaats: { title: 'Plaats', operator: ['$regex', 'i'], condition: '$or', searchable: 'required' } } });
Hi lzwaan,
Right on target. I've added to the last commit a new feature allowing the subscriber and publisher methods to have a "name" property. If you setup same value on both, you should be able to have N numbers of Filter Collections instances sharing the same Meteor.Collection.
I've also updated README.md to describe the new feature.
Let me know if this fix your issue. Thanks,
Thx mate for your quick respons I love your tool!
Gr.....Lars
Op 28 jan. 2014 om 08:27 heeft julianmontagna [email protected] het volgende geschreven:
Hi lzwaan,
Right on target. I've added to the last commit a new feature allowing the subscriber and publisher methods to have a "name" property. If you setup same value on both, you should be able to have N numbers of Filter Collections instances sharing the same Meteor.Collection.
I've also updated README.md to describe the new feature.
Let me know if this fix your issue. Thanks,
Reply to this email directly or view it on GitHubhttps://github.com/julianmontagna/filter-collections/issues/11#issuecomment-33456476 .
Thanks! Let me know if you need further help. Happy to help.
Julian, how should i used it? something like this:
/server/server.js
Meteor.FilterCollections.publish(Sites, { name: 'rfccollection' });
/lib/collections.js (/lib)
Rfc = new Meteor.Collection('rfccollection');
/client/views/rfc-add.js
RfcFilter = new Meteor.FilterCollections(Rfc, {
2014-01-28 julianmontagna [email protected]
Thanks! Let me know if you need further help. Happy to help.
Reply to this email directly or view it on GitHubhttps://github.com/julianmontagna/filter-collections/issues/11#issuecomment-33459188 .
Met vriendelijke groet,
Lars Zwaan
Something like that:
/** /lib/collections.js **/
Rfc = new Meteor.Collection('rfccollection');
/** /server/server.js **/
Meteor.FilterCollections.publish(Rfc, {
name: 'someName'
});
Meteor.FilterCollections.publish(Rfc, {
name: 'anotherName'
});
/** /client/views/rfc-add.js **/
RfcFilter = new Meteor.FilterCollections(Rfc, {
name: 'someName',
// package setup one
});
RfcFilter = new Meteor.FilterCollections(Rfc, {
name: 'anotherName',
// package setup two
});
The publisher and subscriber are attached through 'name' property so for both methods should be the same value. Let me know if this helps. Thanks,
Just found this. Doesn't sharing the same collection for multiple filters also come with the same problem of possibly disturbing the skip/limit pagination selection of each other? Or are you internally already setting up separate client collections for them?
Each fc instance has its own subscription and publisher that works with (but independently) the provided collection. If you work with the template property, once the template is destroyed, the subscription is stopped.
When using the name property, that will define a new subscription scope for that instance with a new publisher so there should be no disturbing skip/limit when using multiple instances over the same collection.
Izwaan, could you verify that the provided configuration worked for your use case? Let me know if you have any problem using it. Thanks,
I'm a little puzzled now. Don't you get false skips when you have another regular subscription running for that collection, for example to hold some documents in the cache or when you set up two fc instances on the same page?
For example, if this is the example data set in the server collection: 1c 2a 3b Subscribing to both sort orders and skipping the first for each, will sync: 2a 3b 1c On the client, according to the subscribed numeric scope the first local in numeric order should be the second from the whole data set. But actually fetching the first numeric from the local collection returns the first from the whole data set (1c), instead of the expected second (2a).
(Edited:) That's why I hope FC may be able to work with the regular local collection in a compatible way, i.e. without making and assuming skipping subscriptions. And set up separate isolated local collections when subscribing to paginated (skip reduced) scopes becomes necessary (if the limit on a shared (non-skipping) subscription would get too large).
When using the name property, so you can use it on another template works not completely. Example: On my first template i search for a address (as an example) and that is working fine. On my 2nd template i use the same collection with the name property and search also for the address, but now it only finds a part of the collection, which is exacly the same as the results of template 1. I am unable to reset the filter.
In your description where you have an example how to search and clear via a button works fine. I like the idea of remembering the filter when you skip to another page and when you are go back you still can see the search query in the input field with the results below.
Is it possible to reset the filter on another page when i have to search through the whole collection for something else ?
Hopefully i explained my issue, otherwise i can sent some screenshots....
I like the idea of remembering the filter when you skip to another page and when you are go back you still can see the search query in the input field with the results below.
That is part of the point that I was trying to make. Each page (more explicitly c-f instance) will have to sync (subscribe) updates to a separate local-only collection(https://github.com/julianmontagna/filter-collections/issues/6#issuecomment-33528174) instead of sharing one or using the usual shared minimongo collection caches, IF the requested scope (#9) includes skips.
Without skips, it is good to sync different scopes to the same local collection, as this requires only one instance of a local document. For this to work, pages (f-c instances) need to keep other scope subscribtions running (in parallel), and only set up, adapt, and tear down its own scope subscription that is required to render its results.
So how to use it without skip?
Gr.....Lars
Op 30 jan. 2014 om 12:27 heeft testbird [email protected] het volgende geschreven:
Without skips, it is good to sync different scopes to the same collection, as this requires only one instance of a local document. For this to work pages (f-c instances) need to keep other scope subscribtions running (in parallel), and only change the scope subscription required to render its own results.
Reply to this email directly or view it on GitHubhttps://github.com/julianmontagna/filter-collections/issues/11#issuecomment-33679675 .
As far as I understood, filter-collections currently always pass on the skip to the server (scope), and sync the regular minimongo collections with these subscriptions (instead of separate collections). The result is that one can not assume that the skip of requested sort scopes is valid for the local collection, as soon as there is more than one subscription running.
So how to use it without skip?
You would have to patch f-c to only make subscriptions without skip options (when using the minimongo cache), and do the skip (pagination) only in template helpers' find()s on the shared local collection cache. And to let different subscriptions be active at the same time.
But if you need to keep the volume of the local pagination cache lower than the limit, you will need to patch f-c to subscribe to such scopes syncing to separate local collections.
I've tested the use case and finally understood the issue (later but at last :P).
As testbird says right, the solution will come managing separated local collections. My idea of implementing this is to check if name property is received on the client and if so, create a new local collection and let the current instance work with that.
Let me know if this sounds OK for you guys. Thanks for all the support!
On Thu, Jan 30, 2014 at 10:51 AM, testbird [email protected] wrote:
As far as I understood, filter-collections currently always pass on the skip to the server (scope), and sync the regular minimongo collections with these subscriptions (instead of separate collections). The result is that one can not assume that the skip of requested sort scopes is valid for the local collection, as soon as there is more than one subscription running.
So how to use it without skip?
You would have to patch f-c to only make subscriptions without skip options (when using the minimongo cache), and do the skip (pagination) only in template helpers' find()s on the shared local collection cache. And to let different subscriptions be active at the same time.
But if you need to keep the volume of the local pagination cache lower than the limit, you will need to patch f-c to subscribe to such scopes syncing to separate local collections.
Reply to this email directly or view it on GitHubhttps://github.com/julianmontagna/filter-collections/issues/11#issuecomment-33688916 .
toOit Web consulting & development www.tooit.com
_Julián Esteban [email protected]* :: +*54 9 11 3468-0401
Great. :-)
I'll think about it a little. Let's see if we can find a nice universal pattern to use and switch shared and separate local caching collections.
Ok, I tried to draw up a universal pattern (https://github.com/julianmontagna/filter-collections/issues/6#issuecomment-33746565) to set up dynamic filters in templates that may be satisfied by scope subscriptions which may sync to shared or separate collections (depending on client settings or cache usage state/size).
The implementation steps may begin like this:
- Let the filter helpers query a collection determined by the FilterCollections instance.
- Remove all skip options to scopes that sync to shared collections.
- Add an option to always use a separate collection (and use skips).
- Have only one FilterCollections instance that manages all filters and required scopes.
- Add options to change between shared and separate collections automatically
The last picture in https://www.discovermeteor.com/2014/01/02/understanding-meteor-publications-and-subscriptions shows two subs on the same shared collection. In the book the subscribe() handlers are set up with waitOn in Router.configure or @route (only on demand).