From 113be7e6ac70b547895a75498afb4be25cd94bbb Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Wed, 12 Jun 2019 16:38:26 +0530 Subject: [PATCH] Create components to install by group & role --- .../apps/release/install/AppInstallModal.js | 8 +- .../apps/release/install/GroupInstall.js | 120 ++++++++++++++++++ .../apps/release/install/RoleInstall.js | 120 ++++++++++++++++++ .../apps/release/install/UserInstall.js | 13 +- 4 files changed, 254 insertions(+), 7 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/GroupInstall.js create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/RoleInstall.js diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/AppInstallModal.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/AppInstallModal.js index c0e562348e..0cced3824f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/AppInstallModal.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/AppInstallModal.js @@ -1,6 +1,8 @@ import React from "react"; import {Button, Modal, Tabs} from "antd"; import UserInstall from "./UserInstall"; +import GroupInstall from "./GroupInstall"; +import RoleInstall from "./RoleInstall"; const { TabPane } = Tabs; @@ -20,13 +22,13 @@ class AppInstallModal extends React.Component{ - Tab 2 + Device install - Tab 3 + - Tab 3 + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/GroupInstall.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/GroupInstall.js new file mode 100644 index 0000000000..e57374f91f --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/GroupInstall.js @@ -0,0 +1,120 @@ +import React from "react"; +import {Typography, Select, Spin, message, notification, Button} from "antd"; +import debounce from 'lodash.debounce'; +import axios from "axios"; +import config from "../../../../../public/conf/config.json"; + +const {Text} = Typography; +const {Option} = Select; + + +class GroupInstall extends React.Component { + + constructor(props) { + super(props); + this.lastFetchId = 0; + this.fetchUser = debounce(this.fetchUser, 800); + } + + state = { + data: [], + value: [], + fetching: false, + }; + + fetchUser = value => { + this.lastFetchId += 1; + const fetchId = this.lastFetchId; + this.setState({data: [], fetching: true}); + + + const parameters = { + method: "get", + 'content-type': "application/json", + payload: "{}", + 'api-endpoint': "/device-mgt/v1.0/admin/groups?name=" + value + }; + + const request = Object.keys(parameters).map(key => key + '=' + parameters[key]).join('&'); + console.log(request); + axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + ).then(res => { + if (res.status === 200) { + if (fetchId !== this.lastFetchId) { + // for fetch callback order + return; + } + + console.log(res.data.data); + + const data = res.data.data.deviceGroups.map(group => ({ + text: group.name, + value: group.name, + })); + + this.setState({data, fetching: false}); + } + + }).catch((error) => { + if (error.hasOwnProperty("status") && error.response.status === 401) { + message.error('You are not logged in'); + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; + } else { + message.error('Something went wrong... :('); + } + + this.setState({fetching: false}); + }); + }; + + handleChange = value => { + this.setState({ + value, + data: [], + fetching: false, + }); + }; + + install = () =>{ + const {value} = this.state; + const data = []; + value.map(val=>{ + data.push(val.key); + }); + this.props.onInstall("group",data); + }; + + render() { + + const {fetching, data, value} = this.state; + + return ( +
+ Lorem ipsum dolor sit amet, ne tation labores quo, errem facilisis expetendis vel in. Ut choro + decore ubique sed, +
+
+ +
+ +
+
+ ); + } +} + +export default GroupInstall; \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/RoleInstall.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/RoleInstall.js new file mode 100644 index 0000000000..358a29ae2e --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/RoleInstall.js @@ -0,0 +1,120 @@ +import React from "react"; +import {Typography, Select, Spin, message, notification, Button} from "antd"; +import debounce from 'lodash.debounce'; +import axios from "axios"; +import config from "../../../../../public/conf/config.json"; + +const {Text} = Typography; +const {Option} = Select; + + +class RoleInstall extends React.Component { + + constructor(props) { + super(props); + this.lastFetchId = 0; + this.fetchUser = debounce(this.fetchUser, 800); + } + + state = { + data: [], + value: [], + fetching: false, + }; + + fetchUser = value => { + this.lastFetchId += 1; + const fetchId = this.lastFetchId; + this.setState({data: [], fetching: true}); + + + const parameters = { + method: "get", + 'content-type': "application/json", + payload: "{}", + 'api-endpoint': "/device-mgt/v1.0/roles?filter=" + value + }; + + const request = Object.keys(parameters).map(key => key + '=' + parameters[key]).join('&'); + console.log(request); + axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + ).then(res => { + if (res.status === 200) { + if (fetchId !== this.lastFetchId) { + // for fetch callback order + return; + } + + console.log(res.data.data); + + const data = res.data.data.roles.map(role => ({ + text: role, + value: role, + })); + + this.setState({data, fetching: false}); + } + + }).catch((error) => { + if (error.hasOwnProperty("status") && error.response.status === 401) { + message.error('You are not logged in'); + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; + } else { + message.error('Something went wrong... :('); + } + + this.setState({fetching: false}); + }); + }; + + handleChange = value => { + this.setState({ + value, + data: [], + fetching: false, + }); + }; + + install = () =>{ + const {value} = this.state; + const data = []; + value.map(val=>{ + data.push(val.key); + }); + this.props.onInstall("role",data); + }; + + render() { + + const {fetching, data, value} = this.state; + + return ( +
+ Lorem ipsum dolor sit amet, ne tation labores quo, errem facilisis expetendis vel in. Ut choro + decore ubique sed, +
+
+ +
+ +
+
+ ); + } +} + +export default RoleInstall; \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js index 3b6f45e534..27ee3b8382 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/install/UserInstall.js @@ -59,7 +59,7 @@ class UserInstall extends React.Component { }).catch((error) => { if (error.response.hasOwnProperty(status) && error.response.status === 401) { message.error('You are not logged in'); - window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/store/login'; + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + '/store/login'; } else { message.error('Something went wrong... :('); } @@ -76,8 +76,13 @@ class UserInstall extends React.Component { }); }; - install = () =>{ - this.props.onInstall("user",this.state.data); + install = () => { + const {value} = this.state; + const data = []; + value.map(val => { + data.push(val.key); + }); + this.props.onInstall("user", data); }; render() { @@ -104,7 +109,7 @@ class UserInstall extends React.Component { ))} -
+