When the fleet page is empty or a printer is "unknown", the reason is almost always upstream: the gateway is not connected, or discovery never reported. A strip per farm now says which - "Gateway online/offline/ checking" (no answer yet is not offline) - with a collapsible list of the printers discovery found, each marked already added, same address as an added printer, or not added yet, using the backend's serial/address match. It also says plainly when discovery has not reported at all, which is the default, as distinct from a scan that found nothing. Read-only on purpose: adding a printer from the UI still needs the proxy's offline-capable store and a credential pass-through that is never kept in the cloud. Polled every 10s (gateway presence has no push channel); a failed poll keeps the last answer instead of flipping to offline. Checked in real Chrome against the live stack (Gateway online, discovery not reported, no page errors); the static SPA still generates, now 6 routes.
76 lines
2.3 KiB
Vue
76 lines
2.3 KiB
Vue
<script setup lang="ts">
|
|
import { computed } from "vue";
|
|
import type { AppFarm, AppFarmDiscovery } from "../types";
|
|
|
|
const props = defineProps<{ farm: AppFarm; status: AppFarmDiscovery | null }>();
|
|
|
|
// Three honest answers, not two: no answer yet is not "offline".
|
|
const gateway = computed(() =>
|
|
props.status === null ? "checking" : props.status.gatewayOnline ? "online" : "offline",
|
|
);
|
|
|
|
const candidates = computed(() => props.status?.discovery?.printers ?? []);
|
|
|
|
const discoveryNote = computed(() => {
|
|
if (!props.status) return "";
|
|
if (props.status.discovery === null)
|
|
return "Discovery has not reported - it is off by default on a gateway.";
|
|
if (!candidates.value.length)
|
|
return `Scanned ${new Date(props.status.discovery.scannedAt).toLocaleString()}: nothing found.`;
|
|
return `Scanned ${new Date(props.status.discovery.scannedAt).toLocaleString()}.`;
|
|
});
|
|
|
|
const label = (c: { name?: string | null; model?: string | null; vendor: string }) =>
|
|
[c.name, c.model].filter(Boolean).join(" / ") || c.vendor;
|
|
</script>
|
|
|
|
<template>
|
|
<section class="farm-status" :aria-label="`Farm ${farm.name}`">
|
|
<span class="farm-status__name">{{ farm.name }}</span>
|
|
<span class="farm-status__gateway" :class="`is-${gateway}`">Gateway {{ gateway }}</span>
|
|
<details v-if="status" class="farm-status__discovery">
|
|
<summary>Discovered printers ({{ candidates.length }})</summary>
|
|
<p>{{ discoveryNote }}</p>
|
|
<ul v-if="candidates.length">
|
|
<li v-for="c in candidates" :key="c.address + (c.serial ?? '')">
|
|
<strong>{{ label(c) }}</strong> - {{ c.vendor }} at {{ c.address }}
|
|
<template v-if="c.matchedOn === 'serial'"> - already added</template>
|
|
<template v-else-if="c.matchedOn === 'address'"> - same address as an added printer (check)</template>
|
|
<template v-else> - not added yet</template>
|
|
</li>
|
|
</ul>
|
|
</details>
|
|
</section>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.farm-status {
|
|
display: flex;
|
|
gap: 1rem;
|
|
align-items: baseline;
|
|
flex-wrap: wrap;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.farm-status__name {
|
|
font-weight: 600;
|
|
}
|
|
|
|
.farm-status__gateway.is-online {
|
|
color: #35d07f;
|
|
}
|
|
|
|
.farm-status__gateway.is-offline {
|
|
color: #f2604c;
|
|
}
|
|
|
|
.farm-status__gateway.is-checking {
|
|
opacity: 0.6;
|
|
}
|
|
|
|
.farm-status__discovery ul {
|
|
margin: 0.25rem 0 0;
|
|
padding-left: 1.25rem;
|
|
}
|
|
</style>
|