🚧 Commiting to switch computers...

This commit is contained in:
Alicia Sykes
2021-12-23 08:58:52 +00:00
parent c1d10d2791
commit 0074c636b6
4 changed files with 110 additions and 9 deletions

View File

@@ -290,6 +290,7 @@ export default {
loading: false,
error: false,
errorMsg: null,
updater: null, // Stores interval
}),
computed: {
/* Returns the widget type, shows error if not specified */
@@ -308,6 +309,20 @@ export default {
widgetRef() {
return `widget-${this.widgetType}-${this.index}`;
},
/* Returns either `false` or a number in ms to continuously update widget data */
updateInterval() {
const usersInterval = this.widget.updateInterval;
if (!usersInterval) return false;
// If set to `true`, then default to 30 seconds
if (typeof usersInterval === 'boolean') return 30 * 1000;
// If set to a number, and within valid range, return user choice
if (typeof usersInterval === 'number'
&& usersInterval >= 10
&& usersInterval < 7200) {
return usersInterval * 1000;
}
return false;
},
},
methods: {
/* Calls update data method on widget */
@@ -328,6 +343,17 @@ export default {
this.loading = loading;
},
},
mounted() {
// If continuous updates enabled, create interval
if (this.updateInterval) {
this.updater = setInterval(() => {
this.update();
}, this.updateInterval);
}
},
beforeDestroy() {
clearInterval(this.updater);
},
};
</script>