Change api requests in publisher

feature/appm-store/pbac
Jayasanka 5 years ago
parent 48c87384f1
commit 129ff7944e

@ -7,10 +7,10 @@
"protocol": "https", "protocol": "https",
"hostname": "localhost", "hostname": "localhost",
"httpsPort": "9443", "httpsPort": "9443",
"invokerUri": "/api/application-mgt-handler/v1.0/invoke", "invokerUri": "/ui-request-handler/invoke/application-mgt-publisher/v1.0",
"loginUri": "/api/application-mgt-handler/v1.0/login" "loginUri": "/ui-request-handler/login",
"platform": "publisher"
}, },
"serverUrl": "https://localhost:9443",
"defaultPlatformIcons": { "defaultPlatformIcons": {
"default": { "default": {
"icon": "mobile", "icon": "mobile",

@ -100,22 +100,26 @@ class AppsTable extends React.Component {
fetch = (params = {}) => { fetch = (params = {}) => {
this.setState({loading: true}); this.setState({loading: true});
if(!params.hasOwnProperty("page")){
params.page = 1;
}
const extraParams = { const extraParams = {
offset: 10 * (params.page - 1), offset: 10 * (params.page - 1),
limit: 10 limit: 10
}; };
// note: encode with '%26' not '&' // note: encode with '%26' not '&'
const encodedExtraParams = Object.keys(extraParams).map(key => key + '=' + extraParams[key]).join('%26'); const encodedExtraParams = Object.keys(extraParams).map(key => key + '=' + extraParams[key]).join('&');
const parameters = { const data = {
method: "post",
'content-type': "application/json",
payload: JSON.stringify({}),
'api-endpoint': "/application-mgt-publisher/v1.0/applications?" + encodedExtraParams
}; };
const request = Object.keys(parameters).map(key => key + '=' + parameters[key]).join('&'); console.log(config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/applications?"+encodedExtraParams);
console.log(request); axios.post(
axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/applications?"+encodedExtraParams,
data,
{
headers: { 'X-Platform': config.serverConfig.platform }
}
).then(res => { ).then(res => {
if (res.status === 200) { if (res.status === 200) {
let apps = []; let apps = [];
@ -136,7 +140,7 @@ class AppsTable extends React.Component {
} }
}).catch((error) => { }).catch((error) => {
if (error.response.status === 401) { if (error.hasOwnProperty("response") && error.response.status === 401) {
message.error('You are not logged in'); message.error('You are not logged in');
window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/publisher/login'; window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/publisher/login';
} else { } else {

@ -8,7 +8,6 @@ const {Title, Text, Paragraph} = Typography;
class ReleaseView extends React.Component { class ReleaseView extends React.Component {
render() { render() {
const release = this.props.release; const release = this.props.release;
console.log(release);
return ( return (
<div> <div>
<div className="release"> <div className="release">
@ -19,7 +18,6 @@ class ReleaseView extends React.Component {
<Col xl={10} sm={11} className="release-title"> <Col xl={10} sm={11} className="release-title">
<Title level={2}>App Name</Title> <Title level={2}>App Name</Title>
<Text>{release.version}</Text><br/> <Text>{release.version}</Text><br/>
<Text type="secondary">{release.description}</Text><br/>
</Col> </Col>
<Col xl={8} md={10} sm={24} xs={24} style={{float: "right"}}> <Col xl={8} md={10} sm={24} xs={24} style={{float: "right"}}>
<div> <div>
@ -50,12 +48,7 @@ class ReleaseView extends React.Component {
</Row> </Row>
<Divider/> <Divider/>
<Paragraph type="secondary" ellipsis={{rows: 3, expandable: true}}> <Paragraph type="secondary" ellipsis={{rows: 3, expandable: true}}>
Ant Design, a design language for background applications, is refined by Ant UED Team. Ant {release.description}
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.
</Paragraph> </Paragraph>
</div> </div>
</div> </div>

@ -20,9 +20,11 @@ class ManageCategories extends React.Component {
}; };
componentDidMount() { componentDidMount() {
const request = "method=get&content-type=application/json&payload={}&api-endpoint=/application-mgt-publisher/v1.0/applications/categories"; axios.get(
axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/admin/applications/categories/",
).then(res => { {
headers: { 'X-Platform': config.serverConfig.platform }
}).then(res => {
if (res.status === 200) { if (res.status === 200) {
let categories = JSON.parse(res.data.data); let categories = JSON.parse(res.data.data);
this.setState({ this.setState({
@ -55,8 +57,11 @@ class ManageCategories extends React.Component {
this.setState({ this.setState({
loading: true loading: true
}); });
const request = "method=delete&content-type=application/json&payload={}&api-endpoint=/application-mgt-publisher/v1.0/admin/applications/categories/" + id; axios.delete(
axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/admin/applications/categories/"+id,
{
headers: { 'X-Platform': config.serverConfig.platform }
}
).then(res => { ).then(res => {
if (res.status === 200) { if (res.status === 200) {
notification["success"]({ notification["success"]({
@ -192,10 +197,14 @@ class ManageCategories extends React.Component {
loading: true 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(
axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri+"/admin/applications/categories",
data,
{
headers: { 'X-Platform': config.serverConfig.platform }
}
).then(res => { ).then(res => {
if (res.status === 200) { if (res.status === 200) {
notification["success"]({ notification["success"]({

@ -57,9 +57,15 @@ class NormalLoginForm extends React.Component {
thisForm.setState({ thisForm.setState({
loading: true loading: true
}); });
console.log('Received values of form: ', values); const parameters = {
let data = "username=" + values.username + "&password=" + values.password + "&platform=publisher"; username: values.username,
axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname+':'+config.serverConfig.httpsPort+config.serverConfig.loginUri, data 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 => { ).then(res => {
if (res.status === 200) { if (res.status === 200) {
window.location = res.data.url; window.location = res.data.url;

@ -1,12 +1,11 @@
import React from "react"; import React from "react";
import '../../../../App.css'; import '../../../../App.css';
import {PageHeader, Typography, Input, Button, Row, Col, Avatar, Card} from "antd"; import {PageHeader, Typography, Row, Col, message, Card} from "antd";
import {connect} from "react-redux"; import axios from 'axios';
import config from "../../../../../public/conf/config.json";
import ReleaseView from "../../../../components/apps/release/ReleaseView"; import ReleaseView from "../../../../components/apps/release/ReleaseView";
import {getRelease} from "../../../../js/actions";
import LifeCycle from "../../../../components/apps/release/LifeCycle"; import LifeCycle from "../../../../components/apps/release/LifeCycle";
const Search = Input.Search;
const {Title} = Typography; const {Title} = Typography;
const routes = [ const routes = [
@ -24,31 +23,67 @@ const routes = [
}, },
]; ];
const mapStateToProps = state => {
return {release: state.release}
};
const mapDispatchToProps = dispatch => ({ class Release extends React.Component {
getRelease: (uuid) => dispatch(getRelease(uuid))
});
class ConnectedRelease extends React.Component {
routes; routes;
constructor(props) { constructor(props) {
super(props); super(props);
this.routes = props.routes; this.routes = props.routes;
this.state={
loading: true,
app: null,
uuid: null
}
} }
componentDidMount() { componentDidMount() {
const {uuid} = this.props.match.params; 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() { render() {
const {app} = this.state;
const release = app;
const release = this.props.release;
if (release == null) { if (release == null) {
return ( return (
<div style={{background: '#f0f2f5', padding: 24, minHeight: 780}}> <div style={{background: '#f0f2f5', padding: 24, minHeight: 780}}>
@ -72,7 +107,7 @@ class ConnectedRelease extends React.Component {
</Col> </Col>
<Col lg={8} md={24} style={{padding: 3}}> <Col lg={8} md={24} style={{padding: 3}}>
<Card lg={8} md={24}> <Card lg={8} md={24}>
<LifeCycle currentStatus={release.currentStatus.toUpperCase()}/> {/*<LifeCycle currentStatus={release.currentStatus.toUpperCase()}/>*/}
</Card> </Card>
</Col> </Col>
</Row> </Row>
@ -83,6 +118,4 @@ class ConnectedRelease extends React.Component {
} }
} }
const Release = connect(mapStateToProps,mapDispatchToProps)(ConnectedRelease);
export default Release; export default Release;

Loading…
Cancel
Save