From 129ff7944e4a2fa2de99fa9d414b013b6d006058 Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Tue, 18 Jun 2019 16:31:32 +0530 Subject: [PATCH] Change api requests in publisher --- .../react-app/public/conf/config.json | 6 +- .../components/apps/list-apps/AppsTable.js | 24 ++++--- .../components/apps/release/ReleaseView.js | 9 +-- .../manage/categories/ManageCategories.js | 25 ++++--- .../react-app/src/pages/Login.js | 12 +++- .../pages/dashboard/apps/release/Release.js | 69 ++++++++++++++----- 6 files changed, 95 insertions(+), 50 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/public/conf/config.json b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/public/conf/config.json index 8ac3b83577..902c2cdd46 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/public/conf/config.json +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/public/conf/config.json @@ -7,10 +7,10 @@ "protocol": "https", "hostname": "localhost", "httpsPort": "9443", - "invokerUri": "/api/application-mgt-handler/v1.0/invoke", - "loginUri": "/api/application-mgt-handler/v1.0/login" + "invokerUri": "/ui-request-handler/invoke/application-mgt-publisher/v1.0", + "loginUri": "/ui-request-handler/login", + "platform": "publisher" }, - "serverUrl": "https://localhost:9443", "defaultPlatformIcons": { "default": { "icon": "mobile", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppsTable.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppsTable.js index 16a6659af8..57a369965f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppsTable.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppsTable.js @@ -100,22 +100,26 @@ class AppsTable extends React.Component { fetch = (params = {}) => { this.setState({loading: true}); + if(!params.hasOwnProperty("page")){ + params.page = 1; + } + const extraParams = { offset: 10 * (params.page - 1), limit: 10 }; // note: encode with '%26' not '&' - const encodedExtraParams = Object.keys(extraParams).map(key => key + '=' + extraParams[key]).join('%26'); - const parameters = { - method: "post", - 'content-type': "application/json", - payload: JSON.stringify({}), - 'api-endpoint': "/application-mgt-publisher/v1.0/applications?" + encodedExtraParams + const encodedExtraParams = Object.keys(extraParams).map(key => key + '=' + extraParams[key]).join('&'); + const data = { }; - 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 + console.log(config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/applications?"+encodedExtraParams); + axios.post( + config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/applications?"+encodedExtraParams, + data, + { + headers: { 'X-Platform': config.serverConfig.platform } + } ).then(res => { if (res.status === 200) { let apps = []; @@ -136,7 +140,7 @@ class AppsTable extends React.Component { } }).catch((error) => { - if (error.response.status === 401) { + if (error.hasOwnProperty("response") && error.response.status === 401) { message.error('You are not logged in'); window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/publisher/login'; } else { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/ReleaseView.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/ReleaseView.js index effa0d7ec6..4fb34364a3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/ReleaseView.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/ReleaseView.js @@ -8,7 +8,6 @@ const {Title, Text, Paragraph} = Typography; class ReleaseView extends React.Component { render() { const release = this.props.release; - console.log(release); return (
@@ -19,7 +18,6 @@ class ReleaseView extends React.Component { App Name {release.version}
- {release.description}
@@ -50,12 +48,7 @@ class ReleaseView extends React.Component { - Ant Design, a design language for background applications, is refined by Ant UED Team. Ant - Design, a design language for background applications, is refined by Ant UED Team. Ant Design, - a design language for background applications, is refined by Ant UED Team. Ant Design, a - design language for background applications, is refined by Ant UED Team. Ant Design, a design - language for background applications, is refined by Ant UED Team. Ant Design, a design - language for background applications, is refined by Ant UED Team. + {release.description}
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/manage/categories/ManageCategories.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/manage/categories/ManageCategories.js index 9339835363..140e3e8a11 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/manage/categories/ManageCategories.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/manage/categories/ManageCategories.js @@ -20,9 +20,11 @@ class ManageCategories extends React.Component { }; componentDidMount() { - const request = "method=get&content-type=application/json&payload={}&api-endpoint=/application-mgt-publisher/v1.0/applications/categories"; - axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request - ).then(res => { + axios.get( + config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/admin/applications/categories/", + { + headers: { 'X-Platform': config.serverConfig.platform } + }).then(res => { if (res.status === 200) { let categories = JSON.parse(res.data.data); this.setState({ @@ -55,8 +57,11 @@ class ManageCategories extends React.Component { this.setState({ loading: true }); - const request = "method=delete&content-type=application/json&payload={}&api-endpoint=/application-mgt-publisher/v1.0/admin/applications/categories/" + id; - axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + axios.delete( + config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/admin/applications/categories/"+id, + { + headers: { 'X-Platform': config.serverConfig.platform } + } ).then(res => { if (res.status === 200) { notification["success"]({ @@ -192,10 +197,14 @@ class ManageCategories extends React.Component { loading: true }); - const dataArray = JSON.stringify(tempElements.map(category => category.categoryName)); + const data = JSON.stringify(tempElements.map(category => category.categoryName)); - const request = "method=post&content-type=application/json&payload=" + dataArray + "&api-endpoint=/application-mgt-publisher/v1.0/admin/applications/categories"; - axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + axios.post( + config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/admin/applications/categories", + data, + { + headers: { 'X-Platform': config.serverConfig.platform } + } ).then(res => { if (res.status === 200) { notification["success"]({ diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/Login.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/Login.js index 030a43dfe4..48701cf09d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/Login.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/Login.js @@ -57,9 +57,15 @@ class NormalLoginForm extends React.Component { thisForm.setState({ loading: true }); - console.log('Received values of form: ', values); - let data = "username=" + values.username + "&password=" + values.password + "&platform=publisher"; - axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname+':'+config.serverConfig.httpsPort+config.serverConfig.loginUri, data + const parameters = { + username: values.username, + password: values.password, + platform: "publisher" + }; + + const request = Object.keys(parameters).map(key => key + '=' + parameters[key]).join('&'); + + axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname+':'+config.serverConfig.httpsPort+config.serverConfig.loginUri, request ).then(res => { if (res.status === 200) { window.location = res.data.url; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/release/Release.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/release/Release.js index 69e268939b..dc19a967d6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/release/Release.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/release/Release.js @@ -1,12 +1,11 @@ import React from "react"; import '../../../../App.css'; -import {PageHeader, Typography, Input, Button, Row, Col, Avatar, Card} from "antd"; -import {connect} from "react-redux"; +import {PageHeader, Typography, Row, Col, message, Card} from "antd"; +import axios from 'axios'; +import config from "../../../../../public/conf/config.json"; import ReleaseView from "../../../../components/apps/release/ReleaseView"; -import {getRelease} from "../../../../js/actions"; import LifeCycle from "../../../../components/apps/release/LifeCycle"; -const Search = Input.Search; const {Title} = Typography; const routes = [ @@ -24,31 +23,67 @@ const routes = [ }, ]; -const mapStateToProps = state => { - return {release: state.release} -}; -const mapDispatchToProps = dispatch => ({ - getRelease: (uuid) => dispatch(getRelease(uuid)) -}); - -class ConnectedRelease extends React.Component { +class Release extends React.Component { routes; constructor(props) { super(props); this.routes = props.routes; - + this.state={ + loading: true, + app: null, + uuid: null + } } componentDidMount() { const {uuid} = this.props.match.params; - this.props.getRelease(uuid); + this.fetchData(uuid); + } + + componentDidUpdate(prevProps, prevState, snapshot) { + if (prevState.uuid !== this.state.uuid) { + const {uuid} = this.props.match.params; + this.fetchData(uuid); + } } + fetchData = (uuid)=>{ + + //send request to the invoker + axios.get( + config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/applications/release/"+uuid, + { + headers: { 'X-Platform': config.serverConfig.platform } + } + ).then(res => { + if (res.status === 200) { + let app = res.data.data; + this.setState({ + app: app, + loading: false, + uuid: uuid + }) + } + + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + //todo display a popop with error + 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({loading: false}); + }); + }; + render() { + const {app} = this.state; + const release = app; - const release = this.props.release; if (release == null) { return (
@@ -72,7 +107,7 @@ class ConnectedRelease extends React.Component { - + {/**/} @@ -83,6 +118,4 @@ class ConnectedRelease extends React.Component { } } -const Release = connect(mapStateToProps,mapDispatchToProps)(ConnectedRelease); - export default Release;