diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 20f301c..3faac06 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -209,34 +209,42 @@ export const makeSelectColumn = ( other?: columnPropsOther, selectOther?: SelectProps ) => makeColumn(title, dataIndex, { + ...other, input: ) @@ -266,7 +274,7 @@ export const makeTagColumn = >( return makeColumn(title, dataIndex, { ...other, - render: (item?: T[]) => item?.map((elm: T) => {elm[label_key]}) ?? '-', + render: (item?: T[]) => item?.map((elm: T) => {other?.render?.(elm) ?? elm[label_key]}) ?? '-', input: , }) } diff --git a/src/components/Views/CompanyView.tsx b/src/components/Views/CompanyView.tsx index e7b6eb1..e279e6e 100644 --- a/src/components/Views/CompanyView.tsx +++ b/src/components/Views/CompanyView.tsx @@ -1,6 +1,7 @@ import { memo } from 'react' import { Tooltip } from 'antd' import { BankOutlined } from '@ant-design/icons' + import { CompanyDto } from '../../services/api' import { Grid, GridItem } from '../Grid' @@ -11,7 +12,7 @@ export type CompanyViewProps = { export const CompanyView = memo(({ company }) => company ? ( - тип: + Тип: {company?.companyTypeCaption} }> diff --git a/src/components/Views/RoleView.tsx b/src/components/Views/RoleView.tsx new file mode 100644 index 0000000..c951e51 --- /dev/null +++ b/src/components/Views/RoleView.tsx @@ -0,0 +1,42 @@ +import { memo } from 'react' +import { Tag, Tooltip } from 'antd' + +import { UserRoleDto } from '../../services/api' +import { Grid, GridItem } from '../Grid' +import PermissionView from './PermissionView' + +export type RoleViewProps = { + role?: UserRoleDto + parentRole?: UserRoleDto +} + +export const RoleView = memo(({ role, parentRole }) => role ? ( + + Название: + {role.caption} + + Роль-родитель: + {parentRole?.caption ?? 'Отсутствует'} + + Тип: + {role.idType} + + Разрешения: + + {role.permissions?.map((permission, i) => ( + + + + )) ?? '-'} + + + } + > + {role.caption} + +) : ( + - +)) diff --git a/src/components/Views/TelemetryView.tsx b/src/components/Views/TelemetryView.tsx index a262426..e76a2fc 100644 --- a/src/components/Views/TelemetryView.tsx +++ b/src/components/Views/TelemetryView.tsx @@ -3,7 +3,7 @@ import { Tooltip } from 'antd' import { TelemetryDto, TelemetryInfoDto } from '../../services/api' import { Grid, GridItem } from '../Grid' -const lables: { [labelKey: string]: string } = { +const lables: Record = { timeZoneId: 'Временная зона', timeZoneOffsetTotalHours: 'Сдвиг временной зоны', drillingStartDate: 'Начало бурения', diff --git a/src/components/Views/UserView.tsx b/src/components/Views/UserView.tsx index 445f7d5..62548c5 100644 --- a/src/components/Views/UserView.tsx +++ b/src/components/Views/UserView.tsx @@ -3,6 +3,7 @@ import { Tooltip } from 'antd' import { UserOutlined } from '@ant-design/icons' import { UserDto } from '../../services/api' import { Grid, GridItem } from '../Grid' +import { CompanyView } from './CompanyView' export type UserViewProps = { user?: UserDto @@ -21,7 +22,9 @@ export const UserView = memo(({ user }) => user ? ( {user?.patronymic} Компания: - {user?.company?.caption} + + + )}> diff --git a/src/components/Views/index.ts b/src/components/Views/index.ts index 5eb61f6..51dae3a 100644 --- a/src/components/Views/index.ts +++ b/src/components/Views/index.ts @@ -1,11 +1,13 @@ -export type { CompanyViewProps } from './CompanyView' -export type { MarkViewProps } from './MarkView' export type { PermissionViewProps } from './PermissionView' export type { TelemetryViewProps } from './TelemetryView' +export type { CompanyViewProps } from './CompanyView' +export type { MarkViewProps } from './MarkView' +export type { RoleViewProps } from './RoleView' export type { UserViewProps } from './UserView' -export { CompanyView } from './CompanyView' -export { MarkView } from './MarkView' export { PermissionView } from './PermissionView' export { TelemetryView, getTelemetryLabel } from './TelemetryView' -export { UserView } from './UserView' +export { CompanyView } from './CompanyView' +export { MarkView } from './MarkView' +export { RoleView } from './RoleView' +export { UserView } from './UserView' \ No newline at end of file diff --git a/src/pages/AdminPanel/RoleController.jsx b/src/pages/AdminPanel/RoleController.jsx index 82956ed..934b1f2 100644 --- a/src/pages/AdminPanel/RoleController.jsx +++ b/src/pages/AdminPanel/RoleController.jsx @@ -1,41 +1,13 @@ -import { Select, Tag } from 'antd' import { memo, useEffect, useState } from 'react' import LoaderPortal from '../../components/LoaderPortal' import { PermissionView } from '../../components/Views' import { invokeWebApiWrapperAsync } from '../../components/factory' -import { EditableTable, makeActionHandler, makeColumn, makeSelectColumn } from '../../components/Table' +import { EditableTable, makeActionHandler, makeColumn, makeSelectColumn, makeTagColumn } from '../../components/Table' import { AdminPermissionService, AdminUserRoleService } from '../../services/api' import { arrayOrDefault } from '../../utils' -const PermissionTag = memo(({ permissions, value, onChange }) => { - const [options, setOptions] = useState([]) - - useEffect(() => { - setOptions(permissions.map((elm) => ({ key: Date.now(), value: `${elm.id}`, label: elm.name }))) - }, [permissions]) - - console.log({ permissions, value }) - - const onSelectChange = (values) => { - const arr = values.map((id) => permissions.find((elm) => `${elm.id}` === id)) - onChange?.(arr) - } - - const selectValue = value?.map((val) => `${val.id}`) - - return ( - + ) +}) export default function UserController() { const [users, setUsers] = useState([]) @@ -35,25 +69,30 @@ export default function UserController() { useEffect(() => invokeWebApiWrapperAsync( async () => { - let companies = arrayOrDefault(await AdminCompanyService.getAll()) - companies = companies?.map((company) => ({ value: company.id, label: company.caption })) + const roles = arrayOrDefault(await AdminUserRoleService.getAll()) + const companies = arrayOrDefault(await AdminCompanyService.getAll()).map((company) => ({ + value: company.id, + label: company.caption + })) const users = arrayOrDefault(await AdminUserService.getAll()) setUsers(users) + setColumns([ makeColumn('Логин', 'login', { editable: true, formItemRules: [ { required: true }, ...createLoginRules, - () => ({ - validator(_, value) { - if (!value || users.findIndex((user) => user.login === value) < 0) - return Promise.resolve() - return Promise.reject(new Error('Логин уже занят!')) - } - }) + // () => ({ + // validator(_, value) { + // if (!value || users.findIndex((user) => user.login === value) < 0) + // return Promise.resolve() + // return Promise.reject(new Error('Логин уже занят!')) + // } + // }) + // TODO: Для проверки уникальности логина необходимо исключить из выборки логин выбранного пользователя ], sorter: makeStringSorter('login'), }), @@ -86,10 +125,19 @@ export default function UserController() { editable: true, sorter: makeStringSorter('position'), }), + makeColumn('Роли', 'roleNames', { + editable: true, + input: , + render: (item) => item?.map((elm) => ( + + role.caption === elm)} /> + + )) ?? '-' + }), makeSelectColumn('Компания', 'idCompany', companies, '--', { editable: true, sorter: makeNumericSorter('idCompany'), - }), + }) ]) }, setShowLoader, @@ -114,7 +162,7 @@ export default function UserController() { onRowAdd={makeActionHandler('insert', handlerProps)} onRowEdit={makeActionHandler('update', handlerProps)} onRowDelete={makeActionHandler('delete', handlerProps)} - additionalButtons={additionalButtons} + // additionalButtons={additionalButtons} buttonsWidth={120} pagination={{ defaultPageSize: 14 }} /> diff --git a/src/pages/AdminPanel/WellController.jsx b/src/pages/AdminPanel/WellController.jsx index 218bed1..34e8cb6 100644 --- a/src/pages/AdminPanel/WellController.jsx +++ b/src/pages/AdminPanel/WellController.jsx @@ -1,9 +1,10 @@ -import { Select } from 'antd' +import { Button, Select } from 'antd' +import { ForkOutlined } from '@ant-design/icons' import { memo, useEffect, useState } from 'react' import LoaderPortal from '../../components/LoaderPortal' import { invokeWebApiWrapperAsync } from '../../components/factory' -import { TelemetryView, getTelemetryLabel } from '../../components/Views' +import { TelemetryView, getTelemetryLabel, CompanyView } from '../../components/Views' import { EditableTable, makeColumn, @@ -11,13 +12,13 @@ import { makeActionHandler, makeStringSorter, makeNumericSorter, - makeTagColumn + makeTagColumn, } from '../../components/Table' import { AdminClusterService, AdminCompanyService, AdminTelemetryService, - AdminWellService + AdminWellService, } from '../../services/api' import { arrayOrDefault } from '../../utils' @@ -58,12 +59,27 @@ export default function WellController() { `Не удалось загрузить список скважин` ) + const duplicateWell = (well) => { + // TODO: Метод дубликации скважины + } + + const addititonalButtons = (record, editingKey) => ( +