|
| 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="create-backup-schedule-layout"> |
| 20 | + <div v-if="!isVMResource" class="vm-selection"> |
| 21 | + <a-form layout="vertical"> |
| 22 | + <a-form-item :label="$t('label.virtualmachine')" required> |
| 23 | + <a-select |
| 24 | + v-model:value="selectedVMId" |
| 25 | + :placeholder="$t('label.select.virtualmachine')" |
| 26 | + :loading="vmsLoading" |
| 27 | + show-search |
| 28 | + :filter-option="filterOption" |
| 29 | + @change="onVMChange" |
| 30 | + > |
| 31 | + <a-select-option |
| 32 | + v-for="vm in vms" |
| 33 | + :key="vm.id" |
| 34 | + :value="vm.id" |
| 35 | + > |
| 36 | + {{ vm.name }} ({{ vm.account }}) |
| 37 | + </a-select-option> |
| 38 | + </a-select> |
| 39 | + </a-form-item> |
| 40 | + </a-form> |
| 41 | + </div> |
| 42 | + <div v-if="isVMResource" class="current-vm-info"> |
| 43 | + <a-alert |
| 44 | + :message="`${$t('label.backup.schedules.for')} ${resource.name}`" |
| 45 | + type="info" |
| 46 | + show-icon |
| 47 | + style="margin-bottom: 16px" |
| 48 | + /> |
| 49 | + </div> |
| 50 | + <div v-if="currentVMResource && currentVMResource.id"> |
| 51 | + <BackupScheduleWizard |
| 52 | + ref="backupScheduleWizard" |
| 53 | + :resource="currentVMResource" |
| 54 | + @close-action="closeAction" |
| 55 | + @refresh="handleRefresh" |
| 56 | + /> |
| 57 | + </div> |
| 58 | + <div v-if="!currentVMResource || !currentVMResource.id" class="no-vm-selected"> |
| 59 | + <div class="empty-state"> |
| 60 | + <p>{{ $t('message.select.vm.to.continue') }}</p> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + </template> |
| 65 | + |
| 66 | +<script> |
| 67 | +import { getAPI } from '@/api' |
| 68 | +import BackupScheduleWizard from '@/views/compute/BackupScheduleWizard' |
| 69 | +
|
| 70 | +export default { |
| 71 | + name: 'CreateBackupSchedule', |
| 72 | + components: { |
| 73 | + BackupScheduleWizard |
| 74 | + }, |
| 75 | + props: { |
| 76 | + resource: { |
| 77 | + type: Object, |
| 78 | + required: false, |
| 79 | + default: () => null |
| 80 | + } |
| 81 | + }, |
| 82 | + data () { |
| 83 | + return { |
| 84 | + vms: [], |
| 85 | + vmsLoading: false, |
| 86 | + selectedVMId: null, |
| 87 | + selectedVM: null |
| 88 | + } |
| 89 | + }, |
| 90 | + computed: { |
| 91 | + resourceType () { |
| 92 | + if (!this.resource) return 'none' |
| 93 | + if (this.resource.vmstate !== undefined || |
| 94 | + this.resource.guestosid !== undefined || this.resource.hypervisor !== undefined || |
| 95 | + this.resource.backupofferingid !== undefined) { |
| 96 | + return 'vm' |
| 97 | + } |
| 98 | + if (this.resource.intervaltype !== undefined && this.resource.schedule !== undefined) { |
| 99 | + return 'backupschedule' |
| 100 | + } |
| 101 | + return 'unknown' |
| 102 | + }, |
| 103 | + isVMResource () { |
| 104 | + return this.resourceType === 'vm' |
| 105 | + }, |
| 106 | + currentVMResource () { |
| 107 | + if (this.isVMResource) { |
| 108 | + return this.resource |
| 109 | + } else { |
| 110 | + return this.selectedVM |
| 111 | + } |
| 112 | + } |
| 113 | + }, |
| 114 | + created () { |
| 115 | + if (!this.isVMResource) { |
| 116 | + this.fetchVMs() |
| 117 | + } |
| 118 | + }, |
| 119 | + methods: { |
| 120 | + async fetchVMs () { |
| 121 | + this.vmsLoading = true |
| 122 | + try { |
| 123 | + const response = await getAPI('listVirtualMachines', { listAll: true }) |
| 124 | + const vms = response.listvirtualmachinesresponse.virtualmachine || [] |
| 125 | + this.vms = vms.filter(vm => { |
| 126 | + return vm.backupofferingid && ['Running', 'Stopped'].includes(vm.state) |
| 127 | + }) |
| 128 | + } catch (error) { |
| 129 | + this.$message.error(this.$t('message.error.fetch.vms')) |
| 130 | + console.error('Error fetching VMs:', error) |
| 131 | + } finally { |
| 132 | + this.vmsLoading = false |
| 133 | + } |
| 134 | + }, |
| 135 | + onVMChange (vmId) { |
| 136 | + const vm = this.vms.find(v => v.id === vmId) |
| 137 | + if (vm) { |
| 138 | + this.selectedVM = vm |
| 139 | + this.selectedVMId = vmId |
| 140 | + } |
| 141 | + }, |
| 142 | + closeAction () { |
| 143 | + this.$emit('refresh') |
| 144 | + this.$emit('close-action') |
| 145 | + }, |
| 146 | + handleRefresh () { |
| 147 | + this.$emit('refresh') |
| 148 | + }, |
| 149 | + filterOption (input, option) { |
| 150 | + return option.children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0 |
| 151 | + } |
| 152 | + } |
| 153 | +} |
| 154 | +</script> |
| 155 | + |
| 156 | +<style lang="less" scoped> |
| 157 | +.create-backup-schedule-layout { |
| 158 | + .vm-selection { |
| 159 | + margin-bottom: 20px; |
| 160 | + padding: 16px; |
| 161 | + border: 1px solid #d9d9d9; |
| 162 | + border-radius: 6px; |
| 163 | + background-color: #fafafa; |
| 164 | + .ant-form-item { |
| 165 | + margin-bottom: 0; |
| 166 | + .ant-select { |
| 167 | + width: 100%; |
| 168 | + min-width: 400px; |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | +
|
| 173 | + .current-vm-info { |
| 174 | + margin-bottom: 16px; |
| 175 | + } |
| 176 | +
|
| 177 | + .no-vm-selected { |
| 178 | + text-align: center; |
| 179 | + padding: 40px 20px; |
| 180 | + } |
| 181 | +} |
| 182 | +</style> |
0 commit comments