|
| 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 | +<template> |
| 18 | + <a-modal |
| 19 | + :visible="true" |
| 20 | + :title="$t('label.action.delete.domain') + ': ' + domain.name" |
| 21 | + :okText="$t('label.delete.domain')" |
| 22 | + okType="danger" |
| 23 | + :confirmLoading="loading" |
| 24 | + :ok-button-props="{ disabled: !canDelete }" |
| 25 | + @cancel="emitClose" |
| 26 | + @ok="emitConfirm"> |
| 27 | + |
| 28 | + <a-alert |
| 29 | + type="warning" |
| 30 | + show-icon |
| 31 | + style="margin-bottom: 16px"> |
| 32 | + <template #message> |
| 33 | + <div v-html="$t('message.delete.domain.warning')"></div> |
| 34 | + </template> |
| 35 | + </a-alert> |
| 36 | + |
| 37 | + <a-spin v-if="loading" /> |
| 38 | + |
| 39 | + <a-table |
| 40 | + v-else |
| 41 | + size="small" |
| 42 | + :columns="columns" |
| 43 | + :dataSource="accountVmSummary" |
| 44 | + :pagination="false" |
| 45 | + rowKey="account" /> |
| 46 | + |
| 47 | + <div style="margin-top: 16px"> |
| 48 | + <a-alert style="margin-bottom: 10px"> |
| 49 | + <template #message> |
| 50 | + <div v-html="$t('message.delete.domain.confirm')"></div> |
| 51 | + </template> |
| 52 | + </a-alert> |
| 53 | + <a-input |
| 54 | + v-model:value="confirmText" |
| 55 | + :placeholder="$t('label.enter.domain.name')" /> |
| 56 | + </div> |
| 57 | + |
| 58 | + </a-modal> |
| 59 | +</template> |
| 60 | + |
| 61 | +<script> |
| 62 | +import { api } from '@/api' |
| 63 | +
|
| 64 | +export default { |
| 65 | + name: 'DomainDeleteConfirm', |
| 66 | + props: { |
| 67 | + domain: { |
| 68 | + type: Object, |
| 69 | + required: true |
| 70 | + } |
| 71 | + }, |
| 72 | + data () { |
| 73 | + return { |
| 74 | + loading: false, |
| 75 | + confirmText: '', |
| 76 | + accountVmSummary: [] |
| 77 | + } |
| 78 | + }, |
| 79 | + computed: { |
| 80 | + canDelete () { |
| 81 | + return this.confirmText.trim() === this.domain.name.trim() |
| 82 | + }, |
| 83 | + columns () { |
| 84 | + return [ |
| 85 | + { title: this.$t('label.account'), dataIndex: 'account' }, |
| 86 | + { title: this.$t('label.total') + ' VMs', dataIndex: 'total' }, |
| 87 | + { title: this.$t('label.running') + ' VMs', dataIndex: 'running' }, |
| 88 | + { title: this.$t('label.stopped') + ' VMs', dataIndex: 'stopped' } |
| 89 | + ] |
| 90 | + } |
| 91 | + }, |
| 92 | + mounted () { |
| 93 | + this.fetchDomainImpact() |
| 94 | + }, |
| 95 | + methods: { |
| 96 | + emitClose () { |
| 97 | + this.$emit('close') |
| 98 | + }, |
| 99 | + emitConfirm () { |
| 100 | + if (this.canDelete) { |
| 101 | + this.$emit('confirm') |
| 102 | + } |
| 103 | + }, |
| 104 | + async fetchDomainImpact () { |
| 105 | + this.loading = true |
| 106 | + try { |
| 107 | + const accResp = await api('listAccounts', { |
| 108 | + domainid: this.domain.id, |
| 109 | + listall: true |
| 110 | + }) |
| 111 | +
|
| 112 | + const accounts = |
| 113 | + accResp.listaccountsresponse && |
| 114 | + accResp.listaccountsresponse.account |
| 115 | + ? accResp.listaccountsresponse.account |
| 116 | + : [] |
| 117 | +
|
| 118 | + const vmResp = await api('listVirtualMachines', { |
| 119 | + domainid: this.domain.id, |
| 120 | + listall: true |
| 121 | + }) |
| 122 | +
|
| 123 | + const vms = |
| 124 | + vmResp.listvirtualmachinesresponse && |
| 125 | + vmResp.listvirtualmachinesresponse.virtualmachine |
| 126 | + ? vmResp.listvirtualmachinesresponse.virtualmachine |
| 127 | + : [] |
| 128 | +
|
| 129 | + this.accountVmSummary = accounts.map(account => { |
| 130 | + const accountVms = vms.filter(vm => vm.account === account.name) |
| 131 | + const running = accountVms.filter(vm => vm.state === 'Running').length |
| 132 | + const stopped = accountVms.length - running |
| 133 | +
|
| 134 | + return { |
| 135 | + account: account.name, |
| 136 | + total: accountVms.length, |
| 137 | + running, |
| 138 | + stopped |
| 139 | + } |
| 140 | + }) |
| 141 | + } catch (e) { |
| 142 | + this.$notification.error({ |
| 143 | + message: this.$t('message.request.failed'), |
| 144 | + description: e.response?.headers['x-description'] || this.$t('message.request.failed') |
| 145 | + }) |
| 146 | + } finally { |
| 147 | + this.loading = false |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | +} |
| 152 | +</script> |
| 153 | +
|
| 154 | +<style scoped> |
| 155 | +</style> |
0 commit comments