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:
co-authored by
Claude Opus 5
parent
d4b9d0870e
commit
3c34b708b9
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
+2
-2
@@ -6,8 +6,8 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="theme-color" content="#2563eb" />
|
||||
<title>DriverVault · API Server</title>
|
||||
<script type="module" crossorigin src="/assets/index-BBZfstAT.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-_8IdQ1wh.css">
|
||||
<script type="module" crossorigin src="/assets/index-CUgU2Fxs.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-Cd85xDqG.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
@@ -62,6 +62,52 @@ func normalizeControlMode(v string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// ankerControlModesAll lists every control mode, in the order the clients offer
|
||||
// them. off leads because it is the default and the fallback.
|
||||
var ankerControlModesAll = []string{ankerControlOff, ankerControlMqtt, ankerControlModbus, ankerControlOwn, ankerControlProxy}
|
||||
|
||||
// parseControlModes reads a stored comma-separated mode list into a set,
|
||||
// dropping anything unrecognized. off is never in it: monitoring-only is what a
|
||||
// charger falls back to, so no layer may take it away from the layers below.
|
||||
func parseControlModes(v string) map[string]bool {
|
||||
out := map[string]bool{}
|
||||
for _, part := range strings.Split(v, ",") {
|
||||
if m := normalizeControlMode(part); m != "" && m != ankerControlOff {
|
||||
out[m] = true
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// joinControlModes renders a mode set back to its stored form, in the canonical
|
||||
// order, so what a client sends round-trips to a predictable string.
|
||||
func joinControlModes(set map[string]bool) string {
|
||||
return strings.Join(controlModeList(set), ",")
|
||||
}
|
||||
|
||||
// controlModeList sorts a mode set into the canonical order.
|
||||
func controlModeList(set map[string]bool) []string {
|
||||
out := []string{}
|
||||
for _, m := range ankerControlModesAll {
|
||||
if set[m] {
|
||||
out = append(out, m)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// controlModesOffered lists the modes a layer may still choose once the layers
|
||||
// above it have hidden theirs.
|
||||
func controlModesOffered(hidden map[string]bool) []string {
|
||||
out := []string{}
|
||||
for _, m := range ankerControlModesAll {
|
||||
if !hidden[m] {
|
||||
out = append(out, m)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ankerConfig is one layer's Anker Solix settings.
|
||||
type ankerConfig struct {
|
||||
Email string `json:"email"`
|
||||
@@ -70,6 +116,12 @@ type ankerConfig struct {
|
||||
// ControlMode is the control path: off | mqtt | modbus | own | proxy.
|
||||
// It resolves independently of the credentials, like Country.
|
||||
ControlMode string `json:"controlMode"`
|
||||
// ControlModesDisabled is a comma-separated list of modes this layer hides
|
||||
// from the layers below it — a mode a deployment (or an organization) does
|
||||
// not want offered at all. It does not constrain this layer's own choice, and
|
||||
// it never hides off. Meaningful on the global and organization layers only:
|
||||
// a user has nobody below them.
|
||||
ControlModesDisabled string `json:"controlModesDisabled,omitempty"`
|
||||
}
|
||||
|
||||
// ankerChargerBinding is what we know about one charger the caller controls:
|
||||
@@ -128,6 +180,14 @@ type ankerResolution struct {
|
||||
available bool // global master switch (plugin enabled in the panel)
|
||||
orgEnabled bool // org gate (default true; gates the org's users)
|
||||
enabled bool // caller's personal enable flag
|
||||
|
||||
// hiddenForOrg is what the global layer hides from everyone below it;
|
||||
// hiddenForUser adds what the caller's organization hides from its own users.
|
||||
// They gate both the pickers the clients draw and which layer's stored mode
|
||||
// is allowed to take effect.
|
||||
hiddenForOrg map[string]bool
|
||||
hiddenForUser map[string]bool
|
||||
orgHidden map[string]bool // the organization layer's own list, for its editor
|
||||
}
|
||||
|
||||
// ankerLayerRank orders the cascade layers; a higher number is lower priority.
|
||||
@@ -137,7 +197,8 @@ var ankerLayerRank = map[string]int{"global": 1, "org": 2, "user": 3}
|
||||
// pluginSettings blob (read from their user record).
|
||||
func (s *Server) resolveAnker(ctx context.Context, who *callerIdentity, userRaw json.RawMessage) ankerResolution {
|
||||
g, masterEnabled, _ := s.plugins.RawConfig(ankerPlugin)
|
||||
gc := ankerConfig{Email: g["email"], Password: g["password"], Country: g["country"], ControlMode: g["controlMode"]}
|
||||
gc := ankerConfig{Email: g["email"], Password: g["password"], Country: g["country"],
|
||||
ControlMode: g["controlMode"], ControlModesDisabled: g["controlModesDisabled"]}
|
||||
|
||||
var oStored ankerStored
|
||||
if who.OrgID != "" {
|
||||
@@ -166,6 +227,21 @@ func (s *Server) resolveAnker(ctx context.Context, who *callerIdentity, userRaw
|
||||
enabled: uStored.Enabled,
|
||||
}
|
||||
|
||||
// What each layer below may still be offered. The global list reaches
|
||||
// everyone; an organization's own list reaches only its users, so it narrows
|
||||
// the set once more on the way down.
|
||||
res.hiddenForOrg = parseControlModes(gc.ControlModesDisabled)
|
||||
res.orgHidden = parseControlModes(oc.ControlModesDisabled)
|
||||
res.hiddenForUser = map[string]bool{}
|
||||
for m := range res.hiddenForOrg {
|
||||
res.hiddenForUser[m] = true
|
||||
}
|
||||
if who.OrgID != "" {
|
||||
for m := range res.orgHidden {
|
||||
res.hiddenForUser[m] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Ordered layers, top (highest priority) first.
|
||||
type layer struct {
|
||||
name string
|
||||
@@ -189,13 +265,18 @@ func (s *Server) resolveAnker(ctx context.Context, who *callerIdentity, userRaw
|
||||
// Control mode resolves independently too, defaulting to off (monitoring
|
||||
// only). The highest layer that sets a recognized value wins; an explicit
|
||||
// "off" set above still wins (and locks lower layers to monitoring).
|
||||
// A mode hidden by a layer above is not merely absent from the picker: a value
|
||||
// stored below before it was hidden stops taking effect too, so switching a
|
||||
// mode off really does switch it off everywhere underneath.
|
||||
res.eff.ControlMode = ankerControlOff
|
||||
res.source["controlMode"] = "unset"
|
||||
for _, l := range layers {
|
||||
if v := normalizeControlMode(l.c.ControlMode); v != "" {
|
||||
res.eff.ControlMode, res.source["controlMode"] = v, l.name
|
||||
break
|
||||
v := normalizeControlMode(l.c.ControlMode)
|
||||
if v == "" || res.hiddenAt(l.name)[v] {
|
||||
continue
|
||||
}
|
||||
res.eff.ControlMode, res.source["controlMode"] = v, l.name
|
||||
break
|
||||
}
|
||||
|
||||
// Credentials resolve as a pair from the highest layer with an email, so the
|
||||
@@ -212,6 +293,19 @@ func (s *Server) resolveAnker(ctx context.Context, who *callerIdentity, userRaw
|
||||
return res
|
||||
}
|
||||
|
||||
// hiddenAt is the set of modes hidden from one cascade layer by the layers above
|
||||
// it. The global layer answers to nobody, so nothing is hidden from it.
|
||||
func (r ankerResolution) hiddenAt(layer string) map[string]bool {
|
||||
switch layer {
|
||||
case "org":
|
||||
return r.hiddenForOrg
|
||||
case "user":
|
||||
return r.hiddenForUser
|
||||
default:
|
||||
return map[string]bool{}
|
||||
}
|
||||
}
|
||||
|
||||
// ankerLockedFor reports whether a field whose value comes from source is locked
|
||||
// for a caller whose editable layer is editable (i.e. the value is set above them).
|
||||
func ankerLockedFor(source, editable string) bool {
|
||||
@@ -301,7 +395,13 @@ func (s *Server) ankerScopeView(res ankerResolution, editable string) map[string
|
||||
}
|
||||
return fv
|
||||
}
|
||||
return map[string]any{
|
||||
// The modes this scope may pick from: everything the layers above it left
|
||||
// standing. A superadmin's read-only view answers as the user layer they are.
|
||||
hidden := res.hiddenForUser
|
||||
if editable == "org" {
|
||||
hidden = res.hiddenForOrg
|
||||
}
|
||||
out := map[string]any{
|
||||
"editableLayer": editable,
|
||||
"fields": map[string]ankerFieldView{
|
||||
"email": field("email", res.eff.Email, own.Email, false),
|
||||
@@ -309,7 +409,15 @@ func (s *Server) ankerScopeView(res ankerResolution, editable string) map[string
|
||||
"country": field("country", res.eff.Country, own.Country, false),
|
||||
"controlMode": field("controlMode", res.eff.ControlMode, own.ControlMode, false),
|
||||
},
|
||||
"controlModes": controlModesOffered(hidden),
|
||||
}
|
||||
if editable == "org" {
|
||||
// The organization's own hide-list, which its admin edits here. Modes the
|
||||
// global layer already hid are not in controlModes above, so they simply
|
||||
// never come up.
|
||||
out["controlModesDisabled"] = controlModeList(res.orgHidden)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ankerView builds the masked, client-safe response body from a resolution.
|
||||
@@ -319,6 +427,7 @@ func (s *Server) ankerView(who *callerIdentity, res ankerResolution) map[string]
|
||||
"orgEnabled": res.orgEnabled,
|
||||
"enabled": res.enabled,
|
||||
"controlMode": res.eff.ControlMode, // effective control mode (off|mqtt|modbus|own|proxy)
|
||||
"controlModes": controlModesOffered(res.hiddenForUser), // modes still offered to this caller
|
||||
"role": who.Role,
|
||||
"orgId": who.OrgID,
|
||||
"canEditOrg": res.canOrg,
|
||||
@@ -430,7 +539,21 @@ func (s *Server) handlePutAnker(w http.ResponseWriter, r *http.Request) {
|
||||
applyField("email", func(c *ankerConfig, v string) { c.Email = v })
|
||||
applyField("password", func(c *ankerConfig, v string) { c.Password = v })
|
||||
applyField("country", func(c *ankerConfig, v string) { c.Country = strings.ToUpper(v) })
|
||||
applyField("controlMode", func(c *ankerConfig, v string) { c.ControlMode = normalizeControlMode(v) })
|
||||
applyField("controlMode", func(c *ankerConfig, v string) {
|
||||
m := normalizeControlMode(v)
|
||||
// A mode hidden above is not a choice this layer can make; keep whatever it
|
||||
// had rather than storing something that would never take effect.
|
||||
if m != "" && res.hiddenAt(editable)[m] {
|
||||
return
|
||||
}
|
||||
c.ControlMode = m
|
||||
})
|
||||
if editable == "org" {
|
||||
// Only a layer with users under it has anything to hide from them.
|
||||
applyField("controlModesDisabled", func(c *ankerConfig, v string) {
|
||||
c.ControlModesDisabled = joinControlModes(parseControlModes(v))
|
||||
})
|
||||
}
|
||||
|
||||
// Persist the organization layer (admins) via the service account.
|
||||
if editable == "org" {
|
||||
|
||||
@@ -241,3 +241,83 @@ func TestAnkerCardRoutesAreRegistered(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseControlModes(t *testing.T) {
|
||||
got := parseControlModes(" Proxy , own ,bogus,, off ")
|
||||
// off is never hideable: monitoring only is what a charger falls back to.
|
||||
want := map[string]bool{"proxy": true, "own": true}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("parseControlModes = %v, want %v", got, want)
|
||||
}
|
||||
for m := range want {
|
||||
if !got[m] {
|
||||
t.Errorf("parseControlModes is missing %q", m)
|
||||
}
|
||||
}
|
||||
if s := joinControlModes(got); s != "own,proxy" {
|
||||
t.Errorf("joinControlModes = %q, want own,proxy (canonical order)", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestControlModesOffered(t *testing.T) {
|
||||
got := controlModesOffered(map[string]bool{"own": true, "proxy": true})
|
||||
want := []string{"off", "mqtt", "modbus"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("controlModesOffered = %v, want %v", got, want)
|
||||
}
|
||||
for i, m := range want {
|
||||
if got[i] != m {
|
||||
t.Errorf("controlModesOffered[%d] = %q, want %q", i, got[i], m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A mode the global layer hides is not merely absent from a lower picker: a
|
||||
// value stored below before it was hidden stops taking effect too.
|
||||
func TestHiddenControlModeDoesNotTakeEffect(t *testing.T) {
|
||||
res := ankerResolution{
|
||||
hiddenForOrg: map[string]bool{"own": true, "proxy": true},
|
||||
hiddenForUser: map[string]bool{"own": true, "proxy": true},
|
||||
}
|
||||
if !res.hiddenAt("user")["proxy"] {
|
||||
t.Error("proxy should be hidden from the user layer")
|
||||
}
|
||||
if res.hiddenAt("global")["proxy"] {
|
||||
t.Error("nothing is hidden from the global layer — it is the one hiding")
|
||||
}
|
||||
view := (&Server{}).ankerScopeView(res, "user")
|
||||
for _, m := range view["controlModes"].([]string) {
|
||||
if m == "own" || m == "proxy" {
|
||||
t.Errorf("hidden mode %q is still offered to the user scope", m)
|
||||
}
|
||||
}
|
||||
if _, ok := view["controlModesDisabled"]; ok {
|
||||
t.Error("the user scope has nobody below it and must carry no hide-list")
|
||||
}
|
||||
}
|
||||
|
||||
// An organization narrows the set once more for its own users, and its admin
|
||||
// edits that list in the org scope.
|
||||
func TestOrgScopeCarriesItsOwnHideList(t *testing.T) {
|
||||
res := ankerResolution{
|
||||
hiddenForOrg: map[string]bool{"proxy": true},
|
||||
hiddenForUser: map[string]bool{"proxy": true, "own": true},
|
||||
orgHidden: map[string]bool{"own": true},
|
||||
}
|
||||
org := (&Server{}).ankerScopeView(res, "org")
|
||||
offered := org["controlModes"].([]string)
|
||||
var sawOwn, sawProxy bool
|
||||
for _, m := range offered {
|
||||
sawOwn = sawOwn || m == "own"
|
||||
sawProxy = sawProxy || m == "proxy"
|
||||
}
|
||||
if !sawOwn {
|
||||
t.Error("an org may still choose a mode it only hides from its users")
|
||||
}
|
||||
if sawProxy {
|
||||
t.Error("a mode the global layer hid must not reach the org picker")
|
||||
}
|
||||
if got := org["controlModesDisabled"].([]string); len(got) != 1 || got[0] != "own" {
|
||||
t.Errorf("org hide-list = %v, want [own]", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,6 +334,19 @@ func (p *Plugin) Descriptor() plugins.Descriptor {
|
||||
{Value: "own", Label: "Own CSMS (full control)"},
|
||||
{Value: "proxy", Label: "Proxy CSMS (relay + control)"},
|
||||
}},
|
||||
// controlModesDisabled hides modes from the layers *below* this one. It
|
||||
// is how a superadmin takes a mode that is broken or unwanted in this
|
||||
// deployment (OCPP, say) out of every organization's and user's picker
|
||||
// without touching the mode this layer itself runs. Organizations carry
|
||||
// the same field for their own users; see integrations_ankersolix.go.
|
||||
{Key: "controlModesDisabled", Label: "Hidden control modes", Type: "multiselect",
|
||||
Help: "Control modes to hide from organizations and users. A hidden mode disappears from their picker and stops taking effect for them; the mode chosen above, which is this layer's own, is unaffected. Off (monitoring only) can never be hidden — it is what a charger falls back to.",
|
||||
Options: []plugins.SelectOption{
|
||||
{Value: "mqtt", Label: "Anker cloud (works anywhere)"},
|
||||
{Value: "modbus", Label: "Modbus TCP (local network)"},
|
||||
{Value: "own", Label: "Own CSMS (full control)"},
|
||||
{Value: "proxy", Label: "Proxy CSMS (relay + control)"},
|
||||
}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,31 @@ func TestDescriptor(t *testing.T) {
|
||||
t.Errorf("controlMode is missing option %q", v)
|
||||
}
|
||||
}
|
||||
|
||||
// controlModesDisabled is the superadmin's hide-list: which of the modes the
|
||||
// organizations and users below are offered at all. off is not among them —
|
||||
// monitoring only is the fallback, so no layer may take it away.
|
||||
hide, ok := fields["controlModesDisabled"]
|
||||
if !ok {
|
||||
t.Fatal("controlModesDisabled config field should be present")
|
||||
}
|
||||
if hide.Type != "multiselect" {
|
||||
t.Errorf("controlModesDisabled type = %q, want multiselect", hide.Type)
|
||||
}
|
||||
hideable := map[string]bool{"mqtt": false, "modbus": false, "own": false, "proxy": false}
|
||||
for _, o := range hide.Options {
|
||||
if o.Value == "off" {
|
||||
t.Error("off must not be hideable — it is what a charger falls back to")
|
||||
}
|
||||
if _, known := hideable[o.Value]; known {
|
||||
hideable[o.Value] = true
|
||||
}
|
||||
}
|
||||
for v, seen := range hideable {
|
||||
if !seen {
|
||||
t.Errorf("controlModesDisabled is missing option %q", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistered(t *testing.T) {
|
||||
|
||||
@@ -44,7 +44,8 @@ const (
|
||||
StatusDown = "down"
|
||||
)
|
||||
|
||||
// SelectOption is one choice for a ConfigField of Type "select".
|
||||
// SelectOption is one choice for a ConfigField of Type "select" (pick one) or
|
||||
// "multiselect" (pick any number; stored as a comma-separated list of values).
|
||||
type SelectOption struct {
|
||||
Value string `json:"value"`
|
||||
Label string `json:"label"`
|
||||
@@ -55,12 +56,12 @@ type SelectOption struct {
|
||||
type ConfigField struct {
|
||||
Key string `json:"key"`
|
||||
Label string `json:"label"`
|
||||
Type string `json:"type"` // "text" | "password" | "number" | "select"
|
||||
Type string `json:"type"` // "text" | "password" | "number" | "select" | "multiselect"
|
||||
Required bool `json:"required"`
|
||||
Secret bool `json:"secret"` // never echoed back to clients in clear
|
||||
Help string `json:"help,omitempty"`
|
||||
Default string `json:"default,omitempty"` // effective default when unset
|
||||
Options []SelectOption `json:"options,omitempty"` // for Type "select"
|
||||
Options []SelectOption `json:"options,omitempty"` // for Type "select" and "multiselect"
|
||||
}
|
||||
|
||||
// Capability is one operation a plugin exposes. It maps a stable id to the
|
||||
|
||||
@@ -62,6 +62,31 @@ function expand(p) {
|
||||
open.value = p.name;
|
||||
}
|
||||
|
||||
// A multiselect field is a comma-separated list of option values in the same
|
||||
// flat string map every other field uses, so the PUT body stays unchanged.
|
||||
function multiValues(name, key) {
|
||||
return String(drafts[name]?.[key] ?? "")
|
||||
.split(",")
|
||||
.map((v) => v.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
function hasMulti(name, key, value) {
|
||||
return multiValues(name, key).includes(value);
|
||||
}
|
||||
function toggleMulti(name, key, value, on) {
|
||||
const set = new Set(multiValues(name, key));
|
||||
if (on) set.add(value);
|
||||
else set.delete(value);
|
||||
// Keep the declared option order rather than click order, so the stored value
|
||||
// is stable across edits.
|
||||
const p = plugins.value.find((x) => x.name === name);
|
||||
const order = (p?.configFields || []).find((f) => f.key === key)?.options || [];
|
||||
drafts[name][key] = order
|
||||
.map((o) => o.value)
|
||||
.filter((v) => set.has(v))
|
||||
.join(",");
|
||||
}
|
||||
|
||||
async function save(p, enabled) {
|
||||
busy.value = true;
|
||||
rowNotice[p.name] = "";
|
||||
@@ -224,7 +249,25 @@ const healthClass = (s) =>
|
||||
<label class="dh-label">
|
||||
{{ f.label || f.key }}<span v-if="f.required" class="text-danger"> *</span>
|
||||
</label>
|
||||
<select v-if="f.type === 'select'" v-model="drafts[p.name][f.key]" class="dh-select">
|
||||
<!-- multiselect: any number of the declared options, stored as a
|
||||
comma-separated list. Nothing checked means the field imposes
|
||||
nothing, which is the unset state for a select too. -->
|
||||
<div v-if="f.type === 'multiselect'" class="flex flex-col gap-1.5 pt-1">
|
||||
<label
|
||||
v-for="o in f.options || []"
|
||||
:key="o.value"
|
||||
class="flex items-center gap-2 text-sm text-body"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="dh-checkbox"
|
||||
:checked="hasMulti(p.name, f.key, o.value)"
|
||||
@change="toggleMulti(p.name, f.key, o.value, $event.target.checked)"
|
||||
/>
|
||||
<span>{{ o.label || o.value }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<select v-else-if="f.type === 'select'" v-model="drafts[p.name][f.key]" class="dh-select">
|
||||
<!-- A non-required select can be left unset (empty), so the global
|
||||
layer abstains and lower layers (org / user) may choose. -->
|
||||
<option v-if="!f.required" value="">{{ t("plugins.notSet") }}</option>
|
||||
|
||||
@@ -293,6 +293,20 @@ body {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px var(--focus-ring);
|
||||
}
|
||||
/* Checkbox for multiselect config fields. accent-color keeps the native control
|
||||
(and its keyboard behaviour) while tinting it to the panel's accent. */
|
||||
.dh-checkbox {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
flex: none;
|
||||
accent-color: var(--accent);
|
||||
cursor: pointer;
|
||||
}
|
||||
.dh-checkbox:focus-visible {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 3px var(--focus-ring);
|
||||
border-radius: 3px;
|
||||
}
|
||||
.dh-label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
|
||||
@@ -661,6 +661,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)",
|
||||
|
||||
@@ -531,6 +531,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)",
|
||||
|
||||
@@ -669,6 +669,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)",
|
||||
|
||||
@@ -998,7 +998,21 @@ class IntegrationScope {
|
||||
final String editableLayer; // "user" | "org"
|
||||
final Map<String, IntegrationField> fields;
|
||||
|
||||
const IntegrationScope({this.editableLayer = "user", this.fields = const {}});
|
||||
/// Anker only. The control modes this scope may still choose — the server has
|
||||
/// already dropped whatever the layers above it hid. Empty for an integration
|
||||
/// that has no such list.
|
||||
final List<String> controlModes;
|
||||
|
||||
/// Anker, org scope only. The modes this organization hides from its own
|
||||
/// users, which its admin edits here.
|
||||
final List<String> controlModesDisabled;
|
||||
|
||||
const IntegrationScope({
|
||||
this.editableLayer = "user",
|
||||
this.fields = const {},
|
||||
this.controlModes = const [],
|
||||
this.controlModesDisabled = const [],
|
||||
});
|
||||
|
||||
factory IntegrationScope.fromJson(Map<String, dynamic> j) {
|
||||
final raw = j["fields"];
|
||||
@@ -1011,6 +1025,8 @@ class IntegrationScope {
|
||||
return IntegrationScope(
|
||||
editableLayer: _asStr(j["editableLayer"]).isEmpty ? "user" : _asStr(j["editableLayer"]),
|
||||
fields: fields,
|
||||
controlModes: _asStrList(j["controlModes"]),
|
||||
controlModesDisabled: _asStrList(j["controlModesDisabled"]),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1547,20 +1547,42 @@ class _DangerSectionState extends State<_DangerSection> {
|
||||
// second "org" scope to edit organization-wide defaults; superadmins manage the
|
||||
// shared layer in the API Server panel, so here it is read-only.
|
||||
|
||||
enum _FieldType { text, number, password, select }
|
||||
enum _FieldType { text, number, password, select, multiselect }
|
||||
|
||||
/// The control modes the server still offers in a scope, and the ones this
|
||||
/// organization hides from its own users. Named functions rather than closures
|
||||
/// so the field specs below can stay const.
|
||||
List<String> _scopeControlModes(IntegrationScope s) => s.controlModes;
|
||||
List<String> _scopeHiddenControlModes(IntegrationScope s) => s.controlModesDisabled;
|
||||
|
||||
/// Describes one credential field within an integration card.
|
||||
class _FieldSpec {
|
||||
final String key;
|
||||
final String labelKey;
|
||||
final _FieldType type;
|
||||
final List<(String, String)> options; // (value, labelKey) for selects
|
||||
final List<(String, String)> options; // (value, labelKey) for select/multiselect
|
||||
final String? placeholder; // literal placeholder
|
||||
final String? hintKey; // shown below the field when not locked
|
||||
final String defaultValue;
|
||||
final bool showEffectiveWhenLocked; // controlMode isn't secret: show it locked
|
||||
final int? maxLength;
|
||||
|
||||
/// Narrows the declared options to those the server still offers in this
|
||||
/// scope — the control-mode hide-list, which is what makes a mode a superadmin
|
||||
/// switched off disappear from an organization's picker, and one an
|
||||
/// organization switched off disappear from its users'. Null leaves every
|
||||
/// declared option standing.
|
||||
final List<String> Function(IntegrationScope)? scopeOptions;
|
||||
|
||||
/// Where a multiselect reads its current value from — a scope list rather than
|
||||
/// a field, because a hide-list is not a cascaded value: it is this layer's
|
||||
/// own instruction to the layers below.
|
||||
final List<String> Function(IntegrationScope)? scopeValue;
|
||||
|
||||
/// Only shown when editing the organization layer. A user has nobody below
|
||||
/// them, so a hide-list would mean nothing there.
|
||||
final bool orgOnly;
|
||||
|
||||
const _FieldSpec({
|
||||
required this.key,
|
||||
required this.labelKey,
|
||||
@@ -1571,6 +1593,9 @@ class _FieldSpec {
|
||||
this.defaultValue = "",
|
||||
this.showEffectiveWhenLocked = false,
|
||||
this.maxLength,
|
||||
this.scopeOptions,
|
||||
this.scopeValue,
|
||||
this.orgOnly = false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1656,6 +1681,7 @@ class _IntegrationsTabState extends State<_IntegrationsTab> {
|
||||
hintKey: "settings.integrations.controlModeHint",
|
||||
defaultValue: "off",
|
||||
showEffectiveWhenLocked: true,
|
||||
scopeOptions: _scopeControlModes,
|
||||
options: [
|
||||
("off", "settings.integrations.controlOff"),
|
||||
("mqtt", "settings.integrations.controlCloud"),
|
||||
@@ -1664,6 +1690,23 @@ class _IntegrationsTabState extends State<_IntegrationsTab> {
|
||||
("proxy", "settings.integrations.controlProxy"),
|
||||
],
|
||||
),
|
||||
// What this organization hides from its own users. Off is absent on
|
||||
// purpose: monitoring only is the fallback, so no layer may take it away.
|
||||
_FieldSpec(
|
||||
key: "controlModesDisabled",
|
||||
labelKey: "settings.integrations.controlModesHidden",
|
||||
type: _FieldType.multiselect,
|
||||
hintKey: "settings.integrations.controlModesHiddenHint",
|
||||
orgOnly: true,
|
||||
scopeOptions: _scopeControlModes,
|
||||
scopeValue: _scopeHiddenControlModes,
|
||||
options: [
|
||||
("mqtt", "settings.integrations.controlCloud"),
|
||||
("modbus", "settings.integrations.controlModbus"),
|
||||
("own", "settings.integrations.controlOwn"),
|
||||
("proxy", "settings.integrations.controlProxy"),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1799,6 +1842,7 @@ class _IntegrationCardState extends State<_IntegrationCard> {
|
||||
|
||||
final Map<String, TextEditingController> _controllers = {};
|
||||
final Map<String, String> _selects = {};
|
||||
final Map<String, Set<String>> _multi = {}; // multiselect fields (hide-lists)
|
||||
|
||||
_IntegrationConfig get _c => widget.config;
|
||||
|
||||
@@ -1806,7 +1850,9 @@ class _IntegrationCardState extends State<_IntegrationCard> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
for (final f in _c.fields) {
|
||||
if (f.type != _FieldType.select) _controllers[f.key] = TextEditingController();
|
||||
if (f.type != _FieldType.select && f.type != _FieldType.multiselect) {
|
||||
_controllers[f.key] = TextEditingController();
|
||||
}
|
||||
}
|
||||
_load();
|
||||
}
|
||||
@@ -1825,6 +1871,25 @@ class _IntegrationCardState extends State<_IntegrationCard> {
|
||||
bool get _readOnly => _view?.isSuperadmin ?? false;
|
||||
IntegrationScope get _scopeData => _view?.scope(_scopeKey) ?? const IntegrationScope();
|
||||
IntegrationField _field(String k) => _scopeData.field(k);
|
||||
|
||||
/// The fields this scope actually shows: an org-only field (a hide-list) is
|
||||
/// out of the user scope, and a field whose options the layers above have all
|
||||
/// hidden has nothing left to offer.
|
||||
List<_FieldSpec> get _shownFields => [
|
||||
for (final f in _c.fields)
|
||||
if ((!f.orgOnly || _editingOrg) && (f.options.isEmpty || _optionsFor(f).isNotEmpty)) f,
|
||||
];
|
||||
|
||||
/// A field's options after the scope's own list has narrowed them.
|
||||
List<(String, String)> _optionsFor(_FieldSpec f) {
|
||||
if (f.scopeOptions == null) return f.options;
|
||||
final allowed = f.scopeOptions!(_scopeData);
|
||||
if (allowed.isEmpty) return f.options;
|
||||
return [
|
||||
for (final o in f.options)
|
||||
if (allowed.contains(o.$1)) o,
|
||||
];
|
||||
}
|
||||
bool _locked(String k) => _readOnly || _field(k).locked;
|
||||
bool get _enabled => _editingOrg ? (_view?.orgEnabled ?? false) : (_view?.enabled ?? false);
|
||||
|
||||
@@ -1839,6 +1904,12 @@ class _IntegrationCardState extends State<_IntegrationCard> {
|
||||
// fields and the secret password are never prefilled.
|
||||
void _fillForm() {
|
||||
for (final f in _c.fields) {
|
||||
if (f.type == _FieldType.multiselect) {
|
||||
// A hide-list is this layer's own, not something inherited, so it comes
|
||||
// from the scope rather than from a cascaded field.
|
||||
_multi[f.key] = {...?f.scopeValue?.call(_scopeData)};
|
||||
continue;
|
||||
}
|
||||
final field = _field(f.key);
|
||||
String value;
|
||||
if (f.type == _FieldType.password) {
|
||||
@@ -1851,7 +1922,11 @@ class _IntegrationCardState extends State<_IntegrationCard> {
|
||||
value = field.own.isNotEmpty ? field.own : f.defaultValue;
|
||||
}
|
||||
if (f.type == _FieldType.select) {
|
||||
_selects[f.key] = value;
|
||||
// A stored mode the layers above have since hidden is no longer on
|
||||
// offer, so the picker starts from the default instead of showing a
|
||||
// choice that would not take effect anyway.
|
||||
final options = _optionsFor(f);
|
||||
_selects[f.key] = options.any((o) => o.$1 == value) ? value : f.defaultValue;
|
||||
} else {
|
||||
_controllers[f.key]!.text = value;
|
||||
}
|
||||
@@ -1896,9 +1971,19 @@ class _IntegrationCardState extends State<_IntegrationCard> {
|
||||
_saved = false;
|
||||
});
|
||||
final config = <String, dynamic>{};
|
||||
for (final f in _c.fields) {
|
||||
for (final f in _shownFields) {
|
||||
if (_locked(f.key)) continue;
|
||||
final val = f.type == _FieldType.select ? (_selects[f.key] ?? "") : _controllers[f.key]!.text;
|
||||
final String val;
|
||||
switch (f.type) {
|
||||
case _FieldType.multiselect:
|
||||
// The server stores a hide-list as the same comma-separated string the
|
||||
// API Server panel writes, so both layers round-trip identically.
|
||||
val = _optionsFor(f).map((o) => o.$1).where(_multi[f.key]!.contains).join(",");
|
||||
case _FieldType.select:
|
||||
val = _selects[f.key] ?? "";
|
||||
default:
|
||||
val = _controllers[f.key]!.text;
|
||||
}
|
||||
if (f.type == _FieldType.password && val.isEmpty) continue;
|
||||
config[f.key] = val;
|
||||
}
|
||||
@@ -2058,7 +2143,7 @@ class _IntegrationCardState extends State<_IntegrationCard> {
|
||||
),
|
||||
|
||||
// Credential fields.
|
||||
for (final f in _c.fields) ...[
|
||||
for (final f in _shownFields) ...[
|
||||
const SizedBox(height: 12),
|
||||
_fieldWidget(f),
|
||||
],
|
||||
@@ -2146,12 +2231,51 @@ class _IntegrationCardState extends State<_IntegrationCard> {
|
||||
final field = _field(f.key);
|
||||
|
||||
Widget input;
|
||||
if (f.type == _FieldType.select) {
|
||||
final options = _optionsFor(f);
|
||||
if (f.type == _FieldType.multiselect) {
|
||||
final chosen = _multi[f.key] ??= {};
|
||||
input = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final o in options)
|
||||
InkWell(
|
||||
onTap: locked
|
||||
? null
|
||||
: () => setState(() {
|
||||
if (!chosen.remove(o.$1)) chosen.add(o.$1);
|
||||
}),
|
||||
child: Row(children: [
|
||||
Checkbox(
|
||||
value: chosen.contains(o.$1),
|
||||
visualDensity: VisualDensity.compact,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
onChanged: locked
|
||||
? null
|
||||
: (v) => setState(() {
|
||||
if (v ?? false) {
|
||||
chosen.add(o.$1);
|
||||
} else {
|
||||
chosen.remove(o.$1);
|
||||
}
|
||||
}),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(child: Text(t(o.$2), style: const TextStyle(fontSize: 14))),
|
||||
]),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (f.type == _FieldType.select) {
|
||||
// A mode hidden above is gone from the list, so a stored value naming one
|
||||
// has nothing to select — fall back to the default rather than crashing
|
||||
// the dropdown on a value it does not carry.
|
||||
final current = _selects[f.key] ?? f.defaultValue;
|
||||
final value = options.any((o) => o.$1 == current) ? current : f.defaultValue;
|
||||
input = DropdownButtonFormField<String>(
|
||||
initialValue: _selects[f.key] ?? f.defaultValue,
|
||||
initialValue: value,
|
||||
decoration: const InputDecoration(border: OutlineInputBorder(), isDense: true),
|
||||
items: [
|
||||
for (final o in f.options) DropdownMenuItem(value: o.$1, child: Text(t(o.$2))),
|
||||
for (final o in options) DropdownMenuItem(value: o.$1, child: Text(t(o.$2))),
|
||||
],
|
||||
onChanged: locked ? null : (v) => setState(() => _selects[f.key] = v ?? ""),
|
||||
);
|
||||
|
||||
@@ -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