-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCentraleYo.js
More file actions
397 lines (359 loc) · 12.8 KB
/
CentraleYo.js
File metadata and controls
397 lines (359 loc) · 12.8 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
Compteur = new Mongo.Collection("compteur"); //servira à contenir le nb de clics
Plat = new Mongo.Collection("plat"); //servira à contenir les plats
Pizza = new Mongo.Collection("pizza");
Adminneb = new Mongo.Collection("adminneb");
Beer = new Mongo.Collection("Beer");
Adminyo = new Mongo.Collection("adminyo");
Admintheodo = new Mongo.Collection("admintheodo");
Router.route('home', {path:'/'});
Router.route('admin', {path:'/adminyo'});
Router.route('adminneb', {path:'/adminneb'});
Router.route('admintheodo', {path:'/admintheodo'});
var isButtonEnabled = function(){
var resetDate = Compteur.findOne().resetDate;
if (!resetDate)
return Meteor.userId() && !Meteor.user().clickDate;
return Meteor.userId() && (!Meteor.user().clickDate || Meteor.user().clickDate < resetDate);
};
Meteor.methods({
getCounter: function() {
return Compteur.findOne().compt;
},
increment: function(){
if (!Meteor.userId())
return;
if (!isButtonEnabled())
return;
Meteor.users.update({_id:Meteor.user()._id}, {$set:{"clickDate":Date()}});
var count = Compteur.findOne().compt;
count++;
Compteur.update({}, { $set: { compt: count}}); //on incrémente le compteur
return count;
},
raz: function(){
Compteur.update({}, {$set: {compt: 0, resetDate: Date()}}); //on incrémente le compteur
},
config:function(){
ServiceConfiguration.configurations.remove({service:'myecp'});
ServiceConfiguration.configurations.insert({
service:'myecp',
appId:'44_4a0dp01spse804ok4kwc44ccc0w8000sc0ocog8w8cc48040c0',
secret:"4v0puc9sdh8gs4k8wsscw4gkggw0ocwks84os4s8kgkoosw4wo"
});
},
checkPlat: function(platId, setChecked){
Plat.update(platId, { $set: { checked: setChecked}});
},
checkBeer: function(BeerId, setChecked){
Beer.update(BeerId, { $set: { checked: setChecked}});
},
checkPizza: function(pizzaId, setChecked){
Pizza.update(pizzaId, { $set: { checked: setChecked} });
},
connectAdmin: function(mail,psw){
if (/@theodo\.fr$/.test(mail) && Admintheodo.find({mdp : psw }).fetch().length != 0){
Session.setPersistent("isAdminTheodo", true);
var prenom = mail.split(/.@theodo.fr/)[0];
Session.setPersistent("adminTheodoName", prenom.charAt(0).toUpperCase() + prenom.substring(1).toLowerCase());
}
},
getHomePage: function(page){
if(typeof Session.get("homePage") == 'undefined'){
Session.setPersistent("homePage", page);
}
else{
Session.update("homePage", page);
}
}
});
if(Meteor.isServer) {
Accounts.onCreateUser(function(options, user)
{
user.clickDate = null
return user;
});
if (!Compteur.findOne())
{
Compteur.insert({compt:0, resetDate: Date()});
}
if (!Plat.findOne()){
Plat.insert({name:"Tout à 2 euros"});
Plat.insert({name:"Tartiflette"});
Plat.insert({name:"Poulet Curry"});
Plat.insert({name:"Gnocci chevre epinard"});
Plat.insert({name:"Poulet pates champi"});
Plat.insert({name:"Risotto"});
Plat.insert({name:"Lasagne"});
Plat.insert({name:"Poulet basquaise"});
Plat.insert({name:"Chili con carne"});
Plat.insert({name:"Tajine de poulet"});
Plat.insert({name:"Poulet teriyaki"});
Plat.insert({name:"Raviolis ricotta épinard"});
Plat.insert({name:"Poulet sauce citron purée de patates douces"});
}
if (!Pizza.findOne()) {
Pizza.insert({name:"Kebab", price:2.5});
Pizza.insert({name:"Royale", price:2.5});
Pizza.insert({name:"Saumon", price:3.5});
Pizza.insert({name:"Tomate mozzarella", price:2.5});
Pizza.insert({name:"Boeuf chorizo", price:4});
Pizza.insert({name:"4 Fromages", price:3.5});
Pizza.insert({name:"Tartiflette", price:3});
Pizza.insert({name:"Jambon speck", price:4});
Pizza.insert({name:"Campagnarde", price:3});
Pizza.insert({name:"Poulet moutarde", price:3});
Pizza.insert({name:"Chorizo", price:3});
Pizza.insert({name:"Chévre", price:3});
Pizza.insert({name:"Chévre miel", price:4});
}
if (!Adminneb.findOne()) {
Adminneb.insert({mail:"erwan.le-jumeau-de-kergaradec@student.ecp.fr"});
Adminneb.insert({mail:"valentine.joseph@student.ecp.fr"});
Adminneb.insert({mail:"maxime.dieudonne@student.ecp.fr"});
Adminneb.insert({mail:"valentin.condette@student.ecp.fr"});
Adminneb.insert({mail:"edouard.borel@student.ecp.fr"});
Adminneb.insert({mail:"henri.desesquelles@student.ecp.fr"});
Adminneb.insert({mail:"achraf.gharbi@student.ecp.fr"});
Adminneb.insert({mail:"thomas.walter@student.ecp.fr"});
Adminneb.insert({mail:"laurent.lin@student.ecp.fr"});
Adminneb.insert({mail:"gabrielle.rappaport@student.ecp.fr"});
Adminneb.insert({mail:"thomas.bellec@student.ecp.fr"});
}
if(!Beer.findOne()) {
Beer.insert({name:"Kro (Pinte)",price:2.5});
Beer.insert({name:"Cidre (Pinte)",price:2});
Beer.insert({name:"Bière du mois (Pinte)",price:3.5});
Beer.insert({name:"Tigre bock (Bouteille)",price:1.2});
Beer.insert({name:"1664 blanche (Bouteille)",price:2});
Beer.insert({name:"1664 (canette)",price:1});
Beer.insert({name:"Adelscott (Bouteille)",price:2.5});
Beer.insert({name:"Carlsberg (Bouteille)",price:1.9});
Beer.insert({name:"BChouffe (Bouteille)",price:2.4});
Beer.insert({name:"Corona (Bouteille)",price:2.4});
Beer.insert({name:"Cuvée des trolls 7° (Bouteille)",price:1.6});
Beer.insert({name:"Delirium 8.5° (Bouteille)",price:2.6});
Beer.insert({name:"Desperados 5.9° (Bouteille)",price:2.3});
Beer.insert({name:"Heineken 5° (Bouteille)",price:1.6});
Beer.insert({name:"Hoegaarden 4,9° (Bouteille)",price:1.8});
Beer.insert({name:"Karmeliet triple (Bouteille)",price:2});
Beer.insert({name:"Kasteel blonde (Bouteille)",price:2});
Beer.insert({name:"Kasteel brune 11° (Bouteille)",price:2.2});
Beer.insert({name:"Kwak 8,4° (Bouteille)",price:1.6});
Beer.insert({name:"Pêcheresse 2,5° (Bouteille)",price:1.6});
Beer.insert({name:"Queue de charrue (Bouteille)",price:1.7});
Beer.insert({name:"Skoll 6° (Bouteille)",price:1.6});
Beer.insert({name:"Trappiste 8° (Bouteille)",price:2.6});
Beer.insert({name:"Trappsite 10° (Bouteille)",price:3.4});
Beer.insert({name:"Coca Cola (Bouteille)",price:1.2});
Beer.insert({name:"Scweppes (Bouteille)",price:1});
Beer.insert({name:"Twist (Bouteille)",price:1});
}
if (!Adminyo.findOne()) {
Adminyo.insert({mail:"thomas.walter@student.ecp.fr"});
Adminyo.insert({mail:"achraf.gharbi@student.ecp.fr"});
Adminyo.insert({mail:"laurent.lin@student.ecp.fr"});
Adminyo.insert({mail:"gabrielle.rappaport@student.ecp.fr"});
Adminyo.insert({mail:"thomas.bellec@student.ecp.fr"});
}
Meteor.publish("compteur", function() {
return Compteur.find({});
});
Meteor.publish("userData", function () {
return Meteor.users.find({_id: this.userId});
});
Meteor.publish("plat", function() {
return Plat.find({});
});
Meteor.publish("pizza", function() {
return Pizza.find({});
});
Meteor.publish("Beer", function() {
return Beer.find({});
});
Meteor.publish("adminneb", function() {
return Adminneb.find({});
});
Meteor.publish("adminyo", function() {
return Adminyo.find({});
});
Meteor.publish("admintheodo", function() {
return Admintheodo.find({});
});
Meteor.call("config");
}
if (Meteor.isClient) {
Push.enabled(true);
Meteor.subscribe("compteur");
Meteor.subscribe("userData");
Meteor.subscribe("plat");
Meteor.subscribe("Beer");
Meteor.subscribe("pizza");
Meteor.subscribe("adminneb");
Meteor.subscribe("adminyo");
Meteor.subscribe("admintheodo");
Template.registerHelper('counter', function () {
return Compteur.findOne().compt;
});
Template.Home.onRendered(function()
{
var template = this;
Meteor.call("getCounter", function(error, result)
{
template.clock = new FlipClock($('.clock'), result, {
clockFace: 'Counter'
});
});
Compteur.find().observeChanges({
changed:function(id, fields)
{
template.clock.setValue(fields.compt);
}
});
}
);
if(typeof Session.get("homePage") == 'undefined'){ Session.setPersistent("homePage","home");} //Par défaut on est sur l'onglet home du Home.
Template.Home.helpers({
counterOver: function(value) { //regarde si le nb de clics > value
return Compteur.findOne().compt >= value;
},
counterInbetween: function(valueinf, valuesup) { //regarde si le nb de clics > value
return (Compteur.findOne().compt >= valueinf) && (Compteur.findOne().compt < valuesup);
},
counterExact: function(value, etat) { //regarde si le nb de clics = value
return Compteur.findOne().compt == value;
},
isConnected :function(){
return Meteor.userId() || Session.get("isAdminTheodo"); //si l'utilisateur est adminTheodo alors il peut se connecter
},
userName : function(){
var name = (Session.get("isAdminTheodo")) ? Session.get("adminTheodoName"):Meteor.user().services.myecp.first_name;
return name;
},
affichePlat : function(){
return Plat.find({checked: true});
},
affichePizza : function(){
return Pizza.find({checked: true});
},
afficheBeer : function(){
return Beer.find({checked: true});
},
isButtonActivated : function() {return isButtonEnabled();},
isHomePageHome: function() {return Session.get("homePage") == "home" ;},
isHomePageBeer: function() {return Session.get("homePage") == "beer" ;},
isHomePageCutlery: function() {return Session.get("homePage") == "cutlery" ;},
isMeteorConnected: function() {return Meteor.status().connected; }
});
Template.Home.events({ //on appelle la méthode increment pour incrémenter le compteur
"click .neb" : function (event, template) {
Meteor.call("increment", function(error, result)
{
template.clock.setValue(result)
});
},
"click .fa-beer" : function (event){
Meteor.call("getHomePage", "beer");
},
"click .fa-home" : function (event){
Meteor.call("getHomePage", "home");
},
"click .fa-cutlery" : function (event){
Meteor.call("getHomePage", "cutlery");
},
"click #myecp-login": function(event, template){
Meteor.loginWithMyECP({loginStyle: "redirect"}, function(err){
if (err) {
throw new Meteor.Error(err);
} else {
throw new Meteor.Error("LOL");
}});
}
});
Template.Admin.helpers({
isAdminYo: function(){
return ((Meteor.userId() && Adminyo.find({mail : Meteor.user().services.myecp.mail}).fetch().length != 0)
|| Session.get('isAdminTheodo')); //Si l'utilisateur est adminTheodo alors il est adminYo
}
});
Template.Admin.events({
"click .neb" : function(event) {
event.preventDefault();
Meteor.call("increment");
},
"click .raz" : function (event) {
event.preventDefault();
Meteor.call("raz");
},
"submit .adminform":function(event){
event.preventDefault();
Meteor.call("serverNotification", event.target.textarea.value, "Centrale YO");
},
"click #myecp-login": function(event, template){
Meteor.loginWithMyECP({loginStyle: "redirect"}, function(err){
if (err) {
throw new Meteor.Error(err);
} else {
throw new Meteor.Error("LOL");
}});
}
});
Template.Adminneb.helpers({
isAdminNeb: function(){
return ((Meteor.userId() && Adminneb.find({mail : Meteor.user().services.myecp.mail}).fetch().length != 0)
|| Session.get('isAdminTheodo')); //Si l'utilisateur est adminTheodo alors il est adminBar
},
listPizza: function(){
return Pizza.find({});
},
listPlat: function(){
return Plat.find({});
},
listBeer: function(){
return Beer.find({});
}
});
Template.Adminneb.events({
"submit .adminform":function(event){
event.preventDefault();
Meteor.call("serverNotification", event.target.textarea.value, "Centrale YO");
},
"click .pizza-check":function(event){
event.preventDefault();
Meteor.call("checkPizza", this._id, ! this.checked);
},
"click .plat-check":function(event){
event.preventDefault();
Meteor.call("checkPlat", this._id, ! this.checked);
},
"click #myecp-login": function(event, template){
Meteor.loginWithMyECP({loginStyle: "redirect"}, function(err){
if (err) {
throw new Meteor.Error(err);
} else {
throw new Meteor.Error("LOL");
}});
},
"click .beer-check":function(event){
event.preventDefault();
Meteor.call("checkBeer", this._id, ! this.checked);
}
});
Template.Admintheodo.helpers({
isAdminTheodo : function(){
return Session.get('isAdminTheodo');
},
adminTheodoName : function(){
return Session.get('adminTheodoName');
}
});
Template.Admintheodo.events({
"submit .connectform":function(event){
event.preventDefault();
Meteor.call("connectAdmin",event.target.textinput.value,event.target.passwordinput.value);
},
"submit .adminform":function(event){
event.preventDefault();
Meteor.call("serverNotification", event.target.textarea.value, "Centrale YO");
}
});
}