2020-06-12 17:40:18 +00:00
|
|
|
<template>
|
2020-11-13 19:19:16 +00:00
|
|
|
<div class="container-fluid">
|
|
|
|
<div class="row">
|
|
|
|
<button class="m-1 btn btn-primary" @click="refreshAll(true)"><RefreshIcon /></button>
|
|
|
|
|
|
|
|
<b-form-checkbox
|
|
|
|
v-model="autoRefreshLoc"
|
2020-11-20 05:48:18 +00:00
|
|
|
class="ml-auto float-right mr-2 my-auto"
|
2020-11-13 19:19:16 +00:00
|
|
|
title="AutoRefresh"
|
|
|
|
switch
|
|
|
|
>AutoRefresh</b-form-checkbox
|
|
|
|
>
|
|
|
|
</div>
|
2020-06-12 17:40:18 +00:00
|
|
|
</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-11-13 19:19:16 +00:00
|
|
|
import RefreshIcon from 'vue-material-design-icons/Refresh.vue';
|
2020-07-19 13:30:34 +00:00
|
|
|
|
2020-11-13 19:19:16 +00:00
|
|
|
@Component({ components: { RefreshIcon } })
|
2020-07-19 13:30:34 +00:00
|
|
|
export default class ReloadControl extends Vue {
|
2020-09-07 18:44:57 +00:00
|
|
|
refreshInterval: number | null = null;
|
2020-07-19 13:30:34 +00:00
|
|
|
|
2020-09-07 18:44:57 +00:00
|
|
|
refreshIntervalSlow: number | null = null;
|
2020-07-19 13:30:34 +00:00
|
|
|
|
2020-06-12 17:40:18 +00:00
|
|
|
created() {
|
2020-07-19 13:35:10 +00:00
|
|
|
if (this.loggedIn) {
|
|
|
|
this.refreshOnce();
|
2020-11-10 19:24:00 +00:00
|
|
|
this.refreshAll(true);
|
2020-07-19 13:35:10 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2020-09-08 13:45:01 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2020-07-23 17:58:25 +00:00
|
|
|
@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) {
|
2020-09-07 18:44:57 +00:00
|
|
|
this.refreshInterval = window.setInterval(() => {
|
2020-07-19 13:30:34 +00:00
|
|
|
this.refreshFrequent();
|
|
|
|
}, 5000);
|
|
|
|
}
|
2020-11-10 19:24:00 +00:00
|
|
|
this.refreshSlow(true);
|
2020-07-19 13:30:34 +00:00
|
|
|
if (this.autoRefresh) {
|
2020-09-07 18:44:57 +00:00
|
|
|
this.refreshIntervalSlow = window.setInterval(() => {
|
2020-11-10 19:24:00 +00:00
|
|
|
this.refreshSlow(false);
|
2020-07-19 13:30:34 +00:00
|
|
|
}, 60000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stopRefresh() {
|
|
|
|
console.log('Stopping automatic refresh.');
|
|
|
|
if (this.refreshInterval) {
|
2020-09-07 18:44:57 +00:00
|
|
|
window.clearInterval(this.refreshInterval);
|
2020-07-19 13:30:34 +00:00
|
|
|
}
|
|
|
|
if (this.refreshIntervalSlow) {
|
2020-09-07 18:44:57 +00:00
|
|
|
window.clearInterval(this.refreshIntervalSlow);
|
2020-07-19 13:30:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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>
|