-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
653 lines (588 loc) · 24.2 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
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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
-->
<link rel="stylesheet" href="css/sidebar.css">
<link href="css/style.css" rel="stylesheet">
<link href="css/star-rating.css" rel="stylesheet">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="#c5d5cb">
<!-- Map -->
<div id="map" hidden></div>
<div id="wrapper">
<div class="overlay"></div>
<!-- Sidebar -->
<div id="spinner"></div>
<nav class="navbar navbar-inverse navbar-fixed-top" id="sidebar-wrapper" role="navigation">
<ul class="nav sidebar-nav">
<li class="sidebar-brand">
<a href="">
Sabri
</a>
</li>
<li>
<a href="">Home</a>
</li>
<li>
<a href="#" data-toggle="modal" data-target=".about-modal">About</a>
</li>
<li>
<a href="#" data-toggle="modal" data-target=".stats-modal">User statistics</a>
</li>
<li>
<a href="#" data-toggle="modal" data-target=".team-modal">Team</a>
</li>
</ul>
</nav>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<button type="button" class="hamburger is-closed" data-toggle="offcanvas">
<span class="hamb-top"></span>
<span class="hamb-middle"></span>
<span class="hamb-bottom"></span>
</button>
<div class="content" id="contentBody">
<center> <img id="sabri-logo" src="img/Sabri_Logo.jpg" style="margin-bottom: 20px;"></center>
<div class="input-group col-xs-6 searchPanel">
<div class="input-group-btn search-panel">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span id="search_concept">Filter by</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><input type="checkbox" id="ID" name="filterByCuisine" value="Indian" onClick="filterByCuisine(this)"><label for="ID">Indian</label></li>
<li><input type="checkbox" id="ID" name="filterByCuisine" value="Chinese" onClick="filterByCuisine(this)"><label for="ID" name="NAME" value="Chinese">Chinese</label></li>
<li><input type="checkbox" id="ID" name="filterByCuisine" value="American" onClick="filterByCuisine(this)"><label for="ID" name="NAME" value="American">American</label></li>
<li><input type="checkbox" id="ID" name="nearby" value="Nearby" onClick="filterByIsClose()"><label for="ID">Nearby</label></li>
<li><input type="checkbox" id="ID" name="isOPen" value="isOpen" onClick="filterByOpenNow()"><label for="ID">Open Now</label></li>
</ul>
</div>
<input type="hidden" name="search_param" value="all" id="search_param">
<form id="searchForm">
<span class="input-group-btn">
<input id="postcode" type="text" class="form-control" name="x" placeholder="Search by postcode..." required>
<button class="btn btn-default" type="button" onclick="getLocation()"><span class="glyphicon glyphicon-record"></span></button>
<button id="postcode-go" class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</span>
</form>
</div>
</div>
<!-- /#wrapper -->
<!-- Description modal -->
<div class="modal fade description-modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<div class="title">Title was not provided</div>
<div class="restaurantHeader">
<p id="cuisineTypes">Food type was not provided</p>
<p>Work time today: <strong id="workTime"><!-- 10am - 10pm --></strong></p>
<p id="address">Address was not provided</p>
<p id="link">Webpage link was not provided</p>
<form class="form-inline">
<div class="form-group">
<label><img src="" class="restaurantHeader-img" alt="restaurant logo"></label>
<input id="restaurantRating" class="rating" type="number" value="0" data-size="md">
</div>
</form>
</div>
<p id="description" class="text-justify">
No description provided
</p>
</div>
</div>
</div>
</div>
<!-- D3 plot -->
<div class="modal fade stats-modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-body" id="plot"></div>
</div>
</div>
</div>
<div class="modal fade about-modal" tabindex="-1" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-body">
<center> <h1> Sabri - Best Restaurant Finder in Glasgow </h1> </center>
<center> <img id="sabri-logo" src="img/Sabri_Logo.jpg" style="margin-bottom: 20px;"></center>
<br> <br>
<p align="justify" style="font-size: 16px;">
Since the dawn of humanity the masses have felt constant depletion of nutrients in their bodies. A non-permanent solution to this problem is the regular supply of substances collectively known as ‘food’. Food, however, is something wars were fought over, and it is not one of those little things our Creators decided they could just freely provide to us. In order for an organism to stay alive they need to prepare their own food, or in current times, buy a ready-made meal from one of the numerous commercial institutions bestowing nourishment. </p>
<p align="justify" style="font-size: 16px;">
We are developing an application that will address all your needs. You want an app that can show you the nearest places where you can grab a bite? You want to see which restaurants or fast-foods have the highest ratings? We’ve got you covered. Sabri will give you all the possibilities for all types of users to choose where, when and what to eat.
</p>
</div>
</div>
</div>
</div>
<div class="modal fade team-modal" tabindex="-1" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-body">
<center> <h1> Team behind Sabri </h1> </center>
<center> <h3> University of Glasgow </h3> </center>
<br> <br>
<p align="justify" style="font-size: 25px;">
<center> Edvinas Simkus </center> <br>
<center> Andrei-Mihai Nicolae </center> <br>
<center> Ivan Kyosev </center> <br>
<center> Richard Pearson </center> <br>
<center> Ian Denev </center> <br>
<center> Mariusz Szmajduch </center> <br>
</p>
</div>
</div>
</div>
</div>
<!-- js files -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC1Fuqax5sLGDq4KRkjaTobvhq-y-UyNVA"></script>
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/d3.min.js" charset="utf-8"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/sidebar.js"></script>
<script src="js/star-rating.js"></script>
<script src="js/spin.min.js"></script>
<script>
var restaurants_res = [];
var initial_res = [];
var initial_locals = [];
var criteria = new Object();
var localLatLang;
$("#searchForm").submit(function(e) {
e.preventDefault();
$('#spinner').spin('default');
$.ajax({
url: "https://public.je-apis.com/restaurants?q=" + $("#postcode").val(),
dataType: 'json',
type: "GET",
headers: {
"Accept-Tenant": "uk",
"Accept-Language": "en-GB",
"Authorization": "Basic VGVjaFRlc3RBUEk6dXNlcjI="
},
success: function (parsed_json) {
//var restaurants_res = [];
parsed_json.Restaurants.forEach(function (entry) {
restaurants_res.push(entry);
});
initial_res = restaurants_res;
onDataReady(restaurants_res);
},
error: function (e) {
alert('Failure ' + e.status);
},
done: function () {
alert('done');
}
});
});
function restaurantinfo(id) {
var restaurant;
Restaurants.forEach(function (o) {
if (o.Id == id) restaurant = o;
});
var cuisineTypes =
restaurant.CuisineTypes.map(function (elem) {
return elem.Name;
}).join(", ");
$('.title').text(restaurant.Name);
$('#cuisineTypes').text(cuisineTypes);
$('#address').text(restaurant.Address + ", " + restaurant.Postcode);
$('#link').html('<a href="' + restaurant.Url + '">More details and delivery information</a>');
$('.restaurantHeader-img').attr("src", restaurant.Logo[0].StandardResolutionURL);
$('#restaurantRating').rating('update', restaurant.RatingStars);
restaurantDetails(id);
}
function restaurantDetails(restaurantId) {
$.ajax({
url: "https://public.je-apis.com/restaurants/" + restaurantId + "/details",
dataType: 'json',
type: "GET",
headers: {
"Accept-Tenant": "uk",
"Accept-Language": "en-GB",
"Authorization": "Basic VGVjaFRlc3RBUEk6dXNlcjI="
},
success: function (parsed_json) {
var now = new Date();
var week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var today = week[now.getDay()];
var workTime = [];
parsed_json.OpeningTimes.forEach(function (o) {
if (o.Key == today) {
workTime.push(o.Open);
workTime.push(o.Closed);
}
});
if (parsed_json.Description.length > 10) {
$('#description').text(parsed_json.Description);
}
else {
$('#description').html("<center> No description available. </center>");
}
$('#workTime').text(workTime.length != 0 ? workTime[0] + " - " + workTime[1] : "time not avaible");
},
error: function (e) {
alert('Failure ' + e.status);
}
});
}
function onDataReady(data) {
var neededProc = data.length + 1;
var googleMapsApiUrl = "https://maps.googleapis.com/maps/api/geocode/json?address=";
//determine zoom in location
var apiUrl = googleMapsApiUrl + $("#postcode").val() + "&sensor=false";
jQuery.getJSON(apiUrl, function (coo) {
neededProc--;
localLatLang = coo.results[0].geometry.location;
if (neededProc == 0) {
onCooRecieved(data);
}
});
for (var i = 0; i < data.length; i++) {
var apiUrl = googleMapsApiUrl + data[i].Postcode + "&sensor=false";
jQuery.getJSON(apiUrl, function (i, coo) {
neededProc--;
if (coo.results[0] != null) {
data[i].latLng = coo.results[0].geometry.location;
}
if (neededProc == 0) {
onCooRecieved(data);
}
}.bind(this, i));
}
}
function onCooRecieved(data) {
$('#map').attr('hidden', false);
$('#sabri-logo').attr('hidden', true);
$('.content').css("padding", 0);
$(".searchPanel").css("top","0");
$('#spinner').spin(false);
$('html, body').animate({scrollTop: $('#map').offset().top}, 'slow');
var map = new google.maps.Map(document.getElementById('map'), {
center: localLatLang,
zoom: 12
});
for (var i = 0; i < data.length; i++) {
//edit contentString for the pop up info
var openText = (data[i].isOpen == true) ? "Closed" : "Open";
var boxColor = (openText == "Open") ? "Green" : "Red";
var contentString = '<div style = "text-align : center ">'
+ data[i].Name
+ '<img style="margin:0 auto; display:block" src=' + data[i].Logo[0].StandardResolutionURL + '>'
+ 'Rating: '
+ data[i].RatingStars
+ '<br>'
+ '<div style="border: 2px; color: ' + boxColor + '"> ' + openText + ' </div>'
+ '<br>'
+ '<button onclick="restaurantinfo(' + data[i].Id + ')" type="button" class="btn btn-sm btn-warning" data-toggle="modal" data-target=".description-modal">More details</button>'
+ '</div>';
Restaurants = data;
var infoWindow = new google.maps.InfoWindow({content: contentString});
var marker = new google.maps.Marker({
position: data[i].latLng,
map: map,
mapTypeId: google.maps.MapTypeId.TERRAIN
});
marker.addListener('click', function (marker, infoWindow) {
infoWindow.open(map, marker);
}.bind(this, marker, infoWindow));
}
}
$(".rating").rating({
min: 0,
max: 6,
step: 1,
stars: 6,
size: 'sm',
showClear: false,
showCaption: false,
readonly: true
});
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
$.ajax({
url: "https://api.postcodes.io/postcodes?lon="+crd.longitude+"&lat="+crd.latitude,
dataType: 'json',
type: "GET",
success: function (location) {
$('#postcode').val(location.result[0].postcode);
$("#searchForm").submit();
},
error: function (e) {
alert('Failure ' + e.status);
}
});
};
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
};
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error, options);
} else {
alert("Geolocation is not supported by this browser.");
}
}
//Checkbox selects what type of cuisine you wish to view
function filterByCuisine(element){
var new_res = [];
if(!("cuisine" in criteria)){
criteria["cuisine"] = element.value;
for(var restaurant of restaurants_res){
for(var cuisine of restaurant.CuisineTypes){
if(JSON.stringify(cuisine.Name) === JSON.stringify(element.value)){
new_res.push(restaurant);
break;
}
}
}
}else{
var checkBoxes = document.getElementsByName("filterByCuisine");
var toCheck = false;
if (element.checked == true){
toCheck = true;
}
for(var box of checkBoxes){
box.checked = false;
}
delete criteria["cuisine"];
new_res = filterByList();
if(toCheck == true){
element.checked = true;
restaurants_res = new_res;
filterByCuisine(element);
new_res = restaurants_res;
}
}
restaurants_res = new_res;
onCooRecieved(restaurants_res);
}
//select whether the restaurant should be close by
function filterByIsClose(){
var new_res = [];;
if(!("closeBy" in criteria)){
criteria["closeBy"] = 2;
for(var restaurant of restaurants_res){
if(restaurant.IsCloseBy){
new_res.push(restaurant);
}
}
}else{
delete criteria["closeBy"];
new_res = filterByList();
}
restaurants_res = new_res;
onCooRecieved(restaurants_res);
}
//iterates through the dictionary of applied filters
//and updates the array of restaurants accordingly
function filterByList(){
restaurants_res = initial_res;
if("cuisine" in criteria){
var cuisine = criteria["cuisine"];
delete criteria["cuisine"];
var boxes = document.getElementsByName("filterByCuisine");
var target;
for(var box of boxes){
if(box.value == cuisine){
target = box;
break;
}
}
filterByCuisine(target);
}
if("closeBy" in criteria){
delete criteria["closeBy"];
filterByIsClose();
}
if("openNow" in criteria){
delete criteria["openNow"];
filterByOpenNow();
}
return restaurants_res;
}
function filterByOpenNow(){
var new_res = [];
if(!("openNow" in criteria)){
criteria["openNow"] = 2;
for(var restaurant of restaurants_res){
if(restaurant.IsOpenNow){
new_res.push(restaurant);
}
}
}else{
delete criteria["openNow"];
new_res = filterByList();
}
restaurants_res = new_res;
onCooRecieved(restaurants_res);
}
//D3 stuff
function render(data){
var margin = {top: 20, right: 15, bottom: 60, left: 60}
, width = 850 - margin.left - margin.right
, height = 500 - margin.top - margin.bottom;
var x = d3.scale.linear()
.domain([0, d3.max(data, function(d) { return d.id; })])
.range([ 0, width ]);
var y = d3.scale.linear()
.domain([0, d3.max(data, function(d) { return d.timeDiff; })])
.range([ height, 0 ]);
var chart = d3.select('#plot')
.append('svg:svg')
.attr('width', width + margin.right + margin.left)
.attr('height', height + margin.top + margin.bottom)
.attr('class', 'chart')
var main = chart.append('g')
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
.attr('width', width)
.attr('height', height)
.attr('class', 'main')
// draw the x axis
var xAxis = d3.svg.axis()
.scale(x)
.orient('bottom')
.innerTickSize(-height)
.outerTickSize(0)
.tickPadding(10);
main.append('g')
.attr('transform', 'translate(0,' + height + ')')
.attr('class', 'main axis date')
.call(xAxis);
// draw the y axis
var yAxis = d3.svg.axis()
.scale(y)
.orient('left')
.innerTickSize(-width)
.outerTickSize(0)
.tickPadding(10);
main.append('g')
.attr('transform', 'translate(0,0)')
.attr('class', 'main axis date')
.call(yAxis);
var g = main.append("svg:g");
g.selectAll("scatter-dots")
.data(data)
.enter().append("svg:circle")
.attr("cx", function (d,i) { return x(d.id); } )
.attr("cy", function (d) { return y(d.timeDiff); } )
.attr("r", 8)
.style("fill", function(d) { return "#0000FF";});
//draw x axis label
main.append("text")
.attr("x", width / 2 )
.attr("y", height + 40)
.style("font-size","15px")
.style("text-anchor", "middle")
.text("Index of Difficulty");
//draw y axis label
main.append("text")
.attr("transform", "rotate(-90)")
.style("font-size","15px")
.attr("y", 0 - 60)
.attr("x",0 - (height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.text("Time - milliseconds");
}
var small_array = [];
var info = [];
render(info);
$("body").click(function(e) {
//clear the previous graph
$("svg").remove();
var x = e.pageX;
var y = e.pageY;
var d = new Date();
var elem = document.elementFromPoint(x, y);
var click = {x:x, y:y, time:d.getTime(), buttonW:elem.offsetWidth};
small_array.push(click);
//create the Fitts object
for(var i = 1; i < small_array.length; i++){
var x1 = small_array[i-1].x;
var x2 = small_array[i].x;
var y1 = small_array[i-1].y;
var y2 = small_array[i].y;
var w = small_array[i].buttonW;
var distance = Math.sqrt(((x1 - x2)*(x1 - x2)) + ((y1 - y2) * (y1 - y2)));
var ID = Math.log(distance/w + 1)/Math.log(2);
var timeDiff = small_array[i].time - small_array[i-1].time;
var fitts = {id:ID, timeDiff:timeDiff};
info.push(fitts);
}
render(info);
});
// spinner
;(function(factory) {
if (typeof exports == 'object') {
// CommonJS
factory(require('jquery'), require('spin.js'))
} else if (typeof define == 'function' && define.amd) {
// AMD, register as anonymous module
define(['jquery', 'spin'], factory)
} else {
// Browser globals
if (!window.Spinner) throw new Error('Spin.js not present')
factory(window.jQuery, window.Spinner)
}
}(function($, Spinner) {
$.fn.spin = function(opts, color) {
return this.each(function() {
var $this = $(this)
, data = $this.data()
if (data.spinner) {
data.spinner.stop()
delete data.spinner
}
if (opts !== false) {
opts = $.extend(
{ color: color || $this.css('color') }
, $.fn.spin.presets[opts] || opts
)
data.spinner = new Spinner(opts).spin(this)
}
})
}
$.fn.spin.presets = {
tiny: { lines: 8, length: 2, width: 2, radius: 3 }
, small: { lines: 8, length: 4, width: 3, radius: 5 }
, large: { lines: 10, length: 8, width: 4, radius: 8 }
, default: {
lines: 13 // The number of lines to draw
, length: 28 // The length of each line
, width: 14 // The line thickness
, radius: 42 // The radius of the inner circle
, scale: 1 // Scales overall size of the spinner
, corners: 1 // Corner roundness (0..1)
, color: '#000' // #rgb or #rrggbb or array of colors
, opacity: 0.25 // Opacity of the lines
, rotate: 0 // The rotation offset
, direction: 1 // 1: clockwise, -1: counterclockwise
, speed: 1 // Rounds per second
, trail: 60 // Afterglow percentage
, fps: 20 // Frames per second when using setTimeout() as a fallback for CSS
, zIndex: 2e9 // The z-index (defaults to 2000000000)
, className: 'spinner' // The CSS class to assign to the spinner
, top: '50%' // Top position relative to parent
, left: '50%' // Left position relative to parent
, shadow: false // Whether to render a shadow
, hwaccel: false // Whether to use hardware acceleration
, position: 'absolute' // Element positioning
}
}
}));
</script>
</body>
</html>