From ed67090e386f9f0f90fdf6b2800d6adced6309bf Mon Sep 17 00:00:00 2001 From: Kaveesha Date: Thu, 19 Mar 2020 11:17:19 +0530 Subject: [PATCH 1/2] Generate Basic data in payload and Add Restriction policies to forms --- .../components/AssignGroups/index.js | 26 +++++++++++++-- .../components/ConfigureProfile/index.js | 33 ++++++++++++++++--- .../components/PublishDevices/index.js | 27 +++++++++++++-- .../components/SelectPlatform/index.js | 8 ++--- .../components/SelectPolicyType/index.js | 16 ++++++++- .../Policies/components/AddPolicy/index.js | 13 +++++++- .../type/template/config/DataPanel.java | 11 +++++++ .../type/template/config/SubFormList.java | 24 ++++++++++++++ 8 files changed, 143 insertions(+), 15 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/SubFormList.java diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js index 38df0b9605..ffc17622b8 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js @@ -48,6 +48,22 @@ class AssignGroups extends React.Component { } }; + // generate payload by adding Assign Groups + onHandleContinue = () => { + this.props.form.validateFields((err, values) => { + if (!err) { + if (!values.users) { + delete values.users; + } + if (values.deviceGroups === 'NONE') { + delete values.deviceGroups; + } + Object.assign(this.props.newPolicyPayload, values); + } + }); + this.props.getNextStep(); + }; + getRolesList = () => { let apiURL = window.location.origin + @@ -164,7 +180,9 @@ class AssignGroups extends React.Component { style={{ display: 'block' }} > - {getFieldDecorator('roles', {})( + {getFieldDecorator('roles', { + initialValue: 'ANY', + })( {this.state.groups.map(group => ( @@ -219,7 +239,7 @@ class AssignGroups extends React.Component { - diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js index a17ad5d6a0..d73a62c163 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js @@ -295,6 +295,16 @@ class ConfigureProfile extends React.Component { return columns; }; + // generate payload by adding policy configurations + onHandleContinue = () => { + this.props.form.validateFields((err, values) => { + if (!err) { + console.log(values); + } + }); + this.props.getNextStep(); + }; + // generate form items getPanelItems = panel => { const { getFieldDecorator } = this.props.form; @@ -710,9 +720,24 @@ class ConfigureProfile extends React.Component { } > -
-
{this.getPanelItems(panel.panelItem)}
-
+ {panel.hasOwnProperty('panelItem') && ( +
+
{this.getPanelItems(panel.panelItem)}
+
+ )} + {panel.hasOwnProperty('subFormLists') && ( +
+ {Object.values(panel.subFormLists).map( + (form, i) => { + return ( +
+ {this.getPanelItems(form.panelItem)} +
+ ); + }, + )} +
+ )} @@ -727,7 +752,7 @@ class ConfigureProfile extends React.Component { - diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/PublishDevices/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/PublishDevices/index.js index 8075d5789c..10726d2b4d 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/PublishDevices/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/PublishDevices/index.js @@ -26,6 +26,23 @@ class PublishDevices extends React.Component { this.config = this.props.context; } + onClickSavePolicy = (event, isPublish) => { + this.props.form.validateFields((err, values) => { + if (!err) { + let policyProfile = Object.assign(this.props.policyProfile, { + profileName: values.policyName, + }); + Object.assign(values, { profile: policyProfile }); + Object.assign(this.props.newPolicyPayload, values); + if (isPublish) { + Object.assign(this.props.newPolicyPayload, { + active: isPublish, + }); + } + } + }); + }; + render() { const { getFieldDecorator } = this.props.form; return ( @@ -51,10 +68,16 @@ class PublishDevices extends React.Component { - - + diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPlatform/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPlatform/index.js index 4a335dfed1..d790408422 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPlatform/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPlatform/index.js @@ -19,15 +19,11 @@ import React from 'react'; import axios from 'axios'; import { Card, Col, Icon, message, notification, Row } from 'antd'; -import TimeAgo from 'javascript-time-ago'; -// Load locale-specific relative date/time formatting rules. -import en from 'javascript-time-ago/locale/en'; import { withConfigContext } from '../../../../../../../../components/ConfigContext'; class SelectPlatform extends React.Component { constructor(props) { super(props); - TimeAgo.addLocale(en); this.config = this.props.context; this.state = { data: [], @@ -41,6 +37,10 @@ class SelectPlatform extends React.Component { onClickCard = (e, type) => { this.props.getPolicyConfigJson(type); + let deviceType = { + deviceType: type, + }; + Object.assign(this.props.policyProfile, deviceType); }; // fetch data from api diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPolicyType/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPolicyType/index.js index 88d2b79134..199a14ba0a 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPolicyType/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPolicyType/index.js @@ -44,6 +44,20 @@ class SelectPolicyType extends React.Component { this.fetchPolicies(); } + // generate payload using Select policy type + onHandleContinue = () => { + this.props.form.validateFields((err, values) => { + if (!err) { + if (values.correctiveActions === 'NONE') { + values.correctiveActions = []; + } + Object.assign(this.props.newPolicyPayload, values); + } + console.log('aaaaaaa'); + }); + this.props.getNextStep(); + }; + fetchPolicies = () => { let apiUrl = window.location.origin + @@ -142,7 +156,7 @@ class SelectPolicyType extends React.Component { - diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/index.js index 082aaaec85..2140bd4059 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/index.js @@ -35,6 +35,8 @@ class AddPolicy extends React.Component { currentStepIndex: 0, isLoading: false, policyUIConfigurationsList: [], + newPolicyPayload: { compliance: 'enforce' }, + policyProfile: {}, }; } @@ -107,6 +109,8 @@ class AddPolicy extends React.Component { >
@@ -122,6 +127,7 @@ class AddPolicy extends React.Component { style={{ display: currentStepIndex === 2 ? 'unset' : 'none' }} > @@ -130,6 +136,7 @@ class AddPolicy extends React.Component { style={{ display: currentStepIndex === 3 ? 'unset' : 'none' }} > @@ -137,7 +144,11 @@ class AddPolicy extends React.Component {
- +
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DataPanel.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DataPanel.java index efb9fe2edb..2ab613f523 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DataPanel.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/DataPanel.java @@ -67,6 +67,10 @@ public class DataPanel { @XmlElement(name = "PanelItem") private List panelItem; + @XmlElementWrapper(name = "SubFormsList") + @XmlElement(name = "SubForm") + private List subFormLists; + public String getPaneId() { return panelId; } @@ -99,4 +103,11 @@ public class DataPanel { this.panelItem = panelItem; } + public List getSubPanelLists() { + return subFormLists; + } + + public void setSubPanelLists(List subFormLists) { + this.subFormLists = subFormLists; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/SubFormList.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/SubFormList.java new file mode 100644 index 0000000000..d4a020e823 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/SubFormList.java @@ -0,0 +1,24 @@ +package org.wso2.carbon.device.mgt.extensions.device.type.template.config; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import java.util.List; + +public class SubFormList { + @XmlAttribute(name = "id", required = true) + protected String id; + + @XmlElementWrapper(name = "PanelItems") + @XmlElement(name = "PanelItem") + private List panelItem; + + public List getPanelItemList() { + return panelItem; + } + + public void setPanelItemList(List panelItem) { + this.panelItem = panelItem; + } +} + From 2bf9977a99b066184d4754cdb9a8e9f4f4c6ca07 Mon Sep 17 00:00:00 2001 From: Kaveesha Date: Thu, 19 Mar 2020 22:42:35 +0530 Subject: [PATCH 2/2] Add new method to create payload --- .../components/AssignGroups/index.js | 11 +++-- .../components/ConfigureProfile/index.js | 11 +++-- .../components/PublishDevices/index.js | 23 ++++----- .../components/SelectPlatform/index.js | 8 ++-- .../components/SelectPolicyType/index.js | 12 +++-- .../Policies/components/AddPolicy/index.js | 48 ++++++++++++++++--- 6 files changed, 79 insertions(+), 34 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js index ffc17622b8..533d23ab11 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js @@ -49,7 +49,7 @@ class AssignGroups extends React.Component { }; // generate payload by adding Assign Groups - onHandleContinue = () => { + onHandleContinue = (e, formName) => { this.props.form.validateFields((err, values) => { if (!err) { if (!values.users) { @@ -58,10 +58,10 @@ class AssignGroups extends React.Component { if (values.deviceGroups === 'NONE') { delete values.deviceGroups; } - Object.assign(this.props.newPolicyPayload, values); + this.props.getPolicyPayloadData(formName, values); + this.props.getNextStep(); } }); - this.props.getNextStep(); }; getRolesList = () => { @@ -239,7 +239,10 @@ class AssignGroups extends React.Component { -
diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js index d73a62c163..7d0d45c27c 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js @@ -296,13 +296,13 @@ class ConfigureProfile extends React.Component { }; // generate payload by adding policy configurations - onHandleContinue = () => { + onHandleContinue = (e, formname) => { this.props.form.validateFields((err, values) => { if (!err) { - console.log(values); + this.props.getPolicyPayloadData(formname, values); + this.props.getNextStep(); } }); - this.props.getNextStep(); }; // generate form items @@ -752,7 +752,10 @@ class ConfigureProfile extends React.Component { - diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/PublishDevices/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/PublishDevices/index.js index 10726d2b4d..af7de28dd4 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/PublishDevices/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/PublishDevices/index.js @@ -26,19 +26,13 @@ class PublishDevices extends React.Component { this.config = this.props.context; } - onClickSavePolicy = (event, isPublish) => { + onClickSavePolicy = (event, isPublish, formName) => { this.props.form.validateFields((err, values) => { if (!err) { - let policyProfile = Object.assign(this.props.policyProfile, { - profileName: values.policyName, - }); - Object.assign(values, { profile: policyProfile }); - Object.assign(this.props.newPolicyPayload, values); if (isPublish) { - Object.assign(this.props.newPolicyPayload, { - active: isPublish, - }); + Object.assign(values, { active: isPublish }); } + this.props.getPolicyPayloadData(formName, values); } }); }; @@ -71,11 +65,18 @@ class PublishDevices extends React.Component { - diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPlatform/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPlatform/index.js index d790408422..cb67f39898 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPlatform/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/SelectPlatform/index.js @@ -35,12 +35,12 @@ class SelectPlatform extends React.Component { this.getDeviceTypes(); } - onClickCard = (e, type) => { + onClickCard = (e, type, formname) => { this.props.getPolicyConfigJson(type); let deviceType = { deviceType: type, }; - Object.assign(this.props.policyProfile, deviceType); + this.props.getPolicyPayloadData(formname, deviceType); }; // fetch data from api @@ -91,7 +91,9 @@ class SelectPlatform extends React.Component { size="default" style={{ width: 150 }} bordered={true} - onClick={e => this.onClickCard(e, data.name)} + onClick={e => + this.onClickCard(e, data.name, 'selectedPlatformData') + } cover={ { + onHandleContinue = (e, formName) => { this.props.form.validateFields((err, values) => { if (!err) { if (values.correctiveActions === 'NONE') { values.correctiveActions = []; } - Object.assign(this.props.newPolicyPayload, values); + this.props.getPolicyPayloadData(formName, values); + this.props.getNextStep(); } - console.log('aaaaaaa'); }); - this.props.getNextStep(); }; fetchPolicies = () => { @@ -156,7 +155,10 @@ class SelectPolicyType extends React.Component { - diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/index.js index 2140bd4059..908c110cf0 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/index.js @@ -37,9 +37,45 @@ class AddPolicy extends React.Component { policyUIConfigurationsList: [], newPolicyPayload: { compliance: 'enforce' }, policyProfile: {}, + payloadData: {}, }; } + getPolicyPayloadData = (dataName, dataValue) => { + Object.defineProperty(this.state.payloadData, dataName, { + value: dataValue, + writable: true, + }); + if (dataName === 'publishDevicesData') { + this.createPayload(); + } + }; + + createPayload = () => { + const { newPolicyPayload } = this.state; + const { + publishDevicesData, + selectedPlatformData, + policyProfile, + policyTypeData, + groupData, + } = this.state.payloadData; + let profile = { + policyName: publishDevicesData.policyName, + devicetype: selectedPlatformData.deviceType, + }; + + let payload = Object.assign( + newPolicyPayload, + publishDevicesData, + policyProfile, + policyTypeData, + groupData, + { profile: profile }, + ); + console.log(payload); + }; + getPolicyConfigJson = type => { this.setState({ isLoading: true }); @@ -109,8 +145,7 @@ class AddPolicy extends React.Component { >
@@ -127,7 +162,7 @@ class AddPolicy extends React.Component { style={{ display: currentStepIndex === 2 ? 'unset' : 'none' }} > @@ -136,7 +171,7 @@ class AddPolicy extends React.Component { style={{ display: currentStepIndex === 3 ? 'unset' : 'none' }} > @@ -145,8 +180,7 @@ class AddPolicy extends React.Component { style={{ display: currentStepIndex === 4 ? 'unset' : 'none' }} >