A mode that does not work stops being on the menu
The control-mode picker offered all five paths to everyone, always. When one of them is broken in a deployment — OCPP is, right now — there was nothing to do about it: the superadmin could pick a different mode for the global layer, but the option stayed in every organization's and every user's dropdown, waiting to be chosen. The cascade could impose a mode. It could not withdraw one. So each layer now carries a second, separate thing: a list of the modes it hides from the layers below it. controlModesDisabled sits beside controlMode, on the global layer as a plugin config field and on an organization as part of the same pluginSettings blob its credentials already live in. A superadmin ticking Own CSMS and Proxy CSMS takes both OCPP paths out of every picker underneath; an org admin ticking Modbus takes it out of their own users'. Three decisions are worth naming. A hide-list governs the layers below, not the layer holding it. The superadmin can keep running Proxy globally while hiding it from everyone else, which is what you want while a mode is being repaired rather than retired: the operator testing the fix is the one person who still needs to select it. The alternative, a list that also invalidates its own layer's choice, would have made the panel contradict itself — a mode chosen in one field and switched off in the one below it. But a hidden mode really is hidden, not merely absent from a dropdown. A user who had picked Proxy last month stops resolving to Proxy the moment the superadmin hides it, and falls back to monitoring only. Filtering the picker alone would have left every existing charger on the broken path and quietly disagreed with the list the operator had just filled in. Resolution now walks the layers accumulating what each hides from the next, so a stored value only takes effect if the layers above it still permit it. And off is never hideable. It is what a charger falls back to and what an empty cascade resolves to, so a layer that could take it away could leave the layer below with a picker holding no valid choice at all. It is not among the checkboxes in any of the three clients, and the parser drops it if it arrives anyway. The panel needed a field shape it did not have — several options, any number chosen — so ConfigField grows a "multiselect" type, stored as the comma-separated string that fits the flat map every other field already uses. That is generic: any plugin can declare one now, and the PUT body is unchanged. The phone's field specs grew the same way, a scopeOptions hook that narrows a declared option list to what the server still offers, rather than teaching the integration card about control modes specifically. Both clients clamp a stored mode that has since been hidden back to off before drawing the picker, so the box shows what will actually happen rather than a choice that would be dropped on save. Verified: Go tests pass, both frontends build, flutter analyze is clean, and the panel's new checkbox field was rendered against the real stylesheet. The end-to-end path — superadmin hides a mode, an org admin and then a user reload and find it gone — has not been walked on a live stack; the panel is embedded in the Go binary, so the remote deployment needs a rebuild before any of this is visible there. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d4b9d0870e
commit
3c34b708b9
21 files changed
+582
-49
No files matched your search
@@ -626,6 +626,8 @@
|
||||
"countryHint": "Landekode på to bogstaver for din Anker-konto (f.eks. DE, GB, US).",
|
||||
"controlMode": "Styringstilstand",
|
||||
"controlModeHint": "Hvordan DriverVault styrer laderen.",
|
||||
"controlModesHidden": "Skjul for dine brugere",
|
||||
"controlModesHiddenHint": "Tilstande du markerer her forsvinder fra dine brugeres liste og træder ikke længere i kraft for dem. Kun overvågning er altid tilgængelig.",
|
||||
"controlOff": "Fra (kun overvågning)",
|
||||
"controlOwn": "Eget CSMS (fuld styring)",
|
||||
"controlProxy": "Proxy-CSMS (videresendelse + styring)",
|
||||
|
||||
@@ -625,6 +625,8 @@
|
||||
"countryHint": "Two-letter country code of your Anker account (e.g. DE, GB, US).",
|
||||
"controlMode": "Control mode",
|
||||
"controlModeHint": "How DriverVault controls the charger.",
|
||||
"controlModesHidden": "Hide from your users",
|
||||
"controlModesHiddenHint": "Modes you tick here disappear from your users' picker and stop taking effect for them. Monitoring only is always available.",
|
||||
"controlOff": "Off (monitoring only)",
|
||||
"controlOwn": "Own CSMS (full control)",
|
||||
"controlProxy": "Proxy CSMS (relay + control)",
|
||||
|
||||
@@ -632,6 +632,8 @@
|
||||
"countryHint": "Dwuliterowy kod kraju Twojego konta Anker (np. DE, GB, US).",
|
||||
"controlMode": "Tryb sterowania",
|
||||
"controlModeHint": "Sposób, w jaki DriverVault steruje ładowarką.",
|
||||
"controlModesHidden": "Ukryj przed użytkownikami",
|
||||
"controlModesHiddenHint": "Zaznaczone tryby znikają z listy Twoich użytkowników i przestają dla nich działać. Tylko monitorowanie jest zawsze dostępne.",
|
||||
"controlOff": "Wyłączone (tylko monitorowanie)",
|
||||
"controlOwn": "Własny CSMS (pełne sterowanie)",
|
||||
"controlProxy": "CSMS pośredniczący (przekazywanie + sterowanie)",
|
||||
|
||||
@@ -361,6 +361,21 @@ body {
|
||||
box-shadow: var(--shadow-focus);
|
||||
}
|
||||
|
||||
/* Checkbox for the small multi-choice lists (hidden control modes, ...).
|
||||
accent-color keeps the native control and its keyboard behaviour. */
|
||||
.dh-checkbox {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
flex: none;
|
||||
accent-color: var(--accent);
|
||||
cursor: pointer;
|
||||
}
|
||||
.dh-checkbox:focus-visible {
|
||||
outline: none;
|
||||
box-shadow: var(--shadow-focus);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.dh-label {
|
||||
display: block;
|
||||
margin-bottom: 0.375rem;
|
||||
|
||||
@@ -519,7 +519,7 @@ function showsIntegration(id) {
|
||||
|
||||
const anker = ref(null); // resolved view from the server
|
||||
const ankerScope = ref("user"); // "user" | "org" (org admins only)
|
||||
const ankerForm = ref({ email: "", password: "", country: "", controlMode: "off" });
|
||||
const ankerForm = ref({ email: "", password: "", country: "", controlMode: "off", controlModesDisabled: [] });
|
||||
const ankerSaving = ref(false);
|
||||
const ankerSaved = ref(false);
|
||||
const ankerError = ref("");
|
||||
@@ -548,17 +548,63 @@ function ankerSourceLabel(k) {
|
||||
return t("settings.integrations.inheritedFrom", { source: t("settings.integrations." + key) });
|
||||
}
|
||||
|
||||
// Clamp a stored mode to what this scope still offers.
|
||||
function ankerModeInScope(mode) {
|
||||
const modes = ankerScopeData.value.controlModes;
|
||||
if (!mode) return "off";
|
||||
if (modes?.length && !modes.includes(mode)) return "off";
|
||||
return mode;
|
||||
}
|
||||
|
||||
function fillAnkerForm() {
|
||||
const f = ankerScopeData.value.fields || {};
|
||||
ankerForm.value = {
|
||||
email: f.email?.locked ? "" : f.email?.own || "",
|
||||
password: "",
|
||||
country: f.country?.locked ? "" : f.country?.own || "",
|
||||
// controlMode isn't secret, so show the effective value when it's locked.
|
||||
controlMode: f.controlMode?.locked ? f.controlMode?.effective || "off" : f.controlMode?.own || "off",
|
||||
// controlMode isn't secret, so show the effective value when it's locked. A
|
||||
// mode the layers above have since hidden is no longer on offer, so the
|
||||
// picker starts from monitoring-only rather than showing a dead choice.
|
||||
controlMode: ankerModeInScope(
|
||||
f.controlMode?.locked ? f.controlMode?.effective : f.controlMode?.own,
|
||||
),
|
||||
// Which modes this organization hides from its own users (org scope only).
|
||||
controlModesDisabled: [...(ankerScopeData.value.controlModesDisabled || [])],
|
||||
};
|
||||
}
|
||||
|
||||
// The modes this scope may still pick: the server has already removed whatever
|
||||
// the layers above hid. An empty list would leave the picker blank, so fall back
|
||||
// to monitoring-only, which no layer can take away.
|
||||
const ankerControlModeOptions = computed(() => {
|
||||
const modes = ankerScopeData.value.controlModes;
|
||||
return modes?.length ? modes : ["off"];
|
||||
});
|
||||
// The modes an org admin may hide from their users — everything they can choose
|
||||
// themselves, minus off, which is the fallback.
|
||||
const ankerHideableModes = computed(() =>
|
||||
ankerControlModeOptions.value.filter((m) => m !== "off"),
|
||||
);
|
||||
const ankerModeLabels = {
|
||||
off: "controlOff",
|
||||
mqtt: "controlCloud",
|
||||
modbus: "controlModbus",
|
||||
own: "controlOwn",
|
||||
proxy: "controlProxy",
|
||||
};
|
||||
function ankerModeLabel(m) {
|
||||
return t("settings.integrations." + (ankerModeLabels[m] || "controlOff"));
|
||||
}
|
||||
function ankerHidesMode(m) {
|
||||
return ankerForm.value.controlModesDisabled.includes(m);
|
||||
}
|
||||
function toggleAnkerHiddenMode(m, on) {
|
||||
const set = new Set(ankerForm.value.controlModesDisabled);
|
||||
if (on) set.add(m);
|
||||
else set.delete(m);
|
||||
ankerForm.value.controlModesDisabled = ankerHideableModes.value.filter((v) => set.has(v));
|
||||
}
|
||||
|
||||
// The effective control mode (off | mqtt | modbus | own | proxy) — it gates the
|
||||
// control panel.
|
||||
const ankerControlMode = computed(() => anker.value?.controlMode || "off");
|
||||
@@ -717,6 +763,9 @@ async function saveAnkerSettings() {
|
||||
if (k === "password" && !ankerForm.value.password) continue;
|
||||
config[k] = ankerForm.value[k];
|
||||
}
|
||||
// The hide-list travels as the comma-separated string the server stores; only
|
||||
// a layer with users under it has one.
|
||||
if (ankerEditingOrg.value) config.controlModesDisabled = ankerForm.value.controlModesDisabled.join(",");
|
||||
try {
|
||||
applyAnkerView(await api.saveAnkerSolix({ scope: ankerScopeKey.value, config }));
|
||||
ankerSaved.value = true;
|
||||
@@ -1602,15 +1651,33 @@ onBeforeUnmount(() => {
|
||||
<div>
|
||||
<label class="dh-label">{{ t("settings.integrations.controlMode") }}</label>
|
||||
<select v-model="ankerForm.controlMode" class="dh-input" :disabled="ankerLocked('controlMode')">
|
||||
<option value="off">{{ t("settings.integrations.controlOff") }}</option>
|
||||
<option value="mqtt">{{ t("settings.integrations.controlCloud") }}</option>
|
||||
<option value="modbus">{{ t("settings.integrations.controlModbus") }}</option>
|
||||
<option value="own">{{ t("settings.integrations.controlOwn") }}</option>
|
||||
<option value="proxy">{{ t("settings.integrations.controlProxy") }}</option>
|
||||
<option v-for="m in ankerControlModeOptions" :key="m" :value="m">{{ ankerModeLabel(m) }}</option>
|
||||
</select>
|
||||
<p v-if="ankerField('controlMode').locked" class="mt-1 text-xs text-muted">{{ ankerSourceLabel('controlMode') }}</p>
|
||||
<p v-else class="mt-1 text-xs text-muted">{{ t("settings.integrations.controlModeHint") }}</p>
|
||||
</div>
|
||||
<!-- An org admin decides which of the modes left to them their own
|
||||
users get to see. Modes the superadmin already hid are not in
|
||||
the list at all, so they cannot be handed back. -->
|
||||
<div v-if="ankerEditingOrg && ankerHideableModes.length">
|
||||
<label class="dh-label">{{ t("settings.integrations.controlModesHidden") }}</label>
|
||||
<div class="flex flex-col gap-1.5 pt-1">
|
||||
<label
|
||||
v-for="m in ankerHideableModes"
|
||||
:key="m"
|
||||
class="flex items-center gap-2 text-sm text-body"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="dh-checkbox"
|
||||
:checked="ankerHidesMode(m)"
|
||||
@change="toggleAnkerHiddenMode(m, $event.target.checked)"
|
||||
/>
|
||||
<span>{{ ankerModeLabel(m) }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<p class="mt-1 text-xs text-muted">{{ t("settings.integrations.controlModesHiddenHint") }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex items-center gap-2">
|
||||
|
||||
Reference in new issue
Block a user