Skip to content

Commit 2392d71

Browse files
rp-Imvedansh
authored andcommitted
Auto update the host status
1 parent 19d58e3 commit 2392d71

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

ui/src/config/section/infra/hosts.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ export default {
113113
dataView: true,
114114
show: (record) => record.resourcestate === 'Enabled',
115115
popup: true,
116-
component: shallowRef(defineAsyncComponent(() => import('@/views/infra/HostEnableDisable')))
116+
component: shallowRef(defineAsyncComponent(() => import('@/views/infra/HostEnableDisable'))),
117+
events: {
118+
'refresh-data': () => {
119+
store.dispatch('refreshCurrentPage')
120+
}
121+
}
117122
},
118123
{
119124
api: 'updateHost',
@@ -123,7 +128,12 @@ export default {
123128
dataView: true,
124129
show: (record) => record.resourcestate === 'Disabled',
125130
popup: true,
126-
component: shallowRef(defineAsyncComponent(() => import('@/views/infra/HostEnableDisable')))
131+
component: shallowRef(defineAsyncComponent(() => import('@/views/infra/HostEnableDisable'))),
132+
events: {
133+
'refresh-data': () => {
134+
store.dispatch('refreshCurrentPage')
135+
}
136+
}
127137
},
128138
{
129139
api: 'prepareHostForMaintenance',

ui/src/views/infra/HostEnableDisable.vue

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<template>
1919
<div class="form-layout">
2020
<a-form
21-
:ref="formRef"
21+
ref="formRef"
2222
:model="form"
2323
:rules="rules"
2424
@finish="handleSubmit"
@@ -54,7 +54,7 @@
5454
</template>
5555

5656
<script>
57-
import { ref, reactive, toRaw } from 'vue'
57+
import { reactive, toRaw } from 'vue'
5858
import { api } from '@/api'
5959
6060
export default {
@@ -78,11 +78,8 @@ export default {
7878
this.resourcestate = this.resource.resourcestate
7979
this.allocationstate = this.resourcestate === 'Enabled' ? 'Disable' : 'Enable'
8080
},
81-
beforeCreate () {
82-
},
8381
methods: {
8482
initForm () {
85-
this.formRef = ref()
8683
this.form = reactive({})
8784
this.rules = reactive({})
8885
},
@@ -97,17 +94,19 @@ export default {
9794
})
9895
},
9996
handleSubmit (e) {
100-
e.preventDefault()
101-
this.formRef.value.validate().then(() => {
97+
if (e) {
98+
e.preventDefault()
99+
}
100+
this.$refs.formRef.validate().then(() => {
102101
const values = toRaw(this.form)
103-
104-
var data = {
102+
const data = {
105103
allocationstate: this.allocationstate,
106104
id: this.resource.id
107105
}
108106
if (values.reason) {
109107
data.annotation = values.reason
110108
}
109+
<<<<<<< HEAD
111110
api('updateHost', data).then(_ => {
112111
this.$emit('close-action')
113112
this.$emit('refresh-data')
@@ -116,23 +115,34 @@ export default {
116115
})
117116
}).catch(() => {
118117
this.$message.error('Validation failed. Please check the inputs.')
118+
=======
119+
api('updateHost', data)
120+
.then(response => {
121+
this.$emit('refresh-data')
122+
this.$emit('close-action')
123+
})
124+
.catch(error => {
125+
console.error('Error updating host:', error)
126+
this.$emit('close-action')
127+
})
128+
}).catch(error => {
129+
console.error('Validation failed:', error)
130+
>>>>>>> 06ddb1abe6 (Auto update the host status)
119131
})
120132
}
121133
}
122134
}
123-
124135
</script>
125136

126137
<style scoped>
127138
.reason {
128-
padding-top: 20px
139+
padding-top: 20px;
129140
}
130141
131142
.form-layout {
132-
width: 30vw;
133-
134-
@media (min-width: 500px) {
135-
width: 450px;
136-
}
143+
width: 30vw;
144+
@media (min-width: 500px) {
145+
width: 450px;
137146
}
147+
}
138148
</style>

0 commit comments

Comments
 (0)