From b3387f74eb1c9ba516046e123cb62a3b309dfeaf Mon Sep 17 00:00:00 2001 From: dannysusername Date: Fri, 20 Nov 2026 14:49:17 -0500 Subject: [PATCH 01/10] Rename Block Time to Hobbs Time and add hour info marks My Hours, the flight log, PDF export, alert emails and the assistant connection now say "Hobbs Time". Java fields, element ids, JSON keys and tests use hobbsTime naming to match. - No data moves: each renamed field is pinned to its existing column (@Column(name = "block_time_...")), so ddl-auto adds nothing. HobbsColumnMappingTest fails if a pin is ever dropped (the Sept 2026 rename left new, empty columns this way). - Old names (blockTimeOut, newBlockTime, ...) are still accepted on input and returned alongside the new keys until 2026-12-31, so a tab running the pre-rename dashboard.js keeps saving correctly. - Info marks next to Hobbs Time and Time in Service: hover, focus or tap shows a one-line description; kept on screen at phone width. - README, constitution (1.0.1) and docs updated. Tests: 234 unit/integration and 84 browser tests pass. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 +- docs/architecture/ARCHITECTURE.md | 2 +- docs/architecture/BACKEND.md | 6 +- docs/architecture/DATABASE.md | 6 +- docs/architecture/FRONTEND.md | 2 +- docs/backend-notes/TRANSACTIONAL.md | 8 +- docs/specs/ADSB_DATA_SOURCE.md | 2 +- docs/specs/ADSB_SYNC_SPEC.md | 4 +- docs/specs/ALERTS_SPEC.md | 2 +- docs/specs/SHARE_EXPORT_SPEC.md | 2 +- .../browser/DashboardMobileCardsTest.java | 4 +- .../browser/FlightLogTableEdgeCasesTest.java | 20 +- .../browser/HoursInfoMarksTest.java | 83 ++++++++ .../browser/HoursTableEdgeCasesTest.java | 36 ++-- .../AviaryService/config/DataSeeder.java | 4 +- .../AviaryService/config/DemoDataSeeder.java | 28 +-- .../controllers/UserController.java | 45 ++-- .../AviaryService/entity/Aircraft.java | 34 +-- .../AviaryService/entity/FlightLog.java | 45 ++-- .../AviaryService/mcp/FlightTools.java | 4 +- .../services/alerts/AlertDigestService.java | 2 +- .../services/dashboard/HoursService.java | 86 ++++---- .../services/dashboard/PdfExportService.java | 10 +- .../services/flights/FlightLogService.java | 56 ++--- .../flights/FlightSuggestionService.java | 4 +- .../services/flights/GarminCsvService.java | 58 ++--- .../services/stats/PublicStatsService.java | 2 +- .../AviaryService/util/Formatting.java | 2 +- .../resources/static/css/dashboardstyle.css | 65 +++++- src/main/resources/static/js/dashboard.js | 200 ++++++++++-------- src/main/resources/templates/dashboard.html | 50 ++--- src/main/resources/templates/pdf-export.html | 12 +- .../config/AircraftBackfillTest.java | 8 +- .../controllers/AircraftIsolationTest.java | 12 +- .../controllers/InputValidationTest.java | 8 +- .../controllers/UserControllerTest.java | 75 +++++-- .../entity/HobbsColumnMappingTest.java | 51 +++++ .../aircraft/AircraftServiceTest.java | 2 +- .../services/alerts/AlertDigestFleetTest.java | 2 +- .../alerts/AlertServiceIntegrationTest.java | 6 +- .../AviaryService/support/TestFleet.java | 4 +- 41 files changed, 676 insertions(+), 382 deletions(-) create mode 100644 src/browserTest/java/com/example/AviaryService/browser/HoursInfoMarksTest.java create mode 100644 src/test/java/com/example/AviaryService/entity/HobbsColumnMappingTest.java diff --git a/README.md b/README.md index 8017766..b403b52 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ No install, no setup, nothing to download. Register a username + password and yo A multi-user maintenance and flight-hours tracker for general-aviation aircraft owners: - **Service timeline** — track every recurring maintenance item (annual, transponder/pitot-static tests, VOR checks, oil changes, etc.) on a **calendar cycle** (days/months/years) *or* an **engine-hours cycle**. Each row shows last-done, next-due, and live "time left," and a one-click **Complete Maintenance** button rolls the dates and hours forward automatically. -- **Hours tracking** — block time and time in service, each with a manual baseline "floor," so log-book activity can only ever raise the displayed hours, never silently lower them. -- **Log book** — record flights by hand (from/to airport, block time and time in service out and in) **or import a Garmin avionics CSV** and let the app derive block time (oil pressure > 15 psi) and airborne time (groundspeed > 35 kt) for you. +- **Hours tracking** — Hobbs time and time in service, each with a manual baseline "floor," so log-book activity can only ever raise the displayed hours, never silently lower them. +- **Log book** — record flights by hand (from/to airport, Hobbs time and time in service out and in) **or import a Garmin avionics CSV** and let the app derive Hobbs time (oil pressure > 15 psi) and airborne time (groundspeed > 35 kt) for you. - **Aircraft info card** — make/model, tail number, owner, and serial number, editable inline. - **Fleets** — track up to 25 aircraft in one account. Each plane has its own info card, hours, service timeline, and log book; a picker in the header switches between them and shows which ones have items overdue or due soon. @@ -27,7 +27,7 @@ Each account is fully isolated — its own aircraft, service timelines, flight l - **More than one plane?** Tap the aircraft button in the header → **Add aircraft**, type the tail number, **Save**. You land on the new plane, ready for its first maintenance item. Switch planes from the same button; Aviary remembers the last one you looked at. - Maintenance alerts stay account-wide: one email covers every plane, grouped by tail number. 3. **Build your service timeline** — add maintenance items with a calendar or hours cycle. Rows are drag-reorderable, and you can insert title rows to group them. -4. **Set your hours** — enter current block time and time in service manually, or let the log book keep them current. +4. **Set your hours** — enter current Hobbs time and time in service manually, or let the log book keep them current. 5. **Log flights** — add entries by hand, or upload a Garmin CSV and Aviary computes the times and updates your meters. ## Connect an AI assistant diff --git a/docs/architecture/ARCHITECTURE.md b/docs/architecture/ARCHITECTURE.md index b4f9b40..1b6fd8f 100644 --- a/docs/architecture/ARCHITECTURE.md +++ b/docs/architecture/ARCHITECTURE.md @@ -24,7 +24,7 @@ Spring Boot 3.4.3 · Java 21 · Spring MVC + Security + Data JPA · Thymeleaf · - **Auth:** Spring Security form login, BCrypt passwords, single `USER` role. See [BACKEND](BACKEND.md#auth). - **Per-user scoping:** every entity has a `user_id`; queries filter by the authenticated user. See [DATABASE](DATABASE.md). - **AI assistants (MCP):** `/mcp` is an MCP server secured by Aviary's own OAuth authorization server (CIMD clients, PKCE, opaque hashed tokens). Assistants preview and import service timeline items; nothing is saved until the owner confirms. See [BACKEND](BACKEND.md#mcp-server--ai-assistant-sign-in). -- **Hours model:** flight logs roll up into `User.blockTimeHours` / `timeInServiceHours`, which maintenance due-dates count against. +- **Hours model:** flight logs roll up into `User.hobbsTimeHours` / `timeInServiceHours`, which maintenance due-dates count against. ## Known issues (high level — details in the area maps) - Local dev uses **in-memory H2** (data is lost on restart). See [DATABASE](DATABASE.md). diff --git a/docs/architecture/BACKEND.md b/docs/architecture/BACKEND.md index 9b3ae54..62ef4d9 100644 --- a/docs/architecture/BACKEND.md +++ b/docs/architecture/BACKEND.md @@ -34,16 +34,16 @@ | DELETE | `/delete/{id}` | — | 200 / 403 / 404 | deletes a timeline row. Ownership checked (403 if not owner) | | POST | `/updateOrder` | `List` ids | void | reorders timelines; user-scoped, matches ids with `.equals` | | POST | `/updateUserInfo` | JSON aircraft fields | status JSON | updates makeModel/tailNumber/ownerName/makeModelSN for auth user | -| POST | `/updateHours` | `blockTimeToAdd`/`timeInServiceToAdd`/`newBlockTime`/`newTimeInService` | hours JSON | set-or-add block time / time in service. 400 for NaN/Infinity, a negative set value, or an add that would go below 0 (checked before anything changes) | +| POST | `/updateHours` | `hobbsTimeToAdd`/`timeInServiceToAdd`/`newHobbsTime`/`newTimeInService` | hours JSON | set-or-add Hobbs time / time in service. 400 for NaN/Infinity, a negative set value, or an add that would go below 0 (checked before anything changes) | | GET | `/flightlogs` | — | `List` JSON | auth user's logs | | POST | `/addflightlog` | `FlightLog` JSON | log + new totals JSON | recomputes hours via `calculateMergedHours` | | DELETE | `/deleteflightlog/{id}` | — | status + new totals | **ownership checked** (403 if not owner) | | DELETE | `/deleteOption/{id}` | — | text | description option; **ownership checked** (403 if not owner) | ## Key logic -- **`calculateMergedHours(logs, useBlockTime)`** — sums flight time across all logs by **merging overlapping intervals** so overlapping flights don't double-count. Block time uses `blockTimeOut`/`blockTimeIn`; time in service uses `timeInServiceOut`/`timeInServiceIn`. Result is written back to `User.blockTimeHours`/`timeInServiceHours` on add/delete of a log. +- **`calculateMergedHours(logs, useHobbsTime)`** — sums flight time across all logs by **merging overlapping intervals** so overlapping flights don't double-count. Hobbs time uses `hobbsTimeOut`/`hobbsTimeIn`; time in service uses `timeInServiceOut`/`timeInServiceIn`. Result is written back to `User.hobbsTimeHours`/`timeInServiceHours` on add/delete of a log. - **`saveCustomDescriptionOption`** — persists a user's custom Service Timeline "Description" values so they reappear in the dropdown. -- **Hours "last updated" stamps:** `/updateHours` sets `blockTimeUpdatedAt`/`timeInServiceUpdatedAt` (UTC `Instant`) + `*UpdatedSource = "manual"` for whichever value changed; `/addflightlog` and `/deleteflightlog` set both with source `"flightlog"`. `GET /dashboard` passes the 4 values (timestamps as ISO strings) to the view, which renders them in the browser's local time. +- **Hours "last updated" stamps:** `/updateHours` sets `hobbsTimeUpdatedAt`/`timeInServiceUpdatedAt` (UTC `Instant`) + `*UpdatedSource = "manual"` for whichever value changed; `/addflightlog` and `/deleteflightlog` set both with source `"flightlog"`. `GET /dashboard` passes the 4 values (timestamps as ISO strings) to the view, which renders them in the browser's local time. ## Time Left + PDF - `DueDates.formatTimeLeft(dueDate, dueHours, today, currentTimeInService)` is the one server-side Time Left formatter (smart format, see [FRONTEND](FRONTEND.md)). Used by `PdfExportService` (computed at render time — the stored `timeLeft` column goes stale) and `/completeMaintenance/{id}`. diff --git a/docs/architecture/DATABASE.md b/docs/architecture/DATABASE.md index c8a2d7d..0e6b9d2 100644 --- a/docs/architecture/DATABASE.md +++ b/docs/architecture/DATABASE.md @@ -17,13 +17,15 @@ One-to-many (cascade ALL) → `aircraft`, `serviceTimeline`, `flightLogs`. **Legacy columns (kept, unmapped):** `block_time_hours`, `time_in_service_hours`, `make_model`, `tail_number`, `owner_name`, `make_modelsn`, both `*_updated_at`, both `*_updated_source`, both `*_manual_baseline`. These held the single aircraft before fleets. `AircraftBackfill` copies them into each account's first aircraft on boot; nothing else reads them. They stay one release so a rollback still works, then get dropped (see `docs/migrations/2026-11-09_multi_aircraft.sql`). ### `aircraft` (`Aircraft`) -`id`, `user_id` (not null), `tailNumber` (upper-cased, spaces removed), `tail_number_key` (comparison key, null when blank; unique with `user_id`), `makeModel`, `ownerName`, `makeModelSN`, `blockTimeHours` / `timeInServiceHours` (Double), `blockTimeManualBaseline` / `timeInServiceManualBaseline` (Double, manually-set floor so log activity can't silently lower the displayed total), `blockTimeUpdatedAt` / `timeInServiceUpdatedAt` (`Instant`), `blockTimeUpdatedSource` / `timeInServiceUpdatedSource` ("manual" | "flightlog"), `createdAt`. One airplane in the owner's fleet; at most 25 per user, at least 1. +`id`, `user_id` (not null), `tailNumber` (upper-cased, spaces removed), `tail_number_key` (comparison key, null when blank; unique with `user_id`), `makeModel`, `ownerName`, `makeModelSN`, `hobbsTimeHours` / `timeInServiceHours` (Double), `hobbsTimeManualBaseline` / `timeInServiceManualBaseline` (Double, manually-set floor so log activity can't silently lower the displayed total), `hobbsTimeUpdatedAt` / `timeInServiceUpdatedAt` (`Instant`), `hobbsTimeUpdatedSource` / `timeInServiceUpdatedSource` ("manual" | "flightlog"), `createdAt`. One airplane in the owner's fleet; at most 25 per user, at least 1. ### `service_timelines` (`ServiceTimeline`) `id`, `item`, `isTitle` (boolean — title row vs item row), `description`, `cycle`, `lastDone`, `dueDate`, `timeLeft`, `timelineOrder` (Integer, display order **within one aircraft**), `user_id`, `aircraft_id`. ### `flight_logs` (`FlightLog`) -`id`, `fromAirport`, `toAirport`, `blockTimeIn`, `blockTimeOut`, `timeInServiceIn`, `timeInServiceOut` (all Double, nullable), `blockTimeStart`, `blockTimeEnd` (`Instant`, nullable — engine start/stop, UTC), `timeInServiceStart`, `timeInServiceEnd` (`Instant`, nullable — wheels-off/wheels-on, UTC), `source` (String "manual" | "csv" | "aeroapi", nullable — see `FlightLog.getEffectiveSource()` and `HoursService.recomputeChain`), `faFlightId` (String, nullable — set only when the row came from an accepted `FlightSuggestion`), `user_id`, `aircraft_id`. Hours math only ever looks at one aircraft's flights. +`id`, `fromAirport`, `toAirport`, `hobbsTimeIn`, `hobbsTimeOut`, `timeInServiceIn`, `timeInServiceOut` (all Double, nullable), `hobbsTimeStart`, `hobbsTimeEnd` (`Instant`, nullable — engine start/stop, UTC), `timeInServiceStart`, `timeInServiceEnd` (`Instant`, nullable — wheels-off/wheels-on, UTC), `source` (String "manual" | "csv" | "aeroapi", nullable — see `FlightLog.getEffectiveSource()` and `HoursService.recomputeChain`), `faFlightId` (String, nullable — set only when the row came from an accepted `FlightSuggestion`), `user_id`, `aircraft_id`. Hours math only ever looks at one aircraft's flights. + +**Hobbs columns keep their old names.** In `aircraft` and `flight_logs`, every `hobbsTime*` field is pinned with `@Column(name = "block_time_…")` (e.g. `hobbsTimeHours` → `block_time_hours`, `hobbsTimeOut` → `block_time_out`). The Nov 2026 rename changed only the Java names, so no data moved. Do not remove those pins: `ddl-auto=update` would add new, empty `hobbs_time_*` columns. `HobbsColumnMappingTest` guards this. ### `description_options` (`DescriptionOption`) `id`, `option` (not null), `user_id`. Stores a user's custom Service Timeline description choices. diff --git a/docs/architecture/FRONTEND.md b/docs/architecture/FRONTEND.md index 59091c8..1ad1bb3 100644 --- a/docs/architecture/FRONTEND.md +++ b/docs/architecture/FRONTEND.md @@ -12,7 +12,7 @@ Each stylesheet defines the same CSS-variable palette (`--primary` green `#2C9B6 ## Dashboard structure - Fixed header (logo, **Share** menu, logout, settings gear). Share is a popover card (`.share-dropdown`, toggled via `hidden` + `aria-expanded` by `setShareOpen()` in `dashboard.js`): Print, Download PDF, then a divider and Email/Text marked with a "Soon" pill (`.share-coming-soon`). Closes on outside click, Escape, or picking an item; Arrow keys move between items. Styled with theme tokens so it works in dark mode. -- "My Hours" card: shows block time and time in service, each with a small muted "last updated" line under it (`.hours-block` / `.hours-updated`) — local date + time + relative ("2 days ago") + source ("you edited it" / "from a flight log"). Edit panel can **set** or **add** hours. +- "My Hours" card: shows Hobbs time and time in service, each with a small muted "last updated" line under it (`.hours-block` / `.hours-updated`) — local date + time + relative ("2 days ago") + source ("you edited it" / "from a flight log"). Edit panel can **set** or **add** hours. - Two tabs: **Service Timeline** and **Log Book**. - Service Timeline table: drag-reorder (SortableJS via grip handle), title rows vs item rows, a custom Description dropdown (with add/remove custom options), and a Calendar/Clock picker for Last Done / Due Date. "Time Left" is computed client-side. - Log Book table: existing rows are **readonly**; an add-row appends a flight. diff --git a/docs/backend-notes/TRANSACTIONAL.md b/docs/backend-notes/TRANSACTIONAL.md index 75a79c1..3dc56d7 100644 --- a/docs/backend-notes/TRANSACTIONAL.md +++ b/docs/backend-notes/TRANSACTIONAL.md @@ -82,14 +82,14 @@ for shredding — including A's work. flightLogRepository.delete(log); // 1. remove the log List remainingLogs = flightLogRepository.findByUser(user); -double newBlockTime = hoursService.recomputeChain(user, true); +double newHobbsTime = hoursService.recomputeChain(user, true); double newTimeInService = hoursService.recomputeChain(user, false); -user.setBlockTimeHours(newBlockTime); +user.setHobbsTimeHours(newHobbsTime); ... userRepository.save(user); // 2. recompute the hours ``` -If step 1 commits and step 2 does not, the aircraft has a deleted flight but stale block time +If step 1 commits and step 2 does not, the aircraft has a deleted flight but stale Hobbs time and time in service hours on screen. That is the exact bug class the recent commits have been fixing. `@Transactional` is what guarantees both or neither. @@ -188,7 +188,7 @@ Run the app: (`-Pdev` is defined in `build.gradle` and serves templates/CSS live from `src/` so frontend edits show without a rebuild.) -Then log in and change the block time hours. Expect log lines like: +Then log in and change the Hobbs time hours. Expect log lines like: ``` Getting transaction for [com.example.AviaryService.services.HoursService.updateHours] diff --git a/docs/specs/ADSB_DATA_SOURCE.md b/docs/specs/ADSB_DATA_SOURCE.md index 6ed8e8e..bf1748d 100644 --- a/docs/specs/ADSB_DATA_SOURCE.md +++ b/docs/specs/ADSB_DATA_SOURCE.md @@ -130,7 +130,7 @@ Each has three variants — `scheduled_`, `estimated_`, `actual_`. **Use `actual only**; the others are predictions. > **`actual_off` → `actual_on` is the flight.** Duration = the difference between -> them. This is *airborne* time, not block time. +> them. This is *airborne* time, not Hobbs time. #### Fields we use diff --git a/docs/specs/ADSB_SYNC_SPEC.md b/docs/specs/ADSB_SYNC_SPEC.md index bd5fd46..663d14a 100644 --- a/docs/specs/ADSB_SYNC_SPEC.md +++ b/docs/specs/ADSB_SYNC_SPEC.md @@ -12,7 +12,7 @@ License forbids mixing it with another real-time flight data provider. | Field | What it is | Source | |---|---|---| -| **Block Time** | engine-on to engine-off | manual entry only | +| **Hobbs Time** | engine-on to engine-off | manual entry only | | **Time in Service** | wheels-off to wheels-on (the real maintenance clock) | manual entry, CSV upload, or AeroAPI | AeroAPI's `actual_off`/`actual_on` map directly to Time in Service. It's just a @@ -40,7 +40,7 @@ suggestion until the user presses Add — nothing writes itself. for that as a possible future feature. 4. New flights are saved as `FlightSuggestion` rows, `pending`. 5. They show up as a banner on the Log Book tab. **Add** creates a real - `FlightLog` row (airports + departure/arrival time; Block Time is left + `FlightLog` row (airports + departure/arrival time; Hobbs Time is left blank and Time in Service is filled in from the flight's airborne duration) and flips the suggestion to `accepted`. **Dismiss** flips it to `dismissed`. Both are permanent — an diff --git a/docs/specs/ALERTS_SPEC.md b/docs/specs/ALERTS_SPEC.md index f4ae117..cf8480e 100644 --- a/docs/specs/ALERTS_SPEC.md +++ b/docs/specs/ALERTS_SPEC.md @@ -111,7 +111,7 @@ nothing is saved. - **Body (plain text):** "Maintenance status for [tail] ([make/model])" + timestamp → baseline note or "What changed" → full status, worst first. Each line puts the overdue part first, e.g. `OVERDUE Annual Inspection — 480.0 hrs overdue · - 106 days left` → aircraft hours (Block Time / Time in Service). + 106 days left` → aircraft hours (Hobbs Time / Time in Service). - **Attachment:** dashboard PDF (`PdfExportService.generateDashboardPdf`), built once per digest. - **Footer:** "You're receiving this because [owner name] added you to maintenance diff --git a/docs/specs/SHARE_EXPORT_SPEC.md b/docs/specs/SHARE_EXPORT_SPEC.md index 0104f48..a3a9137 100644 --- a/docs/specs/SHARE_EXPORT_SPEC.md +++ b/docs/specs/SHARE_EXPORT_SPEC.md @@ -95,7 +95,7 @@ Scope applies to **all four actions, including Print**: ## PDF content = data only, no UI chrome The PDF contains only the record content: **Service Timeline, Aircraft Info, -Hours (block time / time in service), and Log Book**. All interactive controls are excluded — +Hours (Hobbs time / time in service), and Log Book**. All interactive controls are excluded — the Share menu, grip handles, trash/delete icons, complete-maintenance button, chevrons, dropdowns, etc. diff --git a/src/browserTest/java/com/example/AviaryService/browser/DashboardMobileCardsTest.java b/src/browserTest/java/com/example/AviaryService/browser/DashboardMobileCardsTest.java index 8d8f14e..ad13139 100644 --- a/src/browserTest/java/com/example/AviaryService/browser/DashboardMobileCardsTest.java +++ b/src/browserTest/java/com/example/AviaryService/browser/DashboardMobileCardsTest.java @@ -78,8 +78,8 @@ private void seedData(User user) { log.setAircraft(aircraftOf(user)); log.setFromAirport("KSQL"); log.setToAirport("KPAO"); - log.setBlockTimeOut(1234.5); - log.setBlockTimeIn(1236.1); + log.setHobbsTimeOut(1234.5); + log.setHobbsTimeIn(1236.1); log.setTimeInServiceOut(1100.2); log.setTimeInServiceIn(1101.5); flightLogs.save(log); diff --git a/src/browserTest/java/com/example/AviaryService/browser/FlightLogTableEdgeCasesTest.java b/src/browserTest/java/com/example/AviaryService/browser/FlightLogTableEdgeCasesTest.java index 827b9c4..50b89ae 100644 --- a/src/browserTest/java/com/example/AviaryService/browser/FlightLogTableEdgeCasesTest.java +++ b/src/browserTest/java/com/example/AviaryService/browser/FlightLogTableEdgeCasesTest.java @@ -43,15 +43,15 @@ private void assertNoConsoleErrors(List errors) { } private FlightLog saveLog(User user, String from, String to, - Double blockTimeOut, Double blockTimeIn, + Double hobbsTimeOut, Double hobbsTimeIn, Double timeInServiceOut, Double timeInServiceIn) { FlightLog log = new FlightLog(); log.setUser(user); log.setAircraft(aircraftOf(user)); log.setFromAirport(from); log.setToAirport(to); - log.setBlockTimeOut(blockTimeOut); - log.setBlockTimeIn(blockTimeIn); + log.setHobbsTimeOut(hobbsTimeOut); + log.setHobbsTimeIn(hobbsTimeIn); log.setTimeInServiceOut(timeInServiceOut); log.setTimeInServiceIn(timeInServiceIn); return flightLogs.save(log); @@ -86,8 +86,8 @@ void typicalLogRendersAllCellsWithDecimalHours() { assertThat(row).hasCount(1); assertThat(row.locator("input[name='fromAirport']")).hasValue("KAAA"); assertThat(row.locator("input[name='toAirport']")).hasValue("KBBB"); - assertThat(row.locator("input[name='blockTimeOut']")).hasValue("100.0"); - assertThat(row.locator("input[name='blockTimeIn']")).hasValue("101.5"); + assertThat(row.locator("input[name='hobbsTimeOut']")).hasValue("100.0"); + assertThat(row.locator("input[name='hobbsTimeIn']")).hasValue("101.5"); assertThat(row.locator("input[name='timeInServiceOut']")).hasValue("50.0"); assertThat(row.locator("input[name='timeInServiceIn']")).hasValue("51.5"); @@ -113,8 +113,8 @@ void nullAirportsAndHoursRenderEmptyWithoutBreaking() { assertThat(row).hasCount(1); assertThat(row.locator("input[name='fromAirport']")).hasValue(""); assertThat(row.locator("input[name='toAirport']")).hasValue(""); - assertThat(row.locator("input[name='blockTimeOut']")).hasValue(""); - assertThat(row.locator("input[name='blockTimeIn']")).hasValue(""); + assertThat(row.locator("input[name='hobbsTimeOut']")).hasValue(""); + assertThat(row.locator("input[name='hobbsTimeIn']")).hasValue(""); assertThat(row.locator("input[name='timeInServiceOut']")).hasValue(""); assertThat(row.locator("input[name='timeInServiceIn']")).hasValue(""); @@ -134,8 +134,8 @@ void zeroDurationLegRendersWithZeroValues() { page.waitForLoadState(LoadState.NETWORKIDLE); var row = page.locator("tbody#logbook-body tr.log-row[data-id='" + log.getId() + "']"); - assertThat(row.locator("input[name='blockTimeOut']")).hasValue("0.0"); - assertThat(row.locator("input[name='blockTimeIn']")).hasValue("0.0"); + assertThat(row.locator("input[name='hobbsTimeOut']")).hasValue("0.0"); + assertThat(row.locator("input[name='hobbsTimeIn']")).hasValue("0.0"); assertThat(row.locator("input[name='timeInServiceOut']")).hasValue("0.0"); assertThat(row.locator("input[name='timeInServiceIn']")).hasValue("0.0"); @@ -153,7 +153,7 @@ void veryLargeHoursValueRenders() { page.waitForLoadState(LoadState.NETWORKIDLE); var row = page.locator("tbody#logbook-body tr.log-row[data-id='" + log.getId() + "']"); - assertThat(row.locator("input[name='blockTimeIn']")).hasValue("99999.9"); + assertThat(row.locator("input[name='hobbsTimeIn']")).hasValue("99999.9"); assertThat(row.locator("input[name='timeInServiceIn']")).hasValue("99999.9"); assertNoConsoleErrors(errors); diff --git a/src/browserTest/java/com/example/AviaryService/browser/HoursInfoMarksTest.java b/src/browserTest/java/com/example/AviaryService/browser/HoursInfoMarksTest.java new file mode 100644 index 0000000..86bcac8 --- /dev/null +++ b/src/browserTest/java/com/example/AviaryService/browser/HoursInfoMarksTest.java @@ -0,0 +1,83 @@ +package com.example.AviaryService.browser; + +import com.microsoft.playwright.Locator; +import com.microsoft.playwright.options.LoadState; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Spec 005: info marks next to Hobbs Time and Time in Service on My Hours. + * Checks the text, that hover/focus/tap reveal it, that tapping elsewhere + * closes it, and that it fits a phone screen without horizontal scroll. + */ +class HoursInfoMarksTest extends BrowserTestBase { + + private static final String HOBBS_TIP = + "Hobbs time: engine running time, from engine start to shutdown. Includes taxi and run-up."; + private static final String TIS_TIP = + "Flight time: time in the air, from takeoff to landing. Used for maintenance and inspections."; + + private String tipDisplay(Locator mark) { + return (String) mark.evaluate("el => getComputedStyle(el, '::after').display"); + } + + private List openDashboard() { + String username = seedUser("password"); + List errors = new ArrayList<>(); + page.onConsoleMessage(m -> { if ("error".equals(m.type())) errors.add(m.text()); }); + loginAs(username, "password"); + page.waitForLoadState(LoadState.NETWORKIDLE); + return errors; + } + + @Test + void infoMarksHaveTheRightTextAndOpenOnHoverFocusAndTap() { + List errors = openDashboard(); + Locator hobbs = page.locator("#hobbs-time-info"); + Locator tis = page.locator("#time-in-service-info"); + + assertThat(hobbs).hasAttribute("aria-label", HOBBS_TIP); + assertThat(hobbs).hasAttribute("data-tip", HOBBS_TIP); + assertThat(tis).hasAttribute("aria-label", TIS_TIP); + assertThat(tis).hasAttribute("data-tip", TIS_TIP); + + assertEquals("none", tipDisplay(hobbs), "tooltip hidden by default"); + + hobbs.hover(); + page.waitForTimeout(200); + assertEquals("block", tipDisplay(hobbs), "hover shows tooltip"); + + page.mouse().move(0, 0); + tis.click(); + page.waitForTimeout(200); + assertTrue(tis.getAttribute("class").contains("open"), "tap opens tooltip"); + page.locator("h3:has-text('My Hours')").click(); + assertTrue(!tis.getAttribute("class").contains("open"), "tap elsewhere closes it"); + + page.keyboard().press("Tab"); + tis.focus(); + page.keyboard().press("Escape"); + assertTrue(!tis.getAttribute("class").contains("open")); + + if (!errors.isEmpty()) throw new AssertionError("Console errors: " + errors); + } + + @Test + void infoMarksFitAPhoneScreen() { + page.setViewportSize(360, 740); + openDashboard(); + Locator tis = page.locator("#time-in-service-info"); + tis.scrollIntoViewIfNeeded(); + tis.click(); + page.waitForTimeout(200); + Object overflow = page.evaluate( + "() => document.documentElement.scrollWidth > document.documentElement.clientWidth"); + assertEquals(false, overflow, "open tooltip must not cause horizontal scroll at 360px"); + } +} diff --git a/src/browserTest/java/com/example/AviaryService/browser/HoursTableEdgeCasesTest.java b/src/browserTest/java/com/example/AviaryService/browser/HoursTableEdgeCasesTest.java index 17a83f2..ad9886f 100644 --- a/src/browserTest/java/com/example/AviaryService/browser/HoursTableEdgeCasesTest.java +++ b/src/browserTest/java/com/example/AviaryService/browser/HoursTableEdgeCasesTest.java @@ -41,7 +41,7 @@ private void assertNoConsoleErrors(List errors) { @Test void freshUserShowsZeroHoursAndEmptyAircraftInfo() { - // User with no edits — getBlockTimeHours/getTimeInServiceHours default to 0.0, + // User with no edits — getHobbsTimeHours/getTimeInServiceHours default to 0.0, // aircraft info fields are null. String username = seedUser("password"); List errors = attachConsoleErrorListener(); @@ -49,10 +49,10 @@ void freshUserShowsZeroHoursAndEmptyAircraftInfo() { loginAs(username, "password"); page.waitForLoadState(LoadState.NETWORKIDLE); - // Hours block always renders "Block Time: 0.0" / "Time in Service: 0.0" for + // Hours block always renders "Hobbs Time: 0.0" / "Time in Service: 0.0" for // a brand-new user because the getters coalesce null → 0.0. - assertThat(page.locator("#current-block-time-display")).containsText("Block Time:"); - assertThat(page.locator("#current-block-time-display")).containsText("0"); + assertThat(page.locator("#current-hobbs-time-display")).containsText("Hobbs Time:"); + assertThat(page.locator("#current-hobbs-time-display")).containsText("0"); assertThat(page.locator("#current-time-in-service-display")).containsText("Time in Service:"); assertThat(page.locator("#current-time-in-service-display")).containsText("0"); @@ -69,7 +69,7 @@ void freshUserShowsZeroHoursAndEmptyAircraftInfo() { void decimalHoursRenderWithoutTruncation() { String username = seedUser("password"); Aircraft u = aircraftOf(username); - u.setBlockTimeHours(1234.5); + u.setHobbsTimeHours(1234.5); u.setTimeInServiceHours(987.6); aircraftRepository.save(u); @@ -79,11 +79,11 @@ void decimalHoursRenderWithoutTruncation() { // The display string is built by Thymeleaf string-concat which uses // Double.toString(); 1234.5 should appear verbatim. - assertThat(page.locator("#current-block-time-display")).containsText("1234.5"); + assertThat(page.locator("#current-hobbs-time-display")).containsText("1234.5"); assertThat(page.locator("#current-time-in-service-display")).containsText("987.6"); // The "Edit" form input mirrors the same value. - assertThat(page.locator("#current-block-time")).hasValue("1234.5"); + assertThat(page.locator("#current-hobbs-time")).hasValue("1234.5"); assertThat(page.locator("#current-time-in-service")).hasValue("987.6"); assertNoConsoleErrors(errors); @@ -93,7 +93,7 @@ void decimalHoursRenderWithoutTruncation() { void veryLargeHoursValueRenders() { String username = seedUser("password"); Aircraft u = aircraftOf(username); - u.setBlockTimeHours(99999.9); + u.setHobbsTimeHours(99999.9); u.setTimeInServiceHours(99999.9); aircraftRepository.save(u); @@ -101,7 +101,7 @@ void veryLargeHoursValueRenders() { loginAs(username, "password"); page.waitForLoadState(LoadState.NETWORKIDLE); - assertThat(page.locator("#current-block-time-display")).containsText("99999.9"); + assertThat(page.locator("#current-hobbs-time-display")).containsText("99999.9"); assertThat(page.locator("#current-time-in-service-display")).containsText("99999.9"); assertNoConsoleErrors(errors); @@ -158,7 +158,7 @@ void zeroHoursRendersWithoutCollapsingToEmpty() { // not render as blank. String username = seedUser("password"); Aircraft u = aircraftOf(username); - u.setBlockTimeHours(0.0); + u.setHobbsTimeHours(0.0); u.setTimeInServiceHours(0.0); aircraftRepository.save(u); @@ -166,9 +166,9 @@ void zeroHoursRendersWithoutCollapsingToEmpty() { loginAs(username, "password"); page.waitForLoadState(LoadState.NETWORKIDLE); - // "Block Time: 0.0" must include the "0" — not "Block Time: ". - assertThat(page.locator("#current-block-time-display")).containsText("Block Time:"); - assertThat(page.locator("#current-block-time-display")).containsText("0"); + // "Hobbs Time: 0.0" must include the "0" — not "Hobbs Time: ". + assertThat(page.locator("#current-hobbs-time-display")).containsText("Hobbs Time:"); + assertThat(page.locator("#current-hobbs-time-display")).containsText("0"); assertNoConsoleErrors(errors); } @@ -179,18 +179,18 @@ void manualSourceStampSetsHoursUpdatedDataAttributes() { // dashboard.js reads to render the "last updated" label. String username = seedUser("password"); Aircraft u = aircraftOf(username); - u.setBlockTimeHours(50.0); - u.setBlockTimeUpdatedAt(java.time.Instant.parse("2025-10-01T12:00:00Z")); - u.setBlockTimeUpdatedSource("manual"); + u.setHobbsTimeHours(50.0); + u.setHobbsTimeUpdatedAt(java.time.Instant.parse("2025-10-01T12:00:00Z")); + u.setHobbsTimeUpdatedSource("manual"); aircraftRepository.save(u); List errors = attachConsoleErrorListener(); loginAs(username, "password"); page.waitForLoadState(LoadState.NETWORKIDLE); - assertThat(page.locator("#block-time-updated")) + assertThat(page.locator("#hobbs-time-updated")) .hasAttribute("data-source", "manual"); - assertThat(page.locator("#block-time-updated")) + assertThat(page.locator("#hobbs-time-updated")) .hasAttribute("data-updated", "2025-10-01T12:00:00Z"); assertNoConsoleErrors(errors); diff --git a/src/main/java/com/example/AviaryService/config/DataSeeder.java b/src/main/java/com/example/AviaryService/config/DataSeeder.java index 6c7b21a..a6381a5 100644 --- a/src/main/java/com/example/AviaryService/config/DataSeeder.java +++ b/src/main/java/com/example/AviaryService/config/DataSeeder.java @@ -83,9 +83,9 @@ public void run(String... args) throws Exception { serviceTimelineRepository.saveAll(List.of(t1, t2, t3, t4, t5, t6, t7, t8, d1, d2, d3, d4, d5, d6, d7, d8)); } - private Aircraft firstAircraft(User user, double blockTime, double timeInService) { + private Aircraft firstAircraft(User user, double hobbsTime, double timeInService) { Aircraft a = new Aircraft(user); - a.setBlockTimeHours(blockTime); + a.setHobbsTimeHours(hobbsTime); a.setTimeInServiceHours(timeInService); a = aircraftRepository.save(a); user.setLastViewedAircraft(a); diff --git a/src/main/java/com/example/AviaryService/config/DemoDataSeeder.java b/src/main/java/com/example/AviaryService/config/DemoDataSeeder.java index acca437..913c451 100644 --- a/src/main/java/com/example/AviaryService/config/DemoDataSeeder.java +++ b/src/main/java/com/example/AviaryService/config/DemoDataSeeder.java @@ -103,22 +103,22 @@ public void run(String... args) { {"KTMB", "KAPF", "1.8", "1.6"}, {"KAPF", "KTMB", "1.7", "1.5"}, {"KTMB", "KEYW", "2.1", "1.9"}, {"KEYW", "KTMB", "2.0", "1.8"}, }; - double block = 1532.4 - sum(legs, 2); + double hobbs = 1532.4 - sum(legs, 2); double service = 1418.7 - sum(legs, 3); Instant start = today.minusDays(20).atTime(14, 0).toInstant(ZoneOffset.UTC); for (String[] leg : legs) { - double blockLen = Double.parseDouble(leg[2]); + double hobbsLen = Double.parseDouble(leg[2]); double serviceLen = Double.parseDouble(leg[3]); - FlightLog log = new FlightLog(leg[0], leg[1], round(block + blockLen), round(block), + FlightLog log = new FlightLog(leg[0], leg[1], round(hobbs + hobbsLen), round(hobbs), round(service + serviceLen), round(service), demo); log.setSource("manual"); log.setAircraft(sr22); - log.setBlockTimeStart(start); - log.setBlockTimeEnd(start.plus(minutes(blockLen))); + log.setHobbsTimeStart(start); + log.setHobbsTimeEnd(start.plus(minutes(hobbsLen))); log.setTimeInServiceStart(start.plus(Duration.ofMinutes(6))); log.setTimeInServiceEnd(start.plus(Duration.ofMinutes(6)).plus(minutes(serviceLen))); flightLogRepository.save(log); - block += blockLen; + hobbs += hobbsLen; service += serviceLen; start = start.plus(Duration.ofDays(3)); } @@ -160,35 +160,35 @@ private void seedSecondAircraft(User demo, Aircraft pa28, LocalDate today) { timelineRepository.saveAll(rows); String[][] legs = { {"KFXE", "KBCT", "0.8", "0.6"}, {"KBCT", "KFXE", "0.9", "0.7"}, {"KFXE", "KVRB", "1.5", "1.3"} }; - double block = 4210.6 - sum(legs, 2); + double hobbs = 4210.6 - sum(legs, 2); double service = 4105.2 - sum(legs, 3); Instant start = today.minusDays(12).atTime(13, 0).toInstant(ZoneOffset.UTC); for (String[] leg : legs) { - double blockLen = Double.parseDouble(leg[2]); + double hobbsLen = Double.parseDouble(leg[2]); double serviceLen = Double.parseDouble(leg[3]); - FlightLog log = new FlightLog(leg[0], leg[1], round(block + blockLen), round(block), + FlightLog log = new FlightLog(leg[0], leg[1], round(hobbs + hobbsLen), round(hobbs), round(service + serviceLen), round(service), demo); log.setSource("manual"); log.setAircraft(pa28); - log.setBlockTimeStart(start); - log.setBlockTimeEnd(start.plus(minutes(blockLen))); + log.setHobbsTimeStart(start); + log.setHobbsTimeEnd(start.plus(minutes(hobbsLen))); log.setTimeInServiceStart(start.plus(Duration.ofMinutes(5))); log.setTimeInServiceEnd(start.plus(Duration.ofMinutes(5)).plus(minutes(serviceLen))); flightLogRepository.save(log); - block += blockLen; + hobbs += hobbsLen; service += serviceLen; start = start.plus(Duration.ofDays(4)); } } private Aircraft aircraft(User owner, String tail, String makeModel, String serial, - double blockTime, double timeInService) { + double hobbsTime, double timeInService) { Aircraft a = new Aircraft(owner); a.setTailNumber(tail); a.setMakeModel(makeModel); a.setOwnerName("Demo Pilot"); a.setMakeModelSN(serial); - a.setBlockTimeHours(blockTime); + a.setHobbsTimeHours(hobbsTime); a.setTimeInServiceHours(timeInService); return aircraftRepository.save(a); } diff --git a/src/main/java/com/example/AviaryService/controllers/UserController.java b/src/main/java/com/example/AviaryService/controllers/UserController.java index 01917da..1d9e8b2 100644 --- a/src/main/java/com/example/AviaryService/controllers/UserController.java +++ b/src/main/java/com/example/AviaryService/controllers/UserController.java @@ -181,7 +181,7 @@ public String showDashboard(@RequestParam(name = "aircraft", required = false) L model.addAttribute("aircraftFlightCount", aircraftService.flightCount(aircraft)); model.addAttribute("timelines", serviceTimelineRepository.findByAircraftOrderByTimelineOrderAsc(aircraft)); model.addAttribute("descriptionOptions", descriptionOptionService.cleanupAndLoadDescriptionOptions(user)); - model.addAttribute("blockTimeHours", aircraft.getBlockTimeHours()); + model.addAttribute("hobbsTimeHours", aircraft.getHobbsTimeHours()); model.addAttribute("timeInServiceHours", aircraft.getTimeInServiceHours()); model.addAttribute("makeModel", aircraft.getMakeModel()); @@ -189,9 +189,9 @@ public String showDashboard(@RequestParam(name = "aircraft", required = false) L model.addAttribute("ownerName", aircraft.getOwnerName()); model.addAttribute("makeModelSN", aircraft.getMakeModelSN()); model.addAttribute("flightlogs", flightLogService.listFor(aircraft)); - model.addAttribute("blockTimeUpdatedAt", aircraft.getBlockTimeUpdatedAt() != null ? aircraft.getBlockTimeUpdatedAt().toString() : null); + model.addAttribute("hobbsTimeUpdatedAt", aircraft.getHobbsTimeUpdatedAt() != null ? aircraft.getHobbsTimeUpdatedAt().toString() : null); model.addAttribute("timeInServiceUpdatedAt", aircraft.getTimeInServiceUpdatedAt() != null ? aircraft.getTimeInServiceUpdatedAt().toString() : null); - model.addAttribute("blockTimeUpdatedSource", aircraft.getBlockTimeUpdatedSource()); + model.addAttribute("hobbsTimeUpdatedSource", aircraft.getHobbsTimeUpdatedSource()); model.addAttribute("timeInServiceUpdatedSource", aircraft.getTimeInServiceUpdatedSource()); String aeroApiKey = user.getAeroApiKey(); boolean hasAeroApiKey = aeroApiKey != null && !aeroApiKey.isEmpty(); @@ -393,8 +393,10 @@ public ResponseEntity> acceptFlightSuggestion( response.put("id", flightLog.getId()); response.put("fromAirport", flightLog.getFromAirport()); response.put("toAirport", flightLog.getToAirport()); - response.put("blockTimeIn", flightLog.getBlockTimeIn()); - response.put("blockTimeOut", flightLog.getBlockTimeOut()); + response.put("hobbsTimeIn", flightLog.getHobbsTimeIn()); + response.put("blockTimeIn", flightLog.getHobbsTimeIn()); // legacy key, remove after 2026-12-31 + response.put("hobbsTimeOut", flightLog.getHobbsTimeOut()); + response.put("blockTimeOut", flightLog.getHobbsTimeOut()); // legacy key, remove after 2026-12-31 response.put("timeInServiceIn", flightLog.getTimeInServiceIn()); response.put("timeInServiceOut", flightLog.getTimeInServiceOut()); response.put("timeInServiceStart", flightLog.getTimeInServiceStart() != null ? flightLog.getTimeInServiceStart().toString() : null); @@ -529,10 +531,14 @@ public ResponseEntity> deleteSubscription(@CurrentAircraft A @PostMapping("/updateHours") @ResponseBody public ResponseEntity> updateHours( - @RequestParam(required = false) Double blockTimeToAdd, + @RequestParam(required = false) Double hobbsTimeToAdd, @RequestParam(required = false) Double timeInServiceToAdd, - @RequestParam(required = false) Double newBlockTime, + @RequestParam(required = false) Double newHobbsTime, @RequestParam(required = false) Double newTimeInService, + // Pre-rename names (Block Time). Accepted for one release so a tab still + // running the old dashboard.js keeps saving. Remove after 2026-12-31. + @RequestParam(name = "blockTimeToAdd", required = false) Double legacyHobbsTimeToAdd, + @RequestParam(name = "newBlockTime", required = false) Double legacyNewHobbsTime, @CurrentAircraft Aircraft aircraft, Authentication authentication) { try { @@ -540,10 +546,13 @@ public ResponseEntity> updateHours( if (user == null) { throw new IllegalArgumentException("User not found"); } - hoursService.updateHours(blockTimeToAdd, timeInServiceToAdd, newBlockTime, newTimeInService, aircraft); + if (hobbsTimeToAdd == null) hobbsTimeToAdd = legacyHobbsTimeToAdd; + if (newHobbsTime == null) newHobbsTime = legacyNewHobbsTime; + hoursService.updateHours(hobbsTimeToAdd, timeInServiceToAdd, newHobbsTime, newTimeInService, aircraft); Map response = new HashMap<>(); response.put("status", "success"); - response.put("newBlockTime", String.valueOf(aircraft.getBlockTimeHours())); + response.put("newHobbsTime", String.valueOf(aircraft.getHobbsTimeHours())); + response.put("newBlockTime", String.valueOf(aircraft.getHobbsTimeHours())); // legacy key, remove after 2026-12-31 response.put("newTimeInService", String.valueOf(aircraft.getTimeInServiceHours())); return ResponseEntity.ok(response); @@ -661,15 +670,20 @@ public ResponseEntity> addFlightLog( response.put("id", savedLog.getId()); response.put("fromAirport", savedLog.getFromAirport()); response.put("toAirport", savedLog.getToAirport()); - response.put("blockTimeIn", savedLog.getBlockTimeIn()); - response.put("blockTimeOut", savedLog.getBlockTimeOut()); - response.put("blockTimeStart", savedLog.getBlockTimeStart() != null ? savedLog.getBlockTimeStart().toString() : null); - response.put("blockTimeEnd", savedLog.getBlockTimeEnd() != null ? savedLog.getBlockTimeEnd().toString() : null); + response.put("hobbsTimeIn", savedLog.getHobbsTimeIn()); + response.put("blockTimeIn", savedLog.getHobbsTimeIn()); // legacy key, remove after 2026-12-31 + response.put("hobbsTimeOut", savedLog.getHobbsTimeOut()); + response.put("blockTimeOut", savedLog.getHobbsTimeOut()); // legacy key, remove after 2026-12-31 + response.put("hobbsTimeStart", savedLog.getHobbsTimeStart() != null ? savedLog.getHobbsTimeStart().toString() : null); + response.put("blockTimeStart", savedLog.getHobbsTimeStart() != null ? savedLog.getHobbsTimeStart().toString() : null); // legacy key, remove after 2026-12-31 + response.put("hobbsTimeEnd", savedLog.getHobbsTimeEnd() != null ? savedLog.getHobbsTimeEnd().toString() : null); + response.put("blockTimeEnd", savedLog.getHobbsTimeEnd() != null ? savedLog.getHobbsTimeEnd().toString() : null); // legacy key, remove after 2026-12-31 response.put("timeInServiceIn", savedLog.getTimeInServiceIn()); response.put("timeInServiceOut", savedLog.getTimeInServiceOut()); response.put("timeInServiceStart", savedLog.getTimeInServiceStart() != null ? savedLog.getTimeInServiceStart().toString() : null); response.put("timeInServiceEnd", savedLog.getTimeInServiceEnd() != null ? savedLog.getTimeInServiceEnd().toString() : null); - response.put("newBlockTime", added.totals().blockTime()); + response.put("newHobbsTime", added.totals().hobbsTime()); + response.put("newBlockTime", added.totals().hobbsTime()); // legacy key, remove after 2026-12-31 response.put("newTimeInService", added.totals().timeInService()); return ResponseEntity.ok(response); } @@ -764,7 +778,8 @@ public ResponseEntity> deleteFlightLog(@PathVariable Long id Map response = new HashMap<>(); response.put("status", "success"); - response.put("newBlockTime", totals.blockTime()); + response.put("newHobbsTime", totals.hobbsTime()); + response.put("newBlockTime", totals.hobbsTime()); // legacy key, remove after 2026-12-31 response.put("newTimeInService", totals.timeInService()); return ResponseEntity.ok(response); } catch (SecurityException e) { diff --git a/src/main/java/com/example/AviaryService/entity/Aircraft.java b/src/main/java/com/example/AviaryService/entity/Aircraft.java index 2241ba0..521ad08 100644 --- a/src/main/java/com/example/AviaryService/entity/Aircraft.java +++ b/src/main/java/com/example/AviaryService/entity/Aircraft.java @@ -45,8 +45,8 @@ public class Aircraft { @Column private String makeModelSN; - @Column - private Double blockTimeHours; + @Column(name = "block_time_hours") + private Double hobbsTimeHours; @Column private Double timeInServiceHours; @@ -54,20 +54,20 @@ public class Aircraft { // Manual "floor" for each meter. Any manual edit on /updateHours writes // this too; log-book activity can only raise the displayed value above // it, never below. Nullable on purpose: "never set" differs from "0". - @Column - private Double blockTimeManualBaseline; + @Column(name = "block_time_manual_baseline") + private Double hobbsTimeManualBaseline; @Column private Double timeInServiceManualBaseline; - @Column - private Instant blockTimeUpdatedAt; + @Column(name = "block_time_updated_at") + private Instant hobbsTimeUpdatedAt; @Column private Instant timeInServiceUpdatedAt; - @Column - private String blockTimeUpdatedSource; + @Column(name = "block_time_updated_source") + private String hobbsTimeUpdatedSource; @Column private String timeInServiceUpdatedSource; @@ -79,7 +79,7 @@ public Aircraft() {} public Aircraft(User user) { this.user = user; - this.blockTimeHours = 0.0; + this.hobbsTimeHours = 0.0; this.timeInServiceHours = 0.0; this.tailNumber = ""; this.makeModel = ""; @@ -122,26 +122,26 @@ public void setTailNumber(String tailNumber) { public String getMakeModelSN() { return makeModelSN; } public void setMakeModelSN(String makeModelSN) { this.makeModelSN = makeModelSN; } - public Double getBlockTimeHours() { return blockTimeHours != null ? blockTimeHours : 0.0; } - public void setBlockTimeHours(Double blockTimeHours) { this.blockTimeHours = blockTimeHours != null ? blockTimeHours : 0.0; } + public Double getHobbsTimeHours() { return hobbsTimeHours != null ? hobbsTimeHours : 0.0; } + public void setHobbsTimeHours(Double hobbsTimeHours) { this.hobbsTimeHours = hobbsTimeHours != null ? hobbsTimeHours : 0.0; } public Double getTimeInServiceHours() { return timeInServiceHours != null ? timeInServiceHours : 0.0; } public void setTimeInServiceHours(Double timeInServiceHours) { this.timeInServiceHours = timeInServiceHours != null ? timeInServiceHours : 0.0; } - public Double getBlockTimeManualBaseline() { return blockTimeManualBaseline; } - public void setBlockTimeManualBaseline(Double v) { this.blockTimeManualBaseline = v; } + public Double getHobbsTimeManualBaseline() { return hobbsTimeManualBaseline; } + public void setHobbsTimeManualBaseline(Double v) { this.hobbsTimeManualBaseline = v; } public Double getTimeInServiceManualBaseline() { return timeInServiceManualBaseline; } public void setTimeInServiceManualBaseline(Double v) { this.timeInServiceManualBaseline = v; } - public Instant getBlockTimeUpdatedAt() { return blockTimeUpdatedAt; } - public void setBlockTimeUpdatedAt(Instant v) { this.blockTimeUpdatedAt = v; } + public Instant getHobbsTimeUpdatedAt() { return hobbsTimeUpdatedAt; } + public void setHobbsTimeUpdatedAt(Instant v) { this.hobbsTimeUpdatedAt = v; } public Instant getTimeInServiceUpdatedAt() { return timeInServiceUpdatedAt; } public void setTimeInServiceUpdatedAt(Instant v) { this.timeInServiceUpdatedAt = v; } - public String getBlockTimeUpdatedSource() { return blockTimeUpdatedSource; } - public void setBlockTimeUpdatedSource(String v) { this.blockTimeUpdatedSource = v; } + public String getHobbsTimeUpdatedSource() { return hobbsTimeUpdatedSource; } + public void setHobbsTimeUpdatedSource(String v) { this.hobbsTimeUpdatedSource = v; } public String getTimeInServiceUpdatedSource() { return timeInServiceUpdatedSource; } public void setTimeInServiceUpdatedSource(String v) { this.timeInServiceUpdatedSource = v; } diff --git a/src/main/java/com/example/AviaryService/entity/FlightLog.java b/src/main/java/com/example/AviaryService/entity/FlightLog.java index 0c8feda..d2e3708 100644 --- a/src/main/java/com/example/AviaryService/entity/FlightLog.java +++ b/src/main/java/com/example/AviaryService/entity/FlightLog.java @@ -1,5 +1,6 @@ package com.example.AviaryService.entity; +import com.fasterxml.jackson.annotation.JsonAlias; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonBackReference; import jakarta.persistence.*; @@ -17,11 +18,13 @@ public class FlightLog { @Column(nullable = true) private String toAirport; - @Column(nullable = true) - private Double blockTimeIn; // Use Double for decimal hours if needed + @Column(name = "block_time_in", nullable = true) + @JsonAlias("blockTimeIn") + private Double hobbsTimeIn; // Use Double for decimal hours if needed - @Column(nullable = true) - private Double blockTimeOut; + @Column(name = "block_time_out", nullable = true) + @JsonAlias("blockTimeOut") + private Double hobbsTimeOut; @Column(nullable = true) private Double timeInServiceIn; @@ -29,15 +32,17 @@ public class FlightLog { @Column(nullable = true) private Double timeInServiceOut; - // Engine-start / engine-stop, UTC -- when the blockTimeOut/blockTimeIn + // Engine-start / engine-stop, UTC -- when the hobbsTimeOut/hobbsTimeIn // readings were taken. Lets the logbook be sorted chronologically and // lets HoursService.recomputeChain place this flight correctly relative // to others instead of always appending it to the end. - @Column(nullable = true) - private java.time.Instant blockTimeStart; + @Column(name = "block_time_start", nullable = true) + @JsonAlias("blockTimeStart") + private java.time.Instant hobbsTimeStart; - @Column(nullable = true) - private java.time.Instant blockTimeEnd; + @Column(name = "block_time_end", nullable = true) + @JsonAlias("blockTimeEnd") + private java.time.Instant hobbsTimeEnd; // Wheels-up / wheels-down, UTC -- when the timeInServiceOut/timeInServiceIn // readings were taken. This is also the 14 CFR 1.1 "time in service" @@ -81,11 +86,11 @@ public class FlightLog { // Constructors public FlightLog() {} - public FlightLog(String fromAirport, String toAirport, Double blockTimeIn, Double blockTimeOut, Double timeInServiceIn, Double timeInServiceOut, User user) { + public FlightLog(String fromAirport, String toAirport, Double hobbsTimeIn, Double hobbsTimeOut, Double timeInServiceIn, Double timeInServiceOut, User user) { this.fromAirport = fromAirport; this.toAirport = toAirport; - this.blockTimeIn = blockTimeIn; - this.blockTimeOut = blockTimeOut; + this.hobbsTimeIn = hobbsTimeIn; + this.hobbsTimeOut = hobbsTimeOut; this.timeInServiceIn = timeInServiceIn; this.timeInServiceOut = timeInServiceOut; this.user = user; @@ -98,18 +103,18 @@ public FlightLog(String fromAirport, String toAirport, Double blockTimeIn, Doubl public void setFromAirport(String fromAirport) { this.fromAirport = fromAirport; } public String getToAirport() { return toAirport; } public void setToAirport(String toAirport) { this.toAirport = toAirport; } - public Double getBlockTimeIn() { return blockTimeIn; } - public void setBlockTimeIn(Double blockTimeIn) { this.blockTimeIn = blockTimeIn; } - public Double getBlockTimeOut() { return blockTimeOut; } - public void setBlockTimeOut(Double blockTimeOut) { this.blockTimeOut = blockTimeOut; } + public Double getHobbsTimeIn() { return hobbsTimeIn; } + public void setHobbsTimeIn(Double hobbsTimeIn) { this.hobbsTimeIn = hobbsTimeIn; } + public Double getHobbsTimeOut() { return hobbsTimeOut; } + public void setHobbsTimeOut(Double hobbsTimeOut) { this.hobbsTimeOut = hobbsTimeOut; } public Double getTimeInServiceIn() { return timeInServiceIn; } public void setTimeInServiceIn(Double timeInServiceIn) { this.timeInServiceIn = timeInServiceIn; } public Double getTimeInServiceOut() { return timeInServiceOut; } public void setTimeInServiceOut(Double timeInServiceOut) { this.timeInServiceOut = timeInServiceOut; } - public java.time.Instant getBlockTimeStart() { return blockTimeStart; } - public void setBlockTimeStart(java.time.Instant blockTimeStart) { this.blockTimeStart = blockTimeStart; } - public java.time.Instant getBlockTimeEnd() { return blockTimeEnd; } - public void setBlockTimeEnd(java.time.Instant blockTimeEnd) { this.blockTimeEnd = blockTimeEnd; } + public java.time.Instant getHobbsTimeStart() { return hobbsTimeStart; } + public void setHobbsTimeStart(java.time.Instant hobbsTimeStart) { this.hobbsTimeStart = hobbsTimeStart; } + public java.time.Instant getHobbsTimeEnd() { return hobbsTimeEnd; } + public void setHobbsTimeEnd(java.time.Instant hobbsTimeEnd) { this.hobbsTimeEnd = hobbsTimeEnd; } public java.time.Instant getTimeInServiceStart() { return timeInServiceStart; } public void setTimeInServiceStart(java.time.Instant timeInServiceStart) { this.timeInServiceStart = timeInServiceStart; } public java.time.Instant getTimeInServiceEnd() { return timeInServiceEnd; } diff --git a/src/main/java/com/example/AviaryService/mcp/FlightTools.java b/src/main/java/com/example/AviaryService/mcp/FlightTools.java index 5b86713..6540039 100644 --- a/src/main/java/com/example/AviaryService/mcp/FlightTools.java +++ b/src/main/java/com/example/AviaryService/mcp/FlightTools.java @@ -15,7 +15,7 @@ public class FlightTools { //Only what the AI needs, never include the user (it holds the password hash) - public record FlightSummary(Long id, String from, String to, Double blockTimeOut, Double blockTimeIn) {} + public record FlightSummary(Long id, String from, String to, Double hobbsTimeOut, Double hobbsTimeIn) {} private final FlightLogService flightLogService; private final McpCurrentUser currentUser; @@ -35,7 +35,7 @@ public List listFlights( currentUser.requireScope("aviary.read"); User user = currentUser.require(); return flightLogService.listFor(aircraftResolver.resolve(user, aircraft)).stream() - .map(f -> new FlightSummary(f.getId(), f.getFromAirport(), f.getToAirport(), f.getBlockTimeOut(), f.getBlockTimeIn())) + .map(f -> new FlightSummary(f.getId(), f.getFromAirport(), f.getToAirport(), f.getHobbsTimeOut(), f.getHobbsTimeIn())) .toList(); } diff --git a/src/main/java/com/example/AviaryService/services/alerts/AlertDigestService.java b/src/main/java/com/example/AviaryService/services/alerts/AlertDigestService.java index 1d76577..0b8ba64 100644 --- a/src/main/java/com/example/AviaryService/services/alerts/AlertDigestService.java +++ b/src/main/java/com/example/AviaryService/services/alerts/AlertDigestService.java @@ -191,7 +191,7 @@ private static void appendRows(StringBuilder sb, List rows) { } private static void appendHours(StringBuilder sb, String label, Aircraft a) { - sb.append("\n").append(label).append(": Block Time ").append(hours(a.getBlockTimeHours())) + sb.append("\n").append(label).append(": Hobbs Time ").append(hours(a.getHobbsTimeHours())) .append(" · Time in Service ").append(hours(a.getTimeInServiceHours())).append('\n'); } diff --git a/src/main/java/com/example/AviaryService/services/dashboard/HoursService.java b/src/main/java/com/example/AviaryService/services/dashboard/HoursService.java index be51452..15e535b 100644 --- a/src/main/java/com/example/AviaryService/services/dashboard/HoursService.java +++ b/src/main/java/com/example/AviaryService/services/dashboard/HoursService.java @@ -14,7 +14,7 @@ import com.example.AviaryService.repositories.AircraftRepository; import com.example.AviaryService.util.Formatting; -// Keeps one aircraft's hours right (block time and time in service). Handles +// Keeps one aircraft's hours right (Hobbs time and time in service). Handles // manual hour edits, catches typed readings that look like typos compared to // existing logs, and recalculates the hours from the flight logs. @Service @@ -29,26 +29,26 @@ public HoursService(AircraftRepository aircraftRepository, FlightLogRepository f } @Transactional - public void updateHours(Double blockTimeToAdd, - Double timeInServiceToAdd, Double newBlockTime, + public void updateHours(Double hobbsTimeToAdd, + Double timeInServiceToAdd, Double newHobbsTime, Double newTimeInService, Aircraft aircraft) { // NaN/Infinity would poison every Time Left calculation, and a meter // reading can't be negative. - for (Double v : new Double[] { newBlockTime, newTimeInService }) { + for (Double v : new Double[] { newHobbsTime, newTimeInService }) { if (v != null && (!Double.isFinite(v) || v < 0)) { throw new IllegalArgumentException("Hours must be a number of 0 or more."); } } - for (Double v : new Double[] { blockTimeToAdd, timeInServiceToAdd }) { + for (Double v : new Double[] { hobbsTimeToAdd, timeInServiceToAdd }) { if (v != null && !Double.isFinite(v)) { throw new IllegalArgumentException("Hours must be a number."); } } // Checked up front so a rejected add never leaves the aircraft half-updated. - double currentBlock = aircraft.getBlockTimeHours() == null ? 0 : aircraft.getBlockTimeHours(); + double currentHobbs = aircraft.getHobbsTimeHours() == null ? 0 : aircraft.getHobbsTimeHours(); double currentService = aircraft.getTimeInServiceHours() == null ? 0 : aircraft.getTimeInServiceHours(); - if ((newBlockTime == null && blockTimeToAdd != null && currentBlock + blockTimeToAdd < 0) + if ((newHobbsTime == null && hobbsTimeToAdd != null && currentHobbs + hobbsTimeToAdd < 0) || (newTimeInService == null && timeInServiceToAdd != null && currentService + timeInServiceToAdd < 0)) { throw new IllegalArgumentException("That would make your hours negative."); } @@ -57,23 +57,23 @@ public void updateHours(Double blockTimeToAdd, System.out.println("=========="); - if (newBlockTime != null) { //If newBlockTime has a value - aircraft.setBlockTimeHours(newBlockTime); + if (newHobbsTime != null) { //If newHobbsTime has a value + aircraft.setHobbsTimeHours(newHobbsTime); // Manual edit also sets the floor — logs can raise this, never lower it. - aircraft.setBlockTimeManualBaseline(newBlockTime); - System.out.println("Setting BlockTime time to: " + newBlockTime); + aircraft.setHobbsTimeManualBaseline(newHobbsTime); + System.out.println("Setting HobbsTime time to: " + newHobbsTime); updated = true; - } else if (blockTimeToAdd != null) { //else if blockTimeToAdd has a value - double currentBlockTime = aircraft.getBlockTimeHours(); - double computedBlockTime = Formatting.roundHours(currentBlockTime + blockTimeToAdd); - aircraft.setBlockTimeHours(computedBlockTime); - aircraft.setBlockTimeManualBaseline(computedBlockTime); - System.out.println("Adding " + blockTimeToAdd + " to current BlockTime: " + currentBlockTime); + } else if (hobbsTimeToAdd != null) { //else if hobbsTimeToAdd has a value + double currentHobbsTime = aircraft.getHobbsTimeHours(); + double computedHobbsTime = Formatting.roundHours(currentHobbsTime + hobbsTimeToAdd); + aircraft.setHobbsTimeHours(computedHobbsTime); + aircraft.setHobbsTimeManualBaseline(computedHobbsTime); + System.out.println("Adding " + hobbsTimeToAdd + " to current HobbsTime: " + currentHobbsTime); updated = true; } - double finalBlockTime = aircraft.getBlockTimeHours(); - System.out.println("Current blockTime: " + finalBlockTime); + double finalHobbsTime = aircraft.getHobbsTimeHours(); + System.out.println("Current hobbsTime: " + finalHobbsTime); if (newTimeInService != null) { //If newTimeInService has a value aircraft.setTimeInServiceHours(newTimeInService); @@ -97,9 +97,9 @@ public void updateHours(Double blockTimeToAdd, } java.time.Instant now = java.time.Instant.now(); - if (newBlockTime != null || blockTimeToAdd != null) { - aircraft.setBlockTimeUpdatedAt(now); - aircraft.setBlockTimeUpdatedSource("manual"); + if (newHobbsTime != null || hobbsTimeToAdd != null) { + aircraft.setHobbsTimeUpdatedAt(now); + aircraft.setHobbsTimeUpdatedSource("manual"); } if (newTimeInService != null || timeInServiceToAdd != null) { aircraft.setTimeInServiceUpdatedAt(now); @@ -122,7 +122,7 @@ public record AccuracyIssue(Double expectedFloor, Double expectedCeiling, Double // this pair -- without those there's nothing to compare chronologically, // so it's waved through (same as before this feature existed). public AccuracyIssue checkAccuracy(List existingLogs, Instant candidateStart, Instant candidateEnd, - Double enteredOut, Double enteredIn, boolean useBlockTime) { + Double enteredOut, Double enteredIn, boolean useHobbsTime) { if (candidateStart == null || candidateEnd == null || enteredOut == null || enteredIn == null) { return null; } @@ -131,10 +131,10 @@ public AccuracyIssue checkAccuracy(List existingLogs, Instant candida Double ceiling = null; // lowest known reading at/after candidateEnd for (FlightLog log : existingLogs) { - Instant logStart = useBlockTime ? log.getBlockTimeStart() : log.getTimeInServiceStart(); - Instant logEnd = useBlockTime ? log.getBlockTimeEnd() : log.getTimeInServiceEnd(); - Double logOut = useBlockTime ? log.getBlockTimeOut() : log.getTimeInServiceOut(); - Double logIn = useBlockTime ? log.getBlockTimeIn() : log.getTimeInServiceIn(); + Instant logStart = useHobbsTime ? log.getHobbsTimeStart() : log.getTimeInServiceStart(); + Instant logEnd = useHobbsTime ? log.getHobbsTimeEnd() : log.getTimeInServiceEnd(); + Double logOut = useHobbsTime ? log.getHobbsTimeOut() : log.getTimeInServiceOut(); + Double logIn = useHobbsTime ? log.getHobbsTimeIn() : log.getTimeInServiceIn(); if (logStart == null || logEnd == null || logOut == null || logIn == null) continue; if (!logEnd.isAfter(candidateStart) && (floor == null || logIn > floor)) { @@ -155,7 +155,7 @@ public AccuracyIssue checkAccuracy(List existingLogs, Instant candida /** * Walks one aircraft's flight logs in real chronological order (by - * blockTimeStart or timeInServiceStart, whichever pair useBlockTime + * hobbsTimeStart or timeInServiceStart, whichever pair useHobbsTime * selects) and recomputes Out/In for every non-manual row so the chain * stays accurate no matter what order flights were entered in. * @@ -169,24 +169,24 @@ public AccuracyIssue checkAccuracy(List existingLogs, Instant candida * absolute numbers to wherever this flight actually falls in time. * * Returns the final running total, which becomes the aircraft's displayed - * blockTimeHours/timeInServiceHours. Saves every row it changes; does + * hobbsTimeHours/timeInServiceHours. Saves every row it changes; does * not save the aircraft -- the caller sets the displayed hours field itself. */ @Transactional - public double recomputeChain(Aircraft aircraft, boolean useBlockTime) { - Double baselineBoxed = useBlockTime ? aircraft.getBlockTimeManualBaseline() : aircraft.getTimeInServiceManualBaseline(); + public double recomputeChain(Aircraft aircraft, boolean useHobbsTime) { + Double baselineBoxed = useHobbsTime ? aircraft.getHobbsTimeManualBaseline() : aircraft.getTimeInServiceManualBaseline(); if (baselineBoxed == null) { - baselineBoxed = useBlockTime ? aircraft.getBlockTimeHours() : aircraft.getTimeInServiceHours(); - if (useBlockTime) aircraft.setBlockTimeManualBaseline(baselineBoxed); + baselineBoxed = useHobbsTime ? aircraft.getHobbsTimeHours() : aircraft.getTimeInServiceHours(); + if (useHobbsTime) aircraft.setHobbsTimeManualBaseline(baselineBoxed); else aircraft.setTimeInServiceManualBaseline(baselineBoxed); } List chain = flightLogRepository.findByAircraft(aircraft).stream() - .filter(log -> (useBlockTime ? log.getBlockTimeOut() : log.getTimeInServiceOut()) != null - && (useBlockTime ? log.getBlockTimeIn() : log.getTimeInServiceIn()) != null) + .filter(log -> (useHobbsTime ? log.getHobbsTimeOut() : log.getTimeInServiceOut()) != null + && (useHobbsTime ? log.getHobbsTimeIn() : log.getTimeInServiceIn()) != null) .sorted(Comparator .comparing(log -> { - Instant start = useBlockTime ? log.getBlockTimeStart() : log.getTimeInServiceStart(); + Instant start = useHobbsTime ? log.getHobbsTimeStart() : log.getTimeInServiceStart(); return start == null ? Instant.MAX : start; }) .thenComparing(FlightLog::getId)) @@ -195,22 +195,22 @@ public double recomputeChain(Aircraft aircraft, boolean useBlockTime) { double running = Formatting.roundHours(baselineBoxed); List toSave = new ArrayList<>(); for (FlightLog log : chain) { - Instant start = useBlockTime ? log.getBlockTimeStart() : log.getTimeInServiceStart(); + Instant start = useHobbsTime ? log.getHobbsTimeStart() : log.getTimeInServiceStart(); boolean isAnchor = start == null || "manual".equals(log.getEffectiveSource()); if (isAnchor) { - double in = useBlockTime ? log.getBlockTimeIn() : log.getTimeInServiceIn(); + double in = useHobbsTime ? log.getHobbsTimeIn() : log.getTimeInServiceIn(); running = Formatting.roundHours(Math.max(running, in)); } else { - double out = useBlockTime ? log.getBlockTimeOut() : log.getTimeInServiceOut(); - double in = useBlockTime ? log.getBlockTimeIn() : log.getTimeInServiceIn(); + double out = useHobbsTime ? log.getHobbsTimeOut() : log.getTimeInServiceOut(); + double in = useHobbsTime ? log.getHobbsTimeIn() : log.getTimeInServiceIn(); // Round every step so error can't accumulate down the chain. double duration = Formatting.roundHours(in - out); double newOut = Formatting.roundHours(running); double newIn = Formatting.roundHours(running + duration); - if (useBlockTime) { - log.setBlockTimeOut(newOut); - log.setBlockTimeIn(newIn); + if (useHobbsTime) { + log.setHobbsTimeOut(newOut); + log.setHobbsTimeIn(newIn); } else { log.setTimeInServiceOut(newOut); log.setTimeInServiceIn(newIn); diff --git a/src/main/java/com/example/AviaryService/services/dashboard/PdfExportService.java b/src/main/java/com/example/AviaryService/services/dashboard/PdfExportService.java index facded2..c167eae 100644 --- a/src/main/java/com/example/AviaryService/services/dashboard/PdfExportService.java +++ b/src/main/java/com/example/AviaryService/services/dashboard/PdfExportService.java @@ -58,7 +58,7 @@ public byte[] generateDashboardPdf(Aircraft aircraft, LocalDate today) { context.setVariable("tailNumber", aircraft.getTailNumber()); context.setVariable("ownerName", aircraft.getOwnerName()); context.setVariable("makeModelSN", aircraft.getMakeModelSN()); - context.setVariable("blockTimeHours", formatHoursOrBlank(aircraft.getBlockTimeHours())); + context.setVariable("hobbsTimeHours", formatHoursOrBlank(aircraft.getHobbsTimeHours())); context.setVariable("timeInServiceHours", formatHoursOrBlank(aircraft.getTimeInServiceHours())); context.setVariable("generatedAt", DateTimeFormatter.ofPattern("MMM d, yyyy h:mm a") .withZone(ZoneOffset.UTC).format(Instant.now()) + " UTC"); @@ -130,7 +130,7 @@ private List> buildLogRows(Aircraft aircraft) { List logs = flightLogRepository.findByAircraft(aircraft).stream() .sorted(Comparator .comparing(log -> { - Instant start = log.getBlockTimeStart() != null ? log.getBlockTimeStart() : log.getTimeInServiceStart(); + Instant start = log.getHobbsTimeStart() != null ? log.getHobbsTimeStart() : log.getTimeInServiceStart(); return start == null ? Instant.MAX : start; }) .thenComparing(FlightLog::getId)) @@ -139,12 +139,12 @@ private List> buildLogRows(Aircraft aircraft) { List> rows = new ArrayList<>(); for (FlightLog log : logs) { Map row = new HashMap<>(); - Instant start = log.getBlockTimeStart() != null ? log.getBlockTimeStart() : log.getTimeInServiceStart(); + Instant start = log.getHobbsTimeStart() != null ? log.getHobbsTimeStart() : log.getTimeInServiceStart(); row.put("date", start == null ? "" : FLIGHT_DATE.format(start)); row.put("fromAirport", log.getFromAirport()); row.put("toAirport", log.getToAirport()); - row.put("blockTimeOut", formatHoursOrBlank(log.getBlockTimeOut())); - row.put("blockTimeIn", formatHoursOrBlank(log.getBlockTimeIn())); + row.put("hobbsTimeOut", formatHoursOrBlank(log.getHobbsTimeOut())); + row.put("hobbsTimeIn", formatHoursOrBlank(log.getHobbsTimeIn())); row.put("timeInServiceOut", formatHoursOrBlank(log.getTimeInServiceOut())); row.put("timeInServiceIn", formatHoursOrBlank(log.getTimeInServiceIn())); rows.add(row); diff --git a/src/main/java/com/example/AviaryService/services/flights/FlightLogService.java b/src/main/java/com/example/AviaryService/services/flights/FlightLogService.java index e4d3450..63a1932 100644 --- a/src/main/java/com/example/AviaryService/services/flights/FlightLogService.java +++ b/src/main/java/com/example/AviaryService/services/flights/FlightLogService.java @@ -38,8 +38,8 @@ public FlightLogService(FlightLogRepository flightLogRepository, this.hoursService = hoursService; } - // The user's Block Time and Time in Service totals after a log change. - public record HourTotals(double blockTime, double timeInService) {} + // The user's Hobbs Time and Time in Service totals after a log change. + public record HourTotals(double hobbsTime, double timeInService) {} // A saved log plus the totals it produced. public record AddedFlightLog(FlightLog log, HourTotals totals) {} @@ -68,8 +68,8 @@ public AddedFlightLog add(User user, Aircraft aircraft, FlightLog newLog, boolea // Clamp readings to hundredths. Real meters never exceed 2dp (block // time 0.1, time in service 0.01), and this keeps CSV-prefilled or client-computed // values from carrying float artifacts into storage. - newLog.setBlockTimeOut(Formatting.roundHoursOrNull(newLog.getBlockTimeOut())); - newLog.setBlockTimeIn(Formatting.roundHoursOrNull(newLog.getBlockTimeIn())); + newLog.setHobbsTimeOut(Formatting.roundHoursOrNull(newLog.getHobbsTimeOut())); + newLog.setHobbsTimeIn(Formatting.roundHoursOrNull(newLog.getHobbsTimeIn())); newLog.setTimeInServiceOut(Formatting.roundHoursOrNull(newLog.getTimeInServiceOut())); newLog.setTimeInServiceIn(Formatting.roundHoursOrNull(newLog.getTimeInServiceIn())); @@ -80,31 +80,31 @@ public AddedFlightLog add(User user, Aircraft aircraft, FlightLog newLog, boolea // ── Validation ───────────────────────────────────────────────────────── // Reject incomplete entries before they can corrupt displayed hours. - // Rule: must provide at least one COMPLETE pair (blockTimeOut+blockTimeIn or + // Rule: must provide at least one COMPLETE pair (hobbsTimeOut+hobbsTimeIn or // timeInServiceOut+timeInServiceIn). Partial pairs (e.g. only timeInServiceOut) are the exact case // that used to silently wipe the user's manual hours to zero. - Double ho = newLog.getBlockTimeOut(), hi = newLog.getBlockTimeIn(); + Double ho = newLog.getHobbsTimeOut(), hi = newLog.getHobbsTimeIn(); Double to = newLog.getTimeInServiceOut(), ti = newLog.getTimeInServiceIn(); - boolean blockTimePair = (ho != null && hi != null); + boolean hobbsTimePair = (ho != null && hi != null); boolean timeInServicePair = (to != null && ti != null); - boolean blockTimePartial = (ho == null) != (hi == null); // exactly one set + boolean hobbsTimePartial = (ho == null) != (hi == null); // exactly one set boolean timeInServicePartial = (to == null) != (ti == null); - if (!blockTimePair && !timeInServicePair) { + if (!hobbsTimePair && !timeInServicePair) { throw new IllegalArgumentException( - "Enter both Block Time Out and Block Time In, or both Time in Service Out and Time in Service In."); + "Enter both Hobbs Time Out and Hobbs Time In, or both Time in Service Out and Time in Service In."); } - if (blockTimePartial) { + if (hobbsTimePartial) { throw new IllegalArgumentException( - "Block time entry is incomplete — enter both Block Time Out and Block Time In."); + "Hobbs time entry is incomplete — enter both Hobbs Time Out and Hobbs Time In."); } if (timeInServicePartial) { throw new IllegalArgumentException( "Time in Service entry is incomplete — enter both Time in Service Out and Time in Service In."); } - if (blockTimePair && (ho < 0 || hi < 0 || hi < ho)) { + if (hobbsTimePair && (ho < 0 || hi < 0 || hi < ho)) { throw new IllegalArgumentException( - "Block Time In must be ≥ Block Time Out, and values cannot be negative."); + "Hobbs Time In must be ≥ Hobbs Time Out, and values cannot be negative."); } if (timeInServicePair && (to < 0 || ti < 0 || ti < to)) { throw new IllegalArgumentException( @@ -126,14 +126,14 @@ public AddedFlightLog add(User user, Aircraft aircraft, FlightLog newLog, boolea // "inaccurate": it just gets slotted into the chain below. if ("manual".equals(source) && !force) { List existingLogs = flightLogRepository.findByAircraft(aircraft); - HoursService.AccuracyIssue blockIssue = blockTimePair - ? hoursService.checkAccuracy(existingLogs, newLog.getBlockTimeStart(), newLog.getBlockTimeEnd(), ho, hi, true) + HoursService.AccuracyIssue hobbsIssue = hobbsTimePair + ? hoursService.checkAccuracy(existingLogs, newLog.getHobbsTimeStart(), newLog.getHobbsTimeEnd(), ho, hi, true) : null; HoursService.AccuracyIssue serviceIssue = timeInServicePair ? hoursService.checkAccuracy(existingLogs, newLog.getTimeInServiceStart(), newLog.getTimeInServiceEnd(), to, ti, false) : null; - if (blockIssue != null || serviceIssue != null) { - throw new InaccurateEntryException(inaccuracyMessage(blockIssue, serviceIssue)); + if (hobbsIssue != null || serviceIssue != null) { + throw new InaccurateEntryException(inaccuracyMessage(hobbsIssue, serviceIssue)); } } @@ -175,20 +175,20 @@ public HourTotals delete(User user, Long id) { // Re-derives both hour totals from the log chain and stamps them as // coming from the flight log. private HourTotals recomputeHours(Aircraft aircraft) { - double newBlockTime = hoursService.recomputeChain(aircraft, /*useBlockTime=*/true); - double newTimeInService = hoursService.recomputeChain(aircraft, /*useBlockTime=*/false); - aircraft.setBlockTimeHours(newBlockTime); + double newHobbsTime = hoursService.recomputeChain(aircraft, /*useHobbsTime=*/true); + double newTimeInService = hoursService.recomputeChain(aircraft, /*useHobbsTime=*/false); + aircraft.setHobbsTimeHours(newHobbsTime); aircraft.setTimeInServiceHours(newTimeInService); Instant flightNow = Instant.now(); - aircraft.setBlockTimeUpdatedAt(flightNow); - aircraft.setBlockTimeUpdatedSource("flightlog"); + aircraft.setHobbsTimeUpdatedAt(flightNow); + aircraft.setHobbsTimeUpdatedSource("flightlog"); aircraft.setTimeInServiceUpdatedAt(flightNow); aircraft.setTimeInServiceUpdatedSource("flightlog"); aircraftRepository.save(aircraft); - return new HourTotals(newBlockTime, newTimeInService); + return new HourTotals(newHobbsTime, newTimeInService); } - // Chronological order for display: prefer blockTimeStart (engine start), + // Chronological order for display: prefer hobbsTimeStart (engine start), // fall back to timeInServiceStart (wheels-off) when only that's known. // Rows with neither (legacy entries, or a manual entry saved without // dates) sort last, in insertion order among themselves. @@ -196,7 +196,7 @@ private static List sortedByFlightTime(List logs) { return logs.stream() .sorted(Comparator .comparing(log -> { - Instant t = log.getBlockTimeStart() != null ? log.getBlockTimeStart() : log.getTimeInServiceStart(); + Instant t = log.getHobbsTimeStart() != null ? log.getHobbsTimeStart() : log.getTimeInServiceStart(); return t == null ? Instant.MAX : t; }) .thenComparing(FlightLog::getId)) @@ -207,9 +207,9 @@ private static boolean tooLong(String value) { return value != null && value.length() > Validation.MAX_TEXT; } - private static String inaccuracyMessage(HoursService.AccuracyIssue blockIssue, HoursService.AccuracyIssue serviceIssue) { + private static String inaccuracyMessage(HoursService.AccuracyIssue hobbsIssue, HoursService.AccuracyIssue serviceIssue) { List sentences = new ArrayList<>(); - if (blockIssue != null) sentences.add(describeAccuracyIssue("Block Time", blockIssue)); + if (hobbsIssue != null) sentences.add(describeAccuracyIssue("Hobbs Time", hobbsIssue)); if (serviceIssue != null) sentences.add(describeAccuracyIssue("Time in Service", serviceIssue)); return "This entry doesn't match your other flight logs. " + String.join(" ", sentences) + " Add it anyway?"; diff --git a/src/main/java/com/example/AviaryService/services/flights/FlightSuggestionService.java b/src/main/java/com/example/AviaryService/services/flights/FlightSuggestionService.java index 6846816..14ca7e1 100644 --- a/src/main/java/com/example/AviaryService/services/flights/FlightSuggestionService.java +++ b/src/main/java/com/example/AviaryService/services/flights/FlightSuggestionService.java @@ -47,7 +47,7 @@ public FlightLog accept(long suggestionId, User user) { throw new IllegalArgumentException("This flight is already in your log book."); } - // Block Time can't come from AeroAPI (no engine data) -- stays blank + // Hobbs Time can't come from AeroAPI (no engine data) -- stays blank // for the user to fill in. Time in Service IS the flight's airborne // duration (ADSB_SYNC_SPEC.md, "the real maintenance clock"). Out/In // are just seeded with the right duration here -- this suggestion @@ -66,7 +66,7 @@ public FlightLog accept(long suggestionId, User user) { flightLog.setAircraft(aircraft); flightLogRepository.save(flightLog); - double newTimeInService = hoursService.recomputeChain(aircraft, /*useBlockTime=*/false); + double newTimeInService = hoursService.recomputeChain(aircraft, /*useHobbsTime=*/false); aircraft.setTimeInServiceHours(newTimeInService); Instant now = Instant.now(); aircraft.setTimeInServiceUpdatedAt(now); diff --git a/src/main/java/com/example/AviaryService/services/flights/GarminCsvService.java b/src/main/java/com/example/AviaryService/services/flights/GarminCsvService.java index 999b039..e8ce6d4 100644 --- a/src/main/java/com/example/AviaryService/services/flights/GarminCsvService.java +++ b/src/main/java/com/example/AviaryService/services/flights/GarminCsvService.java @@ -12,7 +12,7 @@ import com.example.AviaryService.entity.Aircraft; // Reads a Garmin G1000 CSV file for the logbook's "Upload CSV" button and works -// out the block time and airborne time. Only reads; nothing is saved until the +// out the Hobbs time and airborne time. Only reads; nothing is saved until the // user submits the pre-filled flight log. @Service public class GarminCsvService { @@ -25,16 +25,16 @@ static CsvParseResult error(Map body) { } } - // Reads a Garmin engine-data CSV and works out the flight's block time + // Reads a Garmin engine-data CSV and works out the flight's Hobbs time // (engine running) and airborne time, then pre-fills Out/In readings // from the user's current hours. Returns ok=false with an "error" entry // when the file isn't a Garmin CSV or no engine run is found. public CsvParseResult parse(InputStream in, Aircraft aircraft) { - // Block time: first → last row where oil pressure > 15 psi. - // Mirrors the physical BlockTime meter on the Cirrus, which is oil-pressure activated. - java.time.Instant blockStart = null; - java.time.Instant blockEnd = null; + // Hobbs time: first → last row where oil pressure > 15 psi. + // Mirrors the physical HobbsTime meter on the Cirrus, which is oil-pressure activated. + java.time.Instant hobbsStart = null; + java.time.Instant hobbsEnd = null; // Flight (airborne) time: GndSpd > 35 kt sustained for 3+ consecutive seconds. // Falls back to IAS when GndSpd is empty (no GPS fix yet). @@ -102,13 +102,13 @@ public CsvParseResult parse(InputStream in, Aircraft aircraft) { rowTime = java.time.OffsetDateTime.parse(cols[dateIdx] + "T" + cols[timeIdx] + cols[ofstIdx]).toInstant(); } catch (Exception e) { continue; } - // ── Block time via oil pressure ────────────────────────────────── + // ── Hobbs time via oil pressure ────────────────────────────────── Integer oilPIdx = headerIndexMap.get("E1 OilP"); if(oilPIdx != null && cols.length > oilPIdx && !cols[oilPIdx].isEmpty()) { try { if(Double.parseDouble(cols[oilPIdx]) > 15.0) { - if(blockStart == null) blockStart = rowTime; - blockEnd = rowTime; + if(hobbsStart == null) hobbsStart = rowTime; + hobbsEnd = rowTime; } } catch(NumberFormatException ignored) {} } @@ -137,29 +137,29 @@ public CsvParseResult parse(InputStream in, Aircraft aircraft) { } } - if(blockStart == null && airborneStart == null) { + if(hobbsStart == null && airborneStart == null) { return CsvParseResult.error( - csvValues("Could not detect airtime or block time", blockStart, blockEnd, airborneStart, airborneEnd)); + csvValues("Could not detect airtime or Hobbs time", hobbsStart, hobbsEnd, airborneStart, airborneEnd)); } - if(blockStart == null || blockEnd == null) { + if(hobbsStart == null || hobbsEnd == null) { return CsvParseResult.error( - csvValues("Could not detect engine run — Oil pressure does not go up by 15psi", blockStart, blockEnd, airborneStart, airborneEnd)); + csvValues("Could not detect engine run — Oil pressure does not go up by 15psi", hobbsStart, hobbsEnd, airborneStart, airborneEnd)); } /* if(airborneStart == null || airborneEnd == null) { return CsvParseResult.error( - csvValues("Could not detect air time — Speed does not go above 35kts", blockStart, blockEnd, airborneStart, airborneEnd)); + csvValues("Could not detect air time — Speed does not go above 35kts", hobbsStart, hobbsEnd, airborneStart, airborneEnd)); } */ //Calculate Block duration //Create Block String H: M: S: - Duration blockDuration = Duration.between(blockStart, blockEnd); - String blockStr = "H:" + blockDuration.toHoursPart() + " M:" + blockDuration.toMinutesPart() + " S:" + blockDuration.toSecondsPart(); + Duration hobbsDuration = Duration.between(hobbsStart, hobbsEnd); + String hobbsStr = "H:" + hobbsDuration.toHoursPart() + " M:" + hobbsDuration.toMinutesPart() + " S:" + hobbsDuration.toSecondsPart(); String airStr = "N/A"; @@ -169,8 +169,8 @@ public CsvParseResult parse(InputStream in, Aircraft aircraft) { airStr = "H:" + airDuration.toHoursPart() + " M:" + airDuration.toMinutesPart() + " S:" + airDuration.toSecondsPart(); } - double blockTimeOut = aircraft.getBlockTimeHours(); - double blockTimeIn = Math.round((blockTimeOut + blockDuration.toSeconds() / 3600.0) * 100.0) / 100.0; + double hobbsTimeOut = aircraft.getHobbsTimeHours(); + double hobbsTimeIn = Math.round((hobbsTimeOut + hobbsDuration.toSeconds() / 3600.0) * 100.0) / 100.0; double timeInServiceOut = aircraft.getTimeInServiceHours(); Double timeInServiceIn = airDuration != null ? Math.round((timeInServiceOut + airDuration.toSeconds() / 3600.0) * 100.0) / 100.0 @@ -178,12 +178,16 @@ public CsvParseResult parse(InputStream in, Aircraft aircraft) { Map result = new HashMap<>(); result.put("message", "CSV parse completed"); - result.put("flightDuration", blockStr); + result.put("flightDuration", hobbsStr); result.put("airDuration", airStr); - result.put("blockTimeOut", blockTimeOut); - result.put("blockTimeIn", blockTimeIn); - result.put("blockTimeStart", blockStart.toString()); - result.put("blockTimeEnd", blockEnd.toString()); + result.put("hobbsTimeOut", hobbsTimeOut); + result.put("blockTimeOut", hobbsTimeOut); // legacy key, remove after 2026-12-31 + result.put("hobbsTimeIn", hobbsTimeIn); + result.put("blockTimeIn", hobbsTimeIn); // legacy key, remove after 2026-12-31 + result.put("hobbsTimeStart", hobbsStart.toString()); + result.put("blockTimeStart", hobbsStart.toString()); // legacy key, remove after 2026-12-31 + result.put("hobbsTimeEnd", hobbsEnd.toString()); + result.put("blockTimeEnd", hobbsEnd.toString()); // legacy key, remove after 2026-12-31 result.put("timeInServiceOut", timeInServiceIn != null ? timeInServiceOut : null); result.put("timeInServiceIn", timeInServiceIn); result.put("timeInServiceStart", airborneStart != null ? airborneStart.toString() : null); @@ -199,11 +203,13 @@ public CsvParseResult parse(InputStream in, Aircraft aircraft) { } - private static Map csvValues(String error, java.time.Instant blockStart, java.time.Instant blockEnd, java.time.Instant airborneStart, java.time.Instant airborneEnd) { + private static Map csvValues(String error, java.time.Instant hobbsStart, java.time.Instant hobbsEnd, java.time.Instant airborneStart, java.time.Instant airborneEnd) { Map map = new HashMap<>(); map.put("error", error); - map.put("blockStart", blockStart); - map.put("blockEnd", blockEnd); + map.put("hobbsStart", hobbsStart); + map.put("blockStart", hobbsStart); // legacy key, remove after 2026-12-31 + map.put("hobbsEnd", hobbsEnd); + map.put("blockEnd", hobbsEnd); // legacy key, remove after 2026-12-31 map.put("airborneStart", airborneStart); map.put("airborneEnd", airborneEnd); diff --git a/src/main/java/com/example/AviaryService/services/stats/PublicStatsService.java b/src/main/java/com/example/AviaryService/services/stats/PublicStatsService.java index 2fd617d..fdac5a1 100644 --- a/src/main/java/com/example/AviaryService/services/stats/PublicStatsService.java +++ b/src/main/java/com/example/AviaryService/services/stats/PublicStatsService.java @@ -107,7 +107,7 @@ private boolean isStale(PublicStatsSnapshot snap) { private PublicStatsSnapshot compute() { Instant now = clock.instant(); - // Hours flown = time in service. Block time is empty on production + // Hours flown = time in service. Hobbs time is empty on production // flights, so it would always show 0 (research R6). Double hours = flightLogRepository.sumHoursFlown(); double hoursFlown = hours == null ? 0.0 : Math.round(hours * 10.0) / 10.0; diff --git a/src/main/java/com/example/AviaryService/util/Formatting.java b/src/main/java/com/example/AviaryService/util/Formatting.java index 50188aa..c5b896d 100644 --- a/src/main/java/com/example/AviaryService/util/Formatting.java +++ b/src/main/java/com/example/AviaryService/util/Formatting.java @@ -4,7 +4,7 @@ public class Formatting { private Formatting() {} - // Real-world hour readings never exceed hundredths (block time reads to + // Real-world hour readings never exceed hundredths (Hobbs time reads to // 0.1, time in service to 0.01, AeroAPI is minute precision). Repeated double addition in // HoursService.recomputeChain otherwise leaves artifacts like // "2.0433333333333334". One home for the 2dp rule. diff --git a/src/main/resources/static/css/dashboardstyle.css b/src/main/resources/static/css/dashboardstyle.css index 6e0be60..207867c 100644 --- a/src/main/resources/static/css/dashboardstyle.css +++ b/src/main/resources/static/css/dashboardstyle.css @@ -152,7 +152,7 @@ input[type="checkbox"]:focus-visible { .fixed-header #subscribe, .edit-hours-btn, .back-to-full-list-button, -#add-block-time-btn, +#add-hobbs-time-btn, #add-time-in-service-btn, .add-button, .add-log-button, @@ -327,13 +327,13 @@ input[type="checkbox"]:focus-visible { .section-filter-label strong { color: var(--text); } -#add-block-time-btn, +#add-hobbs-time-btn, #add-time-in-service-btn { background: var(--primary); color: #fff; padding: 5px 10px; } -#add-block-time-btn:hover, #add-time-in-service-btn:hover { background: var(--primary-dark); } +#add-hobbs-time-btn:hover, #add-time-in-service-btn:hover { background: var(--primary-dark); } /* Utility actions — quiet outline style so they don't compete with the page's real work (the timeline and log book). */ @@ -385,7 +385,7 @@ input[type="checkbox"]:focus-visible { flex-wrap: wrap; } -.current-block-time-display, +.current-hobbs-time-display, .current-time-in-service-display { font-size: 15px; font-weight: 600; @@ -399,6 +399,12 @@ input[type="checkbox"]:focus-visible { gap: 2px; } +.hours-label-row { + display: inline-flex; + align-items: center; + flex-wrap: nowrap; +} + .hours-updated { font-size: 11px; font-weight: 500; @@ -2046,7 +2052,7 @@ textarea::placeholder { display: none; } .logbook-table thead { display: none; } .logbook-table tbody#logbook-body { display: flex; flex-direction: column; gap: 8px; margin: 0; } - /* Option C: each log = 2-col grid (From|To, Block Time Out|In, Time in Service Out|In) */ + /* Option C: each log = 2-col grid (From|To, Hobbs Time Out|In, Time in Service Out|In) */ .logbook-table tr.log-row, .logbook-table tr.add-log-row { display: grid; @@ -2740,3 +2746,52 @@ textarea::placeholder { display: none; } @media print { .aircraft-picker, #empty-timeline { display: none !important; } } + +/* Info marks next to Hobbs Time / Time in Service (My Hours). The tooltip + text comes from data-tip; it shows on hover, keyboard focus, or tap + (.open, toggled in dashboard.js). */ +.info-mark { + position: relative; + display: inline-flex; + align-items: center; + margin-left: 4px; + padding: 0; + border: 0; + background: none; + color: var(--text-muted); + font-size: 0.9em; + cursor: help; + vertical-align: middle; +} +.info-mark:focus-visible { outline: 2px solid var(--text-muted); outline-offset: 2px; border-radius: 50%; } +.info-mark::after { + content: attr(data-tip); + position: absolute; + left: 50%; + top: calc(100% + 6px); + transform: translateX(calc(-50% + var(--tip-shift, 0px))); + width: max-content; + max-width: min(260px, calc(100vw - 32px)); + padding: 6px 10px; + border: 1px solid var(--border); + border-radius: 6px; + background: var(--surface); + color: var(--text); + font-size: 12px; + font-weight: normal; + line-height: 1.35; + text-align: left; + white-space: normal; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12); + z-index: 50; + display: none; + pointer-events: none; +} +.info-mark:hover::after, +.info-mark:focus-visible::after, +.info-mark.open::after { display: block; } +/* Phones: the info marks add ~17px per hours block. Tighter column spacing + keeps both blocks on one line, so My Hours doesn't grow taller. */ +@media (max-width: 480px) { + .hours-display-and-editbutton-container { column-gap: 12px; } +} diff --git a/src/main/resources/static/js/dashboard.js b/src/main/resources/static/js/dashboard.js index 1346300..5a4bc95 100644 --- a/src/main/resources/static/js/dashboard.js +++ b/src/main/resources/static/js/dashboard.js @@ -4,7 +4,7 @@ console.log('dashboard.js loaded'); // meant editing a second row (or field) within 500ms cancelled the first save. const rowSaveTimers = new Map(); const userInfoSaveTimers = new Map(); -let previousBlockTimeHours = document.getElementById('current-block-time')?.value || 0; +let previousHobbsTimeHours = document.getElementById('current-hobbs-time')?.value || 0; let previousTimeInServiceHours = document.getElementById('current-time-in-service')?.value || 0; // True from a successful CSV parse until the next Add (or a fresh upload) -- // tells the server this Out/In pair was computed from CSV data, not typed by @@ -141,7 +141,7 @@ function renderUpdatedFromData(elId) { if (el) el.textContent = formatUpdated(el.getAttribute('data-updated'), el.getAttribute('data-source')); } -// When a Block Time / Time in Service reading was actually taken -- distinct +// When a Hobbs Time / Time in Service reading was actually taken -- distinct // from formatUpdated above, which is "when this field was last edited." function formatLogTimestamp(iso) { if (!iso) return ''; @@ -197,8 +197,8 @@ function buildLogRowHtml(log) { return ` ${escapeHtml(log.fromAirport)} ${escapeHtml(log.toAirport)} - ${log.blockTimeOut ?? ''}${formatLogTimestamp(log.blockTimeStart)} - ${log.blockTimeIn ?? ''}${formatLogTimestamp(log.blockTimeEnd)} + ${log.hobbsTimeOut ?? ''}${formatLogTimestamp(log.hobbsTimeStart)} + ${log.hobbsTimeIn ?? ''}${formatLogTimestamp(log.hobbsTimeEnd)} ${log.timeInServiceOut ?? ''}${formatLogTimestamp(log.timeInServiceStart)} ${log.timeInServiceIn ?? ''}${formatLogTimestamp(log.timeInServiceEnd)} @@ -873,10 +873,10 @@ document.addEventListener('DOMContentLoaded', () => { scheduleMidnightUpdate(); // My Hours "last updated" lines (initial render from server data) - renderUpdatedFromData('block-time-updated'); + renderUpdatedFromData('hobbs-time-updated'); renderUpdatedFromData('time-in-service-updated'); - // Flight log rows: when each Block Time/Time in Service reading was taken + // Flight log rows: when each Hobbs Time/Time in Service reading was taken renderLogTimestamps(); // Cycle hours come from the server as a Double ("500.0"); show whole @@ -1059,7 +1059,7 @@ document.addEventListener('DOMContentLoaded', () => { button.closest('.type-dropdown').style.display = 'none'; } else if (event.target.classList.contains('edit-hours-btn')) { document.getElementById('add-time-in-service').value = ''; - document.getElementById('add-block-time').value = ''; + document.getElementById('add-hobbs-time').value = ''; const editSection = document.querySelector('.edit-hours-section'); editSection.style.display = editSection.style.display === 'flex' ? 'none' : 'flex'; } @@ -1242,19 +1242,19 @@ document.addEventListener('DOMContentLoaded', () => { options.forEach(option => option.onclick = () => selectOption(option)); }); - let previousBlockTimeHours = 0; + let previousHobbsTimeHours = 0; let previousTimeInServiceHours = 0; // One timer per field. A single shared timer meant that typing in TimeInService - // within 500ms of typing in BlockTime cancelled the pending BlockTime save. - let blockTimeout; + // within 500ms of typing in HobbsTime cancelled the pending HobbsTime save. + let hobbsTimeout; let timeInServiceTimeout; // The typed value still waiting out the 500ms debounce, or null if none. - let pendingBlockTimeSet = null; + let pendingHobbsTimeSet = null; let pendingTimeInServiceSet = null; - const currentBlockTimeHoursInput = document.getElementById('current-block-time'); + const currentHobbsTimeHoursInput = document.getElementById('current-hobbs-time'); const currentTimeInServiceHoursInput = document.getElementById('current-time-in-service'); function csrfHeaders() { @@ -1266,23 +1266,23 @@ document.addEventListener('DOMContentLoaded', () => { // Sends "set hours to exactly this". Returns a promise so callers can wait // for it to land before doing anything else. async function sendSetHours(kind, value) { - const isBlockTime = kind === 'blockTime'; - const input = isBlockTime ? currentBlockTimeHoursInput : currentTimeInServiceHoursInput; - const displayId = isBlockTime ? 'current-block-time-display' : 'current-time-in-service-display'; - const label = isBlockTime ? 'Block Time' : 'Time in Service'; - const previous = isBlockTime ? previousBlockTimeHours : previousTimeInServiceHours; + const isHobbsTime = kind === 'hobbsTime'; + const input = isHobbsTime ? currentHobbsTimeHoursInput : currentTimeInServiceHoursInput; + const displayId = isHobbsTime ? 'current-hobbs-time-display' : 'current-time-in-service-display'; + const label = isHobbsTime ? 'Hobbs Time' : 'Time in Service'; + const previous = isHobbsTime ? previousHobbsTimeHours : previousTimeInServiceHours; const params = new URLSearchParams(); - params.append(isBlockTime ? 'newBlockTime' : 'newTimeInService', parseFloat(value)); + params.append(isHobbsTime ? 'newHobbsTime' : 'newTimeInService', parseFloat(value)); try { const response = await axios.post('/updateHours', params, { headers: csrfHeaders() }); if (response.data.status === 'success') { - if (isBlockTime) previousBlockTimeHours = value; else previousTimeInServiceHours = value; + if (isHobbsTime) previousHobbsTimeHours = value; else previousTimeInServiceHours = value; document.getElementById(displayId).textContent = `${label}: ${value}`; - markUpdatedNow(isBlockTime ? 'block-time-updated' : 'time-in-service-updated', 'manual'); + markUpdatedNow(isHobbsTime ? 'hobbs-time-updated' : 'time-in-service-updated', 'manual'); console.log(`${label} hours updated successfully:`, - isBlockTime ? response.data.newBlockTime : response.data.newTimeInService); + isHobbsTime ? response.data.newHobbsTime : response.data.newTimeInService); return true; } console.error(`Failed to update ${label} hours:`, response.data.message); @@ -1299,31 +1299,31 @@ document.addEventListener('DOMContentLoaded', () => { // Called before "add hours" so a delayed set can never land afterwards and // overwrite the addition. async function flushPendingHours() { - clearTimeout(blockTimeout); + clearTimeout(hobbsTimeout); clearTimeout(timeInServiceTimeout); - const blockTime = pendingBlockTimeSet; + const hobbsTime = pendingHobbsTimeSet; const timeInService = pendingTimeInServiceSet; - pendingBlockTimeSet = null; + pendingHobbsTimeSet = null; pendingTimeInServiceSet = null; - if (blockTime !== null) await sendSetHours('blockTime', blockTime); + if (hobbsTime !== null) await sendSetHours('hobbsTime', hobbsTime); if (timeInService !== null) await sendSetHours('timeInService', timeInService); } - if (currentBlockTimeHoursInput) { - previousBlockTimeHours = currentBlockTimeHoursInput.value || 0; - currentBlockTimeHoursInput.addEventListener('input', function() { + if (currentHobbsTimeHoursInput) { + previousHobbsTimeHours = currentHobbsTimeHoursInput.value || 0; + currentHobbsTimeHoursInput.addEventListener('input', function() { updateAllTimeLeft(); updateAddRowTimeLeft(); - clearTimeout(blockTimeout); - const newBlockTimeHours = this.value.trim(); - if (newBlockTimeHours === '' || isNaN(parseFloat(newBlockTimeHours))) { - pendingBlockTimeSet = null; + clearTimeout(hobbsTimeout); + const newHobbsTimeHours = this.value.trim(); + if (newHobbsTimeHours === '' || isNaN(parseFloat(newHobbsTimeHours))) { + pendingHobbsTimeSet = null; return; } - pendingBlockTimeSet = newBlockTimeHours; - blockTimeout = setTimeout(() => { - pendingBlockTimeSet = null; - sendSetHours('blockTime', newBlockTimeHours); + pendingHobbsTimeSet = newHobbsTimeHours; + hobbsTimeout = setTimeout(() => { + pendingHobbsTimeSet = null; + sendSetHours('hobbsTime', newHobbsTimeHours); }, 500); }); } @@ -1641,9 +1641,9 @@ document.addEventListener('DOMContentLoaded', () => { document.addEventListener('click', function(event) { - if (event.target.id === 'add-block-time-btn') { - const blockTimeToAdd = document.getElementById('add-block-time').value.trim(); - addBlockTimeHours(blockTimeToAdd); + if (event.target.id === 'add-hobbs-time-btn') { + const hobbsTimeToAdd = document.getElementById('add-hobbs-time').value.trim(); + addHobbsTimeHours(hobbsTimeToAdd); } else if (event.target.id === 'add-time-in-service-btn') { const timeInServiceToAdd = document.getElementById('add-time-in-service').value.trim(); @@ -1808,10 +1808,10 @@ document.addEventListener('DOMContentLoaded', () => { }); }); - async function addBlockTimeHours(blockTimeToAdd) { - if (blockTimeToAdd && !isNaN(blockTimeToAdd)) { + async function addHobbsTimeHours(hobbsTimeToAdd) { + if (hobbsTimeToAdd && !isNaN(hobbsTimeToAdd)) { await flushPendingHours(); - await updateHours({ blockTimeToAdd: parseFloat(blockTimeToAdd) }); + await updateHours({ hobbsTimeToAdd: parseFloat(hobbsTimeToAdd) }); } } @@ -1840,13 +1840,13 @@ document.addEventListener('DOMContentLoaded', () => { }); if (response.data.status === 'success') { - const { newBlockTime, newTimeInService } = response.data; + const { newHobbsTime, newTimeInService } = response.data; - if (newBlockTime !== undefined) { - document.getElementById('current-block-time').value = newBlockTime; - document.getElementById('current-block-time-display').textContent = `Block Time: ${newBlockTime}`; - previousBlockTimeHours = newBlockTime; - console.log('Block time updated successfully:', newBlockTime); + if (newHobbsTime !== undefined) { + document.getElementById('current-hobbs-time').value = newHobbsTime; + document.getElementById('current-hobbs-time-display').textContent = `Hobbs Time: ${newHobbsTime}`; + previousHobbsTimeHours = newHobbsTime; + console.log('Hobbs time updated successfully:', newHobbsTime); } if (newTimeInService !== undefined) { @@ -1856,7 +1856,7 @@ document.addEventListener('DOMContentLoaded', () => { console.log('Time in Service updated successfully:', newTimeInService); } - if ('blockTimeToAdd' in updateParams) markUpdatedNow('block-time-updated', 'manual'); + if ('hobbsTimeToAdd' in updateParams) markUpdatedNow('hobbs-time-updated', 'manual'); if ('timeInServiceToAdd' in updateParams) markUpdatedNow('time-in-service-updated', 'manual'); // Update time left displays if needed (from your existing functions) @@ -2356,18 +2356,18 @@ document.addEventListener('DOMContentLoaded', () => { headers: { [csrfHeader]: csrfToken } }); allSuggestionsStale = true; // deleting can reset a suggestion back to pending - const { newBlockTime, newTimeInService } = deleteResponse.data; - if (newBlockTime !== undefined) { - document.getElementById('current-block-time').value = newBlockTime; - document.getElementById('current-block-time-display').textContent = `Block Time: ${newBlockTime}`; - previousBlockTimeHours = newBlockTime; + const { newHobbsTime, newTimeInService } = deleteResponse.data; + if (newHobbsTime !== undefined) { + document.getElementById('current-hobbs-time').value = newHobbsTime; + document.getElementById('current-hobbs-time-display').textContent = `Hobbs Time: ${newHobbsTime}`; + previousHobbsTimeHours = newHobbsTime; } if (newTimeInService !== undefined) { document.getElementById('current-time-in-service').value = newTimeInService; document.getElementById('current-time-in-service-display').textContent = `Time in Service: ${newTimeInService}`; previousTimeInServiceHours = newTimeInService; } - markUpdatedNow('block-time-updated', 'flightlog'); + markUpdatedNow('hobbs-time-updated', 'flightlog'); markUpdatedNow('time-in-service-updated', 'flightlog'); // A delete can shift other rows' Out/In too (see @@ -2385,8 +2385,8 @@ document.addEventListener('DOMContentLoaded', () => { async function submitAddFlightLog(force) { // Read raw strings first so an empty input stays null (not 0), letting // the server enforce the "complete pair" rule cleanly. - const rawBlockTimeIn = parseFloat(parseFloat(document.getElementById('blockTimeIn').value.trim()).toFixed(2)); - const rawBlockTimeOut = parseFloat(parseFloat(document.getElementById('blockTimeOut').value.trim()).toFixed(2)); + const rawHobbsTimeIn = parseFloat(parseFloat(document.getElementById('hobbsTimeIn').value.trim()).toFixed(2)); + const rawHobbsTimeOut = parseFloat(parseFloat(document.getElementById('hobbsTimeOut').value.trim()).toFixed(2)); const rawTimeInServiceIn = parseFloat(parseFloat(document.getElementById('timeInServiceIn').value.trim()).toFixed(2)); const rawTimeInServiceOut = parseFloat(parseFloat(document.getElementById('timeInServiceOut').value.trim()).toFixed(2)); const numOrNull = (s) => (s === '' || isNaN(parseFloat(s))) ? null : parseFloat(s); @@ -2394,12 +2394,12 @@ document.addEventListener('DOMContentLoaded', () => { const data = { fromAirport: document.getElementById('fromAirport').value, toAirport: document.getElementById('toAirport').value, - blockTimeOut: numOrNull(rawBlockTimeOut), - blockTimeIn: numOrNull(rawBlockTimeIn), + hobbsTimeOut: numOrNull(rawHobbsTimeOut), + hobbsTimeIn: numOrNull(rawHobbsTimeIn), timeInServiceOut: numOrNull(rawTimeInServiceOut), timeInServiceIn: numOrNull(rawTimeInServiceIn), - blockTimeStart: datetimeLocalToIso(document.getElementById('blockTimeStart').value), - blockTimeEnd: datetimeLocalToIso(document.getElementById('blockTimeEnd').value), + hobbsTimeStart: datetimeLocalToIso(document.getElementById('hobbsTimeStart').value), + hobbsTimeEnd: datetimeLocalToIso(document.getElementById('hobbsTimeEnd').value), timeInServiceStart: datetimeLocalToIso(document.getElementById('timeInServiceStart').value), timeInServiceEnd: datetimeLocalToIso(document.getElementById('timeInServiceEnd').value), source: csvPrefilled ? 'csv' : 'manual', @@ -2428,28 +2428,28 @@ document.addEventListener('DOMContentLoaded', () => { await refreshLogbookRows(); // Update hours display from backend-calculated totals - if (log.newBlockTime !== undefined && log.newBlockTime !== null) { - document.getElementById('current-block-time').value = log.newBlockTime; - document.getElementById('current-block-time-display').textContent = `Block Time: ${log.newBlockTime}`; - previousBlockTimeHours = log.newBlockTime; + if (log.newHobbsTime !== undefined && log.newHobbsTime !== null) { + document.getElementById('current-hobbs-time').value = log.newHobbsTime; + document.getElementById('current-hobbs-time-display').textContent = `Hobbs Time: ${log.newHobbsTime}`; + previousHobbsTimeHours = log.newHobbsTime; } if (log.newTimeInService !== undefined && log.newTimeInService !== null) { document.getElementById('current-time-in-service').value = log.newTimeInService; document.getElementById('current-time-in-service-display').textContent = `Time in Service: ${log.newTimeInService}`; previousTimeInServiceHours = log.newTimeInService; } - markUpdatedNow('block-time-updated', 'flightlog'); + markUpdatedNow('hobbs-time-updated', 'flightlog'); markUpdatedNow('time-in-service-updated', 'flightlog'); // Clear inputs document.getElementById('fromAirport').value = ''; document.getElementById('toAirport').value = ''; - document.getElementById('blockTimeIn').value = ''; - document.getElementById('blockTimeOut').value = ''; + document.getElementById('hobbsTimeIn').value = ''; + document.getElementById('hobbsTimeOut').value = ''; document.getElementById('timeInServiceIn').value = ''; document.getElementById('timeInServiceOut').value = ''; - document.getElementById('blockTimeStart').value = ''; - document.getElementById('blockTimeEnd').value = ''; + document.getElementById('hobbsTimeStart').value = ''; + document.getElementById('hobbsTimeEnd').value = ''; document.getElementById('timeInServiceStart').value = ''; document.getElementById('timeInServiceEnd').value = ''; csvPrefilled = false; @@ -2501,18 +2501,18 @@ document.addEventListener('DOMContentLoaded', () => { }); allSuggestionsStale = true; // deleting can reset a suggestion back to pending console.log(`Log ${id} deleted`); - const { newBlockTime, newTimeInService } = deleteResponse.data; - if (newBlockTime !== undefined) { - document.getElementById('current-block-time').value = newBlockTime; - document.getElementById('current-block-time-display').textContent = `Block Time: ${newBlockTime}`; - previousBlockTimeHours = newBlockTime; + const { newHobbsTime, newTimeInService } = deleteResponse.data; + if (newHobbsTime !== undefined) { + document.getElementById('current-hobbs-time').value = newHobbsTime; + document.getElementById('current-hobbs-time-display').textContent = `Hobbs Time: ${newHobbsTime}`; + previousHobbsTimeHours = newHobbsTime; } if (newTimeInService !== undefined) { document.getElementById('current-time-in-service').value = newTimeInService; document.getElementById('current-time-in-service-display').textContent = `Time in Service: ${newTimeInService}`; previousTimeInServiceHours = newTimeInService; } - markUpdatedNow('block-time-updated', 'flightlog'); + markUpdatedNow('hobbs-time-updated', 'flightlog'); markUpdatedNow('time-in-service-updated', 'flightlog'); updateAllTimeLeft(); updateAddRowTimeLeft(); @@ -2567,12 +2567,12 @@ document.addEventListener('DOMContentLoaded', () => { const data = response.data; showToast("CSV parsed successfully", 'info'); - document.getElementById("blockTimeOut").value = data.blockTimeOut ?? ''; - document.getElementById("blockTimeIn").value = data.blockTimeIn ?? ''; + document.getElementById("hobbsTimeOut").value = data.hobbsTimeOut ?? ''; + document.getElementById("hobbsTimeIn").value = data.hobbsTimeIn ?? ''; document.getElementById("timeInServiceOut").value = data.timeInServiceOut ?? ''; document.getElementById("timeInServiceIn").value = data.timeInServiceIn ?? ''; - document.getElementById("blockTimeStart").value = isoToDatetimeLocal(data.blockTimeStart); - document.getElementById("blockTimeEnd").value = isoToDatetimeLocal(data.blockTimeEnd); + document.getElementById("hobbsTimeStart").value = isoToDatetimeLocal(data.hobbsTimeStart); + document.getElementById("hobbsTimeEnd").value = isoToDatetimeLocal(data.hobbsTimeEnd); document.getElementById("timeInServiceStart").value = isoToDatetimeLocal(data.timeInServiceStart); document.getElementById("timeInServiceEnd").value = isoToDatetimeLocal(data.timeInServiceEnd); csvPrefilled = true; @@ -2588,9 +2588,9 @@ document.addEventListener('DOMContentLoaded', () => { const errorMessage = error.response?.data?.error || 'Upload failed'; showToast(errorMessage, 'error'); - console.log(errorData?.error); // "Could not detect airtime or block time" - console.log(errorData?.blockStart); // ISO instant string - console.log(errorData?.blockEnd); + console.log(errorData?.error); // "Could not detect airtime or Hobbs time" + console.log(errorData?.hobbsStart); // ISO instant string + console.log(errorData?.hobbsEnd); console.log(errorData?.airborneStart); console.log(errorData?.airborneEnd); @@ -2969,3 +2969,37 @@ document.addEventListener('DOMContentLoaded', function () { } }); }); + +// Info marks (My Hours). Hover and keyboard focus are handled in CSS; this +// adds tap-to-toggle for touch screens, closes on tap outside or Esc, and +// nudges the tooltip sideways so it never runs off a narrow screen. +function placeInfoTip(mark) { + const r = mark.getBoundingClientRect(); + const vw = document.documentElement.clientWidth; + const half = Math.min(260, vw - 32) / 2; + const center = r.left + r.width / 2; + let shift = 0; + if (center - half < 16) shift = 16 - (center - half); + else if (center + half > vw - 16) shift = (vw - 16) - (center + half); + mark.style.setProperty('--tip-shift', shift + 'px'); +} +document.addEventListener('mouseover', (e) => { + const mark = e.target.closest('.info-mark'); + if (mark) placeInfoTip(mark); +}); +document.addEventListener('focusin', (e) => { + const mark = e.target.closest('.info-mark'); + if (mark) placeInfoTip(mark); +}); +document.addEventListener('click', (e) => { + const mark = e.target.closest('.info-mark'); + document.querySelectorAll('.info-mark.open').forEach((m) => { + if (m !== mark) m.classList.remove('open'); + }); + if (mark) { placeInfoTip(mark); mark.classList.toggle('open'); } +}); +document.addEventListener('keydown', (e) => { + if (e.key === 'Escape') { + document.querySelectorAll('.info-mark.open').forEach((m) => m.classList.remove('open')); + } +}); diff --git a/src/main/resources/templates/dashboard.html b/src/main/resources/templates/dashboard.html index 8bde624..fa6865f 100644 --- a/src/main/resources/templates/dashboard.html +++ b/src/main/resources/templates/dashboard.html @@ -277,33 +277,33 @@

Add aircraft

- +

My Hours

- - + +
- +