Commit a6f7b067 authored by Manuel Gauto's avatar Manuel Gauto
Browse files

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

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