forked from community/device-mgt-core
Create a report to get application not installed devices Closes product-iots#322 See merge request entgra/carbon-device-mgt!438feature/appm-store/pbac
commit
1e1d2acd01
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { PageHeader, Breadcrumb, Icon, Button } from 'antd';
|
||||
|
||||
import { Link } from 'react-router-dom';
|
||||
import { withConfigContext } from '../../../context/ConfigContext';
|
||||
|
||||
import AppListDropDown from '../Widgets/AppListDropDown';
|
||||
import ReportDevicesTable from '../Widgets/ReportDevicesTable';
|
||||
import AppVersionDropDown from '../Widgets/AppVersionDropDown';
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
let config = null;
|
||||
let url;
|
||||
let packageName;
|
||||
let version;
|
||||
|
||||
class AppNotInstalledDevicesReport extends React.Component {
|
||||
routes;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.routes = props.routes;
|
||||
config = this.props.context;
|
||||
this.state = {
|
||||
apiUrl: null,
|
||||
visible: false,
|
||||
packageName: null,
|
||||
version: 'all',
|
||||
};
|
||||
}
|
||||
|
||||
getAppList = appPackageName => {
|
||||
packageName = appPackageName;
|
||||
this.setState({ packageName });
|
||||
};
|
||||
|
||||
getVersion = appVersion => {
|
||||
version = appVersion;
|
||||
this.setState({ version });
|
||||
};
|
||||
|
||||
onClickGenerateButton = () => {
|
||||
const { packageName, version } = this.state;
|
||||
if (version === 'all') {
|
||||
url =
|
||||
window.location.origin +
|
||||
config.serverConfig.invoker.uri +
|
||||
config.serverConfig.invoker.deviceMgt +
|
||||
'/reports/devices/android/' +
|
||||
packageName +
|
||||
'/not-installed?';
|
||||
} else {
|
||||
url =
|
||||
window.location.origin +
|
||||
config.serverConfig.invoker.uri +
|
||||
config.serverConfig.invoker.deviceMgt +
|
||||
'/reports/devices/android/' +
|
||||
packageName +
|
||||
'/not-installed?app-version=' +
|
||||
version +
|
||||
'&';
|
||||
}
|
||||
this.setState({ apiUrl: url });
|
||||
};
|
||||
|
||||
render() {
|
||||
const { apiUrl, packageName } = this.state;
|
||||
return (
|
||||
<div>
|
||||
<PageHeader style={{ paddingTop: 0 }}>
|
||||
<Breadcrumb style={{ paddingBottom: 16 }}>
|
||||
<Breadcrumb.Item>
|
||||
<Link to="/entgra">
|
||||
<Icon type="home" /> Home
|
||||
</Link>
|
||||
</Breadcrumb.Item>
|
||||
<Breadcrumb.Item>
|
||||
<Link to="/entgra/reports">Reports</Link>
|
||||
</Breadcrumb.Item>
|
||||
<Breadcrumb.Item>App NOT Installed Devices Report</Breadcrumb.Item>
|
||||
</Breadcrumb>
|
||||
<div className="wrap" style={{ marginBottom: '10px' }}>
|
||||
<h3>Policy Report</h3>
|
||||
|
||||
<div style={{ display: 'flex', marginBottom: '10px' }}>
|
||||
<div>
|
||||
<AppListDropDown getAppList={this.getAppList} />
|
||||
</div>
|
||||
|
||||
<div style={{ marginLeft: '10px' }}>
|
||||
<AppVersionDropDown
|
||||
getVersion={this.getVersion}
|
||||
packageName={packageName}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={this.onClickGenerateButton}
|
||||
style={{ marginLeft: '10px' }}
|
||||
>
|
||||
Generate Report
|
||||
</Button>
|
||||
</div>
|
||||
<div style={{ backgroundColor: '#ffffff', borderRadius: 5 }}>
|
||||
<ReportDevicesTable apiUrl={apiUrl} />
|
||||
</div>
|
||||
</div>
|
||||
</PageHeader>
|
||||
<div
|
||||
style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}
|
||||
></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withConfigContext(AppNotInstalledDevicesReport);
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { message, notification, Select } from 'antd';
|
||||
import axios from 'axios';
|
||||
import { withConfigContext } from '../../../context/ConfigContext';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
class AppListDropDown extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
selectItem: [],
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.fetchFullAppList();
|
||||
}
|
||||
|
||||
fetchFullAppList = () => {
|
||||
const config = this.props.context;
|
||||
axios
|
||||
.get(
|
||||
window.location.origin +
|
||||
config.serverConfig.invoker.uri +
|
||||
config.serverConfig.invoker.deviceMgt +
|
||||
'/devices/android/applications?offset=0&limit=-1',
|
||||
)
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let selectItem;
|
||||
selectItem = res.data.data.applicationList.map(data => (
|
||||
<Option value={data.id} key={data.applicationIdentifier}>
|
||||
{data.name.replace('%', ' ')}
|
||||
</Option>
|
||||
));
|
||||
this.setState({ selectItem });
|
||||
}
|
||||
})
|
||||
.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 = window.location.origin + '/entgra/login';
|
||||
} else {
|
||||
notification.error({
|
||||
message: 'There was a problem',
|
||||
duration: 0,
|
||||
description:
|
||||
'Error occurred while trying to load application list.',
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
onChange = (value, data) => {
|
||||
this.props.getAppList(data.key);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { selectItem } = this.state;
|
||||
return (
|
||||
<div>
|
||||
<Select
|
||||
showSearch
|
||||
style={{ width: 200 }}
|
||||
placeholder="Select an app"
|
||||
optionFilterProp="children"
|
||||
onChange={this.onChange}
|
||||
filterOption={(input, option) =>
|
||||
option.props.children.toLowerCase().indexOf(input.toLowerCase()) >=
|
||||
0
|
||||
}
|
||||
>
|
||||
{selectItem}
|
||||
</Select>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withConfigContext(AppListDropDown);
|
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { message, notification, Select } from 'antd';
|
||||
import axios from 'axios';
|
||||
import { withConfigContext } from '../../../context/ConfigContext';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
class AppVersionDropDown extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
selectItem: [],
|
||||
loading: false,
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.packageName) {
|
||||
this.fetchVersionList();
|
||||
}
|
||||
}
|
||||
|
||||
// Rerender component when parameters change
|
||||
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||
if (prevProps.packageName !== this.props.packageName) {
|
||||
this.fetchVersionList();
|
||||
}
|
||||
}
|
||||
|
||||
fetchVersionList = () => {
|
||||
const config = this.props.context;
|
||||
this.setState({ loading: true });
|
||||
axios
|
||||
.get(
|
||||
window.location.origin +
|
||||
config.serverConfig.invoker.uri +
|
||||
config.serverConfig.invoker.deviceMgt +
|
||||
'/devices/application/' +
|
||||
this.props.packageName +
|
||||
'/versions',
|
||||
)
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let selectItem;
|
||||
selectItem = JSON.parse(res.data.data).map(data => (
|
||||
<Option value={data} key={data}>
|
||||
{data}
|
||||
</Option>
|
||||
));
|
||||
this.setState({ selectItem, loading: false });
|
||||
}
|
||||
})
|
||||
.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 = window.location.origin + '/entgra/login';
|
||||
} else {
|
||||
notification.error({
|
||||
message: 'There was a problem',
|
||||
duration: 0,
|
||||
description:
|
||||
'Error occurred while trying to load application list.',
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
onChange = value => {
|
||||
this.props.getVersion(value);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { selectItem, loading } = this.state;
|
||||
return (
|
||||
<div>
|
||||
<Select
|
||||
defaultValue={'all'}
|
||||
showSearch
|
||||
style={{ width: 200 }}
|
||||
placeholder="Select app version"
|
||||
optionFilterProp="children"
|
||||
onChange={this.onChange}
|
||||
loading={loading}
|
||||
filterOption={(input, option) =>
|
||||
option.props.children.toLowerCase().indexOf(input.toLowerCase()) >=
|
||||
0
|
||||
}
|
||||
>
|
||||
<Option value={'all'} key={'all'}>
|
||||
All
|
||||
</Option>
|
||||
{selectItem}
|
||||
</Select>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withConfigContext(AppVersionDropDown);
|
@ -0,0 +1,249 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import axios from 'axios';
|
||||
import { Icon, message, notification, Table, Tag, Tooltip } from 'antd';
|
||||
import TimeAgo from 'javascript-time-ago';
|
||||
// Load locale-specific relative date/time formatting rules.
|
||||
import en from 'javascript-time-ago/locale/en';
|
||||
import { withConfigContext } from '../../../context/ConfigContext';
|
||||
|
||||
let config = null;
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: 'Device',
|
||||
dataIndex: 'name',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: 'Type',
|
||||
dataIndex: 'type',
|
||||
key: 'type',
|
||||
// eslint-disable-next-line react/display-name
|
||||
render: type => {
|
||||
const defaultPlatformIcons = config.defaultPlatformIcons;
|
||||
let icon = defaultPlatformIcons.default.icon;
|
||||
let color = defaultPlatformIcons.default.color;
|
||||
let theme = defaultPlatformIcons.default.theme;
|
||||
|
||||
if (defaultPlatformIcons.hasOwnProperty(type)) {
|
||||
icon = defaultPlatformIcons[type].icon;
|
||||
color = defaultPlatformIcons[type].color;
|
||||
theme = defaultPlatformIcons[type].theme;
|
||||
}
|
||||
|
||||
return (
|
||||
<span style={{ fontSize: 20, color: color, textAlign: 'center' }}>
|
||||
<Icon type={icon} theme={theme} />
|
||||
</span>
|
||||
);
|
||||
},
|
||||
// todo add filtering options
|
||||
},
|
||||
{
|
||||
title: 'Owner',
|
||||
dataIndex: 'enrolmentInfo',
|
||||
key: 'owner',
|
||||
render: enrolmentInfo => enrolmentInfo.owner,
|
||||
// todo add filtering options
|
||||
},
|
||||
{
|
||||
title: 'Ownership',
|
||||
dataIndex: 'enrolmentInfo',
|
||||
key: 'ownership',
|
||||
render: enrolmentInfo => enrolmentInfo.ownership,
|
||||
// todo add filtering options
|
||||
},
|
||||
{
|
||||
title: 'Status',
|
||||
dataIndex: 'enrolmentInfo',
|
||||
key: 'status',
|
||||
// eslint-disable-next-line react/display-name
|
||||
render: enrolmentInfo => {
|
||||
const status = enrolmentInfo.status.toLowerCase();
|
||||
let color = '#f9ca24';
|
||||
switch (status) {
|
||||
case 'active':
|
||||
color = '#badc58';
|
||||
break;
|
||||
case 'created':
|
||||
color = '#6ab04c';
|
||||
break;
|
||||
case 'removed':
|
||||
color = '#ff7979';
|
||||
break;
|
||||
case 'inactive':
|
||||
color = '#f9ca24';
|
||||
break;
|
||||
case 'blocked':
|
||||
color = '#636e72';
|
||||
break;
|
||||
}
|
||||
return <Tag color={color}>{status}</Tag>;
|
||||
},
|
||||
// todo add filtering options
|
||||
},
|
||||
{
|
||||
title: 'Last Updated',
|
||||
dataIndex: 'enrolmentInfo',
|
||||
key: 'dateOfLastUpdate',
|
||||
// eslint-disable-next-line react/display-name
|
||||
render: data => {
|
||||
const { dateOfLastUpdate } = data;
|
||||
const timeAgoString = getTimeAgo(dateOfLastUpdate);
|
||||
return (
|
||||
<Tooltip title={new Date(dateOfLastUpdate).toString()}>
|
||||
{timeAgoString}
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
// todo add filtering options
|
||||
},
|
||||
];
|
||||
|
||||
const getTimeAgo = time => {
|
||||
const timeAgo = new TimeAgo('en-US');
|
||||
return timeAgo.format(time);
|
||||
};
|
||||
|
||||
class ReportDeviceTable extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
config = this.props.context;
|
||||
TimeAgo.addLocale(en);
|
||||
this.state = {
|
||||
data: [],
|
||||
pagination: {},
|
||||
loading: false,
|
||||
selectedRows: [],
|
||||
paramsObj: {},
|
||||
};
|
||||
}
|
||||
|
||||
rowSelection = {
|
||||
onChange: (selectedRowKeys, selectedRows) => {
|
||||
this.setState({
|
||||
selectedRows: selectedRows,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.apiUrl) {
|
||||
this.fetch();
|
||||
}
|
||||
}
|
||||
|
||||
// Rerender component when parameters change
|
||||
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||
if (prevProps.apiUrl !== this.props.apiUrl) {
|
||||
this.fetch();
|
||||
}
|
||||
}
|
||||
|
||||
// fetch data from api
|
||||
fetch = (params = {}) => {
|
||||
this.setState({ loading: true });
|
||||
// get current page
|
||||
const currentPage = params.hasOwnProperty('page') ? params.page : 1;
|
||||
|
||||
const extraParams = {
|
||||
offset: 10 * (currentPage - 1), // calculate the offset
|
||||
limit: 10,
|
||||
};
|
||||
|
||||
const encodedExtraParams = Object.keys(extraParams)
|
||||
.map(key => key + '=' + extraParams[key])
|
||||
.join('&');
|
||||
|
||||
// send request to the invokerss
|
||||
axios
|
||||
.get(this.props.apiUrl + encodedExtraParams)
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
const pagination = { ...this.state.pagination };
|
||||
this.setState({
|
||||
loading: false,
|
||||
data: res.data.data,
|
||||
pagination,
|
||||
});
|
||||
}
|
||||
})
|
||||
.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 = window.location.origin + '/entgra/login';
|
||||
} else {
|
||||
notification.error({
|
||||
message: 'There was a problem',
|
||||
duration: 0,
|
||||
description: 'Error occurred while trying to load devices.',
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({ loading: false });
|
||||
});
|
||||
};
|
||||
|
||||
handleTableChange = (pagination, filters, sorter) => {
|
||||
const pager = { ...this.state.pagination };
|
||||
pager.current = pagination.current;
|
||||
this.setState({
|
||||
pagination: pager,
|
||||
});
|
||||
this.fetch({
|
||||
results: pagination.pageSize,
|
||||
page: pagination.current,
|
||||
sortField: sorter.field,
|
||||
sortOrder: sorter.order,
|
||||
...filters,
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const { data, pagination, loading } = this.state;
|
||||
return (
|
||||
<div>
|
||||
<Table
|
||||
columns={columns}
|
||||
rowKey={record =>
|
||||
record.deviceIdentifier +
|
||||
record.enrolmentInfo.owner +
|
||||
record.enrolmentInfo.ownership
|
||||
}
|
||||
dataSource={data.devices}
|
||||
pagination={{
|
||||
...pagination,
|
||||
size: 'small',
|
||||
total: data.count,
|
||||
showTotal: (total, range) =>
|
||||
`showing ${range[0]}-${range[1]} of ${total} devices`,
|
||||
}}
|
||||
loading={loading}
|
||||
onChange={this.handleTableChange}
|
||||
rowSelection={this.rowSelection}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withConfigContext(ReportDeviceTable);
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ApplicationList extends BasePaginatedResult{
|
||||
|
||||
private List<Application> applicationList = new ArrayList<>();
|
||||
|
||||
@ApiModelProperty(value = "List of applications returned")
|
||||
@JsonProperty("applications")
|
||||
public List<Application> getList() {
|
||||
return applicationList;
|
||||
}
|
||||
|
||||
public void setList(List<Application> applicationList) {
|
||||
this.applicationList = applicationList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\n");
|
||||
sb.append(" count: ").append(getCount()).append(",\n");
|
||||
sb.append(" applications: [").append(applicationList).append("\n");
|
||||
sb.append("]}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue