Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christopher M Reffett
whats-open
Commits
922e3f60
Commit
922e3f60
authored
Sep 21, 2013
by
Renfred Harper
Browse files
Fix auto-update to update more reliably
parent
7ff1b228
Changes
1
Show whitespace changes
Inline
Side-by-side
website/static/js/grid.js
View file @
922e3f60
...
@@ -106,22 +106,15 @@ $.ajax({
...
@@ -106,22 +106,15 @@ $.ajax({
restaurants
=
data
.
data
;
restaurants
=
data
.
data
;
update_grid
(
restaurants
);
update_grid
(
restaurants
);
construct_grid
(
restaurants
);
construct_grid
(
restaurants
);
// Update the grid on the hour and 30 minutes after the hour to reflect current hours without refreshing
// Every second, check and see if it is necessary to update the grid.
var
now
=
new
Date
();
var
last_updated
=
new
Date
();
// Find out the time to wait till the next half hour period
if
(
now
.
getMinutes
()
<=
30
)
{
var
timeout
=
new
Date
(
now
.
getFullYear
(),
now
.
getMonth
(),
now
.
getDate
(),
now
.
getHours
(),
30
,
1
,
0
)
-
now
;
}
else
{
var
timeout
=
new
Date
(
now
.
getFullYear
(),
now
.
getMonth
(),
now
.
getDate
(),
now
.
getHours
()
+
1
,
0
,
1
,
0
)
-
now
;
}
// Update the grid on the next half hour, then keep updating every 30 minutes (1800000 milliseconds)
setTimeout
(
function
(){
update_grid
(
restaurants
);
construct_grid
(
restaurants
);
},
timeout
);
setInterval
(
function
(){
setInterval
(
function
(){
now
=
new
Date
();
// If the hour has changed, it the half hour has changed or it has been over a half hour since the last update.
if
(
last_updated
.
getHours
()
!=
now
.
getHours
()
||
(
last_updated
.
getMinutes
()
<
30
&&
now
.
getMinutes
()
>=
30
)
||
now
-
last_updated
>
1800000
){
update_grid
(
restaurants
);
update_grid
(
restaurants
);
construct_grid
(
restaurants
);
construct_grid
(
restaurants
);
},
1800000
);
last_updated
=
new
Date
();
}
},
1000
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment