This commit is contained in:
KharchenkoVV 2021-08-31 12:45:02 +05:00
commit e779253ff6
9 changed files with 202 additions and 144 deletions

View File

@ -0,0 +1,37 @@
import {Tooltip} from 'antd'
import { UserOutlined } from '@ant-design/icons'
import '../styles/grid.css'
export const UserView = ({user}) => {
if(!user)
return <Tooltip title='нет пользователя'>-</Tooltip>
const displayName = user?.login
const tooltipInfo = <div className='grid_container'>
<div className='c1 r1'>
Имя
</div>
<div className='c2 r1'>
{user?.name}
</div>
<div className='c1 r2'>
Фамилия
</div>
<div className='c2 r2'>
{user?.surname}
</div>
<div className='c1 r3'>
Отчество
</div>
<div className='c2 r3'>
{user?.patronymic}
</div>
</div>
return <Tooltip title={tooltipInfo}>
<UserOutlined/>
{displayName}
</Tooltip>
}

View File

@ -85,4 +85,13 @@ export const upload = async (url:string, formData: FormData) => {
method: 'Post', method: 'Post',
body: formData, body: formData,
}) })
}
export const formatBytes = (bytes:number) => {
if(bytes < 1024)
return `${bytes.toFixed(0)}b`
if(bytes < 1024*1024)
return `${(bytes/1024).toFixed(2)}kb`
else
return `${(bytes/1024/1024).toFixed(2)}Mb`
} }

View File

