Host status auto refresh (#10606)

Co-authored-by: Rene Peinthor <rene.peinthor@linbit.com>
This commit is contained in:
Imvedansh 2025-03-25 17:20:25 +05:30 committed by GitHub
parent c9c02d030e
commit fc1f260d52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 20 deletions

View File

@ -111,9 +111,14 @@ export default {
label: 'label.disable.host', label: 'label.disable.host',
message: 'message.confirm.disable.host', message: 'message.confirm.disable.host',
dataView: true, dataView: true,
show: (record) => { return record.resourcestate === 'Enabled' }, show: (record) => record.resourcestate === 'Enabled',
popup: true, popup: true,
component: shallowRef(defineAsyncComponent(() => import('@/views/infra/HostEnableDisable'))) component: shallowRef(defineAsyncComponent(() => import('@/views/infra/HostEnableDisable'))),
events: {
'refresh-data': () => {
store.dispatch('refreshCurrentPage')
}
}
}, },
{ {
api: 'updateHost', api: 'updateHost',
@ -121,9 +126,14 @@ export default {
label: 'label.enable.host', label: 'label.enable.host',
message: 'message.confirm.enable.host', message: 'message.confirm.enable.host',
dataView: true, dataView: true,
show: (record) => { return record.resourcestate === 'Disabled' }, show: (record) => record.resourcestate === 'Disabled',
popup: true, popup: true,
component: shallowRef(defineAsyncComponent(() => import('@/views/infra/HostEnableDisable'))) component: shallowRef(defineAsyncComponent(() => import('@/views/infra/HostEnableDisable'))),
events: {
'refresh-data': () => {
store.dispatch('refreshCurrentPage')
}
}
}, },
{ {
api: 'prepareHostForMaintenance', api: 'prepareHostForMaintenance',

View File

@ -18,7 +18,7 @@
<template> <template>
<div class="form-layout"> <div class="form-layout">
<a-form <a-form
:ref="formRef" ref="formRef"
:model="form" :model="form"
:rules="rules" :rules="rules"
@finish="handleSubmit" @finish="handleSubmit"
@ -54,7 +54,7 @@
</template> </template>
<script> <script>
import { ref, reactive, toRaw } from 'vue' import { reactive, toRaw } from 'vue'
import { api } from '@/api' import { api } from '@/api'
export default { export default {
@ -78,11 +78,8 @@ export default {
this.resourcestate = this.resource.resourcestate this.resourcestate = this.resource.resourcestate
this.allocationstate = this.resourcestate === 'Enabled' ? 'Disable' : 'Enable' this.allocationstate = this.resourcestate === 'Enabled' ? 'Disable' : 'Enable'
}, },
beforeCreate () {
},
methods: { methods: {
initForm () { initForm () {
this.formRef = ref()
this.form = reactive({}) this.form = reactive({})
this.rules = reactive({}) this.rules = reactive({})
}, },
@ -97,11 +94,9 @@ export default {
}) })
}, },
handleSubmit (e) { handleSubmit (e) {
e.preventDefault() this.$refs.formRef.validate().then(() => {
this.formRef.value.validate().then(() => {
const values = toRaw(this.form) const values = toRaw(this.form)
const data = {
var data = {
allocationstate: this.allocationstate, allocationstate: this.allocationstate,
id: this.resource.id id: this.resource.id
} }
@ -110,24 +105,27 @@ export default {
} }
api('updateHost', data).then(_ => { api('updateHost', data).then(_ => {
this.$emit('close-action') this.$emit('close-action')
this.$emit('refresh-data')
}).catch(err => {
this.$message.error(err.message || 'Failed to update host status')
}) })
}).catch(() => {
this.$message.error('Validation failed. Please check the inputs.')
}) })
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
.reason { .reason {
padding-top: 20px padding-top: 20px;
} }
.form-layout { .form-layout {
width: 30vw; width: 30vw;
@media (min-width: 500px) {
@media (min-width: 500px) { width: 450px;
width: 450px;
}
} }
}
</style> </style>