Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +7 -1
- VERSION +1 -1
- api/routes_customers.py +347 -21
- web/src/customer-grid/CustomerGrid.tsx +64 -3
- web/src/customer-grid/MapView.tsx +391 -117
- web/src/customer-grid/apiBridge.ts +63 -1
- web/src/customer-grid/mapProjection.ts +91 -3
- web/src/index.css +67 -17
RELEASES.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
{
|
| 5 |
"version": "v46",
|
| 6 |
"sha": "a8dc531",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "v47 (917f9a0)",
|
| 3 |
"releases": [
|
| 4 |
+
{
|
| 5 |
+
"version": "v47",
|
| 6 |
+
"sha": "917f9a0",
|
| 7 |
+
"date": "2026-08-23",
|
| 8 |
+
"subject": "release v47"
|
| 9 |
+
},
|
| 10 |
{
|
| 11 |
"version": "v46",
|
| 12 |
"sha": "a8dc531",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
v47 (917f9a0)
|
api/routes_customers.py
CHANGED
|
@@ -502,6 +502,154 @@ def customers(session: Session = Depends(module_gate(MODULE))):
|
|
| 502 |
return _payload(session)
|
| 503 |
|
| 504 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
@router.patch("/customers/{pid}")
|
| 506 |
def patch_customer(pid: int, body: dict = Body(default=None),
|
| 507 |
session: Session = Depends(module_gate(MODULE))):
|
|
@@ -529,13 +677,41 @@ def patch_customer(pid: int, body: dict = Body(default=None),
|
|
| 529 |
admin=session.admin, fallback_ws=None, seen_ids={},
|
| 530 |
hidden_keys=_hidden_for(session), table=_customer_table(session),
|
| 531 |
st=session.runtime)
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
|
| 540 |
# What actually landed, read back from the store rather than echoed from the request: a
|
| 541 |
# refused key or a truncated value must not be reported as accepted.
|
|
@@ -549,9 +725,19 @@ def patch_customer(pid: int, body: dict = Body(default=None),
|
|
| 549 |
# payload was cached on a scope key β the arrangement that leaked one user's notes to
|
| 550 |
# another. See `_pool_rows`.) Cross-RUNTIME coherence is still not claimed: the module
|
| 551 |
# docstring says why, and Postgres is the fix.
|
| 552 |
-
out = {"ok": True, "pid": pid, "updates": accepted}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
if refused:
|
| 554 |
-
out["refused"] = refused
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
return out
|
| 556 |
|
| 557 |
|
|
@@ -613,8 +799,8 @@ def _route_slug(label):
|
|
| 613 |
return f"{ROUTE_KEY_PREFIX}{slug[:48]}" if slug else ""
|
| 614 |
|
| 615 |
|
| 616 |
-
def
|
| 617 |
-
"""
|
| 618 |
occupied_keys = {str(key) for key in (defs or {})}
|
| 619 |
occupied_labels = set()
|
| 620 |
for field in list((defs or {}).values()) + list(base_fields or ()):
|
|
@@ -626,9 +812,32 @@ def _next_destination_label(defs, base_fields=()):
|
|
| 626 |
key = str(field.get("key") or "").strip()
|
| 627 |
if key:
|
| 628 |
occupied_keys.add(key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 629 |
n = 1
|
| 630 |
while True:
|
| 631 |
-
label = f"
|
| 632 |
if label.casefold() not in occupied_labels and _route_slug(label) not in occupied_keys:
|
| 633 |
return label
|
| 634 |
n += 1
|
|
@@ -702,7 +911,20 @@ def route_order_list(session: Session = Depends(module_gate(MODULE))):
|
|
| 702 |
"mine": bool(session.admin
|
| 703 |
or str(defn.get("createdBy") or "") == session.uname),
|
| 704 |
})
|
| 705 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
|
| 707 |
|
| 708 |
@router.post("/customers/route-order")
|
|
@@ -740,7 +962,7 @@ def route_order_write(body: dict = Body(default=None),
|
|
| 740 |
elif label:
|
| 741 |
key = _route_slug(label)
|
| 742 |
else:
|
| 743 |
-
label =
|
| 744 |
key = _route_slug(label)
|
| 745 |
if not key:
|
| 746 |
raise err(400, "bad_request", "a name is required for the route order column")
|
|
@@ -845,11 +1067,23 @@ def route_order_write(body: dict = Body(default=None),
|
|
| 845 |
defn = {
|
| 846 |
"key": key,
|
| 847 |
"label": label or (existing or {}).get("label") or key,
|
| 848 |
-
#
|
| 849 |
-
#
|
| 850 |
-
#
|
| 851 |
-
|
| 852 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 853 |
"source": "overlay",
|
| 854 |
"shared": True,
|
| 855 |
"kind": ROUTE_KIND,
|
|
@@ -906,8 +1140,7 @@ def route_order_write(body: dict = Body(default=None),
|
|
| 906 |
_shared_key(), {**{p: {key: str(v)} for p, v in ranks.items()}, **stale},
|
| 907 |
st=session.runtime)
|
| 908 |
|
| 909 |
-
out = {"ok": True, "field": key, "label": defn["label"], "type": "
|
| 910 |
-
"options": defn["options"],
|
| 911 |
"stops": len(ranks), "cleared": len(stale),
|
| 912 |
"rows_written": len(written), "inputsHash": defn["route"]["inputsHash"],
|
| 913 |
"depot": defn["route"]["depot"],
|
|
@@ -980,3 +1213,96 @@ def route_order_delete(field_key: str,
|
|
| 980 |
except Exception: # noqa: BLE001
|
| 981 |
pass
|
| 982 |
return {"ok": True, "field": key, "dropped": bool(dropped)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
return _payload(session)
|
| 503 |
|
| 504 |
|
| 505 |
+
def _split_route_updates(session, updates):
|
| 506 |
+
"""Split a cell PATCH into `(route order updates, everything else)`.
|
| 507 |
+
|
| 508 |
+
β MATCHED ON THE DECLARED `kind`, NEVER ON THE `route_` PREFIX β the rule `route_order_delete`
|
| 509 |
+
and the column menu both state. A prefix is a naming convention; the kind is a declaration.
|
| 510 |
+
"""
|
| 511 |
+
defs = shared_fields(st=session.runtime) or {}
|
| 512 |
+
route, rest = {}, {}
|
| 513 |
+
for key, value in (updates or {}).items():
|
| 514 |
+
defn = defs.get(key)
|
| 515 |
+
if isinstance(defn, dict) and defn.get("kind") == ROUTE_KIND:
|
| 516 |
+
route[key] = value
|
| 517 |
+
else:
|
| 518 |
+
rest[key] = value
|
| 519 |
+
return route, rest
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
def _patch_route_ranks(session, ctx, pid, pool, updates):
|
| 523 |
+
"""Write visit numbers into the SHARED stratum, keeping the column a permutation.
|
| 524 |
+
|
| 525 |
+
ββ OWNER ITEM 7 (2026-08-23) β THE AUTO-DEDUPE, IN THE OWNER'S OWN WORDS: *"when you edit a
|
| 526 |
+
number from say 13 to 14, what ever was record 14 should automatically change to 13 so its
|
| 527 |
+
auto dedupe that way."* That is a TRANSPOSITION, and it is the whole rule: the number you
|
| 528 |
+
typed goes on your record, and the number you displaced goes to whoever was holding it. Two
|
| 529 |
+
rows move, the set of numbers in the column is unchanged, and no other record is renumbered.
|
| 530 |
+
|
| 531 |
+
Three cases, and each one is the same rule read honestly:
|
| 532 |
+
|
| 533 |
+
Β· the target number is FREE -> plain assignment. A gap is not a duplicate, and the owner's
|
| 534 |
+
rule is about duplicates.
|
| 535 |
+
Β· the target is HELD and this record already had a number -> the two swap. The named case.
|
| 536 |
+
Β· the target is HELD and this record had NO number (it was not on the route) -> there is no
|
| 537 |
+
old number to hand over, so the displaced record goes to the end (`max + 1`). Still one
|
| 538 |
+
other row moved, still no duplicate, and nothing loses its place on the route silently.
|
| 539 |
+
|
| 540 |
+
Blanking a cell takes the record OFF the route and frees its number. It renumbers nothing:
|
| 541 |
+
re-solving is what closes the gaps, and doing it here would silently rewrite a day somebody
|
| 542 |
+
is driving.
|
| 543 |
+
|
| 544 |
+
ββ THE WALLS ARE `grid_events`' OWN, CALLED AND NOT COPIED, AND THAT IS THE PRICE OF
|
| 545 |
+
STEPPING OUT OF `overlay_patch`. `_may_edit_field_value` is where the shared-field Share role,
|
| 546 |
+
the creator rule and the admin rule already meet; the hidden-key wall is applied first for the
|
| 547 |
+
reason `overlay_patch` applies it, namely that `hidden_keys` decides what this caller may READ
|
| 548 |
+
and a column they cannot read is not one they may write by naming its key. A second spelling
|
| 549 |
+
of either here would be a second one to keep in step β which is the whole reason
|
| 550 |
+
`patch_customer` routes everything else through `grid_events` rather than writing the store.
|
| 551 |
+
|
| 552 |
+
β UNIQUENESS IS MAINTAINED OVER THE ROWS THIS CALLER CAN SEE, and that is a limit worth
|
| 553 |
+
stating rather than hiding. `shared_overlay.cells` takes the scoped pool BY SIGNATURE (there is
|
| 554 |
+
deliberately no "every shared cell in the tenant" call), so the holder of a displaced number is
|
| 555 |
+
looked for inside this session's book. In practice the whole column lives there anyway --
|
| 556 |
+
`route_order_write` REFUSES a body carrying a pid outside the writer's pool, so every number in
|
| 557 |
+
a route order was written by somebody whose book contained all of them.
|
| 558 |
+
"""
|
| 559 |
+
from core import grid_events, shared_overlay
|
| 560 |
+
|
| 561 |
+
defs = shared_fields(st=session.runtime) or {}
|
| 562 |
+
hidden = _hidden_for(session)
|
| 563 |
+
#: `{key: what the store holds for THIS record now}`, for every key asked about β refused ones
|
| 564 |
+
#: included. See the `_stored` note below.
|
| 565 |
+
accepted = {}
|
| 566 |
+
#: The keys that actually moved. `patch_customer` reports everything else as REFUSED, so this
|
| 567 |
+
#: has to be separate from `accepted`: a refused key still reports a value, and it is the
|
| 568 |
+
#: value the caller did NOT ask for.
|
| 569 |
+
taken, swaps = set(), []
|
| 570 |
+
|
| 571 |
+
def _held():
|
| 572 |
+
"""`{pid: rank}` for this column, over the rows this caller can see.
|
| 573 |
+
|
| 574 |
+
Re-read per key rather than hoisted, because a multi-key patch writes between iterations
|
| 575 |
+
and the second key must see the first one's result.
|
| 576 |
+
"""
|
| 577 |
+
out = {}
|
| 578 |
+
for raw_pid, cells in (shared_cells(pool, st=session.runtime) or {}).items():
|
| 579 |
+
if not isinstance(cells, dict):
|
| 580 |
+
continue
|
| 581 |
+
cell = cells.get(key)
|
| 582 |
+
if cell in (None, ""):
|
| 583 |
+
continue
|
| 584 |
+
try:
|
| 585 |
+
out[int(raw_pid)] = int(str(cell).strip())
|
| 586 |
+
except (TypeError, ValueError):
|
| 587 |
+
continue
|
| 588 |
+
return out
|
| 589 |
+
|
| 590 |
+
for key, raw in updates.items():
|
| 591 |
+
defn = defs.get(key) or {}
|
| 592 |
+
held = _held()
|
| 593 |
+
|
| 594 |
+
def _stored():
|
| 595 |
+
"""ββ A REFUSAL REPORTS WHAT THE CELL ACTUALLY HOLDS, AND THAT IS NOT TIDINESS.
|
| 596 |
+
|
| 597 |
+
`patchTopicRow` adopts `body.updates` into the browser's optimistic copy and rolls
|
| 598 |
+
back only on a non-2xx. A refused key that is simply ABSENT from `updates` is a key
|
| 599 |
+
the client never hears about: the response is 200, the rollback never fires, `adopt`
|
| 600 |
+
has nothing to write, and the typed text goes on painting a value the store rejected
|
| 601 |
+
until something unrelated forces a refetch. On a `select` the option normaliser made
|
| 602 |
+
this unreachable; item 7 made the column an `int`, so `14.5` or a stray letter is now
|
| 603 |
+
an ordinary typo away. `patchTopicRow`'s own docstring already states the rule β
|
| 604 |
+
keep only what the server actually took β and this is that rule with its hole closed.
|
| 605 |
+
"""
|
| 606 |
+
n = held.get(pid)
|
| 607 |
+
return "" if n is None else str(n)
|
| 608 |
+
|
| 609 |
+
if key in hidden:
|
| 610 |
+
accepted[key] = _stored()
|
| 611 |
+
continue
|
| 612 |
+
if not grid_events._may_edit_field_value(ctx, key, defn):
|
| 613 |
+
accepted[key] = _stored()
|
| 614 |
+
continue
|
| 615 |
+
# An empty cell is "not on this route". Legal, and the only way to take a stop off the
|
| 616 |
+
# day without re-solving the whole column.
|
| 617 |
+
if raw is None or (isinstance(raw, str) and not raw.strip()):
|
| 618 |
+
shared_overlay.put_rows(_shared_key(), {pid: {key: ""}}, st=session.runtime)
|
| 619 |
+
accepted[key] = ""
|
| 620 |
+
taken.add(key)
|
| 621 |
+
continue
|
| 622 |
+
# β A BOOL IS AN `int` IN PYTHON, so `True` would store as visit number 1. Excluded by
|
| 623 |
+
# name here exactly as `route_order_write` excludes it, rather than by hoping.
|
| 624 |
+
if isinstance(raw, bool):
|
| 625 |
+
accepted[key] = _stored()
|
| 626 |
+
continue
|
| 627 |
+
try:
|
| 628 |
+
want = int(str(raw).strip())
|
| 629 |
+
except (TypeError, ValueError):
|
| 630 |
+
accepted[key] = _stored()
|
| 631 |
+
continue
|
| 632 |
+
if want < 1:
|
| 633 |
+
accepted[key] = _stored()
|
| 634 |
+
continue
|
| 635 |
+
|
| 636 |
+
prior = held.get(pid)
|
| 637 |
+
if prior == want:
|
| 638 |
+
accepted[key] = str(want)
|
| 639 |
+
taken.add(key)
|
| 640 |
+
continue
|
| 641 |
+
writes = {pid: {key: str(want)}}
|
| 642 |
+
holder = next((p for p, n in held.items() if n == want and p != pid), None)
|
| 643 |
+
if holder is not None:
|
| 644 |
+
moved = prior if prior is not None else max(held.values()) + 1
|
| 645 |
+
writes[holder] = {key: str(moved)}
|
| 646 |
+
swaps.append({"pid": holder, "field": key, "value": str(moved)})
|
| 647 |
+
shared_overlay.put_rows(_shared_key(), writes, st=session.runtime)
|
| 648 |
+
accepted[key] = str(want)
|
| 649 |
+
taken.add(key)
|
| 650 |
+
return accepted, swaps, taken
|
| 651 |
+
|
| 652 |
+
|
| 653 |
@router.patch("/customers/{pid}")
|
| 654 |
def patch_customer(pid: int, body: dict = Body(default=None),
|
| 655 |
session: Session = Depends(module_gate(MODULE))):
|
|
|
|
| 677 |
admin=session.admin, fallback_ws=None, seen_ids={},
|
| 678 |
hidden_keys=_hidden_for(session), table=_customer_table(session),
|
| 679 |
st=session.runtime)
|
| 680 |
+
|
| 681 |
+
# ββ OWNER ITEM 7 (2026-08-23) β A ROUTE RANK IS EDITED HERE, NOT THROUGH `overlay_patch`.
|
| 682 |
+
#
|
| 683 |
+
# β AND **NOT** BECAUSE THE ORDINARY PATH WRITES THE WRONG STRATUM. It does not:
|
| 684 |
+
# `table_store.patch_overlay` has split tenant-wide keys off to `shared_overlay` since W38-T20
|
| 685 |
+
# (D-423), so a route cell already lands where every reader looks. What the ordinary path
|
| 686 |
+
# cannot do is the half the owner actually asked for β *"make sure that none of the number can
|
| 687 |
+
# be a duplicate ... when you edit a number from say 13 to 14, what ever was record 14 should
|
| 688 |
+
# automatically change to 13"*. That is a write to a SECOND record, decided by the first one's
|
| 689 |
+
# OLD value, and nothing in `overlay_patch` has a reason to look at either.
|
| 690 |
+
#
|
| 691 |
+
# β IT ALSO OWNS THE VALIDATION, because item 7 changed the column's type. As a `select` the
|
| 692 |
+
# declared choices refused anything that was not a rank; as an `int` `overlay_patch` stores
|
| 693 |
+
# whatever string it is handed, and "third" in a visit-order column is not a slightly wrong
|
| 694 |
+
# value β it is a stop with no place in the sequence.
|
| 695 |
+
#
|
| 696 |
+
# β INTERCEPTED SERVER-SIDE, NEVER IN THE CLIENT. Every path that can change a cell β typing,
|
| 697 |
+
# paste, fill, undo, the record drawer β comes through this one door; a client-side branch
|
| 698 |
+
# would have to be repeated at each of them and would be wrong at the first one nobody
|
| 699 |
+
# remembered.
|
| 700 |
+
route_updates, updates = _split_route_updates(session, updates)
|
| 701 |
+
|
| 702 |
+
if updates:
|
| 703 |
+
try:
|
| 704 |
+
grid_events.handle_one(
|
| 705 |
+
{"id": f"patch:{pid}:{time.time_ns()}", "type": "overlay_patch",
|
| 706 |
+
"pid": pid, "updates": updates}, ctx)
|
| 707 |
+
except grid_events.StoreUnavailable:
|
| 708 |
+
raise err(503, "store_unavailable",
|
| 709 |
+
"the tenant store is unavailable β your change was not saved")
|
| 710 |
+
|
| 711 |
+
route_accepted, route_swaps, route_taken = ({}, [], set())
|
| 712 |
+
if route_updates:
|
| 713 |
+
route_accepted, route_swaps, route_taken = _patch_route_ranks(
|
| 714 |
+
session, ctx, pid, pool, route_updates)
|
| 715 |
|
| 716 |
# What actually landed, read back from the store rather than echoed from the request: a
|
| 717 |
# refused key or a truncated value must not be reported as accepted.
|
|
|
|
| 725 |
# payload was cached on a scope key β the arrangement that leaked one user's notes to
|
| 726 |
# another. See `_pool_rows`.) Cross-RUNTIME coherence is still not claimed: the module
|
| 727 |
# docstring says why, and Postgres is the fix.
|
| 728 |
+
out = {"ok": True, "pid": pid, "updates": {**accepted, **route_accepted}}
|
| 729 |
+
# β `route_taken` AND NOT `route_accepted`. A refused rank still reports a value β the one
|
| 730 |
+
# the store holds β so membership of `updates` no longer means the write landed.
|
| 731 |
+
refused = [k for k in refused if k not in route_updates]
|
| 732 |
+
refused += [k for k in route_updates if k not in route_taken]
|
| 733 |
if refused:
|
| 734 |
+
out["refused"] = sorted(refused)
|
| 735 |
+
# β THE SWAP CHANGED A ROW THE CLIENT NEVER TYPED IN, so it has to be told. The optimistic
|
| 736 |
+
# copy in the browser covers `pid` only; the record that gave up the number it held would go
|
| 737 |
+
# on painting the old one until something else forced a refetch. `patchTopicRow` reads this
|
| 738 |
+
# key and drops the rows cache.
|
| 739 |
+
if route_swaps:
|
| 740 |
+
out["routeSwaps"] = route_swaps
|
| 741 |
return out
|
| 742 |
|
| 743 |
|
|
|
|
| 799 |
return f"{ROUTE_KEY_PREFIX}{slug[:48]}" if slug else ""
|
| 800 |
|
| 801 |
|
| 802 |
+
def _occupied(defs, base_fields=()):
|
| 803 |
+
"""The keys and case-folded labels a new route column must not land on."""
|
| 804 |
occupied_keys = {str(key) for key in (defs or {})}
|
| 805 |
occupied_labels = set()
|
| 806 |
for field in list((defs or {}).values()) + list(base_fields or ()):
|
|
|
|
| 812 |
key = str(field.get("key") or "").strip()
|
| 813 |
if key:
|
| 814 |
occupied_keys.add(key)
|
| 815 |
+
return occupied_keys, occupied_labels
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
def _next_route_label(defs, base_fields=()):
|
| 819 |
+
"""Return the next human route-field label without colliding with a visible field.
|
| 820 |
+
|
| 821 |
+
β OWNER ITEM 5 (2026-08-23) β THE WORD IS "ROUTE", NOT "DESTINATION". Owner: *"Instead of
|
| 822 |
+
calling it 'Destination 1' etc. for when we saved the route to a field, we just call it
|
| 823 |
+
'Route 1' so it's Route 1, Route 2, Route 3."* A saved column holds the ORDER of a whole day,
|
| 824 |
+
so "Destination 1" read as the first stop rather than as the first route, which is exactly
|
| 825 |
+
backwards from what the numbers in it mean.
|
| 826 |
+
|
| 827 |
+
β NO MIGRATION, AND THAT IS DELIBERATE. Columns already minted as `Destination N` keep their
|
| 828 |
+
label: rewriting a tenant-wide column name that other people's saved views point at is not a
|
| 829 |
+
rename this door was asked for. The owner renames one through `route_order_rename` below, per
|
| 830 |
+
owner item 6 of the same instruction.
|
| 831 |
+
|
| 832 |
+
β THE KEY IS STILL DERIVED FROM THE LABEL, so the default now slugs to `route_route_1`. The
|
| 833 |
+
redundant segment is NOT tidied away: `ROUTE_KEY_PREFIX` is what keeps a route column out of
|
| 834 |
+
the namespace this database owns, and stripping it here would make the labels "Route 1" and
|
| 835 |
+
"1" collide on one key. The key is never on screen.
|
| 836 |
+
"""
|
| 837 |
+
occupied_keys, occupied_labels = _occupied(defs, base_fields)
|
| 838 |
n = 1
|
| 839 |
while True:
|
| 840 |
+
label = f"Route {n}"
|
| 841 |
if label.casefold() not in occupied_labels and _route_slug(label) not in occupied_keys:
|
| 842 |
return label
|
| 843 |
n += 1
|
|
|
|
| 911 |
"mine": bool(session.admin
|
| 912 |
or str(defn.get("createdBy") or "") == session.uname),
|
| 913 |
})
|
| 914 |
+
# ββ OWNER ITEM 5 β THE DEFAULT NAME IS ALLOCATED **HERE**, NEVER ON THE CLIENT.
|
| 915 |
+
#
|
| 916 |
+
# The panel prompts for a route name and pre-fills it. Computing that pre-fill from the
|
| 917 |
+
# `fields` list above would compute it from the columns this session may SEE: `_route_defs`
|
| 918 |
+
# drops every route column the per-field wall hides, so a user with no grant on
|
| 919 |
+
# `route_route_1` would be offered "Route 1" as their default, send it, and be refused
|
| 920 |
+
# `field_key_taken` on a name the app itself put in the box. Allocated over the WHOLE shared
|
| 921 |
+
# stratum, the suggestion can never name a column that already exists.
|
| 922 |
+
#
|
| 923 |
+
# β IT LEAKS NOTHING. What travels is the first FREE name, which is a fact about absence.
|
| 924 |
+
import aios_grid
|
| 925 |
+
return {"fields": out,
|
| 926 |
+
"nextLabel": _next_route_label(shared_fields(st=session.runtime) or {},
|
| 927 |
+
aios_grid.FIELDS)}
|
| 928 |
|
| 929 |
|
| 930 |
@router.post("/customers/route-order")
|
|
|
|
| 962 |
elif label:
|
| 963 |
key = _route_slug(label)
|
| 964 |
else:
|
| 965 |
+
label = _next_route_label(defs, aios_grid.FIELDS)
|
| 966 |
key = _route_slug(label)
|
| 967 |
if not key:
|
| 968 |
raise err(400, "bad_request", "a name is required for the route order column")
|
|
|
|
| 1067 |
defn = {
|
| 1068 |
"key": key,
|
| 1069 |
"label": label or (existing or {}).get("label") or key,
|
| 1070 |
+
# ββ OWNER ITEM 7 (2026-08-23) β THE SAVED ROUTE IS A **NUMBER** COLUMN.
|
| 1071 |
+
#
|
| 1072 |
+
# Owner: *"the Route field once saved should be saved as a number Field. Make sure we can
|
| 1073 |
+
# edit it, BUT also make sure that none of the number can be a duplicate, so its like a
|
| 1074 |
+
# number order field."* It used to be a `select` whose declared choices were the strings
|
| 1075 |
+
# "1".."N", which sorted and rendered as a list rather than as an order and forced a
|
| 1076 |
+
# re-solve to widen the vocabulary before a stop could be numbered past N.
|
| 1077 |
+
#
|
| 1078 |
+
# β UNIQUENESS IS NOT A PROPERTY OF THE TYPE, SO IT LIVES AT THE WRITE DOOR. `int` has no
|
| 1079 |
+
# "no duplicates" flag anywhere in this contract; `_patch_route_ranks` in `patch_customer`
|
| 1080 |
+
# is what keeps the column a permutation, by SWAPPING rather than by refusing.
|
| 1081 |
+
#
|
| 1082 |
+
# β EXISTING COLUMNS ARE NOT MIGRATED, they are UPGRADED BY RE-SOLVE. This dict is
|
| 1083 |
+
# rebuilt whole on every write, so the first re-solve of a `Destination N` column turns it
|
| 1084 |
+
# into a number column; one nobody re-solves keeps working as the select it was, and the
|
| 1085 |
+
# write door reads the KIND rather than the type, so both edit identically.
|
| 1086 |
+
"type": "int",
|
| 1087 |
"source": "overlay",
|
| 1088 |
"shared": True,
|
| 1089 |
"kind": ROUTE_KIND,
|
|
|
|
| 1140 |
_shared_key(), {**{p: {key: str(v)} for p, v in ranks.items()}, **stale},
|
| 1141 |
st=session.runtime)
|
| 1142 |
|
| 1143 |
+
out = {"ok": True, "field": key, "label": defn["label"], "type": "int",
|
|
|
|
| 1144 |
"stops": len(ranks), "cleared": len(stale),
|
| 1145 |
"rows_written": len(written), "inputsHash": defn["route"]["inputsHash"],
|
| 1146 |
"depot": defn["route"]["depot"],
|
|
|
|
| 1213 |
except Exception: # noqa: BLE001
|
| 1214 |
pass
|
| 1215 |
return {"ok": True, "field": key, "dropped": bool(dropped)}
|
| 1216 |
+
|
| 1217 |
+
|
| 1218 |
+
@router.patch("/customers/route-order/{field_key}")
|
| 1219 |
+
def route_order_rename(field_key: str, body: dict = Body(default=None),
|
| 1220 |
+
session: Session = Depends(module_gate(MODULE))):
|
| 1221 |
+
"""Rename a route order column, or write its description. `{label?, note?}`.
|
| 1222 |
+
|
| 1223 |
+
ββ OWNER ITEM 6 (2026-08-23) β "Edit field" MUST BE ABLE TO RENAME THIS COLUMN.
|
| 1224 |
+
|
| 1225 |
+
A route order is a SHARED column on the customers REGISTRY topic. The grid's Edit-field pane
|
| 1226 |
+
offers a Name box only when the host supplies `onRename`, and the host supplies it only for
|
| 1227 |
+
`isUserSchemaField` β a per-user `custom_` column, or a `ut_*` definition field. A route order
|
| 1228 |
+
is neither, so the pane showed a DISABLED Name box reading *"A source field keeps its name and
|
| 1229 |
+
type from the data source"* about a column the person had created themselves an hour earlier.
|
| 1230 |
+
That is the same shape as owner item 3's missing Delete, one stratum over.
|
| 1231 |
+
|
| 1232 |
+
ββ THE KEY IS FROZEN. `_route_slug` derives the store key from the label AT CREATION, and
|
| 1233 |
+
only there. Re-slugging on a rename would leave every written visit number sitting under the
|
| 1234 |
+
old key in `shared_overlay`, every saved view's `colId` pointing at a column that no longer
|
| 1235 |
+
exists, and every field grant naming an oid nobody can reach β a rename that looks perfect on
|
| 1236 |
+
a fresh column and quietly empties a used one. The label moves; nothing else does.
|
| 1237 |
+
|
| 1238 |
+
β CREATOR-OR-ADMIN, and a caller who cannot SEE the column gets the answer a nonexistent key
|
| 1239 |
+
gets. Both walls are `route_order_delete`'s, verbatim and for its reasons: this changes what
|
| 1240 |
+
every account in the workspace reads, and a refusal that said "forbidden" would confirm to a
|
| 1241 |
+
stranger that a route order exists here and who planned it.
|
| 1242 |
+
|
| 1243 |
+
ββ THE DESCRIPTION RIDES THIS DOOR TOO, AND IT HAD TO. The Edit-field pane writes a
|
| 1244 |
+
description through `onNote`, which is `saveField` β a PER-USER `field_upsert`. Traced through
|
| 1245 |
+
`grid_events`: a route key is not `custom`-marked in the shared stratum, so the `shared_field`
|
| 1246 |
+
branch does not take it; it IS in the merged contract, so the `key in field_by_key` branch
|
| 1247 |
+
does, and it stores `{**base, note}` in THIS USER'S field definitions. `_merge_shared_fields`
|
| 1248 |
+
then skips the shared definition, because a key the contract already declares wins β so that
|
| 1249 |
+
user is left reading a private copy of a tenant-wide column, frozen at the label it had when
|
| 1250 |
+
they typed the description, and a later rename through this door is invisible to them.
|
| 1251 |
+
Pre-existing, and unreachable enough to have gone unnoticed; owner item 6 makes that pane the
|
| 1252 |
+
place people go for route columns, so it stops being unreachable on the same day.
|
| 1253 |
+
"""
|
| 1254 |
+
from core import shared_overlay
|
| 1255 |
+
import core.perm_scope as perm_scope
|
| 1256 |
+
import aios_grid
|
| 1257 |
+
|
| 1258 |
+
body = body if isinstance(body, dict) else {}
|
| 1259 |
+
key = str(field_key or "").strip()
|
| 1260 |
+
label = " ".join(str(body.get("label") or "").split())[:120]
|
| 1261 |
+
# β `"note" in body` AND NOT a truthiness test: an empty string is how a description is
|
| 1262 |
+
# CLEARED, and a door that read it as "unchanged" would leave one nobody can delete.
|
| 1263 |
+
note = str(body.get("note") or "")[:2000] if "note" in body else None
|
| 1264 |
+
if not label and note is None:
|
| 1265 |
+
raise err(400, "bad_request", "a route order column needs a name")
|
| 1266 |
+
if "label" in body and not label:
|
| 1267 |
+
raise err(400, "bad_request", "a route order column needs a name")
|
| 1268 |
+
|
| 1269 |
+
all_defs = shared_fields(st=session.runtime) or {}
|
| 1270 |
+
defn = all_defs.get(key) if isinstance(all_defs.get(key), dict) else None
|
| 1271 |
+
unknown = err(404, "unknown_field",
|
| 1272 |
+
"that column is not a route order column on this database")
|
| 1273 |
+
if not defn:
|
| 1274 |
+
raise unknown
|
| 1275 |
+
if key in perm_scope.hidden_keys(
|
| 1276 |
+
session.user, MODULE,
|
| 1277 |
+
_merge_shared_fields(list(aios_grid.FIELDS), all_defs), st=session.runtime):
|
| 1278 |
+
raise unknown
|
| 1279 |
+
if defn.get("kind") != ROUTE_KIND:
|
| 1280 |
+
raise err(400, "not_a_route_column",
|
| 1281 |
+
"that column is shared but it is not a route order column, so this door will "
|
| 1282 |
+
"not rename it")
|
| 1283 |
+
owner = str(defn.get("createdBy") or "")
|
| 1284 |
+
if not session.admin and owner != session.uname:
|
| 1285 |
+
raise err(403, "forbidden",
|
| 1286 |
+
f"a route order column can be renamed by the person who planned it or by an "
|
| 1287 |
+
f"administrator. This one was planned by {owner or 'somebody else'}, and its "
|
| 1288 |
+
f"name is what every account in the workspace reads")
|
| 1289 |
+
|
| 1290 |
+
# β THE COLLISION CHECK LOOKS AT LABELS AND NOT AT KEYS, because the key is frozen: this
|
| 1291 |
+
# rename can never take another column's key, only its NAME. Two columns wearing one name on
|
| 1292 |
+
# the same grid is the confusion `_next_route_label` exists to prevent at creation, so the
|
| 1293 |
+
# rename door refuses it too. The column's OWN current label is excluded, so re-saving an
|
| 1294 |
+
# unchanged name is a no-op rather than a refusal.
|
| 1295 |
+
_keys, occupied_labels = _occupied(
|
| 1296 |
+
{k: v for k, v in all_defs.items() if k != key}, aios_grid.FIELDS)
|
| 1297 |
+
if label and label.casefold() in occupied_labels:
|
| 1298 |
+
raise err(400, "field_label_taken",
|
| 1299 |
+
"this database already has a column with that name")
|
| 1300 |
+
|
| 1301 |
+
patch = dict(defn)
|
| 1302 |
+
if label:
|
| 1303 |
+
patch["label"] = label
|
| 1304 |
+
if note is not None:
|
| 1305 |
+
patch["note"] = note
|
| 1306 |
+
shared_overlay.put_field(_shared_key(), key, patch, st=session.runtime)
|
| 1307 |
+
return {"ok": True, "field": key, "label": patch.get("label") or key,
|
| 1308 |
+
"note": patch.get("note") or ""}
|
web/src/customer-grid/CustomerGrid.tsx
CHANGED
|
@@ -95,7 +95,7 @@ import { NAV_MINIMIZE_EVENT, ROWS_STALE_EVENT, TOAST_EVENT, VIEW_OPEN_EVENT,
|
|
| 95 |
from "../apiContract";
|
| 96 |
import type { ViewOpenDetail } from "../apiContract";
|
| 97 |
import { addTableField, addTableRow, deleteRouteOrderField, deleteTableField, deleteTableRow, fetchLinkTargets,
|
| 98 |
-
fetchRollupSources, patchTableField, enrichField } from "./apiBridge";
|
| 99 |
import type { LinkTarget, RollupSourceOffer } from "./apiBridge";
|
| 100 |
import SelectFromFile from "./SelectFromFile";
|
| 101 |
import ImportDialog from "./ImportDialog";
|
|
@@ -5502,6 +5502,40 @@ function CustomerGridSurface({
|
|
| 5502 |
[lockedKey, config, order, visible, updateConfig, setFields]
|
| 5503 |
);
|
| 5504 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5505 |
const deleteDefinitionField = useCallback(
|
| 5506 |
(key: string) => {
|
| 5507 |
if (!isUserTable || key === lockedKey) return;
|
|
@@ -7733,7 +7767,24 @@ function CustomerGridSurface({
|
|
| 7733 |
// pane. Absent for every other opening, which is the action list as before.
|
| 7734 |
initialPane={columnMenu.pane}
|
| 7735 |
onClose={() => setColumnMenu(null)}
|
| 7736 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7737 |
onHide={() => {
|
| 7738 |
setColumnVisible(menuField.key, false);
|
| 7739 |
setColumnMenu(null);
|
|
@@ -7779,7 +7830,17 @@ function CustomerGridSurface({
|
|
| 7779 |
// user created themselves. A `ut_*` definition field renames through the DEFINITION
|
| 7780 |
// door; `saveField` would fork it into a private overlay copy of itself (the reason
|
| 7781 |
// `onFormula` below already branches this way).
|
| 7782 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7783 |
? undefined
|
| 7784 |
: menuField.custom
|
| 7785 |
? (label) => saveField({ ...menuField, label })
|
|
|
|
| 95 |
from "../apiContract";
|
| 96 |
import type { ViewOpenDetail } from "../apiContract";
|
| 97 |
import { addTableField, addTableRow, deleteRouteOrderField, deleteTableField, deleteTableRow, fetchLinkTargets,
|
| 98 |
+
fetchRollupSources, patchRouteOrderField, patchTableField, enrichField } from "./apiBridge";
|
| 99 |
import type { LinkTarget, RollupSourceOffer } from "./apiBridge";
|
| 100 |
import SelectFromFile from "./SelectFromFile";
|
| 101 |
import ImportDialog from "./ImportDialog";
|
|
|
|
| 5502 |
[lockedKey, config, order, visible, updateConfig, setFields]
|
| 5503 |
);
|
| 5504 |
|
| 5505 |
+
/**
|
| 5506 |
+
* ββ OWNER ITEM 6 (2026-08-23) β A ROUTE ORDER FIELD BECOMES RENAMEABLE.
|
| 5507 |
+
*
|
| 5508 |
+
* β WHY IT NEEDED A FOURTH HANDLER, exactly as the delete above needed a third. `onRename`'s
|
| 5509 |
+
* two existing branches are `saveField` (this user's overlay stratum) and `setFieldConfig` (a
|
| 5510 |
+
* `ut_*` definition PATCH); a route order is a TENANT-WIDE shared column on a REGISTRY topic
|
| 5511 |
+
* and is neither, so `isUserSchemaField` returned false, `onRename` came through undefined, and
|
| 5512 |
+
* the Edit-field pane rendered a DISABLED Name box saying *"A source field keeps its name and
|
| 5513 |
+
* type from the data source"* about a column the person planned themselves.
|
| 5514 |
+
*
|
| 5515 |
+
* β AND `saveField` WOULD HAVE BEEN THE WRONG FIX RATHER THAN A SHORTCUT. It emits a per-user
|
| 5516 |
+
* `field_upsert`, which on a shared column forks it into a private copy wearing the new name
|
| 5517 |
+
* while every colleague keeps reading the old one. The same fork the `onFormula` branch below
|
| 5518 |
+
* already documents, one stratum over.
|
| 5519 |
+
*
|
| 5520 |
+
* β SERVER FIRST, THEN THE SCREEN, like the delete: the door refuses a column somebody else
|
| 5521 |
+
* planned and a name another column already wears, and the bridge has already said which.
|
| 5522 |
+
*/
|
| 5523 |
+
const patchRouteField = useCallback(
|
| 5524 |
+
(key: string, patch: { label?: string; note?: string }) => {
|
| 5525 |
+
if (key === lockedKey) return;
|
| 5526 |
+
void patchRouteOrderField(key, patch).then((ok) => {
|
| 5527 |
+
if (!ok) return; // the bridge has already said why
|
| 5528 |
+
setFields((current) =>
|
| 5529 |
+
current.map((item) => (item.key === key ? { ...item, ...patch } : item))
|
| 5530 |
+
);
|
| 5531 |
+
// It lives on the SHARED definition, so every other surface reading it (the map's own
|
| 5532 |
+
// "Visit order field" picker among them) refetches rather than guessing.
|
| 5533 |
+
signal(WORKSPACE_STALE_EVENT);
|
| 5534 |
+
});
|
| 5535 |
+
},
|
| 5536 |
+
[lockedKey, setFields]
|
| 5537 |
+
);
|
| 5538 |
+
|
| 5539 |
const deleteDefinitionField = useCallback(
|
| 5540 |
(key: string) => {
|
| 5541 |
if (!isUserTable || key === lockedKey) return;
|
|
|
|
| 7767 |
// pane. Absent for every other opening, which is the action list as before.
|
| 7768 |
initialPane={columnMenu.pane}
|
| 7769 |
onClose={() => setColumnMenu(null)}
|
| 7770 |
+
/**
|
| 7771 |
+
* ββ A ROUTE ORDER COLUMN'S DESCRIPTION TAKES ITS OWN DOOR, for the reason its rename
|
| 7772 |
+
* does one prop above. `saveField` is a PER-USER `field_upsert`, and on a route key
|
| 7773 |
+
* `grid_events` takes the `key in field_by_key` branch and stores `{**base, note}` in
|
| 7774 |
+
* THIS user's field definitions; `_merge_shared_fields` then skips the shared
|
| 7775 |
+
* definition, because a key the contract already declares wins. The typist is left
|
| 7776 |
+
* reading a private copy of a tenant-wide column, frozen at the label it had when they
|
| 7777 |
+
* typed, and every later rename is invisible to them alone.
|
| 7778 |
+
* β It was already reachable (this pane has always rendered the Description box for a
|
| 7779 |
+
* route column); owner item 6 makes this pane the place people go for route columns, so
|
| 7780 |
+
* it stops being theoretical on the same day it stops being obscure.
|
| 7781 |
+
*/
|
| 7782 |
+
onNote={
|
| 7783 |
+
menuField.shared && menuField.kind === "route_order" &&
|
| 7784 |
+
menuField.key !== lockedKey
|
| 7785 |
+
? (note) => patchRouteField(menuField.key, { note })
|
| 7786 |
+
: (note) => saveField({ ...menuField, note })
|
| 7787 |
+
}
|
| 7788 |
onHide={() => {
|
| 7789 |
setColumnVisible(menuField.key, false);
|
| 7790 |
setColumnMenu(null);
|
|
|
|
| 7830 |
// user created themselves. A `ut_*` definition field renames through the DEFINITION
|
| 7831 |
// door; `saveField` would fork it into a private overlay copy of itself (the reason
|
| 7832 |
// `onFormula` below already branches this way).
|
| 7833 |
+
/**
|
| 7834 |
+
* ββ OWNER ITEM 6 (2026-08-23) β the route order column's own rename, FIRST in the
|
| 7835 |
+
* chain because it is the most specific true statement about this column. Matched on
|
| 7836 |
+
* the declared `kind`, never on the `route_` prefix, which is the same rule owner
|
| 7837 |
+
* item 3's delete branch below states and for the same reason: the server declares
|
| 7838 |
+
* the kind precisely so nobody has to read a key as a type.
|
| 7839 |
+
*/
|
| 7840 |
+
menuField.shared && menuField.kind === "route_order" &&
|
| 7841 |
+
menuField.key !== lockedKey
|
| 7842 |
+
? (label) => patchRouteField(menuField.key, { label })
|
| 7843 |
+
: !isUserSchemaField(menuField, isUserTable)
|
| 7844 |
? undefined
|
| 7845 |
: menuField.custom
|
| 7846 |
? (label) => saveField({ ...menuField, label })
|
web/src/customer-grid/MapView.tsx
CHANGED
|
@@ -80,8 +80,10 @@ import {
|
|
| 80 |
planRoute,
|
| 81 |
pointInPolygon,
|
| 82 |
project,
|
|
|
|
| 83 |
routeFingerprint,
|
| 84 |
routeRanks,
|
|
|
|
| 85 |
toScreen,
|
| 86 |
unproject,
|
| 87 |
WORLD,
|
|
@@ -117,6 +119,11 @@ const TILES_DEFAULT: TileProvider = {
|
|
| 117 |
* a shared free tile service is exactly the wrong place to find that out. */
|
| 118 |
const TILE_BUDGET = 240;
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
/**
|
| 121 |
* CSS pixels per SVG user unit, at the width this view is normally painted.
|
| 122 |
*
|
|
@@ -477,8 +484,27 @@ export function MapView({
|
|
| 477 |
const [routeCols, setRouteCols] = useState<
|
| 478 |
{ key: string; label: string; inputsHash: string; mine: boolean; depot?: RouteDepot | null }[] | null
|
| 479 |
>(null);
|
| 480 |
-
/** Which saved column a save writes to. `""` = a new,
|
| 481 |
const [saveTarget, setSaveTarget] = useState("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
const [saveBusy, setSaveBusy] = useState(false);
|
| 483 |
const [saveMsg, setSaveMsg] = useState<string | null>(null);
|
| 484 |
const [saveErr, setSaveErr] = useState<string | null>(null);
|
|
@@ -683,12 +709,30 @@ export function MapView({
|
|
| 683 |
const z = Math.max(0, Math.min(tiles.maxZoom, googleZoomForK(view.k)));
|
| 684 |
const n = Math.pow(2, z);
|
| 685 |
const S = WORLD / n;
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 692 |
if (x1 < x0 || y1 < y0) return null;
|
| 693 |
// One tile-pixel of overlap. Tile edges land on fractional device pixels at most zooms, and
|
| 694 |
// without it the seams paint as a faint grid across the whole basemap.
|
|
@@ -788,6 +832,55 @@ export function MapView({
|
|
| 788 |
}
|
| 789 |
}, [routeOn, customerRoutable.length]);
|
| 790 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 791 |
/** The depot joins BOTH index-parallel arrays below at position zero, and only there. */
|
| 792 |
const depotPoint = useMemo((): MapPoint | null => {
|
| 793 |
if (!depot || !isPlottable(depot.lat, depot.lon)) return null;
|
|
@@ -1003,6 +1096,7 @@ export function MapView({
|
|
| 1003 |
const res = await fetch("/api/v1/customers/route-order", { credentials: "same-origin" });
|
| 1004 |
const body = res.ok ? await res.json().catch(() => null) : null;
|
| 1005 |
setRouteCols(Array.isArray(body?.fields) ? body.fields : []);
|
|
|
|
| 1006 |
} catch {
|
| 1007 |
// A listing that cannot be fetched is "none known", not an error banner over the map: the
|
| 1008 |
// planner still works, and the save below reports its own failure in its own words.
|
|
@@ -1026,10 +1120,14 @@ export function MapView({
|
|
| 1026 |
* identical for every record; the server stores it on the column DEFINITION. Staleness is then
|
| 1027 |
* derived by comparing it against `plan.fingerprint` on whatever is on screen later.
|
| 1028 |
*/
|
| 1029 |
-
const saveRouteOrder = useCallback(async () => {
|
| 1030 |
if (!plan) return;
|
| 1031 |
const ranks = plan.ranksByPid;
|
| 1032 |
if (Object.keys(ranks).length < 2) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1033 |
setSaveBusy(true);
|
| 1034 |
setSaveErr(null);
|
| 1035 |
setSaveMsg(null);
|
|
@@ -1042,6 +1140,8 @@ export function MapView({
|
|
| 1042 |
field: saveTarget || undefined,
|
| 1043 |
...(saveTarget
|
| 1044 |
? { label: (routeCols || []).find((f) => f.key === saveTarget)?.label || saveTarget }
|
|
|
|
|
|
|
| 1045 |
: {}),
|
| 1046 |
ranks,
|
| 1047 |
inputsHash: plan.fingerprint,
|
|
@@ -1067,6 +1167,7 @@ export function MapView({
|
|
| 1067 |
}
|
| 1068 |
const savedField = String(body?.field || "");
|
| 1069 |
setSaveTarget(savedField);
|
|
|
|
| 1070 |
if (savedField) onRouteFieldCreated?.(savedField);
|
| 1071 |
setSaveMsg(
|
| 1072 |
`Saved ${Number(body?.stops || 0).toLocaleString()} visit numbers to ` +
|
|
@@ -1079,7 +1180,7 @@ export function MapView({
|
|
| 1079 |
} finally {
|
| 1080 |
setSaveBusy(false);
|
| 1081 |
}
|
| 1082 |
-
}, [plan, saveTarget, roundTrip, routeCols, loadRouteCols, onRouteFieldCreated]);
|
| 1083 |
|
| 1084 |
/**
|
| 1085 |
* The saved column selected for writing, and whether what is on screen would solve differently.
|
|
@@ -1325,6 +1426,34 @@ export function MapView({
|
|
| 1325 |
[kMin, kMax]
|
| 1326 |
);
|
| 1327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1328 |
const doFit = useCallback(() => {
|
| 1329 |
touchedRef.current = false;
|
| 1330 |
setView(fit);
|
|
@@ -1348,6 +1477,10 @@ export function MapView({
|
|
| 1348 |
case "ArrowDown": panBy(0, -step); break;
|
| 1349 |
case "+": case "=": zoomBy(1.6); break;
|
| 1350 |
case "-": case "_": zoomBy(1 / 1.6); break;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1351 |
case "0": doFit(); break;
|
| 1352 |
// Esc abandons a marquee mid-drag. It falls THROUGH when there is no
|
| 1353 |
// drag, so it keeps closing whatever the host has open.
|
|
@@ -1356,7 +1489,7 @@ export function MapView({
|
|
| 1356 |
}
|
| 1357 |
e.preventDefault();
|
| 1358 |
},
|
| 1359 |
-
[panBy, zoomBy, doFit, drag]
|
| 1360 |
);
|
| 1361 |
|
| 1362 |
const onPointerDown = useCallback(
|
|
@@ -1595,7 +1728,12 @@ export function MapView({
|
|
| 1595 |
const hovered = hoverPid != null ? points.find((p) => p.pid === hoverPid) : undefined;
|
| 1596 |
const rect = drag?.kind === "rect" ? normRect(drag.x0, drag.y0, drag.x1, drag.y1) : null;
|
| 1597 |
const lassoPts = drag?.kind === "lasso" && drag.pts.length > 1 ? drag.pts : null;
|
| 1598 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1599 |
// Strokes live in the transformed group, so they are pre-divided by the zoom.
|
| 1600 |
// β This is the map's ONE stroke mechanism β see the note over `hairline` in
|
| 1601 |
// mapProjection.ts. No `.cg-map*` rule may add `vector-effect:
|
|
@@ -1814,6 +1952,204 @@ export function MapView({
|
|
| 1814 |
)}
|
| 1815 |
{roadErr && <span className="cg-cal-nodate">{roadErr}</span>}
|
| 1816 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1817 |
{/* ββ ITEM 9: where the day starts, and it SEARCHES ββββββββββββββββββββββββββββββ
|
| 1818 |
β ITEM 6 removed the "Optional route start" address box above this, so the
|
| 1819 |
start is the record dropdown and nothing else. The `!plan.depot` guard the old
|
|
@@ -1903,17 +2239,6 @@ export function MapView({
|
|
| 1903 |
</div>
|
| 1904 |
)}
|
| 1905 |
|
| 1906 |
-
{/* ββ ITEM 9: add a record the view is not showing ββββββββββββββββββββββββββββββ */}
|
| 1907 |
-
{allRows && allRows.length > 0 && (
|
| 1908 |
-
<RecordPicker
|
| 1909 |
-
label="Add a record"
|
| 1910 |
-
placeholder="Search the database"
|
| 1911 |
-
emptyNote="Every record in your book is already on this route."
|
| 1912 |
-
options={addableRecords}
|
| 1913 |
-
onPick={addRecord}
|
| 1914 |
-
/>
|
| 1915 |
-
)}
|
| 1916 |
-
|
| 1917 |
{plan && routeOrder && (
|
| 1918 |
<button
|
| 1919 |
type="button"
|
|
@@ -1925,97 +2250,6 @@ export function MapView({
|
|
| 1925 |
</button>
|
| 1926 |
)}
|
| 1927 |
|
| 1928 |
-
{/* ββ ITEM 8: the visit order field, and its committing button ββββββββββββββββββ
|
| 1929 |
-
ββ W38-T20 β THE ORDER BECOMES A COLUMN EVERY PERMITTED COLLEAGUE READS.
|
| 1930 |
-
The number written per record is the INVERSE of the planner's permutation (see
|
| 1931 |
-
`saveRouteOrder`), the field is tenant-wide and grant-governed, and the
|
| 1932 |
-
fingerprint it was solved from rides it so a later reader is TOLD it is out of
|
| 1933 |
-
date rather than shown yesterday's numbers as today's.
|
| 1934 |
-
β ITEM 8 β "New column" reads "New field": `ColumnMenu` calls these fields
|
| 1935 |
-
everywhere else, and one surface calling them columns is the kind of split
|
| 1936 |
-
vocabulary a person has to translate. The SERVER key is untouched. */}
|
| 1937 |
-
{plan && (
|
| 1938 |
-
<>
|
| 1939 |
-
<label className="cg-map-route-opt cg-route-field">
|
| 1940 |
-
Visit order field
|
| 1941 |
-
<select
|
| 1942 |
-
className="cg-route-select"
|
| 1943 |
-
value={saveTarget}
|
| 1944 |
-
aria-label="Which visit order field to write"
|
| 1945 |
-
onChange={(e) => {
|
| 1946 |
-
setSaveTarget(e.target.value);
|
| 1947 |
-
setRouteStartPid(null);
|
| 1948 |
-
setSaveMsg(null);
|
| 1949 |
-
setSaveErr(null);
|
| 1950 |
-
}}
|
| 1951 |
-
>
|
| 1952 |
-
<option value="">New field</option>
|
| 1953 |
-
{(routeCols || [])
|
| 1954 |
-
.filter((f) => f.mine)
|
| 1955 |
-
.map((f) => (
|
| 1956 |
-
<option key={f.key} value={f.key}>
|
| 1957 |
-
{f.label}
|
| 1958 |
-
</option>
|
| 1959 |
-
))}
|
| 1960 |
-
</select>
|
| 1961 |
-
</label>
|
| 1962 |
-
{/* ββ ITEM 4: the hand-off links, ONE PER LINE, DIRECTLY under the visit order
|
| 1963 |
-
field ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1964 |
-
They were a `flex-wrap` cluster of chips, unreadable the moment a route
|
| 1965 |
-
needs more than one Google leg. Stacked, each on its own row, the list reads
|
| 1966 |
-
as what it is: leg 1, then leg 2.
|
| 1967 |
-
β POSITION IS PART OF THE INSTRUCTION, not a detail. They sit between the
|
| 1968 |
-
select and its Save button rather than after the whole block, because the
|
| 1969 |
-
block's tail can carry a stale marker, a shared-orders note and two message
|
| 1970 |
-
rows, and "under the Visit order column" stops being true the moment three
|
| 1971 |
-
of those render between the two. */}
|
| 1972 |
-
{plan.links.length > 0 && (
|
| 1973 |
-
<div className="cg-map-google-links" aria-label="Google Maps route links">
|
| 1974 |
-
{plan.links.map((link) => (
|
| 1975 |
-
<a
|
| 1976 |
-
key={link.index}
|
| 1977 |
-
href={link.url}
|
| 1978 |
-
target="_blank"
|
| 1979 |
-
rel="noopener noreferrer"
|
| 1980 |
-
title={`Open Google Maps route ${link.index} in a new tab`}
|
| 1981 |
-
>
|
| 1982 |
-
Google Maps route {link.index}
|
| 1983 |
-
</a>
|
| 1984 |
-
))}
|
| 1985 |
-
</div>
|
| 1986 |
-
)}
|
| 1987 |
-
<button
|
| 1988 |
-
type="button"
|
| 1989 |
-
className="cg-btn cg-btn--primary cg-route-cta"
|
| 1990 |
-
disabled={saveBusy}
|
| 1991 |
-
onClick={() => void saveRouteOrder()}
|
| 1992 |
-
title={
|
| 1993 |
-
saveTarget
|
| 1994 |
-
? "Write these visit numbers into the saved field, for everyone it is shared with"
|
| 1995 |
-
: "Save these visit numbers as the next Destination field"
|
| 1996 |
-
}
|
| 1997 |
-
>
|
| 1998 |
-
{saveBusy ? "Saving" : saveTarget ? "Update visit order" : "Save visit order"}
|
| 1999 |
-
</button>
|
| 2000 |
-
{/* β DERIVED, NEVER STORED. The saved field carries the fingerprint of the
|
| 2001 |
-
inputs it was solved from; this compares it against the cohort ON SCREEN
|
| 2002 |
-
NOW, so the marker cannot itself go out of date. */}
|
| 2003 |
-
{orderStale && (
|
| 2004 |
-
<span className="cg-map-route-note">
|
| 2005 |
-
Stale. The saved numbers were solved from different stops, so re-solving
|
| 2006 |
-
would change them.
|
| 2007 |
-
</span>
|
| 2008 |
-
)}
|
| 2009 |
-
{(routeCols || []).some((f) => !f.mine) && (
|
| 2010 |
-
<span className="cg-map-route-note">
|
| 2011 |
-
Shared orders you can read but not re-solve are not listed above.
|
| 2012 |
-
</span>
|
| 2013 |
-
)}
|
| 2014 |
-
{saveMsg && <span className="cg-map-route-note">{saveMsg}</span>}
|
| 2015 |
-
{saveErr && <span className="cg-cal-nodate">{saveErr}</span>}
|
| 2016 |
-
</>
|
| 2017 |
-
)}
|
| 2018 |
-
|
| 2019 |
{/* β W37-T36 β NAMED, NOT COUNTED. "4 selected records have no location" tells you
|
| 2020 |
something is missing and not WHICH visit you are about to fail to make, and the
|
| 2021 |
whole point of the chip is that the exclusion is not silent. Three inline so a
|
|
@@ -2083,7 +2317,7 @@ export function MapView({
|
|
| 2083 |
className="cg-map-frame"
|
| 2084 |
tabIndex={0}
|
| 2085 |
role="group"
|
| 2086 |
-
aria-label="Map canvas. Arrow keys pan, plus and minus zoom, zero fits to data."
|
| 2087 |
onKeyDown={onFrameKeyDown}
|
| 2088 |
>
|
| 2089 |
<svg
|
|
@@ -2355,8 +2589,31 @@ export function MapView({
|
|
| 2355 |
OUTSIDE the <svg> deliberately: a mousedown on a button inside it would
|
| 2356 |
begin a pan. Icons are SVG strokes β no emoji, no glyph font. The zoom
|
| 2357 |
buttons DISABLE at the limits, which is also how the honesty cap on
|
| 2358 |
-
zoom-in makes itself visible instead of just feeling stuck.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2359 |
<div className="cg-map-ctl" role="group" aria-label="Map camera">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2360 |
<button
|
| 2361 |
type="button"
|
| 2362 |
className="cg-map-ctl-b"
|
|
@@ -2395,8 +2652,11 @@ export function MapView({
|
|
| 2395 |
<button
|
| 2396 |
type="button"
|
| 2397 |
className="cg-map-ctl-b"
|
| 2398 |
-
|
| 2399 |
-
|
|
|
|
|
|
|
|
|
|
| 2400 |
onClick={doFit}
|
| 2401 |
>
|
| 2402 |
<svg viewBox="0 0 16 16" aria-hidden="true">
|
|
@@ -2450,6 +2710,20 @@ export function MapView({
|
|
| 2450 |
<path d="M8.6 3.4h4v4M12.6 3.4 7.4 8.6" />
|
| 2451 |
</svg>
|
| 2452 |
</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2453 |
</div>
|
| 2454 |
|
| 2455 |
{/* --- W37-T35 β THE CREDIT LINE. β A LICENCE TERM, NOT DECORATION.
|
|
|
|
| 80 |
planRoute,
|
| 81 |
pointInPolygon,
|
| 82 |
project,
|
| 83 |
+
rotateAt,
|
| 84 |
routeFingerprint,
|
| 85 |
routeRanks,
|
| 86 |
+
ROUTE_STOP_CAP,
|
| 87 |
toScreen,
|
| 88 |
unproject,
|
| 89 |
WORLD,
|
|
|
|
| 119 |
* a shared free tile service is exactly the wrong place to find that out. */
|
| 120 |
const TILE_BUDGET = 240;
|
| 121 |
|
| 122 |
+
/** β OWNER ITEM 1 (2026-08-23) β degrees per click of Rotate left / Rotate right, the owner's
|
| 123 |
+
* own number: *"every click is say rotating the map by 5 degrees"*. 72 clicks is a full turn,
|
| 124 |
+
* which is why Fit to data doubles as the way back to north. */
|
| 125 |
+
const ROTATE_STEP = 5;
|
| 126 |
+
|
| 127 |
/**
|
| 128 |
* CSS pixels per SVG user unit, at the width this view is normally painted.
|
| 129 |
*
|
|
|
|
| 484 |
const [routeCols, setRouteCols] = useState<
|
| 485 |
{ key: string; label: string; inputsHash: string; mine: boolean; depot?: RouteDepot | null }[] | null
|
| 486 |
>(null);
|
| 487 |
+
/** Which saved column a save writes to. `""` = a new field, named in the prompt below. */
|
| 488 |
const [saveTarget, setSaveTarget] = useState("");
|
| 489 |
+
/**
|
| 490 |
+
* ββ OWNER ITEM 5 (2026-08-23) β THE NAME IS ASKED FOR, AND ITS DEFAULT COMES FROM THE SERVER.
|
| 491 |
+
*
|
| 492 |
+
* Owner: *"When we click the newly renamed 'Save route' it should prompt the user to Name the
|
| 493 |
+
* route, with the default as Route 1, or Route 2, etc."*
|
| 494 |
+
*
|
| 495 |
+
* β `nextLabel` IS ALLOCATED SERVER-SIDE AND NEVER COMPUTED FROM `routeCols`. That list is
|
| 496 |
+
* filtered by the per-field wall, so a user with no grant on `route_route_1` would be offered
|
| 497 |
+
* "Route 1" as their pre-fill, send it, and be refused `field_key_taken` on a name this panel
|
| 498 |
+
* put in the box for them. `GET /customers/route-order` allocates it over the WHOLE shared
|
| 499 |
+
* stratum, which is a fact about absence and leaks nothing.
|
| 500 |
+
*
|
| 501 |
+
* β AND AN UNEDITED DEFAULT IS SENT AS **NO LABEL AT ALL** (see `saveRouteOrder`). The door
|
| 502 |
+
* allocates the next free name at the moment of the write, so a name that went stale between
|
| 503 |
+
* the panel opening and the Save landing cannot become a refusal the user did not cause.
|
| 504 |
+
*/
|
| 505 |
+
const [nextLabel, setNextLabel] = useState("");
|
| 506 |
+
const [naming, setNaming] = useState(false);
|
| 507 |
+
const [nameDraft, setNameDraft] = useState("");
|
| 508 |
const [saveBusy, setSaveBusy] = useState(false);
|
| 509 |
const [saveMsg, setSaveMsg] = useState<string | null>(null);
|
| 510 |
const [saveErr, setSaveErr] = useState<string | null>(null);
|
|
|
|
| 709 |
const z = Math.max(0, Math.min(tiles.maxZoom, googleZoomForK(view.k)));
|
| 710 |
const n = Math.pow(2, z);
|
| 711 |
const S = WORLD / n;
|
| 712 |
+
// β OWNER ITEM 1 (2026-08-23) β ALL FOUR CORNERS, NOT TWO. Two corners describe the world
|
| 713 |
+
// rectangle on screen only while the map is north-up; the moment it carries a bearing the
|
| 714 |
+
// screen rectangle is a rotated QUADRILATERAL in world space, and its top-left corner is no
|
| 715 |
+
// longer its minimum on either axis. Taking two would have left a triangular wedge of the
|
| 716 |
+
// frame with no tiles under it at every bearing that is not a multiple of 90 degrees.
|
| 717 |
+
// β THE BUDGET IS NOT THE BINDING CONSTRAINT, measured rather than assumed: the frame is
|
| 718 |
+
// 1000x620 units at ~1.08 CSS px each, and `googleZoomForK` targets ~256 CSS px per tile, so
|
| 719 |
+
// a north-up frame asks for roughly 5x4 tiles. The worst bearing (45 degrees) grows the
|
| 720 |
+
// bounding box to ~1145x1145 units, i.e. ~5x5 tiles. Both are an order of magnitude under
|
| 721 |
+
// `TILE_BUDGET`.
|
| 722 |
+
const corners = [
|
| 723 |
+
fromScreen({ x: 0, y: 0 }, view),
|
| 724 |
+
fromScreen({ x: VIEW_W, y: 0 }, view),
|
| 725 |
+
fromScreen({ x: 0, y: VIEW_H }, view),
|
| 726 |
+
fromScreen({ x: VIEW_W, y: VIEW_H }, view),
|
| 727 |
+
];
|
| 728 |
+
const minX = Math.min(...corners.map((c) => c.x));
|
| 729 |
+
const maxX = Math.max(...corners.map((c) => c.x));
|
| 730 |
+
const minY = Math.min(...corners.map((c) => c.y));
|
| 731 |
+
const maxY = Math.max(...corners.map((c) => c.y));
|
| 732 |
+
const x0 = Math.max(0, Math.floor(minX / S));
|
| 733 |
+
const x1 = Math.min(n - 1, Math.floor(maxX / S));
|
| 734 |
+
const y0 = Math.max(0, Math.floor(minY / S));
|
| 735 |
+
const y1 = Math.min(n - 1, Math.floor(maxY / S));
|
| 736 |
if (x1 < x0 || y1 < y0) return null;
|
| 737 |
// One tile-pixel of overlap. Tile edges land on fractional device pixels at most zooms, and
|
| 738 |
// without it the seams paint as a faint grid across the whole basemap.
|
|
|
|
| 832 |
}
|
| 833 |
}, [routeOn, customerRoutable.length]);
|
| 834 |
|
| 835 |
+
/**
|
| 836 |
+
* ββ OWNER ITEM 3 (2026-08-23) β OPENING **Route** ROUTES THE VIEW.
|
| 837 |
+
*
|
| 838 |
+
* Owner: *"I have to select first before the route populates? I want it so that by default,
|
| 839 |
+
* when I click the Route button. It already selects everything in that View as the route."*
|
| 840 |
+
* So opening the panel with nothing chosen takes the view's own pins as the cohort and solves
|
| 841 |
+
* them, instead of showing an empty planner and a sentence about shift-clicking.
|
| 842 |
+
*
|
| 843 |
+
* β IT ARMS THE LOCAL SOLVE AND **NOT** THE ROAD REQUEST, which is R3 honoured rather than
|
| 844 |
+
* bent. R3 forbids SPENDING a routing request on anything but a click; `planRoute` is local
|
| 845 |
+
* arithmetic that costs nothing and runs in single-digit milliseconds at the cap, so the
|
| 846 |
+
* sequence, the distance estimate and the drawn line are there on open, and the provider is
|
| 847 |
+
* asked only when somebody presses Driving route. `askRoadRef` is deliberately not set here.
|
| 848 |
+
*
|
| 849 |
+
* β AND IT NEVER OVERRIDES A CHOICE ALREADY MADE. A person who selected pins and then opened
|
| 850 |
+
* the panel keeps their selection; the auto-fill is for the empty case, which is the one the
|
| 851 |
+
* owner is describing.
|
| 852 |
+
*
|
| 853 |
+
* β ONCE PER OPENING, VIA A REF. `points` and `selectedPids` both move constantly (a pan does
|
| 854 |
+
* not, but an edit does), and an effect that re-ran on them would keep dragging the selection
|
| 855 |
+
* back to the whole view every time the user narrowed it by hand.
|
| 856 |
+
* β AND THE REF IS ARMED ONLY WHEN THERE WERE PINS TO TAKE. Opening the panel while the rows
|
| 857 |
+
* are still loading would otherwise consume the one shot on an empty map.
|
| 858 |
+
*
|
| 859 |
+
* β CAPPED AT `ROUTE_STOP_CAP`, IN THE VIEW'S OWN ORDER, AND SAID OUT LOUD. `rows` reaches
|
| 860 |
+
* this component through `useVisibleRows`' filter -> search -> SORT -> group pipeline, so
|
| 861 |
+
* "the first N" means the first N as the view is sorted -- the user's own ranking, which is
|
| 862 |
+
* the only ranking this surface has. The owner asked for "the top SKU"; the map has no SKU,
|
| 863 |
+
* and inventing one would be a plausible order nobody chose. `autoCapped` carries what was
|
| 864 |
+
* left out so the panel can report it rather than quietly routing a subset.
|
| 865 |
+
*/
|
| 866 |
+
const autoRouteRef = useRef(false);
|
| 867 |
+
const [autoCapped, setAutoCapped] = useState(0);
|
| 868 |
+
useEffect(() => {
|
| 869 |
+
if (!routePanelOpen) {
|
| 870 |
+
autoRouteRef.current = false;
|
| 871 |
+
setAutoCapped(0);
|
| 872 |
+
return;
|
| 873 |
+
}
|
| 874 |
+
if (autoRouteRef.current || points.length < 2) return;
|
| 875 |
+
autoRouteRef.current = true;
|
| 876 |
+
if (selectedPids.size >= 2) return;
|
| 877 |
+
const take = points.slice(0, ROUTE_STOP_CAP);
|
| 878 |
+
setAutoCapped(points.length - take.length);
|
| 879 |
+
onSelectPids(take.map((p) => p.pid), "replace");
|
| 880 |
+
setRouteOn(true);
|
| 881 |
+
setRouteOrder(null);
|
| 882 |
+
}, [routePanelOpen, points, selectedPids, onSelectPids]);
|
| 883 |
+
|
| 884 |
/** The depot joins BOTH index-parallel arrays below at position zero, and only there. */
|
| 885 |
const depotPoint = useMemo((): MapPoint | null => {
|
| 886 |
if (!depot || !isPlottable(depot.lat, depot.lon)) return null;
|
|
|
|
| 1096 |
const res = await fetch("/api/v1/customers/route-order", { credentials: "same-origin" });
|
| 1097 |
const body = res.ok ? await res.json().catch(() => null) : null;
|
| 1098 |
setRouteCols(Array.isArray(body?.fields) ? body.fields : []);
|
| 1099 |
+
setNextLabel(typeof body?.nextLabel === "string" ? body.nextLabel : "");
|
| 1100 |
} catch {
|
| 1101 |
// A listing that cannot be fetched is "none known", not an error banner over the map: the
|
| 1102 |
// planner still works, and the save below reports its own failure in its own words.
|
|
|
|
| 1120 |
* identical for every record; the server stores it on the column DEFINITION. Staleness is then
|
| 1121 |
* derived by comparing it against `plan.fingerprint` on whatever is on screen later.
|
| 1122 |
*/
|
| 1123 |
+
const saveRouteOrder = useCallback(async (chosenName?: string) => {
|
| 1124 |
if (!plan) return;
|
| 1125 |
const ranks = plan.ranksByPid;
|
| 1126 |
if (Object.keys(ranks).length < 2) return;
|
| 1127 |
+
// β ITEM 5 β an UNEDITED default travels as no label at all, so the door allocates the next
|
| 1128 |
+
// free name at the moment of the write rather than the moment the panel opened.
|
| 1129 |
+
const typed = (chosenName ?? "").trim();
|
| 1130 |
+
const newLabel = typed && typed !== nextLabel.trim() ? typed : "";
|
| 1131 |
setSaveBusy(true);
|
| 1132 |
setSaveErr(null);
|
| 1133 |
setSaveMsg(null);
|
|
|
|
| 1140 |
field: saveTarget || undefined,
|
| 1141 |
...(saveTarget
|
| 1142 |
? { label: (routeCols || []).find((f) => f.key === saveTarget)?.label || saveTarget }
|
| 1143 |
+
: newLabel
|
| 1144 |
+
? { label: newLabel }
|
| 1145 |
: {}),
|
| 1146 |
ranks,
|
| 1147 |
inputsHash: plan.fingerprint,
|
|
|
|
| 1167 |
}
|
| 1168 |
const savedField = String(body?.field || "");
|
| 1169 |
setSaveTarget(savedField);
|
| 1170 |
+
setNaming(false);
|
| 1171 |
if (savedField) onRouteFieldCreated?.(savedField);
|
| 1172 |
setSaveMsg(
|
| 1173 |
`Saved ${Number(body?.stops || 0).toLocaleString()} visit numbers to ` +
|
|
|
|
| 1180 |
} finally {
|
| 1181 |
setSaveBusy(false);
|
| 1182 |
}
|
| 1183 |
+
}, [plan, saveTarget, roundTrip, routeCols, nextLabel, loadRouteCols, onRouteFieldCreated]);
|
| 1184 |
|
| 1185 |
/**
|
| 1186 |
* The saved column selected for writing, and whether what is on screen would solve differently.
|
|
|
|
| 1426 |
[kMin, kMax]
|
| 1427 |
);
|
| 1428 |
|
| 1429 |
+
/**
|
| 1430 |
+
* ββ OWNER ITEM 1 (2026-08-23) β TURN THE MAP, 5 DEGREES A CLICK.
|
| 1431 |
+
*
|
| 1432 |
+
* Owner: *"we need to add two more button for that navigation. Rotate left and Rotate right.
|
| 1433 |
+
* Where every click is say rotating the map by 5 degrees."*
|
| 1434 |
+
*
|
| 1435 |
+
* β `touchedRef` IS SET, AND WITHOUT IT THE BEARING WOULD NOT SURVIVE THE NEXT EDIT. The
|
| 1436 |
+
* seeding effect above re-fits whenever `fit` changes UNLESS the user has touched the camera,
|
| 1437 |
+
* and `fit` changes on every points change β a cell edit, a filter, an arriving row. Rotating
|
| 1438 |
+
* without panning would then look like the map springing back to north on its own.
|
| 1439 |
+
*
|
| 1440 |
+
* β ABOUT THE VIEWPORT CENTRE, which is what a compass control means by "turn". `rotateAt`
|
| 1441 |
+
* is `zoomAt`'s sibling and holds that point still, so the geography under the middle of the
|
| 1442 |
+
* frame is the geography you were looking at.
|
| 1443 |
+
*/
|
| 1444 |
+
const rotateBy = useCallback((deg: number) => {
|
| 1445 |
+
touchedRef.current = true;
|
| 1446 |
+
setView((v) => (v ? rotateAt(v, deg, VIEW_W / 2, VIEW_H / 2) : v));
|
| 1447 |
+
}, []);
|
| 1448 |
+
|
| 1449 |
+
/**
|
| 1450 |
+
* β AND FIT PUTS NORTH BACK UP. `fit` is a fresh `{k, tx, ty}` with no `rot`, so replacing
|
| 1451 |
+
* the view with it resets the bearing by construction rather than by a line that could be
|
| 1452 |
+
* forgotten. It is deliberate rather than incidental: a compass with no way back to north is a
|
| 1453 |
+
* control with no undo, and `fitView` would otherwise have to frame the bounding box of the
|
| 1454 |
+
* ROTATED points to keep every pin on screen. "Fit to data" is the reset, and the button's
|
| 1455 |
+
* title says so.
|
| 1456 |
+
*/
|
| 1457 |
const doFit = useCallback(() => {
|
| 1458 |
touchedRef.current = false;
|
| 1459 |
setView(fit);
|
|
|
|
| 1477 |
case "ArrowDown": panBy(0, -step); break;
|
| 1478 |
case "+": case "=": zoomBy(1.6); break;
|
| 1479 |
case "-": case "_": zoomBy(1 / 1.6); break;
|
| 1480 |
+
// β ITEM 1 β the bracket keys turn the map, the same 5 degrees the buttons do. Not the
|
| 1481 |
+
// arrows: those are the pan, and shift-arrow is already the bigger pan step.
|
| 1482 |
+
case "[": rotateBy(-ROTATE_STEP); break;
|
| 1483 |
+
case "]": rotateBy(ROTATE_STEP); break;
|
| 1484 |
case "0": doFit(); break;
|
| 1485 |
// Esc abandons a marquee mid-drag. It falls THROUGH when there is no
|
| 1486 |
// drag, so it keeps closing whatever the host has open.
|
|
|
|
| 1489 |
}
|
| 1490 |
e.preventDefault();
|
| 1491 |
},
|
| 1492 |
+
[panBy, zoomBy, rotateBy, doFit, drag]
|
| 1493 |
);
|
| 1494 |
|
| 1495 |
const onPointerDown = useCallback(
|
|
|
|
| 1728 |
const hovered = hoverPid != null ? points.find((p) => p.pid === hoverPid) : undefined;
|
| 1729 |
const rect = drag?.kind === "rect" ? normRect(drag.x0, drag.y0, drag.x1, drag.y1) : null;
|
| 1730 |
const lassoPts = drag?.kind === "lasso" && drag.pts.length > 1 ? drag.pts : null;
|
| 1731 |
+
// β ITEM 1 β `rotate` sits BETWEEN the translate and the scale, which is the transform
|
| 1732 |
+
// `toScreen` computes and `fromScreen` inverts (`t + R . k . p`, read right to left). Any other
|
| 1733 |
+
// order paints a map whose pins, hit tests and hover cards disagree about where things are.
|
| 1734 |
+
const tf =
|
| 1735 |
+
`translate(${view.tx.toFixed(2)} ${view.ty.toFixed(2)}) ` +
|
| 1736 |
+
`rotate(${(view.rot ?? 0).toFixed(2)}) scale(${view.k.toFixed(6)})`;
|
| 1737 |
// Strokes live in the transformed group, so they are pre-divided by the zoom.
|
| 1738 |
// β This is the map's ONE stroke mechanism β see the note over `hairline` in
|
| 1739 |
// mapProjection.ts. No `.cg-map*` rule may add `vector-effect:
|
|
|
|
| 1952 |
)}
|
| 1953 |
{roadErr && <span className="cg-cal-nodate">{roadErr}</span>}
|
| 1954 |
|
| 1955 |
+
{/* ββ STANDING RULE 1's SECOND SENTENCE, WHICH IS THE HALF THAT GETS DROPPED: a
|
| 1956 |
+
limit that cannot be removed is REPORTED, with its cause and what to do about
|
| 1957 |
+
it, never silently enforced. Two different sentences because they are two
|
| 1958 |
+
different situations and only one of them is the user's doing.
|
| 1959 |
+
β NOT a `cg-cal-nodate` (the red one). Neither of these is an error: the first
|
| 1960 |
+
says what the panel took on the user's behalf, the second warns about a click
|
| 1961 |
+
that has not been spent yet. */}
|
| 1962 |
+
{/* β THE FIRST NOTE RETIRES ITSELF THE MOMENT IT STOPS BEING TRUE. `autoCapped` is
|
| 1963 |
+
what the auto-fill left out, and it stays set for as long as the panel is open
|
| 1964 |
+
-- but the sentence it prints is about the CURRENT cohort, and a person who
|
| 1965 |
+
then deselects half the pins is no longer routing "the first 100". Gated on the
|
| 1966 |
+
selection still being exactly the slice that was taken, so the disclosure
|
| 1967 |
+
disappears with the situation it describes rather than becoming a small lie in
|
| 1968 |
+
the corner of the panel. */}
|
| 1969 |
+
{autoCapped > 0 && customerRoutable.length === ROUTE_STOP_CAP && (
|
| 1970 |
+
<span className="cg-map-route-note">
|
| 1971 |
+
Routing the first {ROUTE_STOP_CAP.toLocaleString()} pins in this view, in the
|
| 1972 |
+
order the view is sorted. {autoCapped.toLocaleString()} more are mapped here:
|
| 1973 |
+
the routing service takes {ROUTE_STOP_CAP.toLocaleString()} stops in one
|
| 1974 |
+
request, so sort or filter the view to choose which ones travel.
|
| 1975 |
+
</span>
|
| 1976 |
+
)}
|
| 1977 |
+
{customerRoutable.length > ROUTE_STOP_CAP && (
|
| 1978 |
+
<span className="cg-map-route-note">
|
| 1979 |
+
{customerRoutable.length.toLocaleString()} stops selected. The routing service
|
| 1980 |
+
takes {ROUTE_STOP_CAP.toLocaleString()} in one request, so it will refuse the
|
| 1981 |
+
road answer for this many. The sequence and the straight line estimate below
|
| 1982 |
+
still hold.
|
| 1983 |
+
</span>
|
| 1984 |
+
)}
|
| 1985 |
+
|
| 1986 |
+
{/* ββ OWNER ITEM 3b (2026-08-23) β THE TWO CONTROLS THAT SET UP A ROUTE COME FIRST ββ
|
| 1987 |
+
Owner: *"add a record AND visit order function should be moved to the top, above
|
| 1988 |
+
the Start section of the Route navigation."* They used to sit BELOW the stop list,
|
| 1989 |
+
which put the two things you reach for while building a route (bring another
|
| 1990 |
+
customer in; choose the column the numbers land in) behind a list that is 66 rows
|
| 1991 |
+
long on a real day.
|
| 1992 |
+
β THE SAVE BUTTON AND THE GOOGLE LINKS TRAVEL WITH THE SELECT, not with the old
|
| 1993 |
+
position. Their note below says position is part of the instruction: the links sit
|
| 1994 |
+
BETWEEN the select and its Save button so the block reads as one committing step.
|
| 1995 |
+
Splitting them here to leave Save at the bottom would break the older instruction
|
| 1996 |
+
while honouring the newer one. ββ */}
|
| 1997 |
+
{/* ββ ITEM 9: add a record the view is not showing ββββββββββββββββββββββββββββββ */}
|
| 1998 |
+
{allRows && allRows.length > 0 && (
|
| 1999 |
+
<RecordPicker
|
| 2000 |
+
label="Add a record"
|
| 2001 |
+
placeholder="Search the database"
|
| 2002 |
+
emptyNote="Every record in your book is already on this route."
|
| 2003 |
+
options={addableRecords}
|
| 2004 |
+
onPick={addRecord}
|
| 2005 |
+
/>
|
| 2006 |
+
)}
|
| 2007 |
+
|
| 2008 |
+
{/* ββ ITEM 8: the visit order field, and its committing button ββββββββββββββββββ
|
| 2009 |
+
ββ W38-T20 β THE ORDER BECOMES A COLUMN EVERY PERMITTED COLLEAGUE READS.
|
| 2010 |
+
The number written per record is the INVERSE of the planner's permutation (see
|
| 2011 |
+
`saveRouteOrder`), the field is tenant-wide and grant-governed, and the
|
| 2012 |
+
fingerprint it was solved from rides it so a later reader is TOLD it is out of
|
| 2013 |
+
date rather than shown yesterday's numbers as today's.
|
| 2014 |
+
β ITEM 8 β "New column" reads "New field": `ColumnMenu` calls these fields
|
| 2015 |
+
everywhere else, and one surface calling them columns is the kind of split
|
| 2016 |
+
vocabulary a person has to translate. The SERVER key is untouched. */}
|
| 2017 |
+
{plan && (
|
| 2018 |
+
<>
|
| 2019 |
+
<label className="cg-map-route-opt cg-route-field">
|
| 2020 |
+
Visit order field
|
| 2021 |
+
<select
|
| 2022 |
+
className="cg-route-select"
|
| 2023 |
+
value={saveTarget}
|
| 2024 |
+
aria-label="Which visit order field to write"
|
| 2025 |
+
onChange={(e) => {
|
| 2026 |
+
setSaveTarget(e.target.value);
|
| 2027 |
+
setRouteStartPid(null);
|
| 2028 |
+
setSaveMsg(null);
|
| 2029 |
+
setSaveErr(null);
|
| 2030 |
+
}}
|
| 2031 |
+
>
|
| 2032 |
+
<option value="">New field</option>
|
| 2033 |
+
{(routeCols || [])
|
| 2034 |
+
.filter((f) => f.mine)
|
| 2035 |
+
.map((f) => (
|
| 2036 |
+
<option key={f.key} value={f.key}>
|
| 2037 |
+
{f.label}
|
| 2038 |
+
</option>
|
| 2039 |
+
))}
|
| 2040 |
+
</select>
|
| 2041 |
+
</label>
|
| 2042 |
+
{/* ββ ITEM 4: the hand-off links, ONE PER LINE, DIRECTLY under the visit order
|
| 2043 |
+
field ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2044 |
+
They were a `flex-wrap` cluster of chips, unreadable the moment a route
|
| 2045 |
+
needs more than one Google leg. Stacked, each on its own row, the list reads
|
| 2046 |
+
as what it is: leg 1, then leg 2.
|
| 2047 |
+
β POSITION IS PART OF THE INSTRUCTION, not a detail. They sit between the
|
| 2048 |
+
select and its Save button rather than after the whole block, because the
|
| 2049 |
+
block's tail can carry a stale marker, a shared-orders note and two message
|
| 2050 |
+
rows, and "under the Visit order column" stops being true the moment three
|
| 2051 |
+
of those render between the two. */}
|
| 2052 |
+
{plan.links.length > 0 && (
|
| 2053 |
+
<div className="cg-map-google-links" aria-label="Google Maps route links">
|
| 2054 |
+
{plan.links.map((link) => (
|
| 2055 |
+
<a
|
| 2056 |
+
key={link.index}
|
| 2057 |
+
href={link.url}
|
| 2058 |
+
target="_blank"
|
| 2059 |
+
rel="noopener noreferrer"
|
| 2060 |
+
title={`Open Google Maps route ${link.index} in a new tab`}
|
| 2061 |
+
>
|
| 2062 |
+
Google Maps route {link.index}
|
| 2063 |
+
</a>
|
| 2064 |
+
))}
|
| 2065 |
+
</div>
|
| 2066 |
+
)}
|
| 2067 |
+
{/* ββ ITEMS 4 AND 5: "Save route", and it ASKS FOR THE NAME βββββββββββββββββ
|
| 2068 |
+
β ITEM 4 β the button read "Save visit order". Owner: *"Change the button
|
| 2069 |
+
called 'Save visit order' to 'Save route'."* The FIELD is still the visit
|
| 2070 |
+
order (that is what the numbers in it are); the ACT is saving a route.
|
| 2071 |
+
β ITEM 5 β a NEW field now opens a name box first, pre-filled with the
|
| 2072 |
+
server's next free "Route N". Updating a field that already exists does not
|
| 2073 |
+
prompt: it already has a name, and asking again would invite a rename
|
| 2074 |
+
through a door that re-solves numbers rather than through Edit field.
|
| 2075 |
+
β AN INLINE STEP, NOT A BROWSER `prompt()`. A modal dialog blocks the page
|
| 2076 |
+
and cannot be styled, read by the design system, or dismissed with Escape
|
| 2077 |
+
the way every other overlay here is. */}
|
| 2078 |
+
{naming && !saveTarget ? (
|
| 2079 |
+
<div className="cg-route-name" role="group" aria-label="Name this route">
|
| 2080 |
+
<input
|
| 2081 |
+
className="cg-input"
|
| 2082 |
+
autoFocus
|
| 2083 |
+
value={nameDraft}
|
| 2084 |
+
aria-label="Route name"
|
| 2085 |
+
placeholder={nextLabel || "Name this route"}
|
| 2086 |
+
maxLength={120}
|
| 2087 |
+
onChange={(e) => setNameDraft(e.target.value)}
|
| 2088 |
+
onKeyDown={(e) => {
|
| 2089 |
+
if (e.key === "Enter") { e.preventDefault(); void saveRouteOrder(nameDraft); }
|
| 2090 |
+
if (e.key === "Escape") { e.preventDefault(); setNaming(false); }
|
| 2091 |
+
}}
|
| 2092 |
+
/>
|
| 2093 |
+
<span className="cg-route-name-actions">
|
| 2094 |
+
<button
|
| 2095 |
+
type="button"
|
| 2096 |
+
className="cg-btn cg-btn--primary"
|
| 2097 |
+
disabled={saveBusy || !nameDraft.trim()}
|
| 2098 |
+
onClick={() => void saveRouteOrder(nameDraft)}
|
| 2099 |
+
title="Save these visit numbers into a new field with this name"
|
| 2100 |
+
>
|
| 2101 |
+
{saveBusy ? "Saving" : "Save route"}
|
| 2102 |
+
</button>
|
| 2103 |
+
<button
|
| 2104 |
+
type="button"
|
| 2105 |
+
className="cg-btn"
|
| 2106 |
+
onClick={() => setNaming(false)}
|
| 2107 |
+
title="Do not save this route yet"
|
| 2108 |
+
>
|
| 2109 |
+
Cancel
|
| 2110 |
+
</button>
|
| 2111 |
+
</span>
|
| 2112 |
+
</div>
|
| 2113 |
+
) : (
|
| 2114 |
+
<button
|
| 2115 |
+
type="button"
|
| 2116 |
+
className="cg-btn cg-btn--primary cg-route-cta"
|
| 2117 |
+
disabled={saveBusy}
|
| 2118 |
+
onClick={() => {
|
| 2119 |
+
if (saveTarget) { void saveRouteOrder(); return; }
|
| 2120 |
+
setNameDraft(nextLabel);
|
| 2121 |
+
setSaveErr(null);
|
| 2122 |
+
setSaveMsg(null);
|
| 2123 |
+
setNaming(true);
|
| 2124 |
+
}}
|
| 2125 |
+
title={
|
| 2126 |
+
saveTarget
|
| 2127 |
+
? "Write these visit numbers into the saved field, for everyone it is shared with"
|
| 2128 |
+
: "Name this route and save these visit numbers as a new field"
|
| 2129 |
+
}
|
| 2130 |
+
>
|
| 2131 |
+
{saveBusy ? "Saving" : saveTarget ? "Update route" : "Save route"}
|
| 2132 |
+
</button>
|
| 2133 |
+
)}
|
| 2134 |
+
{/* β DERIVED, NEVER STORED. The saved field carries the fingerprint of the
|
| 2135 |
+
inputs it was solved from; this compares it against the cohort ON SCREEN
|
| 2136 |
+
NOW, so the marker cannot itself go out of date. */}
|
| 2137 |
+
{orderStale && (
|
| 2138 |
+
<span className="cg-map-route-note">
|
| 2139 |
+
Stale. The saved numbers were solved from different stops, so re-solving
|
| 2140 |
+
would change them.
|
| 2141 |
+
</span>
|
| 2142 |
+
)}
|
| 2143 |
+
{(routeCols || []).some((f) => !f.mine) && (
|
| 2144 |
+
<span className="cg-map-route-note">
|
| 2145 |
+
Shared orders you can read but not re-solve are not listed above.
|
| 2146 |
+
</span>
|
| 2147 |
+
)}
|
| 2148 |
+
{saveMsg && <span className="cg-map-route-note">{saveMsg}</span>}
|
| 2149 |
+
{saveErr && <span className="cg-cal-nodate">{saveErr}</span>}
|
| 2150 |
+
</>
|
| 2151 |
+
)}
|
| 2152 |
+
|
| 2153 |
{/* ββ ITEM 9: where the day starts, and it SEARCHES ββββββββββββββββββββββββββββββ
|
| 2154 |
β ITEM 6 removed the "Optional route start" address box above this, so the
|
| 2155 |
start is the record dropdown and nothing else. The `!plan.depot` guard the old
|
|
|
|
| 2239 |
</div>
|
| 2240 |
)}
|
| 2241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2242 |
{plan && routeOrder && (
|
| 2243 |
<button
|
| 2244 |
type="button"
|
|
|
|
| 2250 |
</button>
|
| 2251 |
)}
|
| 2252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2253 |
{/* β W37-T36 β NAMED, NOT COUNTED. "4 selected records have no location" tells you
|
| 2254 |
something is missing and not WHICH visit you are about to fail to make, and the
|
| 2255 |
whole point of the chip is that the exclusion is not silent. Three inline so a
|
|
|
|
| 2317 |
className="cg-map-frame"
|
| 2318 |
tabIndex={0}
|
| 2319 |
role="group"
|
| 2320 |
+
aria-label="Map canvas. Arrow keys pan, plus and minus zoom, square brackets rotate, zero fits to data and faces north."
|
| 2321 |
onKeyDown={onFrameKeyDown}
|
| 2322 |
>
|
| 2323 |
<svg
|
|
|
|
| 2589 |
OUTSIDE the <svg> deliberately: a mousedown on a button inside it would
|
| 2590 |
begin a pan. Icons are SVG strokes β no emoji, no glyph font. The zoom
|
| 2591 |
buttons DISABLE at the limits, which is also how the honesty cap on
|
| 2592 |
+
zoom-in makes itself visible instead of just feeling stuck.
|
| 2593 |
+
ββ OWNER ITEM 1 (2026-08-23) β IT IS A NAVIGATION BAR NOW, AT THE TOP MIDDLE.
|
| 2594 |
+
Owner: *"the navigation for 'Zoom in (+)' etc. should not be at the top left of the
|
| 2595 |
+
Map. it should be at the top MIDDLE of the map, and horizontal. Make the icon bigger
|
| 2596 |
+
so its easier to see. Make it look like a proper navigation bar."* Centred, 34px keys
|
| 2597 |
+
with 20px glyphs, and two new ones: Rotate left and Rotate right, 5 degrees a click.
|
| 2598 |
+
β THE ROTATE PAIR BRACKETS THE CAMERA KEYS rather than sitting at one end. Turning
|
| 2599 |
+
left and turning right are one control with two directions; splitting them would
|
| 2600 |
+
leave a reader hunting for the second half of a pair. --- */}
|
| 2601 |
<div className="cg-map-ctl" role="group" aria-label="Map camera">
|
| 2602 |
+
<button
|
| 2603 |
+
type="button"
|
| 2604 |
+
className="cg-map-ctl-b"
|
| 2605 |
+
title={`Rotate left (${ROTATE_STEP} degrees per click, or press the [ key)`}
|
| 2606 |
+
aria-label="Rotate left"
|
| 2607 |
+
onClick={() => rotateBy(-ROTATE_STEP)}
|
| 2608 |
+
>
|
| 2609 |
+
{/* A dial arrow turning anticlockwise. The arrowhead is what says WHICH way, so it is
|
| 2610 |
+
drawn as a filled wedge rather than a stroked chevron: at 20px a two-line chevron
|
| 2611 |
+
on a curve reads as a kink in the curve. */}
|
| 2612 |
+
<svg viewBox="0 0 20 20" aria-hidden="true">
|
| 2613 |
+
<path d="M5.2 7.4A6 6 0 1 1 4 11" />
|
| 2614 |
+
<path className="cg-map-ctl-head" d="M2.4 4.2 6.2 8.1 2.1 8.6z" />
|
| 2615 |
+
</svg>
|
| 2616 |
+
</button>
|
| 2617 |
<button
|
| 2618 |
type="button"
|
| 2619 |
className="cg-map-ctl-b"
|
|
|
|
| 2652 |
<button
|
| 2653 |
type="button"
|
| 2654 |
className="cg-map-ctl-b"
|
| 2655 |
+
// β ITEM 1 β THE TITLE EARNED A SECOND CLAUSE because the button gained a second
|
| 2656 |
+
// job: `fit` carries no bearing, so this is also the way back to north. A control
|
| 2657 |
+
// that silently un-rotates the map is a surprise; one that says it does is the undo.
|
| 2658 |
+
title="Fit to data and face north (0)"
|
| 2659 |
+
aria-label="Fit to data and face north"
|
| 2660 |
onClick={doFit}
|
| 2661 |
>
|
| 2662 |
<svg viewBox="0 0 16 16" aria-hidden="true">
|
|
|
|
| 2710 |
<path d="M8.6 3.4h4v4M12.6 3.4 7.4 8.6" />
|
| 2711 |
</svg>
|
| 2712 |
</a>
|
| 2713 |
+
<button
|
| 2714 |
+
type="button"
|
| 2715 |
+
className="cg-map-ctl-b"
|
| 2716 |
+
title={`Rotate right (${ROTATE_STEP} degrees per click, or press the ] key)`}
|
| 2717 |
+
aria-label="Rotate right"
|
| 2718 |
+
onClick={() => rotateBy(ROTATE_STEP)}
|
| 2719 |
+
>
|
| 2720 |
+
{/* The mirror of Rotate left, and drawn as its mirror rather than re-derived, so the
|
| 2721 |
+
two cannot end up subtly different weights on the same bar. */}
|
| 2722 |
+
<svg viewBox="0 0 20 20" aria-hidden="true">
|
| 2723 |
+
<path d="M14.8 7.4A6 6 0 1 0 16 11" />
|
| 2724 |
+
<path className="cg-map-ctl-head" d="M17.6 4.2 13.8 8.1 17.9 8.6z" />
|
| 2725 |
+
</svg>
|
| 2726 |
+
</button>
|
| 2727 |
</div>
|
| 2728 |
|
| 2729 |
{/* --- W37-T35 β THE CREDIT LINE. β A LICENCE TERM, NOT DECORATION.
|
web/src/customer-grid/apiBridge.ts
CHANGED
|
@@ -732,7 +732,7 @@ export async function patchTopicRow(
|
|
| 732 |
// through into the cached rows, so a remount within the cache window
|
| 733 |
// shows this edit instead of the pre-edit pull.
|
| 734 |
const body = (await readJson(res)) as
|
| 735 |
-
{ updates?: Record<string, unknown>; cleared?: unknown } | null;
|
| 736 |
const accepted = body?.updates;
|
| 737 |
const cleared = Array.isArray(body?.cleared)
|
| 738 |
? (body.cleared as unknown[]).filter((k): k is string => typeof k === "string")
|
|
@@ -747,6 +747,23 @@ export async function patchTopicRow(
|
|
| 747 |
// A user-table edit may change a reciprocal Link or a Rollup in another database. Their
|
| 748 |
// row payloads share no cache key with this table, so invalidate the user-table family and
|
| 749 |
// let the active grid re-read the server's materialised relationship cells.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 750 |
if (topic.rowsPath.startsWith("tables/")) {
|
| 751 |
// β WAVE 30 β `odoo-tables/` too. A Link or a Rollup can fold a CONNECTED table's rows
|
| 752 |
// into this one, so a user-table edit can move a cell on a read-through grid served by
|
|
@@ -1010,6 +1027,51 @@ export async function deleteRouteOrderField(fieldKey: string): Promise<boolean>
|
|
| 1010 |
}
|
| 1011 |
}
|
| 1012 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1013 |
export async function deleteTableField(
|
| 1014 |
tableKey: string,
|
| 1015 |
fieldKey: string
|
|
|
|
| 732 |
// through into the cached rows, so a remount within the cache window
|
| 733 |
// shows this edit instead of the pre-edit pull.
|
| 734 |
const body = (await readJson(res)) as
|
| 735 |
+
{ updates?: Record<string, unknown>; cleared?: unknown; routeSwaps?: unknown } | null;
|
| 736 |
const accepted = body?.updates;
|
| 737 |
const cleared = Array.isArray(body?.cleared)
|
| 738 |
? (body.cleared as unknown[]).filter((k): k is string => typeof k === "string")
|
|
|
|
| 747 |
// A user-table edit may change a reciprocal Link or a Rollup in another database. Their
|
| 748 |
// row payloads share no cache key with this table, so invalidate the user-table family and
|
| 749 |
// let the active grid re-read the server's materialised relationship cells.
|
| 750 |
+
/**
|
| 751 |
+
* ββ OWNER ITEM 7 (2026-08-23) β A ROUTE RANK EDIT MOVED **ANOTHER** ROW.
|
| 752 |
+
*
|
| 753 |
+
* The route order column is a permutation, so typing 14 over 13 hands 13 to whoever was
|
| 754 |
+
* holding 14 (`routes_customers._patch_route_ranks`). The optimistic copy above covers
|
| 755 |
+
* this pid only, and the displaced record is one the client never typed in, so nothing
|
| 756 |
+
* else on this path would ever repaint it β the same class of miss `cleared` exists for,
|
| 757 |
+
* one row over instead of one column over.
|
| 758 |
+
*
|
| 759 |
+
* β THE CACHE IS DROPPED BEFORE THE SIGNAL. `fetchTopicRows` holds a window per topic, so
|
| 760 |
+
* a refetch served from it would return the payload from before this write and the swap
|
| 761 |
+
* would appear to have been undone.
|
| 762 |
+
*/
|
| 763 |
+
if (Array.isArray(body?.routeSwaps) && body.routeSwaps.length > 0) {
|
| 764 |
+
clearTopicRowsCache(topic.rowsPath);
|
| 765 |
+
signal(ROWS_STALE_EVENT);
|
| 766 |
+
}
|
| 767 |
if (topic.rowsPath.startsWith("tables/")) {
|
| 768 |
// β WAVE 30 β `odoo-tables/` too. A Link or a Rollup can fold a CONNECTED table's rows
|
| 769 |
// into this one, so a user-table edit can move a cell on a read-through grid served by
|
|
|
|
| 1027 |
}
|
| 1028 |
}
|
| 1029 |
|
| 1030 |
+
/**
|
| 1031 |
+
* ββ OWNER ITEM 6 (2026-08-23) β RENAME A ROUTE ORDER FIELD, OR WRITE ITS DESCRIPTION.
|
| 1032 |
+
*
|
| 1033 |
+
* β ITS OWN DOOR, for the reason `deleteRouteOrderField` above states: a route order is a SHARED
|
| 1034 |
+
* column on the customers REGISTRY topic, so neither the per-user `field_upsert` event nor the
|
| 1035 |
+
* `ut_*` definition PATCH reaches it. Sending this rename down the overlay event would fork the
|
| 1036 |
+
* tenant-wide column into a private copy of itself wearing the new name, and the shared one would
|
| 1037 |
+
* keep the old name for everybody else.
|
| 1038 |
+
*
|
| 1039 |
+
* β THE DESCRIPTION TAKES THE SAME DOOR, and that is not tidiness. The Edit-field pane writes
|
| 1040 |
+
* one through `onNote`, which is the per-user `field_upsert` this function exists to avoid; the
|
| 1041 |
+
* server's docstring traces exactly how that forks the column. One pane, one write path.
|
| 1042 |
+
*
|
| 1043 |
+
* β NOT optimistic. The server refuses a column somebody else planned and a name another column
|
| 1044 |
+
* already wears; renaming it on screen first would show the user a name the store never took.
|
| 1045 |
+
*/
|
| 1046 |
+
export async function patchRouteOrderField(
|
| 1047 |
+
fieldKey: string,
|
| 1048 |
+
patch: { label?: string; note?: string }
|
| 1049 |
+
): Promise<boolean> {
|
| 1050 |
+
try {
|
| 1051 |
+
const res = await fetch(
|
| 1052 |
+
`${API_V1}/customers/route-order/${encodeURIComponent(fieldKey)}`,
|
| 1053 |
+
{
|
| 1054 |
+
method: "PATCH",
|
| 1055 |
+
credentials: CREDENTIALS,
|
| 1056 |
+
headers: { "Content-Type": "application/json" },
|
| 1057 |
+
body: JSON.stringify(patch),
|
| 1058 |
+
}
|
| 1059 |
+
);
|
| 1060 |
+
if (handledSession(res)) return false;
|
| 1061 |
+
if (!res.ok) {
|
| 1062 |
+
// The server's own sentence: "somebody else planned this route", "that name is taken" and
|
| 1063 |
+
// "that is not a route column" need three different things from the person reading them.
|
| 1064 |
+
const body = (await readJson(res)) as { error?: { message?: string } } | null;
|
| 1065 |
+
signal(TOAST_EVENT, refusalMessage(body, res.status));
|
| 1066 |
+
return false;
|
| 1067 |
+
}
|
| 1068 |
+
return true;
|
| 1069 |
+
} catch {
|
| 1070 |
+
signal(TOAST_EVENT, "That field could not be changed. Check your connection and try again.");
|
| 1071 |
+
return false;
|
| 1072 |
+
}
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
export async function deleteTableField(
|
| 1076 |
tableKey: string,
|
| 1077 |
fieldKey: string
|
web/src/customer-grid/mapProjection.ts
CHANGED
|
@@ -37,6 +37,34 @@ export interface View {
|
|
| 37 |
k: number;
|
| 38 |
tx: number;
|
| 39 |
ty: number;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
/** lon/lat -> the fixed projected plane (0..WORLD on both axes). */
|
|
@@ -57,7 +85,11 @@ export function unproject(p: Pt): { lon: number; lat: number } {
|
|
| 57 |
|
| 58 |
/** Screen -> the fixed projected plane, through a view. The inverse of `toScreen`. */
|
| 59 |
export function fromScreen(s: Pt, view: View): Pt {
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
}
|
| 62 |
|
| 63 |
// -------------------------------------------------------- the Google hand-off
|
|
@@ -120,7 +152,33 @@ export function googleDirectionsUrl(lat: number, lon: number): string {
|
|
| 120 |
|
| 121 |
/** Projected point -> screen, through a view. */
|
| 122 |
export function toScreen(p: Pt, view: View): Pt {
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
|
@@ -158,11 +216,22 @@ export function fitView(
|
|
| 158 |
}
|
| 159 |
|
| 160 |
/** Zoom by `factor` while holding the point under (mx, my) still β the gesture
|
| 161 |
-
* every map has and the reason zoom cannot be a plain scale on the group.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
export function zoomAt(view: View, factor: number, mx: number, my: number, kMin: number, kMax: number): View {
|
| 163 |
const k = Math.max(kMin, Math.min(kMax, view.k * factor));
|
| 164 |
if (k === view.k) return view;
|
| 165 |
return {
|
|
|
|
| 166 |
k,
|
| 167 |
tx: mx - ((mx - view.tx) * k) / view.k,
|
| 168 |
ty: my - ((my - view.ty) * k) / view.k,
|
|
@@ -599,6 +668,25 @@ function _fnv1a(text: string, base: number): string {
|
|
| 599 |
return h.toString(16).padStart(8, "0");
|
| 600 |
}
|
| 601 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
// --------------------------------------------------- handing the route over
|
| 603 |
//
|
| 604 |
// MEASURED 2026-07-29, do not re-derive: Google Maps URLs need NO API key and
|
|
|
|
| 37 |
k: number;
|
| 38 |
tx: number;
|
| 39 |
ty: number;
|
| 40 |
+
/**
|
| 41 |
+
* ββ OWNER ITEM 1 (2026-08-23) β THE BEARING, IN DEGREES CLOCKWISE. Absent is north up.
|
| 42 |
+
*
|
| 43 |
+
* The painted transform is `translate(tx ty) rotate(rot) scale(k)`, i.e. `t + R(rot) . k . p`,
|
| 44 |
+
* which is exactly what `toScreen` computes and `fromScreen` inverts. Three consequences worth
|
| 45 |
+
* writing down because each one is a function this wave did NOT have to change:
|
| 46 |
+
*
|
| 47 |
+
* Β· `zoomAt` is bearing-agnostic. Holding the point under the cursor still means
|
| 48 |
+
* `t' = m - (k'/k)(m - t)` whatever R is, because R cancels on both sides.
|
| 49 |
+
* Β· PANNING is bearing-agnostic. `tx += dx` is applied AFTER the rotation, so a drag still
|
| 50 |
+
* moves the map the way the hand moved.
|
| 51 |
+
* Β· `fitView` needs no rotation at all, because Fit RESETS the bearing (see MapView's
|
| 52 |
+
* `doFit`). A fit that preserved a bearing would have to frame the AABB of the ROTATED
|
| 53 |
+
* points, and a compass that cannot be put back to north is a control with no undo.
|
| 54 |
+
*
|
| 55 |
+
* β OPTIONAL, AND THAT IS LOAD-BEARING RATHER THAN LAZY. Every existing caller and every
|
| 56 |
+
* fixture in `_test/map.test.ts` writes `{k, tx, ty}`; `rot` undefined reads as 0 and their
|
| 57 |
+
* arithmetic is byte-identical, so this widening cannot silently change a single one of them.
|
| 58 |
+
*/
|
| 59 |
+
rot?: number;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/** `cos` and `sin` of a view's bearing. One place converts degrees to radians. */
|
| 63 |
+
function _bearing(view: View): { c: number; s: number } {
|
| 64 |
+
const rot = view.rot ?? 0;
|
| 65 |
+
if (!rot) return { c: 1, s: 0 };
|
| 66 |
+
const rad = (rot * Math.PI) / 180;
|
| 67 |
+
return { c: Math.cos(rad), s: Math.sin(rad) };
|
| 68 |
}
|
| 69 |
|
| 70 |
/** lon/lat -> the fixed projected plane (0..WORLD on both axes). */
|
|
|
|
| 85 |
|
| 86 |
/** Screen -> the fixed projected plane, through a view. The inverse of `toScreen`. */
|
| 87 |
export function fromScreen(s: Pt, view: View): Pt {
|
| 88 |
+
const u = (s.x - view.tx) / view.k;
|
| 89 |
+
const v = (s.y - view.ty) / view.k;
|
| 90 |
+
const { c, s: sn } = _bearing(view);
|
| 91 |
+
// R(-rot) applied to the unscaled offset. At rot = 0 this is `{x: u, y: v}` exactly.
|
| 92 |
+
return { x: u * c + v * sn, y: -u * sn + v * c };
|
| 93 |
}
|
| 94 |
|
| 95 |
// -------------------------------------------------------- the Google hand-off
|
|
|
|
| 152 |
|
| 153 |
/** Projected point -> screen, through a view. */
|
| 154 |
export function toScreen(p: Pt, view: View): Pt {
|
| 155 |
+
const { c, s } = _bearing(view);
|
| 156 |
+
// t + R(rot) . k . p, which is the SVG transform list `translate(tx ty) rotate(rot) scale(k)`
|
| 157 |
+
// read right to left. At rot = 0 this is `tx + p.x * k` exactly, so nothing that never rotates
|
| 158 |
+
// changes by a floating-point ulp.
|
| 159 |
+
return {
|
| 160 |
+
x: view.tx + view.k * (p.x * c - p.y * s),
|
| 161 |
+
y: view.ty + view.k * (p.x * s + p.y * c),
|
| 162 |
+
};
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
/**
|
| 166 |
+
* ββ OWNER ITEM 1 (2026-08-23) β TURN THE MAP BY `deg`, HOLDING THE POINT AT (mx, my) STILL.
|
| 167 |
+
*
|
| 168 |
+
* `zoomAt`'s sibling, and written the same way for the same reason: the anchored version is the
|
| 169 |
+
* only one that does not feel like the map jumping. The buttons pass the viewport centre, which
|
| 170 |
+
* is what a compass control means by "turn".
|
| 171 |
+
*
|
| 172 |
+
* β THE BEARING WRAPS INTO [0, 360). Without it a user who holds Rotate left for a minute has a
|
| 173 |
+
* view carrying -305 degrees, which reads correctly and prints wrong the moment anything shows it.
|
| 174 |
+
*/
|
| 175 |
+
export function rotateAt(view: View, deg: number, mx: number, my: number): View {
|
| 176 |
+
const at = fromScreen({ x: mx, y: my }, view);
|
| 177 |
+
const rot = (((view.rot ?? 0) + deg) % 360 + 360) % 360;
|
| 178 |
+
const turned: View = { ...view, rot };
|
| 179 |
+
// Put `at` back under (mx, my): solve `m = t + R(rot') . k . at` for t.
|
| 180 |
+
const moved = toScreen(at, { ...turned, tx: 0, ty: 0 });
|
| 181 |
+
return { ...turned, tx: mx - moved.x, ty: my - moved.y };
|
| 182 |
}
|
| 183 |
|
| 184 |
/**
|
|
|
|
| 216 |
}
|
| 217 |
|
| 218 |
/** Zoom by `factor` while holding the point under (mx, my) still β the gesture
|
| 219 |
+
* every map has and the reason zoom cannot be a plain scale on the group.
|
| 220 |
+
*
|
| 221 |
+
* ββ OWNER ITEM 1 (2026-08-23) β `...view` IS LOAD-BEARING AND WAS ADDED AFTER A MEASUREMENT.
|
| 222 |
+
* The recentring arithmetic below is genuinely bearing-agnostic: `t' = m - (k'/k)(m - t)` holds
|
| 223 |
+
* whatever R is, because R cancels on both sides. That was reasoned about, believed, and WRONG
|
| 224 |
+
* about this function anyway β not because the maths was wrong but because the RETURN was a
|
| 225 |
+
* fresh object literal, so every zoom silently dropped `rot` and snapped the map back to north.
|
| 226 |
+
* The gate leg caught it on its first run: the anchor point landed 1,900 px away.
|
| 227 |
+
* β So the rule this records is not about rotation. It is that a function which rebuilds a
|
| 228 |
+
* value instead of amending it has to be revisited every time the value grows a field, and the
|
| 229 |
+
* only defence is to amend. [[a-widened-record-needs-its-builders-revisited]] */
|
| 230 |
export function zoomAt(view: View, factor: number, mx: number, my: number, kMin: number, kMax: number): View {
|
| 231 |
const k = Math.max(kMin, Math.min(kMax, view.k * factor));
|
| 232 |
if (k === view.k) return view;
|
| 233 |
return {
|
| 234 |
+
...view,
|
| 235 |
k,
|
| 236 |
tx: mx - ((mx - view.tx) * k) / view.k,
|
| 237 |
ty: my - ((my - view.ty) * k) / view.k,
|
|
|
|
| 668 |
return h.toString(16).padStart(8, "0");
|
| 669 |
}
|
| 670 |
|
| 671 |
+
/**
|
| 672 |
+
* ββ OWNER ITEM 3 (2026-08-23) β THE MOST STOPS ONE ROUTE MAY CARRY.
|
| 673 |
+
*
|
| 674 |
+
* β THIS NUMBER IS NOT A TASTE CALL AND IT IS NOT OURS. It MIRRORS
|
| 675 |
+
* `aios-web/api/routes_geo.py::MAX_ROUTE_STOPS`, the ceiling the road-routing provider is asked
|
| 676 |
+
* under. A plan longer than this is refused by `POST /geo/route` with `too_many_stops`, so a
|
| 677 |
+
* client cap of anything higher buys nothing but a spent click and a red message; a lower one
|
| 678 |
+
* would withhold stops the service would happily have taken.
|
| 679 |
+
*
|
| 680 |
+
* β THE LOCAL SOLVE IS NOWHERE NEAR THE BINDING CONSTRAINT, and that is worth writing down so
|
| 681 |
+
* nobody "optimises" the wrong end. `planRoute` is nearest-neighbour plus 2-opt: at 100 stops
|
| 682 |
+
* that is ~10k distance calls to construct and ~120k across 24 improvement passes, single-digit
|
| 683 |
+
* milliseconds. The provider request is what stops at 100.
|
| 684 |
+
*
|
| 685 |
+
* β REPORTED, NEVER SILENT (standing rule 1's second sentence). Wherever this cap actually bites,
|
| 686 |
+
* the panel says so, says why, and says which stops it took.
|
| 687 |
+
*/
|
| 688 |
+
export const ROUTE_STOP_CAP = 100;
|
| 689 |
+
|
| 690 |
// --------------------------------------------------- handing the route over
|
| 691 |
//
|
| 692 |
// MEASURED 2026-07-29, do not re-derive: Google Maps URLs need NO API key and
|
web/src/index.css
CHANGED
|
@@ -1244,9 +1244,16 @@ body {
|
|
| 1244 |
|
| 1245 |
/* Map encodings are a second navigation row, matching the time-series controls below its
|
| 1246 |
primary toolbar. They stay in document flow, while route planning is map-local overlay chrome. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1247 |
.cg-map-settings {
|
| 1248 |
flex: 0 0 auto;
|
| 1249 |
-
min-height:
|
| 1250 |
display: flex;
|
| 1251 |
align-items: center;
|
| 1252 |
gap: 6px;
|
|
@@ -1255,7 +1262,7 @@ body {
|
|
| 1255 |
background: var(--lp-surface);
|
| 1256 |
color: var(--lp-muted);
|
| 1257 |
font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
| 1258 |
-
font-size: var(--lp-fs-
|
| 1259 |
line-height: 1.3;
|
| 1260 |
}
|
| 1261 |
.cg-map-settings-label {
|
|
@@ -4739,13 +4746,18 @@ body > .cg-overlay {
|
|
| 4739 |
outline-offset: 2px;
|
| 4740 |
border-radius: 2px;
|
| 4741 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4742 |
.cg-map-route-toggle {
|
| 4743 |
flex: 0 0 auto;
|
| 4744 |
-
|
| 4745 |
-
|
|
|
|
| 4746 |
border: 1px solid var(--lp-line);
|
| 4747 |
-
border-radius:
|
| 4748 |
-
background:
|
| 4749 |
color: var(--lp-ink);
|
| 4750 |
font: inherit;
|
| 4751 |
cursor: pointer;
|
|
@@ -4830,26 +4842,37 @@ body > .cg-overlay {
|
|
| 4830 |
flows through here for free. */
|
| 4831 |
/* β OWNER ITEM 5 (2026-08-23) β THE CAMERA BAR MOVED FROM THE RIGHT EDGE TO THE TOP.
|
| 4832 |
It was a vertical stack pinned `right: 10px`, which is the map convention and is also the
|
| 4833 |
-
corner a reader reaches last on a left-to-right surface. The owner could not find it.
|
| 4834 |
-
|
| 4835 |
-
|
| 4836 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4837 |
.cg-map-ctl {
|
| 4838 |
position: absolute;
|
| 4839 |
top: 10px;
|
| 4840 |
-
left:
|
|
|
|
| 4841 |
display: flex;
|
| 4842 |
flex-direction: row;
|
| 4843 |
background: #fff;
|
| 4844 |
border: 1px solid var(--lp-line);
|
| 4845 |
-
border-radius:
|
| 4846 |
overflow: hidden;
|
| 4847 |
-
box-shadow: 0
|
| 4848 |
pointer-events: auto;
|
| 4849 |
}
|
| 4850 |
.cg-map-ctl-b {
|
| 4851 |
-
width:
|
| 4852 |
-
height:
|
| 4853 |
display: flex;
|
| 4854 |
align-items: center;
|
| 4855 |
justify-content: center;
|
|
@@ -4873,14 +4896,25 @@ body > .cg-overlay {
|
|
| 4873 |
/* The Google hand-off sits in the same cluster and must read as one of the
|
| 4874 |
controls, not as a link β it is an <a> only because it navigates. */
|
| 4875 |
a.cg-map-ctl-b { text-decoration: none; }
|
| 4876 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4877 |
.cg-map-ctl-b path {
|
| 4878 |
fill: none;
|
| 4879 |
stroke: currentColor;
|
| 4880 |
-
stroke-width: 1.
|
| 4881 |
stroke-linecap: round;
|
| 4882 |
stroke-linejoin: round;
|
| 4883 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4884 |
.cg-map-frame svg.cg-map-svg {
|
| 4885 |
width: 100%;
|
| 4886 |
height: 100%;
|
|
@@ -5036,6 +5070,22 @@ a.cg-map-ctl-b { text-decoration: none; }
|
|
| 5036 |
white-space: normal;
|
| 5037 |
}
|
| 5038 |
.cg-map-geo .cg-map-geo-cta { width: 100%; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5039 |
.cg-route-popover .cg-map-route-sum { white-space: normal; line-height: 1.45; }
|
| 5040 |
.cg-route-popover .cg-map-route-opt {
|
| 5041 |
align-items: stretch;
|
|
|
|
| 1244 |
|
| 1245 |
/* Map encodings are a second navigation row, matching the time-series controls below its
|
| 1246 |
primary toolbar. They stay in document flow, while route planning is map-local overlay chrome. */
|
| 1247 |
+
/* β OWNER ITEM 2 (2026-08-23) β ONE TYPE SIZE ACROSS THIS ROW.
|
| 1248 |
+
The row set `--lp-fs-3xs` (11px) and `.cg-map-route-toggle` took it through `font: inherit`,
|
| 1249 |
+
while the two field pickers beside it are `.cg-select` and carry `--lp-fs-xs` (13px) with a
|
| 1250 |
+
30px box. So Route read two pixels smaller and six pixels shorter than its own neighbours β
|
| 1251 |
+
the owner's "the Route one is the only one with smaller font". The row now declares the SAME
|
| 1252 |
+
size the controls in it use, so a control written with `font: inherit` lands on it by
|
| 1253 |
+
construction rather than by being told twice. */
|
| 1254 |
.cg-map-settings {
|
| 1255 |
flex: 0 0 auto;
|
| 1256 |
+
min-height: 40px;
|
| 1257 |
display: flex;
|
| 1258 |
align-items: center;
|
| 1259 |
gap: 6px;
|
|
|
|
| 1262 |
background: var(--lp-surface);
|
| 1263 |
color: var(--lp-muted);
|
| 1264 |
font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
| 1265 |
+
font-size: var(--lp-fs-xs);
|
| 1266 |
line-height: 1.3;
|
| 1267 |
}
|
| 1268 |
.cg-map-settings-label {
|
|
|
|
| 4746 |
outline-offset: 2px;
|
| 4747 |
border-radius: 2px;
|
| 4748 |
}
|
| 4749 |
+
/* β OWNER ITEM 2 β the same box as the pickers it sits beside: 30px tall, `--lp-r-md`, white
|
| 4750 |
+
ground, `--lp-fs-xs` through the row above. `.cg-select` is the shape being matched; this
|
| 4751 |
+
cannot simply BE `.cg-select` because that class is a form control's look and this is a
|
| 4752 |
+
disclosure toggle with an `is-open` state the selects have no equivalent of. */
|
| 4753 |
.cg-map-route-toggle {
|
| 4754 |
flex: 0 0 auto;
|
| 4755 |
+
box-sizing: border-box;
|
| 4756 |
+
height: 30px;
|
| 4757 |
+
padding: 0 10px;
|
| 4758 |
border: 1px solid var(--lp-line);
|
| 4759 |
+
border-radius: var(--lp-r-md);
|
| 4760 |
+
background: #ffffff;
|
| 4761 |
color: var(--lp-ink);
|
| 4762 |
font: inherit;
|
| 4763 |
cursor: pointer;
|
|
|
|
| 4842 |
flows through here for free. */
|
| 4843 |
/* β OWNER ITEM 5 (2026-08-23) β THE CAMERA BAR MOVED FROM THE RIGHT EDGE TO THE TOP.
|
| 4844 |
It was a vertical stack pinned `right: 10px`, which is the map convention and is also the
|
| 4845 |
+
corner a reader reaches last on a left-to-right surface. The owner could not find it.
|
| 4846 |
+
ββ OWNER ITEM 1, SAME DAY, SECOND CORRECTION: *"it should not be at the top left of the Map.
|
| 4847 |
+
it should be at the top MIDDLE of the map, and horizontal. Make the icon bigger so its easier
|
| 4848 |
+
to see. Make it look like a proper navigation bar."* So: centred on the frame, 34px keys with
|
| 4849 |
+
20px glyphs (was 28 and 16), a deeper shadow so it reads as chrome floating over the map
|
| 4850 |
+
rather than as a widget printed on it, and seven keys instead of five.
|
| 4851 |
+
β THE VERTICAL BAND IS WHAT KEEPS IT OFF THE ROUTE PANEL, and that is why the arithmetic is
|
| 4852 |
+
written down rather than eyeballed: the panel is `top: 48px`, and a 34px bar at `top: 10px`
|
| 4853 |
+
ends at 44px. Four pixels of clearance, and `verify_map.py` pins the panel's own geometry, so
|
| 4854 |
+
growing this bar past 38px is a change that has to come back here and argue.
|
| 4855 |
+
β CENTRED WITH `left: 50%` PLUS A TRANSLATE rather than `inset: 0` plus `margin: auto`: the
|
| 4856 |
+
bar must not become a full-width element, because the whole strip would then swallow pointer
|
| 4857 |
+
events across the top of the map even where no key is painted. The legends stay bottom left
|
| 4858 |
+
and the credit bottom right, so nothing else moved into a taken corner. */
|
| 4859 |
.cg-map-ctl {
|
| 4860 |
position: absolute;
|
| 4861 |
top: 10px;
|
| 4862 |
+
left: 50%;
|
| 4863 |
+
transform: translateX(-50%);
|
| 4864 |
display: flex;
|
| 4865 |
flex-direction: row;
|
| 4866 |
background: #fff;
|
| 4867 |
border: 1px solid var(--lp-line);
|
| 4868 |
+
border-radius: var(--lp-r-md);
|
| 4869 |
overflow: hidden;
|
| 4870 |
+
box-shadow: 0 2px 8px rgba(32, 36, 51, 0.16);
|
| 4871 |
pointer-events: auto;
|
| 4872 |
}
|
| 4873 |
.cg-map-ctl-b {
|
| 4874 |
+
width: 34px;
|
| 4875 |
+
height: 34px;
|
| 4876 |
display: flex;
|
| 4877 |
align-items: center;
|
| 4878 |
justify-content: center;
|
|
|
|
| 4896 |
/* The Google hand-off sits in the same cluster and must read as one of the
|
| 4897 |
controls, not as a link β it is an <a> only because it navigates. */
|
| 4898 |
a.cg-map-ctl-b { text-decoration: none; }
|
| 4899 |
+
/* β ITEM 1 β 20px glyphs, up from 16. The zoom keys are a plus and a minus: at 16px inside a
|
| 4900 |
+
28px key they read as hairlines, which is the "make the icon bigger so its easier to see" the
|
| 4901 |
+
owner asked for. The stroke thickens with them, or a 20px glyph drawn at 1.4 looks THINNER
|
| 4902 |
+
than the 16px one it replaced. */
|
| 4903 |
+
.cg-map-ctl-b svg { width: 20px; height: 20px; display: block; }
|
| 4904 |
.cg-map-ctl-b path {
|
| 4905 |
fill: none;
|
| 4906 |
stroke: currentColor;
|
| 4907 |
+
stroke-width: 1.6;
|
| 4908 |
stroke-linecap: round;
|
| 4909 |
stroke-linejoin: round;
|
| 4910 |
}
|
| 4911 |
+
/* The rotate arrowheads are the one FILLED mark on this bar. A stroked chevron at the end of a
|
| 4912 |
+
curve reads as a kink in the curve rather than as a direction, which on a pair of mirrored
|
| 4913 |
+
buttons is the only thing telling them apart. */
|
| 4914 |
+
.cg-map-ctl-b path.cg-map-ctl-head {
|
| 4915 |
+
fill: currentColor;
|
| 4916 |
+
stroke: none;
|
| 4917 |
+
}
|
| 4918 |
.cg-map-frame svg.cg-map-svg {
|
| 4919 |
width: 100%;
|
| 4920 |
height: 100%;
|
|
|
|
| 5070 |
white-space: normal;
|
| 5071 |
}
|
| 5072 |
.cg-map-geo .cg-map-geo-cta { width: 100%; }
|
| 5073 |
+
/* β OWNER ITEM 5 (2026-08-23) β THE NAME-THIS-ROUTE STEP, in the panel and not in a browser
|
| 5074 |
+
`prompt()`. Stacked because a 360px panel cannot hold a label, a text box and two buttons on
|
| 5075 |
+
one line without the buttons shrinking to unreadable stubs; the two actions then share a row,
|
| 5076 |
+
Save first because it is the one being confirmed. */
|
| 5077 |
+
.cg-route-name {
|
| 5078 |
+
display: flex;
|
| 5079 |
+
flex-direction: column;
|
| 5080 |
+
gap: 6px;
|
| 5081 |
+
width: 100%;
|
| 5082 |
+
}
|
| 5083 |
+
.cg-route-name .cg-input { width: 100%; }
|
| 5084 |
+
.cg-route-name-actions {
|
| 5085 |
+
display: flex;
|
| 5086 |
+
gap: 6px;
|
| 5087 |
+
}
|
| 5088 |
+
.cg-route-name-actions .cg-btn { flex: 1 1 0; justify-content: center; }
|
| 5089 |
.cg-route-popover .cg-map-route-sum { white-space: normal; line-height: 1.45; }
|
| 5090 |
.cg-route-popover .cg-map-route-opt {
|
| 5091 |
align-items: stretch;
|