Skip to content

Commit 09de7fd

Browse files
author
Olivier Refalo
committed
parties
1 parent 558f070 commit 09de7fd

File tree

4 files changed

+57
-49
lines changed

4 files changed

+57
-49
lines changed

meteor.d.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,18 @@ declare module Email {
153153

154154
interface EmailMessage {
155155
from:string;
156-
to:string[];
157-
cc?:string[];
158-
bcc?:string[];
159-
replyTo:string[];
156+
157+
// damn it, this should really be string ot string[]
158+
to:any;
159+
160+
// damn it, this should really be string ot string[]
161+
cc?:any;
162+
163+
// damn it, this should really be string ot string[]
164+
bcc?:any;
165+
166+
// damn it, this should really be string ot string[]
167+
replyTo:any;
160168
subject:string;
161169
text?:string;
162170
html?:string;
@@ -368,7 +376,7 @@ declare module Meteor {
368376

369377
function user():User;
370378

371-
function users():Collection<User>;
379+
// function users():Collection<User>;
372380

373381
function userId():string;
374382

@@ -394,7 +402,7 @@ declare module Meteor {
394402

395403
find(selector?:any, options?):Cursor<T>;
396404

397-
findOne(selector, options?):T;
405+
findOne(selector?, options?):T;
398406

399407
insert(doc:T, callback?:Function);
400408

parties/client/client.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,34 @@ Meteor.startup(function () {
2121
///////////////////////////////////////////////////////////////////////////////
2222
// Party details sidebar
2323

24-
Template.details.party = function () {
24+
Template['details'].party = function () {
2525
return Parties.findOne(Session.get("selected"));
2626
};
2727

28-
Template.details.anyParties = function () {
28+
Template['details'].anyParties = function () {
2929
return Parties.find().count() > 0;
3030
};
3131

32-
Template.details.creatorName = function () {
32+
Template['details'].creatorName = function () {
3333
var owner = Meteor.users.findOne(this.owner);
3434
if (owner._id === Meteor.userId())
3535
return "me";
3636
return displayName(owner);
3737
};
3838

39-
Template.details.canRemove = function () {
39+
Template['details'].canRemove = function () {
4040
return this.owner === Meteor.userId() && attending(this) === 0;
4141
};
4242

43-
Template.details.maybeChosen = function (what) {
43+
Template['details'].maybeChosen = function (what) {
4444
var myRsvp = _.find(this.rsvps, function (r) {
4545
return r.user === Meteor.userId();
4646
}) || {};
4747

4848
return what == myRsvp.rsvp ? "chosen btn-inverse" : "";
4949
};
5050

51-
Template.details.events({
51+
Template['details'].events({
5252
'click .rsvp_yes': function () {
5353
Meteor.call("rsvp", Session.get("selected"), "yes");
5454
return false;
@@ -74,32 +74,32 @@ Template.details.events({
7474
///////////////////////////////////////////////////////////////////////////////
7575
// Party attendance widget
7676

77-
Template.attendance.rsvpName = function () {
77+
Template['attendance'].rsvpName = function () {
7878
var user = Meteor.users.findOne(this.user);
7979
return displayName(user);
8080
};
8181

82-
Template.attendance.outstandingInvitations = function () {
82+
Template['attendance'].outstandingInvitations = function () {
8383
var party = Parties.findOne(this._id);
8484
return Meteor.users.find({$and: [
8585
{_id: {$in: party.invited}}, // they're invited
8686
{_id: {$nin: _.pluck(party.rsvps, 'user')}} // but haven't RSVP'd
8787
]});
8888
};
8989

90-
Template.attendance.invitationName = function () {
90+
Template['attendance'].invitationName = function () {
9191
return displayName(this);
9292
};
9393

94-
Template.attendance.rsvpIs = function (what) {
94+
Template['attendance'].rsvpIs = function (what) {
9595
return this.rsvp === what;
9696
};
9797

98-
Template.attendance.nobody = function () {
98+
Template['attendance'].nobody = function () {
9999
return ! this.public && (this.rsvps.length + this.invited.length === 0);
100100
};
101101

102-
Template.attendance.canInvite = function () {
102+
Template['attendance'].canInvite = function () {
103103
return ! this.public && this.owner === Meteor.userId();
104104
};
105105

@@ -114,7 +114,7 @@ var coordsRelativeToElement = function (element, event) {
114114
return { x: x, y: y };
115115
};
116116

117-
Template.map.events({
117+
Template['map'].events({
118118
'mousedown circle, mousedown text': function (event, template) {
119119
Session.set("selected", event.currentTarget.id);
120120
},
@@ -192,7 +192,7 @@ Template['map'].rendered = function () {
192192
}
193193
};
194194

195-
Template.map.destroyed = function () {
195+
Template['map'].destroyed = function () {
196196
this.handle && this.handle.stop();
197197
};
198198

@@ -205,11 +205,11 @@ var openCreateDialog = function (x, y) {
205205
Session.set("showCreateDialog", true);
206206
};
207207

208-
Template.page.showCreateDialog = function () {
208+
Template['page'].showCreateDialog = function () {
209209
return Session.get("showCreateDialog");
210210
};
211211

212-
Template.createDialog.events({
212+
Template['createDialog'].events({
213213
'click .save': function (event, template) {
214214
var title = template.find(".title").value;
215215
var description = template.find(".description").value;
@@ -242,7 +242,7 @@ Template.createDialog.events({
242242
}
243243
});
244244

245-
Template.createDialog.error = function () {
245+
Template['createDialog'].error = function () {
246246
return Session.get("createError");
247247
};
248248

@@ -253,11 +253,11 @@ var openInviteDialog = function () {
253253
Session.set("showInviteDialog", true);
254254
};
255255

256-
Template.page.showInviteDialog = function () {
256+
Template['page'].showInviteDialog = function () {
257257
return Session.get("showInviteDialog");
258258
};
259259

260-
Template.inviteDialog.events({
260+
Template['inviteDialog'].events({
261261
'click .invite': function (event, template) {
262262
Meteor.call('invite', Session.get("selected"), this._id);
263263
},
@@ -267,14 +267,14 @@ Template.inviteDialog.events({
267267
}
268268
});
269269

270-
Template.inviteDialog.uninvited = function () {
270+
Template['inviteDialog'].uninvited = function () {
271271
var party = Parties.findOne(Session.get("selected"));
272272
if (! party)
273273
return []; // party hasn't loaded yet
274274
return Meteor.users.find({$nor: [{_id: {$in: party.invited}},
275275
{_id: party.owner}]});
276276
};
277277

278-
Template.inviteDialog.displayName = function () {
278+
Template['inviteDialog'].displayName = function () {
279279
return displayName(this);
280280
};

parties/model.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="../meteor.d.ts" />
2+
/// <reference path="../underscore.d.ts" />
3+
interface PartyDAO {
4+
_id?: string;
5+
owner?: string;
6+
x?: number;
7+
y?: number;
8+
title?: string;
9+
description?: string;
10+
public?: boolean;
11+
invited?: Array;
12+
rsvps?: Array;
13+
}
14+
15+
declare var Parties:Meteor.Collection<PartyDAO>;

parties/model.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference path="../meteor.d.ts"/>
22
/// <reference path="../underscore.d.ts"/>
3+
/// <reference path="model.d.ts"/>
34

45
// All Tomorrow's Parties -- data model
56
// Loaded on both the client and the server
@@ -17,21 +18,10 @@
1718
rsvps: Array of objects like {user: userId, rsvp: "yes"} (or "no"/"maybe")
1819
*/
1920

20-
interface PartyDAO {
21-
22-
_id?: string;
23-
owner?: string;
24-
x?: number;
25-
y?: number;
26-
title?: string;
27-
description?: string;
28-
public?: boolean;
29-
invited?: Array;
30-
rsvps?: Array;
31-
32-
}
21+
var attending = function(party) {
22+
return (_.groupBy(party.rsvps, 'rsvp')['yes'] || []).length;
23+
};
3324

34-
declare var Parties:Meteor.Collection<PartyDAO>;
3525
Parties = new Meteor.Collection<PartyDAO>("parties");
3626

3727
Parties.allow({
@@ -57,10 +47,6 @@ Parties.allow({
5747
}
5848
});
5949

60-
attending = function(party) {
61-
return (_.groupBy(party.rsvps, 'rsvp').yes || []).length;
62-
};
63-
6450
var NonEmptyString = Match.Where(function(x) {
6551
check(x, String);
6652
return x.length !== 0;
@@ -116,12 +102,12 @@ Meteor.methods({
116102
if (userId !== party.owner && !_.contains(party.invited, userId)) {
117103
Parties.update(partyId, { $addToSet: { invited: userId } });
118104

119-
var from = contactEmail(Meteor.users.findOne(self.userId));
120-
var to = contactEmail(Meteor.users.findOne(userId));
105+
var from:string = contactEmail(Meteor.users.findOne(self.userId));
106+
var to:string = contactEmail(Meteor.users.findOne(userId));
121107
if (Meteor.isServer && to) {
122108
// This code only runs on the server. If you didn't want clients
123109
// to be able to see it, you could move it to a separate file.
124-
Email.send(<Meteor.EmailMessage>{
110+
Email.send(<Email.EmailMessage>{
125111
from: "noreply@example.com",
126112
to: to,
127113
replyTo: from || undefined,
@@ -178,7 +164,6 @@ Meteor.methods({
178164
///////////////////////////////////////////////////////////////////////////////
179165
// Users
180166

181-
182167
// todo global
183168
var displayName = function(user:Meteor.User):string {
184169
if (user.profile && user.profile.name)

0 commit comments

Comments
 (0)