dynamic

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package dynamic provides dynamic component rendering and field handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallWebhookHandler

func CallWebhookHandler(ctx *WorkflowContext, action Action) error

CallWebhookHandler calls an external webhook.

func CreateRecordHandler

func CreateRecordHandler(ctx *WorkflowContext, action Action) error

CreateRecordHandler creates a new record.

func DeleteRecordHandler

func DeleteRecordHandler(ctx *WorkflowContext, action Action) error

DeleteRecordHandler soft deletes a record.

func SendEmailHandler

func SendEmailHandler(ctx *WorkflowContext, action Action) error

SendEmailHandler sends an email notification.

func UpdateFieldHandler

func UpdateFieldHandler(ctx *WorkflowContext, action Action) error

UpdateFieldHandler updates a field value.

Types

type Action

type Action struct {
	Type   string                 `json:"type" yaml:"type"` // update_field, send_email, call_webhook, create_record, delete_record
	Config map[string]interface{} `json:"config" yaml:"config"`
	Order  int                    `json:"order" yaml:"order"`
}

Action defines what happens when a workflow executes.

type ColumnInfo

type ColumnInfo struct {
	Name         string
	DataType     string
	IsNullable   bool
	DefaultValue *string
	MaxLength    int
	Comment      string
	IsPrimaryKey bool
	IsUnique     bool
	IsForeignKey bool
}

ColumnInfo represents database column information.

type ComputedField

type ComputedField struct {
	Name         string `yaml:"name"`
	Label        string `yaml:"label"`
	ShowInList   bool   `yaml:"show_in_list"`
	ShowInForm   bool   `yaml:"show_in_form"`
	Lambda       string `yaml:"lambda"`        // JavaScript lambda function
	ListPosition int    `yaml:"list_position"` // Optional position in list view
}

ComputedField represents a computed field that's not directly from the database.

type Condition

type Condition struct {
	Type     string                 `json:"type" yaml:"type"` // field_value, field_change, time_based, record_count
	Field    string                 `json:"field,omitempty" yaml:"field,omitempty"`
	Operator string                 `json:"operator" yaml:"operator"` // equals, not_equals, contains, greater_than, less_than
	Value    interface{}            `json:"value" yaml:"value"`
	Config   map[string]interface{} `json:"config,omitempty" yaml:"config,omitempty"`
}

Condition defines requirements for workflow execution.

type ConstraintInfo

type ConstraintInfo struct {
	Name       string
	Type       string
	ColumnName string
}

ConstraintInfo represents database constraint information.

type DynamicModuleHandler

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

DynamicModuleHandler handles all dynamic modules.

func NewDynamicModuleHandler

func NewDynamicModuleHandler(db *sql.DB, renderer *pongo2.TemplateSet, modulesPath string) (*DynamicModuleHandler, error)

NewDynamicModuleHandler creates a new dynamic module handler.

func (*DynamicModuleHandler) Close

func (h *DynamicModuleHandler) Close()

Close closes the lambda engine.

func (*DynamicModuleHandler) GetAvailableModules

func (h *DynamicModuleHandler) GetAvailableModules() []string

GetAvailableModules returns list of loaded modules.

func (*DynamicModuleHandler) ServeModule

func (h *DynamicModuleHandler) ServeModule(c *gin.Context)

ServeModule handles requests for any dynamic module.

type Field

type Field struct {
	Name            string         `yaml:"name"`
	Type            string         `yaml:"type"`
	DBColumn        string         `yaml:"db_column"`
	Label           string         `yaml:"label"`
	Required        bool           `yaml:"required"`
	Searchable      bool           `yaml:"searchable"`
	Sortable        bool           `yaml:"sortable"`
	ShowInList      bool           `yaml:"show_in_list"`
	ShowInForm      bool           `yaml:"show_in_form"`
	Default         interface{}    `yaml:"default"`
	Options         []Option       `yaml:"options"`
	Validation      string         `yaml:"validation"`
	Help            string         `yaml:"help"`
	Placeholder     string         `yaml:"placeholder"`
	ListPosition    int            `yaml:"list_position"`
	Filterable      bool           `yaml:"filterable"`
	LookupTable     string         `yaml:"lookup_table"`
	LookupKey       string         `yaml:"lookup_key"`
	LookupDisplay   string         `yaml:"lookup_display"`
	LookupCondition string         `yaml:"lookup_condition"`
	Widget          string         `yaml:"widget"`
	DisplayAs       string         `yaml:"display_as"`
	DisplayMap      map[int]string `yaml:"display_map"`
	Virtual         bool           `yaml:"virtual"`
}

