2022-03-03 19:34:22 +05:00
|
|
|
|
import { memo, useCallback, useEffect, useState } from 'react'
|
2021-12-29 12:00:02 +05:00
|
|
|
|
|
2021-12-21 15:41:48 +05:00
|
|
|
|
import {
|
|
|
|
|
EditableTable,
|
|
|
|
|
makeColumn,
|
|
|
|
|
makeSelectColumn,
|
|
|
|
|
makeActionHandler,
|
2022-01-13 20:32:46 +05:00
|
|
|
|
makeStringSorter,
|
2022-02-28 12:51:45 +05:00
|
|
|
|
defaultPagination,
|
|
|
|
|
makeTimezoneColumn
|
2022-02-07 14:58:38 +05:00
|
|
|
|
} from '@components/Table'
|
|
|
|
|
import LoaderPortal from '@components/LoaderPortal'
|
|
|
|
|
import { invokeWebApiWrapperAsync } from '@components/factory'
|
|
|
|
|
import { AdminClusterService, AdminDepositService } from '@api'
|
|
|
|
|
import { arrayOrDefault } from '@utils'
|
|
|
|
|
import { min1 } from '@utils/validationRules'
|
|
|
|
|
import { hasPermission } from '@utils/permissions'
|
2021-12-29 12:00:02 +05:00
|
|
|
|
|
|
|
|
|
import { coordsFixed } from './DepositController'
|
2021-12-02 15:21:10 +05:00
|
|
|
|
|
2022-02-10 15:49:39 +05:00
|
|
|
|
export const ClusterController = memo(() => {
|
2021-12-02 15:21:10 +05:00
|
|
|
|
const [deposits, setDeposits] = useState([])
|
|
|
|
|
const [clusters, setClusters] = useState([])
|
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
|
|
|
|
|
|
|
|
|
const clusterColumns = [
|
2021-12-21 15:41:48 +05:00
|
|
|
|
makeSelectColumn('Месторождение', 'idDeposit', deposits, '--', {
|
|
|
|
|
width: 200,
|
|
|
|
|
editable: true,
|
|
|
|
|
sorter: makeStringSorter('idDeposit')
|
|
|
|
|
}),
|
|
|
|
|
makeColumn('Название', 'caption', {
|
|
|
|
|
width: 200,
|
|
|
|
|
editable: true,
|
2021-12-29 12:00:02 +05:00
|
|
|
|
sorter: makeStringSorter('caption'),
|
2021-12-30 10:25:42 +05:00
|
|
|
|
formItemRules: min1,
|
2021-12-21 15:41:48 +05:00
|
|
|
|
}),
|
2021-12-29 12:00:02 +05:00
|
|
|
|
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFixed }),
|
|
|
|
|
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFixed }),
|
2022-02-28 12:51:45 +05:00
|
|
|
|
makeTimezoneColumn('Зона', 'timezone', null, true, { width: 150 }),
|
2021-12-02 15:21:10 +05:00
|
|
|
|
]
|
|
|
|
|
|
2022-03-03 19:34:22 +05:00
|
|
|
|
const updateTable = useCallback(() => invokeWebApiWrapperAsync(
|
2021-12-02 15:21:10 +05:00
|
|
|
|
async () => {
|
2021-12-06 14:10:42 +05:00
|
|
|
|
const clusters = await AdminClusterService.getAll()
|
2021-12-22 12:45:30 +05:00
|
|
|
|
setClusters(arrayOrDefault(clusters))
|
2021-12-02 15:21:10 +05:00
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
2022-02-07 17:44:46 +05:00
|
|
|
|
`Не удалось загрузить список кустов`,
|
|
|
|
|
'Получение списка кустов'
|
2022-03-03 19:34:22 +05:00
|
|
|
|
), [])
|
2021-12-02 15:21:10 +05:00
|
|
|
|
|
|
|
|
|
useEffect(() => invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
2021-12-22 12:45:30 +05:00
|
|
|
|
let deposits = arrayOrDefault(await AdminDepositService.getAll())
|
|
|
|
|
deposits = deposits.map((deposit) => ({ value: deposit.id, label: deposit.caption }))
|
|
|
|
|
setDeposits(deposits)
|
2021-12-02 15:21:10 +05:00
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
2022-02-07 17:44:46 +05:00
|
|
|
|
`Не удалось загрузить список месторождений`,
|
|
|
|
|
'Получение списка месторождений'
|
2021-12-02 15:21:10 +05:00
|
|
|
|
), [])
|
|
|
|
|
|
2022-03-03 19:34:22 +05:00
|
|
|
|
useEffect(updateTable, [updateTable])
|
2021-12-02 15:21:10 +05:00
|
|
|
|
|
2021-12-07 19:36:04 +05:00
|
|
|
|
const handlerProps = {
|
|
|
|
|
service: AdminClusterService,
|
|
|
|
|
setLoader: setShowLoader,
|
|
|
|
|
errorMsg: `Не удалось выполнить операцию`,
|
|
|
|
|
onComplete: updateTable,
|
2021-12-02 15:21:10 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<LoaderPortal show={showLoader}>
|
|
|
|
|
<EditableTable
|
|
|
|
|
size={'small'}
|
|
|
|
|
bordered
|
|
|
|
|
dataSource={clusters}
|
2022-01-13 20:32:46 +05:00
|
|
|
|
columns={clusterColumns}
|
|
|
|
|
pagination={defaultPagination}
|
2022-02-07 17:44:46 +05:00
|
|
|
|
onRowAdd={hasPermission('AdminCluster.edit') && makeActionHandler('insert', handlerProps, null, 'Добавление куста')}
|
2022-02-07 18:46:54 +05:00
|
|
|
|
onRowEdit={hasPermission('AdminCluster.edit') && makeActionHandler('update', handlerProps, null, 'Редактирование куста')}
|
2022-02-07 17:44:46 +05:00
|
|
|
|
onRowDelete={hasPermission('AdminCluster.delete') && makeActionHandler('delete', handlerProps, null, 'Удаление куста')}
|
2021-12-02 15:21:10 +05:00
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
2022-02-10 15:49:39 +05:00
|
|
|
|
})
|
2022-01-12 23:58:14 +05:00
|
|
|
|
|
|
|
|
|
export default ClusterController
|