feat(ui/templates): structured trigger editor for template scripts
The script add/edit modal exposed a script's trigger as two raw free-text inputs — a type string and hand-written config JSON — with no validation and no parity with the alarm trigger UI. Replace them with a ScriptTriggerEditor component (mirroring AlarmTriggerEditor): a trigger-type dropdown plus type-specific panels for Interval, ValueChange, Conditional, and Call, a grouped attribute picker, and an auto-generated hint. A ScriptTriggerConfigCodec round-trips the TriggerConfiguration JSON the site runtime's ScriptActor consumes, tolerant of legacy keys; an unrecognized stored type is preserved untouched in a read-only panel.
This commit is contained in:
@@ -874,13 +874,12 @@
|
||||
<label class="form-label">Name</label>
|
||||
<input type="text" class="form-control" @bind="_scriptName" readonly="@editingScript" />
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Trigger Type</label>
|
||||
<input type="text" class="form-control" @bind="_scriptTriggerType" placeholder="e.g. ValueChange" />
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Trigger Config (JSON)</label>
|
||||
<input type="text" class="form-control" @bind="_scriptTriggerConfig" />
|
||||
<div class="col-12">
|
||||
<label class="form-label">Trigger</label>
|
||||
<ScriptTriggerEditor TriggerType="@_scriptTriggerType"
|
||||
TriggerConfig="@_scriptTriggerConfig"
|
||||
Changed="@OnScriptTriggerChanged"
|
||||
AvailableAttributes="@BuildAlarmAttributeChoices()" />
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<div class="form-check">
|
||||
@@ -1456,6 +1455,13 @@
|
||||
else { _toast.ShowError(result.Error); }
|
||||
}
|
||||
|
||||
/// <summary>Applies the structured trigger editor's type + config atomically.</summary>
|
||||
private void OnScriptTriggerChanged(ScriptTriggerValue v)
|
||||
{
|
||||
_scriptTriggerType = v.TriggerType;
|
||||
_scriptTriggerConfig = v.Config;
|
||||
}
|
||||
|
||||
private void BeginAddScript()
|
||||
{
|
||||
_showScriptForm = true;
|
||||
|
||||
Reference in New Issue
Block a user