Field represents a field in the module.

type Filter

type Filter struct {
	Field         string         `yaml:"field" json:"field"`
	Type          string         `yaml:"type" json:"type"`
	Label         string         `yaml:"label" json:"label"`
	Source        string         `yaml:"source" json:"source"`
	Query         string         `yaml:"query" json:"query"`
	LookupTable   string         `yaml:"lookup_table" json:"lookup_table"`
	LookupKey     string         `yaml:"lookup_key" json:"lookup_key"`
	LookupDisplay string         `yaml:"lookup_display" json:"lookup_display"`
	Options       []FilterOption `yaml:"options" json:"options"`
}

Filter represents a filter configuration.

type FilterOption

type FilterOption struct {
	Value string `yaml:"value" json:"value"`
	Label string `yaml:"label" json:"label"`
}

FilterOption represents an option in a filter dropdown.

type ModuleConfig

type ModuleConfig struct {
	Module struct {
		Name        string `yaml:"name"`
		Singular    string `yaml:"singular"`
		Plural      string `yaml:"plural"`
		Table       string `yaml:"table"`
		Description string `yaml:"description"`
		RoutePrefix string `yaml:"route_prefix"`
		ReadOnly    bool   `yaml:"read_only"`
	} `yaml:"module"`

	Fields []Field `yaml:"fields"`

	ComputedFields []ComputedField `yaml:"computed_fields"`

	Features struct {
		SoftDelete   bool `yaml:"soft_delete"`
		Search       bool `yaml:"search"`
		ImportCSV    bool `yaml:"import_csv"`
		ExportCSV    bool `yaml:"export_csv"`
		StatusToggle bool `yaml:"status_toggle"`
		ColorPicker  bool `yaml:"color_picker"`
	} `yaml:"features"`

	Permissions []string `yaml:"permissions"`

	Validation struct {
		UniqueFields []string `yaml:"unique_fields"`
		Required     []string `yaml:"required_fields"`
	} `yaml:"validation"`

	UI struct {
		ListColumns []string `yaml:"list_columns" json:"list_columns"`
	} `yaml:"ui" json:"ui"`

	Filters []Filter `yaml:"filters" json:"filters"`

	LambdaConfig lambda.LambdaConfig `yaml:"lambda_config" json:"lambda_config"`
}

ModuleConfig represents a module's configuration.

type Option

type Option struct {
	Value string `yaml:"value"`
	Label string `yaml:"label"`
	Group string `yaml:"group,omitempty"`
}

Option for select fields.

type SchemaDiscovery

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

SchemaDiscovery handles database schema introspection.

func NewSchemaDiscovery

func NewSchemaDiscovery(db *sql.DB) *SchemaDiscovery

NewSchemaDiscovery creates a new schema discovery instance.

func (*SchemaDiscovery) GenerateModuleConfig

func (sd *SchemaDiscovery) GenerateModuleConfig(tableName string) (*ModuleConfig, error)

GenerateModuleConfig generates a ModuleConfig from database schema.

func (*SchemaDiscovery) GetTableColumns

func (sd *SchemaDiscovery) GetTableColumns(tableName string) ([]ColumnInfo, error)

GetTableColumns retrieves column information for a specific table.

func (*SchemaDiscovery) GetTableConstraints

func (sd *SchemaDiscovery) GetTableConstraints(tableName string) ([]ConstraintInfo, error)

GetTableConstraints retrieves constraint information for a table.

func (*SchemaDiscovery) GetTables

func (sd *SchemaDiscovery) GetTables() ([]TableInfo, error)

GetTables retrieves all tables from the database.

