Skip to content

Image assets (2/3): Angular client — ImageAssetService + Image widget - #1081

Closed
dillan wants to merge 2 commits into
mxtommy:masterfrom
dillan:feat/image-assets-client
Closed

Image assets (2/3): Angular client — ImageAssetService + Image widget#1081
dillan wants to merge 2 commits into
mxtommy:masterfrom
dillan:feat/image-assets-client

Conversation

@dillan

@dillan dillan commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Image assets (2/3) — Angular client: ImageAssetService + Image widget

Part 2 of 3 adding user-uploaded image assets to KIP dashboards. This PR adds the client service and the Image widget that displays a server-stored image, scaled to fit its container while preserving aspect ratio.

Depends on PR 1 (server, #1080) at runtime — the widget fetches bytes from the plugin's /plugins/kip/images endpoints. The code compiles and unit-tests on its own; it just won't display anything until the server side is present. The widget config UI (upload + gallery + settings cache card) is PR 3.

What it does

  • ImageAssetService (providedIn: 'root') — resolves the plugin base URL from the SK connection endpoint and exposes upload() (FormData + progress events), list(), delete(), cacheStats(), purgeCache(), and urlFor(id, cssWidth, dpr) which snaps the requested width to the server's allow-list so a small widget never downloads a full-resolution image. All calls are auto-authenticated by the existing JWT interceptor.
  • resolveKipPluginBaseUrl / snapImageWidth helper (core/utils/kip-plugin-url.util.ts) — small, unit-tested URL/width logic extracted so it's testable in isolation.
  • widget-image — zoneless/signals widget. Reads its config via WidgetRuntimeDirective, derives the image URL from ImageAssetService.urlFor(...) using a ResizeObserver to request the container-matched variant, and renders <img [style.object-fit]> (contain | cover) over a configurable solid or transparent background. Shows an empty state when no image is selected. No data streams (static widget).
  • Registered in widget.service.ts as an Image widget (Component category) so it appears in Add Widgets.

Display behavior

Scales to fit (contain) or fill (cover) preserving aspect ratio; background defaults to transparent (the dashboard shows through the letterbox area), or a user-chosen color (set in PR 3's config UI).

Tests

image-asset.service.spec.ts (URL/variant resolution, FormData upload, cache calls), kip-plugin-url.util.spec.ts (base-URL + width snapping), widget-image.component.spec.ts (empty state, URL derivation, object-fit, transparent default). Vitest/zoneless.

Status / gates

  • App build (npm run build:dev) clean; ng lint clean; the 3 image specs (12 tests) pass.

Stacking / dependency


📚 3-PR stack (review/merge in order)

  1. Image assets (1/3): Signal K plugin — secure upload, processing, worker pool, cache #1080 — Signal K plugin: secure upload, processing, worker pool, cache (server)
  2. Image assets (2/3): Angular client — ImageAssetService + Image widget #1081 — Angular client: ImageAssetService + Image widget
  3. Image assets (3/3): widget config UI + settings image-cache card #1082 — Widget config UI + settings image-cache card

PR 2 needs PR 1 at runtime; PR 3 is stacked on PR 2. Together they add the full image-assets feature.

You are viewing PR 2 of 3.

resolveKipPluginBaseUrl() extracts the <server>/plugins/kip/ resolution (mirroring
kip-series-api-client) and snapImageWidth() snaps a container width (x DPR) to the
server's variant allow-list so the client requests stable, cache-friendly URLs.

ImageAssetService wraps the plugin endpoints: upload (multipart FormData with progress),
list, delete, cacheStats, purgeCache, and urlFor(id, cssWidth, dpr) for the widget.
Requests are auto-authenticated by the JWT interceptor. 9 vitest cases green.
New widget-image renders a selected image (by id) via ImageAssetService, scaled to fit the
widget with object-fit (contain/cover) over a configurable background that defaults to
transparent so the dashboard shows through. It tracks its container width with the existing
kipResizeObserver directive and requests a server variant matched to that width (x DPR) so a
small widget never downloads a full-resolution image. Shows an empty state when nothing is
selected. Registered in WidgetService (component map + Component-category definition); adds the
`image` config block to IWidgetSvcConfig. 3 vitest cases (empty state, render+object-fit,
background default/override).
@dillan

dillan commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1120, which re-points the client at the standalone sk-image plugin and consolidates the widget + config UI into a single PR. Closing.

@dillan dillan closed this Jul 6, 2026
@dillan
dillan deleted the feat/image-assets-client branch July 6, 2026 19:42
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.

1 participant