From bf840d5961bd860f2ac72d9490be555dcf039520 Mon Sep 17 00:00:00 2001 From: Darko Lukic Date: Sat, 24 Mar 2018 19:21:14 +0100 Subject: [PATCH] Add automatic data pulling --- ui/src/components/dashboard/Dashboard.vue | 4 ++++ ui/src/store.js | 9 +++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ui/src/components/dashboard/Dashboard.vue b/ui/src/components/dashboard/Dashboard.vue index 0c0ebf3..402609f 100644 --- a/ui/src/components/dashboard/Dashboard.vue +++ b/ui/src/components/dashboard/Dashboard.vue @@ -85,6 +85,10 @@ export default { }, beforeCreate() { this.$store.dispatch('requestSeries'); + + setInterval(function() { + this.$store.dispatch('requestSeries'); + }.bind(this), 5000); }, } diff --git a/ui/src/store.js b/ui/src/store.js index 90aa2de..2bc2289 100644 --- a/ui/src/store.js +++ b/ui/src/store.js @@ -3,7 +3,7 @@ import Vuex from 'vuex'; import moment from 'moment'; -const SERIES_MAX_SIZE = 50; +const SERIES_MAX_SIZE = 100; Vue.use(Vuex); @@ -27,8 +27,7 @@ const getters = { }, getLastValue: (state) => (key) => { if (state.series.length > 0) { - let last = state.series.reduce((l, e) => e.UTCUnixTime > l.UTCUnixTime ? e : l); - return last[key]; + return state.series[state.series.length - 1][key]; } return 'NA'; }, @@ -64,14 +63,12 @@ const actions = { let params = { format: 'json', limit: SERIES_MAX_SIZE, + from: state.series.length > 0 ? state.series[state.series.length - 1].UTCUnixTime : 0, }; Vue.http.get('series', { params }).then(response => { commit('setSeries', response.body); }); }, - addRandomValues({ commit }) { - commit('setSeries', [ { 'UTCUnixTime': 123123, 'TemperatureC': 26.0 } ]); - }, requestWifi({ commit }) { let params = { token: state.token,