edit diskcheck refactor

This commit is contained in:
wh1te909
2020-05-29 09:40:38 +00:00
parent c925decc16
commit 2187d3b968
2 changed files with 43 additions and 13 deletions

View File

@@ -85,11 +85,11 @@
</template>
<!-- body slots -->
<template slot="body" slot-scope="props" :props="props">
<q-tr @contextmenu="editCheckPK = props.row.id">
<q-tr @contextmenu="checkpk = props.row.id">
<!-- context menu -->
<q-menu context-menu>
<q-list dense style="min-width: 200px">
<q-item clickable v-close-popup @click="editCheck(props.row.check_type)">
<q-item clickable v-close-popup @click="showCheck('edit', props.row.check_type)">
<q-item-section side>
<q-icon name="edit" />
</q-item-section>
@@ -187,8 +187,14 @@
</div>
<!-- modals -->
<q-dialog v-model="showDiskSpaceCheck">
<DiskSpaceCheck @close="showDiskSpaceCheck = false" :agentpk="selectedAgentPk" :mode="mode" />
<DiskSpaceCheck
@close="showDiskSpaceCheck = false"
:agentpk="selectedAgentPk"
:mode="mode"
:checkpk="checkpk"
/>
</q-dialog>
<!-- refactor below -->
<q-dialog v-model="showAddPingCheck">
<AddPingCheck @close="showAddPingCheck = false" :agentpk="selectedAgentPk" />
</q-dialog>
@@ -309,6 +315,7 @@ export default {
data() {
return {
mode: "add",
checkpk: null,
showDiskSpaceCheck: false,
// refactor below
showAddPingCheck: false,

View File

@@ -7,9 +7,15 @@
<q-btn icon="close" flat round dense v-close-popup />
</q-card-section>
<q-form @submit.prevent="addCheck">
<q-form @submit.prevent="mode === 'add' ? addCheck() : editCheck()">
<q-card-section>
<q-select outlined v-model="diskcheck.disk" :options="diskOptions" label="Disk" />
<q-select
:disable="this.mode === 'edit'"
outlined
v-model="diskcheck.disk"
:options="diskOptions"
label="Disk"
/>
</q-card-section>
<q-card-section>
<q-input
@@ -50,7 +56,8 @@ export default {
props: {
agentpk: Number,
policypk: Number,
mode: String
mode: String,
checkpk: Number
},
mixins: [mixins],
data() {
@@ -72,6 +79,9 @@ export default {
this.diskcheck.disk = this.diskOptions[0];
}
},
getCheck() {
axios.get(`/checks/${this.checkpk}/check/`).then(r => (this.diskcheck = r.data));
},
addCheck() {
const pk = this.policypk ? { policy: this.policypk } : { pk: this.agentpk };
const data = {
@@ -82,16 +92,27 @@ export default {
.post("/checks/checks/", data)
.then(r => {
this.$emit("close");
if (this.policypk) {
this.$store.dispatch("automation/loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
this.reloadChecks();
this.notifySuccess(r.data);
})
.catch(e => this.notifyError(e.response.data));
},
editCheck() {
axios
.patch(`/checks/${this.checkpk}/check/`, this.diskcheck)
.then(r => {
this.$emit("close");
this.reloadChecks();
this.notifySuccess(r.data);
})
.catch(e => this.notifyError(e.response.data));
},
reloadChecks() {
if (this.policypk) {
this.$store.dispatch("automation/loadPolicyChecks", this.policypk);
} else {
this.$store.dispatch("loadChecks", this.agentpk);
}
}
},
computed: {
@@ -103,6 +124,8 @@ export default {
this.diskcheck.threshold = 25;
this.diskcheck.fails_b4_alert = 1;
this.setDiskOptions();
} else if (this.mode === "edit") {
this.getCheck();
}
}
};