Skip to content

Commit c9900f5

Browse files
eznttEduardo Zanetta
authored andcommitted
add button to copy a VM console URL (apache#7351)
Co-authored-by: Eduardo Zanetta <eduardo.zanetta@scclouds.com.br>
1 parent 3e52aff commit c9900f5

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

ui/public/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@
503503
"label.copied.clipboard": "Copied to clipboard",
504504
"label.copy": "Copy",
505505
"label.copy.clipboard": "Copy to clipboard",
506+
"label.copy.consoleurl": "Copy console URL to clipboard",
506507
"label.copyid": "Copy ID",
507508
"label.core": "Core",
508509
"label.core.zone.type": "Core zone type",

ui/src/components/view/ActionButton.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,26 @@
2121
<template #title>
2222
{{ $t('label.view.console') }}
2323
</template>
24-
<console :resource="resource" :size="size" />
24+
<console
25+
style="margin-top: -5px;"
26+
:resource="resource"
27+
size="default"
28+
v-if="resource.id"
29+
icon="code"
30+
/>
31+
</a-tooltip>
32+
<a-tooltip arrowPointAtCenter placement="bottomRight" v-if="resource && resource.id && dataView">
33+
<template #title>
34+
{{ $t('label.copy.consoleurl') }}
35+
</template>
36+
<console
37+
copyUrlToClipboard
38+
style="margin-top: -5px;"
39+
:resource="resource"
40+
size="default"
41+
v-if="resource.id"
42+
icon="copy"
43+
/>
2544
</a-tooltip>
2645
<a-tooltip
2746
v-for="(action, actionIndex) in actions"

ui/src/components/view/InfoCard.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,24 @@
8888
<template #title>
8989
<span>{{ $t('label.view.console') }}</span>
9090
</template>
91-
<console style="margin-top: -5px;" :resource="resource" size="default" v-if="resource.id" />
91+
<console
92+
style="margin-top: -5px;"
93+
:resource="resource"
94+
size="default"
95+
v-if="resource.id"
96+
/>
97+
</a-tooltip>
98+
<a-tooltip placement="right" >
99+
<template #title>
100+
<span>{{ $t('label.copy.consoleurl') }}</span>
101+
</template>
102+
<console
103+
copyUrlToClipboard
104+
style="margin-top: -5px;"
105+
:resource="resource"
106+
size="default"
107+
v-if="resource.id"
108+
/>
92109
</a-tooltip>
93110
</div>
94111
</slot>

ui/src/components/widgets/Console.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
v-if="['vm', 'systemvm', 'router', 'ilbvm'].includes($route.meta.name) && 'listVirtualMachines' in $store.getters.apis && 'createConsoleEndpoint' in $store.getters.apis"
2121
@click="consoleUrl">
2222
<a-button style="margin-left: 5px" shape="circle" type="dashed" :size="size" :disabled="['Stopped', 'Error', 'Destroyed'].includes(resource.state) || resource.hostcontrolstate === 'Offline'" >
23-
<code-outlined />
23+
<code-outlined v-if="!copyUrlToClipboard"/>
24+
<copy-outlined v-else />
2425
</a-button>
2526
</a>
2627
</template>
@@ -39,7 +40,8 @@ export default {
3940
size: {
4041
type: String,
4142
default: 'small'
42-
}
43+
},
44+
copyUrlToClipboard: Boolean
4345
},
4446
data () {
4547
return {
@@ -53,7 +55,21 @@ export default {
5355
api('createConsoleEndpoint', params).then(json => {
5456
this.url = (json && json.createconsoleendpointresponse) ? json.createconsoleendpointresponse.consoleendpoint.url : '#/exception/404'
5557
if (json.createconsoleendpointresponse.consoleendpoint.success) {
56-
window.open(this.url, '_blank')
58+
if (this.copyUrlToClipboard) {
59+
this.$message.success({
60+
content: this.$t('label.copied.clipboard')
61+
})
62+
const hiddenElement = document.createElement('textarea')
63+
hiddenElement.value = this.url
64+
document.body.appendChild(hiddenElement)
65+
hiddenElement.focus()
66+
hiddenElement.select()
67+
68+
document.execCommand('copy')
69+
document.body.removeChild(hiddenElement)
70+
} else {
71+
window.open(this.url, '_blank')
72+
}
5773
} else {
5874
this.$notification.error({
5975
message: this.$t('error.execute.api.failed') + ' ' + 'createConsoleEndpoint',

0 commit comments

Comments
 (0)