forked from community/device-mgt-core
Implement reports for device enrollment and policy compliance See merge request entgra/carbon-device-mgt!426feature/appm-store/pbac
commit
ec0c5fde39
@ -0,0 +1,189 @@
|
||||
/*
|
||||
* 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, Radio, Popover, Button } from 'antd';
|
||||
|
||||
import { Link } from 'react-router-dom';
|
||||
import { withConfigContext } from '../../../context/ConfigContext';
|
||||
import PolicyDevicesTable from '../Widgets/PolicyDevicesTable';
|
||||
import moment from 'moment';
|
||||
import DateRangePicker from '../DateRangePicker';
|
||||
import SelectPolicyDropDown from '../Widgets/SelectPolicyDropDown';
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
let config = null;
|
||||
|
||||
class PolicyReport extends React.Component {
|
||||
routes;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.routes = props.routes;
|
||||
config = this.props.context;
|
||||
this.state = {
|
||||
durationMode: 'weekly',
|
||||
isCompliant: true,
|
||||
// This object contains parameters which pass into API endpoint
|
||||
policyReportData: {
|
||||
from: moment()
|
||||
.subtract(7, 'days')
|
||||
.format('YYYY-MM-DD'),
|
||||
to: moment().format('YYYY-MM-DD'),
|
||||
},
|
||||
visible: false,
|
||||
};
|
||||
}
|
||||
|
||||
handleModeChange = e => {
|
||||
const isCompliant = e.target.value;
|
||||
this.setState({ isCompliant });
|
||||
};
|
||||
|
||||
handleDurationModeChange = e => {
|
||||
const durationMode = e.target.value;
|
||||
switch (durationMode) {
|
||||
case 'daily':
|
||||
this.updateDurationValue(
|
||||
moment()
|
||||
.subtract(1, 'days')
|
||||
.format('YYYY-MM-DD'),
|
||||
moment().format('YYYY-MM-DD'),
|
||||
);
|
||||
break;
|
||||
case 'weekly':
|
||||
this.updateDurationValue(
|
||||
moment()
|
||||
.subtract(7, 'days')
|
||||
.format('YYYY-MM-DD'),
|
||||
moment().format('YYYY-MM-DD'),
|
||||
);
|
||||
break;
|
||||
case 'monthly':
|
||||
this.updateDurationValue(
|
||||
moment()
|
||||
.subtract(30, 'days')
|
||||
.format('YYYY-MM-DD'),
|
||||
moment().format('YYYY-MM-DD'),
|
||||
);
|
||||
break;
|
||||
}
|
||||
this.setState({ durationMode });
|
||||
};
|
||||
|
||||
hidePopover = () => {
|
||||
this.setState({
|
||||
visible: false,
|
||||
});
|
||||
};
|
||||
|
||||
handlePopoverVisibleChange = visible => {
|
||||
this.setState({ visible });
|
||||
};
|
||||
|
||||
getPolicyId = policyId => {
|
||||
let tempParamObj = this.state.policyReportData;
|
||||
if (policyId === 'all') {
|
||||
delete tempParamObj.policy;
|
||||
} else {
|
||||
tempParamObj.policy = policyId;
|
||||
}
|
||||
this.setState({ policyReportData: tempParamObj });
|
||||
};
|
||||
|
||||
// Get modified value from datepicker and set it to paramsObject
|
||||
updateDurationValue = (modifiedFromDate, modifiedToDate) => {
|
||||
let tempParamObj = this.state.policyReportData;
|
||||
tempParamObj.from = modifiedFromDate;
|
||||
tempParamObj.to = modifiedToDate;
|
||||
this.setState({ policyReportData: tempParamObj });
|
||||
};
|
||||
|
||||
render() {
|
||||
const { isCompliant, durationMode } = this.state;
|
||||
const policyData = { ...this.state.policyReportData };
|
||||
return (
|
||||
<div>
|
||||
<PageHeader style={{ paddingTop: 0 }}>
|
||||
<Breadcrumb style={{ paddingBottom: 16 }}>
|
||||
<Breadcrumb.Item>
|
||||
<Link to="/entgra">
|
||||
<Icon type="home" /> Home
|
||||
</Link>
|
||||
</Breadcrumb.Item>
|
||||
<Breadcrumb.Item>Report</Breadcrumb.Item>
|
||||
</Breadcrumb>
|
||||
<div className="wrap" style={{ marginBottom: '10px' }}>
|
||||
<h3>Policy Report</h3>
|
||||
|
||||
<Radio.Group
|
||||
onChange={this.handleModeChange}
|
||||
defaultValue={true}
|
||||
value={isCompliant}
|
||||
style={{ marginBottom: 8, marginRight: 10 }}
|
||||
>
|
||||
<Radio.Button value={true}>Policy Compliant Devices</Radio.Button>
|
||||
<Radio.Button value={false}>
|
||||
Policy Non-Compliant Devices
|
||||
</Radio.Button>
|
||||
</Radio.Group>
|
||||
|
||||
<Radio.Group
|
||||
onChange={this.handleDurationModeChange}
|
||||
defaultValue={'weekly'}
|
||||
value={durationMode}
|
||||
style={{ marginBottom: 8, marginRight: 5 }}
|
||||
>
|
||||
<Radio.Button value={'daily'}>Today</Radio.Button>
|
||||
<Radio.Button value={'weekly'}>Last Week</Radio.Button>
|
||||
<Radio.Button value={'monthly'}>Last Month</Radio.Button>
|
||||
</Radio.Group>
|
||||
<Popover
|
||||
trigger="hover"
|
||||
content={
|
||||
<div>
|
||||
<DateRangePicker
|
||||
updateDurationValue={this.updateDurationValue}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
visible={this.state.visible}
|
||||
onVisibleChange={this.handlePopoverVisibleChange}
|
||||
>
|
||||
<Button style={{ marginRight: 10 }}>Custom Date</Button>
|
||||
</Popover>
|
||||
|
||||
<SelectPolicyDropDown getPolicyId={this.getPolicyId} />
|
||||
|
||||
<div style={{ backgroundColor: '#ffffff', borderRadius: 5 }}>
|
||||
<PolicyDevicesTable
|
||||
policyReportData={policyData}
|
||||
isCompliant={isCompliant}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</PageHeader>
|
||||
<div
|
||||
style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}
|
||||
></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withConfigContext(PolicyReport);
|
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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 { Button, message, Modal, notification, List, Typography } from 'antd';
|
||||
import axios from 'axios';
|
||||
import { withConfigContext } from '../../../context/ConfigContext';
|
||||
|
||||
class FeatureListModal extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
modalVisible: false,
|
||||
name: '',
|
||||
description: '',
|
||||
features: [],
|
||||
};
|
||||
}
|
||||
|
||||
fetchViolatedFeatures = id => {
|
||||
const config = this.props.context;
|
||||
|
||||
axios
|
||||
.get(
|
||||
window.location.origin +
|
||||
config.serverConfig.invoker.uri +
|
||||
config.serverConfig.invoker.deviceMgt +
|
||||
'/devices/' +
|
||||
id +
|
||||
'/features',
|
||||
)
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
this.setState({
|
||||
features: JSON.parse(res.data.data),
|
||||
});
|
||||
}
|
||||
})
|
||||
.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 non compliance feature list.',
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
openModal = () => {
|
||||
this.fetchViolatedFeatures(this.props.id);
|
||||
this.setState({
|
||||
modalVisible: true,
|
||||
});
|
||||
};
|
||||
|
||||
handleOk = e => {
|
||||
this.setState({
|
||||
modalVisible: false,
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const { features, modalVisible } = this.state;
|
||||
|
||||
let featureList = features.map(data => (
|
||||
<List.Item key={data.featureCodes}>
|
||||
<Typography.Text key={data.featureCodes} mark>
|
||||
{data.featureCode}
|
||||
</Typography.Text>
|
||||
</List.Item>
|
||||
));
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<Button
|
||||
type="primary"
|
||||
size={'small'}
|
||||
icon="book"
|
||||
onClick={this.openModal}
|
||||
>
|
||||
Violated Features
|
||||
</Button>
|
||||
</div>
|
||||
<div>
|
||||
<Modal
|
||||
title="VIOLATED FEATURES"
|
||||
width="40%"
|
||||
visible={modalVisible}
|
||||
onOk={this.handleOk}
|
||||
footer={[
|
||||
<Button key="submit" type="primary" onClick={this.handleOk}>
|
||||
OK
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<List size="large" bordered>
|
||||
{featureList}
|
||||
</List>
|
||||
</Modal>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withConfigContext(FeatureListModal);
|
@ -0,0 +1,352 @@
|
||||
/*
|
||||
* 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 { Button, Icon, Table, Tooltip } from 'antd';
|
||||
import TimeAgo from 'javascript-time-ago';
|
||||
import moment from 'moment';
|
||||
// Load locale-specific relative date/time formatting rules.
|
||||
import en from 'javascript-time-ago/locale/en';
|
||||
import { withConfigContext } from '../../../context/ConfigContext';
|
||||
import FeatureListModal from './FeatureListModal';
|
||||
import { handleApiError } from '../../../js/Utils';
|
||||
|
||||
let config = null;
|
||||
|
||||
// Table columns for non compliant devices
|
||||
const columnsNonCompliant = [
|
||||
{
|
||||
title: 'Device',
|
||||
dataIndex: 'deviceName',
|
||||
width: 100,
|
||||
sorter: (a, b) => a.deviceName.localeCompare(b.deviceName),
|
||||
},
|
||||
{
|
||||
title: 'Type',
|
||||
dataIndex: 'deviceType',
|
||||
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>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Owner',
|
||||
dataIndex: 'owner',
|
||||
key: 'owner',
|
||||
},
|
||||
{
|
||||
title: 'Policy',
|
||||
dataIndex: 'policyName',
|
||||
key: 'policy',
|
||||
sorter: (a, b) => a.policyName.localeCompare(b.policyName),
|
||||
},
|
||||
{
|
||||
title: 'Last Failed Time',
|
||||
dataIndex: 'lastFailedTime',
|
||||
key: 'lastFailedTime',
|
||||
render: data => {
|
||||
if (data) {
|
||||
return (
|
||||
<Tooltip title={new Date(data).toString()}>
|
||||
{moment(data).fromNow()}
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
return 'Not available';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Last Success Time',
|
||||
dataIndex: 'lastSucceededTime',
|
||||
key: 'lastSucceededTime',
|
||||
render: data => {
|
||||
if (data) {
|
||||
return (
|
||||
<Tooltip title={new Date(data).toString()}>
|
||||
{moment(data).fromNow()}
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
return 'Not available';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Attempts',
|
||||
dataIndex: 'attempts',
|
||||
key: 'attempts',
|
||||
},
|
||||
{
|
||||
title: 'Violated Features',
|
||||
dataIndex: 'id',
|
||||
key: 'violated_features',
|
||||
// eslint-disable-next-line react/display-name
|
||||
render: id => <FeatureListModal id={id} />,
|
||||
},
|
||||
{
|
||||
title: 'Device Details',
|
||||
dataIndex: 'id',
|
||||
key: 'device_details',
|
||||
// eslint-disable-next-line react/display-name
|
||||
render: id => (
|
||||
<Button type="primary" size={'small'} icon="book">
|
||||
Device Details
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
// Table columns for compliant devices
|
||||
const columnsCompliant = [
|
||||
{
|
||||
title: 'Device',
|
||||
dataIndex: 'deviceName',
|
||||
width: 100,
|
||||
sorter: (a, b) => a.deviceName.localeCompare(b.deviceName),
|
||||
},
|
||||
{
|
||||
title: 'Type',
|
||||
dataIndex: 'deviceType',
|
||||
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>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Owner',
|
||||
dataIndex: 'owner',
|
||||
key: 'owner',
|
||||
},
|
||||
{
|
||||
title: 'Policy',
|
||||
dataIndex: 'policyName',
|
||||
key: 'policy',
|
||||
sorter: (a, b) => a.policyName.localeCompare(b.policyName),
|
||||
},
|
||||
{
|
||||
title: 'Last Success Time',
|
||||
dataIndex: 'lastSucceededTime',
|
||||
key: 'lastSucceededTime',
|
||||
render: data => {
|
||||
if (data) {
|
||||
return (
|
||||
<Tooltip title={new Date(data).toString()}>
|
||||
{moment(data).fromNow()}
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
return 'Not available';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Attempts',
|
||||
dataIndex: 'attempts',
|
||||
key: 'attempts',
|
||||
},
|
||||
{
|
||||
title: 'Device Details',
|
||||
dataIndex: 'id',
|
||||
key: 'device_details',
|
||||
// eslint-disable-next-line react/display-name
|
||||
render: id => (
|
||||
<Button type="primary" size={'small'} icon="book">
|
||||
Device Details
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
class PolicyDevicesTable 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() {
|
||||
this.fetchData();
|
||||
}
|
||||
|
||||
// Rerender component when parameters change
|
||||
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||
if (
|
||||
prevProps.isCompliant !== this.props.isCompliant ||
|
||||
prevProps.policyReportData !== this.props.policyReportData
|
||||
) {
|
||||
this.fetchData();
|
||||
}
|
||||
}
|
||||
|
||||
// fetch data from api
|
||||
fetchData = (params = {}) => {
|
||||
// const policyReportData = this.props;
|
||||
this.setState({ loading: true });
|
||||
// get current page
|
||||
const currentPage = params.hasOwnProperty('page') ? params.page : 1;
|
||||
|
||||
let extraParams;
|
||||
|
||||
if (this.props.policyReportData.policy) {
|
||||
extraParams = {
|
||||
policy: this.props.policyReportData.policy,
|
||||
from: this.props.policyReportData.from,
|
||||
to: this.props.policyReportData.to,
|
||||
offset: 10 * (currentPage - 1), // calculate the offset
|
||||
limit: 10,
|
||||
};
|
||||
} else {
|
||||
extraParams = {
|
||||
from: this.props.policyReportData.from,
|
||||
to: this.props.policyReportData.to,
|
||||
offset: 10 * (currentPage - 1), // calculate the offset
|
||||
limit: 10,
|
||||
};
|
||||
}
|
||||
|
||||
const encodedExtraParams = Object.keys(extraParams)
|
||||
.map(key => key + '=' + extraParams[key])
|
||||
.join('&');
|
||||
|
||||
let apiUrl;
|
||||
|
||||
if (this.props.isCompliant) {
|
||||
apiUrl =
|
||||
window.location.origin +
|
||||
config.serverConfig.invoker.uri +
|
||||
config.serverConfig.invoker.deviceMgt +
|
||||
'/devices/compliance/true?' +
|
||||
encodedExtraParams;
|
||||
} else {
|
||||
apiUrl =
|
||||
window.location.origin +
|
||||
config.serverConfig.invoker.uri +
|
||||
config.serverConfig.invoker.deviceMgt +
|
||||
'/devices/compliance/false?' +
|
||||
encodedExtraParams;
|
||||
}
|
||||
|
||||
// send request to the invoker
|
||||
axios
|
||||
.get(apiUrl)
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
const pagination = { ...this.state.pagination };
|
||||
this.setState({
|
||||
loading: false,
|
||||
data: res.data.data,
|
||||
pagination,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
handleApiError(error, '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.fetchData({
|
||||
results: pagination.pageSize,
|
||||
page: pagination.current,
|
||||
sortField: sorter.field,
|
||||
sortOrder: sorter.order,
|
||||
...filters,
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
let { data, pagination, loading } = this.state;
|
||||
const { isCompliant } = this.props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Table
|
||||
columns={isCompliant ? columnsCompliant : columnsNonCompliant}
|
||||
rowKey={record => record.id}
|
||||
dataSource={data.complianceData}
|
||||
pagination={{
|
||||
...pagination,
|
||||
size: 'small',
|
||||
// position: "top",
|
||||
total: data.count,
|
||||
showTotal: (total, range) =>
|
||||
`showing ${range[0]}-${range[1]} of ${total} devices`,
|
||||
// showQuickJumper: true
|
||||
}}
|
||||
loading={loading}
|
||||
onChange={this.handleTableChange}
|
||||
rowSelection={this.rowSelection}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withConfigContext(PolicyDevicesTable);
|
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 { Select, message, notification } from 'antd';
|
||||
|
||||
import { withConfigContext } from '../../../context/ConfigContext';
|
||||
import axios from 'axios';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
class SelectPolicyDropDown extends React.Component {
|
||||
routes;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.routes = props.routes;
|
||||
this.state = {
|
||||
isOpen: false,
|
||||
currentPage: 1,
|
||||
data: [],
|
||||
pagination: {},
|
||||
loading: false,
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.fetchPolicies();
|
||||
}
|
||||
|
||||
// fetch data from api
|
||||
fetchPolicies = (params = {}) => {
|
||||
const config = this.props.context;
|
||||
this.setState({ loading: true });
|
||||
|
||||
// send request to the invokerss
|
||||
axios
|
||||
.get(
|
||||
window.location.origin +
|
||||
config.serverConfig.invoker.uri +
|
||||
config.serverConfig.invoker.deviceMgt +
|
||||
'/policies',
|
||||
)
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
this.setState({
|
||||
loading: false,
|
||||
data: JSON.parse(res.data.data),
|
||||
});
|
||||
}
|
||||
})
|
||||
.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 policies.',
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({ loading: false });
|
||||
});
|
||||
};
|
||||
|
||||
handleChange = value => {
|
||||
this.props.getPolicyId(value);
|
||||
};
|
||||
|
||||
render() {
|
||||
let item;
|
||||
if (this.state.data) {
|
||||
item = this.state.data.map(data => (
|
||||
<Select.Option value={data.id} key={data.id}>
|
||||
{data.profile.profileName}
|
||||
</Select.Option>
|
||||
));
|
||||
}
|
||||
|
||||
return (
|
||||
<Select
|
||||
defaultValue="all"
|
||||
style={{ width: 200 }}
|
||||
onChange={this.handleChange}
|
||||
>
|
||||
<Option value="all">All</Option>
|
||||
{item}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withConfigContext(SelectPolicyDropDown);
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 { message, notification } from 'antd';
|
||||
|
||||
export const handleApiError = (
|
||||
error,
|
||||
errorMessage,
|
||||
isForbiddenMessageSilent = false,
|
||||
) => {
|
||||
if (error.hasOwnProperty('response') && error.response.status === 401) {
|
||||
message.error('You are not logged in');
|
||||
const redirectUrl = encodeURI(window.location.href);
|
||||
window.location.href =
|
||||
window.location.origin + `/entgra/login?redirect=${redirectUrl}`;
|
||||
// silence 403 forbidden message
|
||||
} else if (
|
||||
!(
|
||||
isForbiddenMessageSilent &&
|
||||
error.hasOwnProperty('response') &&
|
||||
error.response.status === 403
|
||||
)
|
||||
) {
|
||||
notification.error({
|
||||
message: 'There was a problem',
|
||||
duration: 10,
|
||||
description: errorMessage,
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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 { Icon, Col, Row, Card } from 'antd';
|
||||
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
class PolicyReportHome extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<div style={{ borderRadius: 5 }}>
|
||||
<Row gutter={16}>
|
||||
<Col span={8}>
|
||||
<Link
|
||||
to={{
|
||||
// Path to respective report page
|
||||
pathname: '/entgra/reports/policy/compliance',
|
||||
data: {
|
||||
name: 'all_policy_compliance_report',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Card
|
||||
bordered={true}
|
||||
hoverable={true}
|
||||
style={{ borderRadius: 10, marginBottom: 16 }}
|
||||
>
|
||||
<div align="center">
|
||||
<Icon
|
||||
type="desktop"
|
||||
style={{ fontSize: '25px', color: '#08c' }}
|
||||
/>
|
||||
<h2>
|
||||
<b>Policy Compliance Report</b>
|
||||
</h2>
|
||||
<p>Policy compliance details of all enrolled devices</p>
|
||||
</div>
|
||||
</Card>
|
||||
</Link>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Link
|
||||
to={{
|
||||
// Path to respective report page
|
||||
pathname: '/entgra/reports/enrollments',
|
||||
data: {
|
||||
name: 'enrollments_vs_unenrollments_report',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Card
|
||||
bordered={true}
|
||||
hoverable={true}
|
||||
style={{ borderRadius: 10, marginBottom: 16 }}
|
||||
>
|
||||
<div align="center">
|
||||
<Icon
|
||||
type="desktop"
|
||||
style={{ fontSize: '25px', color: '#08c' }}
|
||||
/>
|
||||
<h2>
|
||||
<b>Enrollments vs Unenrollments</b>
|
||||
</h2>
|
||||
<p>Details on device enrollments vs unenrollments</p>
|
||||
</div>
|
||||
</Card>
|
||||
</Link>
|
||||
</Col>
|
||||
|
||||
<Col span={8}>
|
||||
<Link
|
||||
to={{
|
||||
// Path to respective report page
|
||||
pathname: '/entgra/reports/device-status',
|
||||
data: {
|
||||
name: 'enrollment_status_report',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Card
|
||||
bordered={true}
|
||||
hoverable={true}
|
||||
style={{ borderRadius: 10, marginBottom: 16 }}
|
||||
>
|
||||
<div align="center">
|
||||
<Icon
|
||||
type="desktop"
|
||||
style={{ fontSize: '25px', color: '#08c' }}
|
||||
/>
|
||||
<h2>
|
||||
<b>Device Status Report</b>
|
||||
</h2>
|
||||
<p>Report based on device status</p>
|
||||
</div>
|
||||
</Card>
|
||||
</Link>
|
||||
</Col>
|
||||
|
||||
<Col span={8}>
|
||||
<Link
|
||||
to={{
|
||||
// Path to respective report page
|
||||
pathname: '/entgra/reports/enrollment-type',
|
||||
data: {
|
||||
name: 'enrollemt_type_report',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Card
|
||||
bordered={true}
|
||||
hoverable={true}
|
||||
style={{ borderRadius: 10, marginBottom: 16 }}
|
||||
>
|
||||
<div align="center">
|
||||
<Icon
|
||||
type="desktop"
|
||||
style={{ fontSize: '25px', color: '#08c' }}
|
||||
/>
|
||||
<h2>
|
||||
<b>Device Type Report</b>
|
||||
</h2>
|
||||
<p>Report for all device types</p>
|
||||
</div>
|
||||
</Card>
|
||||
</Link>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default PolicyReportHome;
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. 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.policy.mgt.monitor.ComplianceData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ComplianceDeviceList extends BasePaginatedResult{
|
||||
private List<ComplianceData> complianceData = new ArrayList<>();
|
||||
|
||||
@ApiModelProperty(value = "List of devices returned")
|
||||
@JsonProperty("devices")
|
||||
public List<ComplianceData> getList() {
|
||||
return complianceData;
|
||||
}
|
||||
|
||||
public void setList(List<ComplianceData> complianceData) {
|
||||
this.complianceData = complianceData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{\n");
|
||||
sb.append(" count: ").append(getCount()).append(",\n");
|
||||
sb.append(" devices: [").append(complianceData).append("\n");
|
||||
sb.append("]}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
public class Count {
|
||||
private String date;
|
||||
private int count;
|
||||
|
||||
public Count(String date, int count) {
|
||||
this.date = date;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
/*
|
||||
* 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.common.policy.mgt.monitor;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public class ComplianceData {
|
||||
|
||||
private int id;
|
||||
private int deviceId;
|
||||
private String deviceName;
|
||||
private String deviceType;
|
||||
private String owner;
|
||||
private int enrolmentId;
|
||||
private int policyId;
|
||||
private String policyName;
|
||||
List<ComplianceFeature> complianceFeatures;
|
||||
private boolean status;
|
||||
private Timestamp lastRequestedTime;
|
||||
private Timestamp lastSucceededTime;
|
||||
private Timestamp lastFailedTime;
|
||||
private int attempts;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* This parameter is to inform the policy core, weather related device type plugins does need the full policy or
|
||||
* the part which is none compliance.
|
||||
*/
|
||||
private boolean completePolicy;
|
||||
private Policy policy;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getEnrolmentId() {
|
||||
return enrolmentId;
|
||||
}
|
||||
|
||||
public void setEnrolmentId(int enrolmentId) {
|
||||
this.enrolmentId = enrolmentId;
|
||||
}
|
||||
|
||||
public Timestamp getLastRequestedTime() {
|
||||
return lastRequestedTime;
|
||||
}
|
||||
|
||||
public void setLastRequestedTime(Timestamp lastRequestedTime) {
|
||||
this.lastRequestedTime = lastRequestedTime;
|
||||
}
|
||||
|
||||
public Timestamp getLastSucceededTime() {
|
||||
return lastSucceededTime;
|
||||
}
|
||||
|
||||
public void setLastSucceededTime(Timestamp lastSucceededTime) {
|
||||
this.lastSucceededTime = lastSucceededTime;
|
||||
}
|
||||
|
||||
public Timestamp getLastFailedTime() {
|
||||
return lastFailedTime;
|
||||
}
|
||||
|
||||
public void setLastFailedTime(Timestamp lastFailedTime) {
|
||||
this.lastFailedTime = lastFailedTime;
|
||||
}
|
||||
|
||||
public int getAttempts() {
|
||||
return attempts;
|
||||
}
|
||||
|
||||
public void setAttempts(int attempts) {
|
||||
this.attempts = attempts;
|
||||
}
|
||||
|
||||
public int getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(int deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public int getPolicyId() {
|
||||
return policyId;
|
||||
}
|
||||
|
||||
public void setPolicyId(int policyId) {
|
||||
this.policyId = policyId;
|
||||
}
|
||||
|
||||
public List<ComplianceFeature> getComplianceFeatures() {
|
||||
return complianceFeatures;
|
||||
}
|
||||
|
||||
public void setComplianceFeatures(List<ComplianceFeature> complianceFeatures) {
|
||||
this.complianceFeatures = complianceFeatures;
|
||||
}
|
||||
|
||||
public boolean isStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boolean isCompletePolicy() {
|
||||
return completePolicy;
|
||||
}
|
||||
|
||||
public void setCompletePolicy(boolean completePolicy) {
|
||||
this.completePolicy = completePolicy;
|
||||
}
|
||||
|
||||
public Policy getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
public void setPolicy(Policy policy) {
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
public String getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
public void setDeviceName(String deviceName) {
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getPolicyName() {
|
||||
return policyName;
|
||||
}
|
||||
|
||||
public void setPolicyName(String policyName) {
|
||||
this.policyName = policyName;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue