From 52dc82ed760f68a4efca005fd79f8faf2ef39d29 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sat, 6 Nov 2021 22:39:21 +0000 Subject: [PATCH] reduce api calls --- .../automation/modals/PolicyExclusions.vue | 23 ++++++++----------- .../modals/alerts/AlertExclusions.vue | 23 ++++++++----------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/components/automation/modals/PolicyExclusions.vue b/src/components/automation/modals/PolicyExclusions.vue index f97b950..669f16f 100644 --- a/src/components/automation/modals/PolicyExclusions.vue +++ b/src/components/automation/modals/PolicyExclusions.vue @@ -83,29 +83,26 @@ export default { this.$q.loading.hide(); }); }, - getClients() { + getClientsandSites() { + this.$q.loading.show(); this.$axios .get("/clients/") .then(r => { this.clientOptions = r.data.map(client => ({ label: client.name, value: client.id })); - }) - .catch(e => {}); - }, - getSites() { - this.$axios - .get("/clients/") - .then(r => { + r.data.forEach(client => { this.siteOptions.push({ category: client.name }); client.sites.forEach(site => this.siteOptions.push({ label: site.name, value: site.id })); }); + this.$q.loading.hide(); }) - .catch(e => {}); + .catch(() => { + this.$q.loading.hide(); + }); }, getOptions() { - this.getClients(); - this.getSites(); this.getAgentOptions("id").then(options => (this.agentOptions = Object.freeze(options))); + this.getClientsandSites(); }, show() { this.$refs.dialog.show(); @@ -122,13 +119,13 @@ export default { }, }, created() { - this.getOptions(); - // copy prop data locally this.localPolicy.id = this.policy.id; this.localPolicy.excluded_clients = this.policy.excluded_clients; this.localPolicy.excluded_sites = this.policy.excluded_sites; this.localPolicy.excluded_agents = this.policy.excluded_agents; + + this.getOptions(); }, }; \ No newline at end of file diff --git a/src/components/modals/alerts/AlertExclusions.vue b/src/components/modals/alerts/AlertExclusions.vue index cfd3c4e..a20a485 100644 --- a/src/components/modals/alerts/AlertExclusions.vue +++ b/src/components/modals/alerts/AlertExclusions.vue @@ -84,6 +84,7 @@ export default { }, methods: { onSubmit() { + this.$q.loading.show(); this.$axios .put(`alerts/templates/${this.template.id}/`, this.localTemplate) .then(r => { @@ -95,29 +96,26 @@ export default { this.$q.loading.hide(); }); }, - getClients() { + getClientsandSites() { + this.$q.loading.show(); this.$axios .get("/clients/") .then(r => { this.clientOptions = r.data.map(client => ({ label: client.name, value: client.id })); - }) - .catch(e => {}); - }, - getSites() { - this.$axios - .get("/clients/") - .then(r => { + r.data.forEach(client => { this.siteOptions.push({ category: client.name }); client.sites.forEach(site => this.siteOptions.push({ label: site.name, value: site.id })); }); + this.$q.loading.hide(); }) - .catch(e => {}); + .catch(() => { + this.$q.loading.hide(); + }); }, getOptions() { - this.getClients(); - this.getSites(); this.getAgentOptions("id").then(options => (this.agentOptions = Object.freeze(options))); + this.getClientsandSites(); }, show() { this.$refs.dialog.show(); @@ -134,8 +132,6 @@ export default { }, }, created() { - this.getOptions(); - // copy prop data locally this.localTemplate.id = this.template.id; this.localTemplate.excluded_clients = this.template.excluded_clients; @@ -143,6 +139,7 @@ export default { this.localTemplate.excluded_agents = this.template.excluded_agents; this.localTemplate.exclude_servers = this.template.exclude_servers; this.localTemplate.exclude_workstations = this.template.exclude_workstations; + this.getOptions(); }, }; \ No newline at end of file