Documentation
¶
Overview ¶
Package lens is the one semantics of a view's filter, group and sort over facets. The cockpit's lens (internal/web/ui/src/lib/lens.ts) follows it through the shared cases in testdata/cases.json.
Index ¶
- Constants
- func Age(w api.RowWords, d time.Duration) string
- func ByID(specs []api.FacetSpec) map[string]api.FacetSpec
- func Countdown(w api.RowWords, left time.Duration) string
- func GroupField(id string, specs map[string]api.FacetSpec, words api.LensWords) (api.FacetSpec, func(Item) []string, bool)
- func Merge(lists ...[]api.FacetSpec) []api.FacetSpec
- func Offered(items []Item, specs []api.FacetSpec, words api.LensWords) []api.FacetSpec
- func Parts(it Item, specs []api.FacetSpec, words api.LensWords, now time.Time) map[string][]Piece
- func SortBy(items []Item, spec api.FacetSpec, desc bool, now time.Time) []int
- func Values(it Item, spec api.FacetSpec, now time.Time) []string
- func Word(template string, vars map[string]string) string
- type Group
- type Item
- type Piece
- type Qualifier
- type Query
Constants ¶
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 ¶
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 Countdown ¶
Countdown is the time left before a pending round sends, in the row words; the cockpit's left mirrors it.
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 ¶
Merge lists the specs of lists once per id, at the position of the first and with the last's spec.
func Offered ¶
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 ¶
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 ¶
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.
Types ¶
type Group ¶
Group is the items of one value of a facet; Items index the slice GroupBy read.
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 Query ¶
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.