Skip to content

8. Flutter Fleet Admin Panel

Repository: Converters (planovi-converter) • Rule Prefix: BR-ADMIN • Documented Rules: 6 • Open [TEAM_WHY_NEEDED] Questions: 2

1. Business Purpose & Actors

Provides the Planovi operations team with a Zone 1 responsive web/mobile control center (cloud.planovi.app / dev-cloud.planovi.app) to monitor infrastructure and fleet health, provision new RP2350 converters via USB/UF2 workflows, assign converters to customer organizations and buildings, fulfill production/service converter orders, inspect live 3-phase telemetry charts and per-packet receipt diagnostics, issue remote commands (including remote Wi-Fi recovery and live metric triggers), download signed firmware builds, and export audit logs.

  • Actors: Planovi Operations / Fleet Administrators & Manufacturing Engineers (desktop web browser >= 900 px or mobile drawer < 900 px).

2. All Features & End-to-End Flows

  • Navigation Shell (admin/lib/screens/main_navigation_shell.dart, widgets/sidebar.dart):
    • Pure in-memory 6-tab shell (AnimatedSwitcher, 200 ms, no URL routing/deep links): 0: Dashboard, 1: Converters (drills into ConverterDetailScreen), 2: Orders, 3: Firmware & Guide, 4: Activity Log, 5: Settings. Collapsible dark graphite sidebar (234 px / 72 px; < 900 px uses dark AppBar + 260 px Drawer), inline SVG icons (immune to MaterialIcons font caching), PL/EN switcher.
  • Dashboard (dashboard_screen.dart): Parallel loads /status, /converters/stats/overview, /activity-logs (top 5) with silent 15-second Timer.periodic refresh. Shows scrolling red marquee (14 s cycle) when any system component != online, 4 KPI cards, infrastructure vs application component cards, and latest 5 activity logs.
  • Fleet List & Provisioning Wizard (converter_list_screen.dart, widgets/converter_dialogs.dart):
    • Server-side org dropdown (all/unassigned/reserved/org UUID) + client-side search & status chips; switches desktop table to mobile cards at < 880 px. Displays 2×2 live telemetry chips (preserving historical values when offline).
    • ConverterFormDialog drives a 5-step USB provisioning state machine (form -> preparing [950 ms] -> baking [1250 ms] -> connectUsb [BOOTSEL 3-step guide, copyable provision_device.py CLI command, .UF2 download, 1500 ms polling on GET converters/$id until online, manual “Check Status Now”, “Finish Registration” -> POST confirm-flash] -> readyToUse), plus Edit (PUT) and 2-step checkbox-confirmed Delete (DELETE).
  • Converter Detail & Telemetry Monitor (converter_detail_screen.dart):
    • Check Live Metrics: Queues trigger_telemetry and polls telemetry-diagnostics(limit=1) + commands every 3 s up to 65 s waiting for a new sequence or APPLIED.
    • Silent 8-Second Auto-Polling (commit 2bdc8a6): _evaluateAutoPolling() runs Timer.periodic(8s) ONLY while a command with status PENDING/SENT is younger than 10 minutes (_isRecentActiveCommand) OR configSyncPending == true; automatically cancels otherwise.
    • 4 Tabs: (0) Overview (metadata, desired cloud endpoint/interval presets [10, 30, 60, 300], SD/FIFO, live Wi-Fi RSSI color-coded -60/-70/-80 dBm, remote commands incl. OTA release picker & Wi-Fi credential modal, recent logs), (1) Monitor (4 KPI boxes, custom Canvas _MultiSeriesTelemetryPainter with 6 parameter groups, meter filter, period stepper, 4h/today/7d/1m ranges, crosshair tooltip, 3-phase AC table, connected meters), (2) Telemetry Diagnostics (5 KPIs, active meters, paginated 25/page receipts with detail modal showing decoded Modbus registers), (3) Commands (full history table + cancel button for PENDING).
  • Converter Orders (converter_orders_screen.dart): Filters open/completed/all and production/service, updates status inline via PATCH converter-orders/$id, and offers “Create & Assign Converter” for open production orders (prefilling ConverterFormDialog, then patching order to ready + converter_serial).
  • Firmware & Guide (firmware_guide_screen.dart): Visualizes RP2350 4 MiB Flash layout + OTP 0x0500..0x0501, serves latest .UF2 download, provides 3 copyable procedure tabs (Initial USB+OTP, Service USB A/B, Remote Cloud OTA), and lists DB + server-build releases with copyable SHA-256 and .UF2/.BIN download links.
  • Activity Log & Settings (activity_log_screen.dart, settings_screen.dart): Filterable log table (ALL/INFO/OK/WARN/ERROR + un-debounced search) with CSV download (LocalStorageHelper.openUrl); Settings persists proxy_endpoint, allow_failover, refresh_rate_sec (5..60 s), keep_history (7/30/90/365 d), and default_language.

