|
|
@ -18,7 +18,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
import React from "react";
|
|
|
|
import axios from "axios";
|
|
|
|
import axios from "axios";
|
|
|
|
import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider} from "antd";
|
|
|
|
import {Tag, message, notification, Table, Typography, Tooltip, Icon, Divider, Button} from "antd";
|
|
|
|
import TimeAgo from 'javascript-time-ago'
|
|
|
|
import TimeAgo from 'javascript-time-ago'
|
|
|
|
|
|
|
|
|
|
|
|
// Load locale-specific relative date/time formatting rules.
|
|
|
|
// Load locale-specific relative date/time formatting rules.
|
|
|
@ -140,7 +140,8 @@ class DeviceTable extends React.Component {
|
|
|
|
data: [],
|
|
|
|
data: [],
|
|
|
|
pagination: {},
|
|
|
|
pagination: {},
|
|
|
|
loading: false,
|
|
|
|
loading: false,
|
|
|
|
selectedRows: []
|
|
|
|
selectedRows: [],
|
|
|
|
|
|
|
|
deviceIds: []
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -149,7 +150,8 @@ class DeviceTable extends React.Component {
|
|
|
|
// console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
|
|
|
|
// console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
|
|
|
|
this.setState({
|
|
|
|
this.setState({
|
|
|
|
selectedRows: selectedRows
|
|
|
|
selectedRows: selectedRows
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
this.state.deviceIds = selectedRows.map(obj => obj.deviceIdentifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -157,6 +159,17 @@ class DeviceTable extends React.Component {
|
|
|
|
this.fetch();
|
|
|
|
this.fetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
|
|
|
|
|
|
if(prevProps.deleteRequest !== this.props.deleteRequest){
|
|
|
|
|
|
|
|
this.deleteDevice();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(prevProps.deselectRequest !== this.props.deselectRequest){
|
|
|
|
|
|
|
|
this.rowSelection.getCheckboxProps = record => ({
|
|
|
|
|
|
|
|
disabled: record.enrolmentInfo.status !== 'REMOVED' // Column configuration not to be checked
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//fetch data from api
|
|
|
|
//fetch data from api
|
|
|
|
fetch = (params = {}) => {
|
|
|
|
fetch = (params = {}) => {
|
|
|
|
const config = this.props.context;
|
|
|
|
const config = this.props.context;
|
|
|
@ -170,11 +183,13 @@ class DeviceTable extends React.Component {
|
|
|
|
requireDeviceInfo: true,
|
|
|
|
requireDeviceInfo: true,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const encodedExtraParams = Object.keys(extraParams).map(key => key + '=' + extraParams[key]).join('&');
|
|
|
|
const encodedExtraParams = Object.keys(extraParams)
|
|
|
|
|
|
|
|
.map(key => key + '=' + extraParams[key]).join('&');
|
|
|
|
|
|
|
|
|
|
|
|
//send request to the invoker
|
|
|
|
//send request to the invoker
|
|
|
|
axios.get(
|
|
|
|
axios.get(
|
|
|
|
window.location.origin + config.serverConfig.invoker.uri + config.serverConfig.invoker.deviceMgt +
|
|
|
|
window.location.origin + config.serverConfig.invoker.uri +
|
|
|
|
|
|
|
|
config.serverConfig.invoker.deviceMgt +
|
|
|
|
"/devices?" + encodedExtraParams,
|
|
|
|
"/devices?" + encodedExtraParams,
|
|
|
|
).then(res => {
|
|
|
|
).then(res => {
|
|
|
|
if (res.status === 200) {
|
|
|
|
if (res.status === 200) {
|
|
|
@ -204,6 +219,49 @@ class DeviceTable extends React.Component {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deleteDevice = () => {
|
|
|
|
|
|
|
|
const config = this.props.context;
|
|
|
|
|
|
|
|
this.setState({loading: true});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const deviceData = JSON.stringify(this.state.deviceIds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//send request to the invoker
|
|
|
|
|
|
|
|
axios.delete(
|
|
|
|
|
|
|
|
window.location.origin + config.serverConfig.invoker.uri +
|
|
|
|
|
|
|
|
config.serverConfig.invoker.deviceMgt +
|
|
|
|
|
|
|
|
"/admin/devices/permanent-delete",
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
headers:{'Content-Type': 'application/json; charset=utf-8'} ,
|
|
|
|
|
|
|
|
data: deviceData
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
).then(res => {
|
|
|
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
|
|
|
const pagination = {...this.state.pagination};
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
|
|
data: res.data.data.devices,
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
handleTableChange = (pagination, filters, sorter) => {
|
|
|
|
const pager = {...this.state.pagination};
|
|
|
|
const pager = {...this.state.pagination};
|
|
|
|
pager.current = pagination.current;
|
|
|
|
pager.current = pagination.current;
|
|
|
|