2020-06-12 17:40:18 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<button @click="refreshAll()" class="btn btn-secondary">
|
|
|
|
Refresh all
|
|
|
|
</button>
|
|
|
|
|
2020-07-23 17:58:25 +00:00
|
|
|
<b-form-checkbox class="float-right" v-model="autoRefreshLoc" size="lg" switch
|
2020-06-12 17:40:18 +00:00
|
|
|
>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 {
|
|
|
|
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-23 17:58:25 +00:00
|
|
|
@State autoRefresh!: boolean;
|
|
|
|
|
|
|
|
@Action setAutoRefresh!: (newValue: boolean) => void;
|
|
|
|
|
2020-07-19 13:30:34 +00:00
|
|
|
@Action refreshSlow;
|
|
|
|
|
|
|
|
@Action refreshFrequent;
|
|
|
|
|
|
|
|
@Action refreshAll;
|
|
|
|
|
|
|
|
@Action refreshOnce;
|
|
|
|
|
2020-07-23 17:58:25 +00:00
|
|
|
get autoRefreshLoc() {
|
|
|
|
return this.autoRefresh;
|
|
|
|
}
|
|
|
|
|
|
|
|
set autoRefreshLoc(newValue: boolean) {
|
|
|
|
this.setAutoRefresh(newValue);
|
|
|
|
}
|
|
|
|
|
2020-07-19 13:30:34 +00:00
|
|
|
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-26 08:48:07 +00:00
|
|
|
<style scoped></style>
|