|
| 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" v-ctrl-enter="handleKeyboardSubmit"> |
| 20 | + <div> |
| 21 | + <a-input-search |
| 22 | + class="top-spaced" |
| 23 | + :placeholder="$t('label.search')" |
| 24 | + v-model="searchQuery" |
| 25 | + style="margin-bottom: 10px;" |
| 26 | + @search="fetchNetworks" |
| 27 | + autoFocus /> |
| 28 | + <a-table |
| 29 | + size="small" |
| 30 | + style="overflow-y: auto" |
| 31 | + :loading="loading" |
| 32 | + :columns="columns" |
| 33 | + :dataSource="networks" |
| 34 | + :pagination="false" |
| 35 | + :rowKey="record => record.id"> |
| 36 | + <template slot="select" slot-scope="record"> |
| 37 | + <a-radio |
| 38 | + @click="updateSelection(record)" |
| 39 | + :checked="selectedNetwork != null && record.id === selectedNetwork.id"> |
| 40 | + </a-radio> |
| 41 | + </template> |
| 42 | + </a-table> |
| 43 | + <a-pagination |
| 44 | + class="top-spaced" |
| 45 | + size="small" |
| 46 | + :current="page" |
| 47 | + :pageSize="pageSize" |
| 48 | + :total="totalCount" |
| 49 | + :showTotal="total => `${$t('label.total')} ${total} ${$t('label.items')}`" |
| 50 | + :pageSizeOptions="['10', '20', '40', '80', '100']" |
| 51 | + @change="handleChangePage" |
| 52 | + @showSizeChange="handleChangePageSize" |
| 53 | + showSizeChanger> |
| 54 | + <template slot="buildOptionText" slot-scope="props"> |
| 55 | + <span>{{ props.value }} / {{ $t('label.page') }}</span> |
| 56 | + </template> |
| 57 | + </a-pagination> |
| 58 | + </div> |
| 59 | + |
| 60 | + <a-divider /> |
| 61 | + |
| 62 | + <div class="actions"> |
| 63 | + <a-button @click="closeModal">{{ $t('label.cancel') }}</a-button> |
| 64 | + <a-button type="primary" ref="submit" :disabled="!selectedNetwork" @click="submitForm">{{ $t('label.ok') }}</a-button> |
| 65 | + </div> |
| 66 | + |
| 67 | + </div> |
| 68 | +</template> |
| 69 | + |
| 70 | +<script> |
| 71 | +import { api } from '@/api' |
| 72 | +
|
| 73 | +export default { |
| 74 | + name: 'NicNetworkSelectForm', |
| 75 | + props: { |
| 76 | + resource: { |
| 77 | + type: Object, |
| 78 | + required: true |
| 79 | + }, |
| 80 | + zoneid: { |
| 81 | + type: String, |
| 82 | + required: true |
| 83 | + }, |
| 84 | + isOpen: { |
| 85 | + type: Boolean, |
| 86 | + required: false |
| 87 | + } |
| 88 | + }, |
| 89 | + data () { |
| 90 | + return { |
| 91 | + loading: false, |
| 92 | + networks: [], |
| 93 | + searchQuery: '', |
| 94 | + totalCount: 0, |
| 95 | + page: 1, |
| 96 | + pageSize: 10, |
| 97 | + selectedNetwork: null, |
| 98 | + columns: [ |
| 99 | + { |
| 100 | + title: this.$t('label.networkid'), |
| 101 | + dataIndex: 'name' |
| 102 | + }, |
| 103 | + { |
| 104 | + title: this.$t('label.guestiptype'), |
| 105 | + dataIndex: 'type' |
| 106 | + }, |
| 107 | + { |
| 108 | + title: this.$t('label.vpc'), |
| 109 | + dataIndex: 'vpcName' |
| 110 | + }, |
| 111 | + { |
| 112 | + title: this.$t('label.cidr'), |
| 113 | + dataIndex: 'cidr' |
| 114 | + }, |
| 115 | + { |
| 116 | + title: this.$t('label.select'), |
| 117 | + scopedSlots: { customRender: 'select' } |
| 118 | + } |
| 119 | + ] |
| 120 | + } |
| 121 | + }, |
| 122 | + created () { |
| 123 | + this.fetchNetworks() |
| 124 | + this.preselectNetwork() |
| 125 | + }, |
| 126 | + watch: { |
| 127 | + isOpen (newValue) { |
| 128 | + if (newValue) { |
| 129 | + setTimeout(() => { |
| 130 | + this.reset() |
| 131 | + }, 50) |
| 132 | + } |
| 133 | + } |
| 134 | + }, |
| 135 | + methods: { |
| 136 | + fetchNetworks () { |
| 137 | + this.loading = true |
| 138 | + var params = { |
| 139 | + zoneid: this.zoneid, |
| 140 | + keyword: this.searchQuery, |
| 141 | + page: this.page, |
| 142 | + pagesize: this.pageSize, |
| 143 | + canusefordeploy: true, |
| 144 | + projectid: this.$store.getters.project ? this.$store.getters.project.id : null, |
| 145 | + domainid: this.$store.getters.project && this.$store.getters.project.id ? null : this.$store.getters.userInfo.domainid, |
| 146 | + account: this.$store.getters.project && this.$store.getters.project.id ? null : this.$store.getters.userInfo.account |
| 147 | + } |
| 148 | + api('listNetworks', params).then(response => { |
| 149 | + this.networks = response.listnetworksresponse.network || [] |
| 150 | + this.totalCount = response.listnetworksresponse.count |
| 151 | + }).catch(error => { |
| 152 | + this.$notifyError(error) |
| 153 | + }).finally(() => { |
| 154 | + this.loading = false |
| 155 | + }) |
| 156 | + }, |
| 157 | + handleChangePage (page, pageSize) { |
| 158 | + this.page = page |
| 159 | + this.pageSize = pageSize |
| 160 | + this.fetchNetworks() |
| 161 | + }, |
| 162 | + handleChangePageSize (currentPage, pageSize) { |
| 163 | + this.page = currentPage |
| 164 | + this.pageSize = pageSize |
| 165 | + this.fetchNetworks() |
| 166 | + }, |
| 167 | + preselectNetwork () { |
| 168 | + if (this.resource && 'selectednetworkid' in this.resource) { |
| 169 | + this.selectedNetwork = { id: this.resource.selectednetworkid } |
| 170 | + } |
| 171 | + }, |
| 172 | + clearView () { |
| 173 | + this.networks = [] |
| 174 | + this.searchQuery = '' |
| 175 | + this.totalCount = 0 |
| 176 | + this.page = 1 |
| 177 | + this.pageSize = 10 |
| 178 | + this.selectedNetwork = null |
| 179 | + }, |
| 180 | + reset () { |
| 181 | + this.clearView() |
| 182 | + this.preselectNetwork() |
| 183 | + this.fetchNetworks() |
| 184 | + }, |
| 185 | + updateSelection (network) { |
| 186 | + this.selectedNetwork = network |
| 187 | + }, |
| 188 | + closeModal () { |
| 189 | + this.$emit('close-action') |
| 190 | + }, |
| 191 | + handleKeyboardSubmit () { |
| 192 | + if (this.selectedNetwork != null) { |
| 193 | + this.submitForm() |
| 194 | + } |
| 195 | + }, |
| 196 | + submitForm () { |
| 197 | + this.$emit('select', this.resource.id, this.selectedNetwork) |
| 198 | + this.closeModal() |
| 199 | + } |
| 200 | + } |
| 201 | +} |
| 202 | +</script> |
| 203 | + |
| 204 | +<style scoped lang="scss"> |
| 205 | + .form { |
| 206 | + width: 80vw; |
| 207 | +
|
| 208 | + @media (min-width: 900px) { |
| 209 | + width: 850px; |
| 210 | + } |
| 211 | + } |
| 212 | +
|
| 213 | + .top-spaced { |
| 214 | + margin-top: 20px; |
| 215 | + } |
| 216 | +
|
| 217 | + .actions { |
| 218 | + display: flex; |
| 219 | + justify-content: flex-end; |
| 220 | + margin-top: 20px; |
| 221 | +
|
| 222 | + button { |
| 223 | + &:not(:last-child) { |
| 224 | + margin-right: 10px; |
| 225 | + } |
| 226 | + } |
| 227 | + } |
| 228 | +</style> |
0 commit comments