mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 11:42:21 +00:00
Merge main into byrdit/recent-imagery-dateline
This commit is contained in:
commit
46f8ea16c0
105 files changed
+6960
-1269
No files matched your search
@@ -908,9 +908,6 @@ export class StyleManager extends ShellFacade {
|
||||
this._panelChrome.setPanelCollapsed(panelId, collapsed, options),
|
||||
readPanel: (panel) => this._panelChrome._shownPanel(panel),
|
||||
onSheetsClosed: () => this._syncShareState(),
|
||||
onTabOpened: (sheet) => {
|
||||
void this._onMobileTabOpened(sheet);
|
||||
},
|
||||
publish: (view) =>
|
||||
useDisplayStore(applicationPinia()).publishPhoneShell(view),
|
||||
afterPublish: (callback) => {
|
||||
@@ -919,32 +916,6 @@ export class StyleManager extends ShellFacade {
|
||||
});
|
||||
}
|
||||
|
||||
/** Reveal a tracked aircraft through Contacts when its phone tab is opened. */
|
||||
async _onMobileTabOpened(sheet) {
|
||||
const context = this.getContextModeState();
|
||||
if (
|
||||
sheet !== 'context' ||
|
||||
this._disposed ||
|
||||
!context ||
|
||||
context.mode ||
|
||||
context.changing ||
|
||||
context.entering ||
|
||||
!this.getAircraftTrackingTarget()
|
||||
)
|
||||
return false;
|
||||
try {
|
||||
const result = await this.setContextMode('contacts');
|
||||
if (result?.ok) return true;
|
||||
if (result?.cancelled || this._disposed) return false;
|
||||
} catch {
|
||||
if (this._disposed) return false;
|
||||
}
|
||||
this._showToast(
|
||||
t('Contacts could not complete the requested transition; try again'),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the owner-approved map stack chip row from the matching controller
|
||||
* entries. Cesium ion/Bing chips remain keyboard-focusable but unavailable,
|
||||
|
||||
+16
-1
@@ -1,3 +1,5 @@
|
||||
import { watch } from 'vue';
|
||||
import { MOBILE_SHEET_ATTR } from './mobileSheets.js';
|
||||
import {
|
||||
EMPTY_CCTV_FRAME,
|
||||
_clearCctvFrame,
|
||||
@@ -73,7 +75,10 @@ export class CctvControls {
|
||||
if (state) this._renderCctvState(state);
|
||||
if (this._cctvChip) this._publishCctvChip({});
|
||||
});
|
||||
if (this._cctvVideo && typeof MutationObserver !== 'undefined') {
|
||||
if (
|
||||
(this._cctvVideo || this._cctvFrame) &&
|
||||
typeof MutationObserver !== 'undefined'
|
||||
) {
|
||||
this._videoVisibilityObserver = new MutationObserver(() =>
|
||||
this._renderCctvState(this._cctvState),
|
||||
);
|
||||
@@ -82,6 +87,15 @@ export class CctvControls {
|
||||
attributes: true,
|
||||
attributeFilter: ['class', 'hidden'],
|
||||
});
|
||||
// On phones the panel is on screen only while the Cameras sheet is open.
|
||||
this._videoVisibilityObserver.observe(document.body, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class', MOBILE_SHEET_ATTR],
|
||||
});
|
||||
this._offPreviewCards = watch(
|
||||
() => this.store.previewCards,
|
||||
() => this._renderCctvState(this._cctvState),
|
||||
);
|
||||
this.listen(document, 'visibilitychange', () =>
|
||||
this._renderCctvState(this._cctvState),
|
||||
);
|
||||
@@ -154,6 +168,7 @@ export class CctvControls {
|
||||
this._quebecCctvOverlay?.dispose();
|
||||
this._cctvVideoSurface?.stop();
|
||||
this._videoVisibilityObserver?.disconnect();
|
||||
this._offPreviewCards?.();
|
||||
this._actionGeneration++;
|
||||
this.listeners.abort();
|
||||
this._cctvUnsubscribe?.();
|
||||
|
||||
@@ -186,6 +186,14 @@ export function _settleCctvFrame(token, src, ok) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Shared live health describes the stream even when this viewer shows a frame. */
|
||||
export function isCctvLiveFrameFallback(activeCamera) {
|
||||
return (
|
||||
activeCamera?.isVideo === false &&
|
||||
String(activeCamera.sourceKind || '').toLowerCase() === 'live'
|
||||
);
|
||||
}
|
||||
|
||||
/** The source badge's label and frame state for the camera and preview. */
|
||||
export function presentCctvSourceBadge(activeCamera, enabled, frame) {
|
||||
if (!enabled || !activeCamera)
|
||||
@@ -194,6 +202,11 @@ export function presentCctvSourceBadge(activeCamera, enabled, frame) {
|
||||
return { label: t('FRAME · LOADING'), state: 'loading' };
|
||||
if (frame.error && !frame.hasFrame)
|
||||
return { label: t('FRAME · UNAVAILABLE'), state: 'error' };
|
||||
if (isCctvLiveFrameFallback(activeCamera))
|
||||
return {
|
||||
label: `${cctvSourceKindLabel('fallback')} · ${cctvSourceStatusLabel('degraded')}`,
|
||||
state: 'ready',
|
||||
};
|
||||
const kind = cctvSourceKindLabel(
|
||||
activeCamera.sourceKind || activeCamera.feedType || 'unknown',
|
||||
);
|
||||
|
||||
+152
-11
@@ -20,7 +20,7 @@ const BUTTONS = {
|
||||
_cctvProjectionBtn: 'cctv-projection-btn',
|
||||
};
|
||||
|
||||
function panel(t) {
|
||||
function panel(t, { video = false } = {}) {
|
||||
document.body.replaceChildren();
|
||||
const host = document.body.appendChild(document.createElement('div'));
|
||||
const pinia = createPinia();
|
||||
@@ -32,6 +32,7 @@ function panel(t) {
|
||||
document.getElementById(id),
|
||||
]),
|
||||
);
|
||||
if (video) elements._cctvVideo = document.getElementById('cctv-video');
|
||||
const controls = new CctvControls({
|
||||
elements: {
|
||||
...elements,
|
||||
@@ -377,17 +378,10 @@ test('a second edit of the same chip gets a fresh input', async (t) => {
|
||||
});
|
||||
|
||||
test('the frame preview renders each step of a camera frame request', async (t) => {
|
||||
const prior = globalThis.Image;
|
||||
const requests = [];
|
||||
globalThis.Image = class {
|
||||
constructor() {
|
||||
requests.push(this);
|
||||
}
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.Image = prior;
|
||||
});
|
||||
const requests = mockImages(t);
|
||||
const { controls, byId } = panel(t);
|
||||
// The preview loads while the panel is open; the panel starts collapsed.
|
||||
byId('cctv-panel').classList.remove('collapsed');
|
||||
const frame = byId('cctv-frame');
|
||||
const wrap = byId('cctv-frame-wrap');
|
||||
const badge = byId('cctv-source-badge');
|
||||
@@ -606,3 +600,150 @@ test('the meta line of a disabled layer does not describe its last camera', () =
|
||||
);
|
||||
assert.match(presentCctvPanel(activeState, true).meta, /^Austin · HDG /);
|
||||
});
|
||||
|
||||
const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
|
||||
function mockImages(t) {
|
||||
const prior = globalThis.Image;
|
||||
const requests = [];
|
||||
globalThis.Image = class {
|
||||
constructor() {
|
||||
requests.push(this);
|
||||
}
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.Image = prior;
|
||||
});
|
||||
return requests;
|
||||
}
|
||||
|
||||
const stillState = (frameUrl, id = 'a') => ({
|
||||
enabled: true,
|
||||
count: 2,
|
||||
cameraIndex: [camera, { ...camera, id: 'b' }],
|
||||
activeCameraId: id,
|
||||
activeCamera: { ...camera, id, frameUrl, sourceKind: 'snapshot' },
|
||||
});
|
||||
|
||||
test('the still preview is fetched only while the tab and the panel are shown', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const hidden = Object.getOwnPropertyDescriptor(document, 'hidden');
|
||||
let tabHidden = false;
|
||||
Object.defineProperty(document, 'hidden', {
|
||||
configurable: true,
|
||||
get: () => tabHidden,
|
||||
});
|
||||
t.after(() => {
|
||||
if (hidden) Object.defineProperty(document, 'hidden', hidden);
|
||||
else delete document.hidden;
|
||||
});
|
||||
const { controls, byId } = panel(t);
|
||||
assert.equal(controls._cctvVideo, undefined);
|
||||
const panelElement = byId('cctv-panel');
|
||||
const state = stillState;
|
||||
|
||||
// Collapsed panel: nothing is requested, however often the state arrives.
|
||||
assert.equal(panelElement.classList.contains('collapsed'), true);
|
||||
controls._renderCctvState(state('a1.jpg'));
|
||||
controls._renderCctvState(state('a2.jpg'));
|
||||
assert.equal(requests.length, 0, 'collapsed panel');
|
||||
|
||||
// Opening it resumes through the class observer, with no manual render.
|
||||
panelElement.classList.remove('collapsed');
|
||||
await settle();
|
||||
assert.equal(requests.length, 1, 'expanded panel');
|
||||
assert.equal(requests[0].src, 'a2.jpg');
|
||||
requests[0].onload();
|
||||
|
||||
// A background tab: refreshed URLs are not requested.
|
||||
tabHidden = true;
|
||||
document.dispatchEvent(new Event('visibilitychange'));
|
||||
controls._renderCctvState(state('a3.jpg'));
|
||||
assert.equal(requests.length, 1, 'hidden tab');
|
||||
|
||||
// Back in the tab: visibilitychange alone fetches the current URL.
|
||||
tabHidden = false;
|
||||
document.dispatchEvent(new Event('visibilitychange'));
|
||||
assert.equal(requests.length, 2, 'visible tab');
|
||||
assert.equal(requests[1].src, 'a3.jpg');
|
||||
});
|
||||
|
||||
test('the still preview waits for the Cameras sheet on phones', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
t.after(() => {
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
});
|
||||
const { controls, byId } = panel(t);
|
||||
byId('cctv-panel').classList.remove('collapsed');
|
||||
document.body.classList.add('mobile-shell');
|
||||
document.body.setAttribute('data-mobile-sheet', 'layers');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 0, 'another sheet is open');
|
||||
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 0, 'no sheet is open');
|
||||
|
||||
document.body.setAttribute('data-mobile-sheet', 'cameras');
|
||||
await settle();
|
||||
assert.equal(requests.length, 1, 'Cameras sheet opened');
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
|
||||
// Off a phone the sheet attribute means nothing.
|
||||
requests[0].onload();
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.setAttribute('data-mobile-sheet', 'layers');
|
||||
controls._renderCctvState(stillState('a2.jpg'));
|
||||
assert.equal(requests.length, 2, 'desktop ignores the sheet');
|
||||
});
|
||||
|
||||
test('a camera picked while the panel is collapsed shows its own still on expanding', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, byId } = panel(t);
|
||||
const panelElement = byId('cctv-panel');
|
||||
panelElement.classList.remove('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 1);
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
panelElement.classList.add('collapsed');
|
||||
await settle();
|
||||
controls._renderCctvState(stillState('b1.jpg', 'b'));
|
||||
assert.equal(requests.length, 1);
|
||||
requests[0].onload();
|
||||
panelElement.classList.remove('collapsed');
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(requests.length, 2);
|
||||
assert.equal(requests[1].src, 'b1.jpg');
|
||||
assert.equal(byId('cctv-frame').dataset.cameraId, 'b');
|
||||
assert.notEqual(byId('cctv-frame').getAttribute('src'), 'a1.jpg');
|
||||
});
|
||||
|
||||
test('leaving the Cameras sheet stops the live video and coming back starts it again', async (t) => {
|
||||
const { controls, byId } = panel(t, { video: true });
|
||||
byId('cctv-panel').classList.remove('collapsed');
|
||||
document.body.classList.add('mobile-shell');
|
||||
document.body.setAttribute('data-mobile-sheet', 'cameras');
|
||||
t.after(() => {
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
});
|
||||
controls._renderCctvState({
|
||||
enabled: true,
|
||||
count: 1,
|
||||
cameraIndex: [camera],
|
||||
activeCameraId: 'a',
|
||||
activeCamera: { ...camera, isVideo: true },
|
||||
});
|
||||
const first = controls._cctvVideoSurface;
|
||||
assert.ok(first);
|
||||
const stop = t.mock.method(first, 'stop');
|
||||
document.body.setAttribute('data-mobile-sheet', 'layers');
|
||||
await settle();
|
||||
assert.equal(stop.mock.callCount(), 1);
|
||||
assert.equal(controls._cctvVideoSurface, null);
|
||||
document.body.setAttribute('data-mobile-sheet', 'cameras');
|
||||
await settle();
|
||||
assert.ok(controls._cctvVideoSurface);
|
||||
assert.notEqual(controls._cctvVideoSurface, first);
|
||||
});
|
||||
@@ -1,9 +1,22 @@
|
||||
import { getLocale, keepCodesWithValues, msg, t, tn } from '../i18n/index.js';
|
||||
import { cctvSourceLabelText, cctvSourceMessageText } from './cctvFrames.js';
|
||||
import {
|
||||
cctvSourceLabelText,
|
||||
cctvSourceMessageText,
|
||||
isCctvLiveFrameFallback,
|
||||
} from './cctvFrames.js';
|
||||
|
||||
import { createCctvVideoSurface } from './cctvVideo.js';
|
||||
import { presentCctvCalibration } from './cctvCalibration.js';
|
||||
import { roundHeadingDegrees } from '../data/headingDegrees.js';
|
||||
import {
|
||||
MOBILE_SHELL_CLASS,
|
||||
MOBILE_SHEET_ATTR,
|
||||
sheetForPanelId,
|
||||
} from './mobileSheets.js';
|
||||
|
||||
const CAMERAS_SHEET = sheetForPanelId('cctv-panel');
|
||||
const CONTEXT_SHEET = sheetForPanelId('global-context-panel');
|
||||
|
||||
export function _calBadgeLabel(badge) {
|
||||
switch (badge) {
|
||||
case 'calibrated':
|
||||
@@ -96,9 +109,10 @@ function metaText(state, enabled, activeCamera, catalogCount) {
|
||||
const provider = cctvSourceLabelText(
|
||||
activeCamera.sourceLabel || activeCamera.provider || 'Configured Source',
|
||||
);
|
||||
const statusMsg = activeCamera.sourceMessage
|
||||
? ` · ${cctvSourceMessageText(activeCamera.sourceMessage)}`
|
||||
: '';
|
||||
const statusMsg =
|
||||
activeCamera.sourceMessage && !isCctvLiveFrameFallback(activeCamera)
|
||||
? ` · ${cctvSourceMessageText(activeCamera.sourceMessage)}`
|
||||
: '';
|
||||
// A partner-supplied feed inside a pack names its owner here.
|
||||
const credit = activeCamera.credit ? ` · ${activeCamera.credit}` : '';
|
||||
const calBadge = activeCamera.calBadge
|
||||
@@ -274,11 +288,25 @@ export function _renderCctvState(state) {
|
||||
const liveIntent =
|
||||
enabled && !!activeCamera?.isVideo && !activeCamera?.browserMediaUrl;
|
||||
this.store.setLive(liveIntent);
|
||||
// A background tab, a collapsed panel or a closed phone sheet shows no
|
||||
// picture; the observers and visibilitychange render again on showing.
|
||||
const body = globalThis.document?.body;
|
||||
const phone = body?.classList.contains(MOBILE_SHELL_CLASS);
|
||||
const sheet = body?.getAttribute(MOBILE_SHEET_ATTR);
|
||||
const tabShown = !!body && !document.hidden;
|
||||
const panelShown =
|
||||
tabShown &&
|
||||
!this._cctvPanel?.classList.contains('collapsed') &&
|
||||
(!phone || sheet === CAMERAS_SHEET);
|
||||
// Context's camera card shows the same still.
|
||||
const cardShown =
|
||||
tabShown &&
|
||||
this.store.previewCards > 0 &&
|
||||
(!phone || sheet === CONTEXT_SHEET);
|
||||
// Its bigger view is a popup over the map, shown on any phone sheet.
|
||||
const popupShown = tabShown && this.store.previewPopups > 0;
|
||||
if (this._cctvVideo) {
|
||||
const visible =
|
||||
liveIntent &&
|
||||
!document.hidden &&
|
||||
!this._cctvPanel?.classList.contains('collapsed');
|
||||
const visible = liveIntent && panelShown;
|
||||
if (!visible || this._cctvVideoCameraId !== activeId) {
|
||||
this._cctvVideoSurface?.stop();
|
||||
this._cctvVideoSurface = null;
|
||||
@@ -303,6 +331,7 @@ export function _renderCctvState(state) {
|
||||
// immediate so navigation never waits on the prior camera's request.
|
||||
if (
|
||||
nextSrc &&
|
||||
(panelShown || cardShown || popupShown) &&
|
||||
(cameraChanged || (!frameLoading && this._frame.currentSrc !== nextSrc))
|
||||
) {
|
||||
this._queueCctvFrame(nextSrc, nextCameraId, cameraChanged);
|
||||
|
||||
@@ -9,7 +9,13 @@ import {
|
||||
subjectEntryAllowed,
|
||||
} from '../contextModePolicy.js';
|
||||
import { cockpitSubjectProviders } from '../cockpitSubjectProviders.js';
|
||||
import { formatAwarenessLabel } from '../data/militaryAwarenessEngine.js';
|
||||
import {
|
||||
AWARENESS_MAX_FLIGHT_SEARCH_RADIUS_M,
|
||||
aircraftClassMatches,
|
||||
formatAwarenessLabel,
|
||||
} from '../data/militaryAwarenessEngine.js';
|
||||
import { fromDegreesInto } from '../geo/ellipsoid.js';
|
||||
import { findCamera } from '../render/rendererOf.js';
|
||||
import { enterCockpitWithTracking } from '../cockpitTracking.js';
|
||||
import { cockpitVisionModeForStyle } from '../cockpitVisionPolicy.js';
|
||||
import { readEntityRecord } from '../data/entityRecords.js';
|
||||
@@ -352,13 +358,41 @@ export class CockpitCoordinator {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a requested-layer entry searches from: the aircraft the camera
|
||||
* follows, else the ground under the camera.
|
||||
* @param {{layerId: string}|null} currentTarget The tracked aircraft.
|
||||
* @returns {{x: number, y: number, z: number}|null}
|
||||
*/
|
||||
_cockpitEntrySearchOrigin(currentTarget) {
|
||||
const { flightsLayer, militaryFlightsLayer } = this.services;
|
||||
const layer =
|
||||
currentTarget?.layerId === 'military'
|
||||
? militaryFlightsLayer
|
||||
: currentTarget?.layerId === 'flights'
|
||||
? flightsLayer
|
||||
: null;
|
||||
const subject = layer?.getTrackedSubject?.();
|
||||
if (subject?.position) return subject.position;
|
||||
const pose = findCamera(this.viewer)?.pose?.();
|
||||
if (!Number.isFinite(pose?.lat) || !Number.isFinite(pose?.lon)) return null;
|
||||
return fromDegreesInto(pose.lon, pose.lat, 0, { x: 0, y: 0, z: 0 });
|
||||
}
|
||||
|
||||
/**
|
||||
* Retarget a voice entry to the requested layer and class before entering.
|
||||
* It searches the aircraft that layer shows, under the person's own
|
||||
* filters, nearest first, from the followed aircraft or the camera, and
|
||||
* follows the nearest match; the aircraft already followed counts when it
|
||||
* matches. It needs nothing from Contacts.
|
||||
*/
|
||||
_retargetCockpitEntryLayer({
|
||||
targetLayer,
|
||||
aircraftClass,
|
||||
currentTarget,
|
||||
selectedTarget,
|
||||
}) {
|
||||
const { militaryAwarenessLayer } = this.services;
|
||||
const { flightsLayer, militaryFlightsLayer } = this.services;
|
||||
if (!['flights', 'military'].includes(targetLayer)) {
|
||||
return {
|
||||
ok: false,
|
||||
@@ -370,12 +404,27 @@ export class CockpitCoordinator {
|
||||
const alreadyOnLayer = activeLayer === targetLayer;
|
||||
if (alreadyOnLayer && !aircraftClass)
|
||||
return { ok: true, retargeted: false };
|
||||
const moved = militaryAwarenessLayer?.navigateNext
|
||||
? !!militaryAwarenessLayer.navigateNext({
|
||||
targetLayer,
|
||||
aircraftClass,
|
||||
origin: 'voice',
|
||||
})
|
||||
const layer =
|
||||
targetLayer === 'military' ? militaryFlightsLayer : flightsLayer;
|
||||
const origin = this._cockpitEntrySearchOrigin(currentTarget);
|
||||
const nearby =
|
||||
origin && typeof layer?.getNearby === 'function'
|
||||
? layer.getNearby(
|
||||
origin,
|
||||
AWARENESS_MAX_FLIGHT_SEARCH_RADIUS_M,
|
||||
targetLayer === 'military' ? 5000 : 25000,
|
||||
)
|
||||
: [];
|
||||
const match = nearby.find(
|
||||
(item) => item?.icao24 && aircraftClassMatches(item, aircraftClass),
|
||||
);
|
||||
const followed =
|
||||
match &&
|
||||
currentTarget?.layerId === targetLayer &&
|
||||
String(currentTarget.id) === String(match.icao24);
|
||||
if (followed) return { ok: true, retargeted: false };
|
||||
const moved = match
|
||||
? !!layer.trackById?.(match.icao24, { origin: 'voice' })
|
||||
: false;
|
||||
if (moved) return { ok: true, retargeted: true };
|
||||
// A filter that matched nothing still enters, as long as the layer is
|
||||
|
||||
@@ -869,3 +869,79 @@ test('a malformed provider is left out and the built-in kinds are unchanged', as
|
||||
assert.equal(cockpit.enter(), true);
|
||||
assert.equal(cockpit.subjectKind, 'aircraft');
|
||||
});
|
||||
|
||||
// A requested-layer entry finds its aircraft in that layer, from the
|
||||
// aircraft the camera follows; it never asks Contacts.
|
||||
function retargetFixture(t, nearby) {
|
||||
const { coordinator } = fixture(t, {
|
||||
enabled: ['flights', 'military'],
|
||||
tracked: { layerId: 'flights', info: CIVIL },
|
||||
});
|
||||
const tracked = [];
|
||||
const searches = [];
|
||||
coordinator.services.militaryAwarenessLayer.navigateNext = () =>
|
||||
assert.fail('entry must not navigate through Contacts');
|
||||
coordinator.services.flightsLayer.getTrackedSubject = () => ({
|
||||
layerId: 'flights',
|
||||
id: CIVIL.icao24,
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
});
|
||||
coordinator.services.militaryFlightsLayer.getNearby = (...args) => {
|
||||
searches.push(args);
|
||||
return nearby;
|
||||
};
|
||||
coordinator.services.militaryFlightsLayer.trackById = (id, options) => {
|
||||
tracked.push([id, options.origin]);
|
||||
return true;
|
||||
};
|
||||
return { coordinator, tracked, searches };
|
||||
}
|
||||
|
||||
test('a voice entry asking for a military class follows the nearest match without Contacts', (t) => {
|
||||
const { coordinator, tracked, searches } = retargetFixture(t, [
|
||||
{ icao24: 'jet1', aircraftClass: 'fighter', distance: 10 },
|
||||
{ icao24: 'helo1', aircraftClass: 'helicopter', distance: 20 },
|
||||
{ icao24: 'helo2', aircraftClass: 'helicopter', distance: 30 },
|
||||
]);
|
||||
const result = coordinator._retargetCockpitEntryLayer({
|
||||
targetLayer: 'military',
|
||||
aircraftClass: 'helicopter',
|
||||
currentTarget: { layerId: 'flights', id: CIVIL.icao24 },
|
||||
selectedTarget: null,
|
||||
});
|
||||
assert.deepEqual(result, { ok: true, retargeted: true });
|
||||
assert.deepEqual(tracked, [['helo1', 'voice']]);
|
||||
// Searched from the followed aircraft, among the aircraft the person's
|
||||
// filters show: never the hidden ones.
|
||||
assert.deepEqual(searches[0][0], { x: 1, y: 2, z: 3 });
|
||||
assert.equal(searches[0][3], undefined);
|
||||
});
|
||||
|
||||
test('a voice entry whose followed aircraft already matches stays on it', (t) => {
|
||||
const { coordinator, tracked } = retargetFixture(t, [
|
||||
{ icao24: 'helo1', aircraftClass: 'helicopter', distance: 0 },
|
||||
]);
|
||||
const result = coordinator._retargetCockpitEntryLayer({
|
||||
targetLayer: 'military',
|
||||
aircraftClass: 'helicopter',
|
||||
currentTarget: { layerId: 'military', id: 'helo1' },
|
||||
selectedTarget: null,
|
||||
});
|
||||
assert.deepEqual(result, { ok: true, retargeted: false });
|
||||
assert.deepEqual(tracked, []);
|
||||
});
|
||||
|
||||
test('a voice entry with no matching aircraft says so and follows nothing', (t) => {
|
||||
const { coordinator, tracked } = retargetFixture(t, [
|
||||
{ icao24: 'jet1', aircraftClass: 'fighter', distance: 10 },
|
||||
]);
|
||||
const result = coordinator._retargetCockpitEntryLayer({
|
||||
targetLayer: 'military',
|
||||
aircraftClass: 'helicopter',
|
||||
currentTarget: { layerId: 'flights', id: CIVIL.icao24 },
|
||||
selectedTarget: null,
|
||||
});
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.error, /No helicopter military contact is available/);
|
||||
assert.deepEqual(tracked, []);
|
||||
});
|
||||
@@ -0,0 +1,281 @@
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createPinia } from 'pinia';
|
||||
import { createApp, nextTick } from 'vue';
|
||||
import { CctvControls } from './cctvControls.js';
|
||||
import { useCctvStore } from './stores/cctv.js';
|
||||
import CctvPanel from './views/panels/CctvPanel.vue';
|
||||
import CctvPreview from './views/panels/CctvPreview.vue';
|
||||
|
||||
const settle = () => new Promise((r) => setTimeout(r, 0));
|
||||
const camera = {
|
||||
id: 'a',
|
||||
city: 'Austin',
|
||||
name: 'Congress Ave',
|
||||
headingDeg: 91.6,
|
||||
fovDeg: 60,
|
||||
rangeM: 120.4,
|
||||
sourceLabel: 'Configured Source',
|
||||
calBadge: 'curated',
|
||||
};
|
||||
const stillState = (frameUrl, id = 'a') => ({
|
||||
enabled: true,
|
||||
count: 2,
|
||||
cameraIndex: [camera, { ...camera, id: 'b' }],
|
||||
activeCameraId: id,
|
||||
activeCamera: { ...camera, id, frameUrl, sourceKind: 'snapshot' },
|
||||
});
|
||||
|
||||
function fixture(t, { card = true } = {}) {
|
||||
document.body.replaceChildren();
|
||||
const host = document.body.appendChild(document.createElement('div'));
|
||||
const cardHost = document.body.appendChild(document.createElement('div'));
|
||||
const pinia = createPinia();
|
||||
const app = createApp(CctvPanel).use(pinia);
|
||||
app.mount(host);
|
||||
let preview;
|
||||
function mountCard() {
|
||||
preview = createApp(CctvPreview, { cameraId: 'a' }).use(pinia);
|
||||
preview.mount(cardHost);
|
||||
}
|
||||
function unmountCard() {
|
||||
preview?.unmount();
|
||||
preview = null;
|
||||
}
|
||||
if (card) mountCard();
|
||||
const store = useCctvStore(pinia);
|
||||
const controls = new CctvControls({
|
||||
elements: {
|
||||
_cctvPanel: document.getElementById('cctv-panel'),
|
||||
_cctvFrame: document.getElementById('cctv-frame'),
|
||||
_cctvFrameWrap: document.getElementById('cctv-frame-wrap'),
|
||||
},
|
||||
cctv: {},
|
||||
actions: {
|
||||
isEnabled: () => true,
|
||||
setPanelCollapsed() {},
|
||||
syncViewport() {},
|
||||
},
|
||||
store,
|
||||
});
|
||||
t.after(() => {
|
||||
controls.destroy();
|
||||
app.unmount();
|
||||
preview?.unmount();
|
||||
});
|
||||
return {
|
||||
controls,
|
||||
cardHost,
|
||||
mountCard,
|
||||
unmountCard,
|
||||
store,
|
||||
panelEl: document.getElementById('cctv-panel'),
|
||||
};
|
||||
}
|
||||
|
||||
function mockImages(t) {
|
||||
const prior = globalThis.Image;
|
||||
const requests = [];
|
||||
globalThis.Image = class {
|
||||
constructor() {
|
||||
requests.push(this);
|
||||
}
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.Image = prior;
|
||||
});
|
||||
return requests;
|
||||
}
|
||||
|
||||
test('desktop: the Context card keeps refreshing while the accordion folds CCTV', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, cardHost, panelEl } = fixture(t);
|
||||
panelEl.classList.remove('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 1);
|
||||
requests[0].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(cardHost.querySelector('img')?.getAttribute('src'), 'a1.jpg');
|
||||
// Context opens: the desktop accordion folds CCTV (class collapsed).
|
||||
panelEl.classList.add('collapsed');
|
||||
await settle();
|
||||
controls._renderCctvState(stillState('a2.jpg'));
|
||||
assert.equal(requests.length, 2);
|
||||
assert.equal(requests[1].src, 'a2.jpg');
|
||||
requests[1].onload();
|
||||
controls._renderCctvState(stillState('a3.jpg'));
|
||||
assert.equal(requests.length, 3);
|
||||
assert.equal(requests[2].src, 'a3.jpg');
|
||||
requests[2].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(cardHost.querySelector('img')?.getAttribute('src'), 'a3.jpg');
|
||||
});
|
||||
|
||||
test('phone: a camera picked with the Context sheet open gets its still', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
t.after(() => {
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
});
|
||||
const { controls, cardHost, panelEl } = fixture(t);
|
||||
document.body.classList.add('mobile-shell');
|
||||
document.body.setAttribute('data-mobile-sheet', 'context');
|
||||
panelEl.classList.remove('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
controls._renderCctvState(stillState('a2.jpg'));
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(
|
||||
requests.length,
|
||||
1,
|
||||
'the Context card on the Context sheet requests the still',
|
||||
);
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
requests.at(-1).onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.ok(
|
||||
cardHost.querySelector('.cctv-preview__expand'),
|
||||
'the card shows a frame, not Acquiring frame…',
|
||||
);
|
||||
});
|
||||
|
||||
test('phone: the card on a closed Context sheet waits', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, panelEl } = fixture(t);
|
||||
panelEl.classList.add('collapsed');
|
||||
document.body.classList.add('mobile-shell');
|
||||
document.body.setAttribute('data-mobile-sheet', 'layers');
|
||||
t.after(() => {
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
});
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 0);
|
||||
document.body.setAttribute('data-mobile-sheet', 'context');
|
||||
await settle();
|
||||
assert.equal(requests.length, 1);
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
});
|
||||
|
||||
test('phone: the bigger view keeps refreshing after the layout turns phone, and stops once closed', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
t.after(() => {
|
||||
document.body.classList.remove('mobile-shell');
|
||||
document.body.removeAttribute('data-mobile-sheet');
|
||||
});
|
||||
const { controls, cardHost, panelEl } = fixture(t);
|
||||
panelEl.classList.add('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 1);
|
||||
requests[0].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
cardHost.querySelector('.cctv-preview__expand').click();
|
||||
await settle();
|
||||
await nextTick();
|
||||
const popup = document.body.querySelector('.cctv-popup');
|
||||
assert.ok(popup);
|
||||
assert.equal(popup.querySelector('img').getAttribute('src'), 'a1.jpg');
|
||||
|
||||
document.body.classList.add('mobile-shell');
|
||||
await settle();
|
||||
controls._renderCctvState(stillState('a2.jpg'));
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.ok(document.body.contains(popup));
|
||||
assert.equal(requests.length, 2);
|
||||
assert.equal(requests[1].src, 'a2.jpg');
|
||||
requests[1].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(popup.querySelector('img').getAttribute('src'), 'a2.jpg');
|
||||
|
||||
popup.querySelector('.cctv-popup__close').click();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(document.body.querySelector('.cctv-popup'), null);
|
||||
controls._renderCctvState(stillState('a3.jpg'));
|
||||
await settle();
|
||||
assert.equal(requests.length, 2);
|
||||
});
|
||||
|
||||
test('desktop: a card that mounts asks for the still', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, panelEl, mountCard } = fixture(t, { card: false });
|
||||
panelEl.classList.add('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
await settle();
|
||||
assert.equal(requests.length, 0);
|
||||
mountCard();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(requests.length, 1);
|
||||
assert.equal(requests[0].src, 'a1.jpg');
|
||||
});
|
||||
|
||||
test('desktop: a card that unmounts stops the still, and a remount resumes it', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, panelEl, mountCard, unmountCard, store } = fixture(t);
|
||||
panelEl.classList.add('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
assert.equal(requests.length, 1);
|
||||
requests[0].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
|
||||
unmountCard();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(store.previewCards, 0);
|
||||
controls._renderCctvState(stillState('a2.jpg'));
|
||||
await settle();
|
||||
assert.equal(requests.length, 1);
|
||||
|
||||
mountCard();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(requests.length, 2);
|
||||
assert.equal(requests[1].src, 'a2.jpg');
|
||||
});
|
||||
|
||||
test('desktop: the bigger view is released when the card unmounts, also in the tick it closes', async (t) => {
|
||||
const requests = mockImages(t);
|
||||
const { controls, cardHost, panelEl, mountCard, unmountCard, store } =
|
||||
fixture(t);
|
||||
panelEl.classList.add('collapsed');
|
||||
controls._renderCctvState(stillState('a1.jpg'));
|
||||
requests[0].onload();
|
||||
await settle();
|
||||
await nextTick();
|
||||
const openPopup = async () => {
|
||||
cardHost.querySelector('.cctv-preview__expand').click();
|
||||
await nextTick();
|
||||
assert.equal(store.previewPopups, 1);
|
||||
};
|
||||
|
||||
await openPopup();
|
||||
unmountCard();
|
||||
await nextTick();
|
||||
assert.equal(document.body.querySelector('.cctv-popup'), null);
|
||||
assert.equal(store.previewPopups, 0);
|
||||
|
||||
mountCard();
|
||||
await nextTick();
|
||||
await openPopup();
|
||||
// Closed and unmounted before the watcher runs, as when one Escape closes
|
||||
// the phone's Context sheet and the popup.
|
||||
document.body.querySelector('.cctv-popup__close').click();
|
||||
unmountCard();
|
||||
await settle();
|
||||
await nextTick();
|
||||
assert.equal(store.previewPopups, 0);
|
||||
assert.equal(store.previewCards, 0);
|
||||
const before = requests.length;
|
||||
controls._renderCctvState(stillState('a3.jpg'));
|
||||
await settle();
|
||||
assert.equal(requests.length, before);
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
export const MOBILE_SHELL_CLASS = 'mobile-shell';
|
||||
export const MOBILE_SHEET_ATTR = 'data-mobile-sheet';
|
||||
|
||||
/**
|
||||
* Panels each sheet expands. A sheet also shows its rail's other panels
|
||||
* collapsed (Scenes under Layers), per styles/mobile-shell.css.
|
||||
*/
|
||||
export const MOBILE_SHEET_PANELS = Object.freeze({
|
||||
layers: Object.freeze(['data-panel']),
|
||||
cameras: Object.freeze(['cctv-panel', 'street-level-panel']),
|
||||
context: Object.freeze(['global-context-panel']),
|
||||
missions: Object.freeze(['space-missions-panel']),
|
||||
search: Object.freeze(['location-bar']),
|
||||
more: Object.freeze(['control-panel', 'pp-toggles']),
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {string} panelId
|
||||
* @returns {string|null} The sheet that presents `panelId`.
|
||||
*/
|
||||
export function sheetForPanelId(panelId) {
|
||||
for (const [sheet, ids] of Object.entries(MOBILE_SHEET_PANELS)) {
|
||||
if (ids.includes(panelId)) return sheet;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
+13
-31
@@ -18,23 +18,20 @@ import {
|
||||
readPanelState,
|
||||
} from './rail/panelState.js';
|
||||
|
||||
import {
|
||||
MOBILE_SHELL_CLASS,
|
||||
MOBILE_SHEET_ATTR,
|
||||
MOBILE_SHEET_PANELS,
|
||||
} from './mobileSheets.js';
|
||||
|
||||
export {
|
||||
MOBILE_SHELL_CLASS,
|
||||
MOBILE_SHEET_ATTR,
|
||||
MOBILE_SHEET_PANELS,
|
||||
sheetForPanelId,
|
||||
} from './mobileSheets.js';
|
||||
|
||||
export const MOBILE_SHELL_MEDIA_QUERY = '(max-width: 720px)';
|
||||
export const MOBILE_SHELL_CLASS = 'mobile-shell';
|
||||
export const MOBILE_SHEET_ATTR = 'data-mobile-sheet';
|
||||
|
||||
/**
|
||||
* Panels each sheet expands. A sheet also shows its rail's other panels
|
||||
* collapsed (Scenes under Layers), per styles/mobile-shell.css.
|
||||
*/
|
||||
export const MOBILE_SHEET_PANELS = Object.freeze({
|
||||
layers: Object.freeze(['data-panel']),
|
||||
cameras: Object.freeze(['cctv-panel', 'street-level-panel']),
|
||||
context: Object.freeze(['global-context-panel']),
|
||||
missions: Object.freeze(['space-missions-panel']),
|
||||
search: Object.freeze(['location-bar']),
|
||||
more: Object.freeze(['control-panel', 'pp-toggles']),
|
||||
});
|
||||
|
||||
export const MOBILE_TABS = Object.freeze([
|
||||
Object.freeze({ sheet: 'layers', label: msg('Layers'), icon: 'layers' }),
|
||||
Object.freeze({ sheet: 'cameras', label: msg('Cameras'), icon: 'videocam' }),
|
||||
@@ -64,17 +61,6 @@ const BORROWED_PANELS = Object.freeze([
|
||||
|
||||
const BORROW_OPTIONS = Object.freeze({ persist: false, syncShare: false });
|
||||
|
||||
/**
|
||||
* @param {string} panelId
|
||||
* @returns {string|null} The sheet that presents `panelId`.
|
||||
*/
|
||||
export function sheetForPanelId(panelId) {
|
||||
for (const [sheet, ids] of Object.entries(MOBILE_SHEET_PANELS)) {
|
||||
if (ids.includes(panelId)) return sheet;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The sheet after a tab press: the same tab closes its sheet, another opens.
|
||||
* @param {string|null} current
|
||||
@@ -112,8 +98,6 @@ function currentSheetOf(body) {
|
||||
* @param {(callback: () => void) => number} [input.requestFrame]
|
||||
* @param {() => void} [input.onSheetsClosed] Runs after the last sheet closes
|
||||
* and its panels are put back (e.g. to refresh the share link).
|
||||
* @param {(sheet: string) => void} [input.onTabOpened] Runs only when the user
|
||||
* opens a sheet from its tab, never on close or programmatic presentation.
|
||||
* @param {(view: ?{enabled: boolean, sheet: string|null, tabs: typeof MOBILE_TABS}) => void} [input.publish]
|
||||
* Receives the tab bar: whether the shell is on, the open sheet and the
|
||||
* tabs; null once the shell is destroyed.
|
||||
@@ -131,7 +115,6 @@ export function initMobileShell({
|
||||
ResizeObserverImpl = globalThis.ResizeObserver,
|
||||
requestFrame = globalThis.requestAnimationFrame?.bind(globalThis),
|
||||
onSheetsClosed = () => {},
|
||||
onTabOpened = () => {},
|
||||
publish = () => {},
|
||||
afterPublish = (callback) => callback(),
|
||||
} = {}) {
|
||||
@@ -365,7 +348,6 @@ export function initMobileShell({
|
||||
// Closing from the tab bar returns focus to the tab that was pressed.
|
||||
if (!sheet) returnFocus = button;
|
||||
setSheet(sheet);
|
||||
if (sheet && currentSheetOf(body) === sheet) onTabOpened(sheet);
|
||||
});
|
||||
// Touch events let native scrolling continue until a downward pull at the
|
||||
// top is intentional. Pointer capture/touch-action:none would also seize
|
||||
|
||||
+11
-155
@@ -2,7 +2,6 @@ import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import test from 'node:test';
|
||||
import { StyleManager } from './applicationShell.js';
|
||||
import { ContextControls } from './contextControls.js';
|
||||
import {
|
||||
MOBILE_SHEET_PANELS,
|
||||
MOBILE_TABS,
|
||||
@@ -10,7 +9,6 @@ import {
|
||||
nextSheet,
|
||||
sheetForPanelId,
|
||||
} from './mobileShell.js';
|
||||
import { withEntityRecord } from '../data/entityRecords.js';
|
||||
|
||||
function element(tag, document) {
|
||||
const node = new EventTarget();
|
||||
@@ -111,12 +109,7 @@ function element(tag, document) {
|
||||
|
||||
const PANEL_IDS = [...new Set(Object.values(MOBILE_SHEET_PANELS).flat())];
|
||||
|
||||
function fixture({
|
||||
mobile = true,
|
||||
expanded = [],
|
||||
onTabOpened = () => {},
|
||||
afterPublish,
|
||||
} = {}) {
|
||||
function fixture({ mobile = true, expanded = [], afterPublish } = {}) {
|
||||
const document = new EventTarget();
|
||||
document.ids = new Map();
|
||||
document.createElement = (tag) => element(tag, document);
|
||||
@@ -208,7 +201,6 @@ function fixture({
|
||||
}
|
||||
const shell = initMobileShell({
|
||||
documentRef: document,
|
||||
onTabOpened,
|
||||
publish,
|
||||
afterPublish,
|
||||
matchMedia: () => media,
|
||||
@@ -587,7 +579,9 @@ test('the phone shell keeps the required attribution visible', () => {
|
||||
};
|
||||
const lift = (block) =>
|
||||
Number(
|
||||
/bottom: calc\(var\(--mobile-tab-space\) \+ (\d+)px \+ var\(--world-timeline-lift, 0px\)\)/.exec(block)?.[1],
|
||||
/bottom: calc\(var\(--mobile-tab-space\) \+ (\d+)px \+ var\(--world-timeline-lift, 0px\)\)/.exec(
|
||||
block,
|
||||
)?.[1],
|
||||
);
|
||||
const z = (block) => Number(/z-index: (\d+);/.exec(block)?.[1]);
|
||||
const idleCredit = rule(
|
||||
@@ -803,157 +797,19 @@ test('touches outside the active sheet and destroyed listeners cannot dismiss or
|
||||
assert.equal(shell.getSheet(), null);
|
||||
});
|
||||
|
||||
test('the tab-open callback reports only a successful manual opening', () => {
|
||||
const opened = [];
|
||||
const phone = fixture({ onTabOpened: (sheet) => opened.push(sheet) });
|
||||
phone.shell.setSheet('context');
|
||||
assert.deepEqual(opened, []);
|
||||
phone.press('context');
|
||||
assert.deepEqual(opened, [], 'closing is not a new context request');
|
||||
phone.press('context');
|
||||
assert.deepEqual(opened, ['context']);
|
||||
phone.setBodyClass('cockpit-mode');
|
||||
test('opening the Context tab only presents its panel and starts no Context mode', () => {
|
||||
const phone = fixture();
|
||||
phone.press('context');
|
||||
assert.equal(phone.shell.getSheet(), 'context');
|
||||
assert.deepEqual(
|
||||
opened,
|
||||
['context'],
|
||||
'blocked sheets cannot activate a mode',
|
||||
phone.calls.map(({ panelId, collapsed }) => ({ panelId, collapsed })),
|
||||
[{ panelId: 'global-context-panel', collapsed: false }],
|
||||
);
|
||||
// The application shell no longer starts Contacts when the tab opens.
|
||||
assert.equal(StyleManager.prototype._onMobileTabOpened, undefined);
|
||||
phone.shell.destroy();
|
||||
});
|
||||
|
||||
test('manual Context opens the existing transaction without disabling the tracked aircraft', async () => {
|
||||
const calls = [];
|
||||
const tracked = { layerId: 'flights', icao24: 'abc123', callsign: 'EJA225' };
|
||||
const viewer = { trackedEntity: withEntityRecord({}, { trackedId: 'flights:abc123' }) };
|
||||
const entity = viewer.trackedEntity;
|
||||
const enabled = new Set(['flights', 'weather']);
|
||||
const controls = new ContextControls({
|
||||
elements: {},
|
||||
installations: {},
|
||||
actions: {
|
||||
getCockpit: () => null,
|
||||
claimVisualAuthority: () => calls.push('claim'),
|
||||
syncDetection() {},
|
||||
scheduleLayout() {},
|
||||
showToast() {},
|
||||
},
|
||||
});
|
||||
controls.connect({
|
||||
layers: new Map(
|
||||
['flights', 'weather', 'military-awareness'].map((id) => [id, {}]),
|
||||
),
|
||||
getEnabledLayerIds: () => [...enabled],
|
||||
getLayerParams: () => ({}),
|
||||
isEffectivelyEnabled: (id) => enabled.has(id),
|
||||
isEnabled: (id) => enabled.has(id),
|
||||
setLayerParams: (id, params) => calls.push({ id, params }),
|
||||
setEnabled: async (id, value) => {
|
||||
calls.push({ id, value });
|
||||
if (!value) enabled.delete(id);
|
||||
if (id === 'flights' && !value) viewer.trackedEntity = null;
|
||||
return true;
|
||||
},
|
||||
_setEnabledWithIntent: (id, value) => {
|
||||
calls.push({ id, value });
|
||||
enabled.add(id);
|
||||
return { intentEpoch: 1, promise: Promise.resolve(true) };
|
||||
},
|
||||
});
|
||||
const shell = {
|
||||
cockpitView: {
|
||||
readAircraftInfo: () => (viewer.trackedEntity ? tracked : null),
|
||||
},
|
||||
getAircraftTrackingTarget: StyleManager.prototype.getAircraftTrackingTarget,
|
||||
getContextModeState: () => controls.getContextModeState(),
|
||||
setContextMode: (mode) => controls.setContextMode(mode),
|
||||
_showToast: () => assert.fail('successful entry must not report a failure'),
|
||||
};
|
||||
try {
|
||||
assert.equal(
|
||||
await StyleManager.prototype._onMobileTabOpened.call(shell, 'context'),
|
||||
true,
|
||||
);
|
||||
assert.equal(controls.getContextModeState().mode, 'flights');
|
||||
assert.equal(viewer.trackedEntity, entity);
|
||||
assert.deepEqual(shell.getAircraftTrackingTarget(), {
|
||||
layerId: 'flights',
|
||||
id: 'abc123',
|
||||
});
|
||||
assert.ok(enabled.has('flights'));
|
||||
assert.ok(
|
||||
calls.some(
|
||||
(call) => call.id === 'military-awareness' && call.value === true,
|
||||
),
|
||||
);
|
||||
assert.ok(!calls.some((call) => call.id === 'flights'));
|
||||
const count = calls.length;
|
||||
assert.equal(
|
||||
await StyleManager.prototype._onMobileTabOpened.call(shell, 'context'),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
calls.length,
|
||||
count,
|
||||
'an already active Contacts session is not restarted',
|
||||
);
|
||||
} finally {
|
||||
controls.stop();
|
||||
controls.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
test('manual Context respects an active mode, busy transitions, missing tracks and disposal', async () => {
|
||||
for (const state of [
|
||||
{ mode: 'flights' },
|
||||
{ changing: true },
|
||||
{ entering: 'flights' },
|
||||
{ noTrack: true },
|
||||
{ disposed: true },
|
||||
{ sheet: 'layers' },
|
||||
]) {
|
||||
const shell = {
|
||||
_disposed: state.disposed,
|
||||
getContextModeState: () => state,
|
||||
getAircraftTrackingTarget: () =>
|
||||
state.noTrack ? null : { layerId: 'flights', id: 'abc123' },
|
||||
setContextMode: () =>
|
||||
assert.fail('guarded tab must not mutate Context or tracking'),
|
||||
};
|
||||
assert.equal(
|
||||
await StyleManager.prototype._onMobileTabOpened.call(
|
||||
shell,
|
||||
state.sheet || 'context',
|
||||
),
|
||||
false,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('failed mobile Contacts entry uses the existing notice and cancelled/disposed entries stay quiet', async () => {
|
||||
for (const outcome of ['failure', 'throw', 'cancelled', 'disposed']) {
|
||||
const notices = [];
|
||||
const shell = {
|
||||
getContextModeState: () => ({ mode: null }),
|
||||
getAircraftTrackingTarget: () => ({ layerId: 'flights', id: 'abc123' }),
|
||||
setContextMode: async () => {
|
||||
if (outcome === 'throw') throw new Error('source unavailable');
|
||||
if (outcome === 'disposed') shell._disposed = true;
|
||||
return { ok: false, cancelled: outcome === 'cancelled' };
|
||||
},
|
||||
_showToast: (message) => notices.push(message),
|
||||
};
|
||||
assert.equal(
|
||||
await StyleManager.prototype._onMobileTabOpened.call(shell, 'context'),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
notices.length,
|
||||
['failure', 'throw'].includes(outcome) ? 1 : 0,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('a slow downward pull is claimed before Android native scroll takes ownership', () => {
|
||||
const { document, shell, press } = fixture();
|
||||
press('layers');
|
||||
|
||||
@@ -20,6 +20,10 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
|
||||
/** The preview: requested and shown frame, loading and error state. */
|
||||
const frame = shallowRef(null);
|
||||
/** Number of camera cards outside the panel showing its preview, including Context's card. */
|
||||
const previewCards = shallowRef(0);
|
||||
/** Number of open bigger views of a camera card (popups over the map). */
|
||||
const previewPopups = shallowRef(0);
|
||||
/** Whether the live video surface replaces the still frame. */
|
||||
const live = shallowRef(false);
|
||||
/** `{label, state}` for the source badge; null until first synced. */
|
||||
@@ -49,6 +53,16 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
frame.value = markRaw(next);
|
||||
}
|
||||
|
||||
/** @param {boolean} shown */
|
||||
function showPreviewCard(shown) {
|
||||
previewCards.value = Math.max(0, previewCards.value + (shown ? 1 : -1));
|
||||
}
|
||||
|
||||
/** @param {boolean} shown */
|
||||
function showPreviewPopup(shown) {
|
||||
previewPopups.value = Math.max(0, previewPopups.value + (shown ? 1 : -1));
|
||||
}
|
||||
|
||||
/** @param {boolean} on */
|
||||
function setLive(on) {
|
||||
live.value = Boolean(on);
|
||||
@@ -73,6 +87,8 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
view,
|
||||
calEdit,
|
||||
frame,
|
||||
previewCards,
|
||||
previewPopups,
|
||||
live,
|
||||
sourceBadge,
|
||||
summary,
|
||||
@@ -80,6 +96,8 @@ export const useCctvStore = defineStore('gev-cctv', () => {
|
||||
publish,
|
||||
setCalEdit,
|
||||
setFrame,
|
||||
showPreviewCard,
|
||||
showPreviewPopup,
|
||||
setLive,
|
||||
setSourceBadge,
|
||||
setSummary,
|
||||
|
||||
@@ -357,6 +357,13 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
* @param {boolean} [options.fly] Also fly the camera to it.
|
||||
* @returns {boolean} Whether a card could be made.
|
||||
*/
|
||||
/**
|
||||
* Counts card selections and clears, so a selection that was asked for
|
||||
* before a newer one can tell it came too late.
|
||||
*/
|
||||
let generation = 0;
|
||||
const selectionGeneration = () => generation;
|
||||
|
||||
/** Things that move are followed as soon as they are picked. */
|
||||
const AUTO_FOLLOW = new Set(['flights', 'military', 'satellites']);
|
||||
/**
|
||||
@@ -374,6 +381,7 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
*/
|
||||
function select(identity, { fly = false, follow: autoFollow = true } = {}) {
|
||||
if (!read(identity)) return false;
|
||||
generation++;
|
||||
stopLocating();
|
||||
away.value = false;
|
||||
reference =
|
||||
@@ -403,6 +411,7 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
}
|
||||
|
||||
function clear() {
|
||||
generation++;
|
||||
if (following.value) shell.value?.letGo?.(card.value);
|
||||
following.value = null;
|
||||
asked = null;
|
||||
@@ -451,6 +460,7 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
locate,
|
||||
connect,
|
||||
select,
|
||||
selectionGeneration,
|
||||
clear,
|
||||
refresh,
|
||||
flyTo,
|
||||
@@ -477,3 +487,33 @@ export const useEntityCardStore = defineStore('gev-entity-card', () => {
|
||||
askAboutView,
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Opens what a voice or chat action selected in the Context panel, as a click
|
||||
* on it does (`src/ui/entityContextBridge.js` selects the same way): its card
|
||||
* opens, and the panel with it. The app hands it to voice, which reads
|
||||
* `generation()` when a selection is asked and passes it back as `since`.
|
||||
* The action has already selected or followed the item in its own layer, so
|
||||
* the card does not follow it again (a click on a flight does not either). A
|
||||
* card picked or cleared since the action was asked stays, and nothing opens
|
||||
* in Cockpit, where Context is hidden.
|
||||
* @param {import('pinia').Pinia} pinia
|
||||
* @returns {{generation: () => number, show: (identity: {layerId: string, id: string|number, label?: string, lat?: number, lon?: number}, options?: {since?: number|null, cockpitActive?: boolean}) => boolean}}
|
||||
*/
|
||||
export function createContextCardOpener(pinia) {
|
||||
const store = () => useEntityCardStore(pinia);
|
||||
return {
|
||||
generation: () => store().selectionGeneration(),
|
||||
show(identity, { since = null, cockpitActive = false } = {}) {
|
||||
if (!identity?.layerId || identity.id == null || identity.id === '')
|
||||
return false;
|
||||
if (cockpitActive) return false;
|
||||
if (since !== null && store().selectionGeneration() !== since)
|
||||
return false;
|
||||
return store().select(
|
||||
{ ...identity, id: String(identity.id) },
|
||||
{ follow: false },
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -28,8 +28,20 @@ body:not(.mobile-shell):not(.cockpit-mode):not(.scene-playback-mode):not(
|
||||
.hud-readout:has(> #hud-mode) {
|
||||
display: none;
|
||||
}
|
||||
/* The globe actions sit on the title row, level with the title, with the
|
||||
loading line under them (status.css). Narrower, where the row would reach
|
||||
the title, they drop to the HUD's top rows and the loading line drops
|
||||
with them, so it never covers the actions. */
|
||||
#top-center-actions {
|
||||
top: clamp(86px, 9.55vh, 108px);
|
||||
top: 32px;
|
||||
}
|
||||
@media (max-width: 1179px) {
|
||||
#top-center-actions {
|
||||
top: clamp(86px, 9.55vh, 108px);
|
||||
}
|
||||
#global-loading-status {
|
||||
top: calc(clamp(86px, 9.55vh, 108px) + 42px);
|
||||
}
|
||||
}
|
||||
#left-panel-stack.layout-focus {
|
||||
bottom: var(--left-stack-safe-bottom, 4vh);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { t } from '../../../i18n/index.js';
|
||||
import { useCctvStore } from '../../stores/cctv.js';
|
||||
@@ -16,7 +16,8 @@ const props = defineProps({
|
||||
cameraId: { type: String, default: '' },
|
||||
});
|
||||
|
||||
const { view, frame, sourceBadge } = storeToRefs(useCctvStore());
|
||||
const cctv = useCctvStore();
|
||||
const { view, frame, sourceBadge } = storeToRefs(cctv);
|
||||
const chrome = usePanelChromeStore();
|
||||
const { panels } = storeToRefs(chrome);
|
||||
|
||||
@@ -53,11 +54,19 @@ const big = ref(false);
|
||||
const onKey = (e) => {
|
||||
if (e.key === 'Escape') big.value = false;
|
||||
};
|
||||
watch(big, (open) => {
|
||||
if (open) document.addEventListener('keydown', onKey);
|
||||
else document.removeEventListener('keydown', onKey);
|
||||
// The cleanup also runs when the card unmounts, even if `big` turned false in
|
||||
// the same tick and the watcher never saw it.
|
||||
watch(big, (open, _, onCleanup) => {
|
||||
if (!open) return;
|
||||
cctv.showPreviewPopup(true);
|
||||
document.addEventListener('keydown', onKey);
|
||||
onCleanup(() => {
|
||||
cctv.showPreviewPopup(false);
|
||||
document.removeEventListener('keydown', onKey);
|
||||
});
|
||||
});
|
||||
onBeforeUnmount(() => document.removeEventListener('keydown', onKey));
|
||||
onMounted(() => cctv.showPreviewCard(true));
|
||||
onBeforeUnmount(() => cctv.showPreviewCard(false));
|
||||
|
||||
function openPanel() {
|
||||
if (panels.value['cctv-panel']?.collapsed !== false) chrome.act('toggle', 'cctv-panel');
|
||||
|
||||
Reference in new issue
Block a user