more fixes

This commit is contained in:
Spynder 2025-05-06 17:56:05 +03:00
parent 86947d6332
commit fba2fb0f5c
12 changed files with 366 additions and 316 deletions

View File

@ -177,6 +177,17 @@ function App() {
icon: <StationIcon />, icon: <StationIcon />,
}, },
}, },
{
name: "stationmodal",
show: "/route/:id/station",
edit: "/route/:id/station/",
meta: {
hide: true,
canDelete: true,
label: "Маршруты",
icon: <RouteIcon />,
},
},
{ {
name: "vehicle", name: "vehicle",
list: "/vehicle", list: "/vehicle",

View File

@ -34,6 +34,7 @@ import { articleStore } from "../store/ArticleStore";
import { ArticleEditModal } from "./modals/ArticleEditModal"; import { ArticleEditModal } from "./modals/ArticleEditModal";
import { StationEditModal } from "./modals/StationEditModal"; import { StationEditModal } from "./modals/StationEditModal";
import { stationStore } from "../store/StationStore"; import { stationStore } from "../store/StationStore";
function insertAtPosition<T>(arr: T[], pos: number, value: T): T[] { function insertAtPosition<T>(arr: T[], pos: number, value: T): T[] {
const index = pos - 1; const index = pos - 1;
if (index >= arr.length) { if (index >= arr.length) {
@ -90,7 +91,8 @@ export const LinkedItems = <T extends { id: number; [key: string]: any }>({
}: LinkedItemsProps<T>) => { }: LinkedItemsProps<T>) => {
const { language } = languageStore; const { language } = languageStore;
const { setArticleModalOpenAction, setArticleIdAction } = articleStore; const { setArticleModalOpenAction, setArticleIdAction } = articleStore;
const { setStationModalOpenAction, setStationIdAction } = stationStore; const { setStationModalOpenAction, setStationIdAction, setRouteIdAction } =
stationStore;
const [position, setPosition] = useState<number>(1); const [position, setPosition] = useState<number>(1);
const [items, setItems] = useState<T[]>([]); const [items, setItems] = useState<T[]>([]);
const [linkedItems, setLinkedItems] = useState<T[]>([]); const [linkedItems, setLinkedItems] = useState<T[]>([]);
@ -306,7 +308,6 @@ export const LinkedItems = <T extends { id: number; [key: string]: any }>({
isDragDisabled={type !== "edit" || !dragAllowed} isDragDisabled={type !== "edit" || !dragAllowed}
> >
{(provided) => ( {(provided) => (
<>
<TableRow <TableRow
sx={{ sx={{
cursor: cursor:
@ -322,6 +323,7 @@ export const LinkedItems = <T extends { id: number; [key: string]: any }>({
if (childResource === "station") { if (childResource === "station") {
setStationModalOpenAction(true); setStationModalOpenAction(true);
setStationIdAction(item.id); setStationIdAction(item.id);
setRouteIdAction(Number(parentId));
} }
}} }}
ref={provided.innerRef} ref={provided.innerRef}
@ -365,7 +367,6 @@ export const LinkedItems = <T extends { id: number; [key: string]: any }>({
</TableCell> </TableCell>
)} )}
</TableRow> </TableRow>
</>
)} )}
</Draggable> </Draggable>
))} ))}

View File

@ -20,6 +20,9 @@ import { LanguageSwitch } from "../../LanguageSwitch/index";
import { useState } from "react"; import { useState } from "react";
import { stationStore } from "../../../store/StationStore"; import { stationStore } from "../../../store/StationStore";
import { useCustom } from "@refinedev/core";
import { useApiUrl } from "@refinedev/core";
import { StationItem } from "src/pages/route/types";
const MemoizedSimpleMDE = memo(MarkdownEditor); const MemoizedSimpleMDE = memo(MarkdownEditor);
const TRANSFER_FIELDS = [ const TRANSFER_FIELDS = [
@ -47,7 +50,7 @@ const style = {
}; };
export const StationEditModal = observer(() => { export const StationEditModal = observer(() => {
const { stationModalOpen, setStationModalOpenAction, selectedStationId } = const { stationModalOpen, setStationModalOpenAction, selectedStationId, selectedRouteId } =
stationStore; stationStore;
const { language } = languageStore; const { language } = languageStore;
@ -57,6 +60,14 @@ export const StationEditModal = observer(() => {
}; };
}, []); }, []);
const apiUrl = useApiUrl();
const { data: stationQuery, isLoading: isStationLoading } = useCustom({
url: `${apiUrl}/route/${selectedRouteId ?? 1}/station`,
method: 'get'
});
const { const {
register, register,
control, control,
@ -65,14 +76,15 @@ export const StationEditModal = observer(() => {
reset, reset,
setValue, setValue,
watch, watch,
handleSubmit,
} = useForm({ } = useForm({
refineCoreProps: { refineCoreProps: {
resource: "station", resource: `route/${selectedRouteId ?? 1}/station`,
id: selectedStationId ?? undefined,
action: "edit", action: "edit",
id: "",
redirect: false, redirect: false,
onMutationSuccess: (data) => {
onMutationSuccess: () => { console.log(data);
setStationModalOpenAction(false); setStationModalOpenAction(false);
reset(); reset();
window.location.reload(); window.location.reload();
@ -85,6 +97,19 @@ export const StationEditModal = observer(() => {
}, },
}); });
useEffect(() => {
if (stationModalOpen) {
const station = stationQuery?.data?.find((station: StationItem) => station.id === selectedStationId);
if(!station) return;
for(const key in station) {
setValue(key, station[key]);
console.log(key, station[key]);
}
setValue("station_id", station.id);
console.log(stationQuery);
}
}, [stationModalOpen, stationQuery]);
return ( return (
<Modal <Modal
open={stationModalOpen} open={stationModalOpen}

View File

@ -163,6 +163,7 @@ export function InfiniteCanvas({children} : Readonly<{children?: ReactNode}>) {
> >
{children} {children}
</pixiContainer> </pixiContainer>
{/* Show center of the screen.
<pixiGraphics <pixiGraphics
eventMode="none" eventMode="none"
@ -172,7 +173,7 @@ export function InfiniteCanvas({children} : Readonly<{children?: ReactNode}>) {
g.circle(center.x, center.y, 1); g.circle(center.x, center.y, 1);
g.fill("#fff"); g.fill("#fff");
}} }}
/> /> */}
</ErrorBoundary> </ErrorBoundary>
); );
} }

View File

@ -59,6 +59,7 @@ export function MapDataProvider({ children }: Readonly<{ children: ReactNode }>)
url: `${apiUrl}/route/${routeId}`, url: `${apiUrl}/route/${routeId}`,
method: 'get', method: 'get',
}); });
const { data: stationQuery, isLoading: isStationLoading } = useCustom({ const { data: stationQuery, isLoading: isStationLoading } = useCustom({
url: `${apiUrl}/route/${routeId}/station`, url: `${apiUrl}/route/${routeId}/station`,
method: 'get' method: 'get'

View File

@ -52,7 +52,7 @@ export function RightSidebar() {
} }
function pan({x, y}: {x: number, y: number}) { function pan({x, y}: {x: number, y: number}) {
const coordinates = coordinatesToLocal(y,x); const coordinates = coordinatesToLocal(x,y);
setTransform(coordinates.x, coordinates.y); setTransform(coordinates.x, coordinates.y);
} }
@ -144,7 +144,7 @@ export function RightSidebar() {
<Stack direction="row" spacing={2}> <Stack direction="row" spacing={2}>
<TextField <TextField
type="number" type="number"
label="Центр карты X" label="Центр карты, широта"
variant="filled" variant="filled"
value={Math.round(localCenter.x*100000)/100000} value={Math.round(localCenter.x*100000)/100000}
onChange={(e) => { onChange={(e) => {
@ -160,7 +160,7 @@ export function RightSidebar() {
/> />
<TextField <TextField
type="number" type="number"
label="Центр карты Y" label="Центр карты, высота"
variant="filled" variant="filled"
value={Math.round(localCenter.y*100000)/100000} value={Math.round(localCenter.y*100000)/100000}
onChange={(e) => { onChange={(e) => {

View File

@ -77,8 +77,6 @@ export function RouteMap() {
return; return;
} }
console.log("Use effect fired")
if ( if (
originalRouteData?.center_latitude === originalRouteData?.center_longitude && originalRouteData?.center_latitude === originalRouteData?.center_longitude &&
originalRouteData?.center_latitude === 0 originalRouteData?.center_latitude === 0
@ -99,7 +97,6 @@ export function RouteMap() {
y: -(boundingBox.from.y + boundingBox.to.y) / 2 y: -(boundingBox.from.y + boundingBox.to.y) / 2
}; };
setPosition(newCenter); setPosition(newCenter);
console.log("Taking easy way out", originalRouteData)
setIsSetup(true); setIsSetup(true);
} }
} else if ( } else if (
@ -114,7 +111,6 @@ export function RouteMap() {
originalRouteData?.rotate, originalRouteData?.rotate,
originalRouteData?.scale_min originalRouteData?.scale_min
); );
console.log("Setup complete")
setIsSetup(true); setIsSetup(true);
} }
}, [points, originalRouteData?.center_latitude, originalRouteData?.center_longitude, originalRouteData?.rotate, isSetup, screenCenter]); }, [points, originalRouteData?.center_latitude, originalRouteData?.center_longitude, originalRouteData?.rotate, isSetup, screenCenter]);

View File

@ -1,14 +1,14 @@
// approximation // approximation
export function coordinatesToLocal(longitude: number, latitude: number) { export function coordinatesToLocal(latitude: number, longitude: number) {
return { return {
x: latitude, x: longitude,
y: -longitude*2 y: -latitude*2,
} }
} }
export function localToCoordinates(x: number, y: number) { export function localToCoordinates(x: number, y: number) {
return { return {
latitude: x, longitude: x,
longitude: -y/2 latitude: -y/2,
} }
} }

View File

@ -4,6 +4,8 @@ export type StationItem = {
id: number; id: number;
name: string; name: string;
description: string; description: string;
offset_x: number;
offset_y: number;
[key: string]: string | number; [key: string]: string | number;
}; };

View File

@ -460,13 +460,13 @@ export const SightEdit = observer(() => {
}, },
}} }}
> >
<Box sx={{ display: "flex", gap: 2, position: "relative" }}> <Box sx={{ display: "flex", flexDirection: "row", gap: 2 }}>
<Box sx={{ display: "flex", gap: 2, position: "relative", flex:1 }}>
<Box <Box
sx={{ sx={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
flex: 1, flex: 1,
maxWidth: "50%",
gap: 10, gap: 10,
justifyContent: "space-between", justifyContent: "space-between",
}} }}
@ -830,9 +830,10 @@ export const SightEdit = observer(() => {
</Box> </Box>
{/* Блок предпросмотра */} {/* Блок предпросмотра */}
</Box>
<Paper <Paper
sx={{ sx={{
position: "fixed",
p: 2, p: 2,
width: "30%", width: "30%",
@ -1014,11 +1015,12 @@ export const SightEdit = observer(() => {
}, },
}} }}
> >
<Box sx={{ display: "flex", flexDirection: "row", gap: 2 }}>
<Box <Box
sx={{ sx={{
maxWidth: "50%", // display: "flex",
display: "flex", flex:1,
flexDirection: "column", // flexDirection: "column",
gap: 2, gap: 2,
position: "relative", position: "relative",
}} }}
@ -1098,14 +1100,14 @@ export const SightEdit = observer(() => {
/> />
</Box> </Box>
</Box> </Box>
</Edit> {/* Предпросмотр */}
<Paper <Paper
sx={{ sx={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
position: "fixed",
p: 0, p: 0,
height: "max-content", height: "max-content",
minWidth: "400px",
width: "30%", width: "30%",
top: "178px", top: "178px",
@ -1383,6 +1385,8 @@ export const SightEdit = observer(() => {
} }
</Box> </Box>
</Paper> </Paper>
</Box>
</Edit>
</CustomTabPanel> </CustomTabPanel>
<CustomTabPanel value={tabValue} index={2}> <CustomTabPanel value={tabValue} index={2}>
@ -1395,10 +1399,11 @@ export const SightEdit = observer(() => {
}, },
}} }}
> >
<Box sx={{ display: "flex", flexDirection: "row", gap: 2 }}>
<Box <Box
sx={{ sx={{
maxWidth: "50%",
display: "flex", display: "flex",
flex: 1,
gap: 2, gap: 2,
position: "relative", position: "relative",
}} }}
@ -1616,11 +1621,11 @@ export const SightEdit = observer(() => {
/> />
</Box> </Box>
{/* Предпросмотр */}
<Paper <Paper
sx={{ sx={{
position: "fixed",
p: 2, p: 2,
minWidth: "fit-content",
width: "30%", width: "30%",
top: "178px", top: "178px",
@ -1758,6 +1763,7 @@ export const SightEdit = observer(() => {
</Box> </Box>
</Paper> </Paper>
</Box> </Box>
</Box>
</Edit> </Edit>
</CustomTabPanel> </CustomTabPanel>
<ArticleEditModal /> <ArticleEditModal />

View File

@ -55,6 +55,7 @@ export const StationList = observer(() => {
display: "flex", display: "flex",
align: "left", align: "left",
headerAlign: "left", headerAlign: "left",
flex: 1,
}, },
{ {
field: "system_name", field: "system_name",
@ -64,6 +65,7 @@ export const StationList = observer(() => {
display: "flex", display: "flex",
align: "left", align: "left",
headerAlign: "left", headerAlign: "left",
flex: 1,
}, },
{ {
field: "direction", field: "direction",
@ -123,15 +125,15 @@ export const StationList = observer(() => {
align: "left", align: "left",
headerAlign: "left", headerAlign: "left",
}, },
{ // {
field: "description", // field: "description",
headerName: "Описание", // headerName: "Описание",
type: "string", // type: "string",
display: "flex", // display: "flex",
align: "left", // align: "left",
headerAlign: "left", // headerAlign: "left",
flex: 1, // flex: 1,
}, // },
{ {
field: "actions", field: "actions",
headerName: "Действия", headerName: "Действия",

View File

@ -3,6 +3,7 @@ import { makeAutoObservable } from "mobx";
class StationStore { class StationStore {
stationModalOpen: boolean = false; stationModalOpen: boolean = false;
selectedStationId: number | null = null; selectedStationId: number | null = null;
selectedRouteId: number | null = null;
constructor() { constructor() {
makeAutoObservable(this); makeAutoObservable(this);
@ -12,6 +13,10 @@ class StationStore {
this.selectedStationId = id; this.selectedStationId = id;
}; };
setRouteIdAction = (id: number) => {
this.selectedRouteId = id;
};
setStationModalOpenAction = (open: boolean) => { setStationModalOpenAction = (open: boolean) => {
this.stationModalOpen = open; this.stationModalOpen = open;
}; };