|
|
@ -1,31 +1,88 @@
|
|
|
|
import React from "react";
|
|
|
|
import React from "react";
|
|
|
|
import AppCard from "./AppCard";
|
|
|
|
import AppCard from "./AppCard";
|
|
|
|
import {Col, Row} from "antd";
|
|
|
|
import {Col, message, Row} from "antd";
|
|
|
|
import {connect} from "react-redux";
|
|
|
|
import axios from "axios";
|
|
|
|
import {getApps} from "../../js/actions";
|
|
|
|
import config from "../../../public/conf/config.json";
|
|
|
|
|
|
|
|
|
|
|
|
// connecting state.apps with the component
|
|
|
|
class AppList extends React.Component {
|
|
|
|
const mapStateToProps= state => {
|
|
|
|
|
|
|
|
return {apps : state.apps}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ConnectedAppList extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
|
|
|
apps: [],
|
|
|
|
|
|
|
|
loading: false
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
componentDidMount() {
|
|
|
|
this.props.getApps();
|
|
|
|
console.log("mounted");
|
|
|
|
|
|
|
|
const {deviceType} = this.props;
|
|
|
|
|
|
|
|
console.log(this.props);
|
|
|
|
|
|
|
|
this.props.changeSelectedMenuItem(deviceType);
|
|
|
|
|
|
|
|
this.fetchData(deviceType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
|
|
|
|
if (prevProps.deviceType !== this.props.deviceType) {
|
|
|
|
|
|
|
|
const {deviceType} = this.props;
|
|
|
|
|
|
|
|
this.props.changeSelectedMenuItem(deviceType);
|
|
|
|
|
|
|
|
this.fetchData(deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fetchData = (deviceType) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const payload = {};
|
|
|
|
|
|
|
|
if(deviceType==="web-clip"){
|
|
|
|
|
|
|
|
payload.appType= "WEB_CLIP";
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
payload.deviceType= deviceType;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
|
|
|
|
method: "post",
|
|
|
|
|
|
|
|
'content-type': "application/json",
|
|
|
|
|
|
|
|
payload: JSON.stringify(payload),
|
|
|
|
|
|
|
|
'api-endpoint': "/application-mgt-store/v1.0/applications/"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//url-encode parameters
|
|
|
|
|
|
|
|
const request = Object.keys(parameters).map(key => key + '=' + parameters[key]).join('&');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//send request to the invoker
|
|
|
|
|
|
|
|
axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request
|
|
|
|
|
|
|
|
).then(res => {
|
|
|
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
|
|
|
//todo remove this property check after backend improvement
|
|
|
|
|
|
|
|
let apps = (res.data.data.hasOwnProperty("applications")) ? res.data.data.applications : [];
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
apps: apps,
|
|
|
|
|
|
|
|
loading: false
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
|
|
|
if (error.hasOwnProperty("response") && error.response.status === 401) {
|
|
|
|
|
|
|
|
//todo display a popup 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 {apps} = this.state;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Row gutter={16}>
|
|
|
|
<Row gutter={16}>
|
|
|
|
{this.props.apps.map(app => (
|
|
|
|
{apps.map(app => (
|
|
|
|
<Col key={app.id} xs={12} sm={6} md={6} lg={4} xl={3}>
|
|
|
|
<Col key={app.id} xs={12} sm={6} md={6} lg={4} xl={3}>
|
|
|
|
<AppCard key={app.id}
|
|
|
|
<AppCard key={app.id}
|
|
|
|
app = {app}
|
|
|
|
app={app}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
))}
|
|
|
|
))}
|
|
|
|
</Row>
|
|
|
|
</Row>
|
|
|
@ -33,6 +90,4 @@ class ConnectedAppList extends React.Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AppList = connect(mapStateToProps,{getApps})(ConnectedAppList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default AppList;
|
|
|
|
export default AppList;
|