2021-07-28 17:29:20 +05:00
|
|
|
|
import {useState, useEffect} from 'react'
|
|
|
|
|
import {Table} from "antd";
|
2021-08-12 17:47:16 +05:00
|
|
|
|
import moment from 'moment'
|
|
|
|
|
|
|
|
|
|
import LoaderPortal from '../../components/LoaderPortal'
|
2021-08-17 17:42:42 +05:00
|
|
|
|
import {invokeWebApiWrapperAsync} from '../../components/factory'
|
2021-08-12 17:47:16 +05:00
|
|
|
|
|
|
|
|
|
import {Subscribe} from '../../services/signalr'
|
|
|
|
|
import {MessageService} from '../../services/api'
|
|
|
|
|
import '../../styles/message.css'
|
2021-07-28 17:29:20 +05:00
|
|
|
|
|
|
|
|
|
// Словарь категорий для строк таблицы
|
|
|
|
|
const categoryDictionary = {
|
|
|
|
|
1: {title: 'Важное'},
|
|
|
|
|
2: {title: 'Предупреждение'},
|
|
|
|
|
3: {title: 'Информация'},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Конфигурация таблицы
|
|
|
|
|
const columns = [
|
|
|
|
|
{
|
|
|
|
|
title: 'Дата',
|
|
|
|
|
dataIndex: 'date',
|
|
|
|
|
render: (item) => moment(item).format('DD MMM YYYY, HH:MM:ss'),
|
|
|
|
|
sorter: (a, b) => new Date(b.date) - new Date(a.date),
|
|
|
|
|
sortDirections: ['descend', 'ascend'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Категория',
|
|
|
|
|
dataIndex: 'categoryId',
|
|
|
|
|
render: (_, item) => categoryDictionary[item.categoryId].title,
|
|
|
|
|
style: (_, item) => categoryDictionary[item.categoryId].style,
|
|
|
|
|
sorter: (a, b) => a.categoryId - b.categoryId,
|
|
|
|
|
sortDirections: ['descend', 'ascend'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Сообщение',
|
|
|
|
|
dataIndex: 'message',
|
|
|
|
|
onFilter: (value, record) => record.name.indexOf(value) === 0,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Пользователь',
|
|
|
|
|
dataIndex: 'user',
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export default function ActiveMessagesOnline({idWell}) {
|
|
|
|
|
const [messages, setMessages] = useState([])
|
|
|
|
|
const [loader, setLoader] = useState(false)
|
|
|
|
|
|
|
|
|
|
const handleReceiveMessages = (messages) => {
|
|
|
|
|
if (messages) {
|
|
|
|
|
setMessages(messages.items.splice(0, 4))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 14:46:22 +05:00
|
|
|
|
useEffect(() => {
|
2021-08-17 17:42:42 +05:00
|
|
|
|
invokeWebApiWrapperAsync(
|
2021-08-13 14:46:22 +05:00
|
|
|
|
async () => {
|
2021-08-12 17:47:16 +05:00
|
|
|
|
const messages = await MessageService.getMessages(idWell, 0, 4)
|
2021-07-29 16:24:01 +05:00
|
|
|
|
handleReceiveMessages(messages)
|
2021-08-13 14:46:22 +05:00
|
|
|
|
},
|
|
|
|
|
setLoader,
|
|
|
|
|
`Не удалось загрузить сообщения по скважине "${idWell}"`,
|
|
|
|
|
)
|
|
|
|
|
return Subscribe('hubs/telemetry','ReceiveMessages', `well_${idWell}`, handleReceiveMessages)
|
2021-07-28 17:29:20 +05:00
|
|
|
|
}, [idWell])
|
|
|
|
|
|
|
|
|
|
return (<LoaderPortal show={loader}>
|
|
|
|
|
<Table
|
|
|
|
|
showHeader={false}
|
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={messages}
|
|
|
|
|
rowClassName={(record) => `event_message_${record.categoryId} event_message`}
|
|
|
|
|
className={'message_table'}
|
|
|
|
|
size={'small'}
|
|
|
|
|
pagination={false}
|
|
|
|
|
rowKey={(record) => record.id}
|
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>)
|
|
|
|
|
}
|