-
Notifications
You must be signed in to change notification settings - Fork 2
/
preference.html
140 lines (115 loc) · 4.2 KB
/
preference.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="http://fonts.googleapis.com/css?family=Didact+Gothic" rel="stylesheet" />
<link href="preference.css" rel="stylesheet" type="text/css" media="all" />
<link href="fonts.css" rel="stylesheet" type="text/css" media="all" />
<!--[if IE 6]><link href="default_ie6.css" rel="stylesheet" type="text/css" /><![endif]-->
</head>
<body>
<!-- The main header -->
<div id="header-wrapper-preference">
<div id="header" class="container">
<div id="logo">
<h1><a href="#">OneRecipe</a></h1>
</div>
<div id="menu">
<ul>
<li><a href="index.html" accesskey="1" title="">Home</a></li>
<li><a href="#" accesskey="2" title="">About</a></li>
<li class="active"><a href="preference.html" accesskey="3" title="">Preferences</a></li>
<li><a href="transfer.html" accesskey="4" title="">GetOneNow</a></li>
<li><a href="#" accesskey="5" title="">Happy Hacking</a></li>
</ul>
</div>
</div>
<!-- The preference input form -->
<div id="preference-wrapper">
<form>
<h1 style="margin-left: 0;">Set up your preferences</h1>
<div class="question">
<h3 style="margin: 0"> Diet Restriction (Leave it blank if no restrictions)</h3>
<input type="checkbox" id="V" name="typeV" value="vegan">Vegan<br>
<input type="checkbox" id="D" name="typeD" value="diabetes">Diabetes<br>
<input type="checkbox" id="H" name="typeH" value="hyperglycemia">Hyperglycemia<br>
</div>
<div class="question">
<h3 style="margin: 0;">Calories Level</h3>
<select class="drop-down" id="options" name="calories-level">
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>
</div>
<button onclick=getFinalPreference() type="button">Submit</button>
</form>
</div>
</body>
<script type="text/javascript" src="theInstructions.json"></script>
<script type="text/javascript" src="recipes.json"></script>
<script type="text/javascript" src="grep.js"></script>
<script>
function getTag() {
var tag = "\"tags\": [";
if (document.getElementById("V").checked == true) {
tag += "\"vegan\"";
if (document.getElementById("D").checked == true) {
tag += ", \"diabetes\"";
}
if (document.getElementById("H").checked == true) {
tag += ", \"hyperglycemia\"";
}
}
else if (document.getElementById("D").checked == true) {
tag += "\"diabetes\"";
if (document.getElementById("H").checked == true) {
tag += ", \"hyperglycemia\"";
}
}
else if (document.getElementById("H").checked == true) {
tag += "\"hyperglycemia\"";
}
tag += "]";
return tag;
}
function getCalory() {
var calory = "\"calories\": \"" + document.getElementById("options").value + "\"";
return calory;
}
function getPreference() {
var string = getTag() + ", " + getCalory();
return string;
}
var ingredient;
function getIngredient(ingredients) {
ingredient = ingredients;
return ingredient;
}
function getFinalPreference() {
var mydata = JSON.parse(JSON.stringify(recipes));
var argument = "{\"ingredients\": " + ingredient + getPreference() + "}";
localStorage.setItem("arguments", argument);
let text = localStorage.getItem("arguments");
obj = JSON.parse(text);
var result = selectRecipe(mydata, obj);
result = ("[" + result + "]");
var resultJson = JSON.parse(result);
if (resultJson.length == 0) return [];
var ins = JSON.parse(JSON.stringify(theInstructions));
var allInstructions = [];
for (let i = 0; i < resultJson.length; i++) {
var name = resultJson[i]['name'];
if (allInstructions.length != 0) allInstructions += ", ";
allInstructions += parseInstruction(name, ins);
}
allInstructions = ("[" + allInstructions + "]");
instruct = JSON.parse(allInstructions);
alert(allInstructions);
}
</script>
</html>