You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2020/03/24 14:17:30 UTC

[cloudstack-primate] branch master updated: autogenview: fill edit form field values (#227)

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

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack-primate.git


The following commit(s) were added to refs/heads/master by this push:
     new 085135d  autogenview: fill edit form field values (#227)
085135d is described below

commit 085135db7ab92eb30a0d6eca8eed83cfd5c9be95
Author: Hoang Nguyen <ho...@unitech.vn>
AuthorDate: Tue Mar 24 21:17:21 2020 +0700

    autogenview: fill edit form field values (#227)
    
    This fixes to fill an edit form fields' value if possible automatically for all auto-generated forms
    
    Fixes #198
    
    Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
    Co-authored-by: Rohit Yadav <ro...@shapeblue.com>
---
 src/config/section/network.js | 13 -------------
 src/views/AutogenView.vue     | 19 +++++++++++++++++++
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/src/config/section/network.js b/src/config/section/network.js
index 70bfa92..6f42198 100644
--- a/src/config/section/network.js
+++ b/src/config/section/network.js
@@ -61,19 +61,6 @@ export default {
           component: () => import('@/views/network/CreateNetwork.vue')
         },
         {
-          api: 'associateIpAddress',
-          icon: 'plus',
-          label: 'Acquire New IP',
-          dataView: true,
-          show: (record) => { return record && record.service && record.service.filter(x => x.name && ['StaticNat', 'SourceNat', 'Firewall', 'PortForwarding', 'Lb'].includes(x.name)).length > 0 },
-          args: ['networkid'],
-          mapping: {
-            networkid: {
-              value: (record) => { return record.id }
-            }
-          }
-        },
-        {
           api: 'updateNetwork',
           icon: 'edit',
           label: 'Update Network',
diff --git a/src/views/AutogenView.vue b/src/views/AutogenView.vue
index 3b53a44..de44650 100644
--- a/src/views/AutogenView.vue
+++ b/src/views/AutogenView.vue
@@ -559,6 +559,9 @@ export default {
         }
       }
       this.currentAction.loading = false
+      if (action.dataView && action.icon === 'edit') {
+        this.fillEditFormFieldValues()
+      }
     },
     listUuidOpts (param) {
       if (this.currentAction.mapping && param.name in this.currentAction.mapping && !this.currentAction.mapping[param.name].api) {
@@ -641,6 +644,22 @@ export default {
         action
       })
     },
+    fillEditFormFieldValues () {
+      const form = this.form
+      this.currentAction.paramFields.map(field => {
+        let fieldValue = null
+        let fieldName = null
+        if (field.type === 'uuid' || field.type === 'list' || field.name === 'account' || (this.currentAction.mapping && field.name in this.currentAction.mapping)) {
+          fieldName = field.name.replace('ids', 'name').replace('id', 'name')
+        } else {
+          fieldName = field.name
+        }
+        fieldValue = this.resource[fieldName] ? this.resource[fieldName] : null
+        if (fieldValue) {
+          form.getFieldDecorator(field.name, { initialValue: fieldValue })
+        }
+      })
+    },
     handleSubmit (e) {
       e.preventDefault()
       this.form.validateFields((err, values) => {