Clone
11
Home
Shawn edited this page 2026-05-31 00:31:58 -04:00

Canteen Admin Server

Standalone FastAPI admin server extracted from the main canteen-asset-tracker.

Quick Start

cd ~/projects/canteen-admin-server
./run.sh
  • Port: 8090 (HTTP)
  • URL: https://admin.canteen.ourpad.casa (NPMPlus proxy ID 20)
  • DB: Shared ../canteen-asset-tracker/assets.db via CANTEEN_DB_PATH
  • Auth: admin / admin123 (also user shawn / Brett85!@)

Port Conflict Resolution (2026-05-23)

Port 8090 conflict fixed: stale admin server process (from a past Hermes gateway session) killed, canteen-admin.service now runs cleanly. Duplicate canteen-main.service (fought with canteen-asset-tracker.service for port 8901) removed. Final map: main :8901 (user systemd, boot-enabled), admin :8090 (system systemd, boot-enabled).

Port Conflict Resolution (2026-05-21)

Port 8090 conflict fixed: stale admin server process (from a past Hermes gateway session) killed, canteen-admin.service now runs cleanly. Duplicate canteen-main.service (fought with canteen-asset-tracker.service for port 8901) removed. Final map: main :8901 (user systemd, boot-enabled), admin :8090 (system systemd, boot-enabled).

Port 8900 was occupied by the Hermes webhook receiver. Admin server moved to port 8090. NPMPlus proxy updated: forward_port 8901 → 8090, forward_scheme https → http.

Endpoints

All standard admin CRUD endpoints for users, customers, locations, rooms, geofences, settings, activity log, stats, CSV exports, and database management.

Asset GPS Management (since 9794d80)

  • GET /api/assets/{id} — Lookup asset by ID
  • GET /api/assets/search?machine_id= — Lookup asset by machine ID
  • DELETE /api/assets/{id}/gps — Clear GPS coordinates (sets lat/lng to NULL)

The Export & Admin page has a "Clear Asset GPS" card where admins can enter an asset ID or machine ID, confirm, and clear GPS data.

Cantaloupe Sync API (since f7ffa0e)

Staged import pipeline for Cantaloupe machine data:

Method Path Description
POST /api/admin/cantaloupe/sync Upload Excel, parse, diff, store as pending batch
GET /api/admin/cantaloupe/batches List all sync batches (filterable by status)
GET /api/admin/cantaloupe/batches/{id} Full batch detail with row-level diff
POST /api/admin/cantaloupe/batches/{id}/approve Apply staged data (upsert assets/customers/locations)
POST /api/admin/cantaloupe/batches/{id}/reject Discard batch, clear raw_data
GET /api/admin/cantaloupe/batches/{id}/field-changes Flat list of per-field diffs with is_blank_fill flag
POST /api/admin/cantaloupe/batches/{id}/apply-field-changes Apply selected field changes only (granular per-field approval)
POST /api/admin/cantaloupe/batches/{id}/replacements Approve/reject individual machine replacement candidates

Database table: cantaloupe_sync_batches — id, status (pending/approved/rejected/error), created_at, approved_at, file_path, row_count, diff_summary (JSON), raw_data (JSON), error_message.

Column mapping: Heuristic word-subset matching of Excel headers to canteen schema fields (machine_id, serial_number, name, customer, location, address, etc.)

New columns (v4 migration, 2026-05-23):

  • dex_report_date — Cantaloupe "Last Dex Report Time" column (Python datetime → ISO)
  • deployed — Yes/No string from Excel export
  • pulled_date — Equipment removal/pulled date

Tests: 10 unit tests (test_cantaloupe_sync.py) + 23 integration tests (test_sync_api.py). All 33 pass.

Machine replacement detection (78f4b74): The sync pipeline now detects when a new Asset ID appears at the same customer + address as an existing live asset not in the current import — indicating a potential machine replacement.

  • high confidence: exact address match
  • medium confidence: same building_name or same street name
  • Results stored in diff_summary.replacements array: {id, new_machine_id, old_machine_id, location_address, customer_name, old_asset_name, new_asset_name, confidence}

Cron Job — 6h Auto-Sync (since e9d18cb)

Hermes cron job 5ababff9c6e9 runs every 6 hours, executing ~/.hermes/scripts/cantaloupe-sync.sh:

  1. Exports from mycantaloupe.com: cd ~/projects/cantaloupe-downloader && python -m cantaloupe export --scheduled --output ~/cantaloupe-exports/
  2. Triggers the sync API: curl -X POST http://127.0.0.1:8090/api/admin/cantaloupe/sync (with admin Bearer token)
  3. Reports results as cron delivery

Source: scripts/cantaloupe-sync.sh in the repo. Credentials: ~/.cantaloupe.env — needs real mycantaloupe.com account (currently dummy, see issue #7). Fix (e9d18cb): Export subprocess cwd corrected to ~/projects/cantaloupe-downloader/.

Cantaloupe Sync Admin UI (since 070e8c2)

A new "Cantaloupe Sync" page in the admin SPA at static/index.html provides a UI for the sync workflow:

  • Sync Overview — Latest batch status badge (pending/approved/rejected/error), diff summary counts (New/Changed/Removed), last sync time, and "Sync Now" button
  • Pending Batch Review — Approve/reject buttons with full diff tables showing Machine ID, Name, Field, Old Value → New Value
  • Per-Field Approval (c35e2a1+) — "📋 Review Changes" button opens geotagger-style cards with checkboxes per field. Blank-fill changes auto-selected. Sticky apply bar at bottom. Apply only selected changes without approving the whole batch.
  • Import History — Expandable rows with status badges, timestamps, and lazy-loaded diff detail
    • Dark theme matching existing admin UI, vanilla JS with fetch(), loading/error states

Fix (20002f4): Updated login password hint from "Brett85!@" to "changeme".

Category Health Dashboard (since d58834b)

The /api/stats endpoint now includes a category_health field that detects asset categories not present in the categories lookup table. The dashboard shows a red ⚠️ Category Health card when unmapped categories exist, with a quick link to Settings → Categories to add them.