trigger editor

This commit is contained in:
2023-10-12 23:27:04 +02:00
parent e06cf1ae34
commit 16e5726cbc
15 changed files with 410 additions and 45 deletions
+13 -3
View File
@@ -12,9 +12,10 @@ import (
)
type Data struct {
Devices map[string]Device `json:"devices"`
Assignments map[uuid.UUID]Assignment `json:"assignments"`
Scripts map[string][]script.Line `json:"scripts"`
Devices map[string]Device `json:"devices"`
Assignments map[uuid.UUID]Assignment `json:"assignments"`
Scripts map[string][]script.Line `json:"scripts"`
Triggers map[uuid.UUID]script.Trigger `json:"triggers"`
}
func (d *Data) WithPatch(patches ...Patch) Data {
@@ -121,6 +122,14 @@ func (d *Data) WithPatch(patches ...Patch) Data {
delete(newData.Scripts, patch.Script.Name)
}
}
if patch.Trigger != nil {
if !patch.Trigger.Delete {
newData.Triggers[patch.Trigger.ID] = patch.Trigger.Trigger
} else {
delete(newData.Triggers, patch.Trigger.ID)
}
}
}
return newData
@@ -131,6 +140,7 @@ func (d *Data) Copy() Data {
Devices: gentools.CopyMap(d.Devices),
Assignments: gentools.CopyMap(d.Assignments),
Scripts: gentools.CopyMap(d.Scripts),
Triggers: gentools.CopyMap(d.Triggers),
}
}
+6
View File
@@ -14,6 +14,7 @@ type Patch struct {
Assignment *AssignmentPatch `json:"assignment,omitempty"`
Device *DevicePatch `json:"device,omitempty"`
Script *ScriptPatch `json:"script,omitempty"`
Trigger *TriggerPatch `json:"trigger,omitempty"`
}
func (e Patch) VerboseKey() string {
@@ -83,3 +84,8 @@ type ScriptPatch struct {
Name string
Lines []script.Line
}
type TriggerPatch struct {
script.Trigger
Delete bool `json:"delete,omitempty"`
}
+12
View File
@@ -18,6 +18,7 @@ func NewService() lucifer3.ActiveService {
Devices: map[string]Device{},
Assignments: map[uuid.UUID]Assignment{},
Scripts: map[string][]script.Line{},
Triggers: map[uuid.UUID]script.Trigger{},
},
}
}
@@ -66,6 +67,17 @@ func (s *service) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command
patches = append(patches, Patch{
Script: &ScriptPatch{Name: command.Name, Lines: command.Lines},
})
case script.UpdateTrigger:
patches = append(patches, Patch{
Trigger: &TriggerPatch{Trigger: script.Trigger(command)},
})
case script.DeleteTrigger:
patches = append(patches, Patch{
Trigger: &TriggerPatch{
Trigger: script.Trigger{ID: command.ID},
Delete: true,
},
})
}
if len(patches) > 0 {