Skip to content

Commit 9a21634

Browse files
authored
Merge pull request #23 from Feazom/dev
Dev
2 parents b664f41 + e294776 commit 9a21634

File tree

6 files changed

+126
-26
lines changed

6 files changed

+126
-26
lines changed

UrfuMaps.Client/src/components/MapCanvas.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from '../services/RequestService';
2020
import URLImage from './URLImage';
2121
import RouteSegmentDTO from '../DTOs/RouteSegmentDTO';
22-
import { canvaPosition } from '../services/utils';
22+
import { canvaPosition, toFrontName } from '../services/utils';
2323
import { OrientationContext } from '../context';
2424
import MarkCanvas from './MarkCanvas';
2525
import { Point } from '../types';
@@ -215,17 +215,23 @@ const MapCanvas = ({
215215
/>
216216
)}
217217

218-
{destinationMarker &&
218+
{imageRef.current &&
219+
destinationMarker &&
219220
segment?.ids.includes(destinationMarker.id) && (
220221
<MarkCanvas
221222
x={destinationMarker.x}
222223
y={destinationMarker.y}
223224
color="red"
224225
/>
225226
)}
226-
{sourceMarker && segment?.ids.includes(sourceMarker.id) && (
227-
<PointCanvas x={sourceMarker.x} y={sourceMarker.y} />
228-
)}
227+
{imageRef.current &&
228+
sourceMarker &&
229+
segment?.ids.includes(sourceMarker.id) && (
230+
<PointCanvas
231+
x={sourceMarker.x}
232+
y={sourceMarker.y}
233+
/>
234+
)}
229235
{/*imageRef.current &&
230236
floor?.positions?.map((position) => {
231237
const backgroundHeight =
@@ -247,7 +253,7 @@ const MapCanvas = ({
247253
<TextCanvas
248254
x={x}
249255
y={y}
250-
text={position.id.toString()}
256+
text={toFrontName(position.name)}
251257
key={position.id}
252258
/>
253259
);

UrfuMaps.Client/src/components/NavAddMap.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import CreateFloorDTO from '../DTOs/CreateFloorDTO';
1111
import CreatePositionDTO from '../DTOs/CreatePositionDTO';
1212
import { logout } from '../services/AuthService';
1313
import { addMap } from '../services/RequestService';
14-
import { convertCabinet } from '../services/utils';
14+
import { toApiName } from '../services/utils';
1515
import '../styles/navMap.css';
1616
import { EdgeDTODict } from '../types';
1717

@@ -62,14 +62,15 @@ const NavAddMap = ({
6262
imageLink: link,
6363
positions: positions.map((p) => ({
6464
localId: p.localId,
65-
name: convertCabinet(p.name),
65+
name: toApiName(p.name),
6666
description: p.description,
6767
type: p.type,
6868
x: p.x,
6969
y: p.y,
7070
})),
7171
edges: edges.current.keys(),
7272
};
73+
7374
console.log(data);
7475

7576
if (

UrfuMaps.Client/src/components/NavMap.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
useMemo,
1111
} from 'react';
1212
import '../styles/navMap.css';
13-
import { convertCabinet } from '../services/utils';
13+
import { toApiName } from '../services/utils';
1414
import { OrientationContext } from '../context';
1515
import { useQuery } from 'react-query';
1616
import { getPrefixes, wrapRequest } from '../services/RequestService';
@@ -78,14 +78,14 @@ const NavMap = ({
7878
useEffect(() => {
7979
window.clearTimeout(timeoutSrc.current);
8080
timeoutSrc.current = window.setTimeout(() => {
81-
setSource(convertCabinet(sourceInput, buildingName));
81+
setSource(toApiName(sourceInput, buildingName));
8282
}, 300);
8383
}, [sourceInput]);
8484

8585
useEffect(() => {
8686
window.clearTimeout(timeoutDst.current);
8787
timeoutDst.current = window.setTimeout(() => {
88-
setDestination(convertCabinet(destinationInput, buildingName));
88+
setDestination(toApiName(destinationInput, buildingName));
8989
}, 300);
9090
}, [destinationInput]);
9191

UrfuMaps.Client/src/context.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,35 @@ export const OrientationContext = createContext('landscape');
55

66
i18next.init({
77
lng: 'ru',
8-
debug: true,
98
resources: {
109
ru: {
1110
translation: {
12-
r: 'Р',
11+
a: 'а',
12+
b: 'б',
13+
v: 'в',
14+
g: 'г',
15+
d: 'д',
16+
e: 'э',
17+
j: 'ж',
18+
z: 'з',
19+
i: 'и',
20+
k: 'к',
21+
l: 'л',
22+
m: 'м',
23+
n: 'н',
24+
o: 'о',
25+
p: 'п',
26+
r: 'р',
27+
s: 'с',
28+
t: 'т',
29+
u: 'у',
30+
f: 'ф',
31+
h: 'х',
32+
c: 'с',
33+
ch: 'ч',
34+
sh: 'ш',
35+
wcw: 'СУ Ж',
36+
entryrtf: 'Вход',
1337
rtf: 'ИРИТ-РТФ',
1438
hti: 'ХТИ',
1539
fti: 'ФТИ',

UrfuMaps.Client/src/pages/MainPage.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ const Main = memo(() => {
3636
const [queryParams] = useSearchParams();
3737
const [orientation, setOrientation] = useState('landscape');
3838

39+
useEffect(() => {
40+
if (buildings && buildingName && floorNumber) {
41+
if (!buildings[buildingName].includes(floorNumber)) {
42+
setFloorNumber(1);
43+
}
44+
}
45+
}, [buildings, buildingName]);
46+
3947
useEffect(() => {
4048
const type = window.screen.orientation.type;
4149
setOrientation(type.substring(0, type.indexOf('-')));

UrfuMaps.Client/src/services/utils.ts

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Vector2d } from 'konva/lib/types';
2+
import { t } from '../context';
23

34
const special = /[\s`~!@#$%^&*()\-_=+[\]{};:'"\\|/,.<>?]/g;
45

@@ -12,38 +13,95 @@ const translation: Record<string, string> = {
1213
а: 'a',
1314
б: 'b',
1415
в: 'v',
15-
ф: 'f',
16+
г: 'g',
17+
д: 'd',
18+
е: 'e',
19+
ж: 'j',
20+
з: 'z',
21+
и: 'i',
22+
к: 'k',
23+
л: 'l',
24+
м: 'm',
25+
н: 'n',
26+
о: 'o',
27+
п: 'p',
28+
р: 'r',
29+
с: 's',
1630
т: 't',
31+
у: 'u',
32+
ф: 'f',
1733
х: 'h',
34+
ц: 'c',
35+
ч: 'ch',
36+
ш: 'sh',
1837
мт: 'mt',
19-
и: 'i',
2038
гук: 'mab',
21-
м: 'm',
2239
э: 'e',
2340
сп: 'sp',
24-
с: 's',
25-
р: 'r',
2641
вход: 'entry',
2742
a: 'a',
2843
b: 'b',
2944
v: 'v',
30-
f: 'f',
45+
g: 'g',
46+
d: 'd',
47+
e: 'e',
48+
j: 'j',
49+
z: 'z',
50+
i: 'i',
51+
k: 'k',
52+
l: 'l',
53+
m: 'm',
54+
n: 'n',
55+
o: 'o',
56+
p: 'p',
57+
r: 'r',
58+
s: 's',
3159
t: 't',
60+
u: 'u',
61+
f: 'f',
3262
h: 'h',
63+
c: 'c',
64+
ch: 'ch',
65+
sh: 'sh',
3366
mt: 'mt',
34-
i: 'i',
3567
mab: 'mab',
36-
m: 'm',
37-
e: 'e',
3868
sp: 'sp',
39-
s: 's',
40-
r: 'r',
4169
entry: 'entry',
4270
};
4371

4472
const tr = new Proxy(translation, propertyHandler);
4573

46-
export function convertCabinet(cabinet: string, building?: string): string {
74+
export function toFrontName(name: string) {
75+
let result = name.toString();
76+
if (!result && result === '') {
77+
return result;
78+
}
79+
result = result.replace(special, '');
80+
let numberIndex: number | undefined = undefined;
81+
let postfixSize = 0;
82+
for (let i = 0; i < result.length; i++) {
83+
if (!isNaN(parseInt(result[i]))) {
84+
numberIndex = i;
85+
break;
86+
}
87+
}
88+
for (let i = result.length - 1; i >= 0; i--) {
89+
if (!isNaN(parseInt(result[i]))) {
90+
break;
91+
}
92+
postfixSize++;
93+
}
94+
if (numberIndex) {
95+
return (result =
96+
t(result.slice(0, numberIndex)) +
97+
' ' +
98+
result.substring(numberIndex, result.length - postfixSize) +
99+
t(result.substring(result.length - postfixSize)));
100+
}
101+
return t(result);
102+
}
103+
104+
export function toApiName(cabinet: string, building?: string): string {
47105
let result = cabinet.toLowerCase();
48106
if (!result) {
49107
return result;
@@ -69,11 +127,14 @@ export function convertCabinet(cabinet: string, building?: string): string {
69127
result.substring(numberIndex, result.length - postfixSize) +
70128
tr[result.substring(result.length - postfixSize)];
71129
} else {
72-
result = tr[result];
130+
result = tr[result.slice(0, 5)];
73131
}
74132
if (building) {
75133
if (result.slice(0, 5) === 'entry') {
76134
result += building;
135+
if (building === 'mab') {
136+
result += 'm';
137+
}
77138
}
78139
}
79140
return result;

0 commit comments

Comments
 (0)