diff --git a/src/components/factory.ts b/src/components/factory.ts index 840e0a7..ca0bd9d 100644 --- a/src/components/factory.ts +++ b/src/components/factory.ts @@ -85,4 +85,13 @@ export const upload = async (url:string, formData: FormData) => { method: 'Post', 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` } \ No newline at end of file diff --git a/src/pages/Documents/DocumentsTemplate.jsx b/src/pages/Documents/DocumentsTemplate.jsx index 15e8eab..9f97e74 100644 --- a/src/pages/Documents/DocumentsTemplate.jsx +++ b/src/pages/Documents/DocumentsTemplate.jsx @@ -5,10 +5,12 @@ import { FileService } from "../../services/api" import { invokeWebApiWrapperAsync, download, + formatBytes, } from "../../components/factory" import { EditableTable, makePaginationObject } from "../../components/Table" import UploadForm from "../../components/UploadForm" import LoaderPortal from "../../components/LoaderPortal" +import {UserView} from '../../components/UserView' const pageSize = 12 const { RangePicker } = DatePicker @@ -17,7 +19,7 @@ const { Search } = Input export default function DocumentsTemplate({ idCategory, idWell }) { const [page, setPage] = useState(1) const [filterDataRange, setFilterDataRange] = useState([]) - const [filterCompany, setFilterCompany] = useState([]) + const [filterCompaniesIds, setFilterCompany] = useState([]) const [filterFileName, setFilterFileName] = useState('') const [pagination, setPagination] = useState(null) const [files, setFiles] = useState([]) @@ -66,13 +68,20 @@ export default function DocumentsTemplate({ idCategory, idWell }) { title: "Дата загрузки", key: "uploadDate", dataIndex: "uploadDate", - render: (item) => + render: item => moment.utc(item).local().format("DD MMM YYYY, HH:mm:ss"), }, { - title: "Ф.И.О.", - key: "userName", - dataIndex: "userName", + title: "Размер", + key: "size", + dataIndex: "size", + render: item => formatBytes(item) + }, + { + title: "Автор", + key: "author", + dataIndex: "author", + render: item => }, { title: "Компания", @@ -101,12 +110,14 @@ export default function DocumentsTemplate({ idCategory, idWell }) { invokeWebApiWrapperAsync( async () => { const paginatedFiles = await FileService.getFilesInfo( - idWell, + idWell, + idCategory, + filterCompaniesIds, + filterFileName, + begin, + end, (page - 1) * pageSize, pageSize, - idCategory, - begin, - end ) if (!paginatedFiles) return 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))] .filter(company=>company) diff --git a/src/pages/DrillingProgram.jsx b/src/pages/DrillingProgram.jsx index d518370..af5e21e 100644 --- a/src/pages/DrillingProgram.jsx +++ b/src/pages/DrillingProgram.jsx @@ -1,132 +1,67 @@ -// import {Table, Button} from 'antd' -// import {useEffect, useState} from 'react' -// import { useParams } from "react-router-dom" -// import FileInfo from '../components/FileInfo' -// import UploadPlanFileForm from '../components/UploadPlanFileForm' -// import { PlanService } from '../services/api' -// import LoaderPortal from '../components/LoaderPortal' +import {Table, Button} from 'antd' +import {useEffect, useState} from 'react' +import {invokeWebApiWrapperAsync, download} from '../components/factory' +import { FileService } from '../services/api' +import UploadForm from '../components/UploadForm' +import LoaderPortal from '../components/LoaderPortal' -// const originData = [ -// {key: 1, category: 'Проект транспорт',}, -// {key: 2, category: 'Программа на бурение',}, -// {key: 3, category: 'Долотная программа',}, -// {key: 4, category: 'Программа промывки',}, -// {key: 5, category: 'Планы на спуски',}, -// {key: 6, category: 'График глубина день',}, -// {key: 7, category: 'Мероприятия по бурению скважины',}, -// ] +const idFileCategoryDrillingProgramItems = 13; +//const idFileCategoryDrillingProgram = 14; -export default function DrillingProgram() { - return
Программа на бурение
- // let { id } = useParams() - // const [data, setData] = useState(originData) - // const [isLoaderVisible, setIsLoaderVisible] = useState(true) +const FileInfo = (fileInfo) => { + return
{fileInfo?.name}
+} - // const columns = [ - // { - // title: '№', - // dataIndex: 'key', - // width: 50 - // }, - // { - // title: 'Раздел', - // dataIndex: 'category', - // key: 'category', - // width: 250 - // }, - // { - // title: 'Файл', - // dataIndex: 'fileInfo', - // key: 'fileInfo', - // render: (_, record) => record.fileInfo - // ? - // : - // }, - // { - // title: 'Автор', - // key: 'owner', - // render: (_,record) => record.fileInfo?.owner - // }, - // { - // title: 'Дата загрузки', - // key: 'uploadDate', - // render: (_, record) => record.fileInfo ? new Date(record.fileInfo.uploadDate).toLocaleString() : '' - // }, - // ] +export default function DrillingProgram({idWell}) { + const [data, setData] = useState([]) + const [showLoader, setShowLoader] = useState(false) - // const updateData = async () => { - // let response = await PlanService.getFilesInfos(id) - - // if(response) { + const update = () => invokeWebApiWrapperAsync( async () => { + const files = await FileService.getInfosByCategory(idWell, idFileCategoryDrillingProgramItems) + setData(files??[]) + },setShowLoader,null) - // let newData = [...originData] - // newData.forEach(item => { - // let newFileInfo = response.find(f=>f.idCategory === item.key) - // item.fileInfo = newFileInfo - // }) - // setIsLoaderVisible(false) - // setData(newData) - // } - // } + useEffect(update, [idWell]) - // useEffect(()=>{updateData()}, []) - - // const downloadDrillingProgram = async () => { - // setIsLoaderVisible(true) - // try{ - // const response = await fetch(`/api/plan/${id}/drillingProgram`, { - // headers: { - // Authorization: 'Bearer ' + localStorage['token'] - // }, - // method: 'Get' - // }) - // const blob = await response.blob() - // const reader = new FileReader() - // reader.readAsDataURL(blob) - // reader.onload = function (e) { - // let a = document.createElement('a') - // 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) =>

- // Автор: {fileInfo.owner} - //      - // Дата загрузки: {new Date(fileInfo.uploadDate).toLocaleString()} - //

+ const columns = [ + { + title: 'Файл', + dataIndex: 'fileInfo', + key: 'fileInfo', + render: (_, record) => + }, + { + title: 'Автор', + key: 'owner', + render: (_,record) => record.fileInfo?.owner + }, + { + title: 'Дата загрузки', + key: 'uploadDate', + render: (_, record) => record.fileInfo ? new Date(record.fileInfo.uploadDate).toLocaleString() : '' + }, + ] + const urlDownloadProgram =`api/well/${idWell}/drillingProgram` - // return(<> - //
 
- // - // - //
 
- // expandInfo(record.fileInfo), - // // rowExpandable: record => record.fileInfo - // // }} - // pagination={false} - // /> - // - // ) + return(<> + + +
 
+
+ + + ) } \ No newline at end of file diff --git a/src/services/api/index.ts b/src/services/api/index.ts index 8ae6671..d441efd 100644 --- a/src/services/api/index.ts +++ b/src/services/api/index.ts @@ -27,6 +27,7 @@ export type { TelemetryOperationDto } from './models/TelemetryOperationDto'; export type { TelemetryOperationDtoPaginationContainer } from './models/TelemetryOperationDtoPaginationContainer'; export type { TelemetryOperationDurationDto } from './models/TelemetryOperationDurationDto'; export type { TelemetryUserDto } from './models/TelemetryUserDto'; +export type { UserDto } from './models/UserDto'; export type { UserTokenDto } from './models/UserTokenDto'; export type { WellDepthToDayDto } from './models/WellDepthToDayDto'; export type { WellDepthToIntervalDto } from './models/WellDepthToIntervalDto'; diff --git a/src/services/api/models/FileInfoDto.ts b/src/services/api/models/FileInfoDto.ts index b00c85f..fecd900 100644 --- a/src/services/api/models/FileInfoDto.ts +++ b/src/services/api/models/FileInfoDto.ts @@ -2,6 +2,8 @@ /* tslint:disable */ /* eslint-disable */ +import type { UserDto } from './UserDto'; + export type FileInfoDto = { id?: number; idWell?: number; @@ -9,6 +11,7 @@ export type FileInfoDto = { idAuthor?: number; name?: string | null; uploadDate?: string; - authorName?: string | null; - companyId?: number; + size?: number; + author?: UserDto; + company?: string | null; } \ No newline at end of file diff --git a/src/services/api/models/UserDto.ts b/src/services/api/models/UserDto.ts new file mode 100644 index 0000000..b4d8f7c --- /dev/null +++ b/src/services/api/models/UserDto.ts @@ -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; +} \ No newline at end of file diff --git a/src/services/api/services/FileService.ts b/src/services/api/services/FileService.ts index 866599a..cbee6bb 100644 --- a/src/services/api/services/FileService.ts +++ b/src/services/api/services/FileService.ts @@ -1,6 +1,7 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { FileInfoDto } from '../models/FileInfoDto'; import type { FileInfoDtoPaginationContainer } from '../models/FileInfoDtoPaginationContainer'; import { request as __request } from '../core/request'; @@ -33,39 +34,60 @@ requestBody?: any, /** * Возвращает информацию о файлах для скважины в выбраной категории * @param idWell id скважины - * @param skip для пагинации кол-во записей пропустить - * @param take для пагинации кол-во записей взять * @param idCategory id категории файла + * @param companies id компаний для фильтрации возвращаемых файлов + * @param fileName часть имени файла для поиска * @param begin дата начала * @param end дата окончания - * @param companies id компаний для фильтрации возвращаемых файлов + * @param skip для пагинации кол-во записей пропустить + * @param take для пагинации кол-во записей взять * @returns FileInfoDtoPaginationContainer Success * @throws ApiError */ public static async getFilesInfo( idWell: number, -skip: number, -take: number = 32, idCategory: number, +companies?: Array, +fileName?: string, begin?: string, end?: string, -companies?: Array, +skip: number = 0, +take: number = 32, ): Promise { const result = await __request({ method: 'GET', path: `/api/well/${idWell}/files`, query: { - 'skip': skip, - 'take': take, 'idCategory': idCategory, + 'companies': companies, + 'fileName': fileName, 'begin': begin, 'end': end, - 'companies': companies, + 'skip': skip, + 'take': take, }, }); return result.body; } + /** + * Возвращает информацию о файлах для скважины в выбраной категории + * @param idWell id скважины + * @param idCategory id категории файла + * @returns FileInfoDto Success + * @throws ApiError + */ + public static async getInfosByCategory( +idWell: number, +idCategory: number, +): Promise> { + const result = await __request({ + method: 'GET', + path: `/api/well/${idWell}/files/category/${idCategory}`, + }); + return result.body; + } + /** * Возвращает файл с диска на сервере * @param idWell id скважины