@ -5,10 +5,12 @@ import { FileService } from "../../services/api"
import { import {
invokeWebApiWrapperAsync, invokeWebApiWrapperAsync,
download, download,
formatBytes,
} from "../../components/factory" } from "../../components/factory"
import { EditableTable, makePaginationObject } from "../../components/Table" import { EditableTable, makePaginationObject } from "../../components/Table"
import UploadForm from "../../components/UploadForm" import UploadForm from "../../components/UploadForm"
import LoaderPortal from "../../components/LoaderPortal" import LoaderPortal from "../../components/LoaderPortal"
import {UserView} from '../../components/UserView'
const pageSize = 12 const pageSize = 12
const { RangePicker } = DatePicker const { RangePicker } = DatePicker
@ -17,7 +19,7 @@ const { Search } = Input
export default function DocumentsTemplate({ idCategory, idWell }) { export default function DocumentsTemplate({ idCategory, idWell }) {
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
const [filterDataRange, setFilterDataRange] = useState([]) const [filterDataRange, setFilterDataRange] = useState([])
const [filterCompany, setFilterCompany] = useState([]) const [filterCompaniesIds, setFilterCompany] = useState([])
const [filterFileName, setFilterFileName] = useState('') const [filterFileName, setFilterFileName] = useState('')
const [pagination, setPagination] = useState(null) const [pagination, setPagination] = useState(null)
const [files, setFiles] = useState([]) const [files, setFiles] = useState([])
@ -66,13 +68,20 @@ export default function DocumentsTemplate({ idCategory, idWell }) {
title: "Дата загрузки", title: "Дата загрузки",
key: "uploadDate", key: "uploadDate",
dataIndex: "uploadDate", dataIndex: "uploadDate",
render: (item) => render: item =>
moment.utc(item).local().format("DD MMM YYYY, HH:mm:ss"), moment.utc(item).local().format("DD MMM YYYY, HH:mm:ss"),
}, },
{ {
title: "Ф.И.О.", title: "Размер",
key: "userName", key: "size",
dataIndex: "userName", dataIndex: "size",
render: item => formatBytes(item)
},
{
title: "Автор",
key: "author",
dataIndex: "author",
render: item => <UserView user={item}/>
}, },
{ {
title: "Компания", title: "Компания",
@ -101,12 +110,14 @@ export default function DocumentsTemplate({ idCategory, idWell }) {
invokeWebApiWrapperAsync( invokeWebApiWrapperAsync(
async () => { async () => {
const paginatedFiles = await FileService.getFilesInfo( const paginatedFiles = await FileService.getFilesInfo(
idWell, idWell,
idCategory,
filterCompaniesIds,
filterFileName,
begin,
end,
(page - 1) * pageSize, (page - 1) * pageSize,
pageSize, pageSize,
idCategory,
begin,
end
) )
if (!paginatedFiles) return if (!paginatedFiles) return
addKeysAndUpdateFiles(paginatedFiles?.items) addKeysAndUpdateFiles(paginatedFiles?.items)
@ -119,7 +130,7 @@ export default function DocumentsTemplate({ idCategory, idWell }) {
) )
} }
useEffect(update, [idWell, idCategory, page, filterDataRange, filterCompany, filterFileName]) useEffect(update, [idWell, idCategory, page, filterDataRange, filterCompaniesIds, filterFileName])
const companies = [...new Set(files.map(file=>file.company))] const companies = [...new Set(files.map(file=>file.company))]
.filter(company=>company) .filter(company=>company)

View File

@ -1,132 +1,67 @@
// import {Table, Button} from 'antd' import {Table, Button} from 'antd'
// import {useEffect, useState} from 'react' import {useEffect, useState} from 'react'
// import { useParams } from "react-router-dom" import {invokeWebApiWrapperAsync, download} from '../components/factory'
// import FileInfo from '../components/FileInfo' import { FileService } from '../services/api'
// import UploadPlanFileForm from '../components/UploadPlanFileForm' import UploadForm from '../components/UploadForm'
// import { PlanService } from '../services/api' import LoaderPortal from '../components/LoaderPortal'
// import LoaderPortal from '../components/LoaderPortal'
// const originData = [ const idFileCategoryDrillingProgramItems = 13;
// {key: 1, category: 'Проект транспорт',}, //const idFileCategoryDrillingProgram = 14;
// {key: 2, category: 'Программа на бурение',},
// {key: 3, category: 'Долотная программа',},
// {key: 4, category: 'Программа промывки',},
// {key: 5, category: 'Планы на спуски',},
// {key: 6, category: 'График глубина день',},
// {key: 7, category: 'Мероприятия по бурению скважины',},
// ]
export default function DrillingProgram() { const FileInfo = (fileInfo) => {
return <div>Программа на бурение</div> return <div>{fileInfo?.name}</div>
// let { id } = useParams() }
// const [data, setData] = useState(originData)
// const [isLoaderVisible, setIsLoaderVisible] = useState(true)
// const columns = [ export default function DrillingProgram({idWell}) {
// { const [data, setData] = useState([])
// title: '', const [showLoader, setShowLoader] = useState(false)
// dataIndex: 'key',
// width: 50
// },
// {
// title: 'Раздел',
// dataIndex: 'category',
// key: 'category',
// width: 250
// },
// {
// title: 'Файл',
// dataIndex: 'fileInfo',
// key: 'fileInfo',
// render: (_, record) => record.fileInfo
// ? <FileInfo idCategory={record.key} fileInfo={record.fileInfo} onUploadComplete={updateData}/>
// : <UploadPlanFileForm idCategory={record.key} onUploadComplete={updateData}/>
// },
// {
// title: 'Автор',
// key: 'owner',
// render: (_,record) => record.fileInfo?.owner
// },
// {
// title: 'Дата загрузки',
// key: 'uploadDate',
// render: (_, record) => record.fileInfo ? new Date(record.fileInfo.uploadDate).toLocaleString() : ''
// },
// ]
// const updateData = async () => { const update = () => invokeWebApiWrapperAsync( async () => {
// let response = await PlanService.getFilesInfos(id) const files = await FileService.getInfosByCategory(idWell, idFileCategoryDrillingProgramItems)
setData(files??[])
// if(response) { },setShowLoader,null)
// let newData = [...originData] useEffect(update, [idWell])
// newData.forEach(item => {
// let newFileInfo = response.find(f=>f.idCategory === item.key)
// item.fileInfo = newFileInfo
// })
// setIsLoaderVisible(false)
// setData(newData)
// }
// }
// useEffect(()=>{updateData()}, []) const columns = [
{
// const downloadDrillingProgram = async () => { title: 'Файл',
// setIsLoaderVisible(true) dataIndex: 'fileInfo',
// try{ key: 'fileInfo',
// const response = await fetch(`/api/plan/${id}/drillingProgram`, { render: (_, record) => <FileInfo idCategory={record.key} fileInfo={record.fileInfo} onUploadComplete={update}/>
// headers: { },
// Authorization: 'Bearer ' + localStorage['token'] {
// }, title: 'Автор',
// method: 'Get' key: 'owner',
// }) render: (_,record) => record.fileInfo?.owner
// const blob = await response.blob() },
// const reader = new FileReader() {
// reader.readAsDataURL(blob) title: 'Дата загрузки',
// reader.onload = function (e) { key: 'uploadDate',
// let a = document.createElement('a') render: (_, record) => record.fileInfo ? new Date(record.fileInfo.uploadDate).toLocaleString() : ''
// a.href = e.target.result },
// a.download = "Программа бурения.xlsx" ]
// document.body.appendChild(a) // we need to append the element to the dom -> otherwise it will not work in firefox
// a.click()
// a.remove()
// }
// }catch(e){
// console.log(e)
// }
// setIsLoaderVisible(false)
// }
// const expandInfo = (fileInfo) => <p>
// <span>Автор:&nbsp{fileInfo.owner}</span>
// &nbsp&nbsp&nbsp&nbsp
// <span>Дата загрузки:&nbsp{new Date(fileInfo.uploadDate).toLocaleString()}</span>
// </p>
const urlDownloadProgram =`api/well/${idWell}/drillingProgram`
// return(<> return(<>
// <div>&nbsp</div> <LoaderPortal show={showLoader}>
// <LoaderPortal show={isLoaderVisible}> <Button
// <Button type="primary"
// type="primary" htmlType="button"
// htmlType="button" disabled={!data.some((el) => !!el.fileInfo)}
// disabled={!data.some((el) => !!el.fileInfo)} onClick={()=>{download(urlDownloadProgram)}}
// onClick={downloadDrillingProgram} >
// > Сформировать программу бурения
// Сформировать программу бурения </Button>
// </Button> <div>&nbsp;</div>
// <div>&nbsp</div> <Table
// <Table bordered
// bordered dataSource={data}
// dataSource={data} columns={columns}
// columns={columns} pagination={false}
// // expandable={{ />
// // expandedRowRender: record => expandInfo(record.fileInfo), <UploadForm idCategory={idFileCategoryDrillingProgramItems}/>
// // rowExpandable: record => record.fileInfo </LoaderPortal>
// // }} </>)
// pagination={false}
// />
// </LoaderPortal>
// </>)
} }

View File

@ -27,6 +27,7 @@ export type { TelemetryOperationDto } from './models/TelemetryOperationDto';
export type { TelemetryOperationDtoPaginationContainer } from './models/TelemetryOperationDtoPaginationContainer'; export type { TelemetryOperationDtoPaginationContainer } from './models/TelemetryOperationDtoPaginationContainer';
export type { TelemetryOperationDurationDto } from './models/TelemetryOperationDurationDto'; export type { TelemetryOperationDurationDto } from './models/TelemetryOperationDurationDto';
export type { TelemetryUserDto } from './models/TelemetryUserDto'; export type { TelemetryUserDto } from './models/TelemetryUserDto';
export type { UserDto } from './models/UserDto';
export type { UserTokenDto } from './models/UserTokenDto'; export type { UserTokenDto } from './models/UserTokenDto';
export type { WellDepthToDayDto } from './models/WellDepthToDayDto'; export type { WellDepthToDayDto } from './models/WellDepthToDayDto';
export type { WellDepthToIntervalDto } from './models/WellDepthToIntervalDto'; export type { WellDepthToIntervalDto } from './models/WellDepthToIntervalDto';

View File

@ -2,6 +2,8 @@
/* tslint:disable */ /* tslint:disable */
/* eslint-disable */ /* eslint-disable */
import type { UserDto } from './UserDto';
export type FileInfoDto = { export type FileInfoDto = {
id?: number; id?: number;
idWell?: number; idWell?: number;
@ -9,6 +11,7 @@ export type FileInfoDto = {
idAuthor?: number; idAuthor?: number;
name?: string | null; name?: string | null;
uploadDate?: string; uploadDate?: string;
authorName?: string | null; size?: number;
companyId?: number; author?: UserDto;
company?: string | null;
} }

View File

@ -0,0 +1,15 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type UserDto = {
login?: string | null;
level?: number | null;
name?: string | null;
surname?: string | null;
patronymic?: string | null;
id?: number;
idCompany?: number | null;
idRole?: number | null;
password?: string | null;
}

View File

@ -1,6 +1,7 @@
/* istanbul ignore file */ /* istanbul ignore file */
/* tslint:disable */ /* tslint:disable */
/* eslint-disable */ /* eslint-disable */
import type { FileInfoDto } from '../models/FileInfoDto';
import type { FileInfoDtoPaginationContainer } from '../models/FileInfoDtoPaginationContainer'; import type { FileInfoDtoPaginationContainer } from '../models/FileInfoDtoPaginationContainer';
import { request as __request } from '../core/request'; import { request as __request } from '../core/request';
@ -33,39 +34,60 @@ requestBody?: any,
/** /**
* Возвращает информацию о файлах для скважины в выбраной категории * Возвращает информацию о файлах для скважины в выбраной категории
* @param idWell id скважины * @param idWell id скважины
* @param skip для пагинации кол-во записей пропустить
* @param take для пагинации кол-во записей взять
* @param idCategory id категории файла * @param idCategory id категории файла
* @param companies id компаний для фильтрации возвращаемых файлов
* @param fileName часть имени файла для поиска
* @param begin дата начала * @param begin дата начала
* @param end дата окончания * @param end дата окончания
* @param companies id компаний для фильтрации возвращаемых файлов * @param skip для пагинации кол-во записей пропустить
* @param take для пагинации кол-во записей взять
* @returns FileInfoDtoPaginationContainer Success * @returns FileInfoDtoPaginationContainer Success
* @throws ApiError * @throws ApiError
*/ */
public static async getFilesInfo( public static async getFilesInfo(
idWell: number, idWell: number,
skip: number,
take: number = 32,
idCategory: number, idCategory: number,
companies?: Array<number>,
fileName?: string,
begin?: string, begin?: string,
end?: string, end?: string,
companies?: Array<number>, skip: number = 0,
take: number = 32,
): Promise<FileInfoDtoPaginationContainer> { ): Promise<FileInfoDtoPaginationContainer> {
const result = await __request({ const result = await __request({
method: 'GET', method: 'GET',
path: `/api/well/${idWell}/files`, path: `/api/well/${idWell}/files`,
query: { query: {
'skip': skip,
'take': take,
'idCategory': idCategory, 'idCategory': idCategory,
'companies': companies,
'fileName': fileName,
'begin': begin, 'begin': begin,
'end': end, 'end': end,
'companies': companies, 'skip': skip,
'take': take,
}, },
}); });
return result.body; return result.body;
} }
/**
* Возвращает информацию о файлах для скважины в выбраной категории
* @param idWell id скважины
* @param idCategory id категории файла
* @returns FileInfoDto Success
* @throws ApiError
*/
public static async getInfosByCategory(
idWell: number,
idCategory: number,
): Promise<Array<FileInfoDto>> {
const result = await __request({
method: 'GET',
path: `/api/well/${idWell}/files/category/${idCategory}`,
});
return result.body;
}
/** /**
* Возвращает файл с диска на сервере * Возвращает файл с диска на сервере
* @param idWell id скважины * @param idWell id скважины

25
src/styles/grid.css Normal file
View File

@ -0,0 +1,25 @@
.grid_container{
display: grid;
column-gap: 4px;
row-gap: 4px;
justify-items: stretch;
align-items: stretch;
}
.c1{ grid-column: 1 / span 1; }
.c2{ grid-column: 2 / span 1; }
.c3{ grid-column: 3 / span 1; }
.c4{ grid-column: 4 / span 1; }
.c5{ grid-column: 5 / span 1; }
.c6{ grid-column: 6 / span 1; }
.c7{ grid-column: 7 / span 1; }
.c8{ grid-column: 8 / span 1; }
.r1{ grid-row: 1 / span 1; }
.r2{ grid-row: 2 / span 1; }
.r3{ grid-row: 3 / span 1; }
.r4{ grid-row: 4 / span 1; }
.r5{ grid-row: 5 / span 1; }
.r6{ grid-row: 6 / span 1; }
.r7{ grid-row: 7 / span 1; }
.r8{ grid-row: 8 / span 1; }