Commit a6f7b067 authored by Manuel Gauto's avatar Manuel Gauto

Fix data age display. Actually save new data when cache expires.

parent b34c4948
......@@ -7,11 +7,10 @@
</div>
<!-- Tabs -->
<div class="mdl-layout__tab-bar mdl-js-ripple-effect">
<a href="#fairfax" class="mdl-layout__tab is-active locationTab">Fairfax</a>
<a id="fairfax-tab-button" href="#fairfax" class="mdl-layout__tab is-active locationTab">Fairfax</a>
<a href="#arlington" class="mdl-layout__tab locationTab">Arlington</a>
<a href="#scitech" class="mdl-layout__tab locationTab">SciTech</a>
<a href="#korea" class="mdl-layout__tab locationTab">Mason Korea</a>
<a href="#saudi" class="mdl-layout__tab locationTab">Ras-Al-Khaimah</a>
</div>
</header>
<main class="mdl-layout__content">
......
Template.home.events({
'click' (event) {
'click #fairfax-tab-button' (event) {
alert("FUCK");
},
'click a.mdl-layout__tab-bar' (event) {
console.log("FUCK");
console.log(event);
}
});
Template.home.onRendered(function() {
document.getElementById("#fairfax-tab-button").addEventListener("click", function(){
alert("FUCK");
});
});
Template.weather.helpers({
weatherData: function() {
weatherDataDependency.depend();
if(weatherData === undefined) return "...";
return weatherData;
},
precipitationWords: function() {
weatherDataDependency.depend();
if(weatherData === undefined) return "...";
var precipProb = weatherData.data.currently.precipProbability;
if(precipProb === 0) return "No Rain Expected";
if(precipProb > 95) return "Bring an Umbrella";
......@@ -13,17 +15,22 @@ Template.weather.helpers({
},
windDirection: function() {
weatherDataDependency.depend();
if(weatherData === undefined) return "...";
return degreesToWords(weatherData.data.currently.windBearing);
},
windDirectionClass: function() {
weatherDataDependency.depend();
if(weatherData === undefined) return "...";
return degreesToWords(weatherData.data.currently.windBearing).toLowerCase();
},
roundNumber: function(number) {
if(number === undefined) return "...";
return Math.round(number);
},
formatTimestamp(timestamp) {
var d = new Date();
if(timestamp === undefined) return "...";
var d = new Date(timestamp*1000);
console.log("GOT: "+timestamp)
return d.toLocaleString("en-us", { hour: 'numeric', minute: 'numeric', timeZoneName:'short'});
}
});
......
{
"weatherCacheExpireTime": "3600"
}
......@@ -9,6 +9,7 @@ function getWeather(latitude, longitude) {
//Check if there is data at all
if(curWeatherData === undefined) {
console.log("Getting first time data.")
var weatherData = getWeatherFromAPI(latitude, longitude);
WeatherData.insert(weatherData);
return curWeatherData;
......@@ -16,8 +17,9 @@ function getWeather(latitude, longitude) {
var date = new Date();
var timeDiff = (date.getTime()) - curWeatherData.retrievalTime; //Subtract the data timestamp form cur time to get age
if(timeDiff > Meteor.settings.weatherCacheExpireTime) {
if(timeDiff > (Meteor.settings.weatherCacheExpireTime*1000)) {
//Data is expired, retrieve again.
console.log("Data Age: "+timeDiff)
console.log("Cache expired. Retrieving...")
var weatherData = getWeatherFromAPI(latitude, longitude);
if(weatherData === undefined) {
......@@ -29,7 +31,7 @@ function getWeather(latitude, longitude) {
//Technically the else isn't needed but it looks nice.
//Save this data.
WeatherData.insert(curWeatherData);
WeatherData.insert(weatherData);
return curWeatherData;
}
} else {
......
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