undo

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package undo provides undo/redo functionality for LacyLights operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BulkFixturePositionSnapshot

type BulkFixturePositionSnapshot struct {
	Positions []FixturePositionEntry `json:"positions"`
}

BulkFixturePositionSnapshot captures multiple fixture positions for undo/redo.

type BulkLookUpdateSnapshot

type BulkLookUpdateSnapshot struct {
	Looks []LookSnapshot `json:"looks"`
}

BulkLookUpdateSnapshot captures multiple looks' state for atomic undo. Used by copyFixturesToLooks to restore all target looks in a single undo operation.

type CueEffectSnapshot

type CueEffectSnapshot struct {
	CueEffect *models.CueEffect `json:"cueEffect"`
	CueID     string            `json:"cueId"`
	EffectID  string            `json:"effectId"`
	ProjectID string            `json:"projectId"`
}

CueEffectSnapshot captures the state of a cue-effect relationship.

type CueListSnapshot

type CueListSnapshot struct {
	CueList *models.CueList `json:"cueList"`
	Cues    []models.Cue    `json:"cues"`
}

CueListSnapshot captures the complete state of a cue list.

type CuePlaybackSnapshot

type CuePlaybackSnapshot struct {
	CueListID   string   `json:"cueListId"`
	ProjectID   string   `json:"projectId"`
	CueID       *string  `json:"cueId,omitempty"`      // nil if not playing
	CueNumber   *float64 `json:"cueNumber,omitempty"`  // nil if not playing
	CueName     *string  `json:"cueName,omitempty"`    // for description purposes
	FadeInTime  *float64 `json:"fadeInTime,omitempty"` // the fade time to use when restoring
	IsPlaying   bool     `json:"isPlaying"`
	CueListName string   `json:"cueListName,omitempty"` // for description purposes
}

CuePlaybackSnapshot captures the playback state for undo/redo. This tracks which cue was playing (or if playback was stopped).

type CueSnapshot

type CueSnapshot struct {
	Cue *models.Cue `json:"cue"`
}

CueSnapshot captures the complete state of a cue.

type EffectSnapshot

type EffectSnapshot struct {
	Effect         *models.Effect         `json:"effect"`
	EffectFixtures []models.EffectFixture `json:"effectFixtures"`
	EffectChannels []models.EffectChannel `json:"effectChannels"`
}

EffectSnapshot captures the complete state of an effect.

type EntityType

type EntityType string

EntityType represents the type of entity being operated on.

const (
	EntityTypeLook                EntityType = "Look"
	EntityTypeFixtureInstance     EntityType = "FixtureInstance"
	EntityTypeCue                 EntityType = "Cue"
	EntityTypeCueList             EntityType = "CueList"
	EntityTypeLookBoard           EntityType = "LookBoard"
	EntityTypeLookBoardButton     EntityType = "LookBoardButton"
	EntityTypeEffect              EntityType = "Effect"
	EntityTypeCueEffect           EntityType = "CueEffect"
	EntityTypeProject             EntityType = "Project"
	EntityTypeCuePlayback         EntityType = "CuePlayback"
	EntityTypeBulkFixturePosition EntityType = "BulkFixturePosition"
	EntityTypeBulkLookUpdate      EntityType = "BulkLookUpdate"
)

type FixtureInstanceSnapshot

type FixtureInstanceSnapshot struct {
	Fixture  *models.FixtureInstance  `json:"fixture"`
	Channels []models.InstanceChannel `json:"channels"`
}

FixtureInstanceSnapshot captures the complete state of a fixture instance.

type FixturePositionEntry

type FixturePositionEntry struct {
	FixtureID      string   `json:"fixtureId"`
	FixtureName    string   `json:"fixtureName"`
	LayoutX        *float64 `json:"layoutX,omitempty"`
	LayoutY        *float64 `json:"layoutY,omitempty"`
	LayoutRotation *float64 `json:"layoutRotation,omitempty"`
}

FixturePositionEntry captures a single fixture's position for bulk operations.

type LookBoardSnapshot

type LookBoardSnapshot struct {
	LookBoard *models.LookBoard        `json:"lookBoard"`
	Buttons   []models.LookBoardButton `json:"buttons"`
}

LookBoardSnapshot captures the complete state of a look board.

type LookSnapshot

type LookSnapshot struct {
	Look          *models.Look          `json:"look"`
	FixtureValues []models.FixtureValue `json:"fixtureValues"`
}

LookSnapshot captures the complete state of a look for undo/redo.

type OperationType

type OperationType string

OperationType represents the type of operation performed.

const (
	OperationTypeCreate OperationType = "CREATE"
	OperationTypeUpdate OperationType = "UPDATE"
	OperationTypeDelete OperationType = "DELETE"
	OperationTypeBulk   OperationType = "BULK"
)

type PlaybackController

type PlaybackController interface {
	// GoToCueNumber jumps to a specific cue by number with optional fade time override.
	GoToCueNumber(ctx context.Context, cueListID string, cueNumber float64, fadeInTimeOverride *float64) error
	// StopCueList stops playback for a cue list.
	StopCueList(cueListID string)
}

