Cars: log what charging costs, and drag the provider readings
Three things, all on a car's page. A Charging cost tab, which is the Fuel cost tab written for an electric car: charges in kWh, consumption in kWh/100km beside km per kWh, cost per km and price per kWh, and the same summary panel over the whole history. It keeps the reference-point method too, and has to — a session records the energy that went in, not what was left in the battery, so a given number of kWh only maps to a distance between two charges that ended at the same state. A charge to the car's usual full point plays the part of the full tank; partial charges still count towards the cost and roll into the next full one; and a charge taken without logging it leaves its window uncomputed rather than reporting an implausibly good figure. Sessions live in their own collection, the figures are derived on read like the fuel ones, and logging a charge advances the odometer exactly as a refill does. The tab switches off from the gear like every other, so a petrol car need never see it. The headline readings on the connected-service tab now drag into any order, saved on drop. Stored on the car as metricOrder, like the Information rows, rather than per device the way the collapsed cards are: an arrangement is something everyone the car is shared with should see, where a folded card is one browser's reading habit. Only what the provider reported can be arranged, so a reading that turns up later joins the end rather than displacing the arrangement. Fuel is now Fuel cost, tab and heading, which is what the tab has always been about and what pairs it with Charging cost. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b6da642ad
commit
6191160f14
20 files changed
+1388
-53
No files matched your search
@@ -9,6 +9,9 @@ import {
|
||||
formatMoney,
|
||||
formatConsumption,
|
||||
formatKmPerLiter,
|
||||
formatKwh,
|
||||
formatConsumptionKwh,
|
||||
formatKmPerKwh,
|
||||
serviceStatus,
|
||||
expiryStatus,
|
||||
reminderStatus,
|
||||
@@ -19,6 +22,7 @@ import ServiceFormModal from "../components/ServiceFormModal.vue";
|
||||
import TechnicalCheckFormModal from "../components/TechnicalCheckFormModal.vue";
|
||||
import PartFormModal from "../components/PartFormModal.vue";
|
||||
import FuelFormModal from "../components/FuelFormModal.vue";
|
||||
import ChargingFormModal from "../components/ChargingFormModal.vue";
|
||||
import MaintenanceFormModal from "../components/MaintenanceFormModal.vue";
|
||||
import DocumentFormModal from "../components/DocumentFormModal.vue";
|
||||
import ReminderFormModal from "../components/ReminderFormModal.vue";
|
||||
@@ -35,6 +39,8 @@ const technicalChecks = ref([]);
|
||||
const parts = ref([]);
|
||||
const fuel = ref([]);
|
||||
const fuelStats = ref(null);
|
||||
const charging = ref([]);
|
||||
const chargingStats = ref(null);
|
||||
const maintenance = ref([]);
|
||||
const documents = ref([]);
|
||||
const reminders = ref([]);
|
||||
@@ -51,6 +57,8 @@ const showPart = ref(false);
|
||||
const editingPart = ref(null);
|
||||
const showFuel = ref(false);
|
||||
const editingFuel = ref(null);
|
||||
const showCharging = ref(false);
|
||||
const editingCharging = ref(null);
|
||||
const showMaintenance = ref(false);
|
||||
const editingMaintenance = ref(null);
|
||||
const showDocument = ref(false);
|
||||
@@ -119,6 +127,7 @@ const TABS = computed(() =>
|
||||
{ key: "technical", label: t("car.tabs.technical") },
|
||||
{ key: "maintenance", label: t("car.tabs.maintenance") },
|
||||
{ key: "fuel", label: t("car.tabs.fuel") },
|
||||
{ key: "charging", label: t("car.tabs.charging") },
|
||||
{ key: "documents", label: t("car.tabs.documents") },
|
||||
{ key: "parts", label: t("car.tabs.parts") },
|
||||
{ key: "reminders", label: t("car.tabs.reminders") },
|
||||
@@ -142,7 +151,8 @@ watch(TABS, (tabs) => {
|
||||
// the page rearrange under the pointer between clicks.
|
||||
const showViewPicker = ref(false);
|
||||
const HIDEABLE_TABS = [
|
||||
"provider", "services", "technical", "maintenance", "fuel", "documents", "parts", "reminders",
|
||||
"provider", "services", "technical", "maintenance", "fuel", "charging",
|
||||
"documents", "parts", "reminders",
|
||||
];
|
||||
// The Information rows, in their default order. Keys mirror hideableCarFields
|
||||
// in the API's cars.go — the server rejects anything else.
|
||||
@@ -324,6 +334,8 @@ async function load() {
|
||||
parts.value,
|
||||
fuel.value,
|
||||
fuelStats.value,
|
||||
charging.value,
|
||||
chargingStats.value,
|
||||
maintenance.value,
|
||||
documents.value,
|
||||
reminders.value,
|
||||
@@ -334,6 +346,8 @@ async function load() {
|
||||
api.listCarParts(props.id),
|
||||
api.listCarFuel(props.id),
|
||||
api.getCarFuelStats(props.id),
|
||||
api.listCarCharging(props.id),
|
||||
api.getCarChargingStats(props.id),
|
||||
api.listCarMaintenance(props.id),
|
||||
api.listCarDocuments(props.id),
|
||||
api.listCarReminders(props.id),
|
||||
@@ -459,6 +473,42 @@ async function deleteFuel(id) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- charging ---
|
||||
//
|
||||
// The same handling as fuel, for the same reasons: a session re-derives every
|
||||
// window it touches and advances the car's odometer, so the whole set is
|
||||
// refetched rather than the one list that was edited.
|
||||
function openAddCharging() {
|
||||
editingCharging.value = null;
|
||||
showCharging.value = true;
|
||||
}
|
||||
function openEditCharging(c) {
|
||||
editingCharging.value = c;
|
||||
showCharging.value = true;
|
||||
}
|
||||
async function reloadCharging() {
|
||||
[charging.value, chargingStats.value, car.value, reminders.value] = await Promise.all([
|
||||
api.listCarCharging(props.id),
|
||||
api.getCarChargingStats(props.id),
|
||||
api.getCar(props.id),
|
||||
api.listCarReminders(props.id),
|
||||
]);
|
||||
}
|
||||
async function onChargingSaved() {
|
||||
showCharging.value = false;
|
||||
editingCharging.value = null;
|
||||
await reloadCharging();
|
||||
}
|
||||
async function deleteCharging(id) {
|
||||
if (!confirm(t("car.charging.confirmDelete"))) return;
|
||||
try {
|
||||
await api.deleteCharging(id);
|
||||
await reloadCharging();
|
||||
} catch (e) {
|
||||
error.value = e.message;
|
||||
}
|
||||
}
|
||||
|
||||
// --- maintenance ---
|
||||
function openAddMaintenance() {
|
||||
editingMaintenance.value = null;
|
||||
@@ -1057,6 +1107,118 @@ onMounted(load);
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Charging cost. The EV counterpart of Fuel: energy in place of litres,
|
||||
and a charge to the usual full point in place of the full tank. -->
|
||||
<section v-else-if="activeTab === 'charging'">
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
<div>
|
||||
<h2 class="text-lg font-bold tracking-[-0.02em] text-strong">{{ t("car.charging.title") }}</h2>
|
||||
<p class="text-sm text-muted">{{ t("car.charging.subtitle") }}</p>
|
||||
</div>
|
||||
<button v-if="canWrite" class="dh-btn dh-btn-primary !px-3 !py-1.5" @click="openAddCharging">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" class="h-4 w-4"><path stroke-linecap="round" stroke-linejoin="round" d="M12 5v14M5 12h14" /></svg>
|
||||
{{ t("car.charging.add") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Rollup -->
|
||||
<div v-if="chargingStats && chargingStats.entries > 0" class="dh-card mb-4 p-6">
|
||||
<dl class="grid grid-cols-2 gap-4 text-sm sm:grid-cols-4">
|
||||
<div>
|
||||
<dt class="eyebrow">{{ t("car.charging.average") }}</dt>
|
||||
<dd class="mt-0.5 data text-lg font-bold text-strong">{{ formatConsumptionKwh(chargingStats.avgConsumptionKwh100) }}</dd>
|
||||
<dd class="text-xs text-muted">{{ formatKmPerKwh(chargingStats.avgKmPerKwh) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="eyebrow">{{ t("car.charging.best") }}</dt>
|
||||
<dd class="mt-0.5 data font-medium text-success">{{ formatConsumptionKwh(chargingStats.bestConsumptionKwh100) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="eyebrow">{{ t("car.charging.worst") }}</dt>
|
||||
<dd class="mt-0.5 data font-medium text-danger">{{ formatConsumptionKwh(chargingStats.worstConsumptionKwh100) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="eyebrow">{{ t("car.charging.costPerKm") }}</dt>
|
||||
<dd class="mt-0.5 data font-medium text-strong">{{ formatMoney(chargingStats.costPerKm) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="eyebrow">{{ t("car.charging.sessions") }}</dt>
|
||||
<dd class="mt-0.5 data font-medium text-strong">{{ chargingStats.entries }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="eyebrow">{{ t("car.charging.totalKwh") }}</dt>
|
||||
<dd class="mt-0.5 data font-medium text-strong">{{ formatKwh(chargingStats.totalKwh) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="eyebrow">{{ t("car.charging.totalSpent") }}</dt>
|
||||
<dd class="mt-0.5 data font-medium text-strong">{{ formatMoney(chargingStats.totalCost) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt class="eyebrow">{{ t("car.charging.trackedDistance") }}</dt>
|
||||
<dd class="mt-0.5 data font-medium text-strong">{{ formatKm(chargingStats.trackedDistanceKm) }}</dd>
|
||||
<dd class="text-xs text-muted">{{ t("car.charging.avgPrice", { price: formatMoney(chargingStats.avgPricePerKwh) }) }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p v-if="!chargingStats.avgConsumptionKwh100" class="mt-4 text-xs text-muted">
|
||||
{{ t("car.charging.needTwoCharges") }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div v-if="charging.length === 0" class="rounded-card border border-dashed border-default p-8 text-center text-muted">
|
||||
{{ t("car.charging.empty") }}
|
||||
</div>
|
||||
|
||||
<div v-else class="dh-card overflow-x-auto p-0">
|
||||
<table class="min-w-full text-sm">
|
||||
<thead class="bg-sunken text-left">
|
||||
<tr class="[&>th]:eyebrow [&>th]:px-4 [&>th]:py-3">
|
||||
<th>{{ t("car.charging.colDate") }}</th>
|
||||
<th>{{ t("car.charging.colKm") }}</th>
|
||||
<th class="!text-right">{{ t("car.charging.colKwh") }}</th>
|
||||
<th class="!text-right">{{ t("car.charging.colCost") }}</th>
|
||||
<th class="!text-right">{{ t("car.charging.colPerKwh") }}</th>
|
||||
<th class="!text-right">{{ t("car.charging.colDistance") }}</th>
|
||||
<th class="!text-right">{{ t("car.charging.colConsumption") }}</th>
|
||||
<th>{{ t("car.charging.colLocation") }}</th>
|
||||
<th>{{ t("car.charging.colFile") }}</th>
|
||||
<th v-if="canWrite"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-subtle">
|
||||
<tr v-for="c in charging" :key="c.id" class="transition-colors hover:bg-sunken">
|
||||
<td class="whitespace-nowrap px-4 py-3 data font-medium text-strong">
|
||||
{{ formatDate(c.date) }}
|
||||
<span v-if="!c.fullCharge" class="ml-1 text-xs font-normal text-muted">{{ t("car.charging.partial") }}</span>
|
||||
<span v-if="c.missedSession" class="ml-1 text-xs font-normal text-warning">{{ t("car.charging.gap") }}</span>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-4 py-3 data text-body">{{ formatKm(c.km) }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3 text-right data text-body">{{ formatKwh(c.kwh) }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3 text-right data text-body">{{ c.cost ? formatMoney(c.cost) : t("common.empty") }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3 text-right data text-muted">{{ formatMoney(c.pricePerKwh) }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3 text-right data text-muted">{{ c.distanceKm ? formatKm(c.distanceKm) : t("common.empty") }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3 text-right data font-medium" :class="c.consumptionKwh100 ? 'text-strong' : 'text-muted'">
|
||||
{{ formatConsumptionKwh(c.consumptionKwh100) }}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-body">
|
||||
{{ c.location || t("common.empty") }}
|
||||
<div v-if="c.notes" class="text-xs text-muted">{{ c.notes }}</div>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-4 py-3">
|
||||
<button v-if="c.hasFile" class="text-xs font-medium text-brandtext hover:underline" @click="downloadAttachment('charging', c)">
|
||||
{{ t("common.download") }}
|
||||
</button>
|
||||
<span v-else class="text-xs text-muted">{{ t("common.empty") }}</span>
|
||||
</td>
|
||||
<td v-if="canWrite" class="whitespace-nowrap px-4 py-3 text-right">
|
||||
<button class="text-xs font-medium text-brandtext hover:underline" @click="openEditCharging(c)">{{ t("common.edit") }}</button>
|
||||
<button class="ml-3 text-xs font-medium text-danger hover:underline" @click="deleteCharging(c.id)">{{ t("common.delete") }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Documents -->
|
||||
<section v-else-if="activeTab === 'documents'">
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
@@ -1250,6 +1412,13 @@ onMounted(load);
|
||||
@saved="onFuelSaved"
|
||||
@close="showFuel = false"
|
||||
/>
|
||||
<ChargingFormModal
|
||||
v-if="showCharging"
|
||||
:car-id="id"
|
||||
:entry="editingCharging"
|
||||
@saved="onChargingSaved"
|
||||
@close="showCharging = false"
|
||||
/>
|
||||
<MaintenanceFormModal
|
||||
v-if="showMaintenance"
|
||||
:car-id="id"
|
||||
@@ -1334,6 +1503,7 @@ onMounted(load);
|
||||
services: t("car.delete.services", { n: services.length }),
|
||||
maintenance: t("car.delete.maintenance", { n: maintenance.length }),
|
||||
fuel: t("car.delete.fuel", { n: fuel.length }),
|
||||
charging: t("car.delete.charging", { n: charging.length }),
|
||||
documents: t("car.delete.documents", { n: documents.length }),
|
||||
parts: t("car.delete.parts", { n: parts.length }),
|
||||
}) }}
|
||||
|
||||
Reference in new issue
Block a user