adsa-cms: github.com/mmanjoura/adsa-cms/transition Index | Files

package transition

import "github.com/mmanjoura/adsa-cms/transition"

Index

Package Files

state_change_log.go transition.go

func GenerateReferenceKey Uses

func GenerateReferenceKey(model interface{}, db *gorm.DB) string

GenerateReferenceKey generate reference key used for change log

func GetStateChangeLogs Uses

func GetStateChangeLogs(model interface{}, db *gorm.DB) []StateChangeLog

GetStateChangeLogs get state change logs

type Event Uses

type Event struct {
    Name string
    // contains filtered or unexported fields
}

Event contains Event information, including transition hooks

func (*Event) To Uses

func (event *Event) To(name string) *EventTransition

To define EventTransition of go to a state

type EventTransition Uses

type EventTransition struct {
    // contains filtered or unexported fields
}

EventTransition hold event's to/froms states, also including befores, afters hooks

func (*EventTransition) After Uses

func (transition *EventTransition) After(fc func(value interface{}, tx *gorm.DB) error) *EventTransition

After register after hooks

func (*EventTransition) Before Uses

func (transition *EventTransition) Before(fc func(value interface{}, tx *gorm.DB) error) *EventTransition

Before register before hooks

func (*EventTransition) From Uses

func (transition *EventTransition) From(states ...string) *EventTransition

From used to define from states

type State Uses

type State struct {
    Name string
    // contains filtered or unexported fields
}

State contains State information, including enter, exit hooks

func (*State) Enter Uses

func (state *State) Enter(fc func(value interface{}, tx *gorm.DB) error) *State

Enter register an enter hook for State

func (*State) Exit Uses

func (state *State) Exit(fc func(value interface{}, tx *gorm.DB) error) *State

Exit register an exit hook for State

type StateChangeLog Uses

type StateChangeLog struct {
    gorm.Model
    ReferTable string
    ReferID    string
    From       string
    To         string
    Note       string `sql:"size:1024"`
    audited.AuditedModel
}

StateChangeLog a model that used to keep state change logs

func (*StateChangeLog) ConfigureQorResource Uses

func (stageChangeLog *StateChangeLog) ConfigureQorResource(res resource.Resourcer)

ConfigureQorResource used to configure transition for qor admin

type StateMachine Uses

type StateMachine struct {
    // contains filtered or unexported fields
}

StateMachine a struct that hold states, events definitions

func New Uses

func New(value interface{}) *StateMachine

New initialize a new StateMachine that hold states, events definitions

func (*StateMachine) Event Uses

func (sm *StateMachine) Event(name string) *Event

Event define an event

func (*StateMachine) Initial Uses

func (sm *StateMachine) Initial(name string) *StateMachine

Initial define the initial state

func (*StateMachine) State Uses

func (sm *StateMachine) State(name string) *State

State define a state

func (*StateMachine) Trigger Uses

func (sm *StateMachine) Trigger(name string, value Stater, tx *gorm.DB, notes ...string) error

Trigger trigger an event

type Stater Uses

type Stater interface {
    SetState(name string)
    GetState() string
}

Stater is a interface including methods `GetState`, `SetState`

type Transition Uses

type Transition struct {
    State           string
    StateChangeLogs []StateChangeLog `sql:"-"`
}

Transition is a struct, embed it in your struct to enable state machine for the struct

func (*Transition) ConfigureQorResource Uses

func (transition *Transition) ConfigureQorResource(res resource.Resourcer)

ConfigureQorResource used to configure transition for qor admin

func (Transition) GetState Uses

func (transition Transition) GetState() string

GetState get current state from

func (*Transition) SetState Uses

func (transition *Transition) SetState(name string)

SetState set state to Stater, just set, won't save it into database

Package transition imports 7 packages (graph) and is imported by 3 packages. Updated 2017-06-08. Refresh now. Tools for package owners.