Compare commits
681 Commits
v0.2.14
...
bb75b70341
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb75b70341 | ||
|
|
585891b0f8 | ||
|
|
c4ed5e71b1 | ||
|
|
824eadc363 | ||
|
|
afab4bb521 | ||
|
|
bf29c666a5 | ||
|
|
4708f98ee9 | ||
|
|
0d465e47b3 | ||
|
|
8ec1fa1761 | ||
|
|
11185282c4 | ||
|
|
492f1f1e55 | ||
|
|
241ab99584 | ||
|
|
8bd5b5c62f | ||
|
|
7e21258d2e | ||
|
|
49277cfdd4 | ||
|
|
1f6dc3cd75 | ||
|
|
7350b0985c | ||
|
|
73bc6dc99c | ||
|
|
095645a209 | ||
|
|
532977056d | ||
|
|
2435f58256 | ||
|
|
ceb560c658 | ||
|
|
d88c239bf6 | ||
|
|
01c4ff2e14 | ||
|
|
c2890e1f3d | ||
|
|
e1ea44c68c | ||
|
|
cec2361b00 | ||
|
|
9672b9949c | ||
|
|
e4e9594a9d | ||
|
|
6daa5202b1 | ||
|
|
cae47da5f2 | ||
|
|
85c7c89c28 | ||
|
|
0d80266e9b | ||
|
|
a604d62d44 | ||
|
|
2cbbfd21aa | ||
|
|
1c17d07497 | ||
|
|
ad15becd7a | ||
|
|
c2a6272413 | ||
|
|
c51af13fb1 | ||
|
|
d9d8562539 | ||
|
|
6891631b8d | ||
|
|
738d58b5f1 | ||
|
|
3081125716 | ||
|
|
6073c7ab43 | ||
|
|
8157dc7a60 | ||
|
|
3b130e9208 | ||
|
|
ab81434c4e | ||
|
|
62c54dc1eb | ||
|
|
347802b2a4 | ||
|
|
a5a8d98984 | ||
|
|
5b42da8290 | ||
|
|
4e041f36ce | ||
|
|
22926b7266 | ||
|
|
0a7f032028 | ||
|
|
4edec5e72d | ||
|
|
c7d524c76a | ||
|
|
9ed558562b | ||
|
|
43f5c1a764 | ||
|
|
46149c09db | ||
|
|
a0757efe8b | ||
|
|
10f4b9d8e2 | ||
|
|
42db496ad7 | ||
|
|
d6fd672409 | ||
|
|
60eb1c9f51 | ||
|
|
a09c804595 | ||
|
|
a17f73fd54 | ||
|
|
2373ae4b8c | ||
|
|
16dd460469 | ||
|
|
58f109ca91 | ||
|
|
75da9c0f4b | ||
|
|
833b918c5b | ||
|
|
72c2691a17 | ||
|
|
cf79bc7bd5 | ||
|
|
f5f2f2cdef | ||
|
|
19a9bab8c2 | ||
|
|
6e221ef8c1 | ||
|
|
e142f56706 | ||
|
|
a794f22366 | ||
|
|
cfe4903c79 | ||
|
|
a0a473f96c | ||
|
|
9e4dd3b4c7 | ||
|
|
e5db0334c0 | ||
|
|
d641ad1bbb | ||
|
|
18393ff661 | ||
|
|
b2a82fba30 | ||
|
|
f6c2fd627f | ||
|
|
15d9b31cb6 | ||
|
|
06cc1663b3 | ||
|
|
88a4b2d69c | ||
|
|
e6072d25c5 | ||
|
|
fc2b65601e | ||
|
|
597bdde7e1 | ||
|
|
f56092e86c | ||
|
|
d5cfe59f47 | ||
|
|
f281eaa662 | ||
|
|
cbb3ed7c48 | ||
|
|
41a0b85376 | ||
|
|
b5a31ee81c | ||
|
|
dceb031822 | ||
|
|
78bc9fc432 | ||
|
|
b9072e4d7c | ||
|
|
5d97e63f93 | ||
|
|
957f5bf9f0 | ||
|
|
6833ac5fad | ||
|
|
3dff2ced6c | ||
|
|
ea7ff3796f | ||
|
|
310617d62b | ||
|
|
1d94e82f4b | ||
|
|
00dad5d673 | ||
|
|
414c6957e7 | ||
|
|
f127298e5a | ||
|
|
f49899e66d | ||
|
|
5717c88857 | ||
|
|
ae8aa16208 | ||
|
|
4ed8e7b421 | ||
|
|
3dd6808ea2 | ||
|
|
f2b426851b | ||
|
|
f9e0833bcf | ||
|
|
11b073c2fd | ||
|
|
1320884409 | ||
|
|
aea2c39215 | ||
|
|
4c2464ab30 | ||
|
|
26053a5fd8 | ||
|
|
589220a2ba | ||
|
|
2cda54633f | ||
|
|
3eea6b9e88 | ||
|
|
db9bb7e168 | ||
|
|
3ccd094a22 | ||
|
|
032f21edaa | ||
|
|
42eb087363 | ||
|
|
d0ff449e3b | ||
|
|
858f5137d8 | ||
|
|
80d5dd0761 | ||
|
|
49b31c6e92 | ||
|
|
8ed2fbbe34 | ||
|
|
5ae8d13719 | ||
|
|
7bf2b81229 | ||
|
|
0215f2824a | ||
|
|
3fdb7e4e37 | ||
|
|
a3f578ebac | ||
|
|
f0bc7abaad | ||
|
|
f9d9231d50 | ||
|
|
465db82bd9 | ||
|
|
885a48bdd8 | ||
|
|
c915b3287b | ||
|
|
7b2f021509 | ||
|
|
5f1bdfefca | ||
|
|
3273a43e20 | ||
|
|
61e439a1d4 | ||
|
|
03808a8b3b | ||
|
|
57aa0ed8e3 | ||
|
|
5efee3f044 | ||
|
|
6588f310f2 | ||
|
|
25b54afff4 | ||
|
|
b9a7f9a03f | ||
|
|
e36324af6f | ||
|
|
60cb45dcca | ||
|
|
215be3cf09 | ||
|
|
b2aa966588 | ||
|
|
67512ac151 | ||
|
|
3f5dedbd6e | ||
|
|
ce07105eea | ||
|
|
587470c48b | ||
|
|
3227d341ed | ||
|
|
2b16a80ef8 | ||
|
|
8b742bbe09 | ||
|
|
189d3d2fc5 | ||
|
|
082093ea17 | ||
|
|
280f314100 | ||
|
|
163a6262c8 | ||
|
|
e8a564aed3 | ||
|
|
53464dfcbf | ||
|
|
b364a6606d | ||
|
|
f09e476bb6 | ||
|
|
e2c9cc4347 | ||
|
|
06106dc31b | ||
|
|
8e3c85991c | ||
|
|
d3e5418221 | ||
|
|
0d0e54032c | ||
|
|
a8de16f66d | ||
|
|
5b2e0e976f | ||
|
|
d601134535 | ||
|
|
dff320d534 | ||
|
|
96cde3ca0d | ||
|
|
6ba0124779 | ||
|
|
34c68858a3 | ||
|
|
4c8cfd4f80 | ||
|
|
85c5d7ccf9 | ||
|
|
46a0d2b9db | ||
|
|
c9b4841f67 | ||
|
|
d62cc2add6 | ||
|
|
9c36e76eaa | ||
|
|
abd8cba7a5 | ||
|
|
e6c4cb7e75 | ||
|
|
3d4435bac5 | ||
|
|
4146d0820b | ||
|
|
dbaa32f589 | ||
|
|
2b8eae67b9 | ||
|
|
225bdc2bb6 | ||
|
|
8605ed1547 | ||
|
|
91cecabaca | ||
|
|
d4922233ae | ||
|
|
c00a214a0f | ||
|
|
0baf152c3e | ||
|
|
c92c617314 | ||
|
|
8c8ba53668 | ||
|
|
2b08e64db8 | ||
|
|
643db8e586 | ||
|
|
5c39386a3a | ||
|
|
8f99aa79ec | ||
|
|
c594c35b37 | ||
|
|
828a63c30c | ||
|
|
36690e674a | ||
|
|
8788323c62 | ||
|
|
5b64996462 | ||
|
|
3f4380ff48 | ||
|
|
59a29aa54b | ||
|
|
5d084bf822 | ||
|
|
ebe4adaa5d | ||
|
|
c3441647e0 | ||
|
|
574803988d | ||
|
|
9ff3c59961 | ||
|
|
c5f22d7da1 | ||
|
|
3c62877757 | ||
|
|
cc19c61f37 | ||
|
|
ad82bd4302 | ||
|
|
d584a25fdb | ||
|
|
baa4295059 | ||
|
|
6cbfac9d6e | ||
|
|
13d28f19ea | ||
|
|
8fa86965b8 | ||
|
|
72c38f613f | ||
|
|
e4982f871f | ||
|
|
4e0338276f | ||
|
|
fe193f4f91 | ||
|
|
0011ba0c04 | ||
|
|
3c2eef9596 | ||
|
|
dac788351f | ||
|
|
8d5bc1296e | ||
|
|
969ad229e4 | ||
|
|
0d291fcf57 | ||
|
|
d711f4c491 | ||
|
|
9369626e21 | ||
|
|
f84bb0dc9e | ||
|
|
20b428264e | ||
|
|
05bb84fc98 | ||
|
|
46a85e4b4a | ||
|
|
b4d1572c79 | ||
|
|
b8e1b77222 | ||
|
|
1a451a576f | ||
|
|
074b2914d8 | ||
|
|
aec5f80879 | ||
|
|
a1fa42e204 | ||
|
|
306cb956a0 | ||
|
|
d837acde63 | ||
|
|
db938a2c8d | ||
|
|
f24156775a | ||
|
|
2a7f94cf17 | ||
|
|
15922ed953 | ||
|
|
7129ec97fd | ||
|
|
a921806e62 | ||
|
|
d1b28b4fdd | ||
|
|
64fd7e4af2 | ||
|
|
7b52a739c2 | ||
|
|
a4e94878e7 | ||
|
|
c7353ac81e | ||
|
|
1fbc720620 | ||
|
|
263ccc3260 | ||
|
|
00c0a399cd | ||
|
|
8127c7bb1b | ||
|
|
7437908baf | ||
|
|
9eb46cb5d3 | ||
|
|
38a70128b0 | ||
|
|
c58ce52b33 | ||
|
|
c82813185f | ||
|
|
a96681e9d6 | ||
|
|
4df6c40034 | ||
|
|
089d728cc7 | ||
|
|
aca3d718b5 | ||
|
|
8a6a584cf3 | ||
|
|
00ed0cf796 | ||
|
|
7e54b2fe43 | ||
|
|
84871faad4 | ||
|
|
bcb433d7b2 | ||
|
|
7d1b130b68 | ||
|
|
24c2376ea1 | ||
|
|
810ef5fc10 | ||
|
|
fe246b1fe6 | ||
|
|
de42bb48aa | ||
|
|
17495c49ac | ||
|
|
0e3a7a06a3 | ||
|
|
e0ee48eb9c | ||
|
|
d2053b1d5a | ||
|
|
fbe8e53858 | ||
|
|
8fe2581b3f | ||
|
|
60cc0e562e | ||
|
|
26898d474f | ||
|
|
2311fbaa3b | ||
|
|
be99cd9423 | ||
|
|
a3dd6fa95b | ||
|
|
433d87c96d | ||
|
|
aff4383671 | ||
|
|
b7c8f6b1a2 | ||
|
|
3443839ba4 | ||
|
|
6c31d48f3b | ||
|
|
1770292fd8 | ||
|
|
afdd5c5740 | ||
|
|
11487f0833 | ||
|
|
4d5d22d0c2 | ||
|
|
314a957922 | ||
|
|
4c57b562e6 | ||
|
|
a757acf51c | ||
|
|
f4a23be1a2 | ||
|
|
93c67ffa14 | ||
|
|
d1ebe4732f | ||
|
|
7b7f3ca05a | ||
|
|
234613f831 | ||
|
|
f6d84e70cc | ||
|
|
5cd324b6ae | ||
|
|
a7457f5749 | ||
|
|
a5afc75099 | ||
|
|
625c9b3e09 | ||
|
|
e20623ed53 | ||
|
|
aa9adf7348 | ||
|
|
2e82aba0d1 | ||
|
|
b7a3f0f8d9 | ||
|
|
38c82389f7 | ||
|
|
cb0a2bee17 | ||
|
|
dc99131794 | ||
|
|
5c23f61a10 | ||
|
|
f87e3c03cb | ||
|
|
d346670839 | ||
|
|
560d8b7234 | ||
|
|
b297c2b311 | ||
|
|
d390c567d5 | ||
|
|
029e614b9c | ||
|
|
f9a78e4eec | ||
|
|
d8758f7531 | ||
|
|
4e86ecff84 | ||
|
|
070d091e07 | ||
|
|
7403b3c3f8 | ||
|
|
1b1e7b7205 | ||
|
|
1b8f19f1ce | ||
|
|
2a14eadf34 | ||
|
|
fd36cd5795 | ||
|
|
f4286ac3c9 | ||
|
|
92d5eb4844 | ||
|
|
87b9f6ab87 | ||
|
|
06d98aab5c | ||
|
|
298f56a53c | ||
|
|
714a5f2f1c | ||
|
|
4e29d0084f | ||
|
|
63f1b4da2e | ||
|
|
9477f53432 | ||
|
|
ed786f087c | ||
|
|
8e22ea05ff | ||
|
|
8414657224 | ||
|
|
e25213ed1b | ||
|
|
4843b0778c | ||
|
|
f5fae98c69 | ||
|
|
6faf0a4a31 | ||
|
|
011fafc0ff | ||
|
|
8ebe74484c | ||
|
|
3eb9523103 | ||
|
|
3dfa922b9e | ||
|
|
248d54a30f | ||
|
|
b30fef4ccd | ||
|
|
a9c4527318 | ||
|
|
c31f08d5b8 | ||
|
|
9e0fa9ddb1 | ||
|
|
8fcd28832d | ||
|
|
cccf029464 | ||
|
|
512e7fb9e7 | ||
|
|
0e69df8282 | ||
|
|
eb5532c200 | ||
|
|
49ed1dfe33 | ||
|
|
62d1c3f7f5 | ||
|
|
b49dce3334 | ||
|
|
8ace9bc4d1 | ||
|
|
ce490007ed | ||
|
|
eb96c64e26 | ||
|
|
2ac96a8486 | ||
|
|
b8e6cc22af | ||
|
|
634a01f618 | ||
|
|
6abea062ba | ||
|
|
f50887a326 | ||
|
|
3c0af05a3c | ||
|
|
c9131d4457 | ||
|
|
2af79a3ef2 | ||
|
|
afd9228efa | ||
|
|
495d77fda5 | ||
|
|
679bb3b6ab | ||
|
|
350c522d19 | ||
|
|
4760f42589 | ||
|
|
50d15e321f | ||
|
|
a3e7fd8f0a | ||
|
|
645172747a | ||
|
|
7c4ac1eebc | ||
|
|
4b4301ad49 | ||
|
|
b60e03eb70 | ||
|
|
2c7bda3ff1 | ||
|
|
eeaaa3635b | ||
|
|
e61cbb3956 | ||
|
|
f9841f2ef3 | ||
|
|
dc232b2523 | ||
|
|
b086b3e236 | ||
|
|
387e1a0fe0 | ||
|
|
08e01d41f2 | ||
|
|
f5edf52571 | ||
|
|
02c62213c3 | ||
|
|
d0722fbbbe | ||
|
|
4ec569342d | ||
|
|
9540d9ccb9 | ||
|
|
6b5cbe854b | ||
|
|
59ed52814e | ||
|
|
3488ab4f6b | ||
|
|
6e2fc5349b | ||
|
|
ea88c2686d | ||
|
|
3df4baec92 | ||
|
|
ff74e1aaa1 | ||
|
|
b0c865ab76 | ||
|
|
3dbc086f10 | ||
|
|
e9b4b34fb4 | ||
|
|
668eeee197 | ||
|
|
799d8471c9 | ||
|
|
f77c16dec9 | ||
|
|
45026cac6a | ||
|
|
edf6ab5bca | ||
|
|
462b1f14e2 | ||
|
|
7a8f18b116 | ||
|
|
d255e4abb6 | ||
|
|
b770240f0d | ||
|
|
43b064673b | ||
|
|
bf2726c151 | ||
|
|
f3cd921c76 | ||
|
|
913f6b6b64 | ||
|
|
3463a52960 | ||
|
|
116db3566f | ||
|
|
32210a5f7c | ||
|
|
d8f9372bbd | ||
|
|
6e1997fd9d | ||
|
|
4e7213d1aa | ||
|
|
5afb427bb4 | ||
|
|
685361a11a | ||
|
|
bd7c97ca91 | ||
|
|
81235c67dc | ||
|
|
65e8e03224 | ||
|
|
85eb3adec7 | ||
|
|
5d0f958a68 | ||
|
|
b82f50b76b | ||
|
|
0ab11a9bf9 | ||
|
|
d28c310704 | ||
|
|
2e1d7fdf2b | ||
|
|
82e96f7b86 | ||
|
|
7229e2abbd | ||
|
|
4e35043da0 | ||
|
|
56fe1c2ccc | ||
|
|
a874edf2a1 | ||
|
|
9d55ec3e43 | ||
|
|
05580ac978 | ||
|
|
667eb4809d | ||
|
|
58fdaa8298 | ||
|
|
5478a2ac27 | ||
|
|
ad37990da9 | ||
|
|
66824030f2 | ||
|
|
90ca8cf97c | ||
|
|
3c8ea28da1 | ||
|
|
5c352eb863 | ||
|
|
8c312bc163 | ||
|
|
6fa8b06063 | ||
|
|
2992f122bc | ||
|
|
e507993065 | ||
|
|
6f22aad6f4 | ||
|
|
097264040f | ||
|
|
2c03ee6af0 | ||
|
|
ec596b2ada | ||
|
|
b01ba0b2d9 | ||
|
|
f74a6ef093 | ||
|
|
ee687fafbe | ||
|
|
60ba17cfea | ||
|
|
8b3aa5891e | ||
|
|
3ff9399b81 | ||
|
|
d18f7862ab | ||
|
|
dc6c1ce43c | ||
|
|
8d1adccec6 | ||
|
|
420ce71fb2 | ||
|
|
8e5a269ff0 | ||
|
|
f357d6f0ee | ||
|
|
a0467d17a8 | ||
|
|
ef3ecfc73f | ||
|
|
d3fcb23e22 | ||
|
|
5a029283a1 | ||
|
|
09ccad2bd4 | ||
|
|
bdcc10bd40 | ||
|
|
2a1fafc3f9 | ||
|
|
6010b9a0af | ||
|
|
11e8f87fe6 | ||
|
|
14b81cba19 | ||
|
|
2b37de3b4d | ||
|
|
73d9a6367c | ||
|
|
c90233b56f | ||
|
|
39dcf38462 | ||
|
|
efa27cd2dd | ||
|
|
ca231964f2 | ||
|
|
2bb83cb990 | ||
|
|
305bcfcf62 | ||
|
|
92a9011f27 | ||
|
|
e64cebdfc2 | ||
|
|
0db426d278 | ||
|
|
6bfef1c7a0 | ||
|
|
f50fe788cb | ||
|
|
4db78ecf1b | ||
|
|
f22dd7749f | ||
|
|
75af0c3be1 | ||
|
|
6f36b84f85 | ||
|
|
e723198b72 | ||
|
|
8f74febff1 | ||
|
|
d9bd6f8e1d | ||
|
|
bf55417901 | ||
|
|
9511970a1a | ||
|
|
5c8557b369 | ||
|
|
5e47c53fcf | ||
|
|
f7493a8bc4 | ||
|
|
4f39b93edd | ||
|
|
ff8b4eb0f6 | ||
|
|
e921862a7f | ||
|
|
4d7177f15a | ||
|
|
c5d7f56399 | ||
|
|
57f789290d | ||
|
|
f34317e504 | ||
|
|
8159a84447 | ||
|
|
f4db0e384c | ||
|
|
69953401b1 | ||
|
|
93a3c246c6 | ||
|
|
6505e18b0b | ||
|
|
51ab73014f | ||
|
|
05d9e6e46b | ||
|
|
8ea9965ee3 | ||
|
|
486df65aa3 | ||
|
|
8044696d7c | ||
|
|
04a7d86636 | ||
|
|
d0e2f31ce8 | ||
|
|
50fcb09758 | ||
|
|
6d3c09d57a | ||
|
|
cc994fb940 | ||
|
|
eee12513dd | ||
|
|
055b6a0a43 | ||
|
|
26b899df16 | ||
|
|
afc8e1a1e5 | ||
|
|
b6c4d3308d | ||
|
|
af4567aa3d | ||
|
|
415bc2044d | ||
|
|
91ad2b0caf | ||
|
|
bc6471fa54 | ||
|
|
0704668d8d | ||
|
|
2e9f8815d2 | ||
|
|
f4689125e0 | ||
|
|
bbba67a253 | ||
|
|
800b857e53 | ||
|
|
921059bed8 | ||
|
|
e8b585dc07 | ||
|
|
afce27184a | ||
|
|
8d41beef0b | ||
|
|
5e482cd77b | ||
|
|
09068fd4e5 | ||
|
|
d8c2b9089b | ||
|
|
bb577bc276 | ||
|
|
6267e3d593 | ||
|
|
c091a39802 | ||
|
|
f94006dd08 | ||
|
|
f42790980d | ||
|
|
779683de4b | ||
|
|
aa8887318f | ||
|
|
3ad8dc6490 | ||
|
|
20f9fae141 | ||
|
|
ec062bbf24 | ||
|
|
8745c9ea2f | ||
|
|
0917654361 | ||
|
|
d892d1cfa0 | ||
|
|
e31138c250 | ||
|
|
7cbe5ce8be | ||
|
|
1c31d4cd1c | ||
|
|
990ec9317f | ||
|
|
718ceac17e | ||
|
|
d154ba6b89 | ||
|
|
f2a63476b3 | ||
|
|
adcd3b37fa | ||
|
|
71dabc1e37 | ||
|
|
2d724876eb | ||
|
|
1927d1fa4d | ||
|
|
d995fab0e4 | ||
|
|
b4135c1626 | ||
|
|
3d0a9f2082 | ||
|
|
1dd5f685a6 | ||
|
|
c1c4394f94 | ||
|
|
16d9fcdadc | ||
|
|
5b1db01fe6 | ||
|
|
e856e9d6c7 | ||
|
|
ad2c783870 | ||
|
|
5e101bef14 | ||
|
|
149949ad99 | ||
|
|
741cc952fa | ||
|
|
d2bb7a0bf4 | ||
|
|
d4d5bcec9e | ||
|
|
b4053a7b94 | ||
|
|
7b27d00972 | ||
|
|
f4d234089f | ||
|
|
50a329fc0d | ||
|
|
6d6df7ca5c | ||
|
|
6b16068706 | ||
|
|
024a0de4af | ||
|
|
e145d63ba6 | ||
|
|
e7e8b0b3f6 | ||
|
|
a7389db674 | ||
|
|
cf1aa4fd2a | ||
|
|
0fd2a589eb | ||
|
|
944131d5a6 | ||
|
|
eff46ac9bf | ||
|
|
14f9b254b2 | ||
|
|
337d6050ff | ||
|
|
d36348b84f | ||
|
|
dfb6f5b375 | ||
|
|
a9089bc2ff | ||
|
|
5f5d690ff3 | ||
|
|
431882ece9 | ||
|
|
b51e76e366 | ||
|
|
4e01740a61 | ||
|
|
e729ed9df3 | ||
|
|
6b241304fb | ||
|
|
3ed8764087 | ||
|
|
df61b245ab | ||
|
|
7a364d654c | ||
|
|
0d1a0be1a0 | ||
|
|
5da9f5aaf4 | ||
|
|
2bec0f5850 | ||
|
|
5bc28ec38b | ||
|
|
8c7a0a1ec0 | ||
|
|
a8eef8107b | ||
|
|
75cd942f39 | ||
|
|
fc04af148d | ||
|
|
d7d7fd614b | ||
|
|
10e9c3ead0 | ||
|
|
70678432c6 | ||
|
|
bb103fac6c | ||
|
|
0e1fc3f5fa | ||
|
|
7830ebdb3b | ||
|
|
b061dd3395 | ||
|
|
a6f2fa8a88 | ||
|
|
37f12ea6f0 | ||
|
|
e29b576102 | ||
|
|
b1b3cf6136 | ||
|
|
173c4c98b8 | ||
|
|
5a3067c8e5 | ||
|
|
803c748738 | ||
|
|
5879b40e8c | ||
|
|
c3decdac13 | ||
|
|
1baf89dde6 | ||
|
|
0219dc0ede | ||
|
|
1c662888c6 | ||
|
|
7fd1c1e41d | ||
|
|
1eaa716f42 | ||
|
|
704bb7401a | ||
|
|
b0c3fdbdc6 | ||
|
|
1d0ceb7045 | ||
|
|
ce85a050d3 | ||
|
|
94ecbcd639 | ||
|
|
ef1d8bcc9c | ||
|
|
1a7bbdc541 | ||
|
|
3dc5a89459 | ||
|
|
9f6268dbc9 | ||
|
|
2e912dd261 | ||
|
|
6d6fff474f | ||
|
|
e725c70570 | ||
|
|
07aeecbbfc | ||
|
|
9bfac04c44 | ||
|
|
6acf0d6378 | ||
|
|
1a09624242 | ||
|
|
9e36385e63 | ||
|
|
43edadde0c | ||
|
|
d577ff6715 | ||
|
|
ca75c90ee9 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,2 +1,8 @@
|
|||||||
/target
|
/target
|
||||||
.env
|
.env
|
||||||
|
/tantivy_indexes
|
||||||
|
server/tantivy_indexes
|
||||||
|
steel_decimal/tests/property_tests.proptest-regressions
|
||||||
|
.direnv/
|
||||||
|
canvas/*.toml
|
||||||
|
.aider*
|
||||||
|
|||||||
9
.gitmodules
vendored
Normal file
9
.gitmodules
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[submodule "client"]
|
||||||
|
path = client
|
||||||
|
url = git@gitlab.com:filipriec/komp_ac_client.git
|
||||||
|
[submodule "canvas"]
|
||||||
|
path = canvas
|
||||||
|
url = git@gitlab.com:filipriec/tui-canvas.git
|
||||||
|
[submodule "server"]
|
||||||
|
path = server
|
||||||
|
url = git@gitlab.com:filipriec/komp_ac_server.git
|
||||||
2212
Cargo.lock
generated
2212
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
46
Cargo.toml
46
Cargo.toml
@@ -1,19 +1,55 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["client", "server", "common"]
|
members = ["client", "server", "common", "search", "canvas"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
# TODO: idk how to do the name, fix later
|
# TODO: idk how to do the name, fix later
|
||||||
# name = "Multieko2"
|
# name = "komp_ac"
|
||||||
version = "0.2.5"
|
version = "0.5.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
authors = ["Filip Priečinský <filippriec@gmail.com>"]
|
authors = ["Filip Priečinský <filippriec@gmail.com>"]
|
||||||
description = "Poriadny uctovnicky software."
|
description = "Poriadny uctovnicky software."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://gitlab.com/filipriec/multieko2"
|
repository = "https://gitlab.com/filipriec/komp_ac"
|
||||||
categories = ["command-line-interface"]
|
categories = ["command-line-interface"]
|
||||||
|
|
||||||
# [workspace.metadata]
|
# [workspace.metadata]
|
||||||
# TODO:
|
# TODO:
|
||||||
# documentation = "https://docs.rs/accounting-client"`
|
# documentation = "https://docs.rs/accounting-client"
|
||||||
|
|
||||||
|
[workspace.dependencies]
|
||||||
|
# Async and gRPC
|
||||||
|
tokio = { version = "1.44.2", features = ["full"] }
|
||||||
|
tonic = "0.13.0"
|
||||||
|
prost = "0.13.5"
|
||||||
|
async-trait = "0.1.88"
|
||||||
|
prost-types = "0.13.0"
|
||||||
|
|
||||||
|
# Data Handling & Serialization
|
||||||
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
|
serde_json = "1.0.140"
|
||||||
|
time = "0.3.41"
|
||||||
|
|
||||||
|
# Utilities & Error Handling
|
||||||
|
anyhow = "1.0.98"
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
lazy_static = "1.5.0"
|
||||||
|
tracing = "0.1.41"
|
||||||
|
|
||||||
|
# Search crate
|
||||||
|
tantivy = "0.24.1"
|
||||||
|
|
||||||
|
# Steel_decimal crate
|
||||||
|
rust_decimal = { version = "1.37.2", features = ["maths", "serde"] }
|
||||||
|
rust_decimal_macros = "1.37.1"
|
||||||
|
thiserror = "2.0.12"
|
||||||
|
regex = "1.11.1"
|
||||||
|
|
||||||
|
# Canvas crate
|
||||||
|
ratatui = { version = "0.29.0", features = ["crossterm"] }
|
||||||
|
crossterm = "0.28.1"
|
||||||
|
toml = "0.8.20"
|
||||||
|
unicode-width = "0.2.0"
|
||||||
|
|
||||||
|
common = { path = "./common" }
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -1,5 +1,7 @@
|
|||||||
# Hey
|
# Hey
|
||||||
|
|
||||||
|
This is only work in progress, until release 1.0.0 this is for development use cases only.
|
||||||
|
|
||||||
I run development like this:
|
I run development like this:
|
||||||
|
|
||||||
Server:
|
Server:
|
||||||
@@ -12,3 +14,12 @@ Client:
|
|||||||
cargo watch -x 'run --package client -- client'
|
cargo watch -x 'run --package client -- client'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Client with tracing:
|
||||||
|
```
|
||||||
|
ENABLE_TRACING=1 RUST_LOG=client=debug cargo watch -x 'run --package client -- client'
|
||||||
|
```
|
||||||
|
|
||||||
|
Client with debug that cant be traced
|
||||||
|
```
|
||||||
|
cargo run --package client --features ui-debug -- client
|
||||||
|
```
|
||||||
|
|||||||
1
canvas
Submodule
1
canvas
Submodule
Submodule canvas added at 29fdc5a6c7
1
client
Submodule
1
client
Submodule
Submodule client added at c1839bd960
@@ -1,20 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "client"
|
|
||||||
version.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
license.workspace = true
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
async-trait = "0.1.88"
|
|
||||||
common = { path = "../common" }
|
|
||||||
|
|
||||||
crossterm = "0.28.1"
|
|
||||||
dirs = "6.0.0"
|
|
||||||
dotenvy = "0.15.7"
|
|
||||||
prost = "0.13.5"
|
|
||||||
ratatui = "0.29.0"
|
|
||||||
serde = { version = "1.0.218", features = ["derive"] }
|
|
||||||
tokio = { version = "1.43.0", features = ["full", "macros"] }
|
|
||||||
toml = "0.8.20"
|
|
||||||
tonic = "0.12.3"
|
|
||||||
tracing = "0.1.41"
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
# config.toml
|
|
||||||
[keybindings]
|
|
||||||
|
|
||||||
enter_command_mode = [":", "ctrl+;"]
|
|
||||||
|
|
||||||
[keybindings.general]
|
|
||||||
move_up = ["k", "Up"]
|
|
||||||
move_down = ["j", "Down"]
|
|
||||||
next_option = ["l", "Right"]
|
|
||||||
previous_option = ["h", "Left"]
|
|
||||||
select = ["Enter"]
|
|
||||||
toggle_sidebar = ["ctrl+t"]
|
|
||||||
next_field = ["Tab"]
|
|
||||||
prev_field = ["Shift+Tab"]
|
|
||||||
|
|
||||||
[keybindings.common]
|
|
||||||
save = ["ctrl+s"]
|
|
||||||
quit = ["ctrl+q"]
|
|
||||||
# !!!change to space b r in the future and from edit mode
|
|
||||||
revert = ["ctrl+r"]
|
|
||||||
|
|
||||||
force_quit = ["ctrl+shift+q"]
|
|
||||||
save_and_quit = ["ctrl+shift+s"]
|
|
||||||
move_up = ["Up"]
|
|
||||||
move_down = ["Down"]
|
|
||||||
toggle_sidebar = ["ctrl+t"]
|
|
||||||
|
|
||||||
# MODE SPECIFIC
|
|
||||||
# READ ONLY MODE
|
|
||||||
[keybindings.read_only]
|
|
||||||
enter_edit_mode_before = ["i"]
|
|
||||||
enter_edit_mode_after = ["a"]
|
|
||||||
previous_entry = ["left","q"]
|
|
||||||
next_entry = ["right","1"]
|
|
||||||
|
|
||||||
move_left = ["h"]
|
|
||||||
move_right = ["l"]
|
|
||||||
move_up = ["k"]
|
|
||||||
move_down = ["j"]
|
|
||||||
move_word_next = ["w"]
|
|
||||||
move_word_end = ["e"]
|
|
||||||
move_word_prev = ["b"]
|
|
||||||
move_word_end_prev = ["ge"]
|
|
||||||
move_line_start = ["0"]
|
|
||||||
move_line_end = ["$"]
|
|
||||||
move_first_line = ["gg"]
|
|
||||||
move_last_line = ["x"]
|
|
||||||
|
|
||||||
[keybindings.edit]
|
|
||||||
exit_edit_mode = ["esc","ctrl+e"]
|
|
||||||
delete_char_forward = ["delete"]
|
|
||||||
delete_char_backward = ["backspace"]
|
|
||||||
next_field = ["tab", "enter"]
|
|
||||||
prev_field = ["shift+tab", "backtab"]
|
|
||||||
move_left = ["left"]
|
|
||||||
move_right = ["right"]
|
|
||||||
|
|
||||||
[keybindings.command]
|
|
||||||
exit_command_mode = ["ctrl+g", "esc"]
|
|
||||||
command_execute = ["enter"]
|
|
||||||
command_backspace = ["backspace"]
|
|
||||||
save = ["w"]
|
|
||||||
quit = ["q"]
|
|
||||||
force_quit = ["q!"]
|
|
||||||
save_and_quit = ["wq"]
|
|
||||||
revert = ["r"]
|
|
||||||
|
|
||||||
[colors]
|
|
||||||
theme = "dark"
|
|
||||||
# Options: "light", "dark", "high_contrast"
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
client/
|
|
||||||
├── Cargo.toml
|
|
||||||
├── config.toml
|
|
||||||
└── src/
|
|
||||||
├── main.rs # Entry point with minimal code
|
|
||||||
├── lib.rs # Core exports
|
|
||||||
├── app.rs # Application lifecycle and main loop
|
|
||||||
│
|
|
||||||
├── ui/ # UI components and rendering
|
|
||||||
│ ├── mod.rs
|
|
||||||
│ ├── theme.rs # Theme definitions (from colors.rs)
|
|
||||||
│ ├── layout.rs # Layout definitions
|
|
||||||
│ ├── render.rs # Main render coordinator
|
|
||||||
│ └── components/ # UI components
|
|
||||||
│ ├── mod.rs
|
|
||||||
│ ├── command_line.rs
|
|
||||||
│ ├── form.rs
|
|
||||||
│ ├── preview_card.rs
|
|
||||||
│ └── status_line.rs
|
|
||||||
│
|
|
||||||
├── input/ # Input handling
|
|
||||||
│ ├── mod.rs
|
|
||||||
│ ├── handler.rs # Main input handler (lightweight coordinator)
|
|
||||||
│ ├── commands.rs # Command processing
|
|
||||||
│ ├── navigation.rs # Navigation between entries and fields
|
|
||||||
│ └── edit.rs # Edit mode logic
|
|
||||||
│
|
|
||||||
├── editor/ # Text editing functionality
|
|
||||||
│ ├── mod.rs
|
|
||||||
│ ├── cursor.rs # Cursor movement
|
|
||||||
│ └── text.rs # Text manipulation (word movements, etc.)
|
|
||||||
│
|
|
||||||
├── state/ # Application state
|
|
||||||
│ ├── mod.rs
|
|
||||||
│ ├── app_state.rs # Main application state
|
|
||||||
│ └── form_state.rs # Form state
|
|
||||||
│
|
|
||||||
├── model/ # Data models
|
|
||||||
│ ├── mod.rs
|
|
||||||
│ └── entry.rs # Entry model with business logic
|
|
||||||
│
|
|
||||||
├── service/ # External services
|
|
||||||
│ ├── mod.rs
|
|
||||||
│ ├── terminal.rs # Terminal setup and management
|
|
||||||
│ └── grpc.rs # gRPC client (extracted from terminal.rs)
|
|
||||||
│
|
|
||||||
└── config/ # Configuration
|
|
||||||
├── mod.rs
|
|
||||||
└── keybindings.rs # Keybinding definitions and matching
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// src/components/admin.rs
|
|
||||||
pub mod admin_panel;
|
|
||||||
|
|
||||||
pub use admin_panel::*;
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
// src/components/admin/admin_panel.rs
|
|
||||||
|
|
||||||
use ratatui::{
|
|
||||||
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
|
||||||
style::Style,
|
|
||||||
text::{Line, Span, Text},
|
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
|
||||||
Frame,
|
|
||||||
};
|
|
||||||
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
|
|
||||||
pub struct AdminPanelState {
|
|
||||||
pub list_state: ListState,
|
|
||||||
pub profiles: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AdminPanelState {
|
|
||||||
pub fn new(profiles: Vec<String>) -> Self {
|
|
||||||
let mut list_state = ListState::default();
|
|
||||||
if !profiles.is_empty() {
|
|
||||||
list_state.select(Some(0));
|
|
||||||
}
|
|
||||||
Self { list_state, profiles }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next(&mut self) {
|
|
||||||
let i = self.list_state.selected().map_or(0, |i|
|
|
||||||
if i >= self.profiles.len() - 1 { 0 } else { i + 1 });
|
|
||||||
self.list_state.select(Some(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn previous(&mut self) {
|
|
||||||
let i = self.list_state.selected().map_or(0, |i|
|
|
||||||
if i == 0 { self.profiles.len() - 1 } else { i - 1 });
|
|
||||||
self.list_state.select(Some(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn render(
|
|
||||||
&mut self,
|
|
||||||
f: &mut Frame,
|
|
||||||
area: Rect,
|
|
||||||
theme: &Theme,
|
|
||||||
profile_tree: &ProfileTreeResponse,
|
|
||||||
selected_profile: &Option<String>,
|
|
||||||
) {
|
|
||||||
let block = Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Rounded)
|
|
||||||
.border_style(Style::default().fg(theme.accent))
|
|
||||||
.style(Style::default().bg(theme.bg));
|
|
||||||
|
|
||||||
let inner_area = block.inner(area);
|
|
||||||
f.render_widget(block, area);
|
|
||||||
|
|
||||||
let chunks = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([Constraint::Length(3), Constraint::Min(1)])
|
|
||||||
.split(inner_area);
|
|
||||||
|
|
||||||
// Title
|
|
||||||
let title = Line::from(Span::styled("Admin Panel", Style::default().fg(theme.highlight)));
|
|
||||||
let title_widget = Paragraph::new(title).alignment(Alignment::Center);
|
|
||||||
f.render_widget(title_widget, chunks[0]);
|
|
||||||
|
|
||||||
// Content
|
|
||||||
let content_chunks = Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
|
||||||
.split(chunks[1]);
|
|
||||||
|
|
||||||
// Profile list
|
|
||||||
let items: Vec<ListItem> = self.profiles.iter()
|
|
||||||
.map(|p| ListItem::new(Line::from(vec![
|
|
||||||
Span::styled(
|
|
||||||
if Some(p) == selected_profile.as_ref() { "✓ " } else { " " },
|
|
||||||
Style::default().fg(theme.accent)
|
|
||||||
),
|
|
||||||
Span::styled(p, Style::default().fg(theme.fg)),
|
|
||||||
])))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let list = List::new(items)
|
|
||||||
.block(Block::default().title("Profiles"))
|
|
||||||
.highlight_style(Style::default().bg(theme.highlight).fg(theme.bg));
|
|
||||||
|
|
||||||
f.render_stateful_widget(list, content_chunks[0], &mut self.list_state);
|
|
||||||
|
|
||||||
// Profile details
|
|
||||||
if let Some(profile) = self.list_state.selected()
|
|
||||||
.and_then(|i| profile_tree.profiles.get(i))
|
|
||||||
{
|
|
||||||
let mut text = Text::default();
|
|
||||||
text.lines.push(Line::from(vec![
|
|
||||||
Span::styled("Profile: ", Style::default().fg(theme.accent)),
|
|
||||||
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
|
|
||||||
]));
|
|
||||||
|
|
||||||
text.lines.push(Line::from(""));
|
|
||||||
text.lines.push(Line::from(Span::styled("Tables:", Style::default().fg(theme.accent))));
|
|
||||||
|
|
||||||
for table in &profile.tables {
|
|
||||||
let mut line = vec![Span::styled(format!("├─ {}", table.name), theme.fg)];
|
|
||||||
if !table.depends_on.is_empty() {
|
|
||||||
line.push(Span::styled(
|
|
||||||
format!(" → {}", table.depends_on.join(", ")),
|
|
||||||
Style::default().fg(theme.secondary)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
text.lines.push(Line::from(line));
|
|
||||||
}
|
|
||||||
|
|
||||||
let details_widget = Paragraph::new(text)
|
|
||||||
.block(Block::default().title("Details"));
|
|
||||||
f.render_widget(details_widget, content_chunks[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
// src/components/form.rs
|
|
||||||
pub mod login;
|
|
||||||
pub mod register;
|
|
||||||
|
|
||||||
pub use login::*;
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
// src/components/auth/login.rs
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
config::colors::themes::Theme,
|
|
||||||
state::pages::auth::AuthState,
|
|
||||||
components::common::dialog,
|
|
||||||
state::state::AppState, // Add this import
|
|
||||||
};
|
|
||||||
use ratatui::{
|
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Rect, Margin},
|
|
||||||
style::{Style, Modifier, Color}, // Removed unused Color import
|
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
|
||||||
Frame, // Removed unused Span import
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn render_login(
|
|
||||||
f: &mut Frame,
|
|
||||||
area: Rect,
|
|
||||||
theme: &Theme,
|
|
||||||
state: &AuthState,
|
|
||||||
app_state: &AppState, // Add AppState parameter
|
|
||||||
is_edit_mode: bool,
|
|
||||||
) {
|
|
||||||
// Main container
|
|
||||||
let block = Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Plain)
|
|
||||||
.border_style(Style::default().fg(theme.border))
|
|
||||||
.title(" Login ")
|
|
||||||
.style(Style::default().bg(theme.bg));
|
|
||||||
|
|
||||||
f.render_widget(block, area);
|
|
||||||
|
|
||||||
let inner_area = area.inner(Margin {
|
|
||||||
horizontal: 1,
|
|
||||||
vertical: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Layout chunks
|
|
||||||
let chunks = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Length(4), // Form (2 fields + padding)
|
|
||||||
Constraint::Length(1), // Error message
|
|
||||||
Constraint::Length(3), // Buttons
|
|
||||||
])
|
|
||||||
.split(inner_area);
|
|
||||||
|
|
||||||
// --- FORM RENDERING ---
|
|
||||||
let input_block = Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_style(if is_edit_mode {
|
|
||||||
Style::default().fg(theme.accent)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.border)
|
|
||||||
})
|
|
||||||
.style(Style::default().bg(theme.bg));
|
|
||||||
|
|
||||||
// Calculate inner area BEFORE rendering
|
|
||||||
let input_area = input_block.inner(chunks[0]);
|
|
||||||
|
|
||||||
f.render_widget(input_block, chunks[0]);
|
|
||||||
|
|
||||||
// Use the canvas renderer for fields
|
|
||||||
crate::components::handlers::canvas::render_canvas(
|
|
||||||
f,
|
|
||||||
input_area, // Use the pre-calculated area
|
|
||||||
state,
|
|
||||||
&["Username/Email", "Password"],
|
|
||||||
&state.current_field,
|
|
||||||
&[&state.username, &state.password],
|
|
||||||
theme,
|
|
||||||
is_edit_mode,
|
|
||||||
);
|
|
||||||
|
|
||||||
// --- BUTTONS --- (Keep this unchanged)
|
|
||||||
let button_chunks = Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
|
||||||
.split(chunks[2]);
|
|
||||||
|
|
||||||
// Login Button
|
|
||||||
let login_active = !state.return_selected;
|
|
||||||
let mut login_style = Style::default().fg(theme.fg);
|
|
||||||
let mut login_border = Style::default().fg(theme.border);
|
|
||||||
if login_active {
|
|
||||||
login_style = login_style.fg(theme.highlight).add_modifier(Modifier::BOLD);
|
|
||||||
login_border = login_border.fg(theme.accent);
|
|
||||||
}
|
|
||||||
|
|
||||||
f.render_widget(
|
|
||||||
Paragraph::new("Login")
|
|
||||||
.style(login_style)
|
|
||||||
.alignment(Alignment::Center)
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Plain)
|
|
||||||
.border_style(login_border),
|
|
||||||
),
|
|
||||||
button_chunks[0],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Return Button
|
|
||||||
let return_active = state.return_selected;
|
|
||||||
let mut return_style = Style::default().fg(theme.fg);
|
|
||||||
let mut return_border = Style::default().fg(theme.border);
|
|
||||||
if return_active {
|
|
||||||
return_style = return_style.fg(theme.highlight).add_modifier(Modifier::BOLD);
|
|
||||||
return_border = return_border.fg(theme.accent);
|
|
||||||
}
|
|
||||||
|
|
||||||
f.render_widget(
|
|
||||||
Paragraph::new("Return")
|
|
||||||
.style(return_style)
|
|
||||||
.alignment(Alignment::Center)
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Plain)
|
|
||||||
.border_style(return_border),
|
|
||||||
),
|
|
||||||
button_chunks[1],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Error message
|
|
||||||
if let Some(err) = &state.error_message {
|
|
||||||
f.render_widget(
|
|
||||||
Paragraph::new(err.as_str())
|
|
||||||
.style(Style::default().fg(Color::Red))
|
|
||||||
.alignment(Alignment::Center),
|
|
||||||
chunks[1],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if app_state.ui.dialog.show_dialog {
|
|
||||||
dialog::render_dialog(
|
|
||||||
f,
|
|
||||||
f.area(), // Use area() instead of deprecated size()
|
|
||||||
theme,
|
|
||||||
&app_state.ui.dialog.dialog_title,
|
|
||||||
&app_state.ui.dialog.dialog_message,
|
|
||||||
app_state.ui.dialog.dialog_button_active,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// src/components/common.rs
|
|
||||||
pub mod command_line;
|
|
||||||
pub mod status_line;
|
|
||||||
pub mod background;
|
|
||||||
pub mod dialog;
|
|
||||||
|
|
||||||
pub use command_line::*;
|
|
||||||
pub use status_line::*;
|
|
||||||
pub use background::*;
|
|
||||||
pub use dialog::*;
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
// src/components/handlers/background.rs
|
|
||||||
use ratatui::{
|
|
||||||
widgets::{Block},
|
|
||||||
layout::Rect,
|
|
||||||
style::Style,
|
|
||||||
Frame,
|
|
||||||
};
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
|
|
||||||
pub fn render_background(f: &mut Frame, area: Rect, theme: &Theme) {
|
|
||||||
let background = Block::default()
|
|
||||||
.style(Style::default().bg(theme.bg));
|
|
||||||
|
|
||||||
f.render_widget(background, area);
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
// src/client/components/command_line.rs
|
|
||||||
use ratatui::{
|
|
||||||
widgets::{Block, Paragraph},
|
|
||||||
style::Style,
|
|
||||||
layout::Rect,
|
|
||||||
Frame,
|
|
||||||
};
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
|
|
||||||
pub fn render_command_line(f: &mut Frame, area: Rect, input: &str, active: bool, theme: &Theme, message: &str) {
|
|
||||||
let prompt = if active {
|
|
||||||
":"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
};
|
|
||||||
|
|
||||||
// Combine the prompt, input, and message
|
|
||||||
let display_text = if message.is_empty() {
|
|
||||||
format!("{}{}", prompt, input)
|
|
||||||
} else {
|
|
||||||
format!("{}{} | {}", prompt, input, message)
|
|
||||||
};
|
|
||||||
|
|
||||||
let style = if active {
|
|
||||||
Style::default().fg(theme.accent)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.fg)
|
|
||||||
};
|
|
||||||
|
|
||||||
let paragraph = Paragraph::new(display_text)
|
|
||||||
.block(Block::default().style(Style::default().bg(theme.bg)))
|
|
||||||
.style(style);
|
|
||||||
|
|
||||||
f.render_widget(paragraph, area);
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
// src/components/common/dialog.rs
|
|
||||||
use ratatui::{
|
|
||||||
layout::{Constraint, Direction, Layout, Rect, Margin},
|
|
||||||
style::{Modifier, Style},
|
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
|
||||||
Frame,
|
|
||||||
text::{Text, Line, Span}
|
|
||||||
};
|
|
||||||
use ratatui::prelude::Alignment;
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
|
|
||||||
pub fn render_dialog(
|
|
||||||
f: &mut Frame,
|
|
||||||
area: Rect,
|
|
||||||
theme: &Theme,
|
|
||||||
title: &str,
|
|
||||||
message: &str,
|
|
||||||
is_active: bool,
|
|
||||||
) {
|
|
||||||
// Create a centered rect for the dialog
|
|
||||||
let dialog_area = centered_rect(60, 25, area);
|
|
||||||
|
|
||||||
// Main dialog container
|
|
||||||
let block = Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Rounded)
|
|
||||||
.border_style(Style::default().fg(theme.accent))
|
|
||||||
.title(title)
|
|
||||||
.style(Style::default().bg(theme.bg));
|
|
||||||
|
|
||||||
f.render_widget(&block, dialog_area);
|
|
||||||
|
|
||||||
// Inner content area
|
|
||||||
let inner_area = block.inner(dialog_area).inner(Margin {
|
|
||||||
horizontal: 2,
|
|
||||||
vertical: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Split into message and button areas
|
|
||||||
let chunks = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Min(3), // Message content
|
|
||||||
Constraint::Length(3), // Button
|
|
||||||
])
|
|
||||||
.split(inner_area);
|
|
||||||
|
|
||||||
// Message text
|
|
||||||
let message_text = Text::from(message.lines().map(|l| Line::from(Span::styled(
|
|
||||||
l,
|
|
||||||
Style::default().fg(theme.fg)
|
|
||||||
))).collect::<Vec<_>>());
|
|
||||||
|
|
||||||
let message_paragraph = Paragraph::new(message_text)
|
|
||||||
.alignment(Alignment::Center);
|
|
||||||
f.render_widget(message_paragraph, chunks[0]);
|
|
||||||
|
|
||||||
// OK Button
|
|
||||||
let button_style = if is_active {
|
|
||||||
Style::default()
|
|
||||||
.fg(theme.highlight)
|
|
||||||
.add_modifier(Modifier::BOLD)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.fg)
|
|
||||||
};
|
|
||||||
|
|
||||||
let button_block = Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Plain)
|
|
||||||
.border_style(Style::default().fg(theme.accent))
|
|
||||||
.style(Style::default().bg(theme.bg));
|
|
||||||
|
|
||||||
f.render_widget(
|
|
||||||
Paragraph::new("OK")
|
|
||||||
.block(button_block)
|
|
||||||
.style(button_style)
|
|
||||||
.alignment(Alignment::Center),
|
|
||||||
chunks[1],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper function to center a rect with given percentage values
|
|
||||||
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
|
|
||||||
let popup_layout = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Percentage((100 - percent_y) / 2),
|
|
||||||
Constraint::Percentage(percent_y),
|
|
||||||
Constraint::Percentage((100 - percent_y) / 2),
|
|
||||||
])
|
|
||||||
.split(r);
|
|
||||||
|
|
||||||
Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Percentage((100 - percent_x) / 2),
|
|
||||||
Constraint::Percentage(percent_x),
|
|
||||||
Constraint::Percentage((100 - percent_x) / 2),
|
|
||||||
])
|
|
||||||
.split(popup_layout[1])[1]
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
// src/client/components/handlers/status_line.rs
|
|
||||||
use ratatui::{
|
|
||||||
widgets::Paragraph,
|
|
||||||
style::Style,
|
|
||||||
layout::Rect,
|
|
||||||
Frame,
|
|
||||||
text::{Line, Span},
|
|
||||||
};
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
pub fn render_status_line(
|
|
||||||
f: &mut Frame,
|
|
||||||
area: Rect,
|
|
||||||
current_dir: &str,
|
|
||||||
theme: &Theme,
|
|
||||||
is_edit_mode: bool,
|
|
||||||
) {
|
|
||||||
// Program name and version
|
|
||||||
let program_info = format!("multieko2 v{}", env!("CARGO_PKG_VERSION"));
|
|
||||||
|
|
||||||
let mode_text = if is_edit_mode {
|
|
||||||
"[EDIT]"
|
|
||||||
} else {
|
|
||||||
"[READ-ONLY]"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Shorten the current directory path
|
|
||||||
let home_dir = dirs::home_dir().map(|p| p.to_string_lossy().into_owned()).unwrap_or_default();
|
|
||||||
let display_dir = if current_dir.starts_with(&home_dir) {
|
|
||||||
current_dir.replacen(&home_dir, "~", 1)
|
|
||||||
} else {
|
|
||||||
current_dir.to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create the full status line text
|
|
||||||
let full_text = format!("{} | {} | {}", mode_text, display_dir, program_info);
|
|
||||||
|
|
||||||
// Check if the full text fits in the available width
|
|
||||||
let available_width = area.width as usize;
|
|
||||||
let mut display_text = if full_text.len() <= available_width {
|
|
||||||
// If it fits, use the full text
|
|
||||||
full_text
|
|
||||||
} else {
|
|
||||||
// If it doesn't fit, prioritize mode and program info, and show only the directory name
|
|
||||||
let dir_name = Path::new(current_dir)
|
|
||||||
.file_name()
|
|
||||||
.and_then(|n| n.to_str())
|
|
||||||
.unwrap_or(current_dir);
|
|
||||||
format!("{} | {} | {}", mode_text, dir_name, program_info)
|
|
||||||
};
|
|
||||||
|
|
||||||
// If even the shortened version overflows, truncate it
|
|
||||||
if display_text.len() > available_width {
|
|
||||||
display_text = display_text.chars().take(available_width).collect();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the status line text using Line and Span
|
|
||||||
let status_line = Line::from(vec![
|
|
||||||
Span::styled(mode_text, Style::default().fg(theme.accent)),
|
|
||||||
Span::styled(" | ", Style::default().fg(theme.border)),
|
|
||||||
Span::styled(
|
|
||||||
display_text.split(" | ").nth(1).unwrap_or(""), // Directory part
|
|
||||||
Style::default().fg(theme.fg),
|
|
||||||
),
|
|
||||||
Span::styled(" | ", Style::default().fg(theme.border)),
|
|
||||||
Span::styled(
|
|
||||||
program_info,
|
|
||||||
Style::default()
|
|
||||||
.fg(theme.secondary)
|
|
||||||
.add_modifier(ratatui::style::Modifier::BOLD),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Render the status line
|
|
||||||
let paragraph = Paragraph::new(status_line)
|
|
||||||
.style(Style::default().bg(theme.bg));
|
|
||||||
|
|
||||||
f.render_widget(paragraph, area);
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// src/components/form.rs
|
|
||||||
pub mod form;
|
|
||||||
|
|
||||||
pub use form::*;
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
// src/components/form/form.rs
|
|
||||||
use ratatui::{
|
|
||||||
widgets::{Paragraph, Block, Borders},
|
|
||||||
layout::{Layout, Constraint, Direction, Rect, Margin, Alignment},
|
|
||||||
style::Style,
|
|
||||||
Frame,
|
|
||||||
};
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
use crate::state::canvas_state::CanvasState;
|
|
||||||
use crate::components::handlers::canvas::render_canvas;
|
|
||||||
|
|
||||||
pub fn render_form(
|
|
||||||
f: &mut Frame,
|
|
||||||
area: Rect,
|
|
||||||
form_state: &impl CanvasState,
|
|
||||||
fields: &[&str],
|
|
||||||
current_field: &usize,
|
|
||||||
inputs: &[&String],
|
|
||||||
theme: &Theme,
|
|
||||||
is_edit_mode: bool,
|
|
||||||
total_count: u64,
|
|
||||||
current_position: u64,
|
|
||||||
) {
|
|
||||||
// Create Adresar card
|
|
||||||
let adresar_card = Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_style(Style::default().fg(theme.border))
|
|
||||||
.title(" Adresar ")
|
|
||||||
.style(Style::default().bg(theme.bg).fg(theme.fg));
|
|
||||||
|
|
||||||
f.render_widget(adresar_card, area);
|
|
||||||
|
|
||||||
// Define inner area
|
|
||||||
let inner_area = area.inner(Margin {
|
|
||||||
horizontal: 1,
|
|
||||||
vertical: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create main layout
|
|
||||||
let main_layout = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Length(1),
|
|
||||||
Constraint::Min(1),
|
|
||||||
])
|
|
||||||
.split(inner_area);
|
|
||||||
|
|
||||||
// Render count/position
|
|
||||||
let count_position_text = format!("Total: {} | Position: {}", total_count, current_position);
|
|
||||||
let count_para = Paragraph::new(count_position_text)
|
|
||||||
.style(Style::default().fg(theme.fg))
|
|
||||||
.alignment(Alignment::Left);
|
|
||||||
f.render_widget(count_para, main_layout[0]);
|
|
||||||
|
|
||||||
// Delegate input handling to canvas
|
|
||||||
render_canvas(
|
|
||||||
f,
|
|
||||||
main_layout[1],
|
|
||||||
form_state,
|
|
||||||
fields,
|
|
||||||
current_field,
|
|
||||||
inputs,
|
|
||||||
theme,
|
|
||||||
is_edit_mode,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// src/components/handlers.rs
|
|
||||||
pub mod canvas;
|
|
||||||
pub mod sidebar;
|
|
||||||
|
|
||||||
pub use canvas::*;
|
|
||||||
pub use sidebar::*;
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
// src/components/handlers/canvas.rs
|
|
||||||
use ratatui::{
|
|
||||||
widgets::{Paragraph, Block, Borders},
|
|
||||||
layout::{Layout, Constraint, Direction, Rect},
|
|
||||||
style::Style,
|
|
||||||
text::{Line, Span},
|
|
||||||
Frame,
|
|
||||||
prelude::Alignment,
|
|
||||||
};
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
use crate::state::canvas_state::CanvasState;
|
|
||||||
|
|
||||||
pub fn render_canvas(
|
|
||||||
f: &mut Frame,
|
|
||||||
area: Rect,
|
|
||||||
form_state: &impl CanvasState,
|
|
||||||
fields: &[&str],
|
|
||||||
current_field: &usize,
|
|
||||||
inputs: &[&String],
|
|
||||||
theme: &Theme,
|
|
||||||
is_edit_mode: bool,
|
|
||||||
) {
|
|
||||||
// Split area into columns
|
|
||||||
let columns = Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
|
||||||
.split(area);
|
|
||||||
|
|
||||||
// Input container styling
|
|
||||||
let input_container = Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_style(if is_edit_mode {
|
|
||||||
form_state.has_unsaved_changes().then(|| theme.warning).unwrap_or(theme.accent)
|
|
||||||
} else {
|
|
||||||
theme.secondary
|
|
||||||
})
|
|
||||||
.style(Style::default().bg(theme.bg));
|
|
||||||
|
|
||||||
// Input block dimensions
|
|
||||||
let input_block = Rect {
|
|
||||||
x: columns[1].x,
|
|
||||||
y: columns[1].y,
|
|
||||||
width: columns[1].width,
|
|
||||||
height: fields.len() as u16 + 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
f.render_widget(&input_container, input_block);
|
|
||||||
|
|
||||||
// Input rows layout
|
|
||||||
let input_area = input_container.inner(input_block);
|
|
||||||
let input_rows = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints(vec![Constraint::Length(1); fields.len()])
|
|
||||||
.split(input_area);
|
|
||||||
|
|
||||||
// Render labels
|
|
||||||
for (i, field) in fields.iter().enumerate() {
|
|
||||||
let label = Paragraph::new(Line::from(Span::styled(
|
|
||||||
format!("{}:", field),
|
|
||||||
Style::default().fg(theme.fg)),
|
|
||||||
));
|
|
||||||
f.render_widget(label, Rect {
|
|
||||||
x: columns[0].x,
|
|
||||||
y: input_block.y + 1 + i as u16,
|
|
||||||
width: columns[0].width,
|
|
||||||
height: 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render inputs and cursor
|
|
||||||
for (i, input) in inputs.iter().enumerate() {
|
|
||||||
let is_active = i == *current_field;
|
|
||||||
let input_display = Paragraph::new(input.as_str())
|
|
||||||
.alignment(Alignment::Left)
|
|
||||||
.style(if is_active {
|
|
||||||
Style::default().fg(theme.highlight)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.fg)
|
|
||||||
});
|
|
||||||
|
|
||||||
f.render_widget(input_display, input_rows[i]);
|
|
||||||
|
|
||||||
if is_active {
|
|
||||||
let cursor_x = input_rows[i].x + form_state.current_cursor_pos() as u16;
|
|
||||||
let cursor_y = input_rows[i].y;
|
|
||||||
f.set_cursor_position((cursor_x, cursor_y));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
// src/components/handlers/sidebar.rs
|
|
||||||
use ratatui::{
|
|
||||||
widgets::{Block, List, ListItem},
|
|
||||||
layout::{Rect, Direction, Layout, Constraint},
|
|
||||||
style::Style,
|
|
||||||
Frame,
|
|
||||||
};
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
use common::proto::multieko2::table_definition::{ProfileTreeResponse};
|
|
||||||
use ratatui::text::{Span, Line};
|
|
||||||
|
|
||||||
// Reduced sidebar width
|
|
||||||
const SIDEBAR_WIDTH: u16 = 12;
|
|
||||||
|
|
||||||
pub fn calculate_sidebar_layout(show_sidebar: bool, main_content_area: Rect) -> (Option<Rect>, Rect) {
|
|
||||||
if show_sidebar {
|
|
||||||
let chunks = Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Length(SIDEBAR_WIDTH),
|
|
||||||
Constraint::Min(0),
|
|
||||||
])
|
|
||||||
.split(main_content_area);
|
|
||||||
(Some(chunks[0]), chunks[1])
|
|
||||||
} else {
|
|
||||||
(None, main_content_area)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn render_sidebar(
|
|
||||||
f: &mut Frame,
|
|
||||||
area: Rect,
|
|
||||||
theme: &Theme,
|
|
||||||
profile_tree: &ProfileTreeResponse,
|
|
||||||
selected_profile: &Option<String>,
|
|
||||||
) {
|
|
||||||
let sidebar_block = Block::default().style(Style::default().bg(theme.bg));
|
|
||||||
let mut items = Vec::new();
|
|
||||||
|
|
||||||
if let Some(profile_name) = selected_profile {
|
|
||||||
// Existing code for when a profile is selected...
|
|
||||||
} else {
|
|
||||||
// Show full profile tree when no profile is selected (compact version)
|
|
||||||
for (profile_idx, profile) in profile_tree.profiles.iter().enumerate() {
|
|
||||||
// Profile header - more compact
|
|
||||||
items.push(ListItem::new(Line::from(vec![
|
|
||||||
Span::styled("◆", Style::default().fg(theme.accent)),
|
|
||||||
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
|
|
||||||
])));
|
|
||||||
|
|
||||||
// Tables with compact prefixes
|
|
||||||
for (table_idx, table) in profile.tables.iter().enumerate() {
|
|
||||||
let is_last_table = table_idx == profile.tables.len() - 1;
|
|
||||||
let is_last_profile = profile_idx == profile_tree.profiles.len() - 1;
|
|
||||||
|
|
||||||
// Shorter prefix characters
|
|
||||||
let prefix = match (is_last_profile, is_last_table) {
|
|
||||||
(true, true) => " └",
|
|
||||||
(true, false) => " ├",
|
|
||||||
(false, true) => "│└",
|
|
||||||
(false, false) => "│├",
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get table name without year prefix to save space
|
|
||||||
let display_name = if table.name.starts_with("2025_") {
|
|
||||||
&table.name[5..] // Skip "2025_" prefix
|
|
||||||
} else {
|
|
||||||
&table.name
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut line = vec![
|
|
||||||
Span::styled(prefix, Style::default().fg(theme.fg)),
|
|
||||||
Span::styled(display_name, Style::default().fg(theme.fg)),
|
|
||||||
];
|
|
||||||
|
|
||||||
// Show a simple indicator for dependencies instead of listing them
|
|
||||||
if !table.depends_on.is_empty() {
|
|
||||||
line.push(Span::styled(
|
|
||||||
"→",
|
|
||||||
Style::default().fg(theme.secondary)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
items.push(ListItem::new(Line::from(line)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compact separator between profiles
|
|
||||||
if profile_idx < profile_tree.profiles.len() - 1 {
|
|
||||||
items.push(ListItem::new(Line::from(
|
|
||||||
Span::styled("│", Style::default().fg(theme.secondary))
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if profile_tree.profiles.is_empty() {
|
|
||||||
items.push(ListItem::new(Span::styled(
|
|
||||||
"No profiles",
|
|
||||||
Style::default().fg(theme.secondary)
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let list = List::new(items)
|
|
||||||
.block(sidebar_block)
|
|
||||||
.highlight_style(Style::default().fg(theme.highlight))
|
|
||||||
.highlight_symbol(">");
|
|
||||||
|
|
||||||
f.render_widget(list, area);
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// src/components/intro.rs
|
|
||||||
pub mod intro;
|
|
||||||
|
|
||||||
pub use intro::*;
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
// src/components/intro/intro.rs
|
|
||||||
use ratatui::{
|
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
|
||||||
style::Style,
|
|
||||||
text::{Line, Span},
|
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
|
||||||
prelude::Margin,
|
|
||||||
Frame,
|
|
||||||
};
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
|
|
||||||
pub struct IntroState {
|
|
||||||
pub selected_option: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntroState {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self { selected_option: 0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn render(&self, f: &mut Frame, area: Rect, theme: &Theme) {
|
|
||||||
let block = Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Rounded)
|
|
||||||
.border_style(Style::default().fg(theme.accent))
|
|
||||||
.style(Style::default().bg(theme.bg));
|
|
||||||
|
|
||||||
let inner_area = block.inner(area);
|
|
||||||
f.render_widget(block, area);
|
|
||||||
|
|
||||||
// Center layout
|
|
||||||
let chunks = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Percentage(40),
|
|
||||||
Constraint::Length(5), // Increased to accommodate 3 buttons
|
|
||||||
Constraint::Percentage(40),
|
|
||||||
])
|
|
||||||
.split(inner_area);
|
|
||||||
|
|
||||||
// Title
|
|
||||||
let title = Line::from(vec![
|
|
||||||
Span::styled("multieko2", Style::default().fg(theme.highlight)),
|
|
||||||
Span::styled(" v", Style::default().fg(theme.fg)),
|
|
||||||
Span::styled(env!("CARGO_PKG_VERSION"), Style::default().fg(theme.secondary)),
|
|
||||||
]);
|
|
||||||
let title_para = Paragraph::new(title)
|
|
||||||
.alignment(Alignment::Center);
|
|
||||||
f.render_widget(title_para, chunks[1]);
|
|
||||||
|
|
||||||
// Buttons - now with 3 options
|
|
||||||
let button_area = Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Percentage(33),
|
|
||||||
Constraint::Percentage(33),
|
|
||||||
Constraint::Percentage(33),
|
|
||||||
])
|
|
||||||
.split(chunks[1].inner(Margin {
|
|
||||||
horizontal: 1,
|
|
||||||
vertical: 1
|
|
||||||
}));
|
|
||||||
|
|
||||||
self.render_button(
|
|
||||||
f,
|
|
||||||
button_area[0],
|
|
||||||
"Continue",
|
|
||||||
self.selected_option == 0,
|
|
||||||
theme,
|
|
||||||
);
|
|
||||||
self.render_button(
|
|
||||||
f,
|
|
||||||
button_area[1],
|
|
||||||
"Admin",
|
|
||||||
self.selected_option == 1,
|
|
||||||
theme,
|
|
||||||
);
|
|
||||||
self.render_button(
|
|
||||||
f,
|
|
||||||
button_area[2],
|
|
||||||
"Login",
|
|
||||||
self.selected_option == 2,
|
|
||||||
theme,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_button(&self, f: &mut Frame, area: Rect, text: &str, selected: bool, theme: &Theme) {
|
|
||||||
let button_style = if selected {
|
|
||||||
Style::default()
|
|
||||||
.fg(theme.highlight)
|
|
||||||
.bg(theme.bg)
|
|
||||||
.add_modifier(ratatui::style::Modifier::BOLD)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.fg).bg(theme.bg)
|
|
||||||
};
|
|
||||||
|
|
||||||
let button = Paragraph::new(text)
|
|
||||||
.style(button_style)
|
|
||||||
.alignment(Alignment::Center)
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Double)
|
|
||||||
.border_style(if selected {
|
|
||||||
Style::default().fg(theme.accent)
|
|
||||||
} else {
|
|
||||||
Style::default().fg(theme.border)
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
f.render_widget(button, area);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_option(&mut self) {
|
|
||||||
self.selected_option = (self.selected_option + 1) % 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn previous_option(&mut self) {
|
|
||||||
self.selected_option = if self.selected_option == 0 { 2 } else { self.selected_option - 1 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
// src/components/mod.rs
|
|
||||||
pub mod handlers;
|
|
||||||
pub mod intro;
|
|
||||||
pub mod admin;
|
|
||||||
pub mod common;
|
|
||||||
pub mod form;
|
|
||||||
pub mod auth;
|
|
||||||
|
|
||||||
pub use handlers::*;
|
|
||||||
pub use intro::*;
|
|
||||||
pub use admin::*;
|
|
||||||
pub use common::*;
|
|
||||||
pub use form::*;
|
|
||||||
pub use auth::*;
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// src/config/binds.rs
|
|
||||||
|
|
||||||
pub mod config;
|
|
||||||
pub mod key_sequences;
|
|
||||||
|
|
||||||
pub use config::*;
|
|
||||||
pub use key_sequences::*;
|
|
||||||
@@ -1,542 +0,0 @@
|
|||||||
// src/config/binds/config.rs
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::path::Path;
|
|
||||||
use crossterm::event::{KeyCode, KeyModifiers};
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Default)]
|
|
||||||
pub struct ColorsConfig {
|
|
||||||
#[serde(default = "default_theme")]
|
|
||||||
pub theme: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn default_theme() -> String {
|
|
||||||
"light".to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct Config {
|
|
||||||
#[serde(rename = "keybindings")]
|
|
||||||
pub keybindings: ModeKeybindings,
|
|
||||||
#[serde(default)]
|
|
||||||
pub colors: ColorsConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct ModeKeybindings {
|
|
||||||
#[serde(default)]
|
|
||||||
pub general: HashMap<String, Vec<String>>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub read_only: HashMap<String, Vec<String>>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub edit: HashMap<String, Vec<String>>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub command: HashMap<String, Vec<String>>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub common: HashMap<String, Vec<String>>,
|
|
||||||
#[serde(flatten)]
|
|
||||||
pub global: HashMap<String, Vec<String>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Config {
|
|
||||||
/// Loads the configuration from "config.toml" in the client crate directory.
|
|
||||||
pub fn load() -> Result<Self, Box<dyn std::error::Error>> {
|
|
||||||
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
|
||||||
let config_path = Path::new(manifest_dir).join("config.toml");
|
|
||||||
let config_str = std::fs::read_to_string(&config_path)
|
|
||||||
.map_err(|e| format!("Failed to read config file at {:?}: {}", config_path, e))?;
|
|
||||||
let config: Config = toml::from_str(&config_str)?;
|
|
||||||
Ok(config)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pub fn get_general_action(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
|
||||||
self.get_action_for_key_in_mode(&self.keybindings.general, key, modifiers)
|
|
||||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.global, key, modifiers))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Common actions for Edit/Read-only modes
|
|
||||||
pub fn get_common_action(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
|
||||||
self.get_action_for_key_in_mode(&self.keybindings.common, key, modifiers)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets an action for a key in Read-Only mode, also checking common keybindings.
|
|
||||||
pub fn get_read_only_action_for_key(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
|
||||||
self.get_action_for_key_in_mode(&self.keybindings.read_only, key, modifiers)
|
|
||||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.common, key, modifiers))
|
|
||||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.global, key, modifiers))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets an action for a key in Edit mode, also checking common keybindings.
|
|
||||||
pub fn get_edit_action_for_key(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
|
||||||
self.get_action_for_key_in_mode(&self.keybindings.edit, key, modifiers)
|
|
||||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.common, key, modifiers))
|
|
||||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.global, key, modifiers))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets an action for a key in Command mode, also checking common keybindings.
|
|
||||||
pub fn get_command_action_for_key(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
|
||||||
self.get_action_for_key_in_mode(&self.keybindings.command, key, modifiers)
|
|
||||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.common, key, modifiers))
|
|
||||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.global, key, modifiers))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Context-aware keybinding resolution
|
|
||||||
pub fn get_action_for_current_context(
|
|
||||||
&self,
|
|
||||||
is_edit_mode: bool,
|
|
||||||
command_mode: bool,
|
|
||||||
key: KeyCode,
|
|
||||||
modifiers: KeyModifiers
|
|
||||||
) -> Option<&str> {
|
|
||||||
match (command_mode, is_edit_mode) {
|
|
||||||
(true, _) => self.get_command_action_for_key(key, modifiers),
|
|
||||||
(_, true) => self.get_edit_action_for_key(key, modifiers)
|
|
||||||
.or_else(|| self.get_common_action(key, modifiers)),
|
|
||||||
_ => self.get_read_only_action_for_key(key, modifiers)
|
|
||||||
.or_else(|| self.get_common_action(key, modifiers))
|
|
||||||
// Add global bindings check for read-only mode
|
|
||||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.global, key, modifiers)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper function to get an action for a key in a specific mode.
|
|
||||||
pub fn get_action_for_key_in_mode<'a>(
|
|
||||||
&self,
|
|
||||||
mode_bindings: &'a HashMap<String, Vec<String>>,
|
|
||||||
key: KeyCode,
|
|
||||||
modifiers: KeyModifiers,
|
|
||||||
) -> Option<&'a str> {
|
|
||||||
for (action, bindings) in mode_bindings {
|
|
||||||
for binding in bindings {
|
|
||||||
if Self::matches_keybinding(binding, key, modifiers) {
|
|
||||||
return Some(action.as_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a sequence of keys matches any keybinding.
|
|
||||||
pub fn matches_key_sequence(&self, sequence: &[KeyCode]) -> Option<&str> {
|
|
||||||
if sequence.is_empty() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert key sequence to a string (for simple character sequences).
|
|
||||||
let sequence_str: String = sequence.iter().filter_map(|key| {
|
|
||||||
if let KeyCode::Char(c) = key {
|
|
||||||
Some(*c)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}).collect();
|
|
||||||
|
|
||||||
if sequence_str.is_empty() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if this sequence matches any binding in the mode-specific sections.
|
|
||||||
for (action, bindings) in &self.keybindings.read_only {
|
|
||||||
for binding in bindings {
|
|
||||||
if binding == &sequence_str {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (action, bindings) in &self.keybindings.edit {
|
|
||||||
for binding in bindings {
|
|
||||||
if binding == &sequence_str {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (action, bindings) in &self.keybindings.command {
|
|
||||||
for binding in bindings {
|
|
||||||
if binding == &sequence_str {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check common keybindings
|
|
||||||
for (action, bindings) in &self.keybindings.common {
|
|
||||||
for binding in bindings {
|
|
||||||
if binding == &sequence_str {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally check global bindings
|
|
||||||
for (action, bindings) in &self.keybindings.global {
|
|
||||||
for binding in bindings {
|
|
||||||
if binding == &sequence_str {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a keybinding matches a key and modifiers.
|
|
||||||
fn matches_keybinding(
|
|
||||||
binding: &str,
|
|
||||||
key: KeyCode,
|
|
||||||
modifiers: KeyModifiers,
|
|
||||||
) -> bool {
|
|
||||||
// For multi-character bindings without modifiers, handle them in matches_key_sequence.
|
|
||||||
if binding.len() > 1 && !binding.contains('+') {
|
|
||||||
return match binding.to_lowercase().as_str() {
|
|
||||||
"left" => key == KeyCode::Left,
|
|
||||||
"right" => key == KeyCode::Right,
|
|
||||||
"up" => key == KeyCode::Up,
|
|
||||||
"down" => key == KeyCode::Down,
|
|
||||||
"esc" => key == KeyCode::Esc,
|
|
||||||
"enter" => key == KeyCode::Enter,
|
|
||||||
"delete" => key == KeyCode::Delete,
|
|
||||||
"backspace" => key == KeyCode::Backspace,
|
|
||||||
"tab" => key == KeyCode::Tab,
|
|
||||||
"backtab" => key == KeyCode::BackTab,
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let parts: Vec<&str> = binding.split('+').collect();
|
|
||||||
let mut expected_modifiers = KeyModifiers::empty();
|
|
||||||
let mut expected_key = None;
|
|
||||||
|
|
||||||
for part in parts {
|
|
||||||
match part.to_lowercase().as_str() {
|
|
||||||
"ctrl" => expected_modifiers |= KeyModifiers::CONTROL,
|
|
||||||
"shift" => expected_modifiers |= KeyModifiers::SHIFT,
|
|
||||||
"alt" => expected_modifiers |= KeyModifiers::ALT,
|
|
||||||
"left" => expected_key = Some(KeyCode::Left),
|
|
||||||
"right" => expected_key = Some(KeyCode::Right),
|
|
||||||
"up" => expected_key = Some(KeyCode::Up),
|
|
||||||
"down" => expected_key = Some(KeyCode::Down),
|
|
||||||
"esc" => expected_key = Some(KeyCode::Esc),
|
|
||||||
"enter" => expected_key = Some(KeyCode::Enter),
|
|
||||||
"delete" => expected_key = Some(KeyCode::Delete),
|
|
||||||
"backspace" => expected_key = Some(KeyCode::Backspace),
|
|
||||||
"tab" => expected_key = Some(KeyCode::Tab),
|
|
||||||
"backtab" => expected_key = Some(KeyCode::BackTab),
|
|
||||||
":" => expected_key = Some(KeyCode::Char(':')),
|
|
||||||
part => {
|
|
||||||
if part.len() == 1 {
|
|
||||||
let c = part.chars().next().unwrap();
|
|
||||||
expected_key = Some(KeyCode::Char(c));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
modifiers == expected_modifiers && Some(key) == expected_key
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets an action for a command string.
|
|
||||||
pub fn get_action_for_command(&self, command: &str) -> Option<&str> {
|
|
||||||
// First check command mode bindings
|
|
||||||
for (action, bindings) in &self.keybindings.command {
|
|
||||||
for binding in bindings {
|
|
||||||
if binding == command {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check common bindings
|
|
||||||
for (action, bindings) in &self.keybindings.common {
|
|
||||||
for binding in bindings {
|
|
||||||
if binding == command {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally check global bindings
|
|
||||||
for (action, bindings) in &self.keybindings.global {
|
|
||||||
for binding in bindings {
|
|
||||||
if binding == command {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a key is bound to entering Edit mode (before cursor).
|
|
||||||
pub fn is_enter_edit_mode_before(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
|
|
||||||
if let Some(bindings) = self.keybindings.read_only.get("enter_edit_mode_before") {
|
|
||||||
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a key is bound to entering Edit mode (after cursor).
|
|
||||||
pub fn is_enter_edit_mode_after(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
|
|
||||||
if let Some(bindings) = self.keybindings.read_only.get("enter_edit_mode_after") {
|
|
||||||
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a key is bound to entering Edit mode.
|
|
||||||
pub fn is_enter_edit_mode(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
|
|
||||||
self.is_enter_edit_mode_before(key, modifiers) || self.is_enter_edit_mode_after(key, modifiers)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a key is bound to exiting Edit mode.
|
|
||||||
pub fn is_exit_edit_mode(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
|
|
||||||
if let Some(bindings) = self.keybindings.edit.get("exit_edit_mode") {
|
|
||||||
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a key is bound to entering Command mode.
|
|
||||||
/// This method is no longer used in event.rs since we now handle command mode entry only in read-only mode directly.
|
|
||||||
pub fn is_enter_command_mode(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
|
|
||||||
if let Some(bindings) = self.keybindings.command.get("enter_command_mode") {
|
|
||||||
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Checks if a key is bound to exiting Command mode.
|
|
||||||
pub fn is_exit_command_mode(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
|
|
||||||
if let Some(bindings) = self.keybindings.command.get("exit_command_mode") {
|
|
||||||
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a key is bound to executing a command.
|
|
||||||
pub fn is_command_execute(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
|
|
||||||
if let Some(bindings) = self.keybindings.command.get("command_execute") {
|
|
||||||
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
|
|
||||||
} else {
|
|
||||||
// Fall back to Enter key if no command_execute is defined.
|
|
||||||
key == KeyCode::Enter && modifiers.is_empty()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a key is bound to backspacing in Command mode.
|
|
||||||
pub fn is_command_backspace(&self, key: KeyCode, modifiers: KeyModifiers) -> bool {
|
|
||||||
if let Some(bindings) = self.keybindings.command.get("command_backspace") {
|
|
||||||
bindings.iter().any(|b| Self::matches_keybinding(b, key, modifiers))
|
|
||||||
} else {
|
|
||||||
// Fall back to Backspace key if no command_backspace is defined.
|
|
||||||
key == KeyCode::Backspace && modifiers.is_empty()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a key is bound to a specific action.
|
|
||||||
pub fn has_key_for_action(&self, action: &str, key_char: char) -> bool {
|
|
||||||
// Check all mode-specific keybindings for the action
|
|
||||||
if let Some(bindings) = self.keybindings.read_only.get(action) {
|
|
||||||
if bindings.iter().any(|binding| binding == &key_char.to_string()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(bindings) = self.keybindings.edit.get(action) {
|
|
||||||
if bindings.iter().any(|binding| binding == &key_char.to_string()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(bindings) = self.keybindings.command.get(action) {
|
|
||||||
if bindings.iter().any(|binding| binding == &key_char.to_string()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(bindings) = self.keybindings.common.get(action) {
|
|
||||||
if bindings.iter().any(|binding| binding == &key_char.to_string()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(bindings) = self.keybindings.global.get(action) {
|
|
||||||
if bindings.iter().any(|binding| binding == &key_char.to_string()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This method handles all keybinding formats, both with and without +
|
|
||||||
pub fn matches_key_sequence_generalized(&self, sequence: &[KeyCode]) -> Option<&str> {
|
|
||||||
if sequence.is_empty() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get string representations of the sequence
|
|
||||||
let sequence_str = sequence.iter()
|
|
||||||
.map(|k| crate::config::binds::key_sequences::key_to_string(k))
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join("");
|
|
||||||
|
|
||||||
// Add the missing sequence_plus definition
|
|
||||||
let sequence_plus = sequence.iter()
|
|
||||||
.map(|k| crate::config::binds::key_sequences::key_to_string(k))
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join("+");
|
|
||||||
|
|
||||||
// Check for matches in all binding formats across all modes
|
|
||||||
// First check read_only mode
|
|
||||||
if let Some(action) = self.check_bindings_for_sequence(&self.keybindings.read_only, &sequence_str, &sequence_plus, sequence) {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check edit mode
|
|
||||||
if let Some(action) = self.check_bindings_for_sequence(&self.keybindings.edit, &sequence_str, &sequence_plus, sequence) {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check command mode
|
|
||||||
if let Some(action) = self.check_bindings_for_sequence(&self.keybindings.command, &sequence_str, &sequence_plus, sequence) {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check common keybindings
|
|
||||||
if let Some(action) = self.check_bindings_for_sequence(&self.keybindings.common, &sequence_str, &sequence_plus, sequence) {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally check global bindings
|
|
||||||
if let Some(action) = self.check_bindings_for_sequence(&self.keybindings.global, &sequence_str, &sequence_plus, sequence) {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper method to check a specific mode's bindings against a key sequence
|
|
||||||
fn check_bindings_for_sequence<'a>(
|
|
||||||
&self,
|
|
||||||
mode_bindings: &'a HashMap<String, Vec<String>>,
|
|
||||||
sequence_str: &str,
|
|
||||||
sequence_plus: &str,
|
|
||||||
sequence: &[KeyCode]
|
|
||||||
) -> Option<&'a str> {
|
|
||||||
for (action, bindings) in mode_bindings {
|
|
||||||
for binding in bindings {
|
|
||||||
let normalized_binding = binding.to_lowercase();
|
|
||||||
|
|
||||||
// Check if binding matches any of our formats
|
|
||||||
if normalized_binding == sequence_str || normalized_binding == sequence_plus {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Special case for + format in bindings
|
|
||||||
if binding.contains('+') {
|
|
||||||
let normalized_sequence = sequence.iter()
|
|
||||||
.map(|k| crate::config::binds::key_sequences::key_to_string(k))
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
|
|
||||||
let binding_parts: Vec<&str> = binding.split('+').collect();
|
|
||||||
|
|
||||||
if binding_parts.len() == sequence.len() {
|
|
||||||
let matches = binding_parts.iter().enumerate().all(|(i, part)| {
|
|
||||||
part.to_lowercase() == normalized_sequence[i].to_lowercase()
|
|
||||||
});
|
|
||||||
|
|
||||||
if matches {
|
|
||||||
return Some(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if the current key sequence is a prefix of a longer binding
|
|
||||||
pub fn is_key_sequence_prefix(&self, sequence: &[KeyCode]) -> bool {
|
|
||||||
if sequence.is_empty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get string representation of the sequence
|
|
||||||
let sequence_str = sequence.iter()
|
|
||||||
.map(|k| crate::config::binds::key_sequences::key_to_string(k))
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join("");
|
|
||||||
|
|
||||||
// Check in each mode if our sequence is a prefix
|
|
||||||
if self.is_prefix_in_mode(&self.keybindings.read_only, &sequence_str, sequence) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.is_prefix_in_mode(&self.keybindings.edit, &sequence_str, sequence) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.is_prefix_in_mode(&self.keybindings.command, &sequence_str, sequence) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.is_prefix_in_mode(&self.keybindings.common, &sequence_str, sequence) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.is_prefix_in_mode(&self.keybindings.global, &sequence_str, sequence) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper method to check if a sequence is a prefix in a specific mode
|
|
||||||
fn is_prefix_in_mode(
|
|
||||||
&self,
|
|
||||||
mode_bindings: &HashMap<String, Vec<String>>,
|
|
||||||
sequence_str: &str,
|
|
||||||
sequence: &[KeyCode]
|
|
||||||
) -> bool {
|
|
||||||
for (_, bindings) in mode_bindings {
|
|
||||||
for binding in bindings {
|
|
||||||
let normalized_binding = binding.to_lowercase();
|
|
||||||
|
|
||||||
// Check standard format
|
|
||||||
if normalized_binding.starts_with(sequence_str) &&
|
|
||||||
normalized_binding.len() > sequence_str.len() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check + format
|
|
||||||
if binding.contains('+') {
|
|
||||||
let binding_parts: Vec<&str> = binding.split('+').collect();
|
|
||||||
let sequence_parts = sequence.iter()
|
|
||||||
.map(|k| crate::config::binds::key_sequences::key_to_string(k))
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
|
|
||||||
if binding_parts.len() > sequence_parts.len() {
|
|
||||||
let prefix_matches = sequence_parts.iter().enumerate().all(|(i, part)| {
|
|
||||||
binding_parts.get(i).map_or(false, |b| b.to_lowercase() == part.to_lowercase())
|
|
||||||
});
|
|
||||||
|
|
||||||
if prefix_matches {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
// client/src/config/key_sequences.rs
|
|
||||||
use crossterm::event::{KeyCode, KeyModifiers};
|
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub struct ParsedKey {
|
|
||||||
pub code: KeyCode,
|
|
||||||
pub modifiers: KeyModifiers,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct KeySequenceTracker {
|
|
||||||
pub current_sequence: Vec<KeyCode>,
|
|
||||||
pub last_key_time: Instant,
|
|
||||||
pub timeout: Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl KeySequenceTracker {
|
|
||||||
pub fn new(timeout_ms: u64) -> Self {
|
|
||||||
Self {
|
|
||||||
current_sequence: Vec::new(),
|
|
||||||
last_key_time: Instant::now(),
|
|
||||||
timeout: Duration::from_millis(timeout_ms),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
|
||||||
self.current_sequence.clear();
|
|
||||||
self.last_key_time = Instant::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_key(&mut self, key: KeyCode) -> bool {
|
|
||||||
// Check if timeout has expired
|
|
||||||
let now = Instant::now();
|
|
||||||
if now.duration_since(self.last_key_time) > self.timeout {
|
|
||||||
self.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.current_sequence.push(key);
|
|
||||||
self.last_key_time = now;
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_sequence(&self) -> Vec<KeyCode> {
|
|
||||||
self.current_sequence.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert a sequence of keys to a string representation
|
|
||||||
pub fn sequence_to_string(&self) -> String {
|
|
||||||
self.current_sequence.iter().map(|k| key_to_string(k)).collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert a sequence to a format with + between keys
|
|
||||||
pub fn sequence_to_plus_format(&self) -> String {
|
|
||||||
if self.current_sequence.is_empty() {
|
|
||||||
return String::new();
|
|
||||||
}
|
|
||||||
|
|
||||||
let parts: Vec<String> = self.current_sequence.iter()
|
|
||||||
.map(|k| key_to_string(k))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
parts.join("+")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to convert any KeyCode to a string representation
|
|
||||||
pub fn key_to_string(key: &KeyCode) -> String {
|
|
||||||
match key {
|
|
||||||
KeyCode::Char(c) => c.to_string(),
|
|
||||||
KeyCode::Left => "left".to_string(),
|
|
||||||
KeyCode::Right => "right".to_string(),
|
|
||||||
KeyCode::Up => "up".to_string(),
|
|
||||||
KeyCode::Down => "down".to_string(),
|
|
||||||
KeyCode::Esc => "esc".to_string(),
|
|
||||||
KeyCode::Enter => "enter".to_string(),
|
|
||||||
KeyCode::Backspace => "backspace".to_string(),
|
|
||||||
KeyCode::Delete => "delete".to_string(),
|
|
||||||
KeyCode::Tab => "tab".to_string(),
|
|
||||||
KeyCode::BackTab => "backtab".to_string(),
|
|
||||||
KeyCode::Home => "home".to_string(),
|
|
||||||
KeyCode::End => "end".to_string(),
|
|
||||||
KeyCode::PageUp => "pageup".to_string(),
|
|
||||||
KeyCode::PageDown => "pagedown".to_string(),
|
|
||||||
KeyCode::Insert => "insert".to_string(),
|
|
||||||
_ => format!("{:?}", key).to_lowercase(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to convert a string to a KeyCode
|
|
||||||
pub fn string_to_keycode(s: &str) -> Option<KeyCode> {
|
|
||||||
match s.to_lowercase().as_str() {
|
|
||||||
"left" => Some(KeyCode::Left),
|
|
||||||
"right" => Some(KeyCode::Right),
|
|
||||||
"up" => Some(KeyCode::Up),
|
|
||||||
"down" => Some(KeyCode::Down),
|
|
||||||
"esc" => Some(KeyCode::Esc),
|
|
||||||
"enter" => Some(KeyCode::Enter),
|
|
||||||
"backspace" => Some(KeyCode::Backspace),
|
|
||||||
"delete" => Some(KeyCode::Delete),
|
|
||||||
"tab" => Some(KeyCode::Tab),
|
|
||||||
"backtab" => Some(KeyCode::BackTab),
|
|
||||||
"home" => Some(KeyCode::Home),
|
|
||||||
"end" => Some(KeyCode::End),
|
|
||||||
"pageup" => Some(KeyCode::PageUp),
|
|
||||||
"pagedown" => Some(KeyCode::PageDown),
|
|
||||||
"insert" => Some(KeyCode::Insert),
|
|
||||||
s if s.len() == 1 => s.chars().next().map(KeyCode::Char),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_binding(binding: &str) -> Vec<ParsedKey> {
|
|
||||||
let mut sequence = Vec::new();
|
|
||||||
|
|
||||||
// Handle different binding formats
|
|
||||||
let parts: Vec<String> = if binding.contains('+') {
|
|
||||||
// Format with explicit '+' separators like "g+left"
|
|
||||||
binding.split('+').map(|s| s.to_string()).collect()
|
|
||||||
} else if binding.contains(' ') {
|
|
||||||
// Format with spaces like "g left"
|
|
||||||
binding.split(' ').map(|s| s.to_string()).collect()
|
|
||||||
} else if is_compound_key(binding) {
|
|
||||||
// A single compound key like "left" or "enter"
|
|
||||||
vec![binding.to_string()]
|
|
||||||
} else {
|
|
||||||
// Simple character sequence like "gg"
|
|
||||||
binding.chars().map(|c| c.to_string()).collect()
|
|
||||||
};
|
|
||||||
|
|
||||||
for part in &parts {
|
|
||||||
if let Some(key) = parse_key_part(part) {
|
|
||||||
sequence.push(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sequence
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_compound_key(part: &str) -> bool {
|
|
||||||
matches!(part.to_lowercase().as_str(),
|
|
||||||
"esc" | "up" | "down" | "left" | "right" | "enter" |
|
|
||||||
"backspace" | "delete" | "tab" | "backtab" | "home" |
|
|
||||||
"end" | "pageup" | "pagedown" | "insert"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_key_part(part: &str) -> Option<ParsedKey> {
|
|
||||||
let mut modifiers = KeyModifiers::empty();
|
|
||||||
let mut code = None;
|
|
||||||
|
|
||||||
if part.contains('+') {
|
|
||||||
// This handles modifiers like "ctrl+s"
|
|
||||||
let components: Vec<&str> = part.split('+').collect();
|
|
||||||
|
|
||||||
for component in components {
|
|
||||||
match component.to_lowercase().as_str() {
|
|
||||||
"ctrl" => modifiers |= KeyModifiers::CONTROL,
|
|
||||||
"shift" => modifiers |= KeyModifiers::SHIFT,
|
|
||||||
"alt" => modifiers |= KeyModifiers::ALT,
|
|
||||||
_ => {
|
|
||||||
// Last component is the key
|
|
||||||
code = string_to_keycode(component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Simple key without modifiers
|
|
||||||
code = string_to_keycode(part);
|
|
||||||
}
|
|
||||||
|
|
||||||
code.map(|code| ParsedKey { code, modifiers })
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// src/config/colors.rs
|
|
||||||
pub mod themes;
|
|
||||||
|
|
||||||
pub use themes::*;
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
// src/client/themes/colors.rs
|
|
||||||
use ratatui::style::Color;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Theme {
|
|
||||||
pub bg: Color,
|
|
||||||
pub fg: Color,
|
|
||||||
pub accent: Color,
|
|
||||||
pub secondary: Color,
|
|
||||||
pub highlight: Color,
|
|
||||||
pub warning: Color,
|
|
||||||
pub border: Color,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Theme {
|
|
||||||
pub fn from_str(theme_name: &str) -> Self {
|
|
||||||
match theme_name.to_lowercase().as_str() {
|
|
||||||
"dark" => Self::dark(),
|
|
||||||
"high_contrast" => Self::high_contrast(),
|
|
||||||
_ => Self::light(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default light theme
|
|
||||||
pub fn light() -> Self {
|
|
||||||
Self {
|
|
||||||
bg: Color::Rgb(245, 245, 245), // Light gray
|
|
||||||
fg: Color::Rgb(64, 64, 64), // Dark gray
|
|
||||||
accent: Color::Rgb(173, 216, 230), // Pastel blue
|
|
||||||
secondary: Color::Rgb(255, 165, 0), // Orange for secondary
|
|
||||||
highlight: Color::Rgb(152, 251, 152), // Pastel green
|
|
||||||
warning: Color::Rgb(255, 182, 193), // Pastel pink
|
|
||||||
border: Color::Rgb(220, 220, 220), // Light gray border
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// High-contrast dark theme
|
|
||||||
pub fn dark() -> Self {
|
|
||||||
Self {
|
|
||||||
bg: Color::Rgb(30, 30, 30), // Dark background
|
|
||||||
fg: Color::Rgb(255, 255, 255), // White text
|
|
||||||
accent: Color::Rgb(0, 191, 255), // Bright blue
|
|
||||||
secondary: Color::Rgb(255, 215, 0), // Gold for secondary
|
|
||||||
highlight: Color::Rgb(50, 205, 50), // Bright green
|
|
||||||
warning: Color::Rgb(255, 99, 71), // Bright red
|
|
||||||
border: Color::Rgb(100, 100, 100), // Medium gray border
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// High-contrast light theme
|
|
||||||
pub fn high_contrast() -> Self {
|
|
||||||
Self {
|
|
||||||
bg: Color::Rgb(255, 255, 255), // White background
|
|
||||||
fg: Color::Rgb(0, 0, 0), // Black text
|
|
||||||
accent: Color::Rgb(0, 0, 255), // Blue
|
|
||||||
secondary: Color::Rgb(255, 140, 0), // Dark orange for secondary
|
|
||||||
highlight: Color::Rgb(0, 128, 0), // Green
|
|
||||||
warning: Color::Rgb(255, 0, 0), // Red
|
|
||||||
border: Color::Rgb(0, 0, 0), // Black border
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Theme {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::light() // Default to light theme
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// src/config/mod.rs
|
|
||||||
|
|
||||||
pub mod binds;
|
|
||||||
pub mod colors;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
// client/src/lib.rs
|
|
||||||
pub mod ui;
|
|
||||||
pub mod tui;
|
|
||||||
pub mod config;
|
|
||||||
pub mod state;
|
|
||||||
pub mod components;
|
|
||||||
pub mod modes;
|
|
||||||
pub mod services;
|
|
||||||
|
|
||||||
pub use ui::run_ui;
|
|
||||||
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// client/src/main.rs
|
|
||||||
use client::run_ui;
|
|
||||||
use dotenvy::dotenv;
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> Result<(), Box<dyn Error>> {
|
|
||||||
dotenv().ok();
|
|
||||||
run_ui().await
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// src/client/modes/canvas.rs
|
|
||||||
pub mod edit;
|
|
||||||
pub mod common;
|
|
||||||
pub mod read_only;
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
// src/modes/canvas/common.rs
|
|
||||||
|
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
|
||||||
use crate::state::pages::{form::FormState, auth::AuthState};
|
|
||||||
use crate::state::state::AppState;
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
|
||||||
use crate::services::auth::AuthClient;
|
|
||||||
use crate::tui::functions::common::{
|
|
||||||
form::{save as form_save, revert},
|
|
||||||
login::{save as login_save, cancel}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub async fn handle_core_action(
|
|
||||||
action: &str,
|
|
||||||
form_state: &mut FormState,
|
|
||||||
auth_state: &mut AuthState,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
auth_client: &mut AuthClient,
|
|
||||||
terminal: &mut TerminalCore,
|
|
||||||
app_state: &mut AppState,
|
|
||||||
current_position: &mut u64,
|
|
||||||
total_count: u64,
|
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
|
||||||
match action {
|
|
||||||
"save" => {
|
|
||||||
if app_state.ui.show_login {
|
|
||||||
let message = login_save(auth_state, auth_client, app_state).await?;
|
|
||||||
Ok((false, message))
|
|
||||||
} else {
|
|
||||||
let message = form_save(
|
|
||||||
form_state,
|
|
||||||
grpc_client,
|
|
||||||
&mut app_state.ui.is_saved,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await?;
|
|
||||||
Ok((false, message))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"force_quit" => {
|
|
||||||
terminal.cleanup()?;
|
|
||||||
Ok((true, "Force exiting without saving.".to_string()))
|
|
||||||
},
|
|
||||||
"save_and_quit" => {
|
|
||||||
let message = if app_state.ui.show_login {
|
|
||||||
login_save(auth_state, auth_client, app_state).await?
|
|
||||||
} else {
|
|
||||||
form_save(
|
|
||||||
form_state,
|
|
||||||
grpc_client,
|
|
||||||
&mut app_state.ui.is_saved,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await?
|
|
||||||
};
|
|
||||||
terminal.cleanup()?;
|
|
||||||
Ok((true, format!("{}. Exiting application.", message)))
|
|
||||||
},
|
|
||||||
"revert" => {
|
|
||||||
if app_state.ui.show_login {
|
|
||||||
let message = cancel(auth_state, app_state).await;
|
|
||||||
Ok((false, message))
|
|
||||||
} else {
|
|
||||||
let message = revert(
|
|
||||||
form_state,
|
|
||||||
grpc_client,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await?;
|
|
||||||
Ok((false, message))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => Ok((false, format!("Core action not handled: {}", action))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,511 +0,0 @@
|
|||||||
// src/modes/canvas/edit.rs
|
|
||||||
|
|
||||||
// TODO THIS is freaking bloated with functions it never uses REFACTOR 200 LOC can be gone
|
|
||||||
|
|
||||||
use std::any::Any;
|
|
||||||
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
|
||||||
use crate::config::binds::config::Config;
|
|
||||||
use crate::state::canvas_state::CanvasState;
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
|
||||||
use crate::tui::functions::common::form::{save, revert};
|
|
||||||
|
|
||||||
pub async fn handle_edit_event_internal<S: CanvasState + Any>(
|
|
||||||
key: KeyEvent,
|
|
||||||
config: &Config,
|
|
||||||
state: &mut S,
|
|
||||||
ideal_cursor_column: &mut usize,
|
|
||||||
command_message: &mut String,
|
|
||||||
is_saved: &mut bool,
|
|
||||||
current_position: &mut u64,
|
|
||||||
total_count: u64,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
if let Some("enter_command_mode") = config.get_action_for_key_in_mode(&config.keybindings.global, key.code, key.modifiers) {
|
|
||||||
handle_edit_specific_input(key, state, ideal_cursor_column);
|
|
||||||
return Ok(command_message.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(action) = config.get_action_for_key_in_mode(&config.keybindings.common, key.code, key.modifiers) {
|
|
||||||
return execute_common_action(
|
|
||||||
action,
|
|
||||||
state,
|
|
||||||
grpc_client,
|
|
||||||
is_saved,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(action) = config.get_edit_action_for_key(key.code, key.modifiers) {
|
|
||||||
return execute_edit_action(
|
|
||||||
action,
|
|
||||||
state,
|
|
||||||
ideal_cursor_column,
|
|
||||||
grpc_client,
|
|
||||||
is_saved,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
handle_edit_specific_input(key, state, ideal_cursor_column);
|
|
||||||
Ok(command_message.clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn execute_common_action<S: CanvasState + Any>(
|
|
||||||
action: &str,
|
|
||||||
state: &mut S,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
is_saved: &mut bool,
|
|
||||||
current_position: &mut u64,
|
|
||||||
total_count: u64,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
match action {
|
|
||||||
"save" | "revert" if state.has_unsaved_changes() => {
|
|
||||||
if let Some(form_state) = (state as &mut dyn Any).downcast_mut::<FormState>() {
|
|
||||||
return match action {
|
|
||||||
"save" => save(form_state, grpc_client, is_saved, current_position, total_count).await,
|
|
||||||
"revert" => revert(form_state, grpc_client, current_position, total_count).await,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Ok("Action not available in this context".to_string())
|
|
||||||
}
|
|
||||||
"move_up" | "move_down" => {
|
|
||||||
execute_edit_action(
|
|
||||||
action,
|
|
||||||
state,
|
|
||||||
&mut 0,
|
|
||||||
grpc_client,
|
|
||||||
is_saved,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await
|
|
||||||
}
|
|
||||||
_ => Ok(format!("Common action not handled: {}", action)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_edit_specific_input<S: CanvasState>( // No Any needed here
|
|
||||||
key: KeyEvent,
|
|
||||||
state: &mut S,
|
|
||||||
ideal_cursor_column: &mut usize,
|
|
||||||
) {
|
|
||||||
match key.code {
|
|
||||||
KeyCode::Char(c) => {
|
|
||||||
let cursor_pos = state.current_cursor_pos();
|
|
||||||
let field_value = state.get_current_input_mut();
|
|
||||||
let mut chars: Vec<char> = field_value.chars().collect();
|
|
||||||
if cursor_pos <= chars.len() {
|
|
||||||
chars.insert(cursor_pos, c);
|
|
||||||
*field_value = chars.into_iter().collect();
|
|
||||||
// Use trait setters
|
|
||||||
state.set_current_cursor_pos(cursor_pos + 1);
|
|
||||||
state.set_has_unsaved_changes(true);
|
|
||||||
*ideal_cursor_column = state.current_cursor_pos(); // Update ideal column
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KeyCode::Backspace => {
|
|
||||||
if state.current_cursor_pos() > 0 {
|
|
||||||
let cursor_pos = state.current_cursor_pos();
|
|
||||||
let field_value = state.get_current_input_mut();
|
|
||||||
let mut chars: Vec<char> = field_value.chars().collect();
|
|
||||||
if cursor_pos <= chars.len() && cursor_pos > 0 {
|
|
||||||
chars.remove(cursor_pos - 1);
|
|
||||||
*field_value = chars.into_iter().collect();
|
|
||||||
// Use trait setters
|
|
||||||
state.set_current_cursor_pos(cursor_pos - 1);
|
|
||||||
state.set_has_unsaved_changes(true);
|
|
||||||
*ideal_cursor_column = state.current_cursor_pos(); // Update ideal column
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KeyCode::Delete => {
|
|
||||||
let cursor_pos = state.current_cursor_pos();
|
|
||||||
let field_value = state.get_current_input_mut();
|
|
||||||
let chars: Vec<char> = field_value.chars().collect();
|
|
||||||
if cursor_pos < chars.len() {
|
|
||||||
let mut new_chars = chars.clone();
|
|
||||||
new_chars.remove(cursor_pos);
|
|
||||||
*field_value = new_chars.into_iter().collect();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_has_unsaved_changes(true);
|
|
||||||
// Cursor position doesn't change, but ideal might if text changed
|
|
||||||
*ideal_cursor_column = state.current_cursor_pos();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KeyCode::Tab => {
|
|
||||||
let num_fields = state.fields().len();
|
|
||||||
if num_fields > 0 { // Avoid panic on empty fields
|
|
||||||
let current_field = state.current_field();
|
|
||||||
let new_field = if key.modifiers.contains(KeyModifiers::SHIFT) {
|
|
||||||
if current_field == 0 { num_fields - 1 } else { current_field - 1 }
|
|
||||||
} else {
|
|
||||||
(current_field + 1) % num_fields
|
|
||||||
};
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_field(new_field);
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
let max_cursor_pos = current_input.len();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos((*ideal_cursor_column).min(max_cursor_pos));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KeyCode::Enter => {
|
|
||||||
let num_fields = state.fields().len();
|
|
||||||
if num_fields > 0 { // Avoid panic on empty fields
|
|
||||||
let new_field = (state.current_field() + 1) % num_fields;
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_field(new_field);
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
let max_cursor_pos = current_input.len();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos((*ideal_cursor_column).min(max_cursor_pos));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn execute_edit_action<S: CanvasState>( // No Any needed here
|
|
||||||
action: &str,
|
|
||||||
state: &mut S,
|
|
||||||
ideal_cursor_column: &mut usize,
|
|
||||||
// These parameters are unused if save/revert aren't handled here,
|
|
||||||
// but keep them for now if execute_common_action calls this
|
|
||||||
_grpc_client: &mut GrpcClient,
|
|
||||||
_is_saved: &mut bool,
|
|
||||||
_current_position: &mut u64,
|
|
||||||
_total_count: u64,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
match action {
|
|
||||||
"move_left" => {
|
|
||||||
let new_pos = state.current_cursor_pos().saturating_sub(1);
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos(new_pos);
|
|
||||||
*ideal_cursor_column = new_pos;
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_right" => {
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
let current_pos = state.current_cursor_pos();
|
|
||||||
// Allow moving cursor to position *after* last character
|
|
||||||
if current_pos < current_input.len() {
|
|
||||||
let new_pos = current_pos + 1;
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos(new_pos);
|
|
||||||
*ideal_cursor_column = new_pos;
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_up" => {
|
|
||||||
let num_fields = state.fields().len();
|
|
||||||
if num_fields > 0 {
|
|
||||||
let current_field = state.current_field();
|
|
||||||
let new_field = if current_field == 0 { num_fields - 1 } else { current_field - 1 };
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_field(new_field);
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
let max_pos = current_input.len();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos((*ideal_cursor_column).min(max_pos));
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_down" => {
|
|
||||||
let num_fields = state.fields().len();
|
|
||||||
if num_fields > 0 {
|
|
||||||
let new_field = (state.current_field() + 1) % num_fields;
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_field(new_field);
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
let max_pos = current_input.len();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos((*ideal_cursor_column).min(max_pos));
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_line_start" => {
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos(0);
|
|
||||||
*ideal_cursor_column = 0;
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_line_end" => {
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
let new_pos = current_input.len();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos(new_pos);
|
|
||||||
*ideal_cursor_column = new_pos;
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_first_line" => {
|
|
||||||
let num_fields = state.fields().len();
|
|
||||||
if num_fields > 0 {
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_field(0);
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
let max_pos = current_input.len();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos((*ideal_cursor_column).min(max_pos));
|
|
||||||
}
|
|
||||||
Ok("Moved to first line".to_string())
|
|
||||||
}
|
|
||||||
"move_last_line" => {
|
|
||||||
let num_fields = state.fields().len();
|
|
||||||
if num_fields > 0 {
|
|
||||||
let new_field = num_fields - 1;
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_field(new_field);
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
let max_pos = current_input.len();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos((*ideal_cursor_column).min(max_pos));
|
|
||||||
}
|
|
||||||
Ok("Moved to last line".to_string())
|
|
||||||
}
|
|
||||||
"move_word_next" => {
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
if !current_input.is_empty() {
|
|
||||||
let new_pos = find_next_word_start(current_input, state.current_cursor_pos());
|
|
||||||
let final_pos = new_pos.min(current_input.len());
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos(final_pos);
|
|
||||||
*ideal_cursor_column = final_pos;
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_word_end" => {
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
if !current_input.is_empty() {
|
|
||||||
let new_pos = find_word_end(current_input, state.current_cursor_pos());
|
|
||||||
let final_pos = new_pos.min(current_input.len());
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos(final_pos);
|
|
||||||
*ideal_cursor_column = final_pos;
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_word_prev" => {
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
if !current_input.is_empty() {
|
|
||||||
let new_pos = find_prev_word_start(current_input, state.current_cursor_pos());
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos(new_pos);
|
|
||||||
*ideal_cursor_column = new_pos;
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_word_end_prev" => {
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
if !current_input.is_empty() {
|
|
||||||
let new_pos = find_prev_word_end(current_input, state.current_cursor_pos());
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos(new_pos);
|
|
||||||
*ideal_cursor_column = new_pos;
|
|
||||||
}
|
|
||||||
Ok("Moved to previous word end".to_string())
|
|
||||||
}
|
|
||||||
"delete_char_forward" => {
|
|
||||||
let cursor_pos = state.current_cursor_pos();
|
|
||||||
let field_value = state.get_current_input_mut();
|
|
||||||
let mut chars: Vec<char> = field_value.chars().collect(); // Use mut for modification
|
|
||||||
if cursor_pos < chars.len() {
|
|
||||||
chars.remove(cursor_pos);
|
|
||||||
*field_value = chars.into_iter().collect();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_has_unsaved_changes(true);
|
|
||||||
// Cursor position doesn't change
|
|
||||||
*ideal_cursor_column = cursor_pos;
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"delete_char_backward" => {
|
|
||||||
if state.current_cursor_pos() > 0 {
|
|
||||||
let cursor_pos = state.current_cursor_pos();
|
|
||||||
let field_value = state.get_current_input_mut();
|
|
||||||
let mut chars: Vec<char> = field_value.chars().collect(); // Use mut
|
|
||||||
if cursor_pos <= chars.len() && cursor_pos > 0 {
|
|
||||||
chars.remove(cursor_pos - 1);
|
|
||||||
*field_value = chars.into_iter().collect();
|
|
||||||
let new_pos = cursor_pos - 1;
|
|
||||||
// Use trait setters
|
|
||||||
state.set_current_cursor_pos(new_pos);
|
|
||||||
state.set_has_unsaved_changes(true);
|
|
||||||
*ideal_cursor_column = new_pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"insert_char" => {
|
|
||||||
// This action doesn't make sense here as char insertion is handled
|
|
||||||
// directly in handle_edit_specific_input
|
|
||||||
Ok("Character insertion handled directly".to_string())
|
|
||||||
}
|
|
||||||
"next_field" => {
|
|
||||||
let num_fields = state.fields().len();
|
|
||||||
if num_fields > 0 {
|
|
||||||
let new_field = (state.current_field() + 1) % num_fields;
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_field(new_field);
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
let max_pos = current_input.len();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos((*ideal_cursor_column).min(max_pos));
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"prev_field" => {
|
|
||||||
let num_fields = state.fields().len();
|
|
||||||
if num_fields > 0 {
|
|
||||||
let current_field = state.current_field();
|
|
||||||
let new_field = if current_field == 0 { num_fields - 1 } else { current_field - 1 };
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_field(new_field);
|
|
||||||
let current_input = state.get_current_input();
|
|
||||||
let max_pos = current_input.len();
|
|
||||||
// Use trait setter
|
|
||||||
state.set_current_cursor_pos((*ideal_cursor_column).min(max_pos));
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
_ => Ok(format!("Unknown edit action: {}", action)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
|
||||||
enum CharType {
|
|
||||||
Whitespace,
|
|
||||||
Alphanumeric,
|
|
||||||
Punctuation,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_char_type(c: char) -> CharType {
|
|
||||||
if c.is_whitespace() {
|
|
||||||
CharType::Whitespace
|
|
||||||
} else if c.is_alphanumeric() {
|
|
||||||
CharType::Alphanumeric
|
|
||||||
} else {
|
|
||||||
CharType::Punctuation
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_next_word_start(text: &str, current_pos: usize) -> usize {
|
|
||||||
let chars: Vec<char> = text.chars().collect();
|
|
||||||
if chars.is_empty() || current_pos >= chars.len() {
|
|
||||||
return current_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pos = current_pos;
|
|
||||||
let initial_type = get_char_type(chars[pos]);
|
|
||||||
while pos < chars.len() && get_char_type(chars[pos]) == initial_type {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while pos < chars.len() && get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_word_end(text: &str, current_pos: usize) -> usize {
|
|
||||||
let chars: Vec<char> = text.chars().collect();
|
|
||||||
if chars.is_empty() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if current_pos >= chars.len() - 1 {
|
|
||||||
return chars.len() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pos = current_pos;
|
|
||||||
|
|
||||||
if get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
while pos < chars.len() && get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let current_type = get_char_type(chars[pos]);
|
|
||||||
if pos + 1 < chars.len() && get_char_type(chars[pos + 1]) != current_type {
|
|
||||||
pos += 1;
|
|
||||||
while pos < chars.len() && get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if pos >= chars.len() {
|
|
||||||
return chars.len() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let word_type = get_char_type(chars[pos]);
|
|
||||||
while pos + 1 < chars.len() && get_char_type(chars[pos + 1]) == word_type {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_prev_word_start(text: &str, current_pos: usize) -> usize {
|
|
||||||
let chars: Vec<char> = text.chars().collect();
|
|
||||||
if chars.is_empty() || current_pos == 0 {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pos = current_pos.saturating_sub(1);
|
|
||||||
|
|
||||||
while pos > 0 && get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if get_char_type(chars[pos]) != CharType::Whitespace {
|
|
||||||
let word_type = get_char_type(chars[pos]);
|
|
||||||
while pos > 0 && get_char_type(chars[pos - 1]) == word_type {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_prev_word_end(text: &str, current_pos: usize) -> usize {
|
|
||||||
let chars: Vec<char> = text.chars().collect();
|
|
||||||
if chars.is_empty() || current_pos <= 1 {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pos = current_pos.saturating_sub(1);
|
|
||||||
|
|
||||||
while pos > 0 && get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if pos > 0 && get_char_type(chars[pos]) != CharType::Whitespace {
|
|
||||||
let word_type = get_char_type(chars[pos]);
|
|
||||||
|
|
||||||
while pos > 0 && get_char_type(chars[pos - 1]) == word_type {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while pos > 0 && get_char_type(chars[pos - 1]) == CharType::Whitespace {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if pos > 0 {
|
|
||||||
pos -= 1;
|
|
||||||
let prev_word_type = get_char_type(chars[pos]);
|
|
||||||
while pos > 0 && get_char_type(chars[pos - 1]) == prev_word_type {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while pos < chars.len() - 1 &&
|
|
||||||
get_char_type(chars[pos + 1]) == prev_word_type {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pos
|
|
||||||
}
|
|
||||||
@@ -1,412 +0,0 @@
|
|||||||
// src/modes/canvas/read_only.rs
|
|
||||||
|
|
||||||
use crossterm::event::{KeyEvent};
|
|
||||||
use crate::config::binds::config::Config;
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
use crate::state::pages::auth::AuthState;
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
|
||||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
|
||||||
enum CharType {
|
|
||||||
Whitespace,
|
|
||||||
Alphanumeric,
|
|
||||||
Punctuation,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn handle_read_only_event(
|
|
||||||
app_state: &crate::state::state::AppState,
|
|
||||||
key: KeyEvent,
|
|
||||||
config: &Config,
|
|
||||||
form_state: &mut FormState,
|
|
||||||
auth_state: &mut AuthState,
|
|
||||||
key_sequence_tracker: &mut KeySequenceTracker,
|
|
||||||
current_position: &mut u64,
|
|
||||||
total_count: u64,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
command_message: &mut String,
|
|
||||||
edit_mode_cooldown: &mut bool,
|
|
||||||
ideal_cursor_column: &mut usize,
|
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
|
||||||
// Check for entering Edit mode from Read-Only mode
|
|
||||||
if config.is_enter_edit_mode_before(key.code, key.modifiers) {
|
|
||||||
*edit_mode_cooldown = true;
|
|
||||||
*command_message = "Entering Edit mode".to_string();
|
|
||||||
return Ok((false, command_message.clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.is_enter_edit_mode_after(key.code, key.modifiers) {
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
if !current_input.is_empty() && form_state.current_cursor_pos < current_input.len() {
|
|
||||||
form_state.current_cursor_pos += 1;
|
|
||||||
*ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
}
|
|
||||||
*edit_mode_cooldown = true;
|
|
||||||
*command_message = "Entering Edit mode (after cursor)".to_string();
|
|
||||||
return Ok((false, command_message.clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle Read-Only mode keybindings
|
|
||||||
if key.modifiers.is_empty() {
|
|
||||||
key_sequence_tracker.add_key(key.code);
|
|
||||||
let sequence = key_sequence_tracker.get_sequence();
|
|
||||||
|
|
||||||
// Try to match the current sequence against Read-Only mode bindings
|
|
||||||
if let Some(action) = config.matches_key_sequence_generalized(&sequence) {
|
|
||||||
let result = if (action == "previous_entry" || action == "next_entry" ||
|
|
||||||
action == "move_up" || action == "move_down") && app_state.ui.show_form {
|
|
||||||
crate::tui::functions::form::handle_action(
|
|
||||||
action,
|
|
||||||
form_state,
|
|
||||||
grpc_client,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
ideal_cursor_column,
|
|
||||||
).await?
|
|
||||||
} else if (action == "move_up" || action == "move_down") && app_state.ui.show_login {
|
|
||||||
crate::tui::functions::login::handle_action(
|
|
||||||
action,
|
|
||||||
auth_state,
|
|
||||||
ideal_cursor_column,
|
|
||||||
).await?
|
|
||||||
} else {
|
|
||||||
execute_action(
|
|
||||||
action,
|
|
||||||
form_state,
|
|
||||||
ideal_cursor_column,
|
|
||||||
key_sequence_tracker,
|
|
||||||
command_message,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
grpc_client,
|
|
||||||
).await?
|
|
||||||
};
|
|
||||||
key_sequence_tracker.reset();
|
|
||||||
return Ok((false, result));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if this might be a prefix of a longer sequence
|
|
||||||
if config.is_key_sequence_prefix(&sequence) {
|
|
||||||
return Ok((false, command_message.clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since it's not part of a multi-key sequence, check for a direct action
|
|
||||||
if sequence.len() == 1 && !config.is_key_sequence_prefix(&sequence) {
|
|
||||||
if let Some(action) = config.get_read_only_action_for_key(key.code, key.modifiers) {
|
|
||||||
let result = if action == "previous_entry" && app_state.ui.show_form {
|
|
||||||
crate::tui::functions::form::handle_action(
|
|
||||||
action,
|
|
||||||
form_state,
|
|
||||||
grpc_client,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
ideal_cursor_column,
|
|
||||||
).await?
|
|
||||||
} else {
|
|
||||||
execute_action(
|
|
||||||
action,
|
|
||||||
form_state,
|
|
||||||
ideal_cursor_column,
|
|
||||||
key_sequence_tracker,
|
|
||||||
command_message,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
grpc_client,
|
|
||||||
).await?
|
|
||||||
};
|
|
||||||
key_sequence_tracker.reset();
|
|
||||||
return Ok((false, result));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If modifiers are pressed, check for direct key bindings
|
|
||||||
key_sequence_tracker.reset();
|
|
||||||
|
|
||||||
if let Some(action) = config.get_read_only_action_for_key(key.code, key.modifiers) {
|
|
||||||
let result = if action == "previous_entry" && app_state.ui.show_form {
|
|
||||||
crate::tui::functions::form::handle_action(
|
|
||||||
action,
|
|
||||||
form_state,
|
|
||||||
grpc_client,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
ideal_cursor_column,
|
|
||||||
).await?
|
|
||||||
} else {
|
|
||||||
execute_action(
|
|
||||||
action,
|
|
||||||
form_state,
|
|
||||||
ideal_cursor_column,
|
|
||||||
key_sequence_tracker,
|
|
||||||
command_message,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
grpc_client,
|
|
||||||
).await?
|
|
||||||
};
|
|
||||||
return Ok((false, result));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show a helpful message when no binding was found
|
|
||||||
if !*edit_mode_cooldown {
|
|
||||||
let default_key = "i".to_string();
|
|
||||||
let edit_key = config.keybindings.read_only.get("enter_edit_mode_before")
|
|
||||||
.and_then(|keys| keys.first())
|
|
||||||
.unwrap_or(&default_key);
|
|
||||||
*command_message = format!("Read-only mode - press {} to edit", edit_key);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok((false, command_message.clone()))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn execute_action(
|
|
||||||
action: &str,
|
|
||||||
form_state: &mut FormState,
|
|
||||||
ideal_cursor_column: &mut usize,
|
|
||||||
key_sequence_tracker: &mut KeySequenceTracker,
|
|
||||||
command_message: &mut String,
|
|
||||||
current_position: &mut u64,
|
|
||||||
total_count: u64,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
match action {
|
|
||||||
"previous_entry" | "next_entry" => {
|
|
||||||
// This will only be called when no component is active
|
|
||||||
key_sequence_tracker.reset();
|
|
||||||
Ok(format!("Navigation prev/next only available in form mode"))
|
|
||||||
}
|
|
||||||
"move_up" | "move_down" => {
|
|
||||||
// This will only be called when no component is active
|
|
||||||
key_sequence_tracker.reset();
|
|
||||||
Ok(format!("Navigation up/down only available in form mode"))
|
|
||||||
}
|
|
||||||
"exit_edit_mode" => {
|
|
||||||
key_sequence_tracker.reset();
|
|
||||||
command_message.clear();
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_left" => {
|
|
||||||
let current_pos = form_state.current_cursor_pos;
|
|
||||||
form_state.current_cursor_pos = current_pos.saturating_sub(1);
|
|
||||||
*ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_right" => {
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
let current_pos = form_state.current_cursor_pos;
|
|
||||||
if !current_input.is_empty() && current_pos < current_input.len() - 1 {
|
|
||||||
form_state.current_cursor_pos += 1;
|
|
||||||
*ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_word_next" => {
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
if !current_input.is_empty() {
|
|
||||||
let new_pos = find_next_word_start(current_input, form_state.current_cursor_pos);
|
|
||||||
form_state.current_cursor_pos = new_pos.min(current_input.len().saturating_sub(1));
|
|
||||||
*ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_word_end" => {
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
if !current_input.is_empty() {
|
|
||||||
let new_pos = find_word_end(current_input, form_state.current_cursor_pos);
|
|
||||||
form_state.current_cursor_pos = new_pos.min(current_input.len().saturating_sub(1));
|
|
||||||
*ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_word_prev" => {
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
if !current_input.is_empty() {
|
|
||||||
let new_pos = find_prev_word_start(current_input, form_state.current_cursor_pos);
|
|
||||||
form_state.current_cursor_pos = new_pos;
|
|
||||||
*ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_word_end_prev" => {
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
if !current_input.is_empty() {
|
|
||||||
let new_pos = find_prev_word_end(current_input, form_state.current_cursor_pos);
|
|
||||||
form_state.current_cursor_pos = new_pos;
|
|
||||||
*ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
}
|
|
||||||
Ok("Moved to previous word end".to_string())
|
|
||||||
}
|
|
||||||
"move_line_start" => {
|
|
||||||
form_state.current_cursor_pos = 0;
|
|
||||||
*ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_line_end" => {
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
if !current_input.is_empty() {
|
|
||||||
form_state.current_cursor_pos = current_input.len() - 1;
|
|
||||||
*ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
}
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_first_line" => {
|
|
||||||
// Change field first
|
|
||||||
form_state.current_field = 0;
|
|
||||||
|
|
||||||
// Get current input AFTER changing field
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
let max_cursor_pos = if !current_input.is_empty() {
|
|
||||||
current_input.len() - 1
|
|
||||||
} else {
|
|
||||||
current_input.len()
|
|
||||||
};
|
|
||||||
form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
|
|
||||||
Ok("Moved to first line".to_string())
|
|
||||||
}
|
|
||||||
"move_last_line" => {
|
|
||||||
// Change field first
|
|
||||||
form_state.current_field = form_state.fields.len() - 1;
|
|
||||||
|
|
||||||
// Get current input AFTER changing field
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
let max_cursor_pos = if !current_input.is_empty() {
|
|
||||||
current_input.len() - 1
|
|
||||||
} else {
|
|
||||||
current_input.len()
|
|
||||||
};
|
|
||||||
form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
|
|
||||||
Ok("Moved to last line".to_string())
|
|
||||||
}
|
|
||||||
_ => Ok(format!("Unknown action: {}", action)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_char_type(c: char) -> CharType {
|
|
||||||
if c.is_whitespace() {
|
|
||||||
CharType::Whitespace
|
|
||||||
} else if c.is_alphanumeric() {
|
|
||||||
CharType::Alphanumeric
|
|
||||||
} else {
|
|
||||||
CharType::Punctuation
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_next_word_start(text: &str, current_pos: usize) -> usize {
|
|
||||||
let chars: Vec<char> = text.chars().collect();
|
|
||||||
if chars.is_empty() || current_pos >= chars.len() {
|
|
||||||
return current_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pos = current_pos;
|
|
||||||
let initial_type = get_char_type(chars[pos]);
|
|
||||||
while pos < chars.len() && get_char_type(chars[pos]) == initial_type {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while pos < chars.len() && get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_word_end(text: &str, current_pos: usize) -> usize {
|
|
||||||
let chars: Vec<char> = text.chars().collect();
|
|
||||||
if chars.is_empty() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if current_pos >= chars.len() - 1 {
|
|
||||||
return chars.len() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pos = current_pos;
|
|
||||||
|
|
||||||
if get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
while pos < chars.len() && get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let current_type = get_char_type(chars[pos]);
|
|
||||||
if pos + 1 < chars.len() && get_char_type(chars[pos + 1]) != current_type {
|
|
||||||
pos += 1;
|
|
||||||
while pos < chars.len() && get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if pos >= chars.len() {
|
|
||||||
return chars.len() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let word_type = get_char_type(chars[pos]);
|
|
||||||
while pos + 1 < chars.len() && get_char_type(chars[pos + 1]) == word_type {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_prev_word_start(text: &str, current_pos: usize) -> usize {
|
|
||||||
let chars: Vec<char> = text.chars().collect();
|
|
||||||
if chars.is_empty() || current_pos == 0 {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pos = current_pos.saturating_sub(1);
|
|
||||||
|
|
||||||
while pos > 0 && get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if get_char_type(chars[pos]) != CharType::Whitespace {
|
|
||||||
let word_type = get_char_type(chars[pos]);
|
|
||||||
while pos > 0 && get_char_type(chars[pos - 1]) == word_type {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_prev_word_end(text: &str, current_pos: usize) -> usize {
|
|
||||||
let chars: Vec<char> = text.chars().collect();
|
|
||||||
if chars.is_empty() || current_pos <= 1 {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pos = current_pos.saturating_sub(1);
|
|
||||||
|
|
||||||
while pos > 0 && get_char_type(chars[pos]) == CharType::Whitespace {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if pos > 0 && get_char_type(chars[pos]) != CharType::Whitespace {
|
|
||||||
let word_type = get_char_type(chars[pos]);
|
|
||||||
|
|
||||||
while pos > 0 && get_char_type(chars[pos - 1]) == word_type {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while pos > 0 && get_char_type(chars[pos - 1]) == CharType::Whitespace {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if pos > 0 {
|
|
||||||
pos -= 1;
|
|
||||||
let prev_word_type = get_char_type(chars[pos]);
|
|
||||||
while pos > 0 && get_char_type(chars[pos - 1]) == prev_word_type {
|
|
||||||
pos -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while pos < chars.len() - 1 &&
|
|
||||||
get_char_type(chars[pos + 1]) == prev_word_type {
|
|
||||||
pos += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pos
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
// src/client/modes/common.rs
|
|
||||||
pub mod command_mode;
|
|
||||||
pub mod highlight;
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
// src/modes/handlers/command_mode.rs
|
|
||||||
|
|
||||||
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
|
||||||
use crate::config::binds::config::Config;
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
use crate::tui::functions::common::commands::CommandHandler;
|
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
|
||||||
use crate::tui::functions::common::form::{save, revert};
|
|
||||||
|
|
||||||
pub async fn handle_command_event(
|
|
||||||
key: KeyEvent,
|
|
||||||
config: &Config,
|
|
||||||
form_state: &mut FormState,
|
|
||||||
command_input: &mut String,
|
|
||||||
command_message: &mut String,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
command_handler: &mut CommandHandler,
|
|
||||||
terminal: &mut TerminalCore,
|
|
||||||
current_position: &mut u64,
|
|
||||||
total_count: u64,
|
|
||||||
) -> Result<(bool, String, bool), Box<dyn std::error::Error>> {
|
|
||||||
|
|
||||||
// Return value: (should_exit, message, should_exit_command_mode)
|
|
||||||
|
|
||||||
// Exit command mode (via configurable keybinding)
|
|
||||||
if config.is_exit_command_mode(key.code, key.modifiers) {
|
|
||||||
command_input.clear();
|
|
||||||
*command_message = "".to_string();
|
|
||||||
return Ok((false, "".to_string(), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute command (via configurable keybinding, defaults to Enter)
|
|
||||||
if config.is_command_execute(key.code, key.modifiers) {
|
|
||||||
return process_command(
|
|
||||||
config,
|
|
||||||
form_state,
|
|
||||||
command_input,
|
|
||||||
command_message,
|
|
||||||
grpc_client,
|
|
||||||
command_handler,
|
|
||||||
terminal,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Backspace (via configurable keybinding, defaults to Backspace)
|
|
||||||
if config.is_command_backspace(key.code, key.modifiers) {
|
|
||||||
command_input.pop();
|
|
||||||
return Ok((false, "".to_string(), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regular character input - accept any character in command mode
|
|
||||||
if let KeyCode::Char(c) = key.code {
|
|
||||||
// Accept regular or shifted characters (e.g., 'a' or 'A')
|
|
||||||
if key.modifiers.is_empty() || key.modifiers == KeyModifiers::SHIFT {
|
|
||||||
command_input.push(c);
|
|
||||||
return Ok((false, "".to_string(), false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore all other keys
|
|
||||||
Ok((false, "".to_string(), false))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn process_command(
|
|
||||||
config: &Config,
|
|
||||||
form_state: &mut FormState,
|
|
||||||
command_input: &mut String,
|
|
||||||
command_message: &mut String,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
command_handler: &mut CommandHandler,
|
|
||||||
terminal: &mut TerminalCore,
|
|
||||||
current_position: &mut u64,
|
|
||||||
total_count: u64,
|
|
||||||
) -> Result<(bool, String, bool), Box<dyn std::error::Error>> {
|
|
||||||
// Clone the trimmed command to avoid borrow issues
|
|
||||||
let command = command_input.trim().to_string();
|
|
||||||
if command.is_empty() {
|
|
||||||
*command_message = "Empty command".to_string();
|
|
||||||
return Ok((false, command_message.clone(), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the action for the command (now checks global and common bindings too)
|
|
||||||
let action = config.get_action_for_command(&command)
|
|
||||||
.unwrap_or("unknown");
|
|
||||||
|
|
||||||
match action {
|
|
||||||
"force_quit" | "save_and_quit" | "quit" => {
|
|
||||||
let (should_exit, message) = command_handler
|
|
||||||
.handle_command(action, terminal)
|
|
||||||
.await?;
|
|
||||||
command_input.clear();
|
|
||||||
Ok((should_exit, message, true))
|
|
||||||
},
|
|
||||||
"save" => {
|
|
||||||
let message = save(
|
|
||||||
form_state,
|
|
||||||
grpc_client,
|
|
||||||
&mut command_handler.is_saved,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await?;
|
|
||||||
command_input.clear();
|
|
||||||
return Ok((false, message, true));
|
|
||||||
},
|
|
||||||
"revert" => {
|
|
||||||
let message = revert(
|
|
||||||
form_state,
|
|
||||||
grpc_client,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await?;
|
|
||||||
command_input.clear();
|
|
||||||
return Ok((false, message, true));
|
|
||||||
},
|
|
||||||
"unknown" => {
|
|
||||||
let message = format!("Unknown command: {}", command);
|
|
||||||
command_input.clear();
|
|
||||||
return Ok((false, message, true));
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
let message = format!("Unhandled action: {}", action);
|
|
||||||
command_input.clear();
|
|
||||||
return Ok((false, message, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// src/client/modes/general.rs
|
|
||||||
pub mod navigation;
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
// src/modes/general/navigation.rs
|
|
||||||
|
|
||||||
use crossterm::event::KeyEvent;
|
|
||||||
use crate::config::binds::config::Config;
|
|
||||||
use crate::state::state::AppState;
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
use crate::tui::functions::{intro, admin};
|
|
||||||
|
|
||||||
pub async fn handle_navigation_event(
|
|
||||||
key: KeyEvent,
|
|
||||||
config: &Config,
|
|
||||||
form_state: &mut FormState,
|
|
||||||
app_state: &mut AppState,
|
|
||||||
command_mode: &mut bool,
|
|
||||||
command_input: &mut String,
|
|
||||||
command_message: &mut String,
|
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
|
||||||
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
|
|
||||||
match action {
|
|
||||||
"move_up" => {
|
|
||||||
move_up(app_state);
|
|
||||||
return Ok((false, String::new()));
|
|
||||||
}
|
|
||||||
"move_down" => {
|
|
||||||
move_down(app_state);
|
|
||||||
return Ok((false, String::new()));
|
|
||||||
}
|
|
||||||
"next_option" => {
|
|
||||||
next_option(app_state); // Intro has 2 options
|
|
||||||
return Ok((false, String::new()));
|
|
||||||
}
|
|
||||||
"previous_option" => {
|
|
||||||
previous_option(app_state);
|
|
||||||
return Ok((false, String::new()));
|
|
||||||
}
|
|
||||||
"select" => {
|
|
||||||
select(app_state);
|
|
||||||
return Ok((false, "Selected".to_string()));
|
|
||||||
}
|
|
||||||
"toggle_sidebar" => {
|
|
||||||
toggle_sidebar(app_state);
|
|
||||||
return Ok((false, format!("Sidebar {}",
|
|
||||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
"next_field" => {
|
|
||||||
next_field(form_state);
|
|
||||||
return Ok((false, String::new()));
|
|
||||||
}
|
|
||||||
"prev_field" => {
|
|
||||||
prev_field(form_state);
|
|
||||||
return Ok((false, String::new()));
|
|
||||||
}
|
|
||||||
"enter_command_mode" => {
|
|
||||||
handle_enter_command_mode(command_mode, command_input, command_message);
|
|
||||||
return Ok((false, String::new()));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok((false, String::new()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn move_up(app_state: &mut AppState) {
|
|
||||||
if app_state.ui.show_intro {
|
|
||||||
app_state.ui.intro_state.previous_option();
|
|
||||||
} else if app_state.ui.show_admin {
|
|
||||||
// Assuming profile_tree.profiles is the list we're navigating
|
|
||||||
let profile_count = app_state.profile_tree.profiles.len();
|
|
||||||
if profile_count == 0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use general state for tracking selection in admin panel
|
|
||||||
if app_state.general.selected_item == 0 {
|
|
||||||
app_state.general.selected_item = profile_count - 1;
|
|
||||||
} else {
|
|
||||||
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn move_down(app_state: &mut AppState) {
|
|
||||||
if app_state.ui.show_intro {
|
|
||||||
app_state.ui.intro_state.next_option();
|
|
||||||
} else if app_state.ui.show_admin {
|
|
||||||
// Assuming profile_tree.profiles is the list we're navigating
|
|
||||||
let profile_count = app_state.profile_tree.profiles.len();
|
|
||||||
if profile_count == 0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
app_state.general.selected_item = (app_state.general.selected_item + 1) % profile_count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_option(app_state: &mut AppState) { // Remove option_count parameter
|
|
||||||
if app_state.ui.show_intro {
|
|
||||||
app_state.ui.intro_state.next_option();
|
|
||||||
} else {
|
|
||||||
// Get option count from state instead of parameter
|
|
||||||
let option_count = app_state.profile_tree.profiles.len();
|
|
||||||
app_state.general.current_option = (app_state.general.current_option + 1) % option_count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn previous_option(app_state: &mut AppState) {
|
|
||||||
if app_state.ui.show_intro {
|
|
||||||
app_state.ui.intro_state.previous_option();
|
|
||||||
} else {
|
|
||||||
let option_count = app_state.profile_tree.profiles.len();
|
|
||||||
app_state.general.current_option = if app_state.general.current_option == 0 {
|
|
||||||
option_count.saturating_sub(1) // Wrap to last option
|
|
||||||
} else {
|
|
||||||
app_state.general.current_option - 1
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn select(app_state: &mut AppState) {
|
|
||||||
if app_state.ui.show_intro {
|
|
||||||
intro::handle_intro_selection(app_state);
|
|
||||||
} else if app_state.ui.show_admin {
|
|
||||||
admin::handle_admin_selection(app_state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn toggle_sidebar(app_state: &mut AppState) {
|
|
||||||
app_state.ui.show_sidebar = !app_state.ui.show_sidebar;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_field(form_state: &mut FormState) {
|
|
||||||
if !form_state.fields.is_empty() {
|
|
||||||
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prev_field(form_state: &mut FormState) {
|
|
||||||
if !form_state.fields.is_empty() {
|
|
||||||
if form_state.current_field == 0 {
|
|
||||||
form_state.current_field = form_state.fields.len() - 1;
|
|
||||||
} else {
|
|
||||||
form_state.current_field -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handle_enter_command_mode(
|
|
||||||
command_mode: &mut bool,
|
|
||||||
command_input: &mut String,
|
|
||||||
command_message: &mut String
|
|
||||||
) {
|
|
||||||
*command_mode = true;
|
|
||||||
command_input.clear();
|
|
||||||
command_message.clear();
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
// src/client/modes/handlers.rs
|
|
||||||
pub mod event;
|
|
||||||
pub mod mode_manager;
|
|
||||||
@@ -1,272 +0,0 @@
|
|||||||
// src/modes/handlers/event.rs
|
|
||||||
use crossterm::event::Event;
|
|
||||||
use crossterm::cursor::SetCursorStyle;
|
|
||||||
use crate::tui::terminal::{
|
|
||||||
core::TerminalCore,
|
|
||||||
};
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
|
||||||
use crate::services::auth::AuthClient;
|
|
||||||
use crate::tui::functions::common::commands::CommandHandler;
|
|
||||||
use crate::config::binds::config::Config;
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
use crate::state::pages::auth::AuthState;
|
|
||||||
use crate::ui::handlers::rat_state::UiStateHandler;
|
|
||||||
use crate::modes::{
|
|
||||||
common::{command_mode},
|
|
||||||
canvas::{edit, read_only, common},
|
|
||||||
general::navigation,
|
|
||||||
};
|
|
||||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
|
||||||
use crate::modes::handlers::mode_manager::{ModeManager, AppMode};
|
|
||||||
|
|
||||||
pub struct EventHandler {
|
|
||||||
pub command_mode: bool,
|
|
||||||
pub command_input: String,
|
|
||||||
pub command_message: String,
|
|
||||||
pub is_edit_mode: bool,
|
|
||||||
pub edit_mode_cooldown: bool,
|
|
||||||
pub ideal_cursor_column: usize,
|
|
||||||
pub key_sequence_tracker: KeySequenceTracker,
|
|
||||||
pub auth_state: AuthState,
|
|
||||||
pub auth_client: AuthClient,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventHandler {
|
|
||||||
pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
|
||||||
Ok(EventHandler {
|
|
||||||
command_mode: false,
|
|
||||||
command_input: String::new(),
|
|
||||||
command_message: String::new(),
|
|
||||||
is_edit_mode: false,
|
|
||||||
edit_mode_cooldown: false,
|
|
||||||
ideal_cursor_column: 0,
|
|
||||||
key_sequence_tracker: KeySequenceTracker::new(800),
|
|
||||||
auth_state: AuthState::new(),
|
|
||||||
auth_client: AuthClient::new().await?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn handle_event(
|
|
||||||
&mut self,
|
|
||||||
event: Event,
|
|
||||||
config: &Config,
|
|
||||||
terminal: &mut TerminalCore,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
command_handler: &mut CommandHandler,
|
|
||||||
form_state: &mut FormState,
|
|
||||||
app_state: &mut crate::state::state::AppState,
|
|
||||||
total_count: u64,
|
|
||||||
current_position: &mut u64,
|
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
|
||||||
// Determine current mode based on app state and event handler state
|
|
||||||
let current_mode = ModeManager::derive_mode(app_state, self);
|
|
||||||
app_state.update_mode(current_mode);
|
|
||||||
|
|
||||||
if let Event::Key(key) = event {
|
|
||||||
let key_code = key.code;
|
|
||||||
let modifiers = key.modifiers;
|
|
||||||
|
|
||||||
// Handle common actions across all modes
|
|
||||||
if UiStateHandler::toggle_sidebar(&mut app_state.ui, config, key_code, modifiers) {
|
|
||||||
return Ok((false, format!("Sidebar {}",
|
|
||||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mode-specific handling
|
|
||||||
match current_mode {
|
|
||||||
AppMode::General => {
|
|
||||||
return navigation::handle_navigation_event(
|
|
||||||
key,
|
|
||||||
config,
|
|
||||||
form_state,
|
|
||||||
app_state,
|
|
||||||
&mut self.command_mode,
|
|
||||||
&mut self.command_input,
|
|
||||||
&mut self.command_message,
|
|
||||||
).await;
|
|
||||||
},
|
|
||||||
|
|
||||||
AppMode::ReadOnly => {
|
|
||||||
// Check for mode transitions first
|
|
||||||
if config.is_enter_edit_mode_before(key_code, modifiers) &&
|
|
||||||
ModeManager::can_enter_edit_mode(current_mode) {
|
|
||||||
self.is_edit_mode = true;
|
|
||||||
self.edit_mode_cooldown = true;
|
|
||||||
self.command_message = "Edit mode".to_string();
|
|
||||||
terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
|
|
||||||
return Ok((false, self.command_message.clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.is_enter_edit_mode_after(key_code, modifiers) &&
|
|
||||||
ModeManager::can_enter_edit_mode(current_mode) {
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
if !current_input.is_empty() && form_state.current_cursor_pos < current_input.len() {
|
|
||||||
form_state.current_cursor_pos += 1;
|
|
||||||
self.ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
}
|
|
||||||
self.is_edit_mode = true;
|
|
||||||
self.edit_mode_cooldown = true;
|
|
||||||
self.command_message = "Edit mode (after cursor)".to_string();
|
|
||||||
terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
|
|
||||||
return Ok((false, self.command_message.clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for entering command mode
|
|
||||||
if let Some(action) = config.get_read_only_action_for_key(key_code, modifiers) {
|
|
||||||
if action == "enter_command_mode" && ModeManager::can_enter_command_mode(current_mode) {
|
|
||||||
self.command_mode = true;
|
|
||||||
self.command_input.clear();
|
|
||||||
self.command_message.clear();
|
|
||||||
return Ok((false, String::new()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for core application actions (save, quit, etc.)
|
|
||||||
// ONLY handle a limited subset of core actions here
|
|
||||||
if let Some(action) = config.get_action_for_key_in_mode(
|
|
||||||
&config.keybindings.common,
|
|
||||||
key_code,
|
|
||||||
modifiers
|
|
||||||
) {
|
|
||||||
match action {
|
|
||||||
"save" | "force_quit" | "save_and_quit" | "revert" => {
|
|
||||||
return common::handle_core_action(
|
|
||||||
action,
|
|
||||||
form_state,
|
|
||||||
&mut self.auth_state,
|
|
||||||
grpc_client,
|
|
||||||
&mut self.auth_client,
|
|
||||||
terminal,
|
|
||||||
app_state,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await;
|
|
||||||
},
|
|
||||||
_ => {} // For other actions, let the mode-specific handler take care of it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let read_only mode handle its own actions (including navigation from common bindings)
|
|
||||||
return read_only::handle_read_only_event(
|
|
||||||
&app_state,
|
|
||||||
key,
|
|
||||||
config,
|
|
||||||
form_state,
|
|
||||||
&mut self.auth_state,
|
|
||||||
&mut self.key_sequence_tracker,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
grpc_client,
|
|
||||||
&mut self.command_message,
|
|
||||||
&mut self.edit_mode_cooldown,
|
|
||||||
&mut self.ideal_cursor_column,
|
|
||||||
).await;
|
|
||||||
},
|
|
||||||
|
|
||||||
AppMode::Edit => {
|
|
||||||
// Check for exiting edit mode
|
|
||||||
if config.is_exit_edit_mode(key_code, modifiers) {
|
|
||||||
if form_state.has_unsaved_changes {
|
|
||||||
self.command_message = "Unsaved changes! Use :w to save or :q! to discard".to_string();
|
|
||||||
return Ok((false, self.command_message.clone()));
|
|
||||||
}
|
|
||||||
self.is_edit_mode = false;
|
|
||||||
self.edit_mode_cooldown = true;
|
|
||||||
self.command_message = "Read-only mode".to_string();
|
|
||||||
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
|
|
||||||
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
if !current_input.is_empty() && form_state.current_cursor_pos >= current_input.len() {
|
|
||||||
form_state.current_cursor_pos = current_input.len() - 1;
|
|
||||||
self.ideal_cursor_column = form_state.current_cursor_pos;
|
|
||||||
}
|
|
||||||
return Ok((false, self.command_message.clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for core application actions (save, quit, etc.)
|
|
||||||
// ONLY handle a limited subset of core actions here
|
|
||||||
if let Some(action) = config.get_action_for_key_in_mode(
|
|
||||||
&config.keybindings.common,
|
|
||||||
key_code,
|
|
||||||
modifiers
|
|
||||||
) {
|
|
||||||
match action {
|
|
||||||
"save" | "force_quit" | "save_and_quit" | "revert" => {
|
|
||||||
return common::handle_core_action(
|
|
||||||
action,
|
|
||||||
form_state,
|
|
||||||
&mut self.auth_state,
|
|
||||||
grpc_client,
|
|
||||||
&mut self.auth_client,
|
|
||||||
terminal,
|
|
||||||
app_state,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await;
|
|
||||||
},
|
|
||||||
_ => {} // For other actions, let the mode-specific handler take care of it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let edit mode handle its own actions (including navigation from common bindings)
|
|
||||||
let result = if app_state.ui.show_login {
|
|
||||||
edit::handle_edit_event_internal(
|
|
||||||
key,
|
|
||||||
config,
|
|
||||||
&mut self.auth_state, // Use auth_state instead of form_state
|
|
||||||
&mut self.ideal_cursor_column,
|
|
||||||
&mut self.command_message,
|
|
||||||
&mut app_state.ui.is_saved,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
grpc_client,
|
|
||||||
).await?
|
|
||||||
} else {
|
|
||||||
edit::handle_edit_event_internal(
|
|
||||||
key,
|
|
||||||
config,
|
|
||||||
form_state,
|
|
||||||
&mut self.ideal_cursor_column,
|
|
||||||
&mut self.command_message,
|
|
||||||
&mut app_state.ui.is_saved,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
grpc_client,
|
|
||||||
).await?
|
|
||||||
};
|
|
||||||
|
|
||||||
self.key_sequence_tracker.reset();
|
|
||||||
return Ok((false, result));
|
|
||||||
},
|
|
||||||
|
|
||||||
AppMode::Command => {
|
|
||||||
let (should_exit, message, exit_command_mode) = command_mode::handle_command_event(
|
|
||||||
key,
|
|
||||||
config,
|
|
||||||
form_state,
|
|
||||||
&mut self.command_input,
|
|
||||||
&mut self.command_message,
|
|
||||||
grpc_client,
|
|
||||||
command_handler,
|
|
||||||
terminal,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
).await?;
|
|
||||||
|
|
||||||
if exit_command_mode {
|
|
||||||
self.command_mode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok((should_exit, message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Non-key events or if no specific handler was matched
|
|
||||||
self.edit_mode_cooldown = false;
|
|
||||||
Ok((false, self.command_message.clone()))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
// src/modes/handlers/mode_manager.rs
|
|
||||||
use crate::state::state::AppState;
|
|
||||||
use crate::modes::handlers::event::EventHandler;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub enum AppMode {
|
|
||||||
General, // For intro and admin screens
|
|
||||||
ReadOnly, // Canvas read-only mode
|
|
||||||
Edit, // Canvas edit mode
|
|
||||||
Command, // Command mode overlay
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ModeManager;
|
|
||||||
|
|
||||||
impl ModeManager {
|
|
||||||
// Determine current mode based on app state
|
|
||||||
pub fn derive_mode(app_state: &AppState, event_handler: &EventHandler) -> AppMode {
|
|
||||||
if event_handler.command_mode {
|
|
||||||
return AppMode::Command;
|
|
||||||
}
|
|
||||||
|
|
||||||
if app_state.ui.show_login { // NEW: Check auth visibility
|
|
||||||
if event_handler.is_edit_mode {
|
|
||||||
AppMode::Edit
|
|
||||||
} else {
|
|
||||||
AppMode::ReadOnly
|
|
||||||
}
|
|
||||||
} else if app_state.ui.show_form {
|
|
||||||
if event_handler.is_edit_mode {
|
|
||||||
AppMode::Edit
|
|
||||||
} else {
|
|
||||||
AppMode::ReadOnly
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
AppMode::General
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mode transition rules
|
|
||||||
pub fn can_enter_command_mode(current_mode: AppMode) -> bool {
|
|
||||||
!matches!(current_mode, AppMode::Edit) // Can't enter from Edit mode
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn can_enter_edit_mode(current_mode: AppMode) -> bool {
|
|
||||||
matches!(current_mode, AppMode::ReadOnly) // Only from ReadOnly
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn can_enter_read_only_mode(current_mode: AppMode) -> bool {
|
|
||||||
matches!(current_mode, AppMode::Edit | AppMode::Command)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// src/client/modes/mod.rs
|
|
||||||
pub mod handlers;
|
|
||||||
pub mod canvas;
|
|
||||||
pub mod general;
|
|
||||||
pub mod common;
|
|
||||||
|
|
||||||
pub use handlers::*;
|
|
||||||
pub use canvas::*;
|
|
||||||
pub use general::*;
|
|
||||||
pub use common::*;
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
// src/services/auth.rs
|
|
||||||
use tonic::transport::Channel;
|
|
||||||
use common::proto::multieko2::auth::{
|
|
||||||
auth_service_client::AuthServiceClient,
|
|
||||||
LoginRequest, LoginResponse
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct AuthClient {
|
|
||||||
client: AuthServiceClient<Channel>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AuthClient {
|
|
||||||
pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
|
||||||
let client = AuthServiceClient::connect("http://[::1]:50051").await?;
|
|
||||||
Ok(Self { client })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn login(&mut self, identifier: String, password: String) -> Result<LoginResponse, Box<dyn std::error::Error>> {
|
|
||||||
let request = tonic::Request::new(LoginRequest { identifier, password });
|
|
||||||
let response = self.client.login(request).await?.into_inner();
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
// src/services/grpc_client.rs
|
|
||||||
|
|
||||||
use tonic::transport::Channel;
|
|
||||||
use common::proto::multieko2::adresar::adresar_client::AdresarClient;
|
|
||||||
use common::proto::multieko2::adresar::{AdresarResponse, PostAdresarRequest, PutAdresarRequest};
|
|
||||||
use common::proto::multieko2::common::{CountResponse, PositionRequest, Empty};
|
|
||||||
use common::proto::multieko2::table_structure::table_structure_service_client::TableStructureServiceClient;
|
|
||||||
use common::proto::multieko2::table_structure::TableStructureResponse;
|
|
||||||
use common::proto::multieko2::table_definition::{
|
|
||||||
table_definition_client::TableDefinitionClient,
|
|
||||||
ProfileTreeResponse
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct GrpcClient {
|
|
||||||
adresar_client: AdresarClient<Channel>,
|
|
||||||
table_structure_client: TableStructureServiceClient<Channel>,
|
|
||||||
table_definition_client: TableDefinitionClient<Channel>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GrpcClient {
|
|
||||||
pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
|
||||||
let adresar_client = AdresarClient::connect("http://[::1]:50051").await?;
|
|
||||||
let table_structure_client = TableStructureServiceClient::connect("http://[::1]:50051").await?;
|
|
||||||
let table_definition_client = TableDefinitionClient::connect("http://[::1]:50051").await?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
adresar_client,
|
|
||||||
table_structure_client,
|
|
||||||
table_definition_client,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_adresar_count(&mut self) -> Result<u64, Box<dyn std::error::Error>> {
|
|
||||||
let request = tonic::Request::new(Empty::default());
|
|
||||||
let response: CountResponse = self.adresar_client.get_adresar_count(request).await?.into_inner();
|
|
||||||
Ok(response.count as u64)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_adresar_by_position(&mut self, position: u64) -> Result<AdresarResponse, Box<dyn std::error::Error>> {
|
|
||||||
let request = tonic::Request::new(PositionRequest { position: position as i64 });
|
|
||||||
let response: AdresarResponse = self.adresar_client.get_adresar_by_position(request).await?.into_inner();
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn post_adresar(&mut self, request: PostAdresarRequest) -> Result<tonic::Response<AdresarResponse>, Box<dyn std::error::Error>> {
|
|
||||||
let request = tonic::Request::new(request);
|
|
||||||
let response = self.adresar_client.post_adresar(request).await?;
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn put_adresar(&mut self, request: PutAdresarRequest) -> Result<tonic::Response<AdresarResponse>, Box<dyn std::error::Error>> {
|
|
||||||
let request = tonic::Request::new(request);
|
|
||||||
let response = self.adresar_client.put_adresar(request).await?;
|
|
||||||
Ok(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_table_structure(&mut self) -> Result<TableStructureResponse, Box<dyn std::error::Error>> {
|
|
||||||
let request = tonic::Request::new(Empty::default());
|
|
||||||
let response = self.table_structure_client.get_adresar_table_structure(request).await?;
|
|
||||||
Ok(response.into_inner())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_profile_tree(&mut self) -> Result<ProfileTreeResponse, Box<dyn std::error::Error>> {
|
|
||||||
let request = tonic::Request::new(Empty::default());
|
|
||||||
let response = self.table_definition_client.get_profile_tree(request).await?;
|
|
||||||
Ok(response.into_inner())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
// services/mod.rs
|
|
||||||
|
|
||||||
pub mod grpc_client;
|
|
||||||
pub mod auth;
|
|
||||||
pub mod ui_service;
|
|
||||||
|
|
||||||
pub use grpc_client::*;
|
|
||||||
pub use ui_service::*;
|
|
||||||
pub use auth::*;
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
// src/services/ui_service.rs
|
|
||||||
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
use crate::state::state::AppState;
|
|
||||||
|
|
||||||
pub struct UiService;
|
|
||||||
|
|
||||||
impl UiService {
|
|
||||||
pub async fn initialize_app_state(
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
app_state: &mut AppState,
|
|
||||||
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
|
||||||
// Fetch profile tree
|
|
||||||
let profile_tree = grpc_client.get_profile_tree().await?;
|
|
||||||
app_state.profile_tree = profile_tree;
|
|
||||||
|
|
||||||
// Fetch table structure
|
|
||||||
let table_structure = grpc_client.get_table_structure().await?;
|
|
||||||
|
|
||||||
// Extract the column names from the response
|
|
||||||
let column_names: Vec<String> = table_structure
|
|
||||||
.columns
|
|
||||||
.iter()
|
|
||||||
.map(|col| col.name.clone())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(column_names)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn initialize_adresar_count(
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
app_state: &mut AppState,
|
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let total_count = grpc_client.get_adresar_count().await?;
|
|
||||||
app_state.update_total_count(total_count);
|
|
||||||
app_state.update_current_position(total_count.saturating_add(1)); // Start in new entry mode
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update_adresar_count(
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
app_state: &mut AppState,
|
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let total_count = grpc_client.get_adresar_count().await?;
|
|
||||||
app_state.update_total_count(total_count);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn load_adresar_by_position(
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
app_state: &mut AppState,
|
|
||||||
form_state: &mut FormState,
|
|
||||||
position: u64,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
match grpc_client.get_adresar_by_position(position).await {
|
|
||||||
Ok(response) => {
|
|
||||||
// Set the ID properly
|
|
||||||
form_state.id = response.id;
|
|
||||||
|
|
||||||
// Update form values dynamically
|
|
||||||
form_state.values = vec![
|
|
||||||
response.firma,
|
|
||||||
response.kz,
|
|
||||||
response.drc,
|
|
||||||
response.ulica,
|
|
||||||
response.psc,
|
|
||||||
response.mesto,
|
|
||||||
response.stat,
|
|
||||||
response.banka,
|
|
||||||
response.ucet,
|
|
||||||
response.skladm,
|
|
||||||
response.ico,
|
|
||||||
response.kontakt,
|
|
||||||
response.telefon,
|
|
||||||
response.skladu,
|
|
||||||
response.fax,
|
|
||||||
];
|
|
||||||
|
|
||||||
form_state.has_unsaved_changes = false;
|
|
||||||
Ok(format!("Loaded entry {}", position))
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
Ok(format!("Error loading entry: {}", e))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
// src/state/canvas_state.rs
|
|
||||||
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
|
|
||||||
pub trait CanvasState {
|
|
||||||
fn current_field(&self) -> usize;
|
|
||||||
fn current_cursor_pos(&self) -> usize;
|
|
||||||
fn has_unsaved_changes(&self) -> bool;
|
|
||||||
fn inputs(&self) -> Vec<&String>;
|
|
||||||
fn get_current_input(&self) -> &str;
|
|
||||||
fn get_current_input_mut(&mut self) -> &mut String;
|
|
||||||
fn fields(&self) -> Vec<&str>;
|
|
||||||
|
|
||||||
fn set_current_field(&mut self, index: usize);
|
|
||||||
fn set_current_cursor_pos(&mut self, pos: usize);
|
|
||||||
fn set_has_unsaved_changes(&mut self, changed: bool);
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// src/state/mod.rs
|
|
||||||
pub mod state;
|
|
||||||
pub mod pages;
|
|
||||||
pub mod canvas_state;
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// src/state/pages.rs
|
|
||||||
|
|
||||||
pub mod form;
|
|
||||||
pub mod auth;
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
// src/state/pages/auth.rs
|
|
||||||
use crate::state::canvas_state::CanvasState;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct AuthState {
|
|
||||||
pub return_selected: bool,
|
|
||||||
pub username: String,
|
|
||||||
pub password: String,
|
|
||||||
pub error_message: Option<String>,
|
|
||||||
pub current_field: usize,
|
|
||||||
pub current_cursor_pos: usize,
|
|
||||||
pub auth_token: Option<String>,
|
|
||||||
pub user_id: Option<String>,
|
|
||||||
pub role: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AuthState {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
return_selected: false,
|
|
||||||
username: String::new(),
|
|
||||||
password: String::new(),
|
|
||||||
error_message: None,
|
|
||||||
current_field: 0,
|
|
||||||
current_cursor_pos: 0,
|
|
||||||
auth_token: None,
|
|
||||||
user_id: None,
|
|
||||||
role: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CanvasState for AuthState {
|
|
||||||
fn current_field(&self) -> usize {
|
|
||||||
self.current_field
|
|
||||||
}
|
|
||||||
|
|
||||||
fn current_cursor_pos(&self) -> usize {
|
|
||||||
self.current_cursor_pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn has_unsaved_changes(&self) -> bool {
|
|
||||||
// Auth form doesn't need unsaved changes tracking
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn inputs(&self) -> Vec<&String> {
|
|
||||||
vec![&self.username, &self.password]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_current_input(&self) -> &str {
|
|
||||||
match self.current_field {
|
|
||||||
0 => &self.username,
|
|
||||||
1 => &self.password,
|
|
||||||
_ => "", // Return empty string for invalid index instead of panicking
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_current_input_mut(&mut self) -> &mut String {
|
|
||||||
match self.current_field {
|
|
||||||
0 => &mut self.username,
|
|
||||||
1 => &mut self.password,
|
|
||||||
_ => panic!("Invalid current_field index in AuthState"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fields(&self) -> Vec<&str> {
|
|
||||||
vec!["Username/Email", "Password"]
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Implement the setter methods ---
|
|
||||||
fn set_current_field(&mut self, index: usize) {
|
|
||||||
// AuthState only has 2 fields (0 and 1)
|
|
||||||
if index < 2 {
|
|
||||||
self.current_field = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_current_cursor_pos(&mut self, pos: usize) {
|
|
||||||
// Optional: Add validation based on current input length if needed
|
|
||||||
self.current_cursor_pos = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_has_unsaved_changes(&mut self, _changed: bool) {
|
|
||||||
// Auth form doesn't track unsaved changes, so do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
// src/state/pages/form.rs
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
use ratatui::layout::Rect;
|
|
||||||
use ratatui::Frame;
|
|
||||||
use crate::state::canvas_state::CanvasState;
|
|
||||||
|
|
||||||
pub struct FormState {
|
|
||||||
pub id: i64,
|
|
||||||
pub fields: Vec<String>, // Use Vec<String> for dynamic field names
|
|
||||||
pub values: Vec<String>, // Store field values dynamically
|
|
||||||
pub current_field: usize,
|
|
||||||
pub has_unsaved_changes: bool,
|
|
||||||
pub current_cursor_pos: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FormState {
|
|
||||||
/// Create a new FormState with dynamic fields.
|
|
||||||
pub fn new(fields: Vec<String>) -> Self {
|
|
||||||
let values = vec![String::new(); fields.len()]; // Initialize values for each field
|
|
||||||
FormState {
|
|
||||||
id: 0,
|
|
||||||
fields,
|
|
||||||
values,
|
|
||||||
current_field: 0,
|
|
||||||
has_unsaved_changes: false,
|
|
||||||
current_cursor_pos: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn render(
|
|
||||||
&self,
|
|
||||||
f: &mut Frame,
|
|
||||||
area: Rect,
|
|
||||||
theme: &Theme,
|
|
||||||
is_edit_mode: bool,
|
|
||||||
total_count: u64,
|
|
||||||
current_position: u64,
|
|
||||||
) {
|
|
||||||
let fields: Vec<&str> = self.fields.iter().map(|s| s.as_str()).collect();
|
|
||||||
let values: Vec<&String> = self.values.iter().collect();
|
|
||||||
|
|
||||||
crate::components::form::form::render_form(
|
|
||||||
f,
|
|
||||||
area,
|
|
||||||
self,
|
|
||||||
&fields,
|
|
||||||
&self.current_field,
|
|
||||||
&values,
|
|
||||||
theme,
|
|
||||||
is_edit_mode,
|
|
||||||
total_count,
|
|
||||||
current_position,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset_to_empty(&mut self) {
|
|
||||||
self.id = 0; // Reset ID to 0 for new entries
|
|
||||||
self.values.iter_mut().for_each(|v| v.clear()); // Clear all values
|
|
||||||
self.has_unsaved_changes = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_current_input(&self) -> &str {
|
|
||||||
self.values
|
|
||||||
.get(self.current_field)
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_current_input_mut(&mut self) -> &mut String {
|
|
||||||
self.values
|
|
||||||
.get_mut(self.current_field)
|
|
||||||
.expect("Invalid current_field index")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_from_response(&mut self, response: common::proto::multieko2::adresar::AdresarResponse) {
|
|
||||||
self.id = response.id;
|
|
||||||
self.values = vec![
|
|
||||||
response.firma, response.kz, response.drc,
|
|
||||||
response.ulica, response.psc, response.mesto,
|
|
||||||
response.stat, response.banka, response.ucet,
|
|
||||||
response.skladm, response.ico, response.kontakt,
|
|
||||||
response.telefon, response.skladu, response.fax,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CanvasState for FormState {
|
|
||||||
fn current_field(&self) -> usize {
|
|
||||||
self.current_field
|
|
||||||
}
|
|
||||||
|
|
||||||
fn current_cursor_pos(&self) -> usize {
|
|
||||||
self.current_cursor_pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn has_unsaved_changes(&self) -> bool {
|
|
||||||
self.has_unsaved_changes
|
|
||||||
}
|
|
||||||
|
|
||||||
fn inputs(&self) -> Vec<&String> {
|
|
||||||
self.values.iter().collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_current_input(&self) -> &str {
|
|
||||||
self.values
|
|
||||||
.get(self.current_field)
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_current_input_mut(&mut self) -> &mut String {
|
|
||||||
self.values
|
|
||||||
.get_mut(self.current_field)
|
|
||||||
.expect("Invalid current_field index")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fields(&self) -> Vec<&str> {
|
|
||||||
self.fields.iter().map(|s| s.as_str()).collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Implement the setter methods ---
|
|
||||||
fn set_current_field(&mut self, index: usize) {
|
|
||||||
if index < self.fields.len() { // Basic bounds check
|
|
||||||
self.current_field = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_current_cursor_pos(&mut self, pos: usize) {
|
|
||||||
// Optional: Add validation based on current input length if needed
|
|
||||||
self.current_cursor_pos = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_has_unsaved_changes(&mut self, changed: bool) {
|
|
||||||
self.has_unsaved_changes = changed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
// src/state/state.rs
|
|
||||||
|
|
||||||
use std::env;
|
|
||||||
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
|
||||||
use crate::components::IntroState;
|
|
||||||
use crate::modes::handlers::mode_manager::AppMode;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct DialogState {
|
|
||||||
pub show_dialog: bool,
|
|
||||||
pub dialog_title: String,
|
|
||||||
pub dialog_message: String,
|
|
||||||
pub dialog_button_active: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct UiState {
|
|
||||||
pub show_sidebar: bool,
|
|
||||||
pub is_saved: bool,
|
|
||||||
pub show_intro: bool,
|
|
||||||
pub show_admin: bool,
|
|
||||||
pub show_form: bool,
|
|
||||||
pub show_login: bool,
|
|
||||||
pub intro_state: IntroState,
|
|
||||||
pub dialog: DialogState, // Add dialog state here
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GeneralState {
|
|
||||||
pub selected_item: usize,
|
|
||||||
pub current_option: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct AppState {
|
|
||||||
// Core editor state
|
|
||||||
pub current_dir: String,
|
|
||||||
pub total_count: u64,
|
|
||||||
pub current_position: u64,
|
|
||||||
pub profile_tree: ProfileTreeResponse,
|
|
||||||
pub selected_profile: Option<String>,
|
|
||||||
pub current_mode: AppMode,
|
|
||||||
|
|
||||||
// UI preferences
|
|
||||||
pub ui: UiState,
|
|
||||||
pub general: GeneralState,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AppState {
|
|
||||||
pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
|
||||||
let current_dir = env::current_dir()?
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string();
|
|
||||||
Ok(AppState {
|
|
||||||
current_dir,
|
|
||||||
total_count: 0,
|
|
||||||
current_position: 0,
|
|
||||||
profile_tree: ProfileTreeResponse::default(),
|
|
||||||
selected_profile: None,
|
|
||||||
current_mode: AppMode::General,
|
|
||||||
ui: UiState::default(),
|
|
||||||
general: GeneralState {
|
|
||||||
selected_item: 0,
|
|
||||||
current_option: 0,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Existing methods remain unchanged
|
|
||||||
pub fn update_total_count(&mut self, total_count: u64) {
|
|
||||||
self.total_count = total_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_current_position(&mut self, current_position: u64) {
|
|
||||||
self.current_position = current_position;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_mode(&mut self, mode: AppMode) {
|
|
||||||
self.current_mode = mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add dialog helper methods
|
|
||||||
pub fn show_dialog(&mut self, title: &str, message: &str) {
|
|
||||||
self.ui.dialog.show_dialog = true;
|
|
||||||
self.ui.dialog.dialog_title = title.to_string();
|
|
||||||
self.ui.dialog.dialog_message = message.to_string();
|
|
||||||
self.ui.dialog.dialog_button_active = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn hide_dialog(&mut self) {
|
|
||||||
self.ui.dialog.show_dialog = false;
|
|
||||||
self.ui.dialog.dialog_title.clear();
|
|
||||||
self.ui.dialog.dialog_message.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_dialog_button_active(&mut self, active: bool) {
|
|
||||||
self.ui.dialog.dialog_button_active = active;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for UiState {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
show_sidebar: true,
|
|
||||||
is_saved: false,
|
|
||||||
show_intro: true,
|
|
||||||
show_admin: false,
|
|
||||||
show_form: false,
|
|
||||||
show_login: false,
|
|
||||||
intro_state: IntroState::new(),
|
|
||||||
dialog: DialogState::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
// src/tui/functions.rs
|
|
||||||
|
|
||||||
pub mod admin;
|
|
||||||
pub mod intro;
|
|
||||||
pub mod login;
|
|
||||||
pub mod form;
|
|
||||||
pub mod common;
|
|
||||||
|
|
||||||
pub use admin::*;
|
|
||||||
pub use intro::*;
|
|
||||||
pub use form::*;
|
|
||||||
pub use common::*;
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
use crate::state::state::AppState;
|
|
||||||
|
|
||||||
pub fn handle_admin_selection(app_state: &mut AppState) {
|
|
||||||
let profiles = &app_state.profile_tree.profiles;
|
|
||||||
if !profiles.is_empty() && app_state.general.selected_item < profiles.len() {
|
|
||||||
app_state.selected_profile = Some(profiles[app_state.general.selected_item].name.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// src/tui/functions/common.rs
|
|
||||||
pub mod commands;
|
|
||||||
pub mod form;
|
|
||||||
pub mod login;
|
|
||||||
|
|
||||||
pub use commands::*;
|
|
||||||
pub use form::{revert, save as form_save};
|
|
||||||
pub use login::{cancel, save as login_save};
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
// src/tui/controls/commands.rs
|
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
|
||||||
|
|
||||||
pub struct CommandHandler {
|
|
||||||
pub is_saved: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandHandler {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self { is_saved: false }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn handle_command(
|
|
||||||
&mut self,
|
|
||||||
action: &str,
|
|
||||||
terminal: &mut TerminalCore,
|
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
|
||||||
match action {
|
|
||||||
"quit" => self.handle_quit(terminal).await,
|
|
||||||
"force_quit" => self.handle_force_quit(terminal).await,
|
|
||||||
"save_and_quit" => self.handle_save_quit(terminal).await,
|
|
||||||
_ => Ok((false, format!("Unknown command: {}", action))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_quit(
|
|
||||||
&self,
|
|
||||||
terminal: &mut TerminalCore,
|
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
|
||||||
if self.is_saved {
|
|
||||||
terminal.cleanup()?;
|
|
||||||
Ok((true, "Exiting.".into()))
|
|
||||||
} else {
|
|
||||||
Ok((false, "No changes saved. Use :q! to force quit.".into()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_force_quit(
|
|
||||||
&self,
|
|
||||||
terminal: &mut TerminalCore,
|
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
|
||||||
terminal.cleanup()?;
|
|
||||||
Ok((true, "Force exiting without saving.".into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_save_quit(
|
|
||||||
&mut self,
|
|
||||||
terminal: &mut TerminalCore,
|
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
|
||||||
self.is_saved = true;
|
|
||||||
terminal.cleanup()?;
|
|
||||||
Ok((true, "State saved. Exiting.".into()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
// src/tui/functions/common/form.rs
|
|
||||||
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest};
|
|
||||||
|
|
||||||
/// Shared logic for saving the current form state
|
|
||||||
pub async fn save(
|
|
||||||
form_state: &mut FormState,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
is_saved: &mut bool,
|
|
||||||
current_position: &mut u64,
|
|
||||||
total_count: u64,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
let is_new = *current_position == total_count + 1;
|
|
||||||
|
|
||||||
let message = if is_new {
|
|
||||||
let post_request = PostAdresarRequest {
|
|
||||||
firma: form_state.values[0].clone(),
|
|
||||||
kz: form_state.values[1].clone(),
|
|
||||||
drc: form_state.values[2].clone(),
|
|
||||||
ulica: form_state.values[3].clone(),
|
|
||||||
psc: form_state.values[4].clone(),
|
|
||||||
mesto: form_state.values[5].clone(),
|
|
||||||
stat: form_state.values[6].clone(),
|
|
||||||
banka: form_state.values[7].clone(),
|
|
||||||
ucet: form_state.values[8].clone(),
|
|
||||||
skladm: form_state.values[9].clone(),
|
|
||||||
ico: form_state.values[10].clone(),
|
|
||||||
kontakt: form_state.values[11].clone(),
|
|
||||||
telefon: form_state.values[12].clone(),
|
|
||||||
skladu: form_state.values[13].clone(),
|
|
||||||
fax: form_state.values[14].clone(),
|
|
||||||
};
|
|
||||||
let response = grpc_client.post_adresar(post_request).await?;
|
|
||||||
let new_total = grpc_client.get_adresar_count().await?;
|
|
||||||
*current_position = new_total;
|
|
||||||
form_state.id = response.into_inner().id;
|
|
||||||
"New entry created".to_string()
|
|
||||||
} else {
|
|
||||||
let put_request = PutAdresarRequest {
|
|
||||||
id: form_state.id,
|
|
||||||
firma: form_state.values[0].clone(),
|
|
||||||
kz: form_state.values[1].clone(),
|
|
||||||
drc: form_state.values[2].clone(),
|
|
||||||
ulica: form_state.values[3].clone(),
|
|
||||||
psc: form_state.values[4].clone(),
|
|
||||||
mesto: form_state.values[5].clone(),
|
|
||||||
stat: form_state.values[6].clone(),
|
|
||||||
banka: form_state.values[7].clone(),
|
|
||||||
ucet: form_state.values[8].clone(),
|
|
||||||
skladm: form_state.values[9].clone(),
|
|
||||||
ico: form_state.values[10].clone(),
|
|
||||||
kontakt: form_state.values[11].clone(),
|
|
||||||
telefon: form_state.values[12].clone(),
|
|
||||||
skladu: form_state.values[13].clone(),
|
|
||||||
fax: form_state.values[14].clone(),
|
|
||||||
};
|
|
||||||
let _ = grpc_client.put_adresar(put_request).await?;
|
|
||||||
"Entry updated".to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
*is_saved = true;
|
|
||||||
form_state.has_unsaved_changes = false;
|
|
||||||
Ok(message)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Discard changes since last save
|
|
||||||
pub async fn revert(
|
|
||||||
form_state: &mut FormState,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
current_position: &mut u64,
|
|
||||||
total_count: u64,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
let is_new = *current_position == total_count + 1;
|
|
||||||
|
|
||||||
if is_new {
|
|
||||||
// Clear all fields for new entries
|
|
||||||
form_state.values.iter_mut().for_each(|v| *v = String::new());
|
|
||||||
form_state.has_unsaved_changes = false;
|
|
||||||
return Ok("New entry cleared".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
let data = grpc_client.get_adresar_by_position(*current_position).await?;
|
|
||||||
|
|
||||||
// Update form fields with saved values
|
|
||||||
form_state.values = vec![
|
|
||||||
data.firma,
|
|
||||||
data.kz,
|
|
||||||
data.drc,
|
|
||||||
data.ulica,
|
|
||||||
data.psc,
|
|
||||||
data.mesto,
|
|
||||||
data.stat,
|
|
||||||
data.banka,
|
|
||||||
data.ucet,
|
|
||||||
data.skladm,
|
|
||||||
data.ico,
|
|
||||||
data.kontakt,
|
|
||||||
data.telefon,
|
|
||||||
data.skladu,
|
|
||||||
data.fax,
|
|
||||||
];
|
|
||||||
|
|
||||||
form_state.has_unsaved_changes = false;
|
|
||||||
Ok("Changes discarded, reloaded last saved version".to_string())
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
// src/tui/functions/common/login.rs
|
|
||||||
use crate::services::auth::AuthClient;
|
|
||||||
use crate::state::pages::auth::AuthState;
|
|
||||||
use crate::state::state::AppState;
|
|
||||||
|
|
||||||
pub async fn save(
|
|
||||||
auth_state: &mut AuthState,
|
|
||||||
auth_client: &mut AuthClient,
|
|
||||||
app_state: &mut AppState,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
let identifier = auth_state.username.clone();
|
|
||||||
let password = auth_state.password.clone();
|
|
||||||
|
|
||||||
match auth_client.login(identifier, password).await {
|
|
||||||
Ok(response) => {
|
|
||||||
auth_state.auth_token = Some(response.access_token);
|
|
||||||
auth_state.user_id = Some(response.user_id);
|
|
||||||
auth_state.role = Some(response.role);
|
|
||||||
auth_state.error_message = None;
|
|
||||||
|
|
||||||
// Update app state to show main interface
|
|
||||||
app_state.ui.show_login = false;
|
|
||||||
app_state.ui.show_form = true;
|
|
||||||
|
|
||||||
Ok("Login successful!".to_string())
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
let error_message = format!("Login failed: {}", e);
|
|
||||||
auth_state.error_message = Some(error_message.clone());
|
|
||||||
Ok(error_message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn cancel(
|
|
||||||
auth_state: &mut AuthState,
|
|
||||||
app_state: &mut AppState,
|
|
||||||
) -> String {
|
|
||||||
auth_state.username.clear();
|
|
||||||
auth_state.password.clear();
|
|
||||||
auth_state.error_message = None;
|
|
||||||
app_state.ui.show_login = false;
|
|
||||||
app_state.ui.show_intro = true;
|
|
||||||
"Login canceled".to_string()
|
|
||||||
}
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
// src/tui/functions/form.rs
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
|
||||||
|
|
||||||
pub async fn handle_action(
|
|
||||||
action: &str,
|
|
||||||
form_state: &mut FormState,
|
|
||||||
grpc_client: &mut GrpcClient,
|
|
||||||
current_position: &mut u64,
|
|
||||||
total_count: u64,
|
|
||||||
ideal_cursor_column: &mut usize,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
match action {
|
|
||||||
"previous_entry" => {
|
|
||||||
let new_position = current_position.saturating_sub(1);
|
|
||||||
if new_position >= 1 {
|
|
||||||
*current_position = new_position;
|
|
||||||
let response = grpc_client.get_adresar_by_position(*current_position).await?;
|
|
||||||
|
|
||||||
// Direct field assignments
|
|
||||||
form_state.id = response.id;
|
|
||||||
form_state.values = vec![
|
|
||||||
response.firma, response.kz, response.drc,
|
|
||||||
response.ulica, response.psc, response.mesto,
|
|
||||||
response.stat, response.banka, response.ucet,
|
|
||||||
response.skladm, response.ico, response.kontakt,
|
|
||||||
response.telefon, response.skladu, response.fax,
|
|
||||||
];
|
|
||||||
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
let max_cursor_pos = if !current_input.is_empty() {
|
|
||||||
current_input.len() - 1
|
|
||||||
} else { 0 };
|
|
||||||
form_state.current_cursor_pos = std::cmp::min(*ideal_cursor_column, max_cursor_pos);
|
|
||||||
form_state.has_unsaved_changes = false;
|
|
||||||
|
|
||||||
Ok(format!("Loaded form entry {}", *current_position))
|
|
||||||
} else {
|
|
||||||
Ok("Already at first form entry".into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"next_entry" => {
|
|
||||||
if *current_position <= total_count {
|
|
||||||
*current_position += 1;
|
|
||||||
if *current_position <= total_count {
|
|
||||||
let response = grpc_client.get_adresar_by_position(*current_position).await?;
|
|
||||||
|
|
||||||
// Direct field assignments
|
|
||||||
form_state.id = response.id;
|
|
||||||
form_state.values = vec![
|
|
||||||
response.firma, response.kz, response.drc,
|
|
||||||
response.ulica, response.psc, response.mesto,
|
|
||||||
response.stat, response.banka, response.ucet,
|
|
||||||
response.skladm, response.ico, response.kontakt,
|
|
||||||
response.telefon, response.skladu, response.fax,
|
|
||||||
];
|
|
||||||
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
let max_cursor_pos = if !current_input.is_empty() {
|
|
||||||
current_input.len() - 1
|
|
||||||
} else { 0 };
|
|
||||||
form_state.current_cursor_pos = std::cmp::min(*ideal_cursor_column, max_cursor_pos);
|
|
||||||
form_state.has_unsaved_changes = false;
|
|
||||||
|
|
||||||
Ok(format!("Loaded form entry {}", *current_position))
|
|
||||||
} else {
|
|
||||||
form_state.reset_to_empty();
|
|
||||||
form_state.current_field = 0;
|
|
||||||
form_state.current_cursor_pos = 0;
|
|
||||||
*ideal_cursor_column = 0;
|
|
||||||
Ok("New form entry mode".into())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ok("Already at last entry".into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"move_up" => {
|
|
||||||
// Change field first
|
|
||||||
if form_state.current_field == 0 {
|
|
||||||
form_state.current_field = form_state.fields.len() - 1;
|
|
||||||
} else {
|
|
||||||
form_state.current_field = form_state.current_field.saturating_sub(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current input AFTER changing field
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
let max_cursor_pos = if !current_input.is_empty() {
|
|
||||||
current_input.len() - 1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
"move_down" => {
|
|
||||||
// Change field first
|
|
||||||
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
|
|
||||||
|
|
||||||
// Get current input AFTER changing field
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
let max_cursor_pos = if !current_input.is_empty() {
|
|
||||||
current_input.len() - 1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
|
|
||||||
Ok("".to_string())
|
|
||||||
}
|
|
||||||
_ => Err("Unknown form action".into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
use crate::state::state::AppState;
|
|
||||||
|
|
||||||
pub fn handle_intro_selection(app_state: &mut AppState) {
|
|
||||||
match app_state.ui.intro_state.selected_option {
|
|
||||||
0 => { // Continue
|
|
||||||
app_state.ui.show_form = true;
|
|
||||||
app_state.ui.show_admin = false;
|
|
||||||
app_state.ui.show_login = false;
|
|
||||||
}
|
|
||||||
1 => { // Admin
|
|
||||||
app_state.ui.show_form = false;
|
|
||||||
app_state.ui.show_admin = true;
|
|
||||||
app_state.ui.show_login = false;
|
|
||||||
}
|
|
||||||
2 => { // Login
|
|
||||||
app_state.ui.show_form = false;
|
|
||||||
app_state.ui.show_admin = false;
|
|
||||||
app_state.ui.show_login = true;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
app_state.ui.show_intro = false;
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
// src/tui/functions/login.rs
|
|
||||||
use crate::state::pages::auth::AuthState;
|
|
||||||
use crate::state::canvas_state::CanvasState;
|
|
||||||
|
|
||||||
pub async fn handle_action(
|
|
||||||
action: &str,
|
|
||||||
auth_state: &mut AuthState,
|
|
||||||
ideal_cursor_column: &mut usize,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
match action {
|
|
||||||
"move_up" => {
|
|
||||||
if auth_state.return_selected {
|
|
||||||
// From Return button to last field (password)
|
|
||||||
auth_state.return_selected = false;
|
|
||||||
auth_state.current_field = 1;
|
|
||||||
} else if auth_state.current_field == 1 {
|
|
||||||
// Password -> Username
|
|
||||||
auth_state.current_field = 0;
|
|
||||||
} else if auth_state.current_field == 0 {
|
|
||||||
// Username -> Password (wrap around fields only)
|
|
||||||
auth_state.current_field = 1;
|
|
||||||
} else if auth_state.current_field == 2 {
|
|
||||||
// From Login button to Password field
|
|
||||||
auth_state.current_field = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update cursor position only when in a field
|
|
||||||
if auth_state.current_field < 2 {
|
|
||||||
let current_input = auth_state.get_current_input();
|
|
||||||
let max_cursor_pos = current_input.len();
|
|
||||||
auth_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(format!("Navigation 'up' from functions/login"))
|
|
||||||
}
|
|
||||||
"move_down" => {
|
|
||||||
if auth_state.return_selected {
|
|
||||||
// From Return button to first field (username)
|
|
||||||
auth_state.return_selected = false;
|
|
||||||
auth_state.current_field = 0;
|
|
||||||
} else if auth_state.current_field == 0 {
|
|
||||||
// Username -> Password
|
|
||||||
auth_state.current_field = 1;
|
|
||||||
} else if auth_state.current_field == 1 {
|
|
||||||
// Password -> Login button
|
|
||||||
auth_state.current_field = 2;
|
|
||||||
auth_state.return_selected = false;
|
|
||||||
} else if auth_state.current_field == 2 {
|
|
||||||
// Login button -> Return button
|
|
||||||
auth_state.return_selected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update cursor position only when in a field
|
|
||||||
if auth_state.current_field < 2 {
|
|
||||||
let current_input = auth_state.get_current_input();
|
|
||||||
let max_cursor_pos = current_input.len();
|
|
||||||
auth_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(format!("Navigation 'down' from functions/login"))
|
|
||||||
}
|
|
||||||
_ => Err("Unknown login action".into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
// src/tui/mod.rs
|
|
||||||
pub mod terminal;
|
|
||||||
pub mod functions;
|
|
||||||
|
|
||||||
pub use functions::*;
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// src/tui/terminal.rs
|
|
||||||
|
|
||||||
pub mod core;
|
|
||||||
pub mod event_reader;
|
|
||||||
|
|
||||||
pub use core::TerminalCore;
|
|
||||||
pub use event_reader::EventReader;
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
// src/tui/terminal/core.rs
|
|
||||||
|
|
||||||
use crossterm::{
|
|
||||||
execute,
|
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
|
||||||
cursor::{SetCursorStyle, EnableBlinking, Show, MoveTo},
|
|
||||||
};
|
|
||||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
|
||||||
use std::io::{self, stdout, Write};
|
|
||||||
|
|
||||||
pub struct TerminalCore {
|
|
||||||
terminal: Terminal<CrosstermBackend<io::Stdout>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TerminalCore {
|
|
||||||
pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
|
||||||
enable_raw_mode()?;
|
|
||||||
let mut stdout = stdout();
|
|
||||||
execute!(
|
|
||||||
stdout,
|
|
||||||
EnterAlternateScreen,
|
|
||||||
SetCursorStyle::SteadyBlock,
|
|
||||||
EnableBlinking
|
|
||||||
)?;
|
|
||||||
let backend = CrosstermBackend::new(stdout);
|
|
||||||
let terminal = Terminal::new(backend)?;
|
|
||||||
Ok(Self { terminal })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn draw<F>(&mut self, f: F) -> Result<(), Box<dyn std::error::Error>>
|
|
||||||
where
|
|
||||||
F: FnOnce(&mut ratatui::Frame),
|
|
||||||
{
|
|
||||||
self.terminal.draw(f)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cleanup(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let backend = self.terminal.backend_mut();
|
|
||||||
execute!(
|
|
||||||
backend,
|
|
||||||
Show,
|
|
||||||
SetCursorStyle::DefaultUserShape,
|
|
||||||
LeaveAlternateScreen
|
|
||||||
)?;
|
|
||||||
disable_raw_mode()?;
|
|
||||||
backend.flush()?;
|
|
||||||
execute!(
|
|
||||||
backend,
|
|
||||||
crossterm::terminal::Clear(crossterm::terminal::ClearType::All),
|
|
||||||
MoveTo(0, 0)
|
|
||||||
)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_cursor_style(
|
|
||||||
&mut self,
|
|
||||||
style: SetCursorStyle,
|
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
execute!(
|
|
||||||
self.terminal.backend_mut(),
|
|
||||||
style,
|
|
||||||
EnableBlinking,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for TerminalCore {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
let _ = self.cleanup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
// src/tui/terminal/event_reader.rs
|
|
||||||
|
|
||||||
use crossterm::event::{self, Event};
|
|
||||||
|
|
||||||
pub struct EventReader;
|
|
||||||
|
|
||||||
impl EventReader {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_event(&self) -> Result<Event, Box<dyn std::error::Error>> {
|
|
||||||
Ok(event::read()?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// src/client/ui/handlers.rs
|
|
||||||
|
|
||||||
pub mod ui;
|
|
||||||
pub mod render;
|
|
||||||
pub mod rat_state;
|
|
||||||
|
|
||||||
pub use ui::run_ui;
|
|
||||||
pub use rat_state::*;
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
// src/ui/handlers/rat_state.rs
|
|
||||||
use crossterm::event::{KeyCode, KeyModifiers};
|
|
||||||
use crate::config::binds::config::Config;
|
|
||||||
use crate::state::state::UiState;
|
|
||||||
|
|
||||||
pub struct UiStateHandler;
|
|
||||||
|
|
||||||
impl UiStateHandler {
|
|
||||||
pub fn toggle_sidebar(
|
|
||||||
ui_state: &mut UiState,
|
|
||||||
config: &Config,
|
|
||||||
key: KeyCode,
|
|
||||||
modifiers: KeyModifiers,
|
|
||||||
) -> bool {
|
|
||||||
if let Some(action) = config.get_action_for_key_in_mode(&config.keybindings.common, key, modifiers) {
|
|
||||||
if action == "toggle_sidebar" {
|
|
||||||
ui_state.show_sidebar = !ui_state.show_sidebar;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
// src/ui/handlers/render.rs
|
|
||||||
|
|
||||||
use crate::components::{
|
|
||||||
render_background,
|
|
||||||
render_command_line,
|
|
||||||
render_status_line,
|
|
||||||
handlers::sidebar::{self, calculate_sidebar_layout},
|
|
||||||
form::form::render_form,
|
|
||||||
admin::{admin_panel::AdminPanelState},
|
|
||||||
auth::login::render_login,
|
|
||||||
};
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
use ratatui::layout::{Constraint, Direction, Layout};
|
|
||||||
use ratatui::Frame;
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
use crate::state::pages::auth::AuthState;
|
|
||||||
use crate::state::state::AppState;
|
|
||||||
|
|
||||||
pub fn render_ui(
|
|
||||||
f: &mut Frame,
|
|
||||||
form_state: &mut FormState,
|
|
||||||
auth_state: &mut AuthState,
|
|
||||||
theme: &Theme,
|
|
||||||
is_edit_mode: bool,
|
|
||||||
total_count: u64,
|
|
||||||
current_position: u64,
|
|
||||||
current_dir: &str,
|
|
||||||
command_input: &str,
|
|
||||||
command_mode: bool,
|
|
||||||
command_message: &str,
|
|
||||||
app_state: &AppState,
|
|
||||||
// intro_state parameter removed
|
|
||||||
) {
|
|
||||||
render_background(f, f.area(), theme);
|
|
||||||
|
|
||||||
let root = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Min(1),
|
|
||||||
Constraint::Length(1),
|
|
||||||
Constraint::Length(1),
|
|
||||||
])
|
|
||||||
.split(f.area());
|
|
||||||
|
|
||||||
let main_content_area = root[0];
|
|
||||||
if app_state.ui.show_intro {
|
|
||||||
// Use app_state's intro_state directly
|
|
||||||
app_state.ui.intro_state.render(f, main_content_area, theme);
|
|
||||||
}else if app_state.ui.show_login {
|
|
||||||
render_login(
|
|
||||||
f,
|
|
||||||
main_content_area,
|
|
||||||
theme,
|
|
||||||
auth_state,
|
|
||||||
app_state, // Add AppState reference here
|
|
||||||
auth_state.current_field < 2
|
|
||||||
);
|
|
||||||
} else if app_state.ui.show_admin {
|
|
||||||
// Create temporary AdminPanelState for rendering
|
|
||||||
let mut admin_state = AdminPanelState::new(
|
|
||||||
app_state.profile_tree.profiles
|
|
||||||
.iter()
|
|
||||||
.map(|p| p.name.clone())
|
|
||||||
.collect()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set the selected item - FIXED
|
|
||||||
if !admin_state.profiles.is_empty() {
|
|
||||||
let selected_index = std::cmp::min(
|
|
||||||
app_state.general.selected_item,
|
|
||||||
admin_state.profiles.len() - 1
|
|
||||||
);
|
|
||||||
admin_state.list_state.select(Some(selected_index));
|
|
||||||
}
|
|
||||||
|
|
||||||
admin_state.render(
|
|
||||||
f,
|
|
||||||
main_content_area,
|
|
||||||
theme,
|
|
||||||
&app_state.profile_tree,
|
|
||||||
&app_state.selected_profile,
|
|
||||||
);
|
|
||||||
} else if app_state.ui.show_form {
|
|
||||||
let (sidebar_area, form_area) = calculate_sidebar_layout(
|
|
||||||
app_state.ui.show_sidebar,
|
|
||||||
main_content_area
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(sidebar_rect) = sidebar_area {
|
|
||||||
sidebar::render_sidebar(
|
|
||||||
f,
|
|
||||||
sidebar_rect,
|
|
||||||
theme,
|
|
||||||
&app_state.profile_tree,
|
|
||||||
&app_state.selected_profile
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This change makes the form stay stationary when toggling sidebar
|
|
||||||
let available_width = form_area.width;
|
|
||||||
let form_constraint = if available_width >= 80 {
|
|
||||||
// Use main_content_area for centering when enough space
|
|
||||||
Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Min(0),
|
|
||||||
Constraint::Length(80),
|
|
||||||
Constraint::Min(0),
|
|
||||||
])
|
|
||||||
.split(main_content_area)[1]
|
|
||||||
} else {
|
|
||||||
// Use form_area (post sidebar) when limited space
|
|
||||||
Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Min(0),
|
|
||||||
Constraint::Length(80.min(available_width)),
|
|
||||||
Constraint::Min(0),
|
|
||||||
])
|
|
||||||
.split(form_area)[1]
|
|
||||||
};
|
|
||||||
|
|
||||||
// Convert fields to &[&str] and values to &[&String]
|
|
||||||
let fields: Vec<&str> = form_state.fields.iter().map(|s| s.as_str()).collect();
|
|
||||||
let values: Vec<&String> = form_state.values.iter().collect();
|
|
||||||
|
|
||||||
render_form(
|
|
||||||
f,
|
|
||||||
form_constraint,
|
|
||||||
form_state,
|
|
||||||
&fields,
|
|
||||||
&form_state.current_field,
|
|
||||||
&values,
|
|
||||||
theme,
|
|
||||||
is_edit_mode,
|
|
||||||
total_count,
|
|
||||||
current_position,
|
|
||||||
);
|
|
||||||
} else{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
render_status_line(f, root[1], current_dir, theme, is_edit_mode);
|
|
||||||
render_command_line(f, root[2], command_input, command_mode, theme, command_message);
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
// src/ui/handlers/ui.rs
|
|
||||||
|
|
||||||
use crate::tui::terminal::TerminalCore;
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
|
||||||
use crate::services::auth::AuthClient;
|
|
||||||
use crate::services::ui_service::UiService; // Add this import
|
|
||||||
use crate::tui::terminal::EventReader;
|
|
||||||
use crate::tui::functions::common::CommandHandler;
|
|
||||||
use crate::config::colors::themes::Theme;
|
|
||||||
use crate::config::binds::config::Config;
|
|
||||||
use crate::ui::handlers::render::render_ui;
|
|
||||||
use crate::state::pages::form::FormState;
|
|
||||||
use crate::state::pages::auth::AuthState;
|
|
||||||
use crate::modes::handlers::event::EventHandler;
|
|
||||||
use crate::state::state::AppState;
|
|
||||||
|
|
||||||
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let config = Config::load()?;
|
|
||||||
let mut terminal = TerminalCore::new()?;
|
|
||||||
let mut grpc_client = GrpcClient::new().await?;
|
|
||||||
let auth_client = AuthClient::new().await?;
|
|
||||||
let mut command_handler = CommandHandler::new();
|
|
||||||
let theme = Theme::from_str(&config.colors.theme);
|
|
||||||
let mut auth_state = AuthState::default();
|
|
||||||
|
|
||||||
// Initialize app_state first
|
|
||||||
let mut app_state = AppState::new()?;
|
|
||||||
|
|
||||||
// Initialize app state with profile tree and table structure
|
|
||||||
let column_names = UiService::initialize_app_state(&mut grpc_client, &mut app_state).await?;
|
|
||||||
|
|
||||||
// Initialize FormState with dynamic fields
|
|
||||||
let mut form_state = FormState::new(column_names);
|
|
||||||
|
|
||||||
// The rest of your UI initialization remains the same
|
|
||||||
let mut event_handler = EventHandler::new().await?;
|
|
||||||
let event_reader = EventReader::new();
|
|
||||||
|
|
||||||
// Fetch the total count of Adresar entries
|
|
||||||
UiService::initialize_adresar_count(&mut grpc_client, &mut app_state).await?;
|
|
||||||
form_state.reset_to_empty();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
UiService::update_adresar_count(&mut grpc_client, &mut app_state).await?;
|
|
||||||
|
|
||||||
terminal.draw(|f| {
|
|
||||||
render_ui(
|
|
||||||
f,
|
|
||||||
&mut form_state,
|
|
||||||
&mut auth_state,
|
|
||||||
&theme,
|
|
||||||
event_handler.is_edit_mode,
|
|
||||||
app_state.total_count,
|
|
||||||
app_state.current_position,
|
|
||||||
&app_state.current_dir,
|
|
||||||
&event_handler.command_input,
|
|
||||||
event_handler.command_mode,
|
|
||||||
&event_handler.command_message,
|
|
||||||
&app_state,
|
|
||||||
);
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let total_count = app_state.total_count;
|
|
||||||
let mut current_position = app_state.current_position;
|
|
||||||
|
|
||||||
let event = event_reader.read_event()?;
|
|
||||||
let (should_exit, message) = event_handler.handle_event(
|
|
||||||
event,
|
|
||||||
&config,
|
|
||||||
&mut terminal,
|
|
||||||
&mut grpc_client,
|
|
||||||
&mut command_handler,
|
|
||||||
&mut form_state,
|
|
||||||
&mut app_state,
|
|
||||||
total_count,
|
|
||||||
&mut current_position,
|
|
||||||
).await?;
|
|
||||||
|
|
||||||
app_state.current_position = current_position;
|
|
||||||
|
|
||||||
// Handle position changes and update form state
|
|
||||||
if !event_handler.is_edit_mode {
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
let max_cursor_pos = if !current_input.is_empty() {
|
|
||||||
current_input.len() - 1 // Limit to last character in readonly mode
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
form_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
|
|
||||||
|
|
||||||
// Ensure position never exceeds total_count + 1
|
|
||||||
if app_state.current_position > total_count + 1 {
|
|
||||||
app_state.current_position = total_count + 1;
|
|
||||||
}
|
|
||||||
if app_state.current_position > total_count {
|
|
||||||
// New entry - reset form
|
|
||||||
form_state.reset_to_empty();
|
|
||||||
form_state.current_field = 0;
|
|
||||||
} else if app_state.current_position >= 1 && app_state.current_position <= total_count {
|
|
||||||
// Existing entry - load data
|
|
||||||
let current_position = app_state.current_position;
|
|
||||||
let message = UiService::load_adresar_by_position(
|
|
||||||
&mut grpc_client,
|
|
||||||
&mut app_state,
|
|
||||||
&mut form_state,
|
|
||||||
current_position
|
|
||||||
).await?;
|
|
||||||
|
|
||||||
let current_input = form_state.get_current_input();
|
|
||||||
let max_cursor_pos = if !event_handler.is_edit_mode && !current_input.is_empty() {
|
|
||||||
current_input.len() - 1 // In readonly mode, limit to last character
|
|
||||||
} else {
|
|
||||||
current_input.len()
|
|
||||||
};
|
|
||||||
form_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
|
|
||||||
event_handler.command_message = message;
|
|
||||||
} else {
|
|
||||||
// Invalid position - reset to first entry
|
|
||||||
app_state.current_position = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event_handler.command_message = message;
|
|
||||||
if should_exit {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
// src/client/ui/mod.rs
|
|
||||||
pub mod models;
|
|
||||||
pub mod handlers;
|
|
||||||
|
|
||||||
pub use handlers::*;
|
|
||||||
@@ -5,9 +5,16 @@ edition.workspace = true
|
|||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tonic = "0.12.3"
|
prost-types = { workspace = true }
|
||||||
|
|
||||||
|
tonic = "0.13.0"
|
||||||
prost = "0.13.5"
|
prost = "0.13.5"
|
||||||
serde = { version = "1.0.218", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
|
|
||||||
|
# Search
|
||||||
|
tantivy = { workspace = true }
|
||||||
|
serde_json.workspace = true
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tonic-build = "0.12.3"
|
tonic-build = { version = "0.13.0", features = ["prost-build"] }
|
||||||
|
prost-build = "0.14.1"
|
||||||
|
|||||||
@@ -1,19 +1,75 @@
|
|||||||
// common/build.rs
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
tonic_build::configure()
|
tonic_build::configure()
|
||||||
.build_server(true)
|
.build_server(true)
|
||||||
.out_dir("src/proto")
|
|
||||||
.file_descriptor_set_path("src/proto/descriptor.bin")
|
.file_descriptor_set_path("src/proto/descriptor.bin")
|
||||||
.compile_protos( // Changed from .compile()
|
.out_dir("src/proto")
|
||||||
|
// Derive serde for the messages
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_validation.FieldValidation",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_validation.CharacterLimits",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_validation.DisplayMask",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_validation.TableValidationResponse",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_validation.UpdateFieldValidationRequest",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_validation.UpdateFieldValidationResponse",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||||
|
)
|
||||||
|
// Enum -> readable strings in JSON ("BYTES", "DISPLAY_WIDTH")
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_validation.CountMode",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)] #[serde(rename_all = \"SCREAMING_SNAKE_CASE\")]",
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_definition.ColumnDefinition",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_definition.TableLink",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]"
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_definition.PostTableDefinitionRequest",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_definition.TableDefinitionResponse",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]"
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_script.PostTableScriptRequest",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||||
|
)
|
||||||
|
.type_attribute(
|
||||||
|
".komp_ac.table_script.TableScriptResponse",
|
||||||
|
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||||
|
)
|
||||||
|
.compile_protos(
|
||||||
&[
|
&[
|
||||||
"proto/common.proto",
|
"proto/common.proto",
|
||||||
"proto/adresar.proto",
|
"proto/adresar.proto",
|
||||||
"proto/auth.proto",
|
"proto/auth.proto",
|
||||||
"proto/uctovnictvo.proto",
|
"proto/search.proto",
|
||||||
"proto/table_structure.proto",
|
"proto/search2.proto",
|
||||||
"proto/table_definition.proto",
|
"proto/table_definition.proto",
|
||||||
"proto/tables_data.proto",
|
|
||||||
"proto/table_script.proto",
|
"proto/table_script.proto",
|
||||||
|
"proto/table_structure.proto",
|
||||||
|
"proto/table_validation.proto",
|
||||||
|
"proto/tables_data.proto",
|
||||||
|
"proto/uctovnictvo.proto",
|
||||||
],
|
],
|
||||||
&["proto"],
|
&["proto"],
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// proto/adresar.proto
|
// proto/adresar.proto
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package multieko2.adresar;
|
package komp_ac.adresar;
|
||||||
|
|
||||||
import "common.proto";
|
import "common.proto";
|
||||||
// import "table_structure.proto";
|
// import "table_structure.proto";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// proto/auth.proto
|
// proto/auth.proto
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package multieko2.auth;
|
package komp_ac.auth;
|
||||||
|
|
||||||
import "common.proto";
|
import "common.proto";
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@ message RegisterRequest {
|
|||||||
string email = 2;
|
string email = 2;
|
||||||
string password = 3;
|
string password = 3;
|
||||||
string password_confirmation = 4;
|
string password_confirmation = 4;
|
||||||
|
string role = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AuthResponse {
|
message AuthResponse {
|
||||||
@@ -34,4 +35,5 @@ message LoginResponse {
|
|||||||
int32 expires_in = 3; // Expiration in seconds (86400 for 24 hours)
|
int32 expires_in = 3; // Expiration in seconds (86400 for 24 hours)
|
||||||
string user_id = 4; // User's UUID in string format
|
string user_id = 4; // User's UUID in string format
|
||||||
string role = 5; // User's role
|
string role = 5; // User's role
|
||||||
|
string username = 6;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// proto/common.proto
|
// proto/common.proto
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package multieko2.common;
|
package komp_ac.common;
|
||||||
|
|
||||||
message Empty {}
|
message Empty {}
|
||||||
message CountResponse { int64 count = 1; }
|
message CountResponse { int64 count = 1; }
|
||||||
|
|||||||
20
common/proto/search.proto
Normal file
20
common/proto/search.proto
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// In common/proto/search.proto
|
||||||
|
syntax = "proto3";
|
||||||
|
package komp_ac.search;
|
||||||
|
|
||||||
|
service Searcher {
|
||||||
|
rpc SearchTable(SearchRequest) returns (SearchResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
message SearchRequest {
|
||||||
|
string table_name = 1;
|
||||||
|
string query = 2;
|
||||||
|
}
|
||||||
|
message SearchResponse {
|
||||||
|
message Hit {
|
||||||
|
int64 id = 1; // PostgreSQL row ID
|
||||||
|
float score = 2;
|
||||||
|
string content_json = 3;
|
||||||
|
}
|
||||||
|
repeated Hit hits = 1;
|
||||||
|
}
|
||||||
46
common/proto/search2.proto
Normal file
46
common/proto/search2.proto
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// In common/proto/search2.proto
|
||||||
|
syntax = "proto3";
|
||||||
|
package komp_ac.search2;
|
||||||
|
|
||||||
|
service Search2 {
|
||||||
|
rpc SearchTable(Search2Request) returns (Search2Response);
|
||||||
|
}
|
||||||
|
|
||||||
|
message Search2Request {
|
||||||
|
string profile_name = 1;
|
||||||
|
string table_name = 2;
|
||||||
|
repeated ColumnFilter column_filters = 3;
|
||||||
|
optional string text_query = 4; // Optional fallback text search
|
||||||
|
optional int32 limit = 5;
|
||||||
|
optional string order_by = 6;
|
||||||
|
optional bool order_desc = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ColumnFilter {
|
||||||
|
string column_name = 1;
|
||||||
|
FilterType filter_type = 2;
|
||||||
|
string value = 3;
|
||||||
|
optional string value2 = 4; // For range queries
|
||||||
|
}
|
||||||
|
|
||||||
|
enum FilterType {
|
||||||
|
EQUALS = 0;
|
||||||
|
CONTAINS = 1;
|
||||||
|
STARTS_WITH = 2;
|
||||||
|
ENDS_WITH = 3;
|
||||||
|
RANGE = 4;
|
||||||
|
GREATER_THAN = 5;
|
||||||
|
LESS_THAN = 6;
|
||||||
|
IS_NULL = 7;
|
||||||
|
IS_NOT_NULL = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Search2Response {
|
||||||
|
message Hit {
|
||||||
|
int64 id = 1;
|
||||||
|
string content_json = 2; // No score - this is SQL-based
|
||||||
|
optional string match_info = 3; // Info about which columns matched
|
||||||
|
}
|
||||||
|
repeated Hit hits = 1;
|
||||||
|
int32 total_count = 2; // Total matching records (for pagination)
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
// common/proto/table_definition.proto
|
// common/proto/table_definition.proto
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package multieko2.table_definition;
|
package komp_ac.table_definition;
|
||||||
|
|
||||||
import "common.proto";
|
import "common.proto";
|
||||||
|
|
||||||
service TableDefinition {
|
service TableDefinition {
|
||||||
rpc PostTableDefinition (PostTableDefinitionRequest) returns (TableDefinitionResponse);
|
rpc PostTableDefinition (PostTableDefinitionRequest) returns (TableDefinitionResponse);
|
||||||
rpc GetProfileTree (multieko2.common.Empty) returns (ProfileTreeResponse);
|
rpc GetProfileTree (komp_ac.common.Empty) returns (ProfileTreeResponse);
|
||||||
rpc DeleteTable (DeleteTableRequest) returns (DeleteTableResponse);
|
rpc DeleteTable (DeleteTableRequest) returns (DeleteTableResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +21,6 @@ message PostTableDefinitionRequest {
|
|||||||
repeated ColumnDefinition columns = 3;
|
repeated ColumnDefinition columns = 3;
|
||||||
repeated string indexes = 4;
|
repeated string indexes = 4;
|
||||||
string profile_name = 5;
|
string profile_name = 5;
|
||||||
optional string linked_table_name = 6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message ColumnDefinition {
|
message ColumnDefinition {
|
||||||
@@ -36,8 +35,9 @@ message TableDefinitionResponse {
|
|||||||
|
|
||||||
message ProfileTreeResponse {
|
message ProfileTreeResponse {
|
||||||
message Table {
|
message Table {
|
||||||
string name = 1;
|
int64 id = 1;
|
||||||
repeated string depends_on = 2;
|
string name = 2;
|
||||||
|
repeated string depends_on = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Profile {
|
message Profile {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package multieko2.table_script;
|
package komp_ac.table_script;
|
||||||
|
|
||||||
service TableScript {
|
service TableScript {
|
||||||
rpc PostTableScript(PostTableScriptRequest) returns (TableScriptResponse);
|
rpc PostTableScript(PostTableScriptRequest) returns (TableScriptResponse);
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
// proto/table_structure.proto
|
// proto/table_structure.proto
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package multieko2.table_structure;
|
package komp_ac.table_structure;
|
||||||
|
|
||||||
import "common.proto";
|
import "common.proto";
|
||||||
|
|
||||||
|
message GetTableStructureRequest {
|
||||||
|
string profile_name = 1; // e.g., "default"
|
||||||
|
string table_name = 2; // e.g., "2025_adresar6"
|
||||||
|
}
|
||||||
|
|
||||||
message TableStructureResponse {
|
message TableStructureResponse {
|
||||||
repeated TableColumn columns = 1;
|
repeated TableColumn columns = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message TableColumn {
|
message TableColumn {
|
||||||
string name = 1;
|
string name = 1;
|
||||||
string data_type = 2;
|
string data_type = 2; // e.g., "TEXT", "BIGINT", "VARCHAR(255)", "TIMESTAMPTZ"
|
||||||
bool is_nullable = 3;
|
bool is_nullable = 3;
|
||||||
bool is_primary_key = 4;
|
bool is_primary_key = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
service TableStructureService {
|
service TableStructureService {
|
||||||
rpc GetAdresarTableStructure (common.Empty) returns (TableStructureResponse);
|
rpc GetTableStructure (GetTableStructureRequest) returns (TableStructureResponse);
|
||||||
rpc GetUctovnictvoTableStructure (common.Empty) returns (TableStructureResponse);
|
|
||||||
}
|
}
|
||||||
|
|||||||
79
common/proto/table_validation.proto
Normal file
79
common/proto/table_validation.proto
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
// common/proto/table_validation.proto
|
||||||
|
syntax = "proto3";
|
||||||
|
package komp_ac.table_validation;
|
||||||
|
|
||||||
|
// Request validation rules for a table
|
||||||
|
message GetTableValidationRequest {
|
||||||
|
string profileName = 1;
|
||||||
|
string tableName = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response with field-level validations; if a field is omitted,
|
||||||
|
// no validation is applied (default unspecified).
|
||||||
|
message TableValidationResponse {
|
||||||
|
repeated FieldValidation fields = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Field-level validation (extensible for future kinds)
|
||||||
|
message FieldValidation {
|
||||||
|
// MUST match your frontend FormState.dataKey for the column
|
||||||
|
string dataKey = 1;
|
||||||
|
|
||||||
|
// Current: only CharacterLimits. More rules can be added later.
|
||||||
|
CharacterLimits limits = 10;
|
||||||
|
// Future expansion:
|
||||||
|
// PatternRules pattern = 11;
|
||||||
|
DisplayMask mask = 3;
|
||||||
|
// ExternalValidation external = 13;
|
||||||
|
// CustomFormatter formatter = 14;
|
||||||
|
bool required = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Character length counting mode
|
||||||
|
enum CountMode {
|
||||||
|
COUNT_MODE_UNSPECIFIED = 0; // default: same as CHARS
|
||||||
|
CHARS = 1;
|
||||||
|
BYTES = 2;
|
||||||
|
DISPLAY_WIDTH = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Character limit validation (Validation 1)
|
||||||
|
message CharacterLimits {
|
||||||
|
// When zero, the field is considered "not set". If both min/max are zero,
|
||||||
|
// the server should avoid sending this FieldValidation (no validation).
|
||||||
|
uint32 min = 1;
|
||||||
|
uint32 max = 2;
|
||||||
|
|
||||||
|
// Optional warning threshold; when unset, no warning threshold is applied.
|
||||||
|
optional uint32 warnAt = 3;
|
||||||
|
|
||||||
|
CountMode countMode = 4; // defaults to CHARS if unspecified
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mask for pretty display
|
||||||
|
message DisplayMask {
|
||||||
|
string pattern = 1; // e.g., "(###) ###-####" or "####-##-##"
|
||||||
|
string input_char = 2; // e.g., "#"
|
||||||
|
optional string template_char = 3; // e.g., "_"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Service to fetch validations for a table
|
||||||
|
service TableValidationService {
|
||||||
|
rpc GetTableValidation(GetTableValidationRequest)
|
||||||
|
returns (TableValidationResponse);
|
||||||
|
|
||||||
|
rpc UpdateFieldValidation(UpdateFieldValidationRequest)
|
||||||
|
returns (UpdateFieldValidationResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateFieldValidationRequest {
|
||||||
|
string profileName = 1;
|
||||||
|
string tableName = 2;
|
||||||
|
string dataKey = 3;
|
||||||
|
FieldValidation validation = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateFieldValidationResponse {
|
||||||
|
bool success = 1;
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
@@ -1,22 +1,23 @@
|
|||||||
// common/proto/tables_data.proto
|
// common/proto/tables_data.proto
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package multieko2.tables_data;
|
package komp_ac.tables_data;
|
||||||
|
|
||||||
import "common.proto";
|
import "common.proto";
|
||||||
|
import "google/protobuf/struct.proto";
|
||||||
|
|
||||||
service TablesData {
|
service TablesData {
|
||||||
rpc PostTableData (PostTableDataRequest) returns (PostTableDataResponse);
|
rpc PostTableData (PostTableDataRequest) returns (PostTableDataResponse);
|
||||||
rpc PutTableData (PutTableDataRequest) returns (PutTableDataResponse);
|
rpc PutTableData (PutTableDataRequest) returns (PutTableDataResponse);
|
||||||
rpc DeleteTableData (DeleteTableDataRequest) returns (DeleteTableDataResponse);
|
rpc DeleteTableData (DeleteTableDataRequest) returns (DeleteTableDataResponse);
|
||||||
rpc GetTableData(GetTableDataRequest) returns (GetTableDataResponse);
|
rpc GetTableData(GetTableDataRequest) returns (GetTableDataResponse);
|
||||||
rpc GetTableDataCount(GetTableDataCountRequest) returns (multieko2.common.CountResponse);
|
rpc GetTableDataCount(GetTableDataCountRequest) returns (komp_ac.common.CountResponse);
|
||||||
rpc GetTableDataByPosition(GetTableDataByPositionRequest) returns (GetTableDataResponse);
|
rpc GetTableDataByPosition(GetTableDataByPositionRequest) returns (GetTableDataResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
message PostTableDataRequest {
|
message PostTableDataRequest {
|
||||||
string profile_name = 1;
|
string profile_name = 1;
|
||||||
string table_name = 2;
|
string table_name = 2;
|
||||||
map<string, string> data = 3;
|
map<string, google.protobuf.Value> data = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PostTableDataResponse {
|
message PostTableDataResponse {
|
||||||
@@ -29,7 +30,7 @@ message PutTableDataRequest {
|
|||||||
string profile_name = 1;
|
string profile_name = 1;
|
||||||
string table_name = 2;
|
string table_name = 2;
|
||||||
int64 id = 3;
|
int64 id = 3;
|
||||||
map<string, string> data = 4;
|
map<string, google.protobuf.Value> data = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PutTableDataResponse {
|
message PutTableDataResponse {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// proto/uctovnictvo.proto
|
// proto/uctovnictvo.proto
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package multieko2.uctovnictvo;
|
package komp_ac.uctovnictvo;
|
||||||
|
|
||||||
import "common.proto";
|
import "common.proto";
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,41 @@
|
|||||||
// common/src/lib.rs
|
// common/src/lib.rs
|
||||||
|
|
||||||
|
pub mod search;
|
||||||
|
|
||||||
pub mod proto {
|
pub mod proto {
|
||||||
pub mod multieko2 {
|
pub mod komp_ac {
|
||||||
pub mod adresar {
|
pub mod adresar {
|
||||||
include!("proto/multieko2.adresar.rs");
|
include!("proto/komp_ac.adresar.rs");
|
||||||
}
|
}
|
||||||
pub mod auth {
|
pub mod auth {
|
||||||
include!("proto/multieko2.auth.rs");
|
include!("proto/komp_ac.auth.rs");
|
||||||
}
|
}
|
||||||
pub mod common {
|
pub mod common {
|
||||||
include!("proto/multieko2.common.rs");
|
include!("proto/komp_ac.common.rs");
|
||||||
}
|
}
|
||||||
pub mod table_structure {
|
pub mod table_structure {
|
||||||
include!("proto/multieko2.table_structure.rs");
|
include!("proto/komp_ac.table_structure.rs");
|
||||||
}
|
}
|
||||||
pub mod uctovnictvo {
|
pub mod uctovnictvo {
|
||||||
include!("proto/multieko2.uctovnictvo.rs");
|
include!("proto/komp_ac.uctovnictvo.rs");
|
||||||
}
|
}
|
||||||
pub mod table_definition {
|
pub mod table_definition {
|
||||||
include!("proto/multieko2.table_definition.rs");
|
include!("proto/komp_ac.table_definition.rs");
|
||||||
}
|
}
|
||||||
pub mod tables_data {
|
pub mod tables_data {
|
||||||
include!("proto/multieko2.tables_data.rs");
|
include!("proto/komp_ac.tables_data.rs");
|
||||||
}
|
}
|
||||||
pub mod table_script {
|
pub mod table_script {
|
||||||
include!("proto/multieko2.table_script.rs");
|
include!("proto/komp_ac.table_script.rs");
|
||||||
|
}
|
||||||
|
pub mod search {
|
||||||
|
include!("proto/komp_ac.search.rs");
|
||||||
|
}
|
||||||
|
pub mod search2 {
|
||||||
|
include!("proto/komp_ac.search2.rs");
|
||||||
|
}
|
||||||
|
pub mod table_validation {
|
||||||
|
include!("proto/komp_ac.table_validation.rs");
|
||||||
}
|
}
|
||||||
pub const FILE_DESCRIPTOR_SET: &[u8] =
|
pub const FILE_DESCRIPTOR_SET: &[u8] =
|
||||||
include_bytes!("proto/descriptor.bin");
|
include_bytes!("proto/descriptor.bin");
|
||||||
|
|||||||
Binary file not shown.
@@ -145,7 +145,7 @@ pub mod adresar_client {
|
|||||||
}
|
}
|
||||||
impl<T> AdresarClient<T>
|
impl<T> AdresarClient<T>
|
||||||
where
|
where
|
||||||
T: tonic::client::GrpcService<tonic::body::BoxBody>,
|
T: tonic::client::GrpcService<tonic::body::Body>,
|
||||||
T::Error: Into<StdError>,
|
T::Error: Into<StdError>,
|
||||||
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
|
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
|
||||||
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
|
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
|
||||||
@@ -166,13 +166,13 @@ pub mod adresar_client {
|
|||||||
F: tonic::service::Interceptor,
|
F: tonic::service::Interceptor,
|
||||||
T::ResponseBody: Default,
|
T::ResponseBody: Default,
|
||||||
T: tonic::codegen::Service<
|
T: tonic::codegen::Service<
|
||||||
http::Request<tonic::body::BoxBody>,
|
http::Request<tonic::body::Body>,
|
||||||
Response = http::Response<
|
Response = http::Response<
|
||||||
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
|
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
<T as tonic::codegen::Service<
|
<T as tonic::codegen::Service<
|
||||||
http::Request<tonic::body::BoxBody>,
|
http::Request<tonic::body::Body>,
|
||||||
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
|
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
|
||||||
{
|
{
|
||||||
AdresarClient::new(InterceptedService::new(inner, interceptor))
|
AdresarClient::new(InterceptedService::new(inner, interceptor))
|
||||||
@@ -225,11 +225,11 @@ pub mod adresar_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.adresar.Adresar/PostAdresar",
|
"/komp_ac.adresar.Adresar/PostAdresar",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(GrpcMethod::new("multieko2.adresar.Adresar", "PostAdresar"));
|
.insert(GrpcMethod::new("komp_ac.adresar.Adresar", "PostAdresar"));
|
||||||
self.inner.unary(req, path, codec).await
|
self.inner.unary(req, path, codec).await
|
||||||
}
|
}
|
||||||
pub async fn get_adresar(
|
pub async fn get_adresar(
|
||||||
@@ -249,11 +249,11 @@ pub mod adresar_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.adresar.Adresar/GetAdresar",
|
"/komp_ac.adresar.Adresar/GetAdresar",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(GrpcMethod::new("multieko2.adresar.Adresar", "GetAdresar"));
|
.insert(GrpcMethod::new("komp_ac.adresar.Adresar", "GetAdresar"));
|
||||||
self.inner.unary(req, path, codec).await
|
self.inner.unary(req, path, codec).await
|
||||||
}
|
}
|
||||||
pub async fn put_adresar(
|
pub async fn put_adresar(
|
||||||
@@ -273,11 +273,11 @@ pub mod adresar_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.adresar.Adresar/PutAdresar",
|
"/komp_ac.adresar.Adresar/PutAdresar",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(GrpcMethod::new("multieko2.adresar.Adresar", "PutAdresar"));
|
.insert(GrpcMethod::new("komp_ac.adresar.Adresar", "PutAdresar"));
|
||||||
self.inner.unary(req, path, codec).await
|
self.inner.unary(req, path, codec).await
|
||||||
}
|
}
|
||||||
pub async fn delete_adresar(
|
pub async fn delete_adresar(
|
||||||
@@ -297,11 +297,11 @@ pub mod adresar_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.adresar.Adresar/DeleteAdresar",
|
"/komp_ac.adresar.Adresar/DeleteAdresar",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(GrpcMethod::new("multieko2.adresar.Adresar", "DeleteAdresar"));
|
.insert(GrpcMethod::new("komp_ac.adresar.Adresar", "DeleteAdresar"));
|
||||||
self.inner.unary(req, path, codec).await
|
self.inner.unary(req, path, codec).await
|
||||||
}
|
}
|
||||||
pub async fn get_adresar_count(
|
pub async fn get_adresar_count(
|
||||||
@@ -321,11 +321,11 @@ pub mod adresar_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.adresar.Adresar/GetAdresarCount",
|
"/komp_ac.adresar.Adresar/GetAdresarCount",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(GrpcMethod::new("multieko2.adresar.Adresar", "GetAdresarCount"));
|
.insert(GrpcMethod::new("komp_ac.adresar.Adresar", "GetAdresarCount"));
|
||||||
self.inner.unary(req, path, codec).await
|
self.inner.unary(req, path, codec).await
|
||||||
}
|
}
|
||||||
pub async fn get_adresar_by_position(
|
pub async fn get_adresar_by_position(
|
||||||
@@ -345,12 +345,12 @@ pub mod adresar_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.adresar.Adresar/GetAdresarByPosition",
|
"/komp_ac.adresar.Adresar/GetAdresarByPosition",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(
|
.insert(
|
||||||
GrpcMethod::new("multieko2.adresar.Adresar", "GetAdresarByPosition"),
|
GrpcMethod::new("komp_ac.adresar.Adresar", "GetAdresarByPosition"),
|
||||||
);
|
);
|
||||||
self.inner.unary(req, path, codec).await
|
self.inner.unary(req, path, codec).await
|
||||||
}
|
}
|
||||||
@@ -465,7 +465,7 @@ pub mod adresar_server {
|
|||||||
B: Body + std::marker::Send + 'static,
|
B: Body + std::marker::Send + 'static,
|
||||||
B::Error: Into<StdError> + std::marker::Send + 'static,
|
B::Error: Into<StdError> + std::marker::Send + 'static,
|
||||||
{
|
{
|
||||||
type Response = http::Response<tonic::body::BoxBody>;
|
type Response = http::Response<tonic::body::Body>;
|
||||||
type Error = std::convert::Infallible;
|
type Error = std::convert::Infallible;
|
||||||
type Future = BoxFuture<Self::Response, Self::Error>;
|
type Future = BoxFuture<Self::Response, Self::Error>;
|
||||||
fn poll_ready(
|
fn poll_ready(
|
||||||
@@ -476,7 +476,7 @@ pub mod adresar_server {
|
|||||||
}
|
}
|
||||||
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
||||||
match req.uri().path() {
|
match req.uri().path() {
|
||||||
"/multieko2.adresar.Adresar/PostAdresar" => {
|
"/komp_ac.adresar.Adresar/PostAdresar" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct PostAdresarSvc<T: Adresar>(pub Arc<T>);
|
struct PostAdresarSvc<T: Adresar>(pub Arc<T>);
|
||||||
impl<
|
impl<
|
||||||
@@ -521,7 +521,7 @@ pub mod adresar_server {
|
|||||||
};
|
};
|
||||||
Box::pin(fut)
|
Box::pin(fut)
|
||||||
}
|
}
|
||||||
"/multieko2.adresar.Adresar/GetAdresar" => {
|
"/komp_ac.adresar.Adresar/GetAdresar" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct GetAdresarSvc<T: Adresar>(pub Arc<T>);
|
struct GetAdresarSvc<T: Adresar>(pub Arc<T>);
|
||||||
impl<
|
impl<
|
||||||
@@ -566,7 +566,7 @@ pub mod adresar_server {
|
|||||||
};
|
};
|
||||||
Box::pin(fut)
|
Box::pin(fut)
|
||||||
}
|
}
|
||||||
"/multieko2.adresar.Adresar/PutAdresar" => {
|
"/komp_ac.adresar.Adresar/PutAdresar" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct PutAdresarSvc<T: Adresar>(pub Arc<T>);
|
struct PutAdresarSvc<T: Adresar>(pub Arc<T>);
|
||||||
impl<
|
impl<
|
||||||
@@ -611,7 +611,7 @@ pub mod adresar_server {
|
|||||||
};
|
};
|
||||||
Box::pin(fut)
|
Box::pin(fut)
|
||||||
}
|
}
|
||||||
"/multieko2.adresar.Adresar/DeleteAdresar" => {
|
"/komp_ac.adresar.Adresar/DeleteAdresar" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct DeleteAdresarSvc<T: Adresar>(pub Arc<T>);
|
struct DeleteAdresarSvc<T: Adresar>(pub Arc<T>);
|
||||||
impl<
|
impl<
|
||||||
@@ -656,7 +656,7 @@ pub mod adresar_server {
|
|||||||
};
|
};
|
||||||
Box::pin(fut)
|
Box::pin(fut)
|
||||||
}
|
}
|
||||||
"/multieko2.adresar.Adresar/GetAdresarCount" => {
|
"/komp_ac.adresar.Adresar/GetAdresarCount" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct GetAdresarCountSvc<T: Adresar>(pub Arc<T>);
|
struct GetAdresarCountSvc<T: Adresar>(pub Arc<T>);
|
||||||
impl<
|
impl<
|
||||||
@@ -701,7 +701,7 @@ pub mod adresar_server {
|
|||||||
};
|
};
|
||||||
Box::pin(fut)
|
Box::pin(fut)
|
||||||
}
|
}
|
||||||
"/multieko2.adresar.Adresar/GetAdresarByPosition" => {
|
"/komp_ac.adresar.Adresar/GetAdresarByPosition" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct GetAdresarByPositionSvc<T: Adresar>(pub Arc<T>);
|
struct GetAdresarByPositionSvc<T: Adresar>(pub Arc<T>);
|
||||||
impl<
|
impl<
|
||||||
@@ -751,7 +751,9 @@ pub mod adresar_server {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let mut response = http::Response::new(empty_body());
|
let mut response = http::Response::new(
|
||||||
|
tonic::body::Body::default(),
|
||||||
|
);
|
||||||
let headers = response.headers_mut();
|
let headers = response.headers_mut();
|
||||||
headers
|
headers
|
||||||
.insert(
|
.insert(
|
||||||
@@ -782,7 +784,7 @@ pub mod adresar_server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Generated gRPC service name
|
/// Generated gRPC service name
|
||||||
pub const SERVICE_NAME: &str = "multieko2.adresar.Adresar";
|
pub const SERVICE_NAME: &str = "komp_ac.adresar.Adresar";
|
||||||
impl<T> tonic::server::NamedService for AdresarServer<T> {
|
impl<T> tonic::server::NamedService for AdresarServer<T> {
|
||||||
const NAME: &'static str = SERVICE_NAME;
|
const NAME: &'static str = SERVICE_NAME;
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,8 @@ pub struct RegisterRequest {
|
|||||||
pub password: ::prost::alloc::string::String,
|
pub password: ::prost::alloc::string::String,
|
||||||
#[prost(string, tag = "4")]
|
#[prost(string, tag = "4")]
|
||||||
pub password_confirmation: ::prost::alloc::string::String,
|
pub password_confirmation: ::prost::alloc::string::String,
|
||||||
|
#[prost(string, tag = "5")]
|
||||||
|
pub role: ::prost::alloc::string::String,
|
||||||
}
|
}
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct AuthResponse {
|
pub struct AuthResponse {
|
||||||
@@ -50,6 +52,8 @@ pub struct LoginResponse {
|
|||||||
/// User's role
|
/// User's role
|
||||||
#[prost(string, tag = "5")]
|
#[prost(string, tag = "5")]
|
||||||
pub role: ::prost::alloc::string::String,
|
pub role: ::prost::alloc::string::String,
|
||||||
|
#[prost(string, tag = "6")]
|
||||||
|
pub username: ::prost::alloc::string::String,
|
||||||
}
|
}
|
||||||
/// Generated client implementations.
|
/// Generated client implementations.
|
||||||
pub mod auth_service_client {
|
pub mod auth_service_client {
|
||||||
@@ -79,7 +83,7 @@ pub mod auth_service_client {
|
|||||||
}
|
}
|
||||||
impl<T> AuthServiceClient<T>
|
impl<T> AuthServiceClient<T>
|
||||||
where
|
where
|
||||||
T: tonic::client::GrpcService<tonic::body::BoxBody>,
|
T: tonic::client::GrpcService<tonic::body::Body>,
|
||||||
T::Error: Into<StdError>,
|
T::Error: Into<StdError>,
|
||||||
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
|
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
|
||||||
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
|
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
|
||||||
@@ -100,13 +104,13 @@ pub mod auth_service_client {
|
|||||||
F: tonic::service::Interceptor,
|
F: tonic::service::Interceptor,
|
||||||
T::ResponseBody: Default,
|
T::ResponseBody: Default,
|
||||||
T: tonic::codegen::Service<
|
T: tonic::codegen::Service<
|
||||||
http::Request<tonic::body::BoxBody>,
|
http::Request<tonic::body::Body>,
|
||||||
Response = http::Response<
|
Response = http::Response<
|
||||||
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
|
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
<T as tonic::codegen::Service<
|
<T as tonic::codegen::Service<
|
||||||
http::Request<tonic::body::BoxBody>,
|
http::Request<tonic::body::Body>,
|
||||||
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
|
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
|
||||||
{
|
{
|
||||||
AuthServiceClient::new(InterceptedService::new(inner, interceptor))
|
AuthServiceClient::new(InterceptedService::new(inner, interceptor))
|
||||||
@@ -156,11 +160,11 @@ pub mod auth_service_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.auth.AuthService/Register",
|
"/komp_ac.auth.AuthService/Register",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(GrpcMethod::new("multieko2.auth.AuthService", "Register"));
|
.insert(GrpcMethod::new("komp_ac.auth.AuthService", "Register"));
|
||||||
self.inner.unary(req, path, codec).await
|
self.inner.unary(req, path, codec).await
|
||||||
}
|
}
|
||||||
pub async fn login(
|
pub async fn login(
|
||||||
@@ -177,11 +181,11 @@ pub mod auth_service_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.auth.AuthService/Login",
|
"/komp_ac.auth.AuthService/Login",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(GrpcMethod::new("multieko2.auth.AuthService", "Login"));
|
.insert(GrpcMethod::new("komp_ac.auth.AuthService", "Login"));
|
||||||
self.inner.unary(req, path, codec).await
|
self.inner.unary(req, path, codec).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,7 +277,7 @@ pub mod auth_service_server {
|
|||||||
B: Body + std::marker::Send + 'static,
|
B: Body + std::marker::Send + 'static,
|
||||||
B::Error: Into<StdError> + std::marker::Send + 'static,
|
B::Error: Into<StdError> + std::marker::Send + 'static,
|
||||||
{
|
{
|
||||||
type Response = http::Response<tonic::body::BoxBody>;
|
type Response = http::Response<tonic::body::Body>;
|
||||||
type Error = std::convert::Infallible;
|
type Error = std::convert::Infallible;
|
||||||
type Future = BoxFuture<Self::Response, Self::Error>;
|
type Future = BoxFuture<Self::Response, Self::Error>;
|
||||||
fn poll_ready(
|
fn poll_ready(
|
||||||
@@ -284,7 +288,7 @@ pub mod auth_service_server {
|
|||||||
}
|
}
|
||||||
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
||||||
match req.uri().path() {
|
match req.uri().path() {
|
||||||
"/multieko2.auth.AuthService/Register" => {
|
"/komp_ac.auth.AuthService/Register" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct RegisterSvc<T: AuthService>(pub Arc<T>);
|
struct RegisterSvc<T: AuthService>(pub Arc<T>);
|
||||||
impl<
|
impl<
|
||||||
@@ -329,7 +333,7 @@ pub mod auth_service_server {
|
|||||||
};
|
};
|
||||||
Box::pin(fut)
|
Box::pin(fut)
|
||||||
}
|
}
|
||||||
"/multieko2.auth.AuthService/Login" => {
|
"/komp_ac.auth.AuthService/Login" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct LoginSvc<T: AuthService>(pub Arc<T>);
|
struct LoginSvc<T: AuthService>(pub Arc<T>);
|
||||||
impl<T: AuthService> tonic::server::UnaryService<super::LoginRequest>
|
impl<T: AuthService> tonic::server::UnaryService<super::LoginRequest>
|
||||||
@@ -374,7 +378,9 @@ pub mod auth_service_server {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let mut response = http::Response::new(empty_body());
|
let mut response = http::Response::new(
|
||||||
|
tonic::body::Body::default(),
|
||||||
|
);
|
||||||
let headers = response.headers_mut();
|
let headers = response.headers_mut();
|
||||||
headers
|
headers
|
||||||
.insert(
|
.insert(
|
||||||
@@ -405,7 +411,7 @@ pub mod auth_service_server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Generated gRPC service name
|
/// Generated gRPC service name
|
||||||
pub const SERVICE_NAME: &str = "multieko2.auth.AuthService";
|
pub const SERVICE_NAME: &str = "komp_ac.auth.AuthService";
|
||||||
impl<T> tonic::server::NamedService for AuthServiceServer<T> {
|
impl<T> tonic::server::NamedService for AuthServiceServer<T> {
|
||||||
const NAME: &'static str = SERVICE_NAME;
|
const NAME: &'static str = SERVICE_NAME;
|
||||||
}
|
}
|
||||||
317
common/src/proto/komp_ac.search.rs
Normal file
317
common/src/proto/komp_ac.search.rs
Normal file
@@ -0,0 +1,317 @@
|
|||||||
|
// This file is @generated by prost-build.
|
||||||
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
|
pub struct SearchRequest {
|
||||||
|
#[prost(string, tag = "1")]
|
||||||
|
pub table_name: ::prost::alloc::string::String,
|
||||||
|
#[prost(string, tag = "2")]
|
||||||
|
pub query: ::prost::alloc::string::String,
|
||||||
|
}
|
||||||
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
|
pub struct SearchResponse {
|
||||||
|
#[prost(message, repeated, tag = "1")]
|
||||||
|
pub hits: ::prost::alloc::vec::Vec<search_response::Hit>,
|
||||||
|
}
|
||||||
|
/// Nested message and enum types in `SearchResponse`.
|
||||||
|
pub mod search_response {
|
||||||
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
|
pub struct Hit {
|
||||||
|
/// PostgreSQL row ID
|
||||||
|
#[prost(int64, tag = "1")]
|
||||||
|
pub id: i64,
|
||||||
|
#[prost(float, tag = "2")]
|
||||||
|
pub score: f32,
|
||||||
|
#[prost(string, tag = "3")]
|
||||||
|
pub content_json: ::prost::alloc::string::String,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Generated client implementations.
|
||||||
|
pub mod searcher_client {
|
||||||
|
#![allow(
|
||||||
|
unused_variables,
|
||||||
|
dead_code,
|
||||||
|
missing_docs,
|
||||||
|
clippy::wildcard_imports,
|
||||||
|
clippy::let_unit_value,
|
||||||
|
)]
|
||||||
|
use tonic::codegen::*;
|
||||||
|
use tonic::codegen::http::Uri;
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct SearcherClient<T> {
|
||||||
|
inner: tonic::client::Grpc<T>,
|
||||||
|
}
|
||||||
|
impl SearcherClient<tonic::transport::Channel> {
|
||||||
|
/// Attempt to create a new client by connecting to a given endpoint.
|
||||||
|
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
|
||||||
|
where
|
||||||
|
D: TryInto<tonic::transport::Endpoint>,
|
||||||
|
D::Error: Into<StdError>,
|
||||||
|
{
|
||||||
|
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
|
||||||
|
Ok(Self::new(conn))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T> SearcherClient<T>
|
||||||
|
where
|
||||||
|
T: tonic::client::GrpcService<tonic::body::Body>,
|
||||||
|
T::Error: Into<StdError>,
|
||||||
|
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
|
||||||
|
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
|
||||||
|
{
|
||||||
|
pub fn new(inner: T) -> Self {
|
||||||
|
let inner = tonic::client::Grpc::new(inner);
|
||||||
|
Self { inner }
|
||||||
|
}
|
||||||
|
pub fn with_origin(inner: T, origin: Uri) -> Self {
|
||||||
|
let inner = tonic::client::Grpc::with_origin(inner, origin);
|
||||||
|
Self { inner }
|
||||||
|
}
|
||||||
|
pub fn with_interceptor<F>(
|
||||||
|
inner: T,
|
||||||
|
interceptor: F,
|
||||||
|
) -> SearcherClient<InterceptedService<T, F>>
|
||||||
|
where
|
||||||
|
F: tonic::service::Interceptor,
|
||||||
|
T::ResponseBody: Default,
|
||||||
|
T: tonic::codegen::Service<
|
||||||
|
http::Request<tonic::body::Body>,
|
||||||
|
Response = http::Response<
|
||||||
|
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
|
<T as tonic::codegen::Service<
|
||||||
|
http::Request<tonic::body::Body>,
|
||||||
|
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
|
||||||
|
{
|
||||||
|
SearcherClient::new(InterceptedService::new(inner, interceptor))
|
||||||
|
}
|
||||||
|
/// Compress requests with the given encoding.
|
||||||
|
///
|
||||||
|
/// This requires the server to support it otherwise it might respond with an
|
||||||
|
/// error.
|
||||||
|
#[must_use]
|
||||||
|
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||||
|
self.inner = self.inner.send_compressed(encoding);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Enable decompressing responses.
|
||||||
|
#[must_use]
|
||||||
|
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||||
|
self.inner = self.inner.accept_compressed(encoding);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Limits the maximum size of a decoded message.
|
||||||
|
///
|
||||||
|
/// Default: `4MB`
|
||||||
|
#[must_use]
|
||||||
|
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
|
||||||
|
self.inner = self.inner.max_decoding_message_size(limit);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Limits the maximum size of an encoded message.
|
||||||
|
///
|
||||||
|
/// Default: `usize::MAX`
|
||||||
|
#[must_use]
|
||||||
|
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
|
||||||
|
self.inner = self.inner.max_encoding_message_size(limit);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
pub async fn search_table(
|
||||||
|
&mut self,
|
||||||
|
request: impl tonic::IntoRequest<super::SearchRequest>,
|
||||||
|
) -> std::result::Result<tonic::Response<super::SearchResponse>, tonic::Status> {
|
||||||
|
self.inner
|
||||||
|
.ready()
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
tonic::Status::unknown(
|
||||||
|
format!("Service was not ready: {}", e.into()),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
|
"/komp_ac.search.Searcher/SearchTable",
|
||||||
|
);
|
||||||
|
let mut req = request.into_request();
|
||||||
|
req.extensions_mut()
|
||||||
|
.insert(GrpcMethod::new("komp_ac.search.Searcher", "SearchTable"));
|
||||||
|
self.inner.unary(req, path, codec).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Generated server implementations.
|
||||||
|
pub mod searcher_server {
|
||||||
|
#![allow(
|
||||||
|
unused_variables,
|
||||||
|
dead_code,
|
||||||
|
missing_docs,
|
||||||
|
clippy::wildcard_imports,
|
||||||
|
clippy::let_unit_value,
|
||||||
|
)]
|
||||||
|
use tonic::codegen::*;
|
||||||
|
/// Generated trait containing gRPC methods that should be implemented for use with SearcherServer.
|
||||||
|
#[async_trait]
|
||||||
|
pub trait Searcher: std::marker::Send + std::marker::Sync + 'static {
|
||||||
|
async fn search_table(
|
||||||
|
&self,
|
||||||
|
request: tonic::Request<super::SearchRequest>,
|
||||||
|
) -> std::result::Result<tonic::Response<super::SearchResponse>, tonic::Status>;
|
||||||
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SearcherServer<T> {
|
||||||
|
inner: Arc<T>,
|
||||||
|
accept_compression_encodings: EnabledCompressionEncodings,
|
||||||
|
send_compression_encodings: EnabledCompressionEncodings,
|
||||||
|
max_decoding_message_size: Option<usize>,
|
||||||
|
max_encoding_message_size: Option<usize>,
|
||||||
|
}
|
||||||
|
impl<T> SearcherServer<T> {
|
||||||
|
pub fn new(inner: T) -> Self {
|
||||||
|
Self::from_arc(Arc::new(inner))
|
||||||
|
}
|
||||||
|
pub fn from_arc(inner: Arc<T>) -> Self {
|
||||||
|
Self {
|
||||||
|
inner,
|
||||||
|
accept_compression_encodings: Default::default(),
|
||||||
|
send_compression_encodings: Default::default(),
|
||||||
|
max_decoding_message_size: None,
|
||||||
|
max_encoding_message_size: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn with_interceptor<F>(
|
||||||
|
inner: T,
|
||||||
|
interceptor: F,
|
||||||
|
) -> InterceptedService<Self, F>
|
||||||
|
where
|
||||||
|
F: tonic::service::Interceptor,
|
||||||
|
{
|
||||||
|
InterceptedService::new(Self::new(inner), interceptor)
|
||||||
|
}
|
||||||
|
/// Enable decompressing requests with the given encoding.
|
||||||
|
#[must_use]
|
||||||
|
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||||
|
self.accept_compression_encodings.enable(encoding);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Compress responses with the given encoding, if the client supports it.
|
||||||
|
#[must_use]
|
||||||
|
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||||
|
self.send_compression_encodings.enable(encoding);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Limits the maximum size of a decoded message.
|
||||||
|
///
|
||||||
|
/// Default: `4MB`
|
||||||
|
#[must_use]
|
||||||
|
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
|
||||||
|
self.max_decoding_message_size = Some(limit);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Limits the maximum size of an encoded message.
|
||||||
|
///
|
||||||
|
/// Default: `usize::MAX`
|
||||||
|
#[must_use]
|
||||||
|
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
|
||||||
|
self.max_encoding_message_size = Some(limit);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T, B> tonic::codegen::Service<http::Request<B>> for SearcherServer<T>
|
||||||
|
where
|
||||||
|
T: Searcher,
|
||||||
|
B: Body + std::marker::Send + 'static,
|
||||||
|
B::Error: Into<StdError> + std::marker::Send + 'static,
|
||||||
|
{
|
||||||
|
type Response = http::Response<tonic::body::Body>;
|
||||||
|
type Error = std::convert::Infallible;
|
||||||
|
type Future = BoxFuture<Self::Response, Self::Error>;
|
||||||
|
fn poll_ready(
|
||||||
|
&mut self,
|
||||||
|
_cx: &mut Context<'_>,
|
||||||
|
) -> Poll<std::result::Result<(), Self::Error>> {
|
||||||
|
Poll::Ready(Ok(()))
|
||||||
|
}
|
||||||
|
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
||||||
|
match req.uri().path() {
|
||||||
|
"/komp_ac.search.Searcher/SearchTable" => {
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
struct SearchTableSvc<T: Searcher>(pub Arc<T>);
|
||||||
|
impl<T: Searcher> tonic::server::UnaryService<super::SearchRequest>
|
||||||
|
for SearchTableSvc<T> {
|
||||||
|
type Response = super::SearchResponse;
|
||||||
|
type Future = BoxFuture<
|
||||||
|
tonic::Response<Self::Response>,
|
||||||
|
tonic::Status,
|
||||||
|
>;
|
||||||
|
fn call(
|
||||||
|
&mut self,
|
||||||
|
request: tonic::Request<super::SearchRequest>,
|
||||||
|
) -> Self::Future {
|
||||||
|
let inner = Arc::clone(&self.0);
|
||||||
|
let fut = async move {
|
||||||
|
<T as Searcher>::search_table(&inner, request).await
|
||||||
|
};
|
||||||
|
Box::pin(fut)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let accept_compression_encodings = self.accept_compression_encodings;
|
||||||
|
let send_compression_encodings = self.send_compression_encodings;
|
||||||
|
let max_decoding_message_size = self.max_decoding_message_size;
|
||||||
|
let max_encoding_message_size = self.max_encoding_message_size;
|
||||||
|
let inner = self.inner.clone();
|
||||||
|
let fut = async move {
|
||||||
|
let method = SearchTableSvc(inner);
|
||||||
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
|
let mut grpc = tonic::server::Grpc::new(codec)
|
||||||
|
.apply_compression_config(
|
||||||
|
accept_compression_encodings,
|
||||||
|
send_compression_encodings,
|
||||||
|
)
|
||||||
|
.apply_max_message_size_config(
|
||||||
|
max_decoding_message_size,
|
||||||
|
max_encoding_message_size,
|
||||||
|
);
|
||||||
|
let res = grpc.unary(method, req).await;
|
||||||
|
Ok(res)
|
||||||
|
};
|
||||||
|
Box::pin(fut)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
Box::pin(async move {
|
||||||
|
let mut response = http::Response::new(
|
||||||
|
tonic::body::Body::default(),
|
||||||
|
);
|
||||||
|
let headers = response.headers_mut();
|
||||||
|
headers
|
||||||
|
.insert(
|
||||||
|
tonic::Status::GRPC_STATUS,
|
||||||
|
(tonic::Code::Unimplemented as i32).into(),
|
||||||
|
);
|
||||||
|
headers
|
||||||
|
.insert(
|
||||||
|
http::header::CONTENT_TYPE,
|
||||||
|
tonic::metadata::GRPC_CONTENT_TYPE,
|
||||||
|
);
|
||||||
|
Ok(response)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T> Clone for SearcherServer<T> {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
let inner = self.inner.clone();
|
||||||
|
Self {
|
||||||
|
inner,
|
||||||
|
accept_compression_encodings: self.accept_compression_encodings,
|
||||||
|
send_compression_encodings: self.send_compression_encodings,
|
||||||
|
max_decoding_message_size: self.max_decoding_message_size,
|
||||||
|
max_encoding_message_size: self.max_encoding_message_size,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Generated gRPC service name
|
||||||
|
pub const SERVICE_NAME: &str = "komp_ac.search.Searcher";
|
||||||
|
impl<T> tonic::server::NamedService for SearcherServer<T> {
|
||||||
|
const NAME: &'static str = SERVICE_NAME;
|
||||||
|
}
|
||||||
|
}
|
||||||
394
common/src/proto/komp_ac.search2.rs
Normal file
394
common/src/proto/komp_ac.search2.rs
Normal file
@@ -0,0 +1,394 @@
|
|||||||
|
// This file is @generated by prost-build.
|
||||||
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
|
pub struct Search2Request {
|
||||||
|
#[prost(string, tag = "1")]
|
||||||
|
pub profile_name: ::prost::alloc::string::String,
|
||||||
|
#[prost(string, tag = "2")]
|
||||||
|
pub table_name: ::prost::alloc::string::String,
|
||||||
|
#[prost(message, repeated, tag = "3")]
|
||||||
|
pub column_filters: ::prost::alloc::vec::Vec<ColumnFilter>,
|
||||||
|
/// Optional fallback text search
|
||||||
|
#[prost(string, optional, tag = "4")]
|
||||||
|
pub text_query: ::core::option::Option<::prost::alloc::string::String>,
|
||||||
|
#[prost(int32, optional, tag = "5")]
|
||||||
|
pub limit: ::core::option::Option<i32>,
|
||||||
|
#[prost(string, optional, tag = "6")]
|
||||||
|
pub order_by: ::core::option::Option<::prost::alloc::string::String>,
|
||||||
|
#[prost(bool, optional, tag = "7")]
|
||||||
|
pub order_desc: ::core::option::Option<bool>,
|
||||||
|
}
|
||||||
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
|
pub struct ColumnFilter {
|
||||||
|
#[prost(string, tag = "1")]
|
||||||
|
pub column_name: ::prost::alloc::string::String,
|
||||||
|
#[prost(enumeration = "FilterType", tag = "2")]
|
||||||
|
pub filter_type: i32,
|
||||||
|
#[prost(string, tag = "3")]
|
||||||
|
pub value: ::prost::alloc::string::String,
|
||||||
|
/// For range queries
|
||||||
|
#[prost(string, optional, tag = "4")]
|
||||||
|
pub value2: ::core::option::Option<::prost::alloc::string::String>,
|
||||||
|
}
|
||||||
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
|
pub struct Search2Response {
|
||||||
|
#[prost(message, repeated, tag = "1")]
|
||||||
|
pub hits: ::prost::alloc::vec::Vec<search2_response::Hit>,
|
||||||
|
/// Total matching records (for pagination)
|
||||||
|
#[prost(int32, tag = "2")]
|
||||||
|
pub total_count: i32,
|
||||||
|
}
|
||||||
|
/// Nested message and enum types in `Search2Response`.
|
||||||
|
pub mod search2_response {
|
||||||
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
|
pub struct Hit {
|
||||||
|
#[prost(int64, tag = "1")]
|
||||||
|
pub id: i64,
|
||||||
|
/// No score - this is SQL-based
|
||||||
|
#[prost(string, tag = "2")]
|
||||||
|
pub content_json: ::prost::alloc::string::String,
|
||||||
|
/// Info about which columns matched
|
||||||
|
#[prost(string, optional, tag = "3")]
|
||||||
|
pub match_info: ::core::option::Option<::prost::alloc::string::String>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
|
||||||
|
#[repr(i32)]
|
||||||
|
pub enum FilterType {
|
||||||
|
Equals = 0,
|
||||||
|
Contains = 1,
|
||||||
|
StartsWith = 2,
|
||||||
|
EndsWith = 3,
|
||||||
|
Range = 4,
|
||||||
|
GreaterThan = 5,
|
||||||
|
LessThan = 6,
|
||||||
|
IsNull = 7,
|
||||||
|
IsNotNull = 8,
|
||||||
|
}
|
||||||
|
impl FilterType {
|
||||||
|
/// String value of the enum field names used in the ProtoBuf definition.
|
||||||
|
///
|
||||||
|
/// The values are not transformed in any way and thus are considered stable
|
||||||
|
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
|
||||||
|
pub fn as_str_name(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Equals => "EQUALS",
|
||||||
|
Self::Contains => "CONTAINS",
|
||||||
|
Self::StartsWith => "STARTS_WITH",
|
||||||
|
Self::EndsWith => "ENDS_WITH",
|
||||||
|
Self::Range => "RANGE",
|
||||||
|
Self::GreaterThan => "GREATER_THAN",
|
||||||
|
Self::LessThan => "LESS_THAN",
|
||||||
|
Self::IsNull => "IS_NULL",
|
||||||
|
Self::IsNotNull => "IS_NOT_NULL",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Creates an enum from field names used in the ProtoBuf definition.
|
||||||
|
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
|
||||||
|
match value {
|
||||||
|
"EQUALS" => Some(Self::Equals),
|
||||||
|
"CONTAINS" => Some(Self::Contains),
|
||||||
|
"STARTS_WITH" => Some(Self::StartsWith),
|
||||||
|
"ENDS_WITH" => Some(Self::EndsWith),
|
||||||
|
"RANGE" => Some(Self::Range),
|
||||||
|
"GREATER_THAN" => Some(Self::GreaterThan),
|
||||||
|
"LESS_THAN" => Some(Self::LessThan),
|
||||||
|
"IS_NULL" => Some(Self::IsNull),
|
||||||
|
"IS_NOT_NULL" => Some(Self::IsNotNull),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Generated client implementations.
|
||||||
|
pub mod search2_client {
|
||||||
|
#![allow(
|
||||||
|
unused_variables,
|
||||||
|
dead_code,
|
||||||
|
missing_docs,
|
||||||
|
clippy::wildcard_imports,
|
||||||
|
clippy::let_unit_value,
|
||||||
|
)]
|
||||||
|
use tonic::codegen::*;
|
||||||
|
use tonic::codegen::http::Uri;
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Search2Client<T> {
|
||||||
|
inner: tonic::client::Grpc<T>,
|
||||||
|
}
|
||||||
|
impl Search2Client<tonic::transport::Channel> {
|
||||||
|
/// Attempt to create a new client by connecting to a given endpoint.
|
||||||
|
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
|
||||||
|
where
|
||||||
|
D: TryInto<tonic::transport::Endpoint>,
|
||||||
|
D::Error: Into<StdError>,
|
||||||
|
{
|
||||||
|
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
|
||||||
|
Ok(Self::new(conn))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T> Search2Client<T>
|
||||||
|
where
|
||||||
|
T: tonic::client::GrpcService<tonic::body::Body>,
|
||||||
|
T::Error: Into<StdError>,
|
||||||
|
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
|
||||||
|
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
|
||||||
|
{
|
||||||
|
pub fn new(inner: T) -> Self {
|
||||||
|
let inner = tonic::client::Grpc::new(inner);
|
||||||
|
Self { inner }
|
||||||
|
}
|
||||||
|
pub fn with_origin(inner: T, origin: Uri) -> Self {
|
||||||
|
let inner = tonic::client::Grpc::with_origin(inner, origin);
|
||||||
|
Self { inner }
|
||||||
|
}
|
||||||
|
pub fn with_interceptor<F>(
|
||||||
|
inner: T,
|
||||||
|
interceptor: F,
|
||||||
|
) -> Search2Client<InterceptedService<T, F>>
|
||||||
|
where
|
||||||
|
F: tonic::service::Interceptor,
|
||||||
|
T::ResponseBody: Default,
|
||||||
|
T: tonic::codegen::Service<
|
||||||
|
http::Request<tonic::body::Body>,
|
||||||
|
Response = http::Response<
|
||||||
|
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
|
<T as tonic::codegen::Service<
|
||||||
|
http::Request<tonic::body::Body>,
|
||||||
|
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
|
||||||
|
{
|
||||||
|
Search2Client::new(InterceptedService::new(inner, interceptor))
|
||||||
|
}
|
||||||
|
/// Compress requests with the given encoding.
|
||||||
|
///
|
||||||
|
/// This requires the server to support it otherwise it might respond with an
|
||||||
|
/// error.
|
||||||
|
#[must_use]
|
||||||
|
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||||
|
self.inner = self.inner.send_compressed(encoding);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Enable decompressing responses.
|
||||||
|
#[must_use]
|
||||||
|
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||||
|
self.inner = self.inner.accept_compressed(encoding);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Limits the maximum size of a decoded message.
|
||||||
|
///
|
||||||
|
/// Default: `4MB`
|
||||||
|
#[must_use]
|
||||||
|
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
|
||||||
|
self.inner = self.inner.max_decoding_message_size(limit);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Limits the maximum size of an encoded message.
|
||||||
|
///
|
||||||
|
/// Default: `usize::MAX`
|
||||||
|
#[must_use]
|
||||||
|
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
|
||||||
|
self.inner = self.inner.max_encoding_message_size(limit);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
pub async fn search_table(
|
||||||
|
&mut self,
|
||||||
|
request: impl tonic::IntoRequest<super::Search2Request>,
|
||||||
|
) -> std::result::Result<
|
||||||
|
tonic::Response<super::Search2Response>,
|
||||||
|
tonic::Status,
|
||||||
|
> {
|
||||||
|
self.inner
|
||||||
|
.ready()
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
tonic::Status::unknown(
|
||||||
|
format!("Service was not ready: {}", e.into()),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
|
"/komp_ac.search2.Search2/SearchTable",
|
||||||
|
);
|
||||||
|
let mut req = request.into_request();
|
||||||
|
req.extensions_mut()
|
||||||
|
.insert(GrpcMethod::new("komp_ac.search2.Search2", "SearchTable"));
|
||||||
|
self.inner.unary(req, path, codec).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Generated server implementations.
|
||||||
|
pub mod search2_server {
|
||||||
|
#![allow(
|
||||||
|
unused_variables,
|
||||||
|
dead_code,
|
||||||
|
missing_docs,
|
||||||
|
clippy::wildcard_imports,
|
||||||
|
clippy::let_unit_value,
|
||||||
|
)]
|
||||||
|
use tonic::codegen::*;
|
||||||
|
/// Generated trait containing gRPC methods that should be implemented for use with Search2Server.
|
||||||
|
#[async_trait]
|
||||||
|
pub trait Search2: std::marker::Send + std::marker::Sync + 'static {
|
||||||
|
async fn search_table(
|
||||||
|
&self,
|
||||||
|
request: tonic::Request<super::Search2Request>,
|
||||||
|
) -> std::result::Result<tonic::Response<super::Search2Response>, tonic::Status>;
|
||||||
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Search2Server<T> {
|
||||||
|
inner: Arc<T>,
|
||||||
|
accept_compression_encodings: EnabledCompressionEncodings,
|
||||||
|
send_compression_encodings: EnabledCompressionEncodings,
|
||||||
|
max_decoding_message_size: Option<usize>,
|
||||||
|
max_encoding_message_size: Option<usize>,
|
||||||
|
}
|
||||||
|
impl<T> Search2Server<T> {
|
||||||
|
pub fn new(inner: T) -> Self {
|
||||||
|
Self::from_arc(Arc::new(inner))
|
||||||
|
}
|
||||||
|
pub fn from_arc(inner: Arc<T>) -> Self {
|
||||||
|
Self {
|
||||||
|
inner,
|
||||||
|
accept_compression_encodings: Default::default(),
|
||||||
|
send_compression_encodings: Default::default(),
|
||||||
|
max_decoding_message_size: None,
|
||||||
|
max_encoding_message_size: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn with_interceptor<F>(
|
||||||
|
inner: T,
|
||||||
|
interceptor: F,
|
||||||
|
) -> InterceptedService<Self, F>
|
||||||
|
where
|
||||||
|
F: tonic::service::Interceptor,
|
||||||
|
{
|
||||||
|
InterceptedService::new(Self::new(inner), interceptor)
|
||||||
|
}
|
||||||
|
/// Enable decompressing requests with the given encoding.
|
||||||
|
#[must_use]
|
||||||
|
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||||
|
self.accept_compression_encodings.enable(encoding);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Compress responses with the given encoding, if the client supports it.
|
||||||
|
#[must_use]
|
||||||
|
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
|
||||||
|
self.send_compression_encodings.enable(encoding);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Limits the maximum size of a decoded message.
|
||||||
|
///
|
||||||
|
/// Default: `4MB`
|
||||||
|
#[must_use]
|
||||||
|
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
|
||||||
|
self.max_decoding_message_size = Some(limit);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
/// Limits the maximum size of an encoded message.
|
||||||
|
///
|
||||||
|
/// Default: `usize::MAX`
|
||||||
|
#[must_use]
|
||||||
|
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
|
||||||
|
self.max_encoding_message_size = Some(limit);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T, B> tonic::codegen::Service<http::Request<B>> for Search2Server<T>
|
||||||
|
where
|
||||||
|
T: Search2,
|
||||||
|
B: Body + std::marker::Send + 'static,
|
||||||
|
B::Error: Into<StdError> + std::marker::Send + 'static,
|
||||||
|
{
|
||||||
|
type Response = http::Response<tonic::body::Body>;
|
||||||
|
type Error = std::convert::Infallible;
|
||||||
|
type Future = BoxFuture<Self::Response, Self::Error>;
|
||||||
|
fn poll_ready(
|
||||||
|
&mut self,
|
||||||
|
_cx: &mut Context<'_>,
|
||||||
|
) -> Poll<std::result::Result<(), Self::Error>> {
|
||||||
|
Poll::Ready(Ok(()))
|
||||||
|
}
|
||||||
|
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
||||||
|
match req.uri().path() {
|
||||||
|
"/komp_ac.search2.Search2/SearchTable" => {
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
struct SearchTableSvc<T: Search2>(pub Arc<T>);
|
||||||
|
impl<T: Search2> tonic::server::UnaryService<super::Search2Request>
|
||||||
|
for SearchTableSvc<T> {
|
||||||
|
type Response = super::Search2Response;
|
||||||
|
type Future = BoxFuture<
|
||||||
|
tonic::Response<Self::Response>,
|
||||||
|
tonic::Status,
|
||||||
|
>;
|
||||||
|
fn call(
|
||||||
|
&mut self,
|
||||||
|
request: tonic::Request<super::Search2Request>,
|
||||||
|
) -> Self::Future {
|
||||||
|
let inner = Arc::clone(&self.0);
|
||||||
|
let fut = async move {
|
||||||
|
<T as Search2>::search_table(&inner, request).await
|
||||||
|
};
|
||||||
|
Box::pin(fut)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let accept_compression_encodings = self.accept_compression_encodings;
|
||||||
|
let send_compression_encodings = self.send_compression_encodings;
|
||||||
|
let max_decoding_message_size = self.max_decoding_message_size;
|
||||||
|
let max_encoding_message_size = self.max_encoding_message_size;
|
||||||
|
let inner = self.inner.clone();
|
||||||
|
let fut = async move {
|
||||||
|
let method = SearchTableSvc(inner);
|
||||||
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
|
let mut grpc = tonic::server::Grpc::new(codec)
|
||||||
|
.apply_compression_config(
|
||||||
|
accept_compression_encodings,
|
||||||
|
send_compression_encodings,
|
||||||
|
)
|
||||||
|
.apply_max_message_size_config(
|
||||||
|
max_decoding_message_size,
|
||||||
|
max_encoding_message_size,
|
||||||
|
);
|
||||||
|
let res = grpc.unary(method, req).await;
|
||||||
|
Ok(res)
|
||||||
|
};
|
||||||
|
Box::pin(fut)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
Box::pin(async move {
|
||||||
|
let mut response = http::Response::new(
|
||||||
|
tonic::body::Body::default(),
|
||||||
|
);
|
||||||
|
let headers = response.headers_mut();
|
||||||
|
headers
|
||||||
|
.insert(
|
||||||
|
tonic::Status::GRPC_STATUS,
|
||||||
|
(tonic::Code::Unimplemented as i32).into(),
|
||||||
|
);
|
||||||
|
headers
|
||||||
|
.insert(
|
||||||
|
http::header::CONTENT_TYPE,
|
||||||
|
tonic::metadata::GRPC_CONTENT_TYPE,
|
||||||
|
);
|
||||||
|
Ok(response)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T> Clone for Search2Server<T> {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
let inner = self.inner.clone();
|
||||||
|
Self {
|
||||||
|
inner,
|
||||||
|
accept_compression_encodings: self.accept_compression_encodings,
|
||||||
|
send_compression_encodings: self.send_compression_encodings,
|
||||||
|
max_decoding_message_size: self.max_decoding_message_size,
|
||||||
|
max_encoding_message_size: self.max_encoding_message_size,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Generated gRPC service name
|
||||||
|
pub const SERVICE_NAME: &str = "komp_ac.search2.Search2";
|
||||||
|
impl<T> tonic::server::NamedService for Search2Server<T> {
|
||||||
|
const NAME: &'static str = SERVICE_NAME;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
// This file is @generated by prost-build.
|
// This file is @generated by prost-build.
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct TableLink {
|
pub struct TableLink {
|
||||||
#[prost(string, tag = "1")]
|
#[prost(string, tag = "1")]
|
||||||
@@ -6,6 +7,7 @@ pub struct TableLink {
|
|||||||
#[prost(bool, tag = "2")]
|
#[prost(bool, tag = "2")]
|
||||||
pub required: bool,
|
pub required: bool,
|
||||||
}
|
}
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct PostTableDefinitionRequest {
|
pub struct PostTableDefinitionRequest {
|
||||||
#[prost(string, tag = "1")]
|
#[prost(string, tag = "1")]
|
||||||
@@ -18,9 +20,8 @@ pub struct PostTableDefinitionRequest {
|
|||||||
pub indexes: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
|
pub indexes: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
|
||||||
#[prost(string, tag = "5")]
|
#[prost(string, tag = "5")]
|
||||||
pub profile_name: ::prost::alloc::string::String,
|
pub profile_name: ::prost::alloc::string::String,
|
||||||
#[prost(string, optional, tag = "6")]
|
|
||||||
pub linked_table_name: ::core::option::Option<::prost::alloc::string::String>,
|
|
||||||
}
|
}
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct ColumnDefinition {
|
pub struct ColumnDefinition {
|
||||||
#[prost(string, tag = "1")]
|
#[prost(string, tag = "1")]
|
||||||
@@ -28,6 +29,7 @@ pub struct ColumnDefinition {
|
|||||||
#[prost(string, tag = "2")]
|
#[prost(string, tag = "2")]
|
||||||
pub field_type: ::prost::alloc::string::String,
|
pub field_type: ::prost::alloc::string::String,
|
||||||
}
|
}
|
||||||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct TableDefinitionResponse {
|
pub struct TableDefinitionResponse {
|
||||||
#[prost(bool, tag = "1")]
|
#[prost(bool, tag = "1")]
|
||||||
@@ -44,9 +46,11 @@ pub struct ProfileTreeResponse {
|
|||||||
pub mod profile_tree_response {
|
pub mod profile_tree_response {
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
pub struct Table {
|
pub struct Table {
|
||||||
#[prost(string, tag = "1")]
|
#[prost(int64, tag = "1")]
|
||||||
|
pub id: i64,
|
||||||
|
#[prost(string, tag = "2")]
|
||||||
pub name: ::prost::alloc::string::String,
|
pub name: ::prost::alloc::string::String,
|
||||||
#[prost(string, repeated, tag = "2")]
|
#[prost(string, repeated, tag = "3")]
|
||||||
pub depends_on: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
|
pub depends_on: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
|
||||||
}
|
}
|
||||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||||
@@ -99,7 +103,7 @@ pub mod table_definition_client {
|
|||||||
}
|
}
|
||||||
impl<T> TableDefinitionClient<T>
|
impl<T> TableDefinitionClient<T>
|
||||||
where
|
where
|
||||||
T: tonic::client::GrpcService<tonic::body::BoxBody>,
|
T: tonic::client::GrpcService<tonic::body::Body>,
|
||||||
T::Error: Into<StdError>,
|
T::Error: Into<StdError>,
|
||||||
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
|
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
|
||||||
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
|
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
|
||||||
@@ -120,13 +124,13 @@ pub mod table_definition_client {
|
|||||||
F: tonic::service::Interceptor,
|
F: tonic::service::Interceptor,
|
||||||
T::ResponseBody: Default,
|
T::ResponseBody: Default,
|
||||||
T: tonic::codegen::Service<
|
T: tonic::codegen::Service<
|
||||||
http::Request<tonic::body::BoxBody>,
|
http::Request<tonic::body::Body>,
|
||||||
Response = http::Response<
|
Response = http::Response<
|
||||||
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
|
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
<T as tonic::codegen::Service<
|
<T as tonic::codegen::Service<
|
||||||
http::Request<tonic::body::BoxBody>,
|
http::Request<tonic::body::Body>,
|
||||||
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
|
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
|
||||||
{
|
{
|
||||||
TableDefinitionClient::new(InterceptedService::new(inner, interceptor))
|
TableDefinitionClient::new(InterceptedService::new(inner, interceptor))
|
||||||
@@ -179,13 +183,13 @@ pub mod table_definition_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.table_definition.TableDefinition/PostTableDefinition",
|
"/komp_ac.table_definition.TableDefinition/PostTableDefinition",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(
|
.insert(
|
||||||
GrpcMethod::new(
|
GrpcMethod::new(
|
||||||
"multieko2.table_definition.TableDefinition",
|
"komp_ac.table_definition.TableDefinition",
|
||||||
"PostTableDefinition",
|
"PostTableDefinition",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -208,13 +212,13 @@ pub mod table_definition_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.table_definition.TableDefinition/GetProfileTree",
|
"/komp_ac.table_definition.TableDefinition/GetProfileTree",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(
|
.insert(
|
||||||
GrpcMethod::new(
|
GrpcMethod::new(
|
||||||
"multieko2.table_definition.TableDefinition",
|
"komp_ac.table_definition.TableDefinition",
|
||||||
"GetProfileTree",
|
"GetProfileTree",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -237,13 +241,13 @@ pub mod table_definition_client {
|
|||||||
})?;
|
})?;
|
||||||
let codec = tonic::codec::ProstCodec::default();
|
let codec = tonic::codec::ProstCodec::default();
|
||||||
let path = http::uri::PathAndQuery::from_static(
|
let path = http::uri::PathAndQuery::from_static(
|
||||||
"/multieko2.table_definition.TableDefinition/DeleteTable",
|
"/komp_ac.table_definition.TableDefinition/DeleteTable",
|
||||||
);
|
);
|
||||||
let mut req = request.into_request();
|
let mut req = request.into_request();
|
||||||
req.extensions_mut()
|
req.extensions_mut()
|
||||||
.insert(
|
.insert(
|
||||||
GrpcMethod::new(
|
GrpcMethod::new(
|
||||||
"multieko2.table_definition.TableDefinition",
|
"komp_ac.table_definition.TableDefinition",
|
||||||
"DeleteTable",
|
"DeleteTable",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -351,7 +355,7 @@ pub mod table_definition_server {
|
|||||||
B: Body + std::marker::Send + 'static,
|
B: Body + std::marker::Send + 'static,
|
||||||
B::Error: Into<StdError> + std::marker::Send + 'static,
|
B::Error: Into<StdError> + std::marker::Send + 'static,
|
||||||
{
|
{
|
||||||
type Response = http::Response<tonic::body::BoxBody>;
|
type Response = http::Response<tonic::body::Body>;
|
||||||
type Error = std::convert::Infallible;
|
type Error = std::convert::Infallible;
|
||||||
type Future = BoxFuture<Self::Response, Self::Error>;
|
type Future = BoxFuture<Self::Response, Self::Error>;
|
||||||
fn poll_ready(
|
fn poll_ready(
|
||||||
@@ -362,7 +366,7 @@ pub mod table_definition_server {
|
|||||||
}
|
}
|
||||||
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
fn call(&mut self, req: http::Request<B>) -> Self::Future {
|
||||||
match req.uri().path() {
|
match req.uri().path() {
|
||||||
"/multieko2.table_definition.TableDefinition/PostTableDefinition" => {
|
"/komp_ac.table_definition.TableDefinition/PostTableDefinition" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct PostTableDefinitionSvc<T: TableDefinition>(pub Arc<T>);
|
struct PostTableDefinitionSvc<T: TableDefinition>(pub Arc<T>);
|
||||||
impl<
|
impl<
|
||||||
@@ -411,7 +415,7 @@ pub mod table_definition_server {
|
|||||||
};
|
};
|
||||||
Box::pin(fut)
|
Box::pin(fut)
|
||||||
}
|
}
|
||||||
"/multieko2.table_definition.TableDefinition/GetProfileTree" => {
|
"/komp_ac.table_definition.TableDefinition/GetProfileTree" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct GetProfileTreeSvc<T: TableDefinition>(pub Arc<T>);
|
struct GetProfileTreeSvc<T: TableDefinition>(pub Arc<T>);
|
||||||
impl<
|
impl<
|
||||||
@@ -457,7 +461,7 @@ pub mod table_definition_server {
|
|||||||
};
|
};
|
||||||
Box::pin(fut)
|
Box::pin(fut)
|
||||||
}
|
}
|
||||||
"/multieko2.table_definition.TableDefinition/DeleteTable" => {
|
"/komp_ac.table_definition.TableDefinition/DeleteTable" => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
struct DeleteTableSvc<T: TableDefinition>(pub Arc<T>);
|
struct DeleteTableSvc<T: TableDefinition>(pub Arc<T>);
|
||||||
impl<
|
impl<
|
||||||
@@ -504,7 +508,9 @@ pub mod table_definition_server {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let mut response = http::Response::new(empty_body());
|
let mut response = http::Response::new(
|
||||||
|
tonic::body::Body::default(),
|
||||||
|
);
|
||||||
let headers = response.headers_mut();
|
let headers = response.headers_mut();
|
||||||
headers
|
headers
|
||||||
.insert(
|
.insert(
|
||||||
@@ -535,7 +541,7 @@ pub mod table_definition_server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Generated gRPC service name
|
/// Generated gRPC service name
|
||||||
pub const SERVICE_NAME: &str = "multieko2.table_definition.TableDefinition";
|
pub const SERVICE_NAME: &str = "komp_ac.table_definition.TableDefinition";
|
||||||
impl<T> tonic::server::NamedService for TableDefinitionServer<T> {
|
impl<T> tonic::server::NamedService for TableDefinitionServer<T> {
|
||||||
const NAME: &'static str = SERVICE_NAME;
|
const NAME: &'static str = SERVICE_NAME;
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user