-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
516 lines (440 loc) · 21.7 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<html ng-app="recipeAssistant">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SOMMELIER</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="css/index.css" rel="stylesheet">
<link href="css/results.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Gruppo" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
function clickAdd(curname) {
$.post("https://kzhe8vy1yd.execute-api.us-east-1.amazonaws.com/prod/TaskWS", JSON.stringify({
"type": "POST",
"data": {
"TableName": "WineFoodShopping",
//New item information to be posted
"Item": {
"Item": String(curname.id),
}}}),
function(data, status){
alert(status);
});
// console.log("???")
// console.log(curname.id)
document.getElementById(curname.id).innerText = 'ADDED TO CART!'
}
</script>
<!-- landing page click animation -->
<script type="text/javascript">
$(function () {
var $landing = $("#landing"),
$actual = $("#actual");
$landing.on("click", function (){
$(this).addClass("clicked");
})
});
$(document).ready(function(){
var list = document.getElementById('cart');
list.setAttribute('data-toggle', 'modal');
list.setAttribute('data-target', '#listModal');
$(list).on("click", function (){
var content = document.getElementById('sh_list')
content.innerHTML = "";
$.get("https://kzhe8vy1yd.execute-api.us-east-1.amazonaws.com/prod/TaskWS?TableName=WineFoodShopping", function(data){
var db = JSON.stringify(data);
var parse = JSON.parse(db);
var recipeList = parse.Items;
var sh_list = document.getElementById('sh_list');
for (i = 0; i < recipeList.length; i++) {
var label= document.createElement("hellogg");
var item = document.createTextNode(" " + recipeList[i].Item);
var checkbox = document.createElement('input');
checkbox.setAttribute('type', 'checkbox');
label.appendChild(checkbox);
label.appendChild(item);
document.getElementById('sh_list').appendChild(label);
document.getElementById('sh_list').appendChild(document.createElement("br"));
}
});
console.log('list printed')
});
var button = document.getElementById('button');
button.setAttribute('data-toggle', 'modal');
button.setAttribute('data-target', '#resModal');
});
</script>
<script>
var gg;
// This function returns a tuple containing the pairing info
// which is (Pair1Name, Pair1Image, Pair1Info)
function findPairingInfo(pName, resList) {
$.post("https://kzhe8vy1yd.execute-api.us-east-1.amazonaws.com/prod/TaskWS", JSON.stringify({
"type": "QUERY",
"data": {
"TableName": "WineFood",
//Condition for item
"FilterExpression": "#y = :y",
//Variable for attribute name (think of key). You have to preface the variables with #
"ExpressionAttributeNames": {
"#y": "Item",
},
//Variable for value to attribute. You have to preface the variables with :
"ExpressionAttributeValues": {
":y": pName
}
}
}),
//success callback
function(data, status) {
var data = JSON.parse(JSON.stringify(data))["Items"][0];
if (data == null) {
return null;
}else if (data.length != 0) {
var rName = data["Item"];
var rImage = data["Picture"];
var rInfo = data["Info"];
console.log('good');
resList.push({'name': rName, 'image': rImage, 'info': rInfo});
} else {
return null;
}
}).fail(function(res) {
console.log(res)
})
}
function clickSearch() {
var searchName = document.getElementById("bar").value.toLowerCase();
// console.log('gg');
// console.log(searchName);
var pList = "";
var resList = [];
var targetName;
var targetImage;
var targetInfo;
var pairings;
$.post("https://kzhe8vy1yd.execute-api.us-east-1.amazonaws.com/prod/TaskWS", JSON.stringify({
"type": "QUERY",
"data": {
"TableName": "WineFood",
//Condition for item
"FilterExpression": "#y = :y",
//Variable for attribute name (think of key). You have to preface the variables with #
"ExpressionAttributeNames": {
"#y": "Item",
},
//Variable for value to attribute. You have to preface the variables with :
"ExpressionAttributeValues": {
":y": searchName.toLowerCase()
}
}
}),
//success callback
function(data, status) {
var data = JSON.parse(JSON.stringify(data))["Items"][0];
// console.log(data);
if (data === undefined) {
return;
}
targetName = data["Item"];
targetImage = data["Picture"];
targetInfo = data["Info"];
pairings = data["Pairings"];
// console.log(data["Items"][0]["Item"]);
console.log('targetName:' + targetName);
console.log('targetImage:' + targetImage);
console.log('targetInfo:' + targetInfo);
// console.log(pairings);
// var targ
pList = pairings.split(", ");
// console.log(pList)
for (i=0; i<pList.length; i++) {
var pName = pList[i];
$.post("https://kzhe8vy1yd.execute-api.us-east-1.amazonaws.com/prod/TaskWS", JSON.stringify({
"type": "QUERY",
"data": {
"TableName": "WineFood",
//Condition for item
"FilterExpression": "#y = :y",
//Variable for attribute name (think of key). You have to preface the variables with #
"ExpressionAttributeNames": {
"#y": "Item",
},
//Variable for value to attribute. You have to preface the variables with :
"ExpressionAttributeValues": {
":y": pName
}
}
}),
//success callback
function(data, status) {
var data = JSON.parse(JSON.stringify(data))["Items"][0];
if (data == null) {
return null;
}else if (data.length != 0) {
var rName = data["Item"];
var rImage = data["Picture"];
var rInfo = data["Info"];
console.log('good');
resList.push({'name': rName, 'image': rImage, 'info': rInfo});
} else {
return null;
}
}).fail(function(res) {
console.log(res)
})
}
// resList = resList.slice(1, resList.length);
console.log(resList);
console.log("targetName");
console.log(targetName);
// Alan's code start here: to fill the content into the box
// variable targetName: the name string of our search
// varablle targetImage: the picture link of our search
// varaible targetInfo: the description of our search
// varaible resList: a list of tuples [(Pair1Name, Pair1Image, Pair1Info), (Pair2Name, Pair2Image, Pair2Info) ...]
// ***Special Note*** Because of javascript issue, the actual content of the resList start from index 1 instead of index 0
}).fail(function(res) {
console.log(res)
// alert('No Result')
})
setTimeout(function(){
if (resList.length == 0) {
// alert('No Result');
var modal = document.getElementById('results_list');
modal.innerHTML = "";
var title = document.getElementById('results-title');
title.innerText = "No Results";
return;
}
console.log("hello");
console.log(resList.length);
var modal = document.getElementById('results_list');
modal.innerHTML = "";
var title = document.getElementById('results-title');
title.innerText = targetName.charAt(0).toUpperCase() + targetName.slice(1).toLowerCase(); // only first letter capital
for (var i = 0; i < resList.length; i++) {
// results container
var container = document.createElement('div');
container.setAttribute('class', 'result-container');
var id = 'rc' + i.toString();
container.setAttribute('id', id);
// img container
var imgContainer = document.createElement('div');
imgContainer.setAttribute('class','result-contents');
var img_id = 'result-img-container' + i.toString();
imgContainer.setAttribute('id', img_id);
// image
var image = document.createElement('img');
image.setAttribute('id','result-img');
image.setAttribute('src',resList[i]['image']);
imgContainer.appendChild(image);
container.appendChild(imgContainer);
// result contents
var descripContainer = document.createElement('div');
descripContainer.setAttribute('class','result-contents');
descripContainer.setAttribute('id', 'result-descrip-container');
// h4
var header = document.createElement('h4');
header.setAttribute('id','result-descrip');
header.innerText = resList[i]['name'];
descripContainer.appendChild(header);
// input
var input = document.createElement('input');
input.setAttribute('class','toggles');
var input_id = 'toggle' + i.toString();
input.setAttribute('id',input_id);
input.setAttribute('type','checkbox');
input.checked = false;
descripContainer.appendChild(input);
// label
var label = document.createElement('label');
label.setAttribute('for',input_id);
label.innerText = ' Details';
descripContainer.appendChild(label);
// expansions div
var expansions = document.createElement('div');
expansions.setAttribute('class','expansions');
var exp_id = 'expand' + i.toString();
expansions.setAttribute('id',exp_id);
// cart
var cart_p = document.createElement('p');
var link = document.createElement('a');
link.setAttribute('class','cart');
link.setAttribute('href','#');
link.setAttribute('id', resList[i]['name'])
link.innerText = 'ADD TO CART';
link.setAttribute('onclick', 'clickAdd(' + String(resList[i]['name']) + ')');
cart_p.appendChild(link);
// descrip
var descrip = document.createElement('p');
descrip.innerText = resList[i]['info'];
expansions.appendChild(cart_p);
expansions.appendChild(descrip);
descripContainer.appendChild(expansions);
container.appendChild(descripContainer);
modal.appendChild(container);
}
var elements = document.getElementsByTagName('label');
var animationSpeed = 500;
var rc = '#rc';
var r_container = '#result-img-container';
var count = document.getElementById('results_list').childElementCount;
for (var k=0; k < count; k++) {
(function() {
var curRC = rc + k.toString();
var cur_container = r_container + k.toString();
console.log(cur_container);
elements[k].addEventListener('click', function() {
if ( $(curRC).height() != 148) {
$(curRC).animate({ height: 150 }, animationSpeed );
$(cur_container).animate({ height: 150 }, animationSpeed );
} else {
$(curRC).animate({ height: 225 }, animationSpeed );
$(cur_container).animate({ height: 224 }, animationSpeed );
}
})
}());
}
}, 1000)
}
</script>
</head>
<body>
<div class="site-wrapper">
<div id="listModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content", id='modal-content'>
<div class="modal-header">
<h3 class="modal-title">SHOPPING LIST</h3>
</div>
<div class="modal-body" id="sh_list_cont">
<div id="sh_list"></div>
</div>
<div class="modal-footer">
<button class="btn btn-outline-primary" data-dismiss="modal">CLOSE</button>
</div>
</div>
</div>
</div>
<div id="resModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="results-title"></h3>
</div>
<div class="modal-body" id="results_list">
</div>
<div class="modal-footer">
<button class="btn btn-outline-primary" data-dismiss="modal">CLOSE</button>
</div>
</div>
</div>
</div>
<div class="container">
<div id="actual">
<div id="navbar">
<span class="glyphicon glyphicon-shopping-cart" id="cart"></span>
<a href="add.html"><span class="glyphicon glyphicon-plus" id="add" style="margin-left:50px"></span></a>
<h2>SOMMELIER</h2>
</div>
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-8" id="center-page">
<div id="search" align="center">
<div class="input-group">
<input type="text" class="form-control" name="search" placeholder="searching..." id="bar">
<span class="input-group-btn"><button class="btn btn-default" id="button" type="submit" onclick="clickSearch()">SEARCH</button></span>
</div>
</div>
</div>
<div class="col-sm-2"></div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" id="pop_name">>>> POPULAR PAIRINGS <<<</div>
</div>
<div class="container-fluid" id="tiles">
<div class="row" id="popular">
<div class="col-sm-2">
<div class="tile" id="one">
<div class="filter">
<p>steak<br />
+<br />
cabernet sauvignon<br /></p>
</div>
</div>
</div>
<div class="col-sm-2">
<div class="tile" id="two">
<div class="filter">
halibut<br />
+<br />
chardonnay<br />
</div>
</div>
</div>
<div class="col-sm-2">
<div class="tile" id="three">
<div class="filter">
crab<br />
+<br />
pinot noir<br />
</div>
</div>
</div>
<div class="col-sm-2">
<div class="tile" id="four">
<div class="filter">
lamb<br />
+<br />
sauvignon blanc<br />
</div>
</div>
</div>
<div class="col-sm-2">
<div class="tile" id="five">
<div class="filter">
shrimp<br />
+<br />
vinho verde<br />
</div>
</div>
</div>
<div class="col-sm-2">
<div class="tile" id="six">
<div class="filter">
duck<br />
+<br />
beaujolais<br />
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div id="footer">© TEAM SANS. CS160 SPRING 2017. ALL RIGHTS RESERVED.</div>
</div>
</div>
</div>
<div id="landing">
<div class="row" id="logo">
<div class="col-sm-2"></div>
<div class="col-sm-8" id="title">
<h1>SOM<br />
MEL<br />
IER
</h1>
</div>
<div class="col-sm-2"></div>
</div>
</div>
</div>
</div>
</body>
</html>