* Добавлены сортировки по месторождению и названию на странице admin/cluster

* Добавлены сортировки по названию и типу компании на странице admin/company
* Добавлены сортировки по кусту, названию и типу скважины на странице admin/well
* Временно добавлено исключение для пользователя dev при проверке прав
* Станадртное кол-во отображаемых записей увеличено ан странице admin/user
* Добавлены сортировки по логину, фамилии, имени, отчеству, e-mail, номеру телефона и должности на странице admin/user
This commit is contained in:
Александр Сироткин 2021-12-21 15:41:48 +05:00
parent 0e24780a91
commit 7ffab81c33
5 changed files with 93 additions and 22 deletions

View File

@ -1,7 +1,13 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { invokeWebApiWrapperAsync } from '../../components/factory' import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal' import LoaderPortal from '../../components/LoaderPortal'
import { EditableTable, makeColumn, makeSelectColumn, makeActionHandler } from '../../components/Table' import {
EditableTable,
makeColumn,
makeSelectColumn,
makeActionHandler,
makeStringSorter
} from '../../components/Table'
import { AdminClusterService, AdminDepositService } from '../../services/api' import { AdminClusterService, AdminDepositService } from '../../services/api'
export default function ClusterController() { export default function ClusterController() {
@ -10,8 +16,16 @@ export default function ClusterController() {
const [showLoader, setShowLoader] = useState(false) const [showLoader, setShowLoader] = useState(false)
const clusterColumns = [ const clusterColumns = [
makeSelectColumn('Месторождение', 'idDeposit', deposits, '--', { width: 200, editable: true }), makeSelectColumn('Месторождение', 'idDeposit', deposits, '--', {
makeColumn('Название', 'caption', { width: 200, editable: true }), width: 200,
editable: true,
sorter: makeStringSorter('idDeposit')
}),
makeColumn('Название', 'caption', {
width: 200,
editable: true,
sorter: makeStringSorter('caption')
}),
makeColumn('Широта', 'latitude', { width: 150, editable: true }), makeColumn('Широта', 'latitude', { width: 150, editable: true }),
makeColumn('Долгота', 'longitude', { width: 150, editable: true }) makeColumn('Долгота', 'longitude', { width: 150, editable: true })
] ]

View File

@ -1,12 +1,20 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { invokeWebApiWrapperAsync } from '../../components/factory' import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal' import LoaderPortal from '../../components/LoaderPortal'
import { EditableTable, makeColumn, makeActionHandler } from '../../components/Table' import { EditableTable, makeColumn, makeActionHandler, makeStringSorter } from '../../components/Table'
import { AdminCompanyService } from '../../services/api' import { AdminCompanyService } from '../../services/api'
const companyColumns = [ const companyColumns = [
makeColumn('Название', 'caption', { width: 200, editable: true }), makeColumn('Название', 'caption', {
makeColumn('Тип компании', 'companyTypeCaption', { width: 200, editable: true }) width: 200,
editable: true,
sorter: makeStringSorter('caption')
}),
makeColumn('Тип компании', 'companyTypeCaption', {
width: 200,
editable: true,
sorter: makeStringSorter('companyTypeCaption')
}),
] ]
export default function CompanyController() { export default function CompanyController() {

View File

@ -1,7 +1,7 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { invokeWebApiWrapperAsync } from '../../components/factory' import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal' import LoaderPortal from '../../components/LoaderPortal'
import { EditableTable, makeColumn, makeSelectColumn, makeActionHandler } from '../../components/Table' import { EditableTable, makeColumn, makeSelectColumn, makeActionHandler, makeStringSorter, makeNumericSorter } from '../../components/Table'
import { AdminCompanyService, AdminUserService } from '../../services/api' import { AdminCompanyService, AdminUserService } from '../../services/api'
import { createLoginRules, nameRules, phoneRules, emailRules } from '../../utils/validationRules' import { createLoginRules, nameRules, phoneRules, emailRules } from '../../utils/validationRules'
@ -13,21 +13,42 @@ export default function UserController() {
const userColumns = [ const userColumns = [
makeColumn('Логин', 'login', { makeColumn('Логин', 'login', {
editable: true, editable: true,
formItemRules: [{ required: true }, ...createLoginRules] formItemRules: [{ required: true }, ...createLoginRules],
sorter: makeStringSorter('login'),
}), }),
makeColumn('Фамилия', 'surname', { makeColumn('Фамилия', 'surname', {
editable: true, editable: true,
formItemRules: [{ required: true }, ...nameRules] formItemRules: [{ required: true }, ...nameRules],
sorter: makeStringSorter('surname'),
}),
makeColumn('Имя', 'name', {
editable: true,
formItemRules: nameRules,
sorter: makeStringSorter('name'),
}),
makeColumn('Отчество', 'patronymic', {
editable: true,
formItemRules: nameRules,
sorter: makeStringSorter('patronymic'),
}), }),
makeColumn('Имя', 'name', { editable: true, formItemRules: nameRules }),
makeColumn('Отчество', 'patronymic', { editable: true, formItemRules: nameRules }),
makeColumn('E-mail', 'email', { makeColumn('E-mail', 'email', {
editable: true, editable: true,
formItemRules: [{ required: true }, ...emailRules] formItemRules: [{ required: true }, ...emailRules],
sorter: makeStringSorter('email'),
}),
makeColumn('Номер телефона', 'phone', {
editable: true,
formItemRules: phoneRules,
sorter: makeStringSorter('phone'),
}),
makeColumn('Должность', 'position', {
editable: true,
sorter: makeStringSorter('position'),
}),
makeSelectColumn('Компания', 'idCompany', companies, '--', {
editable: true,
sorter: makeNumericSorter('idCompany'),
}), }),
makeColumn('Номер телефона', 'phone', { editable: true, formItemRules: phoneRules }),
makeColumn('Должность', 'position', { editable: true }),
makeSelectColumn('Компания', 'idCompany', companies, '--', { editable: true })
] ]
const updateTable = () => invokeWebApiWrapperAsync( const updateTable = () => invokeWebApiWrapperAsync(
@ -55,7 +76,7 @@ export default function UserController() {
service: AdminUserService, service: AdminUserService,
setLoader: setShowLoader, setLoader: setShowLoader,
errorMsg: `Не удалось выполнить операцию`, errorMsg: `Не удалось выполнить операцию`,
onComplete: updateTable onComplete: updateTable,
} }
return ( return (
@ -68,6 +89,7 @@ export default function UserController() {
onRowAdd={makeActionHandler('insert', handlerProps)} onRowAdd={makeActionHandler('insert', handlerProps)}
onRowEdit={makeActionHandler('update', handlerProps)} onRowEdit={makeActionHandler('update', handlerProps)}
onRowDelete={makeActionHandler('delete', handlerProps)} onRowDelete={makeActionHandler('delete', handlerProps)}
pagination={{ defaultPageSize: 14 }}
/> />
</LoaderPortal> </LoaderPortal>
) )

View File

@ -3,8 +3,20 @@ import { memo, useEffect, useState } from 'react'
import { TelemetryView } from '../../components/Views' import { TelemetryView } from '../../components/Views'
import LoaderPortal from '../../components/LoaderPortal' import LoaderPortal from '../../components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '../../components/factory' import { invokeWebApiWrapperAsync } from '../../components/factory'
import { EditableTable, makeColumn, makeSelectColumn, makeActionHandler } from '../../components/Table' import { getTelemetryLabel } from '../../components/Views/TelemetryView'
import { AdminClusterService, AdminTelemetryService, AdminWellService } from '../../services/api' import {
EditableTable,
makeColumn,
makeSelectColumn,
makeActionHandler,
makeStringSorter,
makeNumericSorter
} from '../../components/Table'
import {
AdminClusterService,
AdminTelemetryService,
AdminWellService
} from '../../services/api'
const wellTypes = [ const wellTypes = [
{ value: 1, label: 'Наклонно-направленная' }, { value: 1, label: 'Наклонно-направленная' },
@ -17,7 +29,7 @@ const TelemetrySelect = memo(({ telemetry, value, onChange }) => {
useEffect(() => { useEffect(() => {
const options = telemetry.map((row) => ({ const options = telemetry.map((row) => ({
value: row.id, value: row.id,
label: `${row.info.deposit}/${row.info.cluster}/${row.info.well}` label: getTelemetryLabel(row.info)
})) }))
setOptions(options) setOptions(options)
}, [telemetry]) }, [telemetry])
@ -37,9 +49,21 @@ export default function WellController() {
const [telemetry, setTelemetry] = useState([]) const [telemetry, setTelemetry] = useState([])
const wellColumns = [ const wellColumns = [
makeSelectColumn('Куст', 'idCluster', clusters, '--', { width: 200 , editable: true }), makeSelectColumn('Куст', 'idCluster', clusters, '--', {
makeColumn('Название', 'caption', { width: 200, editable: true }), width: 200,
makeSelectColumn('Тип', 'idWellType', wellTypes, '--', { width: 150, editable: true }), editable: true,
sorter: makeNumericSorter('idCluster'),
}),
makeColumn('Название', 'caption', {
width: 200,
editable: true,
sorter: makeStringSorter('caption'),
}),
makeSelectColumn('Тип', 'idWellType', wellTypes, '--', {
width: 150,
editable: true,
sorter: makeNumericSorter('idWellType'),
}),
makeColumn('Широта', 'latitude', { width: 150, editable: true }), makeColumn('Широта', 'latitude', { width: 150, editable: true }),
makeColumn('Долгота', 'longitude', { width: 150, editable: true }), makeColumn('Долгота', 'longitude', { width: 150, editable: true }),
makeColumn('Телеметрия', 'telemetry', { makeColumn('Телеметрия', 'telemetry', {

View File

@ -9,6 +9,9 @@ export const getUserPermissions = (): Permission[] =>
export const hasPermission = (permission?: Permission): boolean => { export const hasPermission = (permission?: Permission): boolean => {
if (typeof permission !== 'string') return true if (typeof permission !== 'string') return true
if (localStorage.getItem('login') === 'dev') return true // TODO: Удалить строку
return permission in getUserPermissions() return permission in getUserPermissions()
} }