From df9707309f666769e83d05b1875e675eab5d20aa Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 13 Nov 2023 17:29:53 -0700 Subject: [PATCH] Added time to event_ext.UpdateState, added event start time to gql --- event.go | 6 ++++-- gql.go | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/event.go b/event.go index f4d0882..0f99a1c 100644 --- a/event.go +++ b/event.go @@ -45,6 +45,7 @@ var DefaultEventPolicy = NewParentOfPolicy(Tree{ type EventExt struct { Name string `gv:"name"` State EventState `gv:"state"` + StateStart time.Time `gv:"state_start"` 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 { + ext.StateStart = state_start changes.Add(EventExtType, "state") ext.State = state 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": 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)) } } diff --git a/gql.go b/gql.go index d271890..c493c56 100644 --- a/gql.go +++ b/gql.go @@ -1300,12 +1300,17 @@ func NewGQLExtContext() *GQLExtContext { 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) { state := val.String() 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 { panic(err) }