filter-collections icon indicating copy to clipboard operation
filter-collections copied to clipboard

Not possible to use the same collection in another template?

Open lzwaan opened this issue 12 years ago • 19 comments

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

lzwaan avatar Jan 27 '14 21:01 lzwaan

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,

julpod avatar Jan 28 '14 07:01 julpod

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 .

lzwaan avatar Jan 28 '14 07:01 lzwaan

Thanks! Let me know if you need further help. Happy to help.

julpod avatar Jan 28 '14 08:01 julpod

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

lzwaan avatar Jan 28 '14 10:01 lzwaan

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,

julpod avatar Jan 28 '14 11:01 julpod

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?

testbird avatar Jan 28 '14 16:01 testbird

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.

julpod avatar Jan 29 '14 04:01 julpod

Izwaan, could you verify that the provided configuration worked for your use case? Let me know if you have any problem using it. Thanks,

julpod avatar Jan 29 '14 04:01 julpod

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).

testbird avatar Jan 29 '14 07:01 testbird

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

lzwaan avatar Jan 30 '14 10:01 lzwaan

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.

testbird avatar Jan 30 '14 11:01 testbird

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.

testbird avatar Jan 30 '14 11:01 testbird

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 .

lzwaan avatar Jan 30 '14 12:01 lzwaan

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.

testbird avatar Jan 30 '14 13:01 testbird

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

julpod avatar Jan 30 '14 14:01 julpod

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.

testbird avatar Jan 30 '14 16:01 testbird

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).

testbird avatar Jan 30 '14 23:01 testbird

The implementation steps may begin like this:

  1. Let the filter helpers query a collection determined by the FilterCollections instance.
  2. Remove all skip options to scopes that sync to shared collections.
  3. Add an option to always use a separate collection (and use skips).
  4. Have only one FilterCollections instance that manages all filters and required scopes.
  5. Add options to change between shared and separate collections automatically

testbird avatar Jan 31 '14 00:01 testbird

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).

testbird avatar Jan 31 '14 08:01 testbird