github.com/rotari-dev/rotari/internal/stickies

Overview

package stickies // import "github.com/rotari-dev/rotari/internal/stickies"

Package stickies keeps the sticky notes users put on Web UI pages.

A basedir holds one file, <basedir>/stickies.json, mapping a page key (the
page's route inside the Web UI, an arbitrary string rather than a path) to
the notes on that page. Notes are free-form reminders: no job, run, or result
depends on them. Knows nothing of HTTP.

Constants

const (
	MaxNotesPerPage = 100
	MaxPages        = 1000
	MaxTextRunes    = 4000
	MaxIDLength     = 64
	MaxPageKeyBytes = 1024
	MaxCoordinate   = 1e6

	// Sizes are in pixels; a note of size 0 has the default size.
	MinWidth  = 120
	MinHeight = 80
	MaxSize   = 2000
)

Variables

var Colors = []string{"yellow", "pink", "green", "blue", "orange"}
    Colors are the colours a note may have; the first is the default.

Functions

func Save(baseDir, page string, notes []Note) error
    Save replaces the notes on a page; no notes removes the page.

func Validate(page string, notes []Note) error
    Validate reports why notes cannot be saved for a page.

Types

type Note struct {
	ID    string  `json:"id"`
	Text  string  `json:"text"`
	Color string  `json:"color"`
	X     float64 `json:"x"`
	Y     float64 `json:"y"`
	// Width and Height are the note's size in pixels, 0 for the default.
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
	// CreatedAt is when the note was made, RFC 3339; Save fills it in for a
	// note that has none.
	CreatedAt string `json:"created_at"`
}
    Note is one sticky note. X and Y are pixels from the page's top-left corner.

func Load(baseDir, page string) ([]Note, error)
    Load returns the notes on a page; a page without notes has none.

type Page struct {
	Page  string `json:"page"`
	Notes []Note `json:"notes"`
}
    Page is a page key with its notes.

func Pages(baseDir string) ([]Page, error)
    Pages returns every page that has notes, ordered by page key.

func Search(pages []Page, query string) ([]Page, error)
    Search keeps the notes whose text contains every whitespace-separated
    word of query, ignoring case, and the pages that still have notes.
    Pages keep their order, notes theirs. A query without words is an error,
    not "everything".