remove 'created' hooks from components and fix agent and script optino dropdowns

This commit is contained in:
sadnub
2021-05-24 14:26:52 -04:00
parent 9df38bdd84
commit 3469709054
43 changed files with 107 additions and 121 deletions

View File

@@ -327,7 +327,7 @@ export default {
this.$axios
.post(`logs/auditlogs/optionsfilter/`, data)
.then(r => {
this.agentOptions = Object.freeze(r.data.map(agent => agent.hostname));
this.getAgentOptions().then(options => (this.agentOptions = Object.freeze(options)));
this.$q.loading.hide();
})
.catch(e => {
@@ -438,7 +438,7 @@ export default {
return this.searched ? "No data found. Try to refine you search" : "Click search to find audit logs";
},
},
created() {
mounted() {
this.getClients();
},
};

View File

@@ -129,7 +129,7 @@ export default {
});
},
},
created() {
mounted() {
this.getDeployments();
},
};

View File

@@ -121,7 +121,7 @@ export default {
});
},
},
created() {
mounted() {
this.getEventLog();
},
};

View File

@@ -120,7 +120,7 @@ export default {
this.$emit("hide");
},
},
created() {
mounted() {
this.getRoles();
},
};

View File

@@ -207,14 +207,13 @@ export default {
beforeUnmount() {
clearInterval(this.polling);
},
created() {
mounted() {
this.getAgent();
// disable loading bar
this.$q.loadingBar.setDefaults({ size: "0px" });
this.getProcesses();
},
mounted() {
this.refreshProcs();
},
};

View File

@@ -322,7 +322,7 @@ export default {
});
},
},
created() {
mounted() {
this.getServices();
},
};

View File

