Skip to content

feat: Implement drag-and-drop with position persistence for dashboard…#11

Merged
StuartF303 merged 1 commit intomainfrom
claude/camper-van-control-setup-011CUpsFKnx2JFyoEDjhfgbz
Nov 9, 2025
Merged

feat: Implement drag-and-drop with position persistence for dashboard…#11
StuartF303 merged 1 commit intomainfrom
claude/camper-van-control-setup-011CUpsFKnx2JFyoEDjhfgbz

Conversation

@StuartF303
Copy link
Copy Markdown
Owner

… overlays

Fixes drag functionality and adds position persistence for tank and control overlays on the dashboard diagram.

Index.razor (Frontend):

  • Replace broken HTML5 drag API with mouse event handlers
    • @onmousedown: Captures overlay and mouse position when drag starts
    • @OnMouseMove: Updates overlay position in real-time during drag
    • @onMouseUp: Saves position to backend when drag ends
  • Add ElementReference for diagram container to calculate dimensions
  • Add JSRuntime to get container dimensions for percentage calculations
  • Add LoadOverlayPositions method to fetch saved positions from API
  • Add SaveOverlayPosition method to persist positions to backend
  • Update CreateOverlaysFromTanks/Controls to use saved positions
  • Add savedPositions dictionary to cache positions locally
  • Add BoundingBox class for container dimension calculations
  • Add OverlayPositionDto class for API communication
  • Fix cursor changes (4-way arrow in edit mode)
  • Add user-select: none to prevent text selection during drag

SettingsController.cs (Backend):

  • Add ConcurrentDictionary to store overlay positions in memory
  • Add GET /api/settings/overlay-positions endpoint
    • Returns all saved overlay positions
  • Add POST /api/settings/overlay-positions endpoint
    • Saves or updates overlay position
    • Logs position changes for debugging
  • Add DELETE /api/settings/overlay-positions/{id} endpoint
    • Removes saved position for overlay
  • Add OverlayPosition class
    • Id: Guid of tank or control
    • Type: "Tank" or "Control"
    • X, Y: Position as percentage (0-100)

Drag Behavior:

  • Only works in edit mode (toggle lock/edit icon)
  • Smooth dragging with real-time position updates
  • Position constrained to 0-100% (stays within container)
  • Success notification when position saved
  • Positions persist across page reloads and app restarts
  • Each tank and control remembers its last saved position

Technical Implementation:

  • Mouse events preferred over HTML5 drag API for better Blazor WASM support
  • Positions stored as percentages for responsive layout
  • In-memory storage (can be persisted to database later)
  • Delta-based position calculation for smooth movement
  • Container dimensions calculated via JavaScript interop

Fixes:

  • Icons now drag smoothly when in edit mode
  • Cursor correctly shows 4-way arrow on hover in edit mode
  • Positions saved automatically on drag end
  • Saved positions loaded on page initialization
  • No more broken drag events

… overlays

Fixes drag functionality and adds position persistence for tank and control
overlays on the dashboard diagram.

Index.razor (Frontend):
- Replace broken HTML5 drag API with mouse event handlers
  - @onmousedown: Captures overlay and mouse position when drag starts
  - @OnMouseMove: Updates overlay position in real-time during drag
  - @onMouseUp: Saves position to backend when drag ends
- Add ElementReference for diagram container to calculate dimensions
- Add JSRuntime to get container dimensions for percentage calculations
- Add LoadOverlayPositions method to fetch saved positions from API
- Add SaveOverlayPosition method to persist positions to backend
- Update CreateOverlaysFromTanks/Controls to use saved positions
- Add savedPositions dictionary to cache positions locally
- Add BoundingBox class for container dimension calculations
- Add OverlayPositionDto class for API communication
- Fix cursor changes (4-way arrow in edit mode)
- Add user-select: none to prevent text selection during drag

SettingsController.cs (Backend):
- Add ConcurrentDictionary to store overlay positions in memory
- Add GET /api/settings/overlay-positions endpoint
  - Returns all saved overlay positions
- Add POST /api/settings/overlay-positions endpoint
  - Saves or updates overlay position
  - Logs position changes for debugging
- Add DELETE /api/settings/overlay-positions/{id} endpoint
  - Removes saved position for overlay
- Add OverlayPosition class
  - Id: Guid of tank or control
  - Type: "Tank" or "Control"
  - X, Y: Position as percentage (0-100)

Drag Behavior:
- Only works in edit mode (toggle lock/edit icon)
- Smooth dragging with real-time position updates
- Position constrained to 0-100% (stays within container)
- Success notification when position saved
- Positions persist across page reloads and app restarts
- Each tank and control remembers its last saved position

Technical Implementation:
- Mouse events preferred over HTML5 drag API for better Blazor WASM support
- Positions stored as percentages for responsive layout
- In-memory storage (can be persisted to database later)
- Delta-based position calculation for smooth movement
- Container dimensions calculated via JavaScript interop

Fixes:
- Icons now drag smoothly when in edit mode
- Cursor correctly shows 4-way arrow on hover in edit mode
- Positions saved automatically on drag end
- Saved positions loaded on page initialization
- No more broken drag events
@StuartF303 StuartF303 merged commit 7115e03 into main Nov 9, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants