|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +<template> |
| 19 | + <div class="form-layout" v-ctrl-enter="handleSubmit"> |
| 20 | + <a-spin :spinning="loading"> |
| 21 | + <div style="margin-bottom: 20px;"> |
| 22 | + <a-alert type="warning"> |
| 23 | + <template #message> |
| 24 | + <div v-html="$t('message.action.delete.dns.server')"></div> |
| 25 | + </template> |
| 26 | + </a-alert> |
| 27 | + </div> |
| 28 | + |
| 29 | + <div style="margin-bottom: 20px; word-break: break-all;"> |
| 30 | + Please type <strong>{{ resource.name }}</strong> to confirm. |
| 31 | + </div> |
| 32 | + |
| 33 | + <div v-if="dnsZones && dnsZones.length > 0" style="margin-bottom: 20px;"> |
| 34 | + <a-alert type="error"> |
| 35 | + <template #message> |
| 36 | + <div> |
| 37 | + <strong>This action will impact {{ this.totalDnsZones }} DNS Zone(s):</strong> |
| 38 | + <ul style="margin-top: 10px; margin-bottom: 0; padding-left: 20px;"> |
| 39 | + <li v-for="zone in dnsZones.slice(0, this.maxResults)" :key="zone.id">{{ zone.name }}</li> |
| 40 | + </ul> |
| 41 | + <div v-if="this.totalDnsZones > this.maxResults" style="margin-top: 5px; font-style: italic;"> |
| 42 | + ...and {{ this.totalDnsZones - this.maxResults }} more |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + </template> |
| 46 | + </a-alert> |
| 47 | + </div> |
| 48 | + |
| 49 | + <a-form |
| 50 | + ref="formRef" |
| 51 | + :model="form" |
| 52 | + :rules="rules" |
| 53 | + layout="vertical"> |
| 54 | + |
| 55 | + <a-form-item name="name" ref="name"> |
| 56 | + <a-input |
| 57 | + v-model:value="form.name" |
| 58 | + :placeholder="resource.name" |
| 59 | + v-focus="true" /> |
| 60 | + </a-form-item> |
| 61 | + |
| 62 | + <div class="action-button"> |
| 63 | + <a-button @click="closeAction"> |
| 64 | + {{ $t('label.cancel') }} |
| 65 | + </a-button> |
| 66 | + <a-button |
| 67 | + type="primary" |
| 68 | + danger |
| 69 | + :disabled="form.name !== resource.name" |
| 70 | + :loading="loading" |
| 71 | + @click="handleSubmit"> |
| 72 | + {{ $t('label.delete') }} |
| 73 | + </a-button> |
| 74 | + </div> |
| 75 | + </a-form> |
| 76 | + </a-spin> |
| 77 | + </div> |
| 78 | +</template> |
| 79 | + |
| 80 | +<script> |
| 81 | +import { getAPI, postAPI } from '@/api' |
| 82 | +
|
| 83 | +export default { |
| 84 | + name: 'DeleteDnsServer', |
| 85 | + props: { |
| 86 | + resource: { |
| 87 | + type: Object, |
| 88 | + required: true |
| 89 | + } |
| 90 | + }, |
| 91 | + data () { |
| 92 | + return { |
| 93 | + loading: false, |
| 94 | + dnsZones: [], |
| 95 | + form: { |
| 96 | + name: '' |
| 97 | + }, |
| 98 | + rules: { |
| 99 | + name: [{ required: true, message: this.$t('message.error.required.input') }] |
| 100 | + }, |
| 101 | + maxResults: 5, |
| 102 | + totalDnsZones: 0 |
| 103 | + } |
| 104 | + }, |
| 105 | + created () { |
| 106 | + this.fetchDnsZones() |
| 107 | + }, |
| 108 | + methods: { |
| 109 | + async fetchDnsZones () { |
| 110 | + this.loading = true |
| 111 | + try { |
| 112 | + const response = await getAPI('listDnsZones', { dnsserverid: this.resource.id, page: 1, pagesize: this.maxResults, filter: 'name' }) |
| 113 | + this.dnsZones = response?.listdnszonesresponse?.dnszone || [] |
| 114 | + this.totalDnsZones = response?.listdnszonesresponse?.count || 0 |
| 115 | + } catch (error) { |
| 116 | + console.error('Failed to fetch DNS zones', error) |
| 117 | + } finally { |
| 118 | + this.loading = false |
| 119 | + } |
| 120 | + }, |
| 121 | + async handleSubmit () { |
| 122 | + if (this.loading || this.form.name !== this.resource.name) return |
| 123 | +
|
| 124 | + this.loading = true |
| 125 | +
|
| 126 | + try { |
| 127 | + const params = { |
| 128 | + id: this.resource.id |
| 129 | + } |
| 130 | +
|
| 131 | + const response = await postAPI('deleteDnsServer', params) |
| 132 | + const jobId = response?.deletednsserverresponse?.jobid |
| 133 | + if (jobId) { |
| 134 | + this.$pollJob({ |
| 135 | + jobId: jobId, |
| 136 | + title: this.$t('label.dns.delete.server'), |
| 137 | + description: this.resource.name, |
| 138 | + successMethod: () => { |
| 139 | + this.$notification.success({ |
| 140 | + message: this.$t('label.dns.delete.server'), |
| 141 | + description: `Successfully deleted DNS server ${this.resource.name}` |
| 142 | + }) |
| 143 | + }, |
| 144 | + loadingMessage: `${this.$t('label.dns.delete.server')} ${this.$t('label.in.progress')}`, |
| 145 | + catchMessage: this.$t('error.fetching.async.job.result') |
| 146 | + }) |
| 147 | + } |
| 148 | +
|
| 149 | + if (this.$route.path !== '/dnsserver') { |
| 150 | + this.$router.push({ path: '/dnsserver' }) |
| 151 | + } else { |
| 152 | + this.$emit('refresh-data') |
| 153 | + } |
| 154 | + this.closeAction() |
| 155 | + } catch (error) { |
| 156 | + this.$notification.error({ |
| 157 | + message: this.$t('message.request.failed'), |
| 158 | + description: error?.response?.headers['x-description'] || error.message, |
| 159 | + duration: 0 |
| 160 | + }) |
| 161 | + } finally { |
| 162 | + this.loading = false |
| 163 | + } |
| 164 | + }, |
| 165 | + closeAction () { |
| 166 | + this.$emit('close-action') |
| 167 | + } |
| 168 | + } |
| 169 | +} |
| 170 | +</script> |
| 171 | +
|
| 172 | +<style lang="less" scoped> |
| 173 | +.form-layout { |
| 174 | + width: 80vw; |
| 175 | + @media (min-width: 600px) { |
| 176 | + width: 450px; |
| 177 | + } |
| 178 | +} |
| 179 | +
|
| 180 | +.action-button { |
| 181 | + text-align: right; |
| 182 | + margin-top: 20px; |
| 183 | +} |
| 184 | +.action-button button { |
| 185 | + margin-left: 8px; |
| 186 | +} |
| 187 | +</style> |
0 commit comments