From b3d87186ebefb074a179de0434e1512d98a47f0f Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Sun, 28 Apr 2019 16:32:25 +0530 Subject: [PATCH] listed apps --- .../react-app/src/js/actions/index.js | 16 ++++++ .../src/js/constants/action-types.js | 4 +- .../react-app/src/js/reducers/index.js | 9 +++- .../src/pages/dashboard/apps/Apps.js | 49 ++++++------------- 4 files changed, 42 insertions(+), 36 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/actions/index.js diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/actions/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/actions/index.js new file mode 100644 index 00000000000..a1192b70eb6 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/actions/index.js @@ -0,0 +1,16 @@ +import axios from "axios"; +import {GET_APPS} from "../constants/action-types"; + +export function getApps() { + axios.post('https://localhost:9443/api/application-mgt-handler/v1.0/invoke', request + ).then(res => { + if(res.status === 200){ + return {type: GET_APPS, payload : res.data} + } + + }).catch(function (error) { + if(error.response.status === 401){ + window.location.href = 'https://localhost:9443/publisher/login'; + } + }); +} \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/constants/action-types.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/constants/action-types.js index 2cd535bbc21..e270ea0c6aa 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/constants/action-types.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/constants/action-types.js @@ -1 +1,3 @@ -export const LOGIN = "LOGIN"; \ No newline at end of file +export const LOGIN = "LOGIN"; +export const GET_APPS = "GET_APPS"; + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/reducers/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/reducers/index.js index 08eb66ed6da..8ba2625ee7f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/reducers/index.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/reducers/index.js @@ -1,8 +1,15 @@ +import {GET_APPS} from "../constants/action-types"; + const initialState = { - + apps : [] }; function rootReducer(state = initialState, action) { + if (action.type === GET_APPS) { + return Object.assign({}, state, { + apps: state.apps.concat(action.payload) + }); + } return state; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/Apps.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/Apps.js index 5a38f1460ef..68022454864 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/Apps.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/Apps.js @@ -23,41 +23,9 @@ const routes = [ ]; - - -const data = [{ - key: '1', - icon: 'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png', - name: 'John Brown', - platform: 'android', - type: 'Enterprise', - status: 'published', - version: '13.0.0.1', - updated_at: '27-03-2019 08:27' -},{ - key: '2', - icon: 'http://aztechbeat.com/wp-content/uploads/2014/04/confide-app-icon.png', - name: 'Lorem Ipsum', - platform: 'ios', - type: 'Enterprise', - status: 'published', - version: '2.3.1.2', - updated_at: '27-03-2019 09:45' -},{ - key: '3', - icon: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRx2Xx1-hnH16EGZHUlT06nOcfGODPoboA2TXKaBVtODto4lJtK', - name: 'Lorem Ipsum', - platform: 'ios', - type: 'Enterprise', - status: 'removed', - version: '4.1.1.0', - updated_at: '27-03-2019 09:46' -}]; - class Apps extends React.Component { routes; - state = { searchText: '', }; @@ -79,14 +47,27 @@ class Apps extends React.Component { axios.post('https://localhost:9443/api/application-mgt-handler/v1.0/invoke', request ).then(res => { if(res.status === 200){ + console.log(res.status); + let apps = []; + res.data['data']['applications'].forEach(function (app) { + apps.push({ + key: app.id, + icon: app["applicationReleases"][0]["iconPath"], + name: app.name, + platform: 'undefined', + type: app.type, + status: 'undefined', + version: 'undefined', + updated_at: 'undefined' + }); + }); thisComponent.setState({ - data : [] + data : apps }) } }).catch(function (error) { if(error.response.status === 401){ - console.log("bis"); window.location.href = 'https://localhost:9443/publisher/login'; } });