Skip to content

Commit 8939ebb

Browse files
authored
ui: allow copying password from notification (#7985)
* ui: allow copying password from notification Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix warnings, use clipboard lib Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix for deploy vm Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> --------- Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 1bda234 commit 8939ebb

4 files changed

Lines changed: 61 additions & 10 deletions

File tree

ui/public/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@
517517
"label.copy.clipboard": "Copy to clipboard",
518518
"label.copy.consoleurl": "Copy console URL to clipboard",
519519
"label.copyid": "Copy ID",
520+
"label.copy.password": "Copy password",
520521
"label.core": "Core",
521522
"label.core.zone.type": "Core zone type",
522523
"label.counter": "Counter",

ui/src/config/section/compute.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,13 @@ export default {
370370
message: 'message.action.instance.reset.password',
371371
dataView: true,
372372
show: (record) => { return ['Stopped'].includes(record.state) && record.passwordenabled },
373-
response: (result) => { return result.virtualmachine && result.virtualmachine.password ? `The password of VM <b>${result.virtualmachine.displayname}</b> is <b>${result.virtualmachine.password}</b>` : null }
373+
response: (result) => {
374+
return {
375+
message: result.virtualmachine && result.virtualmachine.password ? `The password of VM <b>${result.virtualmachine.displayname}</b> is <b>${result.virtualmachine.password}</b>` : null,
376+
copybuttontext: result.virtualmachine.password ? 'label.copy.password' : null,
377+
copytext: result.virtualmachine.password ? result.virtualmachine.password : null
378+
}
379+
}
374380
},
375381
{
376382
api: 'resetSSHKeyForVirtualMachine',

ui/src/views/AutogenView.vue

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@
444444
</template>
445445

446446
<script>
447-
import { ref, reactive, toRaw } from 'vue'
447+
import { ref, reactive, toRaw, h } from 'vue'
448+
import { Button } from 'ant-design-vue'
448449
import { api } from '@/api'
449450
import { mixinDevice } from '@/utils/mixin.js'
450451
import { genericCompare } from '@/utils/sort.js'
@@ -1301,13 +1302,30 @@ export default {
13011302
eventBus.emit('update-resource-state', { selectedItems: this.selectedItems, resource, state: 'success' })
13021303
}
13031304
if (action.response) {
1304-
const description = action.response(result.jobresult)
1305-
if (description) {
1306-
this.$notification.info({
1307-
message: this.$t(action.label),
1308-
description: (<span v-html={description}></span>),
1309-
duration: 0
1310-
})
1305+
const response = action.response(result.jobresult)
1306+
if (response) {
1307+
if (typeof response === 'object') {
1308+
this.$notification.info({
1309+
message: this.$t(action.label),
1310+
description: (<span v-html={response.message}></span>),
1311+
btn: () => h(
1312+
Button,
1313+
{
1314+
type: 'primary',
1315+
size: 'small',
1316+
onClick: () => this.copyToClipboard(response.copytext)
1317+
},
1318+
() => [this.$t(response.copybuttontext)]
1319+
),
1320+
duration: 0
1321+
})
1322+
} else {
1323+
this.$notification.info({
1324+
message: this.$t(action.label),
1325+
description: (<span v-html={response}></span>),
1326+
duration: 0
1327+
})
1328+
}
13111329
}
13121330
}
13131331
if ('successMethod' in action) {
@@ -1903,6 +1921,14 @@ export default {
19031921
if (screenWidth <= 768) {
19041922
this.modalWidth = '450px'
19051923
}
1924+
},
1925+
copyToClipboard (txt) {
1926+
const parent = this
1927+
this.$copyText(txt, document.body, function (err) {
1928+
if (!err) {
1929+
parent.$message.success(parent.$t('label.copied.clipboard'))
1930+
}
1931+
})
19061932
}
19071933
}
19081934
}

ui/src/views/compute/DeployVM.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,8 @@
840840
</template>
841841

842842
<script>
843-
import { ref, reactive, toRaw, nextTick } from 'vue'
843+
import { ref, reactive, toRaw, nextTick, h } from 'vue'
844+
import { Button } from 'ant-design-vue'
844845
import { api } from '@/api'
845846
import _ from 'lodash'
846847
import { mixin, mixinDevice } from '@/utils/mixin.js'
@@ -2191,6 +2192,15 @@ export default {
21912192
this.$notification.success({
21922193
message: password + ` ${this.$t('label.for')} ` + name,
21932194
description: vm.password,
2195+
btn: () => h(
2196+
Button,
2197+
{
2198+
type: 'primary',
2199+
size: 'small',
2200+
onClick: () => this.copyToClipboard(vm.password)
2201+
},
2202+
() => [this.$t('label.copy.password')]
2203+
),
21942204
duration: 0
21952205
})
21962206
}
@@ -2690,6 +2700,14 @@ export default {
26902700
}
26912701
}
26922702
return networks
2703+
},
2704+
copyToClipboard (txt) {
2705+
const parent = this
2706+
this.$copyText(txt, document.body, function (err) {
2707+
if (!err) {
2708+
parent.$message.success(parent.$t('label.copied.clipboard'))
2709+
}
2710+
})
26932711
}
26942712
}
26952713
}

0 commit comments

Comments
 (0)