Pass lowVoltage/timeoutLength via props instead of re-importing config

This commit is contained in:
Adam Goldsmith 2023-07-14 18:03:56 -04:00
parent 269cdb65f1
commit 9426e2ead6
2 changed files with 17 additions and 17 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<tr :class="{ timedOut, lowVoltage, neverHeard: !stationStatus.lastHeard }"> <tr :class="{ timedOut, isLowVoltage, neverHeard: !stationStatus.lastHeard }">
<td :title="callsign">{{ tacticalAndOrCall }}</td> <td :title="callsign">{{ tacticalAndOrCall }}</td>
<template v-if="stationStatus.lastHeard"> <template v-if="stationStatus.lastHeard">
<td>{{ formatTime(stationStatus.lastHeard) }}</td> <td>{{ formatTime(stationStatus.lastHeard) }}</td>
@ -24,11 +24,12 @@
<script setup> <script setup>
import { ref, computed, watch } from 'vue'; import { ref, computed, watch } from 'vue';
import config from './status_config.yaml';
const props = defineProps({ const props = defineProps({
callsign: String, callsign: String,
tactical: String, tactical: String,
timeoutLength: Number,
lowVoltage: Number,
messages: Array, messages: Array,
now: Date, now: Date,
}); });
@ -70,15 +71,15 @@ const timedOut = computed(() => {
return false; return false;
} else { } else {
return ( return (
props.now.getTime() - stationStatus.value.lastHeard > config.timeoutLength props.now.getTime() - stationStatus.value.lastHeard > props.timeoutLength
); );
} }
}); });
const lowVoltage = computed(() => { const isLowVoltage = computed(() => {
return ( return (
stationStatus.value.lastVoltage && stationStatus.value.lastVoltage &&
stationStatus.value.lastVoltage < config.lowVoltage stationStatus.value.lastVoltage < props.lowVoltage
); );
}); });
@ -114,23 +115,20 @@ const stationStatus = computed(() => {
return status; return status;
}); });
watch( watch(isLowVoltage, (newVal) => {
() => props.lowVoltage,
(newVal) => {
if (newVal) { if (newVal) {
notify( notify(
`${tacticalAndOrCall}'s battery has dropepd below ${config.lowVoltage}V`, `${tacticalAndOrCall}'s battery has dropepd below ${props.lowVoltage}V`,
`Voltage: ${stationStatus.value.lastVoltage}` `Voltage: ${stationStatus.value.lastVoltage}`
); );
} }
} });
);
watch(timedOut, (newVal) => { watch(timedOut, (newVal) => {
if (newVal) { if (newVal) {
notify( notify(
`${tacticalAndOrCall.value} has not been heard for over ${prettyDuration( `${tacticalAndOrCall.value} has not been heard for over ${prettyDuration(
config.timeoutLength props.timeoutLength
)}!`, )}!`,
`Last Heard: ${formatTime( `Last Heard: ${formatTime(
stationStatus.value.lastHeard stationStatus.value.lastHeard
@ -147,7 +145,7 @@ tr.timedOut {
background-color: red; background-color: red;
} }
tr.lowVoltage { tr.isLowVoltage {
background-color: yellow; background-color: yellow;
} }

View File

@ -25,6 +25,8 @@
:key="callsign" :key="callsign"
:callsign="callsign" :callsign="callsign"
:tactical="tactical" :tactical="tactical"
:lowVoltage="config.lowVoltage"
:timeoutLength="config.timeoutLength"
:messages="messagesFromStation[callsign] || []" :messages="messagesFromStation[callsign] || []"
:now="now" :now="now"
> >