Skip to content
This repository was archived by the owner on Jan 20, 2021. It is now read-only.

Commit 7ad730c

Browse files
authored
Merge pull request #744 from utchoang/feature/fix-public-vpc-network
2 parents 2f1767d + 9f84792 commit 7ad730c

File tree

3 files changed

+176
-1
lines changed

3 files changed

+176
-1
lines changed

src/config/section/network.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export default {
244244
resourceType: 'PublicIpAddress',
245245
columns: ['ipaddress', 'state', 'associatednetworkname', 'virtualmachinename', 'allocated', 'account', 'zonename'],
246246
details: ['ipaddress', 'id', 'associatednetworkname', 'virtualmachinename', 'networkid', 'issourcenat', 'isstaticnat', 'virtualmachinename', 'vmipaddress', 'vlan', 'allocated', 'account', 'zonename'],
247+
component: () => import('@/views/network/PublicIpResource.vue'),
247248
tabs: [{
248249
name: 'details',
249250
component: () => import('@/components/view/DetailsTab.vue')

src/views/AutogenView.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@
6565
<a-col
6666
:span="device === 'mobile' ? 24 : 12"
6767
:style="device === 'mobile' ? { float: 'right', 'margin-top': '12px', 'margin-bottom': '-6px', display: 'table' } : { float: 'right', display: 'table', 'margin-bottom': '-6px' }" >
68+
<slot name="action" v-if="dataView && $route.path.startsWith('/publicip')"></slot>
6869
<action-button
70+
v-else
6971
:style="dataView ? { float: device === 'mobile' ? 'left' : 'right' } : { 'margin-right': '10px', display: 'inline-flex' }"
7072
:loading="loading"
7173
:actions="actions"
@@ -290,7 +292,7 @@
290292
</div>
291293

292294
<div v-if="dataView">
293-
<slot v-if="$route.path.startsWith('/quotasummary')"></slot>
295+
<slot name="resource" v-if="$route.path.startsWith('/quotasummary') || $route.path.startsWith('/publicip')"></slot>
294296
<resource-view
295297
v-else
296298
:resource="resource"
@@ -403,6 +405,9 @@ export default {
403405
eventBus.$on('async-job-complete', () => {
404406
this.fetchData()
405407
})
408+
eventBus.$on('exec-action', (action, isGroupAction) => {
409+
this.execAction(action, isGroupAction)
410+
})
406411
},
407412
mounted () {
408413
if (this.device === 'desktop') {
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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

Comments
 (0)