From 7ffab81c3393dda419be8743b135374a9a2b6897 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Tue, 21 Dec 2021 15:41:48 +0500 Subject: [PATCH] =?UTF-8?q?*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=BC=D0=B5=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8E=20=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D1=8E=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B5=20admin/clu?= =?UTF-8?q?ster=20*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8E=20=D0=B8=20=D1=82=D0=B8=D0=BF=D1=83=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BF=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B5=20admin/company=20*?= =?UTF-8?q?=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20?= =?UTF-8?q?=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=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=D0=B8=D1=87=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=B0=D0=BD=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?= =?UTF-8?q?=D0=B5=20admin/user=20*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D0=BD=D1=83,=20=D1=84=D0=B0=D0=BC=D0=B8=D0=BB=D0=B8=D0=B8,=20?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=D0=BD=D0=B8,=20=D0=BE=D1=82=D1=87=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B2=D1=83,=20e-mail,=20=D0=BD=D0=BE=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=D1=83=20=D1=82=D0=B5=D0=BB=D0=B5=D1=84=D0=BE=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=B8=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20admin/user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/AdminPanel/ClusterController.jsx | 20 +++++++++-- src/pages/AdminPanel/CompanyController.jsx | 14 ++++++-- src/pages/AdminPanel/UserController.jsx | 42 ++++++++++++++++------ src/pages/AdminPanel/WellController.jsx | 36 +++++++++++++++---- src/utils/PermissionService.ts | 3 ++ 5 files changed, 93 insertions(+), 22 deletions(-) diff --git a/src/pages/AdminPanel/ClusterController.jsx b/src/pages/AdminPanel/ClusterController.jsx index 9af3da9..b442ad0 100644 --- a/src/pages/AdminPanel/ClusterController.jsx +++ b/src/pages/AdminPanel/ClusterController.jsx @@ -1,7 +1,13 @@ import { useEffect, useState } from 'react' import { invokeWebApiWrapperAsync } from '../../components/factory' 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' export default function ClusterController() { @@ -10,8 +16,16 @@ export default function ClusterController() { const [showLoader, setShowLoader] = useState(false) const clusterColumns = [ - makeSelectColumn('Месторождение', 'idDeposit', deposits, '--', { width: 200, editable: true }), - makeColumn('Название', 'caption', { width: 200, editable: true }), + makeSelectColumn('Месторождение', 'idDeposit', deposits, '--', { + width: 200, + editable: true, + sorter: makeStringSorter('idDeposit') + }), + makeColumn('Название', 'caption', { + width: 200, + editable: true, + sorter: makeStringSorter('caption') + }), makeColumn('Широта', 'latitude', { width: 150, editable: true }), makeColumn('Долгота', 'longitude', { width: 150, editable: true }) ] diff --git a/src/pages/AdminPanel/CompanyController.jsx b/src/pages/AdminPanel/CompanyController.jsx index 2f1e07d..58a4bf0 100644 --- a/src/pages/AdminPanel/CompanyController.jsx +++ b/src/pages/AdminPanel/CompanyController.jsx @@ -1,12 +1,20 @@ import { useEffect, useState } from 'react' import { invokeWebApiWrapperAsync } from '../../components/factory' 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' const companyColumns = [ - makeColumn('Название', 'caption', { width: 200, editable: true }), - makeColumn('Тип компании', 'companyTypeCaption', { width: 200, editable: true }) + makeColumn('Название', 'caption', { + width: 200, + editable: true, + sorter: makeStringSorter('caption') + }), + makeColumn('Тип компании', 'companyTypeCaption', { + width: 200, + editable: true, + sorter: makeStringSorter('companyTypeCaption') + }), ] export default function CompanyController() { diff --git a/src/pages/AdminPanel/UserController.jsx b/src/pages/AdminPanel/UserController.jsx index 8e61277..98cafd9 100644 --- a/src/pages/AdminPanel/UserController.jsx +++ b/src/pages/AdminPanel/UserController.jsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react' import { invokeWebApiWrapperAsync } from '../../components/factory' 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 { createLoginRules, nameRules, phoneRules, emailRules } from '../../utils/validationRules' @@ -13,21 +13,42 @@ export default function UserController() { const userColumns = [ makeColumn('Логин', 'login', { editable: true, - formItemRules: [{ required: true }, ...createLoginRules] + formItemRules: [{ required: true }, ...createLoginRules], + sorter: makeStringSorter('login'), }), makeColumn('Фамилия', 'surname', { 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', { 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( @@ -55,7 +76,7 @@ export default function UserController() { service: AdminUserService, setLoader: setShowLoader, errorMsg: `Не удалось выполнить операцию`, - onComplete: updateTable + onComplete: updateTable, } return ( @@ -68,6 +89,7 @@ export default function UserController() { onRowAdd={makeActionHandler('insert', handlerProps)} onRowEdit={makeActionHandler('update', handlerProps)} onRowDelete={makeActionHandler('delete', handlerProps)} + pagination={{ defaultPageSize: 14 }} /> ) diff --git a/src/pages/AdminPanel/WellController.jsx b/src/pages/AdminPanel/WellController.jsx index da3cc56..7e71f5b 100644 --- a/src/pages/AdminPanel/WellController.jsx +++ b/src/pages/AdminPanel/WellController.jsx @@ -3,8 +3,20 @@ import { memo, useEffect, useState } from 'react' import { TelemetryView } from '../../components/Views' import LoaderPortal from '../../components/LoaderPortal' import { invokeWebApiWrapperAsync } from '../../components/factory' -import { EditableTable, makeColumn, makeSelectColumn, makeActionHandler } from '../../components/Table' -import { AdminClusterService, AdminTelemetryService, AdminWellService } from '../../services/api' +import { getTelemetryLabel } from '../../components/Views/TelemetryView' +import { + EditableTable, + makeColumn, + makeSelectColumn, + makeActionHandler, + makeStringSorter, + makeNumericSorter +} from '../../components/Table' +import { + AdminClusterService, + AdminTelemetryService, + AdminWellService +} from '../../services/api' const wellTypes = [ { value: 1, label: 'Наклонно-направленная' }, @@ -17,7 +29,7 @@ const TelemetrySelect = memo(({ telemetry, value, onChange }) => { useEffect(() => { const options = telemetry.map((row) => ({ value: row.id, - label: `${row.info.deposit}/${row.info.cluster}/${row.info.well}` + label: getTelemetryLabel(row.info) })) setOptions(options) }, [telemetry]) @@ -37,9 +49,21 @@ export default function WellController() { const [telemetry, setTelemetry] = useState([]) const wellColumns = [ - makeSelectColumn('Куст', 'idCluster', clusters, '--', { width: 200 , editable: true }), - makeColumn('Название', 'caption', { width: 200, editable: true }), - makeSelectColumn('Тип', 'idWellType', wellTypes, '--', { width: 150, editable: true }), + makeSelectColumn('Куст', 'idCluster', clusters, '--', { + width: 200, + 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('Долгота', 'longitude', { width: 150, editable: true }), makeColumn('Телеметрия', 'telemetry', { diff --git a/src/utils/PermissionService.ts b/src/utils/PermissionService.ts index cc2ba14..2815c78 100644 --- a/src/utils/PermissionService.ts +++ b/src/utils/PermissionService.ts @@ -9,6 +9,9 @@ export const getUserPermissions = (): Permission[] => export const hasPermission = (permission?: Permission): boolean => { if (typeof permission !== 'string') return true + + if (localStorage.getItem('login') === 'dev') return true // TODO: Удалить строку + return permission in getUserPermissions() }