3. Hard Business Rules, Validations, Calculations & Edge Cases

  • BR-ADMIN-01 (API Base URL Resolution Without --dart-define): ApiService._baseUrl (admin/lib/services/api_service.dart) resolves kIsWeb && host != 'localhost' && host != '127.0.0.1' to ${scheme}://${host}${port}/api/v1/; otherwise hardcodes 'http://localhost:8000/api/v1/'. Dio enforces 4 s connect and 4 s receive timeouts.
  • BR-ADMIN-02 (Zero Client-Side Authentication): ApiService sends no Authorization header, JWT, or cookie. AuthService (admin/lib/services/auth_service.dart) is unreferenced dead mock code. Access control depends entirely on upstream Nginx IP allowlisting (deploy/nginx.admin.planovi.conf).
  • BR-ADMIN-03 (Bounded Conditional Auto-Polling): ConverterDetailScreen polls silently every 8 s strictly when configSyncPending == true or an active PENDING/SENT command was created < 10 minutes ago (_isRecentActiveCommand); DashboardScreen polls every 15 s (hardcoded, ignoring AdminSettings.refreshRateSec); ConverterFormDialog polls every 1500 ms during connectUsb.
  • BR-ADMIN-04 (Remote Wi-Fi Modal Validation): converter_detail_screen.dart enforces SSID 1..32 chars and password either empty (open) or 8..63 chars before queuing update_wifi_credentials.
  • BR-ADMIN-05 (100% PL/EN Dictionary Parity & Persistence): I18n (admin/lib/services/i18n_service.dart) defaults to 'pl', persists selection in browser localStorage['planovi_language_preference'] (via web_storage_web.dart / in-memory stub web_storage_stub.dart), and maintains 473 keys in both 'pl' and 'en' verified by admin/test/i18n_service_test.dart.
  • BR-ADMIN-06 (Zone 1 Theme & Tabular Numerics): admin/lib/theme.dart enforces light zinc canvas (#FAFAFA/#FFFFFF/#F4F4F5), dark graphite chrome (#09090B/#121215/#18181B), solid #32CA42 buttons with #09090B foreground (brandOnSolid), #22A830 green text on light backgrounds, FontFeature.tabularFigures(), and surfaceTintColor: Colors.transparent.

4. State Machines & Data Lifecycle

stateDiagram-v2
    [*] --> form: Open Add / OS Upload dialog
    form --> preparing: Submit -> POST prepare-usb-provisioning (950ms anim)
    preparing --> baking: 1250ms firmware bake animation
    baking --> connectUsb: Show BOOTSEL + CLI + UF2 download + 1.5s status poll
    connectUsb --> readyToUse: Converter reports online OR user clicks Finish -> POST confirm-flash
    readyToUse --> [*]

5. Technical Contract (Inputs -> Processing -> Side Effects)

  • Consumed Backend Endpoints: GET/PUT/DELETE converters, GET converters/stats/overview, GET converters-next-serial, POST converters/prepare-usb-provisioning, POST converters/$id/{confirm-flash,desired-config,commands}, GET converters/$id/{telemetry-diagnostics,monitor,commands}, DELETE converters/$id/commands/$cmdId, GET converters/firmware/{info,latest-uf2,download/*}, GET firmware/releases (fallback converters/firmware/releases), GET organizations, GET/PATCH converter-orders, GET status, GET activity-logs (+ /export-csv), GET/PUT settings.
  • Browser APIs: window.localStorage (planovi_language_preference), window.open (CSV/UF2 downloads), window.fetch monkey-patch in admin/web/index.html forcing cache: 'no-cache' on Flutter font/asset manifests.

6. Cross-Repository Dependencies

  • admin/ -> cloud/api/* | Same-origin HTTPS /api/v1/* (or http://localhost:8000/api/v1/ locally), unauthenticated | JSON REST.
  • Brand assets in admin/assets/brand/ synced from PA-IDEAS/planovi-docs via scripts/sync-brand.sh.

7. Why It Works This Way (Decisions, Trade-offs & Workarounds)

  • Inline SVG Sidebar Icons (sidebar.dart:182): Intentionally avoids MaterialIcons glyphs in the navigation rail to eliminate browser font-cache rendering glitches; admin/web/index.html additionally bypasses HTTP cache on MaterialIcons-Regular.otf and FontManifest.json.
  • Confirmed Bugs & Tech Debt:
    1. 5 Missing I18n Keys Rendered Raw: chart_legend_pv (converter_detail_screen.dart:2213), chart_legend_cons (:2214), th_time (:2267), modal_close (:2330, sidebar.dart:152), no_components_found (dashboard_screen.dart:706) are referenced in widgets without dictionary entries (and 76 keys in i18n_service.dart are unused).
    2. Hardcoded Untranslated Strings: Polish literals in converter_detail_screen.dart (lines 1195, 2164–2204, 2255–2297, 2631, 2654), converter_list_screen.dart:708, converter_dialogs.dart:322,1677,1683; English-only StatusPill (status_pill.dart).
    3. Production Response Logging: ApiService attaches LogInterceptor(request: true, responseBody: true, error: true) unconditionally, printing full responses (including USB provisioning aes_key_hex & client private keys!) to browser DevTools console.
    4. Ignored / Fake UI Data: DashboardScreen ignores AdminSettings.refreshRateSec (hardcoded 15 s); ConverterDetailScreen hardcodes 'HTTPS Standalone mTLS (:443)' (:1202) and static "Bus Channel 0 · Baud 9600 · 0 CRC Errors" (:2087); ActivityLogScreen fires search API calls on every keystroke without debounce; SettingsScreen omits controls for statusAlertsEnabled, requireMfa, and apiTokenPreview.
    5. Dead Code: AuthService, sampleConverters (converter.dart:361-583), ApiService.{fetchFacilities,createConverter,uploadFirmwareRelease}, window.requestPicoUsbDevice (admin/web/index.html:48-71), google_fonts in pubspec.yaml; deprecated dart:html in web_storage_web.dart.
  • [TEAM_WHY_NEEDED: ConverterDetailScreen:2087 displays a static string "Bus Channel 0 · Baud 9600 · 0 CRC Errors" instead of real device Modbus diagnostics, and hardcodes dev-telemetry.planovi.app defaults. Should these be wired to real telemetry/status fields?]
  • [TEAM_WHY_NEEDED: Is Supabase Auth (TODOs in auth_service.dart) planned for cloud.planovi.app, or will admin access remain behind Nginx IP allowlist / Cloudflare Access?]

8. Debugging, Logs & Common Failure Modes

Symptom / Error MessageRoot Cause in CodeHow to Verify / Exact CommandFix
Raw strings modal_close / chart_legend_pv / no_components_found appear in UI5 i18n keys missing from I18n._localizedValues (admin/lib/services/i18n_service.dart)Search I18n.t('modal_close') etc. in admin/lib/Add the 5 missing keys to both 'pl' and 'en' maps
Local flutter run -d chrome fails with DioException connection refusedApiService._baseUrl hardcodes http://localhost:8000/api/v1/ on localhostCheck DevTools console (logged by LogInterceptor)Start FastAPI backend on port 8000 (uvicorn cloud.app:app --port 8000)
Order status dropdown update fails with 500 errorConverterOrdersScreen calls PATCH converter-orders/$id hitting AttributeError bug in cloud/api/converters.py:635-648Check network tab response on PATCH /api/v1/converter-orders/<uuid>Fix backend ConverterOrderUpdateRequest field names
flutter test fails on i18n parityUnmatched key added to 'pl' or 'en' in i18n_service.dartcd admin && flutter testKeep 'pl' and 'en' key sets strictly identical