|
| 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> |
| 20 | + <autogen-view @change-resource="changeResource"> |
| 21 | + <div slot="action"> |
| 22 | + <action-button |
| 23 | + :style="{ float: device === 'mobile' ? 'left' : 'right' }" |
| 24 | + :loading="loading" |
| 25 | + :actions="actions" |
| 26 | + :selectedRowKeys="selectedRowKeys" |
| 27 | + :dataView="true" |
| 28 | + :resource="resource" |
| 29 | + @exec-action="(action) => execAction(action, action.groupAction && !dataView)" /> |
| 30 | + </div> |
| 31 | + <div slot="resource"> |
| 32 | + <resource-view |
| 33 | + v-if="isPublicIpAddress && 'id' in resource" |
| 34 | + :loading="loading" |
| 35 | + :resource="resource" |
| 36 | + :tabs="tabs" /> |
| 37 | + </div> |
| 38 | + </autogen-view> |
| 39 | + </div> |
| 40 | +</template> |
| 41 | + |
| 42 | +<script> |
| 43 | +import { api } from '@api' |
| 44 | +import { mixinDevice } from '@/utils/mixin.js' |
| 45 | +import eventBus from '@/config/eventBus' |
| 46 | +import AutogenView from '@/views/AutogenView.vue' |
| 47 | +import ResourceView from '@/components/view/ResourceView' |
| 48 | +import ActionButton from '@/components/view/ActionButton' |
| 49 | +
|
| 50 | +export default { |
| 51 | + name: 'PublicIpResource', |
| 52 | + components: { |
| 53 | + AutogenView, |
| 54 | + ResourceView, |
| 55 | + ActionButton |
| 56 | + }, |
| 57 | + data () { |
| 58 | + return { |
| 59 | + loading: false, |
| 60 | + selectedRowKeys: [], |
| 61 | + actions: [], |
| 62 | + resource: {}, |
| 63 | + tabs: [{ |
| 64 | + name: 'details', |
| 65 | + component: () => import('@/components/view/DetailsTab.vue') |
| 66 | + }] |
| 67 | + } |
| 68 | + }, |
| 69 | + mixins: [mixinDevice], |
| 70 | + provide: function () { |
| 71 | + return { |
| 72 | + parentFetchData: this.fetchData(), |
| 73 | + parentToggleLoading: this.toggleLoading |
| 74 | + } |
| 75 | + }, |
| 76 | + computed: { |
| 77 | + isPublicIpAddress () { |
| 78 | + return this.$route.path.startsWith('/publicip') && this.$route.path.includes('/publicip/') |
| 79 | + } |
| 80 | + }, |
| 81 | + watch: { |
| 82 | + resource () { |
| 83 | + if ('id' in this.resource) { |
| 84 | + this.fetchData() |
| 85 | + } |
| 86 | + } |
| 87 | + }, |
| 88 | + mounted () { |
| 89 | + if ('id' in this.resource) { |
| 90 | + this.fetchData() |
| 91 | + } |
| 92 | + }, |
| 93 | + methods: { |
| 94 | + async fetchData () { |
| 95 | + if (Object.keys(this.resource).length === 0) { |
| 96 | + return |
| 97 | + } |
| 98 | +
|
| 99 | + this.loading = true |
| 100 | + this.portFWRuleCount = await this.fetchPortFWRule() |
| 101 | +
|
| 102 | + if (this.portFWRuleCount > 0) { |
| 103 | + this.tabs = this.$route.meta.tabs.filter(tab => tab.name !== 'loadbalancing') |
| 104 | + } else { |
| 105 | + this.loadBalancerRuleCount = await this.fetchLoadBalancerRule() |
| 106 | +
|
| 107 | + if (this.loadBalancerRuleCount > 0) { |
| 108 | + this.tabs = this.$route.meta.tabs.filter(tab => tab.name !== 'portforwarding') |
| 109 | + this.loading = false |
| 110 | + } else { |
| 111 | + this.tabs = this.$route.meta.tabs |
| 112 | + } |
| 113 | + } |
| 114 | +
|
| 115 | + await this.fetchAction() |
| 116 | + this.loading = false |
| 117 | + }, |
| 118 | + fetchAction () { |
| 119 | + this.actions = [] |
| 120 | + if (this.$route.meta.actions) { |
| 121 | + this.actions = this.$route.meta.actions |
| 122 | + } |
| 123 | +
|
| 124 | + if (this.portFWRuleCount > 0 || this.loadBalancerRuleCount > 0) { |
| 125 | + this.actions = this.actions.filter(action => action.api !== 'enableStaticNat') |
| 126 | + } |
| 127 | + }, |
| 128 | + fetchPortFWRule () { |
| 129 | + return new Promise((resolve, reject) => { |
| 130 | + api('listPortForwardingRules', { |
| 131 | + listAll: true, |
| 132 | + ipaddressid: this.resource.id, |
| 133 | + page: 1, |
| 134 | + pagesize: 1 |
| 135 | + }).then(json => { |
| 136 | + const portFWRuleCount = json.listportforwardingrulesresponse.count || 0 |
| 137 | + resolve(portFWRuleCount) |
| 138 | + }).catch(e => { |
| 139 | + reject(e) |
| 140 | + }) |
| 141 | + }) |
| 142 | + }, |
| 143 | + fetchLoadBalancerRule () { |
| 144 | + return new Promise((resolve, reject) => { |
| 145 | + api('listLoadBalancerRules', { |
| 146 | + listAll: true, |
| 147 | + publicipid: this.resource.id, |
| 148 | + page: 1, |
| 149 | + pagesize: 1 |
| 150 | + }).then(json => { |
| 151 | + const loadBalancerRuleCount = json.listloadbalancerrulesresponse.count || 0 |
| 152 | + resolve(loadBalancerRuleCount) |
| 153 | + }).catch(e => { |
| 154 | + reject(e) |
| 155 | + }) |
| 156 | + }) |
| 157 | + }, |
| 158 | + changeResource (resource) { |
| 159 | + this.resource = resource |
| 160 | + }, |
| 161 | + toggleLoading () { |
| 162 | + this.loading = !this.loading |
| 163 | + }, |
| 164 | + execAction (action, isGroupAction) { |
| 165 | + eventBus.$emit('exec-action', action, isGroupAction) |
| 166 | + } |
| 167 | + } |
| 168 | +} |
| 169 | +</script> |
0 commit comments