2021-08-17 13:01:13 +05:00
|
|
|
|
import {Table, Select, DatePicker, Input} from 'antd';
|
2021-05-27 12:53:42 +05:00
|
|
|
|
import {useState, useEffect} from 'react'
|
2021-08-13 10:30:26 +05:00
|
|
|
|
import moment from 'moment'
|
|
|
|
|
|
|
|
|
|
import {MessageService} from '../services/api'
|
2021-06-02 11:38:27 +05:00
|
|
|
|
import LoaderPortal from '../components/LoaderPortal'
|
2021-06-01 12:20:29 +05:00
|
|
|
|
import notify from '../components/notify'
|
2021-08-13 10:30:26 +05:00
|
|
|
|
import '../styles/message.css'
|
2021-05-19 16:05:01 +05:00
|
|
|
|
|
2021-05-28 12:04:38 +05:00
|
|
|
|
const {Option} = Select
|
2021-06-01 12:20:29 +05:00
|
|
|
|
const pageSize = 26
|
|
|
|
|
const {RangePicker} = DatePicker;
|
2021-08-09 16:27:13 +05:00
|
|
|
|
const { Search } = Input
|
2021-05-28 12:04:38 +05:00
|
|
|
|
|
2021-05-19 16:05:01 +05:00
|
|
|
|
// Словарь категорий для строк таблицы
|
|
|
|
|
const categoryDictionary = {
|
2021-05-27 12:53:42 +05:00
|
|
|
|
1: {title: 'Авария'},
|
|
|
|
|
2: {title: 'Предупреждение'},
|
|
|
|
|
3: {title: 'Информация'},
|
2021-05-19 16:05:01 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 12:20:29 +05:00
|
|
|
|
const columns = [
|
|
|
|
|
{
|
|
|
|
|
title: 'Дата',
|
|
|
|
|
key: 'date',
|
|
|
|
|
dataIndex: 'date',
|
|
|
|
|
render: (item) => moment(item).format('DD MMM YYYY, HH:MM:ss'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Категория',
|
|
|
|
|
key: 'categoryId',
|
|
|
|
|
dataIndex: 'categoryId',
|
|
|
|
|
render: (_, item) => categoryDictionary[item.categoryId].title,
|
|
|
|
|
style: (_, item) => categoryDictionary[item.categoryId].style,
|
|
|
|
|
ellipsis: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Сообщение',
|
|
|
|
|
key: 'message',
|
|
|
|
|
dataIndex: 'message',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Пользователь',
|
|
|
|
|
key: 'user',
|
|
|
|
|
dataIndex: 'user',
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const filterOptions = [
|
2021-06-24 16:20:48 +05:00
|
|
|
|
{label: 'Важное', value: 1},
|
2021-06-01 12:20:29 +05:00
|
|
|
|
{label: 'Предупреждение', value: 2},
|
|
|
|
|
{label: 'Информация', value: 3},
|
|
|
|
|
]
|
|
|
|
|
|
2021-05-19 16:05:01 +05:00
|
|
|
|
// Данные для таблицы
|
2021-08-13 10:30:26 +05:00
|
|
|
|
export default function Messages({idWell}) {
|
2021-05-19 16:05:01 +05:00
|
|
|
|
const [messages, setMessages] = useState([])
|
2021-06-01 12:20:29 +05:00
|
|
|
|
const [pagination, setPagination] = useState(null)
|
2021-06-01 14:32:36 +05:00
|
|
|
|
const [page, setPage] = useState(1)
|
2021-06-01 12:20:29 +05:00
|
|
|
|
const [range, setRange] = useState([])
|
|
|
|
|
const [categories, setCategories] = useState([])
|
2021-08-09 16:27:13 +05:00
|
|
|
|
const [searchString, setSearchString] = useState('')
|
2021-08-18 13:50:44 +05:00
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
2021-05-28 12:04:38 +05:00
|
|
|
|
|
2021-06-01 12:20:29 +05:00
|
|
|
|
const children = filterOptions.map((line) => <Option key={line.value}>{line.label}</Option>)
|
|
|
|
|
|
|
|
|
|
const onChangeRange = (range) => {
|
|
|
|
|
setRange(range)
|
2021-05-19 16:05:01 +05:00
|
|
|
|
}
|
2021-08-09 16:27:13 +05:00
|
|
|
|
|
|
|
|
|
const onChangeSearchString = (message) => {
|
|
|
|
|
if (message.length < 3) {
|
|
|
|
|
setSearchString('')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
setSearchString(message)
|
|
|
|
|
}
|
2021-08-09 16:49:14 +05:00
|
|
|
|
|
2021-06-02 11:38:27 +05:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
const GetMessages = async () => {
|
2021-08-18 13:50:44 +05:00
|
|
|
|
setShowLoader(true)
|
2021-06-24 15:36:57 +05:00
|
|
|
|
|
2021-06-02 11:38:27 +05:00
|
|
|
|
try {
|
|
|
|
|
let begin = null
|
|
|
|
|
let end = null
|
|
|
|
|
if (range?.length > 1) {
|
|
|
|
|
begin = range[0].toISOString()
|
|
|
|
|
end = range[1].toISOString()
|
2021-06-01 12:20:29 +05:00
|
|
|
|
}
|
2021-08-13 10:30:26 +05:00
|
|
|
|
let paginatedMessages = await MessageService.getMessages(idWell,
|
2021-06-02 11:38:27 +05:00
|
|
|
|
(page - 1) * pageSize,
|
|
|
|
|
pageSize,
|
|
|
|
|
categories,
|
|
|
|
|
begin,
|
2021-08-09 16:27:13 +05:00
|
|
|
|
end,
|
|
|
|
|
searchString)
|
2021-06-24 15:36:57 +05:00
|
|
|
|
if (paginatedMessages === null){
|
2021-08-13 10:30:26 +05:00
|
|
|
|
notify(`Данных по скважине "${idWell}" нет`, 'warning')
|
2021-08-18 13:50:44 +05:00
|
|
|
|
setShowLoader(false)
|
2021-06-24 15:36:57 +05:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 11:38:27 +05:00
|
|
|
|
setMessages(paginatedMessages.items.map(m => {
|
|
|
|
|
return {
|
|
|
|
|
key: m.id,
|
|
|
|
|
categoryids: categoryDictionary[m.categoryId],
|
|
|
|
|
begin: m.date,
|
|
|
|
|
...m
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
setPagination({
|
|
|
|
|
total: paginatedMessages.count,
|
|
|
|
|
current: Math.floor(paginatedMessages.skip / pageSize),
|
|
|
|
|
})
|
2021-06-24 15:36:57 +05:00
|
|
|
|
|
2021-06-02 11:38:27 +05:00
|
|
|
|
} catch (ex) {
|
|
|
|
|
console.log(ex)
|
2021-08-13 10:30:26 +05:00
|
|
|
|
notify(`Не удалось загрузить сообщения по скважине "${idWell}"`, 'error')
|
2021-06-02 11:38:27 +05:00
|
|
|
|
}
|
2021-08-18 13:50:44 +05:00
|
|
|
|
setShowLoader(false)
|
2021-05-19 16:05:01 +05:00
|
|
|
|
}
|
2021-06-01 12:20:29 +05:00
|
|
|
|
GetMessages()
|
2021-08-13 10:30:26 +05:00
|
|
|
|
}, [idWell, page, categories, range, searchString])
|
2021-05-31 09:34:22 +05:00
|
|
|
|
|
2021-05-19 16:05:01 +05:00
|
|
|
|
return (
|
2021-05-27 12:53:42 +05:00
|
|
|
|
<>
|
2021-06-01 14:32:36 +05:00
|
|
|
|
<div className='filter-group'>
|
2021-07-22 14:53:30 +05:00
|
|
|
|
<h3 className='filter-group-heading'>Фильтр сообщений</h3>
|
2021-06-01 14:32:36 +05:00
|
|
|
|
<Select
|
|
|
|
|
mode="multiple"
|
|
|
|
|
allowClear
|
|
|
|
|
placeholder="Фильтр сообщений"
|
|
|
|
|
className="filter-selector"
|
|
|
|
|
value={categories}
|
|
|
|
|
onChange={setCategories}>
|
|
|
|
|
{children}
|
|
|
|
|
</Select>
|
2021-08-17 13:01:13 +05:00
|
|
|
|
<RangePicker
|
|
|
|
|
showTime
|
|
|
|
|
onChange={onChangeRange}
|
|
|
|
|
/>
|
2021-08-09 16:27:13 +05:00
|
|
|
|
<Search
|
|
|
|
|
className="filter-selector"
|
|
|
|
|
placeholder="Фильтр сообщений по тексту"
|
|
|
|
|
onSearch={onChangeSearchString}
|
|
|
|
|
/>
|
2021-06-01 14:32:36 +05:00
|
|
|
|
</div>
|
2021-08-18 13:50:44 +05:00
|
|
|
|
<LoaderPortal show={showLoader}>
|
2021-06-02 11:38:27 +05:00
|
|
|
|
<Table
|
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={messages}
|
|
|
|
|
rowClassName={(record) => `event_message_${record.categoryId} event_message`}
|
|
|
|
|
size={'small'}
|
|
|
|
|
pagination={{
|
|
|
|
|
pageSize: pageSize,
|
|
|
|
|
showSizeChanger: false,
|
|
|
|
|
total: pagination?.total,
|
|
|
|
|
current: page,
|
|
|
|
|
onChange: (page) => setPage(page)
|
|
|
|
|
}}
|
|
|
|
|
rowKey={(record) => record.id}
|
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>
|
2021-05-27 12:53:42 +05:00
|
|
|
|
</>
|
2021-05-19 16:05:01 +05:00
|
|
|
|
)
|
2021-05-28 12:04:38 +05:00
|
|
|
|
}
|