Added time to event_ext.UpdateState, added event start time to gql

gql_cataclysm
noah metz 2023-11-13 17:29:53 -07:00
parent 646e6592f0
commit df9707309f
2 changed files with 10 additions and 3 deletions

@ -45,6 +45,7 @@ var DefaultEventPolicy = NewParentOfPolicy(Tree{
type EventExt struct { type EventExt struct {
Name string `gv:"name"` Name string `gv:"name"`
State EventState `gv:"state"` State EventState `gv:"state"`
StateStart time.Time `gv:"state_start"`
Parent NodeID `gv:"parent"` Parent NodeID `gv:"parent"`
} }
@ -106,8 +107,9 @@ func (signal EventControlSignal) Permission() Tree {
} }
} }
func (ext *EventExt) UpdateState(node *Node, changes Changes, state EventState) { func (ext *EventExt) UpdateState(node *Node, changes Changes, state EventState, state_start time.Time) {
if ext.State != state { if ext.State != state {
ext.StateStart = state_start
changes.Add(EventExtType, "state") changes.Add(EventExtType, "state")
ext.State = state ext.State = state
node.QueueSignal(time.Now(), NewEventStateSignal(node.ID, ext.State, time.Now())) node.QueueSignal(time.Now(), NewEventStateSignal(node.ID, ext.State, time.Now()))
@ -168,7 +170,7 @@ func (ext *TestEventExt) Process(ctx *Context, node *Node, source NodeID, signal
case "start": case "start":
node.QueueSignal(time.Now().Add(ext.Length), NewEventControlSignal("finish")) node.QueueSignal(time.Now().Add(ext.Length), NewEventControlSignal("finish"))
} }
event_ext.UpdateState(node, changes, new_state) event_ext.UpdateState(node, changes, new_state, time.Now())
messages = messages.Add(ctx, source, node, nil, NewSuccessSignal(sig.Id)) messages = messages.Add(ctx, source, node, nil, NewSuccessSignal(sig.Id))
} }
} }

@ -1300,12 +1300,17 @@ func NewGQLExtContext() *GQLExtContext {
return name, nil return name, nil
}) })
err = context.RegisterField(graphql.String, "EventStateStart", EventExtType, "state_start", func(p graphql.ResolveParams, ctx *ResolveContext, val reflect.Value)(interface{}, error) {
state_start := val.Interface().(time.Time)
return state_start, nil
})
err = context.RegisterField(graphql.String, "EventState", EventExtType, "state", func(p graphql.ResolveParams, ctx *ResolveContext, val reflect.Value)(interface{}, error) { err = context.RegisterField(graphql.String, "EventState", EventExtType, "state", func(p graphql.ResolveParams, ctx *ResolveContext, val reflect.Value)(interface{}, error) {
state := val.String() state := val.String()
return state, nil return state, nil
}) })
err = context.RegisterInterface("Event", "EventNode", []string{"Node"}, []string{"EventName", "EventState"}, map[string]SelfField{}, map[string]ListField{}) err = context.RegisterInterface("Event", "EventNode", []string{"Node"}, []string{"EventName", "EventStateStart", "EventState"}, map[string]SelfField{}, map[string]ListField{})
if err != nil { if err != nil {
panic(err) panic(err)
} }