func (*SchemaDiscovery) InferFieldType

func (sd *SchemaDiscovery) InferFieldType(columnName, dataType string) string

InferFieldType infers the appropriate field type from column name and data type.

type TableInfo

type TableInfo struct {
	Name    string
	Comment string
}

TableInfo represents database table information.

type Trigger

type Trigger struct {
	Type     string                 `json:"type" yaml:"type"` // schedule, event, webhook, manual
	Config   map[string]interface{} `json:"config" yaml:"config"`
	Schedule string                 `json:"schedule,omitempty" yaml:"schedule,omitempty"` // Cron expression
	Event    string                 `json:"event,omitempty" yaml:"event,omitempty"`       // create, update, delete
}

Trigger defines when a workflow should execute.

type Workflow

type Workflow struct {
	ID          string                 `json:"id" yaml:"id"`
	Name        string                 `json:"name" yaml:"name"`
	Module      string                 `json:"module" yaml:"module"`
	Description string                 `json:"description" yaml:"description"`
	Enabled     bool                   `json:"enabled" yaml:"enabled"`
	Triggers    []Trigger              `json:"triggers" yaml:"triggers"`
	Conditions  []Condition            `json:"conditions" yaml:"conditions"`
	Actions     []Action               `json:"actions" yaml:"actions"`
	Metadata    map[string]interface{} `json:"metadata" yaml:"metadata"`
}

Workflow represents an automated workflow configuration.

type WorkflowContext

type WorkflowContext struct {
	Workflow  *Workflow
	Module    string
	Record    map[string]interface{}
	OldRecord map[string]interface{} // For update triggers
	Variables map[string]interface{}
	StartTime time.Time
	Logs      []string
}

WorkflowContext provides context for workflow execution.

func (*WorkflowContext) Log

func (ctx *WorkflowContext) Log(message string)

Log adds a log entry to the workflow context.

type WorkflowEngine

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

WorkflowEngine manages automated workflows for dynamic modules.

func NewWorkflowEngine

func NewWorkflowEngine(db interface{}) *WorkflowEngine

NewWorkflowEngine creates a new workflow engine.

func (*WorkflowEngine) ExecuteWorkflow

func (we *WorkflowEngine) ExecuteWorkflow(workflowID string, record map[string]interface{}) error

ExecuteWorkflow executes a workflow.

func (*WorkflowEngine) HandleWorkflowCreate

func (we *WorkflowEngine) HandleWorkflowCreate(c *gin.Context)

HandleWorkflowCreate creates a new workflow.

func (*WorkflowEngine) HandleWorkflowDelete

func (we *WorkflowEngine) HandleWorkflowDelete(c *gin.Context)

HandleWorkflowDelete deletes a workflow.

func (*WorkflowEngine) HandleWorkflowExecute

func (we *WorkflowEngine) HandleWorkflowExecute(c *gin.Context)

HandleWorkflowExecute manually executes a workflow.

func (*WorkflowEngine) HandleWorkflowList

func (we *WorkflowEngine) HandleWorkflowList(c *gin.Context)

HandleWorkflowList lists all workflows.

func (*WorkflowEngine) HandleWorkflowToggle

func (we *WorkflowEngine) HandleWorkflowToggle(c *gin.Context)

HandleWorkflowToggle enables/disables a workflow.

func (*WorkflowEngine) RegisterHandler

func (we *WorkflowEngine) RegisterHandler(actionType string, handler WorkflowHandler)

RegisterHandler registers a workflow action handler.

func (*WorkflowEngine) RegisterWorkflow

func (we *WorkflowEngine) RegisterWorkflow(workflow *Workflow) error

RegisterWorkflow registers a new workflow.

func (*WorkflowEngine) Start

func (we *WorkflowEngine) Start()

Start starts the workflow engine.

func (*WorkflowEngine) Stop

func (we *WorkflowEngine) Stop()

Stop stops the workflow engine.

type WorkflowHandler

type WorkflowHandler func(ctx *WorkflowContext, action Action) error

WorkflowHandler processes workflow actions.

Jump to

Keyboard shortcuts

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