summaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
authorHumberto Alfonso Díaz <humberto.alfonso@asvito.es>2019-12-11 09:41:30 +0100
committerLorenzo Tilve <ltilve@igalia.com>2020-02-04 19:12:47 +0100
commit4ce65d8965bdebdf35e5f3a4272482c0f40ef2bd (patch)
treebac6b24ecfd7045975834c18b840dfd723baa2fb /src/js
parent6d8916c58d823b13b89477f59bf05373e87f3a98 (diff)
FUNCT Added homescreen
Diffstat (limited to 'src/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);