lens

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lens is the one semantics of a view's filter, group and sort over facets. The cockpit's app.js follows it through the shared cases in testdata/cases.json.

Index

Constants

View Source
const AtVar = "{{.at}}"

AtVar is the variable of an age piece's template a client fills with its time.

Variables

This section is empty.

Functions

func Age

func Age(w api.RowWords, d time.Duration) string

Age is d in the row words: under a minute, in minutes, in hours and minutes, or in days and hours; a negative d reads as under a minute.

func ByID

func ByID(specs []api.FacetSpec) map[string]api.FacetSpec

ByID indexes specs by id.

func Countdown

func Countdown(w api.RowWords, left time.Duration) string

Countdown is the time left before a pending round sends, in the row words; it mirrors app.js's left.

func GroupField

func GroupField(id string, specs map[string]api.FacetSpec, words api.LensWords) (api.FacetSpec, func(Item) []string, bool)

GroupField resolves a group field id: a facet's own, or "<facet>:<key>" for a prefix-match facet, which groups by the values starting with "<key>:", an item under each of them. For the second kind it returns the keys of an item, to give GroupByKeys, and its name in words; for the first, nil keys and GroupBy applies.

func Merge

func Merge(lists ...[]api.FacetSpec) []api.FacetSpec

Merge lists the specs of lists once per id, at the position of the first and with the last's spec.

func Offered

func Offered(items []Item, specs []api.FacetSpec, words api.LensWords) []api.FacetSpec

Offered are the fields a list's menus offer: the specs some item has a value of, in order, then a "tag:<key>" field for each key of the prefix-match "tag" facet's values the items hold.

func Parts

func Parts(it Item, specs []api.FacetSpec, words api.LensWords, now time.Time) map[string][]Piece

Parts are the pieces of it each part of a row shows, by part, from the specs that show in one, in their order: a spec of another provider places none, and a spec merged across providers places it with its provider's display keys, and a spec whose show_when the item does not hold places none. A value "none" and a time facet's value that is no time never show, the age part holds the first time of its first facet, labeled with its age at now in words (or its show_label with {{.age}} filled), and a part with show_max counts the values past it into one last piece.

func SortBy

func SortBy(items []Item, spec api.FacetSpec, desc bool, now time.Time) []int

SortBy orders the items' indexes by spec: a time facet by its first time, any other by key, ranked values first in rank order. An item without a value is always last in a key order and first in an ascending time order. Ties keep the input order.

func Values

func Values(it Item, spec api.FacetSpec, now time.Time) []string

Values are the item's values of spec's facet, folded the way filters compare: a time facet's are its buckets at now, "none" without a time.

func Word

func Word(template string, vars map[string]string) string

Word fills a lens word's {{.name}} actions from vars, a name vars lacks with nothing.

Types

type Group

type Group struct {
	Key, Label string
	Items      []int
}

Group is the items of one value of a facet; Items index the slice GroupBy read.

func GroupBy

func GroupBy(items []Item, spec api.FacetSpec, now time.Time) []Group

GroupBy puts each item under its first value of spec, under "none" without one, or under each of its values when the facet matches by prefix. Groups come in rank order, then by name, "none" last.

func GroupByKeys

func GroupByKeys(items []Item, spec api.FacetSpec, keys func(Item) []string) []Group

GroupByKeys groups like GroupBy, an item under each of the keys the function gives, "none" without one.

type Item

type Item struct {
	Facets   map[string][]string `json:"facets"`
	Texts    []string            `json:"texts"`
	Provider string              `json:"provider,omitempty"`
}

Item is what the lens reads of one thing on a list: its facet values, the texts a free word searches and the provider whose display keys place it on a row ("" for a task).

type Piece

type Piece struct {
	Field string `json:"field"`
	Value string `json:"value"`
	Raw   string `json:"raw"`
	Label string `json:"label"`
	// Template is an age piece's show_label, whose {{.at}} a client fills with Raw in its own locale.
	Template string `json:"template,omitempty"`
}

Piece is one value a row shows of a facet: Field and Value are the qualifier a click on it toggles (a time facet's Value its bucket), Raw the item's own value and Label what the row reads.

type Qualifier

type Qualifier struct {
	Field, Value string
	Neg          bool
}

Qualifier is a field:value term of a query. Value is folded.

type Query

type Query struct {
	Terms []string
	Quals []Qualifier
}

Query is a parsed filter: free words, each of which every item must hold in some text, and qualifiers, whose values of one field are alternatives and whose fields all must hold. Terms are folded.

func Parse

func Parse(q string, specs map[string]api.FacetSpec) Query

Parse reads q as space-separated tokens, a quoted value kept whole. A token is a qualifier when it reads [-]field:value for a field of specs and has a value; any other token, an unknown field's included, is a free word.

func (Query) Match

func (q Query) Match(it Item, specs map[string]api.FacetSpec, now time.Time) bool

Match says whether it holds every term and every field's qualifiers.

Jump to

Keyboard shortcuts

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