Commit c23a707f authored by Daniel W Bond's avatar Daniel W Bond

Merge branch 'master' of git.gmu.edu:srct/whats-open

parents 74149a41 fe30667a
......@@ -58,7 +58,7 @@ function construct_grid(filtered_restaurants) {
function update_grid(restaurants) {
$.each(restaurants, function (idx, restaurant) {
var now = new Date();
var date = new Date().setHours(0,0,0,0);
var endDate = new Date().setHours(5,0,0,0);
// JavaScript sets 0 to Sunday instead of Monday
var day = now.getDay() - 1;
if (day === -1) {
......@@ -67,10 +67,13 @@ function update_grid(restaurants) {
var schedule = undefined;
// If there exists a valid special schedule choose it.
$.each(restaurant.special_schedules, function (idx, special) {
console.log(Date.parse(special.start))
console.log(date)
if (date >= Date.parse(special.start)
&& date <= Date.parse(special.end)) {
// Special schedules take effect after 5am on their start day
// to prevent collisions with the previous night's schedule,
// and they end at 5am the day after their end date.
special_start = Date.parse(special.start + ' 05:00:00');
special_end = Date.parse(special.end + ' 05:00:00');
special_end.setDate(special_end.getDate()+1);
if (now >= special_start && now <= special_end) {
schedule = special;
}
});
......@@ -78,8 +81,11 @@ function update_grid(restaurants) {
if (schedule === undefined) {
schedule = restaurant.main_schedule;
}
restaurant.current_schedule = schedule;
// Open the restaurants that are open, leave the rest closed.
if (schedule.open_times.length === 0) {
restaurant.open = false;
}
restaurant.current_schedule = schedule;
$.each(schedule.open_times, function (idx, time) {
var start_day = time.start_day;
var end_day = time.end_day;
......
......@@ -12,14 +12,60 @@ function compareTimes(time1, time2) {
return true;
}
function areConsecutiveDays(time1, time2) {
if (time1 === undefined || time2 === undefined) {
return false;
}
else if (time1.start_day !== time2.start_day - 1) {
return false;
}
return true;
}
$.fn.displaySchedule = function(open_times){
/* Display each open time in a concise format. The following loop will
* determine if two consecutive days have the same open and closing times.
* If that is the case, the time will be shown as a range.
* (ie. Mon - Sat: 10:00 AM - 6:00 PM")
* Otherwise, each date is displayed for its individual day.
* (ie. Sun: "4:00 PM - 12:00 AM
*/
var element = '';
for(var i = 0; i < open_times.length; i++){
if (!compareTimes(open_times[i], open_times[i-1]) ||
!areConsecutiveDays(open_times[i-1], open_times[i])) {
element += '<div class="col-md-3"><b>';
}
if ((!compareTimes(open_times[i], open_times[i-1])
|| !areConsecutiveDays(open_times[i-1], open_times[i]))
&& compareTimes(open_times[i], open_times[i+1])
&& areConsecutiveDays(open_times[i], open_times[i+1])) {
// Add: "StartDay - "
element += days[open_times[i].start_day] + ' - ';
}
if (!compareTimes(open_times[i], open_times[i+1]) ||
open_times[i].start_day !== (open_times[i+1].start_day - 1)) {
// Add "EndDay: OpenTime - CloseTime"
opening = Date.parse(open_times[i].start_time);
closing = Date.parse(open_times[i].end_time);
element += days[open_times[i].start_day] + '</b>: ' +
opening.toLocaleTimeString().replace(/(\d+:\d{2})(:\d+ )/, "$1 ") + ' - ' +
closing.toLocaleTimeString().replace(/(\d+:\d{2})(:\d+ )/, "$1 ") + '</div>';
$(this).append(element);
element = '';
}
}
}
function dispalyInfo(restaurant) {
// Display restaurant info in the info-body without bracketed locations
$('#info-name').text(restaurant.name.replace(/ ?\[(.+)\]/, ''));
if (restaurant.location !== null){
$('#info-location').html('<b>Location:</b> ' + restaurant.location).show();
if (restaurant.location == '') {
$('#info-location').hide();
}
else {
$('#info-location').hide();
$('#info-location').html('<b>Location:</b> ' + restaurant.location).show();
}
if (restaurant.open){
$('#info-status').html('<b>Status:</b> Open');
......@@ -31,30 +77,10 @@ function dispalyInfo(restaurant) {
$('#info-status').html('<b>Status:</b> Closed');
$('#info-next').empty().hide()
}
$('#info-schedule').empty();
// Display all open times for the main schedule
var open_times = restaurant.current_schedule.open_times;
var element = '';
$('#info-schedule').empty();
for(var i = 0; i < open_times.length; i++){
if (!compareTimes(open_times[i], open_times[i-1])){
element += '<div class="col-md-3"><b>';
}
if (!compareTimes(open_times[i], open_times[i-1]) &&
// Add: "StartDay - "
compareTimes(open_times[i], open_times[i+1])){
element += days[open_times[i].start_day] + ' - ';
}
if (!compareTimes(open_times[i], open_times[i+1])){
// Add "EndDay: OpenTime - CloseTime"
opening = Date.parse(open_times[i].start_time);
closing = Date.parse(open_times[i].end_time);
element += days[open_times[i].start_day] + '</b>: ' +
opening.toLocaleTimeString().replace(/(\d+:\d{2})(:\d+ )/, "$1 ") + ' - ' +
closing.toLocaleTimeString().replace(/(\d+:\d{2})(:\d+ )/, "$1 ") + '</div>';
$("#info-schedule").append(element);
element = '';
}
}
$('#info-schedule').displaySchedule(open_times);
}
days = {
......
......@@ -6,7 +6,7 @@
<link href="{{ STATIC_URL }}css/style.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://www.datejs.com/build/date.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
<script src="{{ STATIC_URL }}js/bootstrap.min.js"></script>
<script src="{{ STATIC_URL }}js/grid.js"></script>
<script src="{{ STATIC_URL }}js/typeAhead.js"></script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment