@mxpicture/tesla-superchargers-http 0.1.42 → 0.1.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ui.d.ts CHANGED
@@ -13,5 +13,5 @@
13
13
  * The inner <script> deliberately avoids template literals so it can live inside
14
14
  * this outer template string without escaping.
15
15
  */
16
- export declare const UI_HTML = "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<title>Tesla Superchargers</title>\n<style>\n :root {\n --bg: #f6f7f9; --card: #ffffff; --ink: #1a1d21; --muted: #6b7280;\n --line: #e4e7eb; --accent: #2563eb; --action: #b45309; --ok: #047857;\n --err: #b91c1c; --code-bg: #0f172a; --code-ink: #e2e8f0;\n }\n @media (prefers-color-scheme: dark) {\n :root {\n --bg: #0f1216; --card: #171b21; --ink: #e6e8eb; --muted: #9aa4b2;\n --line: #262b33; --accent: #60a5fa; --action: #f59e0b; --ok: #34d399;\n --err: #f87171; --code-bg: #0b0f16; --code-ink: #dbe2ea;\n }\n }\n * { box-sizing: border-box; }\n body {\n margin: 0; background: var(--bg); color: var(--ink);\n font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;\n }\n header {\n padding: 20px 24px; border-bottom: 1px solid var(--line);\n display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;\n }\n header h1 { margin: 0; font-size: 18px; font-weight: 650; }\n header p { margin: 0; color: var(--muted); font-size: 13px; }\n main {\n max-width: 1100px; margin: 0 auto; padding: 24px;\n display: grid; gap: 16px;\n grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));\n }\n .card {\n background: var(--card); border: 1px solid var(--line); border-radius: 10px;\n padding: 16px; display: flex; flex-direction: column; gap: 10px;\n }\n .card .title { display: flex; align-items: center; gap: 8px; }\n .card h2 { margin: 0; font-size: 15px; font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }\n .badge {\n font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 2px 6px;\n border-radius: 5px; color: #fff;\n }\n .badge.get { background: var(--accent); }\n .badge.post { background: var(--action); }\n .desc { margin: 0; color: var(--muted); font-size: 13px; }\n .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }\n .field { display: flex; flex-direction: column; gap: 3px; }\n .field.wide { grid-column: 1 / -1; }\n .field label { font-size: 12px; color: var(--muted); }\n .field input, .field select {\n padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;\n background: var(--bg); color: var(--ink); font-size: 14px; width: 100%;\n }\n .row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }\n button {\n align-self: flex-start; padding: 7px 14px; border: 0; border-radius: 7px;\n background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;\n cursor: pointer;\n }\n .card.action button { background: var(--action); }\n button:disabled { opacity: .55; cursor: default; }\n pre.result {\n margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--code-bg);\n color: var(--code-ink); font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;\n max-height: 340px; overflow: auto; white-space: pre-wrap; word-break: break-word;\n border-left: 3px solid var(--line);\n }\n pre.result.ok { border-left-color: var(--ok); }\n pre.result.err { border-left-color: var(--err); }\n pre.result.running { border-left-color: var(--accent); color: var(--muted); }\n #favourites { max-width: 1100px; margin: 0 auto; padding: 24px 24px 0; }\n #favourites h2 { margin: 0; font-size: 15px; font-weight: 600; }\n .fav-wrap { overflow-x: auto; }\n table.fav { width: 100%; border-collapse: collapse; font-size: 13px; }\n table.fav th, table.fav td {\n text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line);\n white-space: nowrap;\n }\n table.fav th { color: var(--muted); font-weight: 600; font-size: 12px; }\n table.fav td.num { text-align: right; font-variant-numeric: tabular-nums; }\n table.fav td.msg { color: var(--muted); }\n button.star {\n padding: 0 4px; background: none; color: var(--muted);\n font-size: 18px; line-height: 1;\n }\n button.star.on { color: var(--accent); }\n .fav-controls { display: flex; gap: 8px; }\n .fav-controls input {\n padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;\n background: var(--bg); color: var(--ink); font-size: 14px; width: 100%; max-width: 260px;\n }\n table.fav th.sortable { cursor: pointer; user-select: none; }\n table.fav th.sortable::after { content: \" \u2195\"; opacity: .35; }\n table.fav th.sortable.asc::after { content: \" \u2191\"; opacity: 1; }\n table.fav th.sortable.desc::after { content: \" \u2193\"; opacity: 1; }\n .fav-pager { display: flex; align-items: center; gap: 10px; }\n .fav-pager button { align-self: center; padding: 5px 12px; font-size: 13px; }\n .fav-pager span { color: var(--muted); font-size: 13px; }\n</style>\n</head>\n<body>\n<header>\n <h1>Tesla Superchargers</h1>\n <p>Run a command against the price-history database. Actions are highlighted and ask to confirm.</p>\n</header>\n<section id=\"favourites\">\n <div class=\"card\">\n <div class=\"title\"><h2>Favourites</h2></div>\n <p class=\"desc\">Charger favourites. Click a star to toggle; the change persists immediately.</p>\n <div class=\"fav-controls\">\n <input id=\"fav-filter\" type=\"text\" placeholder=\"Filter name or site\u2026\" />\n </div>\n <div class=\"fav-wrap\">\n <table class=\"fav\">\n <thead>\n <tr>\n <th>\u2605</th>\n <th class=\"sortable\" data-key=\"name\">Name</th>\n <th class=\"sortable\" data-key=\"common_site_name\">Site</th>\n <th class=\"num sortable\" data-key=\"public_stall_count\">Stalls</th>\n <th class=\"num sortable\" data-key=\"failure_count\">Failures</th>\n <th class=\"num\">Lat / Lon</th>\n </tr>\n </thead>\n <tbody id=\"fav-body\"></tbody>\n </table>\n </div>\n <div class=\"fav-pager\">\n <button id=\"fav-prev\" type=\"button\">Prev</button>\n <span id=\"fav-pageinfo\"></span>\n <button id=\"fav-next\" type=\"button\">Next</button>\n </div>\n <pre id=\"fav-status\" class=\"result\" hidden></pre>\n </div>\n</section>\n<main id=\"commands\"></main>\n<script>\n(function () {\n var F = {\n lat: { name: \"lat\", label: \"Latitude\", type: \"text\", placeholder: \"49.3135644\", required: true },\n lon: { name: \"lon\", label: \"Longitude\", type: \"text\", placeholder: \"12.1445587\", required: true },\n radiusKm: { name: \"radiusKm\", label: \"Radius (km)\", type: \"number\", placeholder: \"default\" },\n locale: { name: \"locale\", label: \"Locale\", type: \"text\", placeholder: \"de-DE\" },\n maxFetches: { name: \"maxFetches\", label: \"Max fetches\", type: \"number\", placeholder: \"default\" },\n at: { name: \"at\", label: \"At (local)\", type: \"datetime-local\", wide: true },\n source: { name: \"source\", label: \"Source\", type: \"select\", options: [\"all\", \"charges\", \"chargers\", \"slugs\"] },\n sourceCon: { name: \"source\", label: \"Source\", type: \"select\", options: [\"charges\", \"chargers\", \"slugs\", \"all\"] },\n threshold: { name: \"threshold\", label: \"Threshold\", type: \"number\", placeholder: \"default\" },\n id: { name: \"id\", label: \"Id\", type: \"text\", placeholder: \"reset all if empty\", wide: true },\n latOpt: { name: \"lat\", label: \"Latitude\", type: \"text\", placeholder: \"49.3135644\" },\n lonOpt: { name: \"lon\", label: \"Longitude\", type: \"text\", placeholder: \"12.1445587\" },\n slug: { name: \"slug\", label: \"Slug\", type: \"text\", placeholder: \"location_url_slug\", wide: true },\n chargerId: { name: \"id\", label: \"Charger id\", type: \"text\", placeholder: \"pic_chargers id\" }\n };\n\n var COMMANDS = [\n { name: \"query-slugs\", method: \"GET\", kind: \"read\", fields: [F.lat, F.lon, F.radiusKm],\n desc: \"Nearest location slugs (tesla_uuid) to a coordinate.\" },\n { name: \"query-chargers\", method: \"GET\", kind: \"read\", fields: [F.lat, F.lon, F.radiusKm],\n desc: \"Chargers already stored near a coordinate. Never fetches tesla.com \u2014 fast.\" },\n { name: \"fetch-charger\", method: \"GET\", kind: \"read\", fields: [F.latOpt, F.lonOpt, F.slug, F.radiusKm, F.locale],\n desc: \"One charger by slug, or the nearest to a coordinate. May fetch tesla.com on demand.\" },\n { name: \"fetch-chargers\", method: \"GET\", kind: \"read\", fields: [F.lat, F.lon, F.locale, F.radiusKm, F.maxFetches],\n desc: \"Nearest chargers to a coordinate. May fetch tesla.com on demand \u2014 can be slow.\" },\n { name: \"fetch-prices\", method: \"GET\", kind: \"read\", fields: [F.latOpt, F.lonOpt, F.slug, F.chargerId, F.at, F.radiusKm],\n desc: \"Supercharger prices valid at a time (default now), by coordinate, slug or charger id.\" },\n { name: \"query-unpriced-charges\", method: \"GET\", kind: \"read\", fields: [],\n desc: \"TeslaMate Supercharger charges with no cost yet.\" },\n { name: \"query-failures\", method: \"GET\", kind: \"read\", fields: [F.source, F.threshold],\n desc: \"Rows with repeated failures at or above the threshold.\" },\n { name: \"query-unmatched-invoices\", method: \"GET\", kind: \"read\", fields: [],\n desc: \"Supercharger charges without a matched invoice.\" },\n { name: \"sync-invoices-dropbox\", method: \"POST\", kind: \"action\", fields: [],\n desc: \"Import Tesla charging-history CSV exports from Dropbox.\" },\n { name: \"run-unpriced-charges\", method: \"POST\", kind: \"action\", fields: [],\n desc: \"Backfill cost on unpriced charges from stored Supercharger prices.\" },\n { name: \"sync-slugs\", method: \"POST\", kind: \"action\", fields: [],\n desc: \"Snapshot-sync pic_slugs against the live Tesla map feed.\" },\n { name: \"fetch-fav-chargers\", method: \"POST\", kind: \"action\", fields: [F.locale],\n desc: \"Refresh the favourite chargers whose cached row went stale.\" },\n { name: \"reset-failures\", method: \"POST\", kind: \"action\", fields: [F.sourceCon, F.id],\n desc: \"Clear failure state. Leave id empty to reset ALL rows of the source.\",\n buildBody: function (v) { return v.id ? { source: v.source, id: v.id } : { source: v.source, all: true }; } },\n { name: \"notify-failures\", method: \"POST\", kind: \"action\", fields: [F.threshold],\n desc: \"Send a Pushover alert for not-yet-notified failures.\" },\n { name: \"notify-unmatched-invoices\", method: \"POST\", kind: \"action\", fields: [],\n desc: \"Send a Pushover alert for Supercharger charges without a matched invoice.\" }\n ];\n\n function el(tag, attrs, text) {\n var e = document.createElement(tag);\n if (attrs) for (var k in attrs) e.setAttribute(k, attrs[k]);\n if (text != null) e.textContent = text;\n return e;\n }\n\n function fieldNode(f) {\n var wrap = el(\"div\", { class: \"field\" + (f.wide ? \" wide\" : \"\") });\n wrap.appendChild(el(\"label\", null, f.label));\n var input;\n if (f.type === \"select\") {\n input = el(\"select\", { name: f.name });\n f.options.forEach(function (o) { input.appendChild(el(\"option\", { value: o }, o)); });\n } else {\n input = el(\"input\", { name: f.name, type: f.type });\n if (f.placeholder) input.setAttribute(\"placeholder\", f.placeholder);\n }\n wrap.appendChild(input);\n return wrap;\n }\n\n function collect(cmd, form) {\n var values = {};\n cmd.fields.forEach(function (f) {\n var input = form.elements[f.name];\n var val = input ? String(input.value).trim() : \"\";\n if (f.type === \"datetime-local\" && val) val = new Date(val).toISOString();\n if (val !== \"\") values[f.name] = val;\n });\n return values;\n }\n\n function show(out, cls, text) {\n out.hidden = false;\n out.className = \"result \" + cls;\n out.textContent = text;\n }\n\n function pretty(text) {\n try { return JSON.stringify(JSON.parse(text), null, 2); } catch (e) { return text; }\n }\n\n function run(cmd, form, out, btn) {\n var values = collect(cmd, form);\n for (var i = 0; i < cmd.fields.length; i++) {\n var f = cmd.fields[i];\n if (f.required && !values[f.name]) { show(out, \"err\", \"Please fill in \" + f.label + \".\"); return; }\n }\n\n var url = \"/\" + cmd.name;\n var opts = { method: cmd.method, headers: {} };\n if (cmd.method === \"GET\") {\n var qs = new URLSearchParams(values).toString();\n if (qs) url += \"?\" + qs;\n } else {\n if (!window.confirm(\"Run \" + cmd.name + \"? This performs a real action.\")) return;\n var body = cmd.buildBody ? cmd.buildBody(values) : values;\n opts.headers[\"content-type\"] = \"application/json\";\n opts.body = JSON.stringify(body);\n }\n\n btn.disabled = true;\n show(out, \"running\", \"Running\u2026\");\n fetch(url, opts).then(function (res) {\n return res.text().then(function (text) {\n if (res.ok) show(out, \"ok\", pretty(text));\n else if (res.status === 401) show(out, \"err\", \"401 Unauthorized \u2014 sign in via the SSO portal (running locally, the command endpoints need the bearer token).\");\n else show(out, \"err\", res.status + \" \u2014 \" + pretty(text));\n });\n }).catch(function (e) {\n show(out, \"err\", \"Request failed: \" + (e && e.message ? e.message : e));\n }).then(function () { btn.disabled = false; });\n }\n\n function card(cmd) {\n var form = el(\"form\", { class: \"card \" + cmd.kind });\n var title = el(\"div\", { class: \"title\" });\n title.appendChild(el(\"span\", { class: \"badge \" + (cmd.method === \"GET\" ? \"get\" : \"post\") }, cmd.method));\n title.appendChild(el(\"h2\", null, cmd.name));\n form.appendChild(title);\n form.appendChild(el(\"p\", { class: \"desc\" }, cmd.desc));\n\n if (cmd.fields.length) {\n var fields = el(\"div\", { class: \"fields\" });\n cmd.fields.forEach(function (f) { fields.appendChild(fieldNode(f)); });\n form.appendChild(fields);\n }\n\n var btn = el(\"button\", { type: \"submit\" }, cmd.kind === \"action\" ? \"Run action\" : \"Run\");\n form.appendChild(btn);\n var out = el(\"pre\", { class: \"result\", hidden: \"hidden\" });\n form.appendChild(out);\n\n form.addEventListener(\"submit\", function (e) { e.preventDefault(); run(cmd, form, out, btn); });\n return form;\n }\n\n var favBody = document.getElementById(\"fav-body\");\n var favStatus = document.getElementById(\"fav-status\");\n var favFilterInput = document.getElementById(\"fav-filter\");\n var favPrev = document.getElementById(\"fav-prev\");\n var favNext = document.getElementById(\"fav-next\");\n var favPageInfo = document.getElementById(\"fav-pageinfo\");\n var favSortables = document.querySelectorAll(\"#favourites th.sortable\");\n\n var FAV_PAGE_SIZE = 10;\n var favRows = []; // full dataset from the server\n var favFilter = \"\"; // lower-cased name/site filter\n var favSort = { key: \"\", dir: 1 }; // dir: 1 asc, -1 desc\n var favPage = 0; // zero-based page index\n\n function favMessage(text) {\n favBody.innerHTML = \"\";\n var tr = el(\"tr\");\n tr.appendChild(el(\"td\", { colspan: \"6\", class: \"msg\" }, text));\n favBody.appendChild(tr);\n }\n\n function setStar(btn, on) {\n btn.textContent = on ? \"\u2605\" : \"\u2606\";\n btn.className = \"star\" + (on ? \" on\" : \"\");\n }\n\n function toggleFav(row, btn) {\n var next = !row.favourite;\n btn.disabled = true;\n setStar(btn, next); // optimistic\n fetch(\"/update-fav-charger\", {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ id: String(row.id), favourite: next }),\n }).then(function (res) {\n return res.text().then(function (text) {\n if (res.ok) {\n row.favourite = JSON.parse(text).favourite;\n setStar(btn, row.favourite);\n favStatus.hidden = true;\n } else {\n setStar(btn, row.favourite); // revert\n if (res.status === 401) show(favStatus, \"err\", \"401 Unauthorized \u2014 sign in via the SSO portal (running locally, the command endpoints need the bearer token).\");\n else show(favStatus, \"err\", res.status + \" \u2014 \" + pretty(text));\n }\n });\n }).catch(function (e) {\n setStar(btn, row.favourite); // revert\n show(favStatus, \"err\", \"Request failed: \" + (e && e.message ? e.message : e));\n }).then(function () { btn.disabled = false; });\n }\n\n function starButton(row) {\n var btn = el(\"button\", { type: \"button\", class: \"star\" + (row.favourite ? \" on\" : \"\"), title: \"Toggle favourite\" }, row.favourite ? \"\u2605\" : \"\u2606\");\n btn.addEventListener(\"click\", function () { toggleFav(row, btn); });\n return btn;\n }\n\n function coord(n) {\n return typeof n === \"number\" ? n.toFixed(4) : \"\u2014\";\n }\n\n function favCmp(a, b) {\n if (a == null && b == null) return 0;\n if (a == null) return -1;\n if (b == null) return 1;\n if (typeof a === \"number\" && typeof b === \"number\") return a - b;\n return String(a).localeCompare(String(b));\n }\n\n function favRowNode(row) {\n var tr = el(\"tr\");\n var star = el(\"td\");\n star.appendChild(starButton(row));\n tr.appendChild(star);\n tr.appendChild(el(\"td\", null, row.name));\n tr.appendChild(el(\"td\", null, row.common_site_name));\n tr.appendChild(el(\"td\", { class: \"num\" }, String(row.public_stall_count)));\n tr.appendChild(el(\"td\", { class: \"num\" }, String(row.failure_count)));\n tr.appendChild(el(\"td\", { class: \"num\" }, coord(row.latitude) + \" / \" + coord(row.longitude)));\n return tr;\n }\n\n // filter -> sort against the full dataset, returning the rows to page through.\n function favView() {\n var rows = favRows;\n if (favFilter) {\n rows = rows.filter(function (r) {\n return String(r.name || \"\").toLowerCase().indexOf(favFilter) >= 0 ||\n String(r.common_site_name || \"\").toLowerCase().indexOf(favFilter) >= 0;\n });\n }\n if (favSort.key) {\n var k = favSort.key, dir = favSort.dir;\n rows = rows.slice().sort(function (a, b) { return favCmp(a[k], b[k]) * dir; });\n }\n return rows;\n }\n\n function updateFavPager(total, pages) {\n favPrev.disabled = favPage <= 0;\n favNext.disabled = favPage >= pages - 1;\n if (!total) { favPageInfo.textContent = \"0 of 0\"; return; }\n var from = favPage * FAV_PAGE_SIZE + 1;\n var to = Math.min(total, (favPage + 1) * FAV_PAGE_SIZE);\n favPageInfo.textContent = from + \"\u2013\" + to + \" of \" + total;\n }\n\n function updateFavSortIndicators() {\n Array.prototype.forEach.call(favSortables, function (th) {\n th.classList.remove(\"asc\", \"desc\");\n if (th.getAttribute(\"data-key\") === favSort.key) {\n th.classList.add(favSort.dir > 0 ? \"asc\" : \"desc\");\n }\n });\n }\n\n function renderFav() {\n var rows = favView();\n var pages = Math.max(1, Math.ceil(rows.length / FAV_PAGE_SIZE));\n if (favPage > pages - 1) favPage = pages - 1;\n if (favPage < 0) favPage = 0;\n\n favBody.innerHTML = \"\";\n if (!favRows.length) favMessage(\"No favourites yet.\");\n else if (!rows.length) favMessage(\"No matches.\");\n else {\n var start = favPage * FAV_PAGE_SIZE;\n rows.slice(start, start + FAV_PAGE_SIZE).forEach(function (row) {\n favBody.appendChild(favRowNode(row));\n });\n }\n updateFavPager(rows.length, pages);\n updateFavSortIndicators();\n }\n\n function loadFavourites() {\n show(favStatus, \"running\", \"Loading favourites\u2026\");\n fetch(\"/query-fav-chargers\").then(function (res) {\n return res.text().then(function (text) {\n if (res.ok) { favRows = JSON.parse(text); favPage = 0; renderFav(); favStatus.hidden = true; }\n else if (res.status === 401) show(favStatus, \"err\", \"401 Unauthorized \u2014 sign in via the SSO portal (running locally, the command endpoints need the bearer token).\");\n else show(favStatus, \"err\", res.status + \" \u2014 \" + pretty(text));\n });\n }).catch(function (e) {\n show(favStatus, \"err\", \"Request failed: \" + (e && e.message ? e.message : e));\n });\n }\n\n favFilterInput.addEventListener(\"input\", function () {\n favFilter = favFilterInput.value.trim().toLowerCase();\n favPage = 0;\n renderFav();\n });\n favPrev.addEventListener(\"click\", function () { favPage -= 1; renderFav(); });\n favNext.addEventListener(\"click\", function () { favPage += 1; renderFav(); });\n Array.prototype.forEach.call(favSortables, function (th) {\n th.addEventListener(\"click\", function () {\n var key = th.getAttribute(\"data-key\");\n if (favSort.key === key) favSort.dir = -favSort.dir;\n else { favSort.key = key; favSort.dir = 1; }\n favPage = 0;\n renderFav();\n });\n });\n\n var root = document.getElementById(\"commands\");\n COMMANDS.forEach(function (cmd) { root.appendChild(card(cmd)); });\n loadFavourites();\n})();\n</script>\n</body>\n</html>\n";
16
+ export declare const UI_HTML = "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<title>Tesla Superchargers</title>\n<style>\n :root {\n --bg: #f6f7f9; --card: #ffffff; --ink: #1a1d21; --muted: #6b7280;\n --line: #e4e7eb; --accent: #2563eb; --action: #b45309; --ok: #047857;\n --err: #b91c1c; --code-bg: #0f172a; --code-ink: #e2e8f0;\n }\n @media (prefers-color-scheme: dark) {\n :root {\n --bg: #0f1216; --card: #171b21; --ink: #e6e8eb; --muted: #9aa4b2;\n --line: #262b33; --accent: #60a5fa; --action: #f59e0b; --ok: #34d399;\n --err: #f87171; --code-bg: #0b0f16; --code-ink: #dbe2ea;\n }\n }\n * { box-sizing: border-box; }\n body {\n margin: 0; background: var(--bg); color: var(--ink);\n font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;\n }\n header {\n padding: 20px 24px; border-bottom: 1px solid var(--line);\n display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;\n }\n header h1 { margin: 0; font-size: 18px; font-weight: 650; }\n header p { margin: 0; color: var(--muted); font-size: 13px; }\n main {\n max-width: 1100px; margin: 0 auto; padding: 24px;\n display: grid; gap: 16px;\n grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));\n }\n .card {\n background: var(--card); border: 1px solid var(--line); border-radius: 10px;\n padding: 16px; display: flex; flex-direction: column; gap: 10px;\n }\n .card .title { display: flex; align-items: center; gap: 8px; }\n .card h2 { margin: 0; font-size: 15px; font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }\n .badge {\n font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 2px 6px;\n border-radius: 5px; color: #fff;\n }\n .badge.get { background: var(--accent); }\n .badge.post { background: var(--action); }\n .desc { margin: 0; color: var(--muted); font-size: 13px; }\n .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }\n .field { display: flex; flex-direction: column; gap: 3px; }\n .field.wide { grid-column: 1 / -1; }\n .field label { font-size: 12px; color: var(--muted); }\n .field input, .field select {\n padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;\n background: var(--bg); color: var(--ink); font-size: 14px; width: 100%;\n }\n .row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }\n button {\n align-self: flex-start; padding: 7px 14px; border: 0; border-radius: 7px;\n background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;\n cursor: pointer;\n }\n .card.action button { background: var(--action); }\n button:disabled { opacity: .55; cursor: default; }\n pre.result {\n margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--code-bg);\n color: var(--code-ink); font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;\n max-height: 340px; overflow: auto; white-space: pre-wrap; word-break: break-word;\n border-left: 3px solid var(--line);\n }\n pre.result.ok { border-left-color: var(--ok); }\n pre.result.err { border-left-color: var(--err); }\n pre.result.running { border-left-color: var(--accent); color: var(--muted); }\n #favourites { max-width: 1100px; margin: 0 auto; padding: 24px 24px 0; }\n #favourites h2 { margin: 0; font-size: 15px; font-weight: 600; }\n .fav-wrap { overflow-x: auto; }\n table.fav { width: 100%; border-collapse: collapse; font-size: 13px; }\n table.fav th, table.fav td {\n text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line);\n white-space: nowrap;\n }\n table.fav th { color: var(--muted); font-weight: 600; font-size: 12px; }\n table.fav td.num { text-align: right; font-variant-numeric: tabular-nums; }\n table.fav td.msg { color: var(--muted); }\n button.star {\n padding: 0 4px; background: none; color: var(--muted);\n font-size: 18px; line-height: 1;\n }\n button.star.on { color: var(--accent); }\n .fav-controls { display: flex; gap: 8px; }\n .fav-controls input {\n padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;\n background: var(--bg); color: var(--ink); font-size: 14px; width: 100%; max-width: 260px;\n }\n table.fav th.sortable { cursor: pointer; user-select: none; }\n table.fav th.sortable::after { content: \" \u2195\"; opacity: .35; }\n table.fav th.sortable.asc::after { content: \" \u2191\"; opacity: 1; }\n table.fav th.sortable.desc::after { content: \" \u2193\"; opacity: 1; }\n .fav-pager { display: flex; align-items: center; gap: 10px; }\n .fav-pager button { align-self: center; padding: 5px 12px; font-size: 13px; }\n .fav-pager span { color: var(--muted); font-size: 13px; }\n</style>\n</head>\n<body>\n<header>\n <h1>Tesla Superchargers</h1>\n <p>Run a command against the price-history database. Actions are highlighted and ask to confirm.</p>\n</header>\n<section id=\"favourites\">\n <div class=\"card\">\n <div class=\"title\"><h2>Favourites</h2></div>\n <p class=\"desc\">Charger favourites. Click a star to toggle; the change persists immediately.</p>\n <div class=\"fav-controls\">\n <input id=\"fav-filter\" type=\"text\" placeholder=\"Filter name or site\u2026\" />\n </div>\n <div class=\"fav-wrap\">\n <table class=\"fav\">\n <thead>\n <tr>\n <th class=\"sortable\" data-key=\"favourite\">\u2605</th>\n <th class=\"sortable\" data-key=\"name\">Name</th>\n <th class=\"sortable\" data-key=\"common_site_name\">Site</th>\n <th class=\"num sortable\" data-key=\"public_stall_count\">Stalls</th>\n <th class=\"num sortable\" data-key=\"failure_count\">Failures</th>\n <th class=\"num\">Lat / Lon</th>\n </tr>\n </thead>\n <tbody id=\"fav-body\"></tbody>\n </table>\n </div>\n <div class=\"fav-pager\">\n <button id=\"fav-prev\" type=\"button\">Prev</button>\n <span id=\"fav-pageinfo\"></span>\n <button id=\"fav-next\" type=\"button\">Next</button>\n </div>\n <pre id=\"fav-status\" class=\"result\" hidden></pre>\n </div>\n</section>\n<main id=\"commands\"></main>\n<script>\n(function () {\n // \"value\" pre-fills the field with the default the endpoint would apply\n // anyway; \"placeholder\" is only a hint for fields that have no fixed default.\n var F = {\n lat: { name: \"lat\", label: \"Latitude\", type: \"text\", value: \"49.3135644\", required: true },\n lon: { name: \"lon\", label: \"Longitude\", type: \"text\", value: \"12.1445587\", required: true },\n radiusKm: { name: \"radiusKm\", label: \"Radius (km)\", type: \"number\", value: \"0.2625\" },\n locale: { name: \"locale\", label: \"Locale\", type: \"text\", value: \"de-DE\" },\n maxFetches: { name: \"maxFetches\", label: \"Max fetches\", type: \"number\", value: \"3\" },\n at: { name: \"at\", label: \"At (local)\", type: \"datetime-local\", wide: true },\n source: { name: \"source\", label: \"Source\", type: \"select\", options: [\"all\", \"charges\", \"chargers\", \"slugs\"] },\n sourceCon: { name: \"source\", label: \"Source\", type: \"select\", options: [\"charges\", \"chargers\", \"slugs\", \"all\"] },\n threshold: { name: \"threshold\", label: \"Threshold\", type: \"number\", value: \"3\" },\n id: { name: \"id\", label: \"Id\", type: \"text\", placeholder: \"reset all if empty\", wide: true },\n latOpt: { name: \"lat\", label: \"Latitude\", type: \"text\", placeholder: \"49.3135644\" },\n lonOpt: { name: \"lon\", label: \"Longitude\", type: \"text\", placeholder: \"12.1445587\" },\n slug: { name: \"slug\", label: \"Slug\", type: \"text\", placeholder: \"location_url_slug\", wide: true },\n chargerId: { name: \"id\", label: \"Charger id\", type: \"text\", placeholder: \"pic_chargers id\" }\n };\n\n var COMMANDS = [\n { name: \"query-slugs\", method: \"GET\", kind: \"read\", fields: [F.lat, F.lon, F.radiusKm],\n desc: \"Nearest location slugs (tesla_uuid) to a coordinate.\" },\n { name: \"query-chargers\", method: \"GET\", kind: \"read\", fields: [F.lat, F.lon, F.radiusKm],\n desc: \"Chargers already stored near a coordinate. Never fetches tesla.com \u2014 fast.\" },\n { name: \"fetch-charger\", method: \"GET\", kind: \"read\", fields: [F.latOpt, F.lonOpt, F.slug, F.radiusKm, F.locale],\n desc: \"One charger by slug, or the nearest to a coordinate. May fetch tesla.com on demand.\" },\n { name: \"fetch-chargers\", method: \"GET\", kind: \"read\", fields: [F.lat, F.lon, F.locale, F.radiusKm, F.maxFetches],\n desc: \"Nearest chargers to a coordinate. May fetch tesla.com on demand \u2014 can be slow.\" },\n { name: \"fetch-prices\", method: \"GET\", kind: \"read\", fields: [F.latOpt, F.lonOpt, F.slug, F.chargerId, F.at, F.radiusKm],\n desc: \"Supercharger prices valid at a time (default now), by coordinate, slug or charger id.\" },\n { name: \"query-unpriced-charges\", method: \"GET\", kind: \"read\", fields: [],\n desc: \"TeslaMate Supercharger charges with no cost yet.\" },\n { name: \"query-failures\", method: \"GET\", kind: \"read\", fields: [F.source, F.threshold],\n desc: \"Rows with repeated failures at or above the threshold.\" },\n { name: \"query-unmatched-invoices\", method: \"GET\", kind: \"read\", fields: [],\n desc: \"Supercharger charges without a matched invoice.\" },\n { name: \"sync-invoices-dropbox\", method: \"POST\", kind: \"action\", fields: [],\n desc: \"Import Tesla charging-history CSV exports from Dropbox.\" },\n { name: \"run-unpriced-charges\", method: \"POST\", kind: \"action\", fields: [],\n desc: \"Backfill cost on unpriced charges from stored Supercharger prices.\" },\n { name: \"sync-slugs\", method: \"POST\", kind: \"action\", fields: [],\n desc: \"Snapshot-sync pic_slugs against the live Tesla map feed.\" },\n { name: \"fetch-fav-chargers\", method: \"POST\", kind: \"action\", fields: [F.locale],\n desc: \"Refresh the favourite chargers whose cached row went stale.\" },\n { name: \"reset-failures\", method: \"POST\", kind: \"action\", fields: [F.sourceCon, F.id],\n desc: \"Clear failure state. Leave id empty to reset ALL rows of the source.\",\n buildBody: function (v) { return v.id ? { source: v.source, id: v.id } : { source: v.source, all: true }; } },\n { name: \"notify-failures\", method: \"POST\", kind: \"action\", fields: [F.threshold],\n desc: \"Send a Pushover alert for not-yet-notified failures.\" },\n { name: \"notify-unmatched-invoices\", method: \"POST\", kind: \"action\", fields: [],\n desc: \"Send a Pushover alert for Supercharger charges without a matched invoice.\" }\n ];\n\n function el(tag, attrs, text) {\n var e = document.createElement(tag);\n if (attrs) for (var k in attrs) e.setAttribute(k, attrs[k]);\n if (text != null) e.textContent = text;\n return e;\n }\n\n function fieldNode(f) {\n var wrap = el(\"div\", { class: \"field\" + (f.wide ? \" wide\" : \"\") });\n wrap.appendChild(el(\"label\", null, f.label));\n var input;\n if (f.type === \"select\") {\n input = el(\"select\", { name: f.name });\n f.options.forEach(function (o) { input.appendChild(el(\"option\", { value: o }, o)); });\n } else {\n input = el(\"input\", { name: f.name, type: f.type });\n if (f.placeholder) input.setAttribute(\"placeholder\", f.placeholder);\n if (f.value) input.setAttribute(\"value\", f.value);\n }\n wrap.appendChild(input);\n return wrap;\n }\n\n function collect(cmd, form) {\n var values = {};\n cmd.fields.forEach(function (f) {\n var input = form.elements[f.name];\n var val = input ? String(input.value).trim() : \"\";\n if (f.type === \"datetime-local\" && val) val = new Date(val).toISOString();\n if (val !== \"\") values[f.name] = val;\n });\n return values;\n }\n\n function show(out, cls, text) {\n out.hidden = false;\n out.className = \"result \" + cls;\n out.textContent = text;\n }\n\n function pretty(text) {\n try { return JSON.stringify(JSON.parse(text), null, 2); } catch (e) { return text; }\n }\n\n function run(cmd, form, out, btn) {\n var values = collect(cmd, form);\n for (var i = 0; i < cmd.fields.length; i++) {\n var f = cmd.fields[i];\n if (f.required && !values[f.name]) { show(out, \"err\", \"Please fill in \" + f.label + \".\"); return; }\n }\n\n var url = \"/\" + cmd.name;\n var opts = { method: cmd.method, headers: {} };\n if (cmd.method === \"GET\") {\n var qs = new URLSearchParams(values).toString();\n if (qs) url += \"?\" + qs;\n } else {\n if (!window.confirm(\"Run \" + cmd.name + \"? This performs a real action.\")) return;\n var body = cmd.buildBody ? cmd.buildBody(values) : values;\n opts.headers[\"content-type\"] = \"application/json\";\n opts.body = JSON.stringify(body);\n }\n\n btn.disabled = true;\n show(out, \"running\", \"Running\u2026\");\n fetch(url, opts).then(function (res) {\n return res.text().then(function (text) {\n if (res.ok) show(out, \"ok\", pretty(text));\n else if (res.status === 401) show(out, \"err\", \"401 Unauthorized \u2014 sign in via the SSO portal (running locally, the command endpoints need the bearer token).\");\n else show(out, \"err\", res.status + \" \u2014 \" + pretty(text));\n });\n }).catch(function (e) {\n show(out, \"err\", \"Request failed: \" + (e && e.message ? e.message : e));\n }).then(function () { btn.disabled = false; });\n }\n\n function card(cmd) {\n var form = el(\"form\", { class: \"card \" + cmd.kind });\n var title = el(\"div\", { class: \"title\" });\n title.appendChild(el(\"span\", { class: \"badge \" + (cmd.method === \"GET\" ? \"get\" : \"post\") }, cmd.method));\n title.appendChild(el(\"h2\", null, cmd.name));\n form.appendChild(title);\n form.appendChild(el(\"p\", { class: \"desc\" }, cmd.desc));\n\n if (cmd.fields.length) {\n var fields = el(\"div\", { class: \"fields\" });\n cmd.fields.forEach(function (f) { fields.appendChild(fieldNode(f)); });\n form.appendChild(fields);\n }\n\n var btn = el(\"button\", { type: \"submit\" }, cmd.kind === \"action\" ? \"Run action\" : \"Run\");\n form.appendChild(btn);\n var out = el(\"pre\", { class: \"result\", hidden: \"hidden\" });\n form.appendChild(out);\n\n form.addEventListener(\"submit\", function (e) { e.preventDefault(); run(cmd, form, out, btn); });\n return form;\n }\n\n var favBody = document.getElementById(\"fav-body\");\n var favStatus = document.getElementById(\"fav-status\");\n var favFilterInput = document.getElementById(\"fav-filter\");\n var favPrev = document.getElementById(\"fav-prev\");\n var favNext = document.getElementById(\"fav-next\");\n var favPageInfo = document.getElementById(\"fav-pageinfo\");\n var favSortables = document.querySelectorAll(\"#favourites th.sortable\");\n\n var FAV_PAGE_SIZE = 10;\n var favRows = []; // full dataset from the server\n var favFilter = \"\"; // lower-cased name/site filter\n // Favourites first by default; the sort is stable, so within a group the\n // server's own order survives.\n var favSort = { key: \"favourite\", dir: -1 }; // dir: 1 asc, -1 desc\n var favPage = 0; // zero-based page index\n\n function favMessage(text) {\n favBody.innerHTML = \"\";\n var tr = el(\"tr\");\n tr.appendChild(el(\"td\", { colspan: \"6\", class: \"msg\" }, text));\n favBody.appendChild(tr);\n }\n\n function setStar(btn, on) {\n btn.textContent = on ? \"\u2605\" : \"\u2606\";\n btn.className = \"star\" + (on ? \" on\" : \"\");\n }\n\n function toggleFav(row, btn) {\n var next = !row.favourite;\n btn.disabled = true;\n setStar(btn, next); // optimistic\n fetch(\"/update-fav-charger\", {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ id: String(row.id), favourite: next }),\n }).then(function (res) {\n return res.text().then(function (text) {\n if (res.ok) {\n row.favourite = JSON.parse(text).favourite;\n setStar(btn, row.favourite);\n favStatus.hidden = true;\n } else {\n setStar(btn, row.favourite); // revert\n if (res.status === 401) show(favStatus, \"err\", \"401 Unauthorized \u2014 sign in via the SSO portal (running locally, the command endpoints need the bearer token).\");\n else show(favStatus, \"err\", res.status + \" \u2014 \" + pretty(text));\n }\n });\n }).catch(function (e) {\n setStar(btn, row.favourite); // revert\n show(favStatus, \"err\", \"Request failed: \" + (e && e.message ? e.message : e));\n }).then(function () { btn.disabled = false; });\n }\n\n function starButton(row) {\n var btn = el(\"button\", { type: \"button\", class: \"star\" + (row.favourite ? \" on\" : \"\"), title: \"Toggle favourite\" }, row.favourite ? \"\u2605\" : \"\u2606\");\n btn.addEventListener(\"click\", function () { toggleFav(row, btn); });\n return btn;\n }\n\n function coord(n) {\n return typeof n === \"number\" ? n.toFixed(4) : \"\u2014\";\n }\n\n function favCmp(a, b) {\n if (typeof a === \"boolean\") a = a ? 1 : 0;\n if (typeof b === \"boolean\") b = b ? 1 : 0;\n if (a == null && b == null) return 0;\n if (a == null) return -1;\n if (b == null) return 1;\n if (typeof a === \"number\" && typeof b === \"number\") return a - b;\n return String(a).localeCompare(String(b));\n }\n\n function favRowNode(row) {\n var tr = el(\"tr\");\n var star = el(\"td\");\n star.appendChild(starButton(row));\n tr.appendChild(star);\n tr.appendChild(el(\"td\", null, row.name));\n tr.appendChild(el(\"td\", null, row.common_site_name));\n tr.appendChild(el(\"td\", { class: \"num\" }, String(row.public_stall_count)));\n tr.appendChild(el(\"td\", { class: \"num\" }, String(row.failure_count)));\n tr.appendChild(el(\"td\", { class: \"num\" }, coord(row.latitude) + \" / \" + coord(row.longitude)));\n return tr;\n }\n\n // filter -> sort against the full dataset, returning the rows to page through.\n function favView() {\n var rows = favRows;\n if (favFilter) {\n rows = rows.filter(function (r) {\n return String(r.name || \"\").toLowerCase().indexOf(favFilter) >= 0 ||\n String(r.common_site_name || \"\").toLowerCase().indexOf(favFilter) >= 0;\n });\n }\n if (favSort.key) {\n var k = favSort.key, dir = favSort.dir;\n rows = rows.slice().sort(function (a, b) { return favCmp(a[k], b[k]) * dir; });\n }\n return rows;\n }\n\n function updateFavPager(total, pages) {\n favPrev.disabled = favPage <= 0;\n favNext.disabled = favPage >= pages - 1;\n if (!total) { favPageInfo.textContent = \"0 of 0\"; return; }\n var from = favPage * FAV_PAGE_SIZE + 1;\n var to = Math.min(total, (favPage + 1) * FAV_PAGE_SIZE);\n favPageInfo.textContent = from + \"\u2013\" + to + \" of \" + total;\n }\n\n function updateFavSortIndicators() {\n Array.prototype.forEach.call(favSortables, function (th) {\n th.classList.remove(\"asc\", \"desc\");\n if (th.getAttribute(\"data-key\") === favSort.key) {\n th.classList.add(favSort.dir > 0 ? \"asc\" : \"desc\");\n }\n });\n }\n\n function renderFav() {\n var rows = favView();\n var pages = Math.max(1, Math.ceil(rows.length / FAV_PAGE_SIZE));\n if (favPage > pages - 1) favPage = pages - 1;\n if (favPage < 0) favPage = 0;\n\n favBody.innerHTML = \"\";\n if (!favRows.length) favMessage(\"No favourites yet.\");\n else if (!rows.length) favMessage(\"No matches.\");\n else {\n var start = favPage * FAV_PAGE_SIZE;\n rows.slice(start, start + FAV_PAGE_SIZE).forEach(function (row) {\n favBody.appendChild(favRowNode(row));\n });\n }\n updateFavPager(rows.length, pages);\n updateFavSortIndicators();\n }\n\n function loadFavourites() {\n show(favStatus, \"running\", \"Loading favourites\u2026\");\n fetch(\"/query-fav-chargers\").then(function (res) {\n return res.text().then(function (text) {\n if (res.ok) { favRows = JSON.parse(text); favPage = 0; renderFav(); favStatus.hidden = true; }\n else if (res.status === 401) show(favStatus, \"err\", \"401 Unauthorized \u2014 sign in via the SSO portal (running locally, the command endpoints need the bearer token).\");\n else show(favStatus, \"err\", res.status + \" \u2014 \" + pretty(text));\n });\n }).catch(function (e) {\n show(favStatus, \"err\", \"Request failed: \" + (e && e.message ? e.message : e));\n });\n }\n\n favFilterInput.addEventListener(\"input\", function () {\n favFilter = favFilterInput.value.trim().toLowerCase();\n favPage = 0;\n renderFav();\n });\n favPrev.addEventListener(\"click\", function () { favPage -= 1; renderFav(); });\n favNext.addEventListener(\"click\", function () { favPage += 1; renderFav(); });\n Array.prototype.forEach.call(favSortables, function (th) {\n th.addEventListener(\"click\", function () {\n var key = th.getAttribute(\"data-key\");\n if (favSort.key === key) favSort.dir = -favSort.dir;\n else { favSort.key = key; favSort.dir = 1; }\n favPage = 0;\n renderFav();\n });\n });\n\n var root = document.getElementById(\"commands\");\n COMMANDS.forEach(function (cmd) { root.appendChild(card(cmd)); });\n loadFavourites();\n})();\n</script>\n</body>\n</html>\n";
17
17
  //# sourceMappingURL=ui.d.ts.map
