mirror of https://github.com/apache/cloudstack.git
167 lines
4.5 KiB
Vue
167 lines
4.5 KiB
Vue
// Licensed to the Apache Software Foundation (ASF) under one
|
|
// or more contributor license agreements. See the NOTICE file
|
|
// distributed with this work for additional information
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
// to you under the Apache License, Version 2.0 (the
|
|
// "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing,
|
|
// software distributed under the License is distributed on an
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the License for the
|
|
// specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
<template>
|
|
<div class="form-layout">
|
|
<a-spin :spinning="loading">
|
|
<a-form
|
|
:form="form"
|
|
@submit="handleSubmit"
|
|
layout="vertical">
|
|
<a-form-item :label="$t('label.state')">
|
|
<a-select
|
|
id="state-selection"
|
|
v-decorator="['state', {
|
|
rules: [{ required: true }]
|
|
}]"
|
|
showSearch
|
|
optionFilterProp="children"
|
|
:filterOption="(input, option) => {
|
|
return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
|
}"
|
|
:loading="stateLoading"
|
|
:placeholder="apiParams.state.description"
|
|
autoFocus >
|
|
<a-select-option v-for="(opt, optIndex) in this.states" :key="optIndex">
|
|
{{ opt.name || opt.description }}
|
|
</a-select-option>
|
|
</a-select>
|
|
</a-form-item>
|
|
|
|
<div :span="24" class="action-button">
|
|
<a-button @click="closeAction">{{ this.$t('label.cancel') }}</a-button>
|
|
<a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('label.ok') }}</a-button>
|
|
</div>
|
|
</a-form>
|
|
</a-spin>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { api } from '@/api'
|
|
|
|
export default {
|
|
name: 'UpdateKubernetesSupportedVersion',
|
|
props: {
|
|
resource: {
|
|
type: Object,
|
|
required: true
|
|
}
|
|
},
|
|
data () {
|
|
return {
|
|
states: [],
|
|
stateLoading: false,
|
|
loading: false
|
|
}
|
|
},
|
|
beforeCreate () {
|
|
this.form = this.$form.createForm(this)
|
|
this.apiConfig = this.$store.getters.apis.updateKubernetesSupportedVersion || {}
|
|
this.apiParams = {}
|
|
this.apiConfig.params.forEach(param => {
|
|
this.apiParams[param.name] = param
|
|
})
|
|
},
|
|
created () {
|
|
this.states = [
|
|
{
|
|
id: 'Enabled',
|
|
name: this.$t('state.enabled')
|
|
},
|
|
{
|
|
id: 'Disabled',
|
|
name: this.$t('state.disabled')
|
|
}
|
|
]
|
|
},
|
|
mounted () {
|
|
this.fetchData()
|
|
},
|
|
methods: {
|
|
fetchData () {
|
|
var selectedState = 0
|
|
if (!this.isObjectEmpty(this.resource)) {
|
|
for (var i = 0; i < this.states.length; ++i) {
|
|
if (this.states[i].id === this.resource.state) {
|
|
selectedState = i
|
|
break
|
|
}
|
|
}
|
|
}
|
|
this.form.setFieldsValue({
|
|
state: selectedState
|
|
})
|
|
},
|
|
isValidValueForKey (obj, key) {
|
|
return key in obj && obj[key] != null
|
|
},
|
|
arrayHasItems (array) {
|
|
return array !== null && array !== undefined && Array.isArray(array) && array.length > 0
|
|
},
|
|
isObjectEmpty (obj) {
|
|
return !(obj !== null && obj !== undefined && Object.keys(obj).length > 0 && obj.constructor === Object)
|
|
},
|
|
handleSubmit (e) {
|
|
e.preventDefault()
|
|
this.form.validateFields((err, values) => {
|
|
if (err) {
|
|
return
|
|
}
|
|
this.loading = true
|
|
const params = {
|
|
id: this.resource.id
|
|
}
|
|
if (this.isValidValueForKey(values, 'state') && this.arrayHasItems(this.states)) {
|
|
params.state = this.states[values.state].id
|
|
}
|
|
api('updateKubernetesSupportedVersion', params).then(json => {
|
|
this.$message.success(`${this.$t('message.success.update.kubeversion')}: ${this.resource.name}`)
|
|
this.$emit('refresh-data')
|
|
this.closeAction()
|
|
}).catch(error => {
|
|
this.$notifyError(error)
|
|
}).finally(() => {
|
|
this.loading = false
|
|
})
|
|
})
|
|
},
|
|
closeAction () {
|
|
this.$emit('close-action')
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped lang="less">
|
|
.form-layout {
|
|
width: 60vw;
|
|
|
|
@media (min-width: 500px) {
|
|
width: 450px;
|
|
}
|
|
}
|
|
|
|
.action-button {
|
|
text-align: right;
|
|
|
|
button {
|
|
margin-right: 5px;
|
|
}
|
|
}
|
|
</style>
|