modify database for workstation/server policies

This commit is contained in:
Josh Krawczyk
2020-08-22 09:57:03 -04:00
parent 17369890d2
commit 0a6ff54497
4 changed files with 157 additions and 25 deletions

View File

@@ -1,19 +1,64 @@
<template>
<q-card style="width: 60vw">
<q-card-section class="row items-center">
<div class="text-h6">Edit policy assigned to {{ type }}</div>
<div class="text-h6">Edit policies assigned to {{ type }}</div>
<q-space />
<q-btn icon="close" flat round dense v-close-popup />
</q-card-section>
<q-form @submit="submit" ref="form">
<q-card-section>
<q-card-section v-if="type !== 'agent'">
<q-select
v-model="selected"
v-model="selectedServerPolicy"
:options="options"
filled
options-selected-class="text-green"
dense
clearable
label="Server Policy"
>
<template v-slot:option="props">
<q-item v-bind="props.itemProps" v-on="props.itemEvents">
<q-item-section avatar>
<q-icon v-if="props.selected" name="check" />
</q-item-section>
<q-item-section>
<q-item-label v-html="props.opt.label" />
</q-item-section>
</q-item>
</template>
</q-select>
</q-card-section>
<q-card-section>
<q-select
v-model="selectedWorkstationPolicy"
:options="options"
filled
options-selected-class="text-green"
dense
clearable
label="Workstation Policy"
>
<template v-slot:option="props">
<q-item v-bind="props.itemProps" v-on="props.itemEvents">
<q-item-section avatar>
<q-icon v-if="props.selected" name="check" />
</q-item-section>
<q-item-section>
<q-item-label v-html="props.opt.label" />
</q-item-section>
</q-item>
</template>
</q-select>
</q-card-section>
<q-card-section v-if="type === 'agent'">
<q-select
v-model="selectedAgentPolicy"
:options="options"
filled
options-selected-class="text-green"
dense
clearable
label="Policy"
>
<template v-slot:option="props">
<q-item v-bind="props.itemProps" v-on="props.itemEvents">
@@ -28,7 +73,7 @@
</q-select>
</q-card-section>
<q-card-section class="row items-center">
<q-btn label="Add Policy" color="primary" type="submit" />
<q-btn label="Add Policies" color="primary" type="submit" />
</q-card-section>
</q-form>
</q-card>
@@ -45,29 +90,32 @@ export default {
type: {
required: true,
type: String,
validator: function(value) {
validator: function (value) {
// The value must match one of these strings
return ["agent", "site", "client"].includes(value);
}
}
},
},
},
data() {
return {
selected: null,
options: []
selectedWorkstationPolicy: null,
selectedServerPolicy: null,
selectedAgentPolicy: null,
options: [],
};
},
computed: {
...mapGetters({
policies: "automation/policies"
})
policies: "automation/policies",
}),
},
methods: {
submit() {
this.$q.loading.show();
let data = {};
(data.pk = this.pk), (data.type = this.type);
data.pk = this.pk;
data.type = this.type;
data.policy = this.selected === null ? 0 : this.selected.value;
this.$store
@@ -88,7 +136,7 @@ export default {
.then(() => {
this.options = this.policies.map(policy => ({
label: policy.name,
value: policy.id
value: policy.id,
}));
})
.catch(e => {
@@ -101,20 +149,38 @@ export default {
.dispatch("automation/getRelatedPolicies", { pk, type })
.then(r => {
if (r.data.id !== undefined) {
this.selected = {
label: r.data.name,
value: r.data.id
};
if (type === "agent") {
this.selectedAgentPolicy = {
label: r.data.name,
value: r.data.id,
};
}
if (type !== "agent") {
if (r.data.server_policy.id !== undefined) {
this.selectedServerPolicy = {
label: r.data.server_policy.name,
value: r.data.server_policy.id,
};
}
if (r.data.workstation_policy.id !== undefined) {
this.selectedWorkstationPolicy = {
label: r.data.workstation_policy.name,
value: r.data.workstation_policy.id,
};
}
}
}
})
.catch(e => {
this.$q.notify(notifyErrorConfig("Add error occured while loading"));
});
}
},
},
mounted() {
this.getPolicies();
this.getRelation(this.pk, this.type);
}
},
};
</script>