forked from catcount/catcount
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
executable file
·582 lines (459 loc) · 13.1 KB
/
menu.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
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
//breakfast
var scrambledeggs = {
name: "Scrambled Eggs",
calories: 210,
protein: 15,
carbs: 5,
fats: 7,
serving: "2 Eggs"
};
var bacon = {
name: "Bacon",
calories: 80,
protein: 7,
carbs: 5,
fats: 11,
serving: "1 Strip"
};
var porksausage = {
name: "Pork Sausage",
calories: 90,
protein: 8,
carbs: 5,
fats: 6,
serving: "1 Link"
};
var sweetpotatoes = {
name: "Sweet Potatoes",
calories: 110,
protein: 2,
carbs: 5,
fats: 3,
serving: "130 grams"
};
var oats = {
name: "Oats",
calories: 180,
protein: 2,
carbs: 20,
fats: 1,
serving: "40 grams"
};
var eggtaco = {
name: "Egg Taco",
calories: 170,
protein: 10,
carbs: 17,
fats: 7,
serving: "1 Taco"
}
var blueberrymuffin = {
name: "Blueberry Muffin",
calories: 230,
protein: 2,
carbs: 17,
fats: 1,
serving: "1 Muffin"
}
var tatertots = {
name: "Tater Tots",
calories: 170,
protein: 2,
carbs: 21,
fats: 9,
serving: "170 grams"
}
var biscuits = {
name: "Biscuits",
calories: 170,
protein: 4,
carbs: 15,
fats: 10,
serving: "1 Biscuit"
}
var porridge = {
name: "Porridge",
calories: 125,
protein: 2,
carbs: 23,
fats: 3,
serving: "250 grams"
}
//lunch
var grilledchicken = {
name: "Grilled Chicken",
calories: 170,
protein: 24,
carbs: 5,
fats: 4,
isVegan: false,
isVeggie: false,
isNoGluten: true,
serving: "1 Breast"
};
var porkloin = {
name: "Pork Loin",
calories: 200,
protein: 22,
carbs: 4,
fats: 8,
isVegan: false,
isVeggie: false,
isNoGluten: true,
serving: "1 Loin"
};
var rice = {
name: "Rice",
calories: 130,
protein: 1,
carbs: 10,
fats: 2,
isVegan: true,
isVeggie: true,
isNoGluten: true,
serving: "130 grams"
};
var corn = {
name: "Corn",
calories: 170,
protein: 2,
carbs: 18,
fats: 3,
isVegan: true,
isVeggie: true,
isNoGluten: true,
serving: "91 grams"
};
var zucchini = {
name: "Zucchini",
calories: 40,
protein: 0,
carbs: 5,
fats: 0,
isVegan: true,
isVeggie: true,
isNoGluten: true,
serving: "1 Zucchini, chopped"
};
var carbonara = {
name: "Carbonara",
calories: 1110,
protein: 41,
carbs: 176,
fats: 26,
serving: "150 grams"
}
var breadstick = {
name: "Breadstick",
calories: 160,
protein: 5,
carbs: 22,
fats: 6,
serving: "1 Stick"
}
var ropavieja = {
name: "Ropa Vieja",
calories: 500,
protein: 34,
carbs: 21,
fats: 28,
serving: "113 grams"
}
var hamburgerpatty = {
name: "Hamburger Patty",
calories: 210,
protein: 20,
carbs: 0,
fats: 14,
serving: "110 grams"
}
var frenchfries = {
name: "French Fries",
calories: 200,
protein: 2,
carbs: 23,
fats: 11,
serving: "80 grams"
}
//dinner
var salmon = {
name: "Salmon",
calories: 320,
protein: 23,
carbs: 8,
fats: 7,
isVegan: false,
isVeggie: false,
isNoGluten: false,
serving: "1 Fillet"
};
var alfredo = {
name: "Alfredo",
calories: 250,
protein: 6,
carbs: 32,
fats: 5,
isVegan: false,
isVeggie: true,
isNoGluten: true,
serving: "200 grams"
};
var broccoli = {
name: "Broccoli",
calories: 40,
protein: 1,
carbs: 4,
fats: 0,
isVegan: true,
isVeggie: true,
isNoGluten: true,
serving: "80 grams"
};
var pizza = {
name: "Pizza",
calories: 320,
protein: 11,
carbs: 23,
fats: 17,
isVegan: false,
isVeggie: true,
isNoGluten: false,
serving: "1 Slice"
};
var greenbeans = {
name: "Green Beans",
calories: 20,
protein: 1,
carbs: 3,
fats: 1,
isVegan: true,
isVeggie: true,
isNoGluten: true,
serving: "110 grams"
};
var friedrice = {
name: "Fried Rice",
calories: 220,
protein: 5,
carbs: 28,
fats: 7,
serving: "160 grams"
}
var cod = {
name: "Cod",
calories: 270,
protein: 21,
carbs: 13,
fats: 12,
serving: "1 Fillet"
}
var spinach = {
name: "Spinach",
calories: 23,
protein: 0,
carbs: 5,
fats: 0,
serving: "100 grams"
}
var padthai = {
name: "Pad Thai",
calories: 420,
protein: 11,
carbs: 37,
fats: 11,
serving: "230 grams"
}
var broccolicheddarsoup = {
name: "Broccoli Cheddar Soup",
calories: 280,
protein: 7,
carbs: 14,
fats: 15,
serving: "180 grams"
}
var chickentenders = {
name: "Chicken Tenders",
calories: 250,
protein: 18,
carbs: 11,
fats: 11,
serving: "2 Tenders"
}
var totalcal = 0;
var totalprotein = 0;
var totalfats = 0;
var totalcarbs = 0;
// meal times
var breakfast = [scrambledeggs, bacon, porksausage, sweetpotatoes, oats, eggtaco, blueberrymuffin, tatertots, biscuits, porridge];
var lunch = [grilledchicken, porkloin, rice, corn, zucchini, carbonara, breadstick, ropavieja, hamburgerpatty, frenchfries];
var dinner = [salmon, alfredo, broccoli, pizza, greenbeans, friedrice, cod, spinach, padthai, broccolicheddarsoup, chickentenders];
var studentMenu = [];
$(document).ready(function () {
for (var i = 0; i < breakfast.length; i++) {
var menu = `<option class="food_option" value="${i}" data-toggle="modal" data-target="#foodModal">${
breakfast[i].name
}</option>`;
$("#selection").append(menu);
}
$("#breakfast").change(function () {
$("#selection .food_option").remove();
console.log("breakfast pressed");
$("#myInput").val('');
if ($(this).is(":checked")) {
for (var i = 0; i < breakfast.length; i++) {
var menu = `<option class="food_option" value="${i}" data-toggle="modal" data-target="#foodModal">${
breakfast[i].name
}</option>`;
$("#selection").append(menu);
}
}
});
$("#lunch").change(function () {
$("#selection .food_option").remove();
console.log("lunch pressed");
$("#myInput").val('');
if ($(this).is(":checked")) {
for (var i = 0; i < lunch.length; i++) {
var menu = `<option class="food_option" value="${i}" data-toggle="modal" data-target="#foodModal">${
lunch[i].name
}</option>`;
$("#selection").append(menu);
}
}
});
$("#dinner").change(function () {
$("#selection .food_option").remove();
console.log("dinner pressed");
$("#myInput").val('');
if ($(this).is(":checked")) {
for (var i = 0; i < dinner.length; i++) {
var menu = `<option class="food_option" value="${i}" data-toggle="modal" data-target="#foodModal">${
dinner[i].name
}</option>`;
$("#selection").append(menu);
}
}
});
//search box
$("#myInput").on("keyup", function () {
var value = $(this).val().toLowerCase();
$("#selection option").filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
$("#selection").click(function () {
var selected_menu = parseInt($("#selection option:selected").val());
var selected_meal = eval($("input[name=options]:checked").attr("id"));
$("#foodName").html(selected_meal[selected_menu].name);
$(servingText).html(
selected_meal[selected_menu].serving
);
$(foodCalories).html(selected_meal[selected_menu].calories + " cal");
$(foodProtein).html(selected_meal[selected_menu].protein + " g");
$(foodCarbs).html(selected_meal[selected_menu].carbs + " g");
$(foodFats).html(selected_meal[selected_menu].fats + " g");
});
//change macronutrients information when field has changed
$("#stufftoadd").bind('keyup mouseup', function () {
var servingSize = document.getElementById("stufftoadd").value;
var selected_menu = parseInt($("#selection option:selected").val());
var selected_meal = eval($("input[name=options]:checked").attr("id"));
$(foodCalories).html(selected_meal[selected_menu].calories * servingSize + " cal");
$(foodProtein).html(selected_meal[selected_menu].protein * servingSize + " g");
$(foodCarbs).html(selected_meal[selected_menu].carbs * servingSize + " g");
$(foodFats).html(selected_meal[selected_menu].fats * servingSize + " g");
});
function additem() {
var servingSize = document.getElementById("stufftoadd").value;
var selected_menu = parseInt($("#selection option:selected").val());
var selected_meal = eval($("input[name=options]:checked").attr("id"));
for (var i = 0; i < servingSize; i++) {
studentMenu.push(selected_meal[selected_menu]);
}
sessionStorage.setItem("menu", JSON.stringify(studentMenu));
totalcal = totalcal + parseInt(selected_meal[selected_menu].calories) * servingSize;
sessionStorage.setItem("calories", JSON.stringify(totalcal));
totalprotein = totalprotein + parseInt(selected_meal[selected_menu].protein) * servingSize;
sessionStorage.setItem("protein", JSON.stringify(totalprotein));
totalfats = totalfats + parseInt(selected_meal[selected_menu].fats) * servingSize;
sessionStorage.setItem("fats", JSON.stringify(totalfats));
totalcarbs = totalcarbs + parseInt(selected_meal[selected_menu].carbs) * servingSize;
sessionStorage.setItem("carbs", JSON.stringify(totalcarbs));
$("#calories").html("Calories: " + totalcal + " cal");
$("#protein").html("Protein: " + totalprotein + " g");
$("#fats").html("Fats: " + totalfats + " g");
$("#carbs").html("Carbohydrate: " + totalcarbs + " g");
//check repeated food before this step
var food =
"<li class = 'shadow-sm rounded'><span class = 'rounded'><i id = 'trash' class='fa fa-trash'></i></span>" +
$("#selection option:selected").text() +
" (" +
servingSize +
")</li>";
$("#food-list").append(food);
// defaults back to 1
document.getElementById("stufftoadd").value = 1;
};
$("#add-item").click(additem);
// lets you add food when you hit "enter"
var addbyenter = document.getElementById("stufftoadd");
addbyenter.addEventListener("keyup", function (event) {
if (event.keyCode === 13) {
event.preventDefault();
additem();
$("#close-item").click();
}
});
$("#close-item").click(function () {
document.getElementById("stufftoadd").value = 1;
});
//remove item from list
$("ul").on("click", "span", function (event) {
$(this)
.parent()
.fadeOut(500, function () {
foodName = $(this).text();
foodName_small = foodName.replace(/ +/g, "").toLowerCase();
remove_number = foodName_small.split("(")[0];
serving_size_rough = foodName_small.split("(")[1];
servingSize = serving_size_rough.substr(
0,
serving_size_rough.length - 1
);
var compare;
//not removing any items because the comparison is wrong
//remove_number is stripped so it is never true
for (var i = 0; i < studentMenu.length; i++) {
compare = studentMenu[i].name.replace(/ +/g, "").toLowerCase();
console.log("compare:" + compare);
if (compare === remove_number) {
studentMenu.splice(i, 1);
}
}
sessionStorage.setItem("menu", JSON.stringify(studentMenu));
var selected_food = eval(remove_number);
totalcal = totalcal - parseInt(selected_food.calories) * servingSize;
sessionStorage.setItem("calories", JSON.stringify(totalcal));
totalprotein = totalprotein - parseInt(selected_food.protein) * servingSize;
sessionStorage.setItem("protein", JSON.stringify(totalprotein));
totalfats = totalfats - parseInt(selected_food.fats) * servingSize;
sessionStorage.setItem("fats", JSON.stringify(totalfats));
totalcarbs = totalcarbs - parseInt(selected_food.carbs) * servingSize;
sessionStorage.setItem("carbs", JSON.stringify(totalcarbs));
//get serving size
$("#calories").html("Calories: " + totalcal + " cal");
$("#protein").html("Protein: " + totalprotein + " g");
$("#fats").html("Fats: " + totalfats + " g");
$("#carbs").html("Carbohydrate: " + totalcarbs + " g");
$(this).remove();
});
event.stopPropagation();
});
$("#complete-btn").click(function () {
if (studentMenu.length == 0) {
alert("Please add an item");
} else {
window.location = "finishpage.html";
}
})
});