@@ -137,7 +137,7 @@ export default {
getOptions() {
this.getClients();
this.getSites();
this.agentOptions = this.getAgentOptions();
this.getAgentOptions().then(options => (this.agentOptions = Object.freeze(options)));
},
show() {
this.$refs.dialog.show();

View File

@@ -153,7 +153,7 @@ export default {
this.$emit("hide");
},
},
created() {
mounted() {
// create warning and error annotation on chart for certain check types
if (
this.check.check_type === "cpuload" ||

View File

@@ -278,11 +278,11 @@ export default {
}
},
},
created() {
mounted() {
this.setTitles();
this.getClients();
this.getAgents();
this.scriptOptions = this.getScriptOptions(this.showCommunityScripts);
this.getScriptOptions(this.showCommunityScripts).then(options => (this.scriptOptions = Object.freeze(options)));
this.selected_mode = this.mode;
},

View File

@@ -262,7 +262,7 @@ export default {
}
},
},
created() {
mounted() {
// Get custom fields
this.getCustomFields("agent").then(r => {
this.customFields = r.data.filter(field => !field.hide_in_ui);

View File

@@ -250,7 +250,7 @@ export default {
return text;
},
},
created() {
mounted() {
this.getClients();
},
};

View File

@@ -78,7 +78,7 @@ export default {
computed: {
...mapGetters(["selectedAgentPk"]),
},
created() {
mounted() {
this.getCurrentDate();
},
};

View File

@@ -167,8 +167,8 @@ export default {
});
},
},
created() {
this.scriptOptions = this.getScriptOptions(this.showCommunityScripts);
mounted() {
this.getScriptOptions(this.showCommunityScripts).then(options => (this.scriptOptions = Object.freeze(options)));
},
};
</script>

View File

@@ -97,7 +97,7 @@ export default {
return options.sort((a, b) => a.label.localeCompare(b.label));
},
},
created() {
mounted() {
this.getVersions();
},
};

View File

@@ -144,7 +144,7 @@ export default {
getOptions() {
this.getClients();
this.getSites();
this.agentOptions = this.getAgentOptions();
this.getAgentOptions().then(options => (this.agentOptions = Object.freeze(options)));
},
show() {
this.$refs.dialog.show();

View File

@@ -694,7 +694,7 @@ export default {
},
},
mounted() {
this.scriptOptions = this.getScriptOptions();
this.getScriptOptions(this.showCommunityScripts).then(options => (this.scriptOptions = Object.freeze(options)));
// Copy alertTemplate prop locally
if (this.editing) Object.assign(this.template, this.alertTemplate);
},

View File

@@ -125,7 +125,7 @@ export default {
}
},
},
created() {
mounted() {
if (this.mode === "edit") {
this.getCheck();
}

View File

@@ -154,7 +154,7 @@ export default {
computed: {
...mapGetters(["agentDisks"]),
},
created() {
mounted() {
if (this.mode === "add") {
this.setDiskOptions();
} else if (this.mode === "edit") {

View File

@@ -125,7 +125,7 @@ export default {
}
},
},
created() {
mounted() {
if (this.mode === "edit") {
this.getCheck();
}

View File

@@ -125,7 +125,7 @@ export default {
}
},
},
created() {
mounted() {
if (this.mode === "edit") {
this.getCheck();
}

View File

@@ -204,8 +204,8 @@ export default {
/^\d+$/.test(val) ? done(val) : done();
},
},
created() {
this.scriptOptions = this.getScriptOptions(this.showCommunityScripts);
mounted() {
this.getScriptOptions(this.showCommunityScripts).then(options => (this.scriptOptions = Object.freeze(options)));
if (this.mode === "edit") this.getCheck();
},

View File

@@ -237,10 +237,8 @@ export default {
}
},
},
created() {
this.setServices();
},
mounted() {
this.setServices();
if (this.mode === "edit") {
this.getCheck();
}

View File

@@ -164,7 +164,7 @@ export default {
this.hide();
},
},
created() {
mounted() {
// Get custom fields
this.getCustomFields("client").then(r => {
this.customFields = r.data.filter(field => !field.hide_in_ui);

View File

@@ -158,7 +158,7 @@ export default {
this.hide();
},
},
created() {
mounted() {
this.getSites();
},
};

View File

@@ -142,7 +142,7 @@ export default {
return this.client !== null ? this.formatSiteOptions(this.client.sites) : [];
},
},
created() {
mounted() {
this.getCurrentDate();
this.getClients();
},

View File

@@ -189,7 +189,7 @@ export default {
this.hide();
},
},
created() {
mounted() {
this.getClients();
// Get custom fields

View File

@@ -81,7 +81,7 @@ export default {
});
},
},
created() {
mounted() {
this.getToken();
},
};

View File

@@ -494,7 +494,7 @@ export default {
});
},
},
created() {
mounted() {
this.getCoreSettings();
this.getPolicies();
this.getAlertTemplates();

View File

@@ -217,7 +217,7 @@ export default {
.catch(e => {});
},
},
created() {
mounted() {
this.getUserPrefs();
},
};

View File

@@ -76,7 +76,7 @@ export default {
.catch(e => {});
},
},
created() {
mounted() {
this.getLog();
},
};

View File

@@ -228,7 +228,7 @@ export default {
return !!this.agentpk ? `Pending Actions for ${this.hostname}` : "All Pending Actions";
},
},
created() {
mounted() {
this.getPendingActions();
},
};

View File

@@ -253,7 +253,7 @@ export default {
return this.maximized ? "--prism-height: 76vh" : "--prism-height: 70vh";
},
},
created() {
mounted() {
if (!!this.script) {
this.localScript.id = this.script.id;
this.localScript.name = this.script.name;

View File

@@ -105,7 +105,7 @@ export default {
computed: {
...mapGetters(["agentHostname"]),
},
created() {
mounted() {
this.getChocos();
},
};

View File

@@ -1,22 +1,16 @@
<template>
<q-card v-if="scriptOptions.length === 0" class="q-pa-xs" style="min-width: 400px">
<q-card class="q-pa-xs" style="min-width: 40vw">
<q-card-section class="row items-center">
<div class="text-h6">Add Automated Task</div>
<q-space />
<q-btn icon="close" flat round dense v-close-popup />
</q-card-section>
<q-card-section>
<q-card-section v-if="scriptOptions.length === 0">
<p>You need to upload a script first</p>
<p>Settings -> Script Manager</p>
</q-card-section>
</q-card>
<q-card v-else class="q-pa-xs" style="min-width: 40vw">
<q-card-section class="row items-center">
<div class="text-h6">Add Automated Task</div>
<q-space />
<q-btn icon="close" flat round dense v-close-popup />
</q-card-section>
<q-stepper v-model="step" ref="stepper" color="primary" animated>
<q-stepper v-else v-model="step" ref="stepper" color="primary" animated>
<q-step :name="1" title="Select Task" :done="step1Done" :error="!step1Done">
<q-card-section>
<q-select
@@ -352,8 +346,8 @@ export default {
}
},
},
created() {
this.scriptOptions = this.getScriptOptions(this.showCommunityScripts);
mounted() {
this.getScriptOptions(this.showCommunityScripts).then(options => (this.scriptOptions = Object.freeze(options)));
if (this.policypk) {
this.getPolicyChecks();

View File

@@ -190,7 +190,7 @@ export default {
},
},
mounted() {
this.scriptOptions = this.getScriptOptions(this.showCommunityScripts);
this.getScriptOptions(this.showCommunityScripts).then(options => (this.scriptOptions = Object.freeze(options)));
this.getCustomFields("agent").then(r => {
this.customFieldOptions = r.data.map(field => ({ label: field.name, value: field.id }));

View File

@@ -156,77 +156,73 @@ export default {
}
return tempArray
},
getScriptOptions(showCommunityScripts = false) {
async getScriptOptions(showCommunityScripts = false) {
let options = [];
axios.get("/scripts/scripts/").then(r => {
let scripts;
if (showCommunityScripts) {
scripts = r.data;
} else {
scripts = r.data.filter(i => i.script_type !== "builtin");
const { data } = await axios.get("/scripts/scripts/")
let scripts;
if (showCommunityScripts) {
scripts = data;
} else {
scripts = data.filter(i => i.script_type !== "builtin");
}
let categories = [];
let create_unassigned = false
scripts.forEach(script => {
if (!!script.category && !categories.includes(script.category)) {
categories.push(script.category);
} else if (!script.category) {
create_unassigned = true
}
});
let categories = [];
let create_unassigned = false
if (create_unassigned) categories.push("Unassigned")
categories.sort().forEach(cat => {
options.push({ category: cat });
let tmp = [];
scripts.forEach(script => {
if (!!script.category && !categories.includes(script.category)) {
categories.push(script.category);
} else if (!script.category) {
create_unassigned = true
if (script.category === cat) {
tmp.push({ label: script.name, value: script.id, timeout: script.default_timeout, args: script.args });
} else if (cat === "Unassigned" && !script.category) {
tmp.push({ label: script.name, value: script.id, timeout: script.default_timeout, args: script.args });
}
});
if (create_unassigned) categories.push("Unassigned")
categories.sort().forEach(cat => {
options.push({ category: cat });
let tmp = [];
scripts.forEach(script => {
if (script.category === cat) {
tmp.push({ label: script.name, value: script.id, timeout: script.default_timeout, args: script.args });
} else if (cat === "Unassigned" && !script.category) {
tmp.push({ label: script.name, value: script.id, timeout: script.default_timeout, args: script.args });
}
})
const sorted = tmp.sort((a, b) => a.label.localeCompare(b.label));
options.push(...sorted);
});
})
.catch(e => { });
})
const sorted = tmp.sort((a, b) => a.label.localeCompare(b.label));
options.push(...sorted);
});
return options;
},
getAgentOptions() {
async getAgentOptions() {
let options = []
axios.get("/agents/listagentsnodetail/").then(r => {
const agents = r.data.map(agent => ({
label: agent.hostname,
value: agent.pk,
cat: `${agent.client} > ${agent.site}`,
}));
const { data } = await axios.get("/agents/listagentsnodetail/")
const agents = data.map(agent => ({
label: agent.hostname,
value: agent.pk,
cat: `${agent.client} > ${agent.site}`,
}));
let categories = [];
agents.forEach(option => {
if (!categories.includes(option.cat)) {
categories.push(option.cat);
let categories = [];
agents.forEach(option => {
if (!categories.includes(option.cat)) {
categories.push(option.cat);
}
});
categories.sort().forEach(cat => {
options.push({ category: cat });
let tmp = []
agents.forEach(agent => {
if (agent.cat === cat) {
tmp.push(agent);
}
});
categories.sort().forEach(cat => {
options.push({ category: cat });
let tmp = []
agents.forEach(agent => {
if (agent.cat === cat) {
tmp.push(agent);
}
});
const sorted = tmp.sort((a, b) => a.label.localeCompare(b.label));
options.push(...sorted);
});
})
.catch(e => { });
const sorted = tmp.sort((a, b) => a.label.localeCompare(b.label));
options.push(...sorted);
});
return options;
},

View File

@@ -888,14 +888,13 @@ export default {
},
},
},
created() {
mounted() {
this.setupWS();
this.getDashInfo();
this.$store.dispatch("getUpdatedSites");
this.$store.dispatch("checkVer");
this.getTree();
},
mounted() {
this.livePoll();
},
beforeUnmount() {

View File

@@ -112,7 +112,7 @@ export default {
.catch(e => {});
},
},
created() {
mounted() {
this.getSettings();
},
};

View File

@@ -105,7 +105,7 @@ export default {
});
},
},
created() {
mounted() {
this.$q.dark.set(true);
},
};

View File

@@ -97,7 +97,7 @@ export default {
return this.$route.params.pk;
},
},
created() {
mounted() {
this.getUI();
this.genURLS();
},

View File

@@ -1,14 +1,14 @@
<template>
<div class="fixed-center text-center">
<p class="text-faded">Your session has expired</p>
<q-btn color="secondary" style="width:200px;" to="/login">Login</q-btn>
<q-btn color="secondary" style="width: 200px" to="/login">Login</q-btn>
</div>
</template>
<script>
export default {
name: "SessionExpired",
created() {
mounted() {
this.$store.dispatch("destroyToken");
},
};

View File

@@ -79,7 +79,7 @@ export default {
});
},
},
created() {
mounted() {
this.getQRCodeData();
this.$q.dark.set(false);
},

View File

@@ -123,7 +123,7 @@ export default {
});
},
},
created() {
mounted() {
this.getUI();
this.genURL();
},