dev
RekHoto 3 years ago
parent 9a83f686eb
commit 8954747822

@ -6,6 +6,7 @@ import { useRegionFilterExpression } from "./useRegionFilterExpression";
import { LAYER_IDS } from "./constants";
import { useMode } from "../../stores/useMode";
import { useOnApprovalPointsFilters } from "../../stores/useOnApprovalPointsFilters";
import { getSourceLayerName } from "../../api.js";
const statusExpression = ["==", ["get", "status"], STATUSES.cancelled];
@ -34,7 +35,7 @@ export const CancelledPoints = () => {
{...cancelledPointLayer}
id={LAYER_IDS.cancelled}
source={"points"}
source-layer={"public.points_with_dist"}
source-layer={getSourceLayerName()}
layout={{
visibility: isVisible[LAYER_IDS.cancelled] ? "visible" : "none",
}}

@ -5,6 +5,7 @@ import { STATUSES } from "../../config";
import { useRegionFilterExpression } from "./useRegionFilterExpression";
import { LAYER_IDS } from "./constants";
import { useWorkingPointsFilters } from "../../stores/useWorkingPointsFilters";
import { getSourceLayerName } from "../../api.js";
const statusExpression = ["==", ["get", "status"], STATUSES.working];
@ -53,7 +54,7 @@ export const FilteredWorkingPoints = () => {
{...workingPointSymbolLayer}
id={LAYER_IDS.filteredWorking}
source={"points"}
source-layer={"public.points_with_dist"}
source-layer={getSourceLayerName()}
layout={{
...workingPointSymbolLayer.layout,
visibility: isVisible[LAYER_IDS.filteredWorking] ? "visible" : "none",

@ -5,6 +5,7 @@ import { STATUSES } from "../../config";
import { useRegionFilterExpression } from "./useRegionFilterExpression";
import { LAYER_IDS } from "./constants";
import { useOnApprovalPointsFilters } from "../../stores/useOnApprovalPointsFilters";
import { getSourceLayerName } from "../../api.js";
const statusExpression = ["==", ["get", "status"], STATUSES.onApproval];
@ -25,7 +26,7 @@ export const OnApprovalPoints = () => {
{...approvePointLayer}
id={LAYER_IDS.approve}
source={"points"}
source-layer={"public.points_with_dist"}
source-layer={getSourceLayerName()}
layout={{
visibility: isVisible[LAYER_IDS.approve] ? "visible" : "none",
}}

@ -10,6 +10,7 @@ import { useRegionFilterExpression } from "./useRegionFilterExpression";
import { LAYER_IDS } from "./constants";
import { RANGE_FILTERS_KEYS, usePendingPointsFilters } from "../../stores/usePendingPointsFilters";
import { fieldHasChanged } from "../../utils.js";
import { getSourceLayerName } from "../../api.js";
const statusExpression = ["==", ["get", "status"], STATUSES.pending];
@ -97,7 +98,7 @@ export const PendingPoints = () => {
{...matchInitialPointLayer}
id={LAYER_IDS["initial-unmatch"]}
source={"points"}
source-layer={"public.points_with_dist"}
source-layer={getSourceLayerName()}
layout={{
...matchInitialPointLayer.layout,
visibility: isVisible[LAYER_IDS.initial] ? "visible" : "none",
@ -109,7 +110,7 @@ export const PendingPoints = () => {
{...matchInitialPointLayer}
id={LAYER_IDS["initial-match"]}
source={"points"}
source-layer={"public.points_with_dist"}
source-layer={getSourceLayerName()}
layout={{
...matchInitialPointLayer.layout,
visibility: isVisible[LAYER_IDS.initial] ? "visible" : "none",

@ -1,5 +1,5 @@
import { Source } from "react-map-gl";
import { BASE_URL } from "../../api";
import { BASE_URL, getSourceLayerName } from "../../api";
import { useUpdateLayerCounter } from "../../stores/useUpdateLayerCounter";
import { PendingPoints } from "./PendingPoints";
import { OnApprovalPoints } from "./OnApprovalPoints";
@ -17,7 +17,7 @@ export const Points = () => {
type="vector"
key={`points-${updateCounter}`}
tiles={[
`${BASE_URL}/martin/public.points_with_dist/{z}/{x}/{y}.pbf`,
`${BASE_URL}/martin/${getSourceLayerName()}/{z}/{x}/{y}.pbf`,
]}
>
<PendingPoints />

@ -6,6 +6,7 @@ import { useRegionFilterExpression } from "./useRegionFilterExpression";
import { LAYER_IDS } from "./constants";
import { useMode } from "../../stores/useMode";
import { useOnApprovalPointsFilters } from "../../stores/useOnApprovalPointsFilters";
import {getSourceLayerName} from "../../api.js";
const statusExpression = ["==", ["get", "status"], STATUSES.working];
@ -34,7 +35,7 @@ export const WorkingPoints = () => {
{...workingPointSymbolLayer}
id={LAYER_IDS.working}
source={"points"}
source-layer={"public.points_with_dist"}
source-layer={getSourceLayerName()}
layout={{
...workingPointSymbolLayer.layout,
visibility: isVisible[LAYER_IDS.working] ? "visible" : "none",

@ -1,6 +1,29 @@
const POINT_SIZE = 5;
const UNMATCH_POINT_SIZE = 3;
// const getPendingColor = () => {
// const { prediction } = usePendingPointsFilters();
//
// const getValue = (multiply) => {
// const difference = prediction[1] - prediction[0];
// const value = prediction[0] + (difference * multiply);
// return Math.floor(value);
// }
//
// return {
// property: "prediction_current",
// stops: [
// [getValue(0), "#FDEBF0"],
// [getValue(0.1), "#F8C7D8"],
// [getValue(0.25), "#F398BC"],
// [getValue(0.4), "#EE67A1"],
// [getValue(0.55), "#B64490"],
// [getValue(0.7), "#7E237E"],
// [getValue(0.85), "#46016C"],
// ],
// };
// }
export const PENDING_COLOR = {
property: "prediction_current",
stops: [
@ -13,6 +36,7 @@ export const PENDING_COLOR = {
[251, "#46016C"],
],
};
export const CANCELLED_COLOR = "#CC2222";
export const APPROVE_COLOR = "#ff7d00";
export const WORKING_COLOR = "#006e01";

@ -4,6 +4,7 @@ import { STATUSES } from "./config";
import { usePointSelection } from "./stores/usePointSelection";
import { RANGE_FILTERS_KEYS, usePendingPointsFilters } from "./stores/usePendingPointsFilters";
import { fieldHasChanged } from "./utils.js";
import { useMode } from "./stores/useMode.js";
export const BASE_URL = import.meta.env.VITE_API_URL;
@ -17,6 +18,18 @@ export const api = axios.create({
xsrfCookieName: "csrftoken",
});
export const getApiName = () => {
const {isImportMode} = useMode();
if (isImportMode) return "pre_placement_points";
return "placement_points";
}
export const getSourceLayerName = () => {
const {isImportMode} = useMode();
if (isImportMode) return "public.service_preplacementpoint";
return "public.points_with_dist";
}
const enrichParamsWithRegionFilter = (params, region) => {
const resultParams = params ? params : new URLSearchParams();
@ -33,11 +46,11 @@ const enrichParamsWithRegionFilter = (params, region) => {
return resultParams;
};
export const getPoints = async (params, region) => {
export const getPoints = async (params, region, link = "placement_points") => {
const resultParams = enrichParamsWithRegionFilter(params, region);
const { data } = await api.get(
`/api/placement_points/?${resultParams.toString()}`
`/api/${link}/?${resultParams.toString()}`
);
return data;
@ -54,9 +67,33 @@ export const exportPoints = async (params, region) => {
return data;
};
export const uploadPointsFile = async (file, config) => {
const formData = new FormData();
formData.append("file", file);
const { data } = await api.post(
`/api/pre_placement_points/load_matching_file/`,
formData,
config
);
return data;
};
export const importPoints = async (id) => {
const formData = new FormData();
formData.append("id", id);
const { data } = await api.post(
`/api/pre_placement_points/start_matching/`,
formData
);
return data;
};
export const useGetTotalInitialPointsCount = () => {
const link = getApiName();
return useQuery(
["all-initial-count"],
["all-initial-count", link],
async () => {
const params = new URLSearchParams({
page: 1,
@ -64,7 +101,7 @@ export const useGetTotalInitialPointsCount = () => {
"status[]": [STATUSES.pending],
});
return await getPoints(params);
return await getPoints(params, null, link);
},
{ select: (data) => data.count }
);
@ -114,12 +151,14 @@ export const useGetFilteredPendingPointsCount = () => {
return params;
}
const link = getApiName();
return useQuery(
["filtered-points", filters, includedIds],
["filtered-points", filters, link, includedIds],
async () => {
const params = getParams();
return await getPoints(params, region);
return await getPoints(params, region, link);
},
{ select: (data) => data.count, keepPreviousData: true }
);
@ -205,11 +244,13 @@ export const useLastMLRun = () => {
}
export const useGetPendingPointsRange = () => {
const link = getApiName();
return useQuery(
["prediction-max-min"],
["prediction-max-min", link],
async () => {
const { data } = await api.get(
`/api/placement_points/filters?status[]=${STATUSES.pending}`
`/api/${link}/filters?status[]=${STATUSES.pending}`
);
return data;
@ -241,6 +282,7 @@ export const useGetPendingPointsRange = () => {
export const useGetPopupPoints = (features) => {
const pointsIds = features.map(f => f.properties.id);
const link = getApiName();
const { data, isInitialLoading, isFetching } = useQuery(
["popup_data", features],
@ -250,7 +292,7 @@ export const useGetPopupPoints = (features) => {
});
const { data } = await api.get(
`/api/placement_points/?${params.toString()}`
`/api/${link}/?${params.toString()}`
);
return data.results;

@ -6,7 +6,7 @@ import { ApproveIcon } from "../icons/ApproveIcon";
import { WorkingIcon } from "../icons/WorkingIcon";
export const ModeSelector = () => {
const { mode, setMode } = useMode();
const { mode, setMode, isImportMode } = useMode();
const handleClick = (selectedMode) => {
setMode(selectedMode);
@ -47,6 +47,7 @@ export const ModeSelector = () => {
onClick={() => handleClick(MODES.WORKING)}
className="flex items-center justify-center"
size="large"
disabled={isImportMode}
/>
</Tooltip>
</>

@ -26,9 +26,9 @@
@apply bg-white-background rounded-xl max-h-[calc(100vh-100px)] overflow-y-auto;
}
.ant-modal-header {
border-bottom: none;
}
/*.ant-modal-header {*/
/* border-bottom: none;*/
/*}*/
.ant-select-multiple .ant-select-selection-item {
@apply !bg-rose;

@ -0,0 +1,91 @@
import { Button, Modal, Spin } from "antd";
import { useState } from "react";
import { useGetFilteredPendingPointsCount } from "../../api.js";
import { CheckCircleOutlined, InfoCircleOutlined, LoadingOutlined } from "@ant-design/icons";
import { useMode } from "../../stores/useMode.js";
export const AddPointsModal = ({isOpened, onClose}) => {
const {setImportMode} = useMode();
const [isLoading, setIsLoading] = useState(false);
const { data: filteredCount, isInitialLoading: isFilteredLoading } =
useGetFilteredPendingPointsCount();
const [isSuccess, setIsSuccess] = useState(false);
const onConfirm = () => {
setIsLoading(true);
setTimeout(() => {
setIsLoading(false);
setIsSuccess(true);
}, 2000);
}
const getFooter = () => {
if (isSuccess) return [
<Button
key="ok-button"
type="primary"
onClick={() => {
onClose();
setImportMode(false);
}}
disabled={isLoading}
>
Хорошо
</Button>,
];
return [
<Button
key="close-button"
type="default"
onClick={onClose}
>
Назад
</Button>,
<Button
key="ok-button"
type="primary"
onClick={() => onConfirm()}
disabled={isLoading}
>
Подтвердить
</Button>,
]
}
const getContent = () => {
if (isFilteredLoading) return <Spin />;
if (isLoading) return (
<div className="flex flex-col justify-center gap-2 items-center">
<Spin indicator={<LoadingOutlined style={{ fontSize: 32}} spin />} />
Добавляем точки...
</div>
);
if (isSuccess) return (
<div className="flex items-center justify-center font-bold gap-2">
<CheckCircleOutlined style={{ fontSize: 24, color: "#52C41A" }} />
Добавлено {filteredCount} новых точек
</div>
);
return (
<div className="flex flex-row gap-4">
<InfoCircleOutlined style={{ fontSize: 24, color: "#FFC53D" }} />
<div className="flex flex-col gap-2">
<p className="font-bold mb-0">Подтвердите добавление</p>
<p>В базу данных будет добавлено {filteredCount} новых точек.</p>
</div>
</div>
);
}
return (
<Modal
open={isOpened}
title="Добавить в базу"
onCancel={onClose}
width={400}
footer={getFooter()}
>
{getContent()}
</Modal>
);
}

@ -0,0 +1,45 @@
import { useLayoutEffect, useRef, useState } from "react";
import { uploadPointsFile } from "../../api.js";
import { Button, Upload } from "antd";
import { UploadOutlined } from "@ant-design/icons";
export const LoadingStage = ({setFileId}) => {
const ref = useRef(null);
const [isClicked, setIsClicked] = useState(true);
const onFileChange = async (options) => {
const { onSuccess, onError, file, onProgress } = options;
const config = {
onUploadProgress: event => {
const percent = Math.floor((event.loaded / event.total) * 100);
onProgress({ percent });
}
};
try {
const {id} = await uploadPointsFile(file, config);
setFileId(id);
onSuccess("Ok");
} catch (e) {
//
}
};
useLayoutEffect(() => {
if (ref && ref.current && !isClicked) {
ref.current.click();
setIsClicked(true);
}
}, [isClicked]);
return (
<>
<Upload
name='file'
accept='application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml'
customRequest={onFileChange}
>
<Button icon={<UploadOutlined />}>Выбрать файл .xlsx</Button>
</Upload>
</>
);
}

@ -0,0 +1,91 @@
import { Button, Modal, Spin } from "antd";
import { useState } from "react";
import { importPoints } from "../../api.js";
import { LoadingStage } from "./LoadingStage.jsx";
import { ReportStage } from "./ReportStage.jsx";
import { CheckCircleOutlined, LoadingOutlined } from "@ant-design/icons";
export const OnLoadModal = ({onClose, isOpened}) => {
const [fileId, setFileId] = useState(31);
const [report, setReport] = useState();
const [isImporting, setIsImporting] = useState(false);
const [isReportStage, setIsReportStage] = useState(false);
const onImportPoints = async () => {
setIsImporting(true);
try {
const { message } = await importPoints(fileId);
setReport(message);
} catch (e) {
console.log(e);
} finally {
setIsImporting(false);
}
}
const getFooter = () => {
if (isReportStage) return [
<Button
key="finish-button"
type="primary"
onClick={onClose}
>
Перейти к выбору
</Button>
]
if (report) return [
<Button
key="report-button"
type="primary"
onClick={() => setIsReportStage(true)}
>
Просмотреть отчет
</Button>
]
return [
<Button
key="close-button"
type="default"
onClick={onClose}
>
Отмена
</Button>,
<Button
key="ok-button"
type="primary"
onClick={() => onImportPoints()}
disabled={!fileId || isImporting}
>
Импортировать
</Button>,
]
}
const getContent = () => {
if (isImporting) return (
<div className="flex flex-col justify-center gap-2 items-center">
<Spin indicator={<LoadingOutlined style={{ fontSize: 64}} spin />} />
Импортируем точки...
</div>
);
if (isReportStage) return <ReportStage report={report} />;
if (report) return (
<div className="flex items-center justify-center font-bold gap-2">
<CheckCircleOutlined style={{ fontSize: 24, color: "#52C41A" }} />
Точки успешно импортированы
</div>
);
return <LoadingStage setFileId={setFileId} />;
}
return (
<Modal
open={isOpened}
title="Импорт точек"
onCancel={onClose}
width={400}
footer={getFooter()}
>
{getContent()}
</Modal>
);
}

@ -0,0 +1,34 @@
import { Col, Row } from "antd";
import { twMerge } from "tailwind-merge";
export const ReportStage = ({ report }) => {
return (
<>
<Row className={twMerge("p-1")}>
<Col className={"text-gray-600"} span={12}>
Всего точек:
</Col>
<Col span={12}>{report.total}</Col>
</Row>
<Row className={twMerge("p-1")}>
<Col className={"text-gray-600"} span={12}>
Совпадений:
</Col>
<Col span={12}>{report.matched}</Col>
</Row>
<Row className={twMerge("p-1")}>
<Col className={"text-gray-600"} span={12}>
Проблемные:
</Col>
<Col span={12}>{report.error}</Col>
</Row>
<Row className={twMerge("p-1")}>
<Col className={"text-gray-600"} span={12}>
Новые:
</Col>
<Col span={12}>{report.unmatched}</Col>
</Row>
</>
);
}

@ -0,0 +1,56 @@
import { useMode } from "../../stores/useMode.js";
import { Button } from "antd";
import { ImportOutlined } from "@ant-design/icons";
import { OnLoadModal } from "./OnLoadModal.jsx";
import { useState } from "react";
import { AddPointsModal } from "./AddPointsModal.jsx";
export const ImportModeSidebarButtons = () => {
const {isImportMode, setImportMode} = useMode();
const [loadModalOpen, setLoadModalOpen] = useState(false);
const [addPointsModalOpen, setAddPointsModalOpen] = useState(false);
const onCancel = () => {
setImportMode(false);
};
const onImport = () => {
setImportMode(true);
setLoadModalOpen(true);
};
if (isImportMode) {
return (
<div className="flex flex-row flex-0 gap-2 border-t-[1px] border-b-[1px]">
<Button type="default" onClick={onCancel}>
Отмена
</Button>
<Button type="primary" className="flex-1" onClick={() => setAddPointsModalOpen(true)}>
Добавить в базу
</Button>
{loadModalOpen &&
<OnLoadModal
isOpened={loadModalOpen}
onClose={() => setLoadModalOpen(false)}
/>
}
{addPointsModalOpen &&
<AddPointsModal
isOpened={addPointsModalOpen}
onClose={() => setAddPointsModalOpen(false)}
/>
}
</div>
);
}
return (
<div className="flex flex-col flex-0 border-t-[1px] border-b-[1px]">
<Button type="default" onClick={onImport}>
<ImportOutlined />
Импортировать
</Button>
</div>
);
}

@ -5,6 +5,7 @@ import { MODES } from "../../config";
import { PendingPointsFilters } from "./PendingPointsFilters/PendingPointsFilters";
import { OnApprovalPointsFilters } from "./OnApprovalPointsFilters/OnApprovalPointsFilters";
import { WorkingPointsFilters } from "./WorkingPointsFilters/WorkingPointsFilters";
import { ImportModeSidebarButtons } from "../ImportMode/SidebarButtons.jsx";
export const Sidebar = forwardRef(({ isCollapsed }, ref) => {
const { mode } = useMode();
@ -29,6 +30,7 @@ export const Sidebar = forwardRef(({ isCollapsed }, ref) => {
)}
ref={ref}
>
<ImportModeSidebarButtons />
<div className="flex flex-col flex-1">{getFilters()}</div>
</div>
);

@ -1,5 +1,5 @@
import { useQuery } from "@tanstack/react-query";
import { getPoints } from "../../../api";
import { getApiName, getPoints } from "../../../api";
import { useMergeTableData } from "../useMergeTableData";
import { STATUSES } from "../../../config";
import { RANGE_FILTERS_KEYS, usePendingPointsFilters } from "../../../stores/usePendingPointsFilters";
@ -13,6 +13,8 @@ export const usePendingTableData = (page, resetPage, pageSize, setPageSize, sort
region,
} = filters;
const link = getApiName();
const getParams = () => {
const params = new URLSearchParams({
page,
@ -46,11 +48,11 @@ export const usePendingTableData = (page, resetPage, pageSize, setPageSize, sort
}
const {data, isInitialLoading, isFetching} = useQuery(
["table", page, filters, sort],
["table", page, filters, sort, link],
async () => {
const params = getParams();
return await getPoints(params, region);
return await getPoints(params, region, link);
},
{
keepPreviousData: true,

@ -5,12 +5,18 @@ import { persist } from "zustand/middleware";
const store = (set) => ({
mode: MODES.PENDING,
isImportMode: false,
setMode: (mode) => {
set((state) => {
state.mode = mode;
});
},
setImportMode: (value) => {
set((state) => {
state.isImportMode = value
});
}
});
export const useMode = create(persist(immer(store), { name: "postnet/mode" }));

Loading…
Cancel
Save