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
SRCT
weather
Commits
a6f7b067
Commit
a6f7b067
authored
Nov 17, 2016
by
Manuel Gauto
Browse files
Fix data age display. Actually save new data when cache expires.
parent
b34c4948
Changes
5
Hide whitespace changes
Inline
Side-by-side
weather/client/views/home/home.html
View file @
a6f7b067
...
...
@@ -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"
>
...
...
weather/client/views/home/home.js
View file @
a6f7b067
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
"
);
});
});
weather/client/views/weather/weather.js
View file @
a6f7b067
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
'
});
}
});
...
...
weather/config/settings.json
0 → 100644
View file @
a6f7b067
{
"weatherCacheExpireTime"
:
"3600"
}
weather/server/methods.js
View file @
a6f7b067
...
...
@@ -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
(
curW
eatherData
);
WeatherData
.
insert
(
w
eatherData
);
return
curWeatherData
;
}
}
else
{
...
...
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