Skip to content

Commit

Permalink
updated customer-provision-wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
Linko91 committed Feb 23, 2024
1 parent 900c08f commit 5533fa2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,24 @@ function validateUrl(rule: FormItemRule, value: string) {
}
function getProvisioningDefaultSettings() {
loadingDefaultSettings.value = true
Api.customers
.getProvisioningDefaultSettings()
.then(res => {
if (res.data.success) {
isNew.value = false
setForm(res.data?.customer_provisioning_default_settings)
}
})
.finally(() => {
loadingDefaultSettings.value = false
})
}
function load() {
if (!loadingDefaultSettings.value) {
loadingDefaultSettings.value = true
Api.customers
.getProvisioningDefaultSettings()
.then(res => {
if (res.data.success) {
isNew.value = false
setForm(res.data?.customer_provisioning_default_settings)
}
})
.finally(() => {
loadingDefaultSettings.value = false
})
getProvisioningDefaultSettings()
}
}
Expand All @@ -229,7 +233,7 @@ onBeforeMount(() => {
onMounted(() => {
emit("mounted", {
load: getProvisioningDefaultSettings
load
})
})
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const settingsFormCTX = ref<{ load: () => void } | null>(null)
const showForm = ref(false)
const loading = ref(false)
watch(showForm, () => {
settingsFormCTX.value?.load()
watch(showForm, val => {
if (val) {
settingsFormCTX.value?.load()
}
})
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,14 @@ import {
type FormItemRule,
type FormValidationError
} from "naive-ui"
import type { CustomerMeta, CustomerProvision } from "@/types/customers.d"
import type { CustomerMeta, CustomerProvision, CustomerProvisioningDefaultSettings } from "@/types/customers.d"
import Icon from "@/components/common/Icon.vue"
import Api from "@/api"
import isURL from "validator/es/lib/isURL"
import isPort from "validator/es/lib/isPort"
import isIP from "validator/es/lib/isIP"
import { onBeforeMount } from "vue"
import _uniqBy from "lodash/uniqBy"
const emit = defineEmits<{
(e: "update:loading", value: boolean): void
Expand All @@ -262,6 +263,7 @@ const ArrowLeftIcon = "carbon:arrow-left"
const loading = ref(false)
const loadingSubscriptions = ref(false)
const loadingDashboards = ref(false)
const loadingDefaultSettings = ref(false)
const message = useMessage()
const current = ref<number>(1)
const currentStatus = ref<StepsProps["status"]>("process")
Expand Down Expand Up @@ -398,7 +400,7 @@ function validateAtLeastOne(rule: FormItemRule, value: string[]) {
return true
}
function getClearForm(): CustomerProvision {
function getClearForm(settings?: CustomerProvisioningDefaultSettings): CustomerProvision {
return {
// step1
customer_name: customerName.value,
Expand All @@ -425,10 +427,10 @@ function getClearForm(): CustomerProvision {
wazuh_registration_port: "",
wazuh_logs_port: "",
wazuh_api_port: "",
wazuh_cluster_name: "",
wazuh_cluster_key: "",
wazuh_master_ip: "",
grafana_url: ""
wazuh_cluster_name: settings?.cluster_name || "",
wazuh_cluster_key: settings?.cluster_key || "",
wazuh_master_ip: settings?.master_ip || "",
grafana_url: settings?.grafana_url || ""
}
}
Expand All @@ -446,14 +448,32 @@ function prev() {
current.value--
}
function getProvisioningDefaultSettings() {
loadingDefaultSettings.value = true
Api.customers
.getProvisioningDefaultSettings()
.then(res => {
if (res.data.success) {
setForm(res.data?.customer_provisioning_default_settings)
}
})
.finally(() => {
loadingDefaultSettings.value = false
})
}
function getSubscriptions() {
loadingSubscriptions.value = true
Api.customers
.getProvisioningSubscriptions()
.then(res => {
if (res.data.success) {
subscriptionOptions.value = (res.data?.available_subscriptions || []).map(o => ({ label: o, value: o }))
subscriptionOptions.value = _uniqBy(
(res.data?.available_subscriptions || []).map(o => ({ label: o, value: o })),
"value"
)
} else {
message.warning(res.data?.message || "An error occurred. Please try again later.")
}
Expand All @@ -473,7 +493,10 @@ function getDashboards() {
.getProvisioningDashboards()
.then(res => {
if (res.data.success) {
dashboardOptions.value = (res.data?.available_dashboards || []).map(o => ({ label: o, value: o }))
dashboardOptions.value = _uniqBy(
(res.data?.available_dashboards || []).map(o => ({ label: o, value: o })),
"value"
)
} else {
message.warning(res.data?.message || "An error occurred. Please try again later.")
}
Expand Down Expand Up @@ -511,6 +534,11 @@ function reset() {
currentStatus.value = "process"
slideFormDirection.value = "right"
current.value = 1
setForm()
}
function setForm(settings?: CustomerProvisioningDefaultSettings) {
form.value = getClearForm(settings)
}
async function submit() {
Expand Down Expand Up @@ -540,6 +568,7 @@ async function submit() {
}
onBeforeMount(() => {
getProvisioningDefaultSettings()
getSubscriptions()
getDashboards()
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/Customers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<script setup lang="ts">
import CustomersList from "@/components/customers/CustomersList.vue"
import CustomerCreationButton from "@/components/customers/CustomerCreationButton.vue"
import CustomerDefaultSettingsButton from "@/components/customers/CustomerDefaultSettingsButton.vue"
import CustomerDefaultSettingsButton from "@/components/customers/provision/CustomerDefaultSettingsButton.vue"
import { onBeforeMount, onMounted, onUnmounted, ref } from "vue"
import { useRoute, useRouter } from "vue-router"
import { emitter } from "@/emitter"
Expand Down

0 comments on commit 5533fa2

Please sign in to comment.