package/dist/ui.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,OAAO,msqBA+cnB,CAAC"}
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,OAAO,snrBAsdnB,CAAC"}
package/dist/ui.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { FAILURE_DEPRIORITIZE_THRESHOLD, MAX_CHARGER_FETCHES, } from "@mxpicture/tesla-superchargers-api/common";
2
+ import { COVERED_MARGIN, COVERED_RADIUS_KM, } from "@mxpicture/tesla-superchargers-mate/common";
1
3
  /**
2
4
  * The web UI, served at `GET /` by the server (see `server.ts`). It is one
3
5
  * self-contained HTML document — inline CSS + JS, no build step, no assets — so
@@ -132,7 +134,7 @@ export const UI_HTML = `<!doctype html>
132
134
  <table class="fav">
133
135
  <thead>
134
136
  <tr>
135
- <th>★</th>
137
+ <th class="sortable" data-key="favourite">★</th>
136
138
  <th class="sortable" data-key="name">Name</th>
137
139
  <th class="sortable" data-key="common_site_name">Site</th>
138
140
  <th class="num sortable" data-key="public_stall_count">Stalls</th>
@@ -154,16 +156,18 @@ export const UI_HTML = `<!doctype html>
154
156
  <main id="commands"></main>
155
157
  <script>
156
158
  (function () {
159
+ // "value" pre-fills the field with the default the endpoint would apply
160
+ // anyway; "placeholder" is only a hint for fields that have no fixed default.
157
161
  var F = {
158
- lat: { name: "lat", label: "Latitude", type: "text", placeholder: "49.3135644", required: true },
159
- lon: { name: "lon", label: "Longitude", type: "text", placeholder: "12.1445587", required: true },
160
- radiusKm: { name: "radiusKm", label: "Radius (km)", type: "number", placeholder: "default" },
161
- locale: { name: "locale", label: "Locale", type: "text", placeholder: "de-DE" },
162
- maxFetches: { name: "maxFetches", label: "Max fetches", type: "number", placeholder: "default" },
162
+ lat: { name: "lat", label: "Latitude", type: "text", value: "49.3135644", required: true },
163
+ lon: { name: "lon", label: "Longitude", type: "text", value: "12.1445587", required: true },
164
+ radiusKm: { name: "radiusKm", label: "Radius (km)", type: "number", value: "${COVERED_RADIUS_KM * COVERED_MARGIN}" },
165
+ locale: { name: "locale", label: "Locale", type: "text", value: "de-DE" },
166
+ maxFetches: { name: "maxFetches", label: "Max fetches", type: "number", value: "${MAX_CHARGER_FETCHES}" },
163
167
  at: { name: "at", label: "At (local)", type: "datetime-local", wide: true },
164
168
  source: { name: "source", label: "Source", type: "select", options: ["all", "charges", "chargers", "slugs"] },
165
169
  sourceCon: { name: "source", label: "Source", type: "select", options: ["charges", "chargers", "slugs", "all"] },
166
- threshold: { name: "threshold", label: "Threshold", type: "number", placeholder: "default" },
170
+ threshold: { name: "threshold", label: "Threshold", type: "number", value: "${FAILURE_DEPRIORITIZE_THRESHOLD}" },
167
171
  id: { name: "id", label: "Id", type: "text", placeholder: "reset all if empty", wide: true },
168
172
  latOpt: { name: "lat", label: "Latitude", type: "text", placeholder: "49.3135644" },
169
173
  lonOpt: { name: "lon", label: "Longitude", type: "text", placeholder: "12.1445587" },
@@ -222,6 +226,7 @@ export const UI_HTML = `<!doctype html>
222
226
  } else {
223
227
  input = el("input", { name: f.name, type: f.type });
224
228
  if (f.placeholder) input.setAttribute("placeholder", f.placeholder);
229
+ if (f.value) input.setAttribute("value", f.value);
225
230
  }
226
231
  wrap.appendChild(input);
227
232
  return wrap;
@@ -314,7 +319,9 @@ export const UI_HTML = `<!doctype html>
314
319
  var FAV_PAGE_SIZE = 10;
315
320
  var favRows = []; // full dataset from the server
316
321
  var favFilter = ""; // lower-cased name/site filter
317
- var favSort = { key: "", dir: 1 }; // dir: 1 asc, -1 desc
322
+ // Favourites first by default; the sort is stable, so within a group the
323
+ // server's own order survives.
324
+ var favSort = { key: "favourite", dir: -1 }; // dir: 1 asc, -1 desc
318
325
  var favPage = 0; // zero-based page index
319
326
 
320
327
  function favMessage(text) {
@@ -366,6 +373,8 @@ export const UI_HTML = `<!doctype html>
366
373
  }
367
374
 
368
375
  function favCmp(a, b) {
376
+ if (typeof a === "boolean") a = a ? 1 : 0;
377
+ if (typeof b === "boolean") b = b ? 1 : 0;
369
378
  if (a == null && b == null) return 0;
370
379
  if (a == null) return -1;
371
380
  if (b == null) return 1;
package/dist/ui.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+ctB,CAAC"}
1
+ {"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,mBAAmB,GACpB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,cAAc,EACd,iBAAiB,GAClB,MAAM,4CAA4C,CAAC;AAEpD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+FAkJwE,iBAAiB,GAAG,cAAc;;+FAElC,mBAAmB;;;;+FAInB,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8T5H,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxpicture/tesla-superchargers-http",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "Http server for interacting with superchargers",
5
5
  "type": "module",
6
6
  "author": "MXPicture",
@@ -32,8 +32,8 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
- "@mxpicture/tesla-superchargers-api": "^0.1.42",
36
- "@mxpicture/tesla-superchargers-mate": "^0.1.42"
35
+ "@mxpicture/tesla-superchargers-api": "^0.1.44",
36
+ "@mxpicture/tesla-superchargers-mate": "^0.1.44"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^25.2.3",