Files
shopdb-flask/plugins/warranty/frontend/components/MachineMapChip.vue
cproudlock 9e271b4c03 warranty: show the machine a covered PC drives, with a map on hover
A shopfloor PC is bought, warranted and replaced as a PC, but it is FOUND by
the machine it drives - nobody walks the floor looking for an asset number. The
warranty tables listed the covered asset and left the reader to work out where
that is.

Both tables gain a Machine # column. The payload resolves it by walking the
asset relationship graph in BOTH directions: the canonical edge is
PC --controls--> machine, but a dual-bay pair carries controls on both bays and
hand-made links are not reliably oriented.

Hovering the chip shows the floor map with the machine marked, so the row
answers "where do I go" without opening anything. The blueprint follows the
viewer's theme and the marker is placed from mapx/mapy as a percentage of the
configured map dimensions, since the preview is a few hundred pixels wide
rather than the full plan. It renders only while hovered, so a long table does
not build a blueprint per row.

A machine with no map position still gets its chip and says so, rather than
being dropped: against real data 142 PCs resolve to a machine and 125 of those
are placed, so 17 rows would otherwise have silently lost their number.

The chip is deliberately not a link. /machines/:id is keyed by machineid, not
assetid, and resolving one to the other here would make the warranty plugin
import the machines plugin (ADR-014). Worth noting separately: the existing
assetLink() in these tables already sends machine-type assets to
/machines/<assetid>, which is that same mismatch and predates this change.
2026-08-10 09:41:48 -04:00

125 lines
4.0 KiB
Vue

<template>
<span
v-if="machine"
class="mmc"
@mouseenter="open = true"
@mouseleave="open = false"
>
<!-- Deliberately not a link. /machines/:id is keyed by machineid, not
assetid, and resolving one to the other here would make the warranty
plugin import the machines plugin (ADR-014). The number plus the map
is what someone needs to walk to the bay. -->
<span class="mmc-chip">{{ machine.machinenumber || machine.name || '-' }}</span>
<!-- Hover preview: where to walk to. Rendered only while hovered so a
table of 200 rows does not build 200 blueprints. -->
<span v-if="open && hasPosition" class="mmc-pop">
<span class="mmc-pop-title">{{ machine.name || machine.machinenumber }}</span>
<span v-if="machine.locationname" class="mmc-pop-loc">{{ machine.locationname }}</span>
<span class="mmc-map">
<img :src="blueprint" alt="" class="mmc-map-img" />
<span class="mmc-marker" :style="markerStyle"></span>
</span>
</span>
<!-- A machine with a number but no map position still deserves the chip;
say why there is no picture rather than showing an empty box. -->
<span v-else-if="open" class="mmc-pop mmc-pop-plain">
<span class="mmc-pop-title">{{ machine.name || machine.machinenumber }}</span>
<span class="mmc-pop-loc">{{ machine.locationname || 'Not placed on the floor map' }}</span>
</span>
</span>
<span v-else class="muted">-</span>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { state as mapState, loadMapConfig, blueprintUrlFor } from '@/composables/mapConfig'
const props = defineProps({
machine: { type: Object, default: null }
})
const open = ref(false)
onMounted(() => { loadMapConfig() })
const hasPosition = computed(() =>
props.machine && props.machine.mapx != null && props.machine.mapy != null)
// Follow the viewer's theme the same way the full map does, so the preview is
// not a white rectangle on a dark page.
const blueprint = computed(() => {
const dark = document.documentElement.dataset.theme === 'dark'
|| (!document.documentElement.dataset.theme
&& window.matchMedia('(prefers-color-scheme: dark)').matches)
return blueprintUrlFor(dark ? 'dark' : 'light')
})
// mapx/mapy are pixel coordinates in the blueprint's own space, so they have to
// be expressed as a percentage of its configured dimensions - the preview is a
// few hundred pixels wide, not the full plan.
const markerStyle = computed(() => {
if (!hasPosition.value) return {}
const width = mapState.width || 3300
const height = mapState.height || 2550
return {
left: `${(props.machine.mapx / width) * 100}%`,
top: `${(props.machine.mapy / height) * 100}%`
}
})
</script>
<style scoped>
.mmc { position: relative; display: inline-block; }
.mmc-chip {
display: inline-block;
padding: 0.1rem 0.5rem;
border-radius: 999px;
background: var(--bg);
border: 1px solid var(--border);
color: var(--text);
font-size: 0.8rem;
font-family: ui-monospace, Menlo, Consolas, monospace;
text-decoration: none;
}
.mmc:hover .mmc-chip { border-color: var(--primary); }
.mmc-pop {
position: absolute;
z-index: 40;
left: 0;
top: calc(100% + 0.35rem);
display: flex;
flex-direction: column;
gap: 0.25rem;
padding: 0.5rem;
width: 18rem;
background: var(--bg-card-solid);
border: 1px solid var(--border);
border-radius: 6px;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.mmc-pop-plain { width: 14rem; }
.mmc-pop-title { font-weight: 600; font-size: 0.85rem; color: var(--text); }
.mmc-pop-loc { font-size: 0.78rem; color: var(--text-light); }
.mmc-map { position: relative; display: block; line-height: 0; }
.mmc-map-img {
width: 100%;
height: auto;
border-radius: 4px;
border: 1px solid var(--border);
}
.mmc-marker {
position: absolute;
width: 12px;
height: 12px;
margin: -6px 0 0 -6px;
border-radius: 50%;
background: var(--danger);
border: 2px solid #fff;
box-shadow: 0 0 0 2px var(--danger);
}
</style>