Toyota Connected: Toyota, Lexus and Subaru as three plugins
One connector, registered once per brand with the brand fixed, so the
panel, the Web App and the Phone App each list Toyota, Lexus and Subaru
separately: own card, own account, own enable switch, own
/api/integrations/{brand} routes and vehicle provider. The brand picker
is gone.
Settings saved before the split under pluginSettings.toyota with brand
L or S move onto their brand's key on read, and are written back on the
next save. Cars linked as provider "toyota" read through their make's
brand.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9d8636ee73
commit
914aeeee23
21 files changed
+837
-471
No files matched your search
@@ -260,9 +260,13 @@ export const api = {
|
||||
// field, with secrets and inherited usernames masked); saveToyota writes the
|
||||
// caller's editable layer (scope "user" by default, "org" for org admins);
|
||||
// testToyota runs a live login probe under the resolved credentials.
|
||||
getToyota: () => request("/integrations/toyota"),
|
||||
saveToyota: (body) => request("/integrations/toyota", { method: "PUT", body: JSON.stringify(body) }),
|
||||
testToyota: () => request("/integrations/toyota/health", { method: "POST" }),
|
||||
//
|
||||
// brand is "toyota", "lexus" or "subaru": one connector on the server, but
|
||||
// three integrations with their own accounts (see TOYOTA_BRANDS).
|
||||
getToyota: (brand = "toyota") => request(`/integrations/${brand}`),
|
||||
saveToyota: (body, brand = "toyota") =>
|
||||
request(`/integrations/${brand}`, { method: "PUT", body: JSON.stringify(body) }),
|
||||
testToyota: (brand = "toyota") => request(`/integrations/${brand}/health`, { method: "POST" }),
|
||||
|
||||
// Vehicle providers — manufacturer services a car can be created from, and the
|
||||
// data feed behind a car's provider tab. Every call runs server-side under the
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
<script setup>
|
||||
// One brand of the Toyota Connected Europe connector — Toyota, Lexus or Subaru —
|
||||
// as its own integration card. The server runs a single connector for the three
|
||||
// (they share a backend and differ only in the login), but each brand is a plugin
|
||||
// of its own to the user: its own account, its own enable switch, its own card.
|
||||
//
|
||||
// The server resolves a superadmin → org admin → user cascade and returns, per
|
||||
// field, the effective value (secrets/inherited usernames masked), the caller's
|
||||
// own-layer value, its source layer, and whether it's locked (set above us).
|
||||
// An org admin gets a second "org" scope to edit organization-wide defaults.
|
||||
//
|
||||
// Settings loads the view (so it knows which cards to list) and hands it in;
|
||||
// every save comes back out through update:view.
|
||||
import { ref, computed, watch } from "vue";
|
||||
import { api } from "../api";
|
||||
import { t } from "../i18n";
|
||||
|
||||
const props = defineProps({
|
||||
brand: { type: String, required: true }, // "toyota" | "lexus" | "subaru"
|
||||
view: { type: Object, required: true }, // resolved view from the server
|
||||
});
|
||||
const emit = defineEmits(["update:view"]);
|
||||
|
||||
// Collapsed by default, so the Integrations tab reads as a compact list.
|
||||
const open = ref(false);
|
||||
const scope = ref("user"); // "user" | "org" (org admins only)
|
||||
const form = ref({ username: "", password: "" });
|
||||
const saving = ref(false);
|
||||
const saved = ref(false);
|
||||
const error = ref("");
|
||||
const testing = ref(false);
|
||||
const health = ref(null); // { status, detail } from the last test
|
||||
|
||||
// The app the owner knows the account by ("MyToyota", "Lexus Link+"); the
|
||||
// server names it, so a new brand needs no change here.
|
||||
const app = computed(() => props.view.app || "MyToyota");
|
||||
|
||||
// Superadmins manage the shared (global) layer in the API Server panel; here the
|
||||
// credential fields are read-only (they may still toggle their own opt-in).
|
||||
const readOnly = computed(() => !!props.view.isSuperadmin);
|
||||
const scopeKey = computed(() => (props.view.isSuperadmin ? "user" : scope.value));
|
||||
const scopeData = computed(
|
||||
() => props.view.scopes?.[scopeKey.value] || { editableLayer: "user", fields: {} }
|
||||
);
|
||||
const editingOrg = computed(() => scopeKey.value === "org");
|
||||
|
||||
function field(k) {
|
||||
return scopeData.value.fields?.[k] || { effective: "", own: "", source: "unset", locked: false };
|
||||
}
|
||||
// A field is locked when it's set above the caller's editable layer, or the
|
||||
// whole scope is read-only (superadmin).
|
||||
function locked(k) {
|
||||
return readOnly.value || field(k).locked;
|
||||
}
|
||||
// The toggle reflects the personal opt-in normally, or the org gate in org scope.
|
||||
const enabled = computed(() => (editingOrg.value ? props.view.orgEnabled : props.view.enabled));
|
||||
// A friendly "inherited from …" note for a locked field.
|
||||
function sourceLabel(k) {
|
||||
const map = { global: "sourceGlobal", org: "sourceOrg", user: "sourceUser" };
|
||||
const key = map[field(k).source] || "sourceGlobal";
|
||||
return t("settings.integrations.inheritedFrom", { source: t("settings.integrations." + key) });
|
||||
}
|
||||
|
||||
// Load the editable inputs from the current scope's own-layer values. Locked
|
||||
// fields and the secret password are never prefilled.
|
||||
function fillForm() {
|
||||
const f = scopeData.value.fields || {};
|
||||
form.value = {
|
||||
username: f.username?.locked ? "" : f.username?.own || "",
|
||||
password: "",
|
||||
};
|
||||
}
|
||||
|
||||
function apply(body) {
|
||||
emit("update:view", body);
|
||||
}
|
||||
|
||||
// Keep the selected scope valid (fall back to personal when org isn't offered),
|
||||
// and refill the form whenever a fresh view arrives.
|
||||
watch(
|
||||
() => props.view,
|
||||
(body) => {
|
||||
if (scope.value === "org" && !body.canEditOrg) scope.value = "user";
|
||||
fillForm();
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// Refill the form when an admin flips between personal and organization scope.
|
||||
watch(scope, () => {
|
||||
error.value = "";
|
||||
saved.value = false;
|
||||
health.value = null;
|
||||
fillForm();
|
||||
});
|
||||
|
||||
async function toggle(v) {
|
||||
error.value = "";
|
||||
const org = editingOrg.value;
|
||||
try {
|
||||
apply(await api.saveToyota(org ? { scope: "org", enabled: v } : { scope: "user", enabled: v }, props.brand));
|
||||
} catch (e) {
|
||||
error.value = e.message;
|
||||
}
|
||||
}
|
||||
|
||||
async function save() {
|
||||
error.value = "";
|
||||
saving.value = true;
|
||||
saved.value = false;
|
||||
const config = {};
|
||||
for (const k of ["username", "password"]) {
|
||||
if (locked(k)) continue;
|
||||
// Only send the password when the user actually typed a new one.
|
||||
if (k === "password" && !form.value.password) continue;
|
||||
config[k] = form.value[k];
|
||||
}
|
||||
try {
|
||||
apply(await api.saveToyota({ scope: scopeKey.value, config }, props.brand));
|
||||
saved.value = true;
|
||||
setTimeout(() => (saved.value = false), 2000);
|
||||
} catch (e) {
|
||||
error.value = e.message;
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function test() {
|
||||
error.value = "";
|
||||
health.value = null;
|
||||
testing.value = true;
|
||||
try {
|
||||
health.value = (await api.testToyota(props.brand)).health;
|
||||
} catch (e) {
|
||||
error.value = e.message;
|
||||
} finally {
|
||||
testing.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="rounded-control border border-subtle p-4">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full items-start justify-between gap-3 text-left"
|
||||
:aria-expanded="open"
|
||||
@click="open = !open"
|
||||
>
|
||||
<div>
|
||||
<p class="text-sm font-semibold text-strong">{{ t(`settings.integrations.${brand}`) }}</p>
|
||||
<p class="mt-0.5 text-xs text-muted">{{ t(`settings.integrations.${brand}Desc`) }}</p>
|
||||
</div>
|
||||
<div class="flex shrink-0 items-center gap-2">
|
||||
<span
|
||||
v-if="!editingOrg"
|
||||
class="dh-badge"
|
||||
:class="view.enabled ? 'dh-badge-success' : 'dh-badge-warning'"
|
||||
>
|
||||
{{ view.enabled ? t("settings.integrations.connected") : t("settings.integrations.notConnected") }}
|
||||
</span>
|
||||
<svg
|
||||
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
class="h-4 w-4 text-muted transition-transform" :class="open ? 'rotate-180' : ''"
|
||||
><path stroke-linecap="round" stroke-linejoin="round" d="m6 9 6 6 6-6" /></svg>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<div v-show="open">
|
||||
<!-- Master / org gates -->
|
||||
<p v-if="!view.available" class="mt-3 text-sm text-warning">{{ t("settings.integrations.unavailable") }}</p>
|
||||
<p
|
||||
v-else-if="view.orgId && !view.orgEnabled && !editingOrg"
|
||||
class="mt-3 text-sm text-warning"
|
||||
>
|
||||
{{ t("settings.integrations.orgDisabled") }}
|
||||
</p>
|
||||
|
||||
<template v-else>
|
||||
<!-- Scope switch (org admins) -->
|
||||
<div v-if="view.canEditOrg" class="mt-4 flex gap-2">
|
||||
<button
|
||||
v-for="sc in ['user', 'org']"
|
||||
:key="sc"
|
||||
class="rounded-control border px-3 py-1.5 text-sm font-medium transition-colors"
|
||||
:class="scope === sc
|
||||
? 'border-accent bg-accent text-white'
|
||||
: 'border-subtle text-body hover:bg-sunken hover:text-strong'"
|
||||
@click="scope = sc"
|
||||
>
|
||||
{{ sc === 'org' ? t("settings.integrations.scopeOrg") : t("settings.integrations.scopeMy") }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="editingOrg" class="mt-2 text-xs text-muted">{{ t("settings.integrations.scopeHint") }}</p>
|
||||
<p v-if="readOnly" class="mt-3 text-xs text-muted">{{ t("settings.integrations.readOnly") }}</p>
|
||||
|
||||
<!-- Enable toggle -->
|
||||
<label class="mt-4 flex items-center gap-2 text-sm font-medium text-body">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="h-4 w-4 rounded border-subtle text-accent focus:ring-accent"
|
||||
:checked="enabled"
|
||||
@change="toggle($event.target.checked)"
|
||||
/>
|
||||
<span>{{ editingOrg ? t("settings.integrations.enableOrg") : t("settings.integrations.enable") }}</span>
|
||||
</label>
|
||||
|
||||
<!-- Credential fields -->
|
||||
<div class="mt-4 grid max-w-sm gap-3">
|
||||
<div>
|
||||
<label class="dh-label">{{ t("settings.integrations.email", { app }) }}</label>
|
||||
<input
|
||||
v-model="form.username"
|
||||
class="dh-input"
|
||||
:disabled="locked('username')"
|
||||
:placeholder="locked('username') ? '••••••••' : ''"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<p v-if="field('username').locked" class="mt-1 text-xs text-muted">{{ sourceLabel('username') }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="dh-label">{{ t("settings.integrations.password", { app }) }}</label>
|
||||
<input
|
||||
v-model="form.password"
|
||||
type="password"
|
||||
class="dh-input"
|
||||
:disabled="locked('password')"
|
||||
:placeholder="field('password').effective ? '••••••••' : ''"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
<p v-if="field('password').locked" class="mt-1 text-xs text-muted">{{ sourceLabel('password') }}</p>
|
||||
<p v-else class="mt-1 text-xs text-muted">{{ t("settings.integrations.passwordKeep") }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex items-center gap-2">
|
||||
<button v-if="!readOnly" class="dh-btn dh-btn-primary" :disabled="saving" @click="save">
|
||||
{{ saving ? t("common.saving") : saved ? t("settings.integrations.saved") : t("settings.integrations.save") }}
|
||||
</button>
|
||||
<button class="dh-btn dh-btn-ghost" :disabled="testing" @click="test">
|
||||
{{ testing ? t("settings.integrations.testing") : t("settings.integrations.test") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p
|
||||
v-if="health"
|
||||
class="mt-2 text-sm"
|
||||
:class="health.status === 'ok' ? 'text-success' : 'text-danger'"
|
||||
>
|
||||
{{ health.detail || health.status }}
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<p v-if="error" class="mt-2 text-sm text-danger">{{ error }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -593,6 +593,10 @@
|
||||
"subtitle": "Forbind eksterne tjenester til din konto.",
|
||||
"toyota": "Toyota Connected (MyToyota)",
|
||||
"toyotaDesc": "Log ind med din MyToyota-konto for at hente køretøjsdata fra Toyota Connected Europe. Kun Europa.",
|
||||
"lexus": "Lexus (Lexus Link+)",
|
||||
"lexusDesc": "Log ind med din Lexus Link+-konto for at hente køretøjsdata fra Toyota Connected Europe. Kun Europa.",
|
||||
"subaru": "Subaru (MySubaru)",
|
||||
"subaruDesc": "Log ind med din MySubaru-konto for at hente Solterra-data fra Toyota Connected Europe. Kun Europa.",
|
||||
"enable": "Aktivér for min konto",
|
||||
"enableOrg": "Aktivér for organisationen",
|
||||
"unavailable": "Denne integration er slået fra af administratoren.",
|
||||
@@ -601,12 +605,8 @@
|
||||
"scopeOrg": "Organisation",
|
||||
"scopeHint": "Organisationens indstillinger gælder for alle i din organisation, der lader et felt stå tomt.",
|
||||
"readOnly": "Denne integrations fælles indstillinger administreres i API-serverens panel; her er de skrivebeskyttede.",
|
||||
"email": "MyToyota-e-mail",
|
||||
"password": "MyToyota-adgangskode",
|
||||
"brand": "Mærke",
|
||||
"brandToyota": "Toyota",
|
||||
"brandLexus": "Lexus",
|
||||
"brandSubaru": "Subaru",
|
||||
"email": "{app}-e-mail",
|
||||
"password": "{app}-adgangskode",
|
||||
"inherited": "Sat på et højere niveau",
|
||||
"inheritedFrom": "Nedarvet fra {source}",
|
||||
"sourceGlobal": "administratoren",
|
||||
|
||||
@@ -592,6 +592,10 @@
|
||||
"subtitle": "Connect external services to your account.",
|
||||
"toyota": "Toyota Connected (MyToyota)",
|
||||
"toyotaDesc": "Sign in with your MyToyota account to pull vehicle data from Toyota Connected Europe. Europe only.",
|
||||
"lexus": "Lexus (Lexus Link+)",
|
||||
"lexusDesc": "Sign in with your Lexus Link+ account to pull vehicle data from Toyota Connected Europe. Europe only.",
|
||||
"subaru": "Subaru (MySubaru)",
|
||||
"subaruDesc": "Sign in with your MySubaru account to pull Solterra vehicle data from Toyota Connected Europe. Europe only.",
|
||||
"enable": "Enable for my account",
|
||||
"enableOrg": "Enable for the organization",
|
||||
"unavailable": "This integration is turned off by the administrator.",
|
||||
@@ -600,12 +604,8 @@
|
||||
"scopeOrg": "Organization",
|
||||
"scopeHint": "Organization settings apply to everyone in your organization who leaves a field blank.",
|
||||
"readOnly": "You manage this integration's shared settings in the API Server panel; here it is read-only.",
|
||||
"email": "MyToyota email",
|
||||
"password": "MyToyota password",
|
||||
"brand": "Brand",
|
||||
"brandToyota": "Toyota",
|
||||
"brandLexus": "Lexus",
|
||||
"brandSubaru": "Subaru",
|
||||
"email": "{app} email",
|
||||
"password": "{app} password",
|
||||
"inherited": "Set above your level",
|
||||
"inheritedFrom": "Inherited from {source}",
|
||||
"sourceGlobal": "the administrator",
|
||||
|
||||
@@ -599,6 +599,10 @@
|
||||
"subtitle": "Połącz zewnętrzne usługi ze swoim kontem.",
|
||||
"toyota": "Toyota Connected (MyToyota)",
|
||||
"toyotaDesc": "Zaloguj się kontem MyToyota, aby pobierać dane pojazdu z Toyota Connected Europe. Tylko Europa.",
|
||||
"lexus": "Lexus (Lexus Link+)",
|
||||
"lexusDesc": "Zaloguj się kontem Lexus Link+, aby pobierać dane pojazdu z Toyota Connected Europe. Tylko Europa.",
|
||||
"subaru": "Subaru (MySubaru)",
|
||||
"subaruDesc": "Zaloguj się kontem MySubaru, aby pobierać dane Solterry z Toyota Connected Europe. Tylko Europa.",
|
||||
"enable": "Włącz dla mojego konta",
|
||||
"enableOrg": "Włącz dla organizacji",
|
||||
"unavailable": "Ta integracja została wyłączona przez administratora.",
|
||||
@@ -607,12 +611,8 @@
|
||||
"scopeOrg": "Organizacja",
|
||||
"scopeHint": "Ustawienia organizacji obowiązują każdego w Twojej organizacji, kto pozostawi pole puste.",
|
||||
"readOnly": "Wspólnymi ustawieniami tej integracji zarządzasz w panelu API Servera; tutaj są tylko do odczytu.",
|
||||
"email": "E-mail MyToyota",
|
||||
"password": "Hasło MyToyota",
|
||||
"brand": "Marka",
|
||||
"brandToyota": "Toyota",
|
||||
"brandLexus": "Lexus",
|
||||
"brandSubaru": "Subaru",
|
||||
"email": "E-mail {app}",
|
||||
"password": "Hasło {app}",
|
||||
"inherited": "Ustawione na wyższym poziomie",
|
||||
"inheritedFrom": "Odziedziczone od: {source}",
|
||||
"sourceGlobal": "administratora",
|
||||
|
||||
@@ -11,6 +11,7 @@ import { TAB_SURFACES, SETTINGS_TABS, defaultTabFor } from "../lib/tabs.js";
|
||||
import { askConfirm } from "../lib/confirm.js";
|
||||
import OrgManager from "../components/OrgManager.vue";
|
||||
import AdminUsers from "../components/AdminUsers.vue";
|
||||
import ToyotaBrandIntegration from "../components/ToyotaBrandIntegration.vue";
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
@@ -53,7 +54,6 @@ function selectTab(tab) {
|
||||
// Each integration card folds open/closed, like the plugin rows in the API
|
||||
// Server panel. Collapsed by default so the Integrations tab reads as a compact
|
||||
// list of connectors you expand to configure.
|
||||
const toyotaOpen = ref(false);
|
||||
const ankerOpen = ref(false);
|
||||
const greencellOpen = ref(false);
|
||||
|
||||
@@ -355,129 +355,32 @@ function inheritedPlaceholder(field, example = "") {
|
||||
return field.locked ? field.effective || "" : example;
|
||||
}
|
||||
|
||||
// --- Integrations: Toyota Connected (per-user, cascading settings) ---
|
||||
// --- Integrations: Toyota Connected (Toyota, Lexus, Subaru) ---
|
||||
//
|
||||
// The server resolves a superadmin → org admin → user cascade and returns, per
|
||||
// field, the effective value (secrets/inherited usernames masked), the caller's
|
||||
// own-layer value, its source layer, and whether it's locked (set above us).
|
||||
// An org admin gets a second "org" scope to edit organization-wide defaults.
|
||||
|
||||
const toyota = ref(null); // resolved view from the server
|
||||
const toyotaScope = ref("user"); // "user" | "org" (org admins only)
|
||||
const toyotaForm = ref({ username: "", password: "", brand: "" });
|
||||
const toyotaSaving = ref(false);
|
||||
const toyotaSaved = ref(false);
|
||||
const toyotaError = ref("");
|
||||
const toyotaTesting = ref(false);
|
||||
const toyotaHealth = ref(null); // { status, detail } from the last test
|
||||
|
||||
// Superadmins manage the shared (global) layer in the API Server panel; here the
|
||||
// credential fields are read-only (they may still toggle their own opt-in).
|
||||
const toyotaReadOnly = computed(() => !!toyota.value?.isSuperadmin);
|
||||
const toyotaScopeKey = computed(() => (toyota.value?.isSuperadmin ? "user" : toyotaScope.value));
|
||||
const toyotaScopeData = computed(
|
||||
() => toyota.value?.scopes?.[toyotaScopeKey.value] || { editableLayer: "user", fields: {} }
|
||||
);
|
||||
const toyotaEditingOrg = computed(() => toyotaScopeKey.value === "org");
|
||||
|
||||
function toyotaField(k) {
|
||||
return toyotaScopeData.value.fields?.[k] || { effective: "", own: "", source: "unset", locked: false };
|
||||
}
|
||||
// A field is locked when it's set above the caller's editable layer, or the
|
||||
// whole scope is read-only (superadmin).
|
||||
function toyotaLocked(k) {
|
||||
return toyotaReadOnly.value || toyotaField(k).locked;
|
||||
}
|
||||
// The toggle reflects the personal opt-in normally, or the org gate in org scope.
|
||||
const toyotaEnabled = computed(() =>
|
||||
toyotaEditingOrg.value ? toyota.value?.orgEnabled : toyota.value?.enabled
|
||||
);
|
||||
// A friendly "inherited from …" note for a locked field.
|
||||
function toyotaSourceLabel(k) {
|
||||
const map = { global: "sourceGlobal", org: "sourceOrg", user: "sourceUser" };
|
||||
const key = map[toyotaField(k).source] || "sourceGlobal";
|
||||
return t("settings.integrations.inheritedFrom", { source: t("settings.integrations." + key) });
|
||||
}
|
||||
|
||||
// Load the editable inputs from the current scope's own-layer values. Locked
|
||||
// fields and the secret password are never prefilled.
|
||||
function fillToyotaForm() {
|
||||
const f = toyotaScopeData.value.fields || {};
|
||||
toyotaForm.value = {
|
||||
username: f.username?.locked ? "" : f.username?.own || "",
|
||||
password: "",
|
||||
brand: f.brand?.locked ? "" : f.brand?.own || "",
|
||||
};
|
||||
}
|
||||
|
||||
function applyToyotaView(body) {
|
||||
toyota.value = body;
|
||||
// Keep the selected scope valid (fall back to personal when org isn't offered).
|
||||
if (toyotaScope.value === "org" && !body.canEditOrg) toyotaScope.value = "user";
|
||||
fillToyotaForm();
|
||||
}
|
||||
// One connector on the server, three integrations here: each brand has its own
|
||||
// account, enable switch and card (see components/ToyotaBrandIntegration.vue).
|
||||
// The views are loaded here so the category tabs know which cards exist; a
|
||||
// brand the server does not know (an older API Server) simply has no card.
|
||||
const TOYOTA_BRANDS = ["toyota", "lexus", "subaru"];
|
||||
const toyotaViews = ref({}); // brand -> resolved view from the server
|
||||
|
||||
async function loadToyota() {
|
||||
try {
|
||||
applyToyotaView(await api.getToyota());
|
||||
} catch (e) {
|
||||
toyotaError.value = e.message;
|
||||
}
|
||||
await Promise.all(
|
||||
TOYOTA_BRANDS.map(async (brand) => {
|
||||
try {
|
||||
toyotaViews.value = { ...toyotaViews.value, [brand]: await api.getToyota(brand) };
|
||||
} catch {
|
||||
// Not offered by this server; leave the card out.
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Refill the form when an admin flips between personal and organization scope.
|
||||
watch(toyotaScope, () => {
|
||||
toyotaError.value = "";
|
||||
toyotaSaved.value = false;
|
||||
toyotaHealth.value = null;
|
||||
fillToyotaForm();
|
||||
});
|
||||
|
||||
async function toggleToyota(v) {
|
||||
toyotaError.value = "";
|
||||
const org = toyotaEditingOrg.value;
|
||||
try {
|
||||
applyToyotaView(await api.saveToyota(org ? { scope: "org", enabled: v } : { scope: "user", enabled: v }));
|
||||
} catch (e) {
|
||||
toyotaError.value = e.message;
|
||||
}
|
||||
function setToyotaView(brand, body) {
|
||||
toyotaViews.value = { ...toyotaViews.value, [brand]: body };
|
||||
}
|
||||
|
||||
async function saveToyotaSettings() {
|
||||
toyotaError.value = "";
|
||||
toyotaSaving.value = true;
|
||||
toyotaSaved.value = false;
|
||||
const config = {};
|
||||
for (const k of ["username", "password", "brand"]) {
|
||||
if (toyotaLocked(k)) continue;
|
||||
// Only send the password when the user actually typed a new one.
|
||||
if (k === "password" && !toyotaForm.value.password) continue;
|
||||
config[k] = toyotaForm.value[k];
|
||||
}
|
||||
try {
|
||||
applyToyotaView(await api.saveToyota({ scope: toyotaScopeKey.value, config }));
|
||||
toyotaSaved.value = true;
|
||||
setTimeout(() => (toyotaSaved.value = false), 2000);
|
||||
} catch (e) {
|
||||
toyotaError.value = e.message;
|
||||
} finally {
|
||||
toyotaSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function testToyotaConnection() {
|
||||
toyotaError.value = "";
|
||||
toyotaHealth.value = null;
|
||||
toyotaTesting.value = true;
|
||||
try {
|
||||
const { health } = await api.testToyota();
|
||||
toyotaHealth.value = health;
|
||||
} catch (e) {
|
||||
toyotaError.value = e.message;
|
||||
} finally {
|
||||
toyotaTesting.value = false;
|
||||
}
|
||||
}
|
||||
const toyotaBrandsLoaded = computed(() => TOYOTA_BRANDS.filter((b) => toyotaViews.value[b]));
|
||||
|
||||
// --- Integrations: category tabs ---
|
||||
//
|
||||
@@ -491,7 +394,7 @@ async function testToyotaConnection() {
|
||||
const INTEGRATION_CATEGORIES = ["vehicles", "chargers"];
|
||||
|
||||
const integrationsByCategory = computed(() => ({
|
||||
vehicles: [toyota.value && "toyota"].filter(Boolean),
|
||||
vehicles: toyotaBrandsLoaded.value,
|
||||
chargers: [anker.value && "anker", greencell.value && "greencell"].filter(Boolean),
|
||||
}));
|
||||
|
||||
@@ -1394,7 +1297,7 @@ onBeforeUnmount(() => {
|
||||
|
||||
<!-- Integrations -->
|
||||
<div v-show="activeTab === 'integrations'" class="space-y-6">
|
||||
<section v-if="toyota || anker || greencell" class="dh-card p-6">
|
||||
<section v-if="toyotaBrandsLoaded.length || anker || greencell" class="dh-card p-6">
|
||||
<h2 class="text-lg font-bold tracking-[-0.02em] text-strong">{{ t("settings.integrations.title") }}</h2>
|
||||
<p class="mb-4 mt-1 text-sm text-muted">{{ t("settings.integrations.subtitle") }}</p>
|
||||
|
||||
@@ -1414,135 +1317,15 @@ onBeforeUnmount(() => {
|
||||
</nav>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div v-if="toyota && showsIntegration('toyota')" class="rounded-control border border-subtle p-4">
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-full items-start justify-between gap-3 text-left"
|
||||
:aria-expanded="toyotaOpen"
|
||||
@click="toyotaOpen = !toyotaOpen"
|
||||
>
|
||||
<div>
|
||||
<p class="text-sm font-semibold text-strong">{{ t("settings.integrations.toyota") }}</p>
|
||||
<p class="mt-0.5 text-xs text-muted">{{ t("settings.integrations.toyotaDesc") }}</p>
|
||||
</div>
|
||||
<div class="flex shrink-0 items-center gap-2">
|
||||
<span
|
||||
v-if="!toyotaEditingOrg"
|
||||
class="dh-badge"
|
||||
:class="toyota.enabled ? 'dh-badge-success' : 'dh-badge-warning'"
|
||||
>
|
||||
{{ toyota.enabled ? t("settings.integrations.connected") : t("settings.integrations.notConnected") }}
|
||||
</span>
|
||||
<svg
|
||||
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||||
class="h-4 w-4 text-muted transition-transform" :class="toyotaOpen ? 'rotate-180' : ''"
|
||||
><path stroke-linecap="round" stroke-linejoin="round" d="m6 9 6 6 6-6" /></svg>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<div v-show="toyotaOpen">
|
||||
<!-- Master / org gates -->
|
||||
<p v-if="!toyota.available" class="mt-3 text-sm text-warning">{{ t("settings.integrations.unavailable") }}</p>
|
||||
<p
|
||||
v-else-if="toyota.orgId && !toyota.orgEnabled && !toyotaEditingOrg"
|
||||
class="mt-3 text-sm text-warning"
|
||||
>
|
||||
{{ t("settings.integrations.orgDisabled") }}
|
||||
</p>
|
||||
|
||||
<template v-else>
|
||||
<!-- Scope switch (org admins) -->
|
||||
<div v-if="toyota.canEditOrg" class="mt-4 flex gap-2">
|
||||
<button
|
||||
v-for="sc in ['user', 'org']"
|
||||
:key="sc"
|
||||
class="rounded-control border px-3 py-1.5 text-sm font-medium transition-colors"
|
||||
:class="toyotaScope === sc
|
||||
? 'border-accent bg-accent text-white'
|
||||
: 'border-subtle text-body hover:bg-sunken hover:text-strong'"
|
||||
@click="toyotaScope = sc"
|
||||
>
|
||||
{{ sc === 'org' ? t("settings.integrations.scopeOrg") : t("settings.integrations.scopeMy") }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="toyotaEditingOrg" class="mt-2 text-xs text-muted">{{ t("settings.integrations.scopeHint") }}</p>
|
||||
<p v-if="toyotaReadOnly" class="mt-3 text-xs text-muted">{{ t("settings.integrations.readOnly") }}</p>
|
||||
|
||||
<!-- Enable toggle -->
|
||||
<label class="mt-4 flex items-center gap-2 text-sm font-medium text-body">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="h-4 w-4 rounded border-subtle text-accent focus:ring-accent"
|
||||
:checked="toyotaEnabled"
|
||||
@change="toggleToyota($event.target.checked)"
|
||||
/>
|
||||
<span>{{ toyotaEditingOrg ? t("settings.integrations.enableOrg") : t("settings.integrations.enable") }}</span>
|
||||
</label>
|
||||
|
||||
<!-- Credential fields -->
|
||||
<div class="mt-4 grid max-w-sm gap-3">
|
||||
<div>
|
||||
<label class="dh-label">{{ t("settings.integrations.email") }}</label>
|
||||
<input
|
||||
v-model="toyotaForm.username"
|
||||
class="dh-input"
|
||||
:disabled="toyotaLocked('username')"
|
||||
:placeholder="toyotaLocked('username') ? '••••••••' : ''"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<p v-if="toyotaField('username').locked" class="mt-1 text-xs text-muted">{{ toyotaSourceLabel('username') }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="dh-label">{{ t("settings.integrations.password") }}</label>
|
||||
<input
|
||||
v-model="toyotaForm.password"
|
||||
type="password"
|
||||
class="dh-input"
|
||||
:disabled="toyotaLocked('password')"
|
||||
:placeholder="toyotaField('password').effective ? '••••••••' : ''"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
<p v-if="toyotaField('password').locked" class="mt-1 text-xs text-muted">{{ toyotaSourceLabel('password') }}</p>
|
||||
<p v-else class="mt-1 text-xs text-muted">{{ t("settings.integrations.passwordKeep") }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="dh-label">{{ t("settings.integrations.brand") }}</label>
|
||||
<select v-model="toyotaForm.brand" class="dh-input" :disabled="toyotaLocked('brand')">
|
||||
<option value="">—</option>
|
||||
<option value="T">{{ t("settings.integrations.brandToyota") }}</option>
|
||||
<option value="L">{{ t("settings.integrations.brandLexus") }}</option>
|
||||
<option value="S">{{ t("settings.integrations.brandSubaru") }}</option>
|
||||
</select>
|
||||
<p v-if="toyotaField('brand').locked" class="mt-1 text-xs text-muted">{{ toyotaSourceLabel('brand') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex items-center gap-2">
|
||||
<button
|
||||
v-if="!toyotaReadOnly"
|
||||
class="dh-btn dh-btn-primary"
|
||||
:disabled="toyotaSaving"
|
||||
@click="saveToyotaSettings"
|
||||
>
|
||||
{{ toyotaSaving ? t("common.saving") : toyotaSaved ? t("settings.integrations.saved") : t("settings.integrations.save") }}
|
||||
</button>
|
||||
<button class="dh-btn dh-btn-ghost" :disabled="toyotaTesting" @click="testToyotaConnection">
|
||||
{{ toyotaTesting ? t("settings.integrations.testing") : t("settings.integrations.test") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p
|
||||
v-if="toyotaHealth"
|
||||
class="mt-2 text-sm"
|
||||
:class="toyotaHealth.status === 'ok' ? 'text-success' : 'text-danger'"
|
||||
>
|
||||
{{ toyotaHealth.detail || toyotaHealth.status }}
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<p v-if="toyotaError" class="mt-2 text-sm text-danger">{{ toyotaError }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Toyota Connected: one connector, a card per brand. -->
|
||||
<template v-for="brand in toyotaBrandsLoaded" :key="brand">
|
||||
<ToyotaBrandIntegration
|
||||
v-if="showsIntegration(brand)"
|
||||
:brand="brand"
|
||||
:view="toyotaViews[brand]"
|
||||
@update:view="setToyotaView(brand, $event)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- Anker Solix (V1 Smart EV Charger) -->
|
||||
<div v-if="anker && showsIntegration('anker')" class="rounded-control border border-subtle p-4">
|
||||
|
||||
Reference in new issue
Block a user