mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
parties: use transform to make "attending" a method
This commit is contained in:
@@ -33,7 +33,7 @@ Template.details.creatorName = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Template.details.canRemove = function () {
|
Template.details.canRemove = function () {
|
||||||
return this.owner === Meteor.userId() && attending(this) === 0;
|
return this.owner === Meteor.userId() && this.attending() === 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Template.details.maybeChosen = function (what) {
|
Template.details.maybeChosen = function (what) {
|
||||||
@@ -131,7 +131,7 @@ Template.map.rendered = function () {
|
|||||||
var selected = Session.get('selected');
|
var selected = Session.get('selected');
|
||||||
var selectedParty = selected && Parties.findOne(selected);
|
var selectedParty = selected && Parties.findOne(selected);
|
||||||
var radius = function (party) {
|
var radius = function (party) {
|
||||||
return 10 + Math.sqrt(attending(party)) * 10;
|
return 10 + Math.sqrt(party.attending()) * 10;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Draw a circle for each party
|
// Draw a circle for each party
|
||||||
@@ -158,7 +158,7 @@ Template.map.rendered = function () {
|
|||||||
// Label each with the current attendance count
|
// Label each with the current attendance count
|
||||||
var updateLabels = function (group) {
|
var updateLabels = function (group) {
|
||||||
group.attr("id", function (party) { return party._id; })
|
group.attr("id", function (party) { return party._id; })
|
||||||
.text(function (party) {return attending(party) || '';})
|
.text(function (party) {return party.attending() || '';})
|
||||||
.attr("x", function (party) { return party.x * 500; })
|
.attr("x", function (party) { return party.x * 500; })
|
||||||
.attr("y", function (party) { return party.y * 500 + radius(party)/2 })
|
.attr("y", function (party) { return party.y * 500 + radius(party)/2 })
|
||||||
.style('font-size', function (party) {
|
.style('font-size', function (party) {
|
||||||
|
|||||||
@@ -13,7 +13,14 @@
|
|||||||
invited: Array of user id's that are invited (only if !public)
|
invited: Array of user id's that are invited (only if !public)
|
||||||
rsvps: Array of objects like {user: userId, rsvp: "yes"} (or "no"/"maybe")
|
rsvps: Array of objects like {user: userId, rsvp: "yes"} (or "no"/"maybe")
|
||||||
*/
|
*/
|
||||||
Parties = new Meteor.Collection("parties");
|
|
||||||
|
Parties = new Meteor.Collection("parties", {
|
||||||
|
transform: function (p) {
|
||||||
|
p.attending = function () {
|
||||||
|
return (_.groupBy(this.rsvps, 'rsvp').yes || []).length;
|
||||||
|
};
|
||||||
|
return p;
|
||||||
|
}});
|
||||||
|
|
||||||
Parties.allow({
|
Parties.allow({
|
||||||
insert: function (userId, party) {
|
insert: function (userId, party) {
|
||||||
@@ -37,15 +44,11 @@ Parties.allow({
|
|||||||
remove: function (userId, parties) {
|
remove: function (userId, parties) {
|
||||||
return ! _.any(parties, function (party) {
|
return ! _.any(parties, function (party) {
|
||||||
// deny if not the owner, or if other people are going
|
// deny if not the owner, or if other people are going
|
||||||
return party.owner !== userId || attending(party) > 0;
|
return party.owner !== userId || party.attending() > 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var attending = function (party) {
|
|
||||||
return (_.groupBy(party.rsvps, 'rsvp').yes || []).length;
|
|
||||||
};
|
|
||||||
|
|
||||||
Meteor.methods({
|
Meteor.methods({
|
||||||
// options should include: title, description, x, y, public
|
// options should include: title, description, x, y, public
|
||||||
createParty: function (options) {
|
createParty: function (options) {
|
||||||
|
|||||||
Reference in New Issue
Block a user