PlaybackController defines the interface for playback operations needed by undo. This avoids circular dependencies with the playback package.

type Service

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

Service provides undo/redo functionality.

func NewService

NewService creates a new undo service.

func (*Service) CaptureBulkLookState

func (s *Service) CaptureBulkLookState(ctx context.Context, lookIDs []string) (*BulkLookUpdateSnapshot, error)

CaptureBulkLookState captures the complete state of multiple looks for atomic undo. Used by copyFixturesToLooks to enable single-undo for multi-look updates.

func (*Service) CaptureCueEffectState

func (s *Service) CaptureCueEffectState(ctx context.Context, cueID, effectID string) (*CueEffectSnapshot, error)

CaptureCueEffectState captures the state of a cue-effect relationship for undo.

func (*Service) CaptureCueListState

func (s *Service) CaptureCueListState(ctx context.Context, cueListID string) (*CueListSnapshot, error)

CaptureCueListState captures the complete state of a cue list for undo.

func (*Service) CaptureCueState

func (s *Service) CaptureCueState(ctx context.Context, cueID string) (*CueSnapshot, error)

CaptureCueState captures the complete state of a cue for undo.

func (*Service) CaptureEffectState

func (s *Service) CaptureEffectState(ctx context.Context, effectID string) (*EffectSnapshot, error)

CaptureEffectState captures the complete state of an effect for undo. This includes all EffectFixtures and their EffectChannels.

func (*Service) CaptureFixturePositions

func (s *Service) CaptureFixturePositions(ctx context.Context, fixtureIDs []string) (*BulkFixturePositionSnapshot, error)

CaptureFixturePositions captures positions of multiple fixtures for bulk undo.

func (*Service) CaptureFixtureState

func (s *Service) CaptureFixtureState(ctx context.Context, fixtureID string) (*FixtureInstanceSnapshot, error)

CaptureFixtureState captures the complete state of a fixture instance for undo.

func (*Service) CaptureLookBoardState

func (s *Service) CaptureLookBoardState(ctx context.Context, lookBoardID string) (*LookBoardSnapshot, error)

CaptureLookBoardState captures the complete state of a look board for undo.

func (*Service) CaptureLookState

func (s *Service) CaptureLookState(ctx context.Context, lookID string) (*LookSnapshot, error)

CaptureLookState captures the complete state of a look for undo.

func (*Service) ClearHistory

func (s *Service) ClearHistory(ctx context.Context, projectID string) error

ClearHistory removes all operation history for a project.

func (*Service) DeleteEntityForUndo

func (s *Service) DeleteEntityForUndo(ctx context.Context, entityType EntityType, entityID string) error

DeleteEntityForUndo handles deletion during undo of a CREATE operation.

func (*Service) GetOperationHistory

func (s *Service) GetOperationHistory(ctx context.Context, projectID string, page, perPage int) ([]models.Operation, int64, error)

GetOperationHistory returns paginated operation history for a project.

func (*Service) GetStatus

func (s *Service) GetStatus(ctx context.Context, projectID string) (*repositories.UndoRedoStatus, error)

GetStatus returns the current undo/redo status for a project.

func (*Service) JumpToOperation

func (s *Service) JumpToOperation(ctx context.Context, projectID, operationID string) (*UndoRedoResult, error)

JumpToOperation moves to a specific operation in the history. This applies or reverts operations to reach the target sequence.

func (*Service) RecordOperation

func (s *Service) RecordOperation(
	ctx context.Context,
	projectID string,
	opType OperationType,
	entityType EntityType,
	entityID string,
	description string,
	prevState interface{},
	newState interface{},
	relatedIDs []string,
) error

RecordOperation records an operation for undo/redo. prevState and newState should be snapshot structs (e.g., LookSnapshot). relatedIDs is used for bulk operations to track all affected entity IDs.

func (*Service) Redo

func (s *Service) Redo(ctx context.Context, projectID string) (*UndoRedoResult, error)

Redo re-applies the last undone operation for a project. This uses an atomic pattern: get operation, apply snapshot, then confirm pointer update. If the snapshot fails to apply, the pointer is not modified.

func (*Service) SetPlaybackController

func (s *Service) SetPlaybackController(pc PlaybackController)

SetPlaybackController sets the playback controller for cue playback undo/redo. This is called after initialization to avoid circular dependencies.

func (*Service) Undo

func (s *Service) Undo(ctx context.Context, projectID string) (*UndoRedoResult, error)

Undo reverts the last operation for a project. This uses an atomic pattern: get operation, apply snapshot, then confirm pointer update. If the snapshot fails to apply, the pointer is not modified.

type UndoRedoResult

type UndoRedoResult struct {
	Success          bool
	Operation        *models.Operation
	Message          string
	RestoredEntityID string
}

UndoRedoResult contains the result of an undo or redo operation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL