aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/time.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/time.js')
-rw-r--r--src/js/time.js49
1 files changed, 39 insertions, 10 deletions
diff --git a/src/js/time.js b/src/js/time.js
index 1757257..d4c3aa3 100644
--- a/src/js/time.js
+++ b/src/js/time.js
@@ -1,16 +1,31 @@
import { load as load_template } from './templates';
import Mustache from 'mustache';
+import { weather } from 'agl-js-api';
var template;
var root;
+var counter = 0;
+var updateTime = 10000;
var page = {
date: {
day: '',
hour: ''
},
- weather: {
- icon: 'fas fa-cloud-sun-rain',
- temperature: '20ºC'
+ weather: undefined,
+ showTemperature: function() {
+ return counter%5 === 0;
+ },
+ showWind: function() {
+ return counter%5 === 1;
+ },
+ showPosition: function() {
+ return counter%5 === 2;
+ },
+ showHumidity: function() {
+ return counter%5 === 3;
+ },
+ showDescription: function() {
+ return counter%5 === 4;
}
}
@@ -29,15 +44,28 @@ function formatAMPM(date) {
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
- }
+}
-function initInterval() {
- setInterval(function() {
- var date = new Date();
- page.date.day = days[date.getDay()],
- page.date.hour = formatAMPM(date);
+function update() {
+ var date = new Date();
+ page.date.day = days[date.getDay()],
+ page.date.hour = formatAMPM(date);
+ if( counter === 0 || !page.weather) {
+ weather.current_weather().then(function(result) {
+ page.weather = result;
+ show();
+ }, function(error) {
+ console.error(error);
+ show();
+ });
+ } else {
show();
- }, 1000);
+ }
+ counter = (counter+1) % Math.floor(300000/updateTime);
+}
+
+function initInterval() {
+ setInterval(update, updateTime);
}
export function init(node) {
@@ -45,6 +73,7 @@ export function init(node) {
template = result;
root = node;
Mustache.parse(template);
+ update();
initInterval();
}, function(error) {
console.error('ERRROR loading main template', error);