This is an automated email from the ASF dual-hosted git repository.

weizhou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new 8939ebbf4e9 ui: allow copying password from notification (#7985)
8939ebbf4e9 is described below

commit 8939ebbf4e9031fe58bdf63ce2aaff036870ddc7
Author: Abhishek Kumar <[email protected]>
AuthorDate: Thu Sep 28 18:32:36 2023 +0530

    ui: allow copying password from notification (#7985)
    
    * ui: allow copying password from notification
    
    Signed-off-by: Abhishek Kumar <[email protected]>
    
    * fix warnings, use clipboard lib
    
    Signed-off-by: Abhishek Kumar <[email protected]>
    
    * fix for deploy vm
    
    Signed-off-by: Abhishek Kumar <[email protected]>
    
    ---------
    
    Signed-off-by: Abhishek Kumar <[email protected]>
---
 ui/public/locales/en.json         |  1 +
 ui/src/config/section/compute.js  |  8 +++++++-
 ui/src/views/AutogenView.vue      | 42 +++++++++++++++++++++++++++++++--------
 ui/src/views/compute/DeployVM.vue | 20 ++++++++++++++++++-
 4 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json
index 7b7bb0810b5..216c6168c5f 100644
--- a/ui/public/locales/en.json
+++ b/ui/public/locales/en.json
@@ -517,6 +517,7 @@
 "label.copy.clipboard": "Copy to clipboard",
 "label.copy.consoleurl": "Copy console URL to clipboard",
 "label.copyid": "Copy ID",
+"label.copy.password": "Copy password",
 "label.core": "Core",
 "label.core.zone.type": "Core zone type",
 "label.counter": "Counter",
diff --git a/ui/src/config/section/compute.js b/ui/src/config/section/compute.js
index 6602ecb884c..22ee2b007f5 100644
--- a/ui/src/config/section/compute.js
+++ b/ui/src/config/section/compute.js
@@ -370,7 +370,13 @@ export default {
           message: 'message.action.instance.reset.password',
           dataView: true,
           show: (record) => { return ['Stopped'].includes(record.state) && 
record.passwordenabled },
-          response: (result) => { return result.virtualmachine && 
result.virtualmachine.password ? `The password of VM 
<b>${result.virtualmachine.displayname}</b> is 
<b>${result.virtualmachine.password}</b>` : null }
+          response: (result) => {
+            return {
+              message: result.virtualmachine && result.virtualmachine.password 
? `The password of VM <b>${result.virtualmachine.displayname}</b> is 
<b>${result.virtualmachine.password}</b>` : null,
+              copybuttontext: result.virtualmachine.password ? 
'label.copy.password' : null,
+              copytext: result.virtualmachine.password ? 
result.virtualmachine.password : null
+            }
+          }
         },
         {
           api: 'resetSSHKeyForVirtualMachine',
diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue
index ba1b87042b7..fa33be8d1b0 100644
--- a/ui/src/views/AutogenView.vue
+++ b/ui/src/views/AutogenView.vue
@@ -444,7 +444,8 @@
 </template>
 
 <script>
-import { ref, reactive, toRaw } from 'vue'
+import { ref, reactive, toRaw, h } from 'vue'
+import { Button } from 'ant-design-vue'
 import { api } from '@/api'
 import { mixinDevice } from '@/utils/mixin.js'
 import { genericCompare } from '@/utils/sort.js'
@@ -1301,13 +1302,30 @@ export default {
               eventBus.emit('update-resource-state', { selectedItems: 
this.selectedItems, resource, state: 'success' })
             }
             if (action.response) {
-              const description = action.response(result.jobresult)
-              if (description) {
-                this.$notification.info({
-                  message: this.$t(action.label),
-                  description: (<span v-html={description}></span>),
-                  duration: 0
-                })
+              const response = action.response(result.jobresult)
+              if (response) {
+                if (typeof response === 'object') {
+                  this.$notification.info({
+                    message: this.$t(action.label),
+                    description: (<span v-html={response.message}></span>),
+                    btn: () => h(
+                      Button,
+                      {
+                        type: 'primary',
+                        size: 'small',
+                        onClick: () => this.copyToClipboard(response.copytext)
+                      },
+                      () => [this.$t(response.copybuttontext)]
+                    ),
+                    duration: 0
+                  })
+                } else {
+                  this.$notification.info({
+                    message: this.$t(action.label),
+                    description: (<span v-html={response}></span>),
+                    duration: 0
+                  })
+                }
               }
             }
             if ('successMethod' in action) {
@@ -1903,6 +1921,14 @@ export default {
       if (screenWidth <= 768) {
         this.modalWidth = '450px'
       }
+    },
+    copyToClipboard (txt) {
+      const parent = this
+      this.$copyText(txt, document.body, function (err) {
+        if (!err) {
+          parent.$message.success(parent.$t('label.copied.clipboard'))
+        }
+      })
     }
   }
 }
diff --git a/ui/src/views/compute/DeployVM.vue 
b/ui/src/views/compute/DeployVM.vue
index e33ab9fbe73..effc9a1c349 100644
--- a/ui/src/views/compute/DeployVM.vue
+++ b/ui/src/views/compute/DeployVM.vue
@@ -840,7 +840,8 @@
 </template>
 
 <script>
-import { ref, reactive, toRaw, nextTick } from 'vue'
+import { ref, reactive, toRaw, nextTick, h } from 'vue'
+import { Button } from 'ant-design-vue'
 import { api } from '@/api'
 import _ from 'lodash'
 import { mixin, mixinDevice } from '@/utils/mixin.js'
@@ -2191,6 +2192,15 @@ export default {
                   this.$notification.success({
                     message: password + ` ${this.$t('label.for')} ` + name,
                     description: vm.password,
+                    btn: () => h(
+                      Button,
+                      {
+                        type: 'primary',
+                        size: 'small',
+                        onClick: () => this.copyToClipboard(vm.password)
+                      },
+                      () => [this.$t('label.copy.password')]
+                    ),
                     duration: 0
                   })
                 }
@@ -2690,6 +2700,14 @@ export default {
         }
       }
       return networks
+    },
+    copyToClipboard (txt) {
+      const parent = this
+      this.$copyText(txt, document.body, function (err) {
+        if (!err) {
+          parent.$message.success(parent.$t('label.copied.clipboard'))
+        }
+      })
     }
   }
 }

Reply via email to