Skip to content

Commit

Permalink
Fixed clearInterval is not working within configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldzou committed Aug 3, 2024
1 parent b64ba2e commit 52989c8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/static/app/dist/assets/index.css

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions src/static/app/dist/assets/index.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ export default {
},
methods: {
peerCreate(){
this.saving = true
fetchPost("/api/addPeers/" + this.$route.params.id, this.data, (res) => {
if (res.status){
this.$router.push(`/configuration/${this.$route.params.id}/peers`)
this.dashboardStore.newMessage("Server", "Peer create successfully", "success")
}else{
this.dashboardStore.newMessage("Server", res.message, "danger")
}
this.saving = false;
})
}
},
Expand Down Expand Up @@ -132,10 +133,11 @@ export default {
</div>
<div class="d-flex mt-2">
<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()"
>
<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>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import ScheduleDropdown from "@/components/configurationComponents/peerScheduleJobsComponents/scheduleDropdown.vue";
import SchedulePeerJob from "@/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue";
import {WireguardConfigurationsStore} from "@/stores/WireguardConfigurationsStore.js";
import {v4} from "uuid";
export default {
name: "peerJobs",
setup(){
Expand All @@ -26,7 +27,7 @@ export default {
},
addJob(){
this.selectedPeer.jobs.unshift(JSON.parse(JSON.stringify({
JobID: crypto.randomUUID(),
JobID: v4().toString(),
Configuration: this.selectedPeer.configuration.Name,
Peer: this.selectedPeer.id,
Field: this.store.PeerScheduleJobs.dropdowns.Field[0].value,
Expand Down
28 changes: 18 additions & 10 deletions src/static/app/src/components/configurationComponents/peerList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import PeerCreate from "@/components/configurationComponents/peerCreate.vue";
import PeerJobs from "@/components/configurationComponents/peerJobs.vue";
import PeerJobsAllModal from "@/components/configurationComponents/peerJobsAllModal.vue";
import PeerJobsLogsModal from "@/components/configurationComponents/peerJobsLogsModal.vue";
import {ref} from "vue";
Chart.register(
ArcElement,
Expand Down Expand Up @@ -74,7 +75,8 @@ export default {
setup(){
const dashboardConfigurationStore = DashboardConfigurationStore();
const wireguardConfigurationStore = WireguardConfigurationsStore();
return {dashboardConfigurationStore, wireguardConfigurationStore}
const interval = ref(undefined)
return {dashboardConfigurationStore, wireguardConfigurationStore, interval}
},
data(){
return {
Expand Down Expand Up @@ -139,24 +141,29 @@ export default {
'$route': {
immediate: true,
handler(){
clearInterval(this.interval)
console.log(this.dashboardConfigurationStore.Peers.RefreshInterval)
clearInterval(this.dashboardConfigurationStore.Peers.RefreshInterval);
console.log(this.dashboardConfigurationStore.Peers.RefreshInterval)
this.loading = true;
let id = this.$route.params.id;
this.configurationInfo = [];
this.configurationPeers = [];
if (id){
this.getPeers(id)
this.setInterval();
console.log("Changed..")
this.setPeerInterval();
}
}
},
'dashboardConfigurationStore.Configuration.Server.dashboard_refresh_interval'(){
clearInterval(this.interval);
this.setInterval();
}
console.log("Changed?")
clearInterval(this.dashboardConfigurationStore.Peers.RefreshInterval);
this.setPeerInterval();
},
},
beforeRouteLeave(){
clearInterval(this.interval)
clearInterval(this.dashboardConfigurationStore.Peers.RefreshInterval);
},
methods:{
toggle(){
Expand Down Expand Up @@ -237,11 +244,12 @@ export default {
}
});
},
setInterval(){
this.interval = setInterval(() => {
setPeerInterval(){
this.dashboardConfigurationStore.Peers.RefreshInterval = setInterval(() => {
this.getPeers()
}, parseInt(this.dashboardConfigurationStore.Configuration.Server.dashboard_refresh_interval))
}
console.log(this.dashboardConfigurationStore.Peers.RefreshInterval)
},
},
computed: {
configurationSummary(){
Expand Down
3 changes: 2 additions & 1 deletion src/static/app/src/stores/DashboardConfigurationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const DashboardConfigurationStore = defineStore('DashboardConfigurationSt
Configuration: undefined,
Messages: [],
Peers: {
Selecting: false
Selecting: false,
RefreshInterval: undefined
}
}),
actions: {
Expand Down

0 comments on commit 52989c8

Please sign in to comment.