-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposterize.js
130 lines (111 loc) · 3.73 KB
/
posterize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Users = new Meteor.Collection("users");
Posters = new Meteor.Collection("posters");
if (Meteor.isClient) {
//temp user name
Session.set('current_user', "Joe");
Template.people.users = function () {
return Users.find({});
};
Template.posters.posters = function () {
return Posters.find({});
};
// remove a poster
Template.posters.events({
'click': function () {
Meteor.call('removePoster', this.file);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
Meteor.methods({
// login call
// true on success, false otherwise
login: function ( username, pw ) {
user = Users.find({user: username});
if (user.user == username && user.pw == pw) {
Session.set('current_user', user);
return true;
}
return false;
},
// create a new account
createAccount: function( username, pw ) {
if (Users.find({user: username}).count() === 0) {
Users.insert({user: username, pw: pw});
}
},
// add a poster entry with username as owner
addPoster: function( username, filename ) {
Posters.insert({owner: username, file: filename});
},
// remove poster entry
removePoster: function( filename ) {
Posters.remove({file: filename});
},
// Edit a poster
// must resend all info in order to be updated
// where is a GeoJSON operator: http://docs.mongodb.org/manual/reference/glossary/#term-geojson
addPosterInfo: function( filename, title, tags, where, date, time, notes ) {
Posters.update(
{file: filename},
{$set: {title: title,
tags: tags,
where: where,
date: date,
time: time,
notes: notes
}
});
console.log(Posters.find({file: filename}));
},
// get all the info about a poster
// returns a map of the data
getPosterInfo: function ( filename ) {
var poster = Posters.find({file: filename});
return {title: poster.title,
tags: poster.tags,
where: poster.where,
date: poster.date,
time: poster.time,
notes: poster.notes
};
},
// mine is a bool specifying whether searching all/mine
// where has a longitude and latitude field
// within is in miles
search: function ( username, mine, tags, where, within, start_date, end_date ) {
if ( mine ) {
var with_mine = Posters.find({ owner: username });
} else {
var with_mine = Posters.find({});
}
var with_date = with_mine.find({$and: [ {date: {$gte: start_date}}, {date: {$lte: end_date}} ] });
var with_tags = with_date.find({tags: {$in: tags}});
var with_where = with_tags.find({
where: {
$near : {
$geometry : {
type : "Point" ,
coordinates : [ where.longitude , where.latitude ]
},
$maxDistance : within
}
}
});
}
});
//temp testing data
Users.remove({});
Posters.remove({});
if (Users.find({}).count() === 0) {
Users.insert({user: "DavidKarger", pw: "hello"});
Posters.insert({owner: "DavidKarger", file: "/posters/poster69.jpg"});
Users.insert({user: "RobMiller", pw: "hello"});
Posters.insert({owner: "RobMiller", file: "/posters/newhope.jpg"});
Users.insert({user: "Joe", pw: "hello"});
Posters.insert({owner: "Joe", file: "/posters/JamSession.JPG"});
Posters.insert({owner: "Joe", file: "/posters/BallRoomDance.JPG"});
}
});
}