1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-22 15:20:09 +01:00

Fixed clearInterval is not working within configuration

This commit is contained in:
Donald Zou 2024-08-03 13:26:16 -04:00
parent b64ba2ef16
commit 52989c8f5c
6 changed files with 48 additions and 36 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -55,6 +55,7 @@ export default {
}, },
methods: { methods: {
peerCreate(){ peerCreate(){
this.saving = true
fetchPost("/api/addPeers/" + this.$route.params.id, this.data, (res) => { fetchPost("/api/addPeers/" + this.$route.params.id, this.data, (res) => {
if (res.status){ if (res.status){
this.$router.push(`/configuration/${this.$route.params.id}/peers`) this.$router.push(`/configuration/${this.$route.params.id}/peers`)
@ -62,7 +63,7 @@ export default {
}else{ }else{
this.dashboardStore.newMessage("Server", res.message, "danger") this.dashboardStore.newMessage("Server", res.message, "danger")
} }
this.saving = false;
}) })
} }
}, },
@ -132,10 +133,11 @@ export default {
</div> </div>
<div class="d-flex mt-2"> <div class="d-flex mt-2">
<button class="ms-auto btn btn-dark btn-brand rounded-3 px-3 py-2 shadow" <button class="ms-auto btn btn-dark btn-brand rounded-3 px-3 py-2 shadow"
:disabled="!this.allRequireFieldsFilled" :disabled="!this.allRequireFieldsFilled || this.saving"
@click="this.peerCreate()" @click="this.peerCreate()"
> >
<i class="bi bi-plus-circle-fill me-2"></i>Add <i class="bi bi-plus-circle-fill me-2" v-if="!this.saving"></i>
{{this.saving ? 'Saving...': 'Add'}}
</button> </button>
</div> </div>
</div> </div>

View File

@ -2,6 +2,7 @@
import ScheduleDropdown from "@/components/configurationComponents/peerScheduleJobsComponents/scheduleDropdown.vue"; import ScheduleDropdown from "@/components/configurationComponents/peerScheduleJobsComponents/scheduleDropdown.vue";
import SchedulePeerJob from "@/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue"; import SchedulePeerJob from "@/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue";
import {WireguardConfigurationsStore} from "@/stores/WireguardConfigurationsStore.js"; import {WireguardConfigurationsStore} from "@/stores/WireguardConfigurationsStore.js";
import {v4} from "uuid";
export default { export default {
name: "peerJobs", name: "peerJobs",
setup(){ setup(){
@ -26,7 +27,7 @@ export default {
}, },
addJob(){ addJob(){
this.selectedPeer.jobs.unshift(JSON.parse(JSON.stringify({ this.selectedPeer.jobs.unshift(JSON.parse(JSON.stringify({
JobID: crypto.randomUUID(), JobID: v4().toString(),
Configuration: this.selectedPeer.configuration.Name, Configuration: this.selectedPeer.configuration.Name,
Peer: this.selectedPeer.id, Peer: this.selectedPeer.id,
Field: this.store.PeerScheduleJobs.dropdowns.Field[0].value, Field: this.store.PeerScheduleJobs.dropdowns.Field[0].value,

View File

@ -39,6 +39,7 @@ import PeerCreate from "@/components/configurationComponents/peerCreate.vue";
import PeerJobs from "@/components/configurationComponents/peerJobs.vue"; import PeerJobs from "@/components/configurationComponents/peerJobs.vue";
import PeerJobsAllModal from "@/components/configurationComponents/peerJobsAllModal.vue"; import PeerJobsAllModal from "@/components/configurationComponents/peerJobsAllModal.vue";
import PeerJobsLogsModal from "@/components/configurationComponents/peerJobsLogsModal.vue"; import PeerJobsLogsModal from "@/components/configurationComponents/peerJobsLogsModal.vue";
import {ref} from "vue";
Chart.register( Chart.register(
ArcElement, ArcElement,
@ -74,7 +75,8 @@ export default {
setup(){ setup(){
const dashboardConfigurationStore = DashboardConfigurationStore(); const dashboardConfigurationStore = DashboardConfigurationStore();
const wireguardConfigurationStore = WireguardConfigurationsStore(); const wireguardConfigurationStore = WireguardConfigurationsStore();
return {dashboardConfigurationStore, wireguardConfigurationStore} const interval = ref(undefined)
return {dashboardConfigurationStore, wireguardConfigurationStore, interval}
}, },
data(){ data(){
return { return {
@ -139,24 +141,29 @@ export default {
'$route': { '$route': {
immediate: true, immediate: true,
handler(){ handler(){
clearInterval(this.interval) console.log(this.dashboardConfigurationStore.Peers.RefreshInterval)
clearInterval(this.dashboardConfigurationStore.Peers.RefreshInterval);
console.log(this.dashboardConfigurationStore.Peers.RefreshInterval)
this.loading = true; this.loading = true;
let id = this.$route.params.id; let id = this.$route.params.id;
this.configurationInfo = []; this.configurationInfo = [];
this.configurationPeers = []; this.configurationPeers = [];
if (id){ if (id){
this.getPeers(id) this.getPeers(id)
this.setInterval(); console.log("Changed..")
this.setPeerInterval();
} }
} }
}, },
'dashboardConfigurationStore.Configuration.Server.dashboard_refresh_interval'(){ 'dashboardConfigurationStore.Configuration.Server.dashboard_refresh_interval'(){
clearInterval(this.interval); console.log("Changed?")
this.setInterval(); clearInterval(this.dashboardConfigurationStore.Peers.RefreshInterval);
} this.setPeerInterval();
},
}, },
beforeRouteLeave(){ beforeRouteLeave(){
clearInterval(this.interval) clearInterval(this.dashboardConfigurationStore.Peers.RefreshInterval);
}, },
methods:{ methods:{
toggle(){ toggle(){
@ -237,11 +244,12 @@ export default {
} }
}); });
}, },
setInterval(){ setPeerInterval(){
this.interval = setInterval(() => { this.dashboardConfigurationStore.Peers.RefreshInterval = setInterval(() => {
this.getPeers() this.getPeers()
}, parseInt(this.dashboardConfigurationStore.Configuration.Server.dashboard_refresh_interval)) }, parseInt(this.dashboardConfigurationStore.Configuration.Server.dashboard_refresh_interval))
} console.log(this.dashboardConfigurationStore.Peers.RefreshInterval)
},
}, },
computed: { computed: {
configurationSummary(){ configurationSummary(){

View File

@ -8,7 +8,8 @@ export const DashboardConfigurationStore = defineStore('DashboardConfigurationSt
Configuration: undefined, Configuration: undefined,
Messages: [], Messages: [],
Peers: { Peers: {
Selecting: false Selecting: false,
RefreshInterval: undefined
} }
}), }),
actions: { actions: {