Files
gods-eye-view/src/ui/views/panels/AwarenessPanel.vue
T
Manjunath PaparajuandSameh Khamis 1ce7e51c22 Bring Contacts, Space Missions and Radio back into Context
The Context panel's main tab shows the mode row again, with Contacts
(nearby sites search, the TR-3B toggle and the Awareness list) and Space
Missions (the roster and launch replay); only the Properties tab hides
them. Radio shows while its layer is on, and turning Radio or Launches on
opens Context. When Contacts follows the aircraft the card shows, its list
sits inside the card in a compact form and the card leaves out the flights
and vessels Contacts already lists. The card's Enter Cockpit replaces the
Contacts button, and leaving the cockpit returns focus to it.

Co-authored-by: Sameh Khamis <[email protected]>
2026-11-16 14:59:18 -08:00

88 lines
5.1 KiB
Vue

<script setup>
import { storeToRefs } from 'pinia';
import { onBeforeUpdate, onUpdated, ref } from 'vue';
import { t } from '../../../i18n/index.js';
import { useContextStore } from '../../stores/context.js';
import AwarenessNames from './AwarenessNames.vue';
// The Contacts panel inside Context. The Contacts layer publishes its view
// (standby, results or empty); until it does, the panel shows its initial
// markup. Buttons call the layer's navigation as the person's own.
const props = defineProps({ compact: Boolean });
const { awareness: view, awarenessLayer: layer } = storeToRefs(useContextStore());
const user = { origin: 'user' };
const root = ref(null);
// A photo whose image failed to load stays hidden until another one arrives.
// The failing image's own src is recorded, so a late error from a previous
// photo never hides the current one.
const failedPhoto = ref('');
const fail = (event) => {
failedPhoto.value = event.target.getAttribute('src');
};
// A live repaint keeps focus on the same control by identity: browsers drop
// focus from a node Vue moves, removes or disables, so the control is found
// again by its key. When it is gone or disabled, focus continues at the note
// beyond the list rather than jumping to another contact.
const CONTINUATION = '[data-awareness-focus-continuation]';
const controlKey = (el) => {
if (el?.matches?.(CONTINUATION)) return 'continuation';
const { awarenessAction: action, awarenessLayer: layer, awarenessId: id } = el?.dataset ?? {};
if (action) return `action:${action}`;
return layer && id ? `target:${layer}:${id}` : null;
};
let focusedKey = null;
onBeforeUpdate(() => {
const active = document.activeElement;
focusedKey = root.value?.contains(active) ? controlKey(active) ?? 'continuation' : null;
});
onUpdated(() => {
const key = focusedKey;
focusedKey = null;
const panel = root.value;
// A disabled control may keep focus until the browser's next frame.
const active = document.activeElement;
if (!key || !panel || (panel.contains(active) && !active.disabled)) return;
const retained = key === 'continuation' ? null : [...panel.querySelectorAll('button[data-awareness-action], button[data-awareness-id]')].find((control) => !control.disabled && controlKey(control) === key);
(retained || panel.querySelector(CONTINUATION))?.focus({ preventScroll: true });
});
</script>
<template>
<aside id="military-awareness-panel" class="ui-scroll" ref="root">
<div v-if="!view" class="military-awareness-standby">
<strong>{{ t('CONTACTS CONTEXT OFF') }}</strong>
<span>{{ t('SELECT CONTACTS TO LOAD OBSERVED / MAPPED PROXIMITY') }}</span>
</div>
<div v-else-if="view.kind === 'standby'" class="military-awareness-standby">
<strong>{{ view.title }}</strong>
<span>{{ view.text }}</span>
</div>
<template v-else-if="view.kind === 'results'">
<div v-if="!props.compact" class="military-awareness-subject">{{ view.subject }}</div>
<a v-if="!props.compact && view.photo && view.photo.src !== failedPhoto" class="military-awareness-photo" :href="view.photo.link" target="_blank" rel="noopener">
<img :src="view.photo.src" :width="view.photo.width ?? undefined" :height="view.photo.height ?? undefined" alt="" @error="fail" />
<small v-if="view.photo.credit">{{ view.photo.credit }}</small>
</a>
<AwarenessNames v-if="view.subjectNames" :names="view.subjectNames" />
<div class="military-awareness-controls" role="group" :aria-label="view.navigation.label">
<button type="button" data-awareness-action="previous" :title="view.navigation.previous.title" :disabled="view.navigation.previous.disabled" @click="layer?.navigatePrevious(user)">{{ view.navigation.previous.text }}</button>
<button type="button" data-awareness-action="focus" @click="layer?.focusCurrent(user)">{{ view.navigation.focus.text }}</button>
<button type="button" data-awareness-action="next" :title="view.navigation.next.title" :disabled="view.navigation.next.disabled" @click="layer?.navigateNext(user)">{{ view.navigation.next.text }}</button>
</div>
<section v-for="row in view.rows" :key="row.id" :class="['military-awareness-row', row.relationship]">
<div><strong>{{ row.label }}</strong><b aria-live="polite">{{ row.count }}</b></div>
<small>{{ row.detail }}</small>
<ul v-if="row.nearest.length">
<li v-for="item in row.nearest" :key="item.key">
<button v-if="item.targetId" type="button" class="military-awareness-target" :data-awareness-layer="item.layer" :data-awareness-id="item.targetId" :aria-label="item.ariaLabel" @click="layer?.focusTarget(item.layer, item.targetId, user)">{{ item.label }} <span>{{ item.distance }}</span></button>
<span v-else class="military-awareness-target unavailable" :aria-label="item.ariaLabel">{{ item.label }} <span>{{ item.distance }}</span></span>
<AwarenessNames v-if="item.names" :names="item.names" />
</li>
</ul>
</section>
<p class="military-awareness-note" tabindex="-1" data-awareness-focus-continuation>{{ view.note }}</p>
</template>
</aside>
</template>