Skip to content

Commit 2b5d7a5

Browse files
committed
UI demo: display a result in multiple rows
1 parent 01e2e5a commit 2b5d7a5

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

ui/src/components/view/VnfConfigurationTab.vue

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@
6464
<a-row
6565
v-for="param in vnfOperation.requiredParameters"
6666
:key="param.name"
67-
gutter="16"
67+
gutter="12"
6868
style="margin-bottom: 1rem; align-items: center;"
6969
>
7070
<a-col :span="12">
71-
<strong>{{ param.description }}</strong>
71+
{{ param.description }}
7272
</a-col>
7373

7474
<a-col :span="6">
@@ -94,6 +94,7 @@
9494
import { getAPI, postAPI } from '@/api'
9595
import Status from '@/components/widgets/Status'
9696
import { h } from 'vue'
97+
import yaml from 'js-yaml'
9798
9899
export default {
99100
name: 'VnfAppliancesTab',
@@ -188,7 +189,9 @@ export default {
188189
'{"name":"destination_port","type":"string","description":"Destination port number or any"},' +
189190
'{"name":"descr","type":"string","description":"Description of the firewall rule"},' +
190191
'{"name":"vnf_rule_id","type":"string","description":"Unique identifier for the VNF firewall rule"}]')
191-
this.vnfOperation.optionalParameters = ''
192+
console.log('yaml 1 = ' + yaml.dump(this.vnfOperation.requiredParameters))
193+
this.vnfOperation.optionalParameters = yaml.load('firewall: {action: pass, interface: lan, protocol: tcp}')
194+
console.log('yaml 2 = ' + yaml.dump(this.vnfOperation.optionalParameters))
192195
}
193196
if (this.vnfOperation.autoSubmit) {
194197
this.handleSubmit()
@@ -216,20 +219,68 @@ export default {
216219
'{"uuid":"123e4567-e89b-12d3-a456-426614174000","id":1,"action":"pass","enabled":true,"interface":"lan","direction":"in","ipprotocol":"inet","protocol":"tcp","source_net":"192.168.1.0/24","source_port":"any","destination_net":"any","destination_port":443,"description":"Allow LAN → any on HTTPS"},' +
217220
'{"uuid":"123e4567-e89b-12d3-a456-426614174001","id":2,"action":"block","enabled":true,"interface":"lan","direction":"in","ipprotocol":"inet","protocol":"any","source_net":"any","source_port":"any","destination_net":"192.168.1.0/24","destination_port":"any","description":"Block any inbound to LAN subnet"},' +
218221
'{"uuid":"123e4567-e89b-12d3-a456-426614174002","id":3,"action":"pass","enabled":true,"interface":"wan","direction":"in","ipprotocol":"inet","protocol":"tcp","source_net":"any","source_port":"any","destination_net":"203.0.113.10","destination_port":22,"description":"Allow SSH access to firewall host"}]}'
222+
} else if (this.vnfOperationName === 'FIREWALL_RULE_CREATE') {
223+
this.vnfOperationResponse = '{"result":' +
224+
'{"uuid":"123e4567-e89b-12d3-a456-426614174002","id":3,"action":"pass","enabled":true,"interface":"wan","direction":"in","ipprotocol":"inet","protocol":"tcp","source_net":"any","source_port":"any","destination_net":"203.0.113.10","destination_port":22,"description":"Allow SSH access to firewall host"}}'
219225
}
220226
this.processVnfOperationResponse()
221227
})
222228
},
223229
processVnfOperationResponse () {
224230
const message = this.$t('label.vnf.operation.response') + ' : ' + this.vnfOperationName
225231
this.vnfOperationResponseNode = [h('p', `${message}`)]
226-
let parsedVnfOperationResponse = JSON.parse(this.vnfOperationResponse)?.result
232+
const parsedVnfOperationResponse = JSON.parse(this.vnfOperationResponse)?.result
227233
if (!parsedVnfOperationResponse) {
228234
this.vnfOperationResponseNode = h('div', this.vnfOperationResponseNode)
229235
return
230236
}
231-
if (parsedVnfOperationResponse && !Array.isArray(parsedVnfOperationResponse) && typeof parsedVnfOperationResponse === 'object' && Object.keys(parsedVnfOperationResponse).length > 0) {
232-
parsedVnfOperationResponse = [parsedVnfOperationResponse]
237+
if (!Array.isArray(parsedVnfOperationResponse) && typeof parsedVnfOperationResponse === 'object' && Object.keys(parsedVnfOperationResponse).length > 0) {
238+
this.vnfOperationResponseNode.push(
239+
h('div', {
240+
style: {
241+
marginTop: '1em',
242+
maxHeight: '50vh',
243+
maxWidth: '100%',
244+
overflow: 'auto',
245+
backgroundColor: '#f6f6f6',
246+
border: '1px solid #ddd',
247+
borderRadius: '4px',
248+
display: 'block'
249+
}
250+
}, [
251+
h('table', {
252+
style: {
253+
width: '100%',
254+
minWidth: 'max-content',
255+
borderCollapse: 'collapse',
256+
whiteSpace: 'pre-wrap'
257+
}
258+
}, [
259+
h('tbody',
260+
Object.keys(parsedVnfOperationResponse).map(key =>
261+
h('tr', [
262+
h('td', {
263+
style: {
264+
padding: '8px',
265+
border: '1px solid #ddd',
266+
textAlign: 'left',
267+
fontWeight: 'bold',
268+
backgroundColor: '#fafafa'
269+
}
270+
}, key),
271+
h('td', {
272+
style: {
273+
padding: '8px',
274+
border: '1px solid #ddd',
275+
textAlign: 'left'
276+
}
277+
}, String(parsedVnfOperationResponse[key]))
278+
])
279+
)
280+
)
281+
])
282+
])
283+
)
233284
}
234285
235286
if (Array.isArray(parsedVnfOperationResponse) && parsedVnfOperationResponse.length > 0) {

0 commit comments

Comments
 (0)