2020-06-12 17:40:18 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<button @click="refreshAll()" class="btn btn-secondary">
|
|
|
|
Refresh all
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<b-form-checkbox class="float-right" v-model="autoRefresh" size="lg" switch
|
|
|
|
>AutoRefresh</b-form-checkbox
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2020-07-19 13:30:34 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Vue, Watch } from 'vue-property-decorator';
|
2020-07-19 13:35:10 +00:00
|
|
|
import { Action, State } from 'vuex-class';
|
2020-07-19 13:30:34 +00:00
|
|
|
|
|
|
|
@Component({})
|
|
|
|
export default class ReloadControl extends Vue {
|
|
|
|
autoRefresh = true;
|
|
|
|
|
|
|
|
refreshInterval: NodeJS.Timer | null = null;
|
|
|
|
|
|
|
|
refreshIntervalSlow: NodeJS.Timer | null = null;
|
|
|
|
|
2020-06-12 17:40:18 +00:00
|
|
|
created() {
|
2020-07-19 13:35:10 +00:00
|
|
|
if (this.loggedIn) {
|
|
|
|
this.refreshOnce();
|
|
|
|
this.refreshAll();
|
|
|
|
}
|
2020-07-19 13:30:34 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 17:40:18 +00:00
|
|
|
mounted() {
|
|
|
|
this.startRefresh();
|
2020-07-19 13:30:34 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 17:40:18 +00:00
|
|
|
beforeDestroy() {
|
|
|
|
this.stopRefresh();
|
2020-07-19 13:30:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-19 13:35:10 +00:00
|
|
|
@State loggedIn;
|
|
|
|
|
2020-07-19 13:30:34 +00:00
|
|
|
@Action refreshSlow;
|
|
|
|
|
|
|
|
@Action refreshFrequent;
|
|
|
|
|
|
|
|
@Action refreshAll;
|
|
|
|
|
|
|
|
@Action refreshOnce;
|
|
|
|
|
|
|
|
startRefresh() {
|
2020-07-19 13:35:10 +00:00
|
|
|
if (this.loggedIn !== true) {
|
|
|
|
console.log('Not logged in.');
|
|
|
|
return;
|
|
|
|
}
|
2020-07-19 13:30:34 +00:00
|
|
|
console.log('Starting automatic refresh.');
|
|
|
|
this.refreshFrequent();
|
|
|
|
if (this.autoRefresh) {
|
|
|
|
this.refreshInterval = setInterval(() => {
|
|
|
|
this.refreshFrequent();
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
this.refreshSlow();
|
|
|
|
if (this.autoRefresh) {
|
|
|
|
this.refreshIntervalSlow = setInterval(() => {
|
|
|
|
this.refreshSlow();
|
|
|
|
}, 60000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stopRefresh() {
|
|
|
|
console.log('Stopping automatic refresh.');
|
|
|
|
if (this.refreshInterval) {
|
|
|
|
clearInterval(this.refreshInterval);
|
|
|
|
}
|
|
|
|
if (this.refreshIntervalSlow) {
|
|
|
|
clearInterval(this.refreshIntervalSlow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Watch('autoRefresh')
|
|
|
|
watchAutoRefresh(val) {
|
|
|
|
if (val) {
|
|
|
|
this.startRefresh();
|
|
|
|
} else {
|
|
|
|
this.stopRefresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 17:40:18 +00:00
|
|
|
</script>
|
|
|
|
|
2020-07-11 18:00:13 +00:00
|
|
|
<style scoped>
|
2020-06-12 17:40:18 +00:00
|
|
|
</style>
|