crudview

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCSS

func GenerateCSS() *Stylesheet

func IconSvg

func IconSvg() *sprite.Sprite

IconSvg returns the sprite with the captured Pa100T icons. Captured paths from Pa100T v3.0.1 (base64 SVGs in IE_MODULE_CONTENT.md §2).

Types

type Config added in v0.0.11

type Config struct {
	// ParentID is the DOM id the form mounts under (a module passes its own ID).
	ParentID string

	Caller router.Caller
	Title  string // h1, top-left

	// Record is BOTH the form's source of truth and the payload sent over the wire.
	// model.Model (v0.0.14) is exactly that contract — never declare a local intersection.
	Record model.Model

	ListOp   string // required
	SaveOp   string // "" → no save button
	DeleteOp string // "" → no delete button

	Args   func() model.Encodable           // list args (nil → none)
	Decode func(raw []byte) ([]Item, error) // list response → cards

	// Fill returns the full record for id, from what the module ALREADY decoded in Decode.
	// A nil return (including a typed-nil pointer) resets the form — that is not an error.
	Fill func(id string) model.Model

	OnError func(err error)

	// SearchPlaceholder overrides the search box text ("" → "Search…").
	SearchPlaceholder string
}

Config is everything a module decides about its CRUD view: its record and its ops. Everything else — generating the form from the record, filling it on select, validating and shipping it on save, reloading the list — is wired HERE, once, for every app.

type CrudView

type CrudView struct {
	Element // value embed — NEVER *dom.Element

	Title  string    // h1, top-left corner of the panel (white on accent bar)
	Form   Component // LEFT slot, the protagonist (typically *form.Form)
	Source Source    // feeds the right-hand list; zero Source = full-page

	// Interaction callbacks — the composition root wires these to the form
	// and transport ONCE per app; modules never re-implement them.
	OnSelect func(it Item)                         // list card clicked → load into form
	OnNew    func()                                // (+) pressed → reset form for create
	OnSave   func(done func(err error))            // (💾) pressed; done(nil) reloads list
	OnDelete func(id string, done func(err error)) // (−) pressed on selection
	OnCancel func()                                // (↺) pressed → undo current edit
	OnError  func(err error)                       // list load/decode failures; nil = drop

	SearchPlaceholder string
	// contains filtered or unexported fields
}

func New added in v0.0.11

func New(cfg Config) (*CrudView, error)

New builds the standard CRUD view and wires the whole form↔list↔transport cycle. A module calls this and passes its record and its ops. Nothing else.

func (*CrudView) Init

func (v *CrudView) Init(ctx Ctx)

func (*CrudView) Reload

func (v *CrudView) Reload()

func (*CrudView) Render

func (v *CrudView) Render() *Element

func (*CrudView) Select

func (v *CrudView) Select(id string)

type Item

type Item struct {
	ID          string // selection key
	Label       string // main text of the card
	Description string // small chip at the card's bottom-right (e.g. an IP)
}

Item is one record in the right-hand list.

type Source

type Source struct {
	Caller router.Caller
	ListOp string                 // logical operation, e.g. "list_devices"
	Args   func() model.Encodable // list request args (nil → no args)
	Decode func(raw []byte) ([]Item, error)
}

Source is the data seam: a fake in tests, a router.Caller adapter in prod.

Jump to

Keyboard shortcuts

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