perak / kitchen-examples

Meteor Kitchen examples
164 stars 115 forks source link

Invoice-Example show owner name in dataview #13

Closed smerk closed 9 years ago

smerk commented 9 years ago

Hi Perak, Thanks for your awesome work with Meteor-Kitchen. Just a quick question: How can I add profile.name of user/owner who created an invoice to dataview? I am able to show the ownerId by defining fields for the component. But I can´t figure how to show the actual name of the user/owner.

Would be great if you could give me a hint. Thanks

perak commented 9 years ago

Hi @smerk,

Try to use before_insert hook (collection object, before_insert_code). It executes server side (you cannot do it client side because your user cannot see data from other users).

So, in "before_insert_code" you need to enter something like:

var ownerData = Users.findOne({_id: doc.ownerId }); 
if(ownerData) doc.ownerName = ownerData.profile.name;
return doc;

Let me know if it helps

smerk commented 9 years ago

Hi Perak,

Thanks so much for your lightning fast reply. I am still digging into meteor - so sorry if this is a stupid question. But how would I call the field in the dataview component. I tried a couple of options, but field remains empty.

Thanks again.

perak commented 9 years ago

Hi, give me more info please. What, where, when, how :)

smerk commented 9 years ago

Great question and by answering your WWWH - I found my mistake ;) Thanks works now like a charm and I continue to be impressed by your work

perak commented 9 years ago

Great! :)

BTW, new version (v0.9.33) is now online. It's related with what you do now - document ownership.

Please take a look at http://www.meteorkitchen.com/version_history and

http://www.meteorkitchen.com/getting_started - search for "Document owner".

smerk commented 9 years ago

Awesome. Thanks for the update. Very handy for what I am doing right now.

2015-04-19 23:11 GMT+02:00 Petar Korponaić notifications@github.com:

Great! :)

BTW, new version (v0.9.33) is now online. It's related with what you do now - document ownership.

Please take a look at http://www.meteorkitchen.com/version_history and

http://www.meteorkitchen.com/getting_started - search for "Document owner".

— Reply to this email directly or view it on GitHub https://github.com/perak/kitchen-examples/issues/13#issuecomment-94315234 .

perak commented 9 years ago

Well... "owner" role doesn't work properly after update to v0.9.33 as reported here: https://github.com/perak/kitchen-site/issues/70 will be fixed in v0.9.34

:(