blob: 2452456ea238152c08d4947856d56539f657423d [file]
// 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" v-ctrl-enter="handleSubmit">
<a-spin :spinning="loading">
<div style="margin-bottom: 20px;">
<a-alert type="warning">
<template #message>
<div v-html="$t('message.action.delete.dns.server')"></div>
</template>
</a-alert>
</div>
<div style="margin-bottom: 20px; word-break: break-all;">
Please type <strong>{{ resource.name }}</strong> to confirm.
</div>
<div v-if="dnsZones && dnsZones.length > 0" style="margin-bottom: 20px;">
<a-alert type="error">
<template #message>
<div>
<strong>This action will impact {{ this.totalDnsZones }} DNS Zone(s):</strong>
<ul style="margin-top: 10px; margin-bottom: 0; padding-left: 20px;">
<li v-for="zone in dnsZones.slice(0, this.maxResults)" :key="zone.id">{{ zone.name }}</li>
</ul>
<div v-if="this.totalDnsZones > this.maxResults" style="margin-top: 5px; font-style: italic;">
...and {{ this.totalDnsZones - this.maxResults }} more
</div>
</div>
</template>
</a-alert>
</div>
<a-form
ref="formRef"
:model="form"
:rules="rules"
layout="vertical"
@finish="handleSubmit">
<a-form-item name="name" ref="name">
<a-input
v-model:value="form.name"
:placeholder="resource.name"
v-focus="true" />
</a-form-item>
<a-form-item name="cleanup" ref="cleanup">
<template #label>
<tooltip-label :title="$t('label.cleanup')" :tooltip="apiParams.cleanup?.description" />
</template>
<a-switch v-model:checked="form.cleanup" @change="onCleanupChange" />
</a-form-item>
<a-form-item v-if="form.cleanup" name="unmanage" ref="unmanage">
<template #label>
<tooltip-label :title="$t('label.dns.unmanage.zone')" :tooltip="apiParams.unmanage?.description" />
</template>
<a-switch v-model:checked="form.unmanage" />
</a-form-item>
<div class="action-button">
<a-button @click="closeAction">
{{ $t('label.cancel') }}
</a-button>
<a-button
type="primary"
danger
:disabled="form.name !== resource.name"
:loading="loading"
htmlType="submit">
{{ $t('label.delete') }}
</a-button>
</div>
</a-form>
</a-spin>
</div>
</template>
<script>
import { getAPI, postAPI } from '@/api'
import TooltipLabel from '@/components/widgets/TooltipLabel'
export default {
name: 'DeleteDnsServer',
components: {
TooltipLabel
},
props: {
resource: {
type: Object,
required: true
}
},
data () {
return {
loading: false,
apiParams: {},
dnsZones: [],
form: {
name: '',
cleanup: true,
unmanage: false
},
rules: {
name: [{ required: true, message: this.$t('message.error.required.input') }]
},
maxResults: 5,
totalDnsZones: 0
}
},
created () {
this.apiParams = this.$getApiParams('deleteDnsServer') || {}
this.fetchDnsZones()
},
methods: {
onCleanupChange (checked) {
if (!checked) {
this.form.unmanage = false
}
},
async fetchDnsZones () {
this.loading = true
try {
const response = await getAPI('listDnsZones', { dnsserverid: this.resource.id, page: 1, pagesize: this.maxResults, filter: 'name' })
this.dnsZones = response?.listdnszonesresponse?.dnszone || []
this.totalDnsZones = response?.listdnszonesresponse?.count || 0
} catch (error) {
console.error('Failed to fetch DNS zones', error)
} finally {
this.loading = false
}
},
async handleSubmit () {
if (this.loading || this.form.name !== this.resource.name) return
this.loading = true
try {
const params = {
id: this.resource.id,
cleanup: this.form.cleanup
}
if (this.form.cleanup) {
params.unmanage = this.form.unmanage
}
const response = await postAPI('deleteDnsServer', params)
const jobId = response?.deletednsserverresponse?.jobid
if (!jobId) {
this.$notification.error({
message: this.$t('message.request.failed'),
description: 'Failed to get jobid for DeleteDnsServer',
duration: 0
})
this.loading = false
return
}
this.$pollJob({
jobId: jobId,
title: this.$t('label.dns.delete.server'),
description: this.resource.name,
successMethod: () => {
this.loading = false
this.$notification.success({
message: this.$t('label.dns.delete.server'),
description: `${this.$t('message.success.delete.dns.server')} ${this.resource.name}`
})
if (this.$route.path !== '/dnsserver') {
this.$router.push({ path: '/dnsserver' })
} else {
this.$emit('refresh-data')
}
},
errorMethod: () => {
this.loading = false
this.$notification.error({
message: this.$t('label.dns.delete.server'),
description: this.$t('message.error.delete.dns.server')
})
},
loadingMessage: `${this.$t('label.dns.delete.server')} ${this.resource.name} ${this.$t('label.in.progress')}`,
catchMessage: this.$t('error.fetching.async.job.result')
})
this.closeAction()
} catch (error) {
this.loading = false
this.$notification.error({
message: this.$t('message.request.failed'),
description: error?.response?.headers['x-description'] || error.message,
duration: 0
})
}
},
closeAction () {
this.$emit('close-action')
}
}
}
</script>
<style lang="less" scoped>
.form-layout {
width: 80vw;
@media (min-width: 600px) {
width: 450px;
}
}
.action-button {
text-align: right;
margin-top: 20px;
}
.action-button button {
margin-left: 8px;
}
</style>