av

package
v0.0.0-...-2c8f587 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package av 包含了属性视图(Attribute View)相关的实现。

Index

Constants

View Source
const (
	NodeAttrNameAvs = "custom-avs"        // 用于标记块所属的属性视图,逗号分隔 av id
	NodeAttrView    = "custom-sy-av-view" // 用于标记块所属的属性视图视图 view id Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443

	NodeAttrViewNames = "av-names" // 用于临时标记块所属的属性视图名称,空格分隔
)
View Source
const (
	RelativeDateUnitDay = iota
	RelativeDateUnitWeek
	RelativeDateUnitMonth
	RelativeDateUnitYear
)
View Source
const (
	RelativeDateDirectionBefore = -1
	RelativeDateDirectionThis   = 0
	RelativeDateDirectionAfter  = 1
)
View Source
const (
	AssetTypeFile  = "file"
	AssetTypeImage = "image"
)

Variables

View Source
var (
	ErrViewNotFound = errors.New("view not found")
	ErrKeyNotFound  = errors.New("key not found")
)
View Source
var (
	AttributeViewBlocksLock = sync.Mutex{}
)

Functions

func BatchUpsertBlockRel

func BatchUpsertBlockRel(nodes []*ast.Node)

func GetAttributeViewDataPath

func GetAttributeViewDataPath(avID string) (ret string)

func GetAttributeViewName

func GetAttributeViewName(avID string) (ret string, err error)

func GetAttributeViewNameByPath

func GetAttributeViewNameByPath(avJSONPath string) (ret string, err error)

func GetBlockRels

func GetBlockRels() (ret map[string][]string)

func GetSrcAvIDs

func GetSrcAvIDs(destAvID string) []string

func IsAttributeViewExist

func IsAttributeViewExist(avID string) bool

func IsMirror

func IsMirror(avID string) bool

func NewTableViewWithBlockKey

func NewTableViewWithBlockKey(blockKeyID string) (view *View, blockKey, selectKey *Key)

func RemoveAvRel

func RemoveAvRel(srcAvID, destAvID string)

func RemoveBlockRel

func RemoveBlockRel(avID, blockID string, existBlockTree func(string) bool) (ret bool)

func Round

func Round(val float64, precision int) float64

Round rounds to nearest like 12.3456 -> 12.35

func RoundDown

func RoundDown(val float64, precision int) float64

RoundDown rounds like 12.3496 -> 12.34

func RoundUp

func RoundUp(val float64, precision int) float64

RoundUp rounds like 12.3416 -> 12.35

func SaveAttributeView

func SaveAttributeView(av *AttributeView) (err error)

func UpsertAvBackRel

func UpsertAvBackRel(srcAvID, destAvID string)

func UpsertBlockRel

func UpsertBlockRel(avID, blockID string) (ret bool)

Types

type AssetType

type AssetType string

type AttributeView

type AttributeView struct {
	Spec      int          `json:"spec"`      // 格式版本
	ID        string       `json:"id"`        // 属性视图 ID
	Name      string       `json:"name"`      // 属性视图名称
	KeyValues []*KeyValues `json:"keyValues"` // 属性视图属性列值
	ViewID    string       `json:"viewID"`    // 当前视图 ID
	Views     []*View      `json:"views"`     // 视图
}

AttributeView 描述了属性视图的结构。

func NewAttributeView

func NewAttributeView(id string) (ret *AttributeView)

func ParseAttributeView

func ParseAttributeView(avID string) (ret *AttributeView, err error)

func (*AttributeView) ExistBlock

func (av *AttributeView) ExistBlock(blockID string) bool

func (*AttributeView) GetBlockKey

func (av *AttributeView) GetBlockKey() (ret *Key)

func (*AttributeView) GetBlockKeyValues

func (av *AttributeView) GetBlockKeyValues() (ret *KeyValues)

func (*AttributeView) GetCurrentView

func (av *AttributeView) GetCurrentView(viewID string) (ret *View, err error)

func (*AttributeView) GetDuplicateViewName

func (av *AttributeView) GetDuplicateViewName(masterViewName string) (ret string)

func (*AttributeView) GetKey

func (av *AttributeView) GetKey(keyID string) (ret *Key, err error)

func (*AttributeView) GetKeyValues

func (av *AttributeView) GetKeyValues(keyID string) (ret *KeyValues, err error)

func (*AttributeView) GetValue

func (av *AttributeView) GetValue(keyID, blockID string) (ret *Value)

func (*AttributeView) GetView

func (av *AttributeView) GetView(viewID string) (ret *View)

func (*AttributeView) ShallowClone

func (av *AttributeView) ShallowClone() (ret *AttributeView)

type CalcOperator

type CalcOperator string
const (
	CalcOperatorNone              CalcOperator = ""
	CalcOperatorCountAll          CalcOperator = "Count all"
	CalcOperatorCountValues       CalcOperator = "Count values"
	CalcOperatorCountUniqueValues CalcOperator = "Count unique values"
	CalcOperatorCountEmpty        CalcOperator = "Count empty"
	CalcOperatorCountNotEmpty     CalcOperator = "Count not empty"
	CalcOperatorPercentEmpty      CalcOperator = "Percent empty"
	CalcOperatorPercentNotEmpty   CalcOperator = "Percent not empty"
	CalcOperatorSum               CalcOperator = "Sum"
	CalcOperatorAverage           CalcOperator = "Average"
	CalcOperatorMedian            CalcOperator = "Median"
	CalcOperatorMin               CalcOperator = "Min"
	CalcOperatorMax               CalcOperator = "Max"
	CalcOperatorRange             CalcOperator = "Range"
	CalcOperatorEarliest          CalcOperator = "Earliest"
	CalcOperatorLatest            CalcOperator = "Latest"
	CalcOperatorChecked           CalcOperator = "Checked"
	CalcOperatorUnchecked         CalcOperator = "Unchecked"
	CalcOperatorPercentChecked    CalcOperator = "Percent checked"
	CalcOperatorPercentUnchecked  CalcOperator = "Percent unchecked"
)

type Calculable

type Calculable interface {
	CalcCols()
}

type ColumnCalc

type ColumnCalc struct {
	Operator CalcOperator `json:"operator"`
	Result   *Value       `json:"result"`
}

type CreatedFormat

type CreatedFormat string
const (
	CreatedFormatNone     CreatedFormat = "" // 2006-01-02 15:04
	CreatedFormatDuration CreatedFormat = "duration"
)

type Date

type Date struct {
	AutoFillNow bool `json:"autoFillNow"` // 是否自动填充当前时间 The database date field supports filling the current time by default https://github.com/siyuan-note/siyuan/issues/10823
}

type DateFormat

type DateFormat string
const (
	DateFormatNone     DateFormat = ""
	DateFormatDuration DateFormat = "duration"
)

type FilterOperator

type FilterOperator string
const (
	FilterOperatorIsEqual          FilterOperator = "="
	FilterOperatorIsNotEqual       FilterOperator = "!="
	FilterOperatorIsGreater        FilterOperator = ">"
	FilterOperatorIsGreaterOrEqual FilterOperator = ">="
	FilterOperatorIsLess           FilterOperator = "<"
	FilterOperatorIsLessOrEqual    FilterOperator = "<="
	FilterOperatorContains         FilterOperator = "Contains"
	FilterOperatorDoesNotContain   FilterOperator = "Does not contains"
	FilterOperatorIsEmpty          FilterOperator = "Is empty"
	FilterOperatorIsNotEmpty       FilterOperator = "Is not empty"
	FilterOperatorStartsWith       FilterOperator = "Starts with"
	FilterOperatorEndsWith         FilterOperator = "Ends with"
	FilterOperatorIsBetween        FilterOperator = "Is between"
	FilterOperatorIsTrue           FilterOperator = "Is true"
	FilterOperatorIsFalse          FilterOperator = "Is false"
)

type Filterable

type Filterable interface {
	FilterRows(attrView *AttributeView)
}

type Key

type Key struct {
	ID   string  `json:"id"`   // 列 ID
	Name string  `json:"name"` // 列名
	Type KeyType `json:"type"` // 列类型
	Icon string  `json:"icon"` // 列图标

	// 单选/多选
	Options []*SelectOption `json:"options,omitempty"` // 选项列表

	// 数字
	NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化

	// 模板
	Template string `json:"template"` // 模板内容

	// 关联
	Relation *Relation `json:"relation,omitempty"` // 关联信息

	// 汇总
	Rollup *Rollup `json:"rollup,omitempty"` // 汇总信息

	// 日期
	Date *Date `json:"date,omitempty"` // 日期设置
}

Key 描述了属性视图属性列的基础结构。

func NewKey

func NewKey(id, name, icon string, keyType KeyType) *Key

type KeyType

type KeyType string
const (
	KeyTypeBlock      KeyType = "block"
	KeyTypeText       KeyType = "text"
	KeyTypeNumber     KeyType = "number"
	KeyTypeDate       KeyType = "date"
	KeyTypeSelect     KeyType = "select"
	KeyTypeMSelect    KeyType = "mSelect"
	KeyTypeURL        KeyType = "url"
	KeyTypeEmail      KeyType = "email"
	KeyTypePhone      KeyType = "phone"
	KeyTypeMAsset     KeyType = "mAsset"
	KeyTypeTemplate   KeyType = "template"
	KeyTypeCreated    KeyType = "created"
	KeyTypeUpdated    KeyType = "updated"
	KeyTypeCheckbox   KeyType = "checkbox"
	KeyTypeRelation   KeyType = "relation"
	KeyTypeRollup     KeyType = "rollup"
	KeyTypeLineNumber KeyType = "lineNumber"
)

type KeyValues

type KeyValues struct {
	Key    *Key     `json:"key"`              // 属性视图属性列
	Values []*Value `json:"values,omitempty"` // 属性视图属性列值
}

KeyValues 描述了属性视图属性列值的结构。

func (*KeyValues) GetValue

func (kValues *KeyValues) GetValue(blockID string) (ret *Value)

type LayoutTable

type LayoutTable struct {
	Spec int    `json:"spec"` // 布局格式版本
	ID   string `json:"id"`   // 布局 ID

	Columns  []*ViewTableColumn `json:"columns"`  // 表格列
	RowIDs   []string           `json:"rowIds"`   // 行 ID,用于自定义排序
	Filters  []*ViewFilter      `json:"filters"`  // 过滤规则
	Sorts    []*ViewSort        `json:"sorts"`    // 排序规则
	PageSize int                `json:"pageSize"` // 每页行数
}

LayoutTable 描述了表格布局的结构。

type LayoutType

type LayoutType string

LayoutType 描述了视图布局的类型。

const (
	LayoutTypeTable LayoutType = "table" // 属性视图类型 - 表格
)

type NumberFormat

type NumberFormat string
const (
	NumberFormatNone           NumberFormat = ""
	NumberFormatCommas         NumberFormat = "commas"
	NumberFormatPercent        NumberFormat = "percent"
	NumberFormatUSDollar       NumberFormat = "usDollar"
	NumberFormatYuan           NumberFormat = "yuan"
	NumberFormatEuro           NumberFormat = "euro"
	NumberFormatPound          NumberFormat = "pound"
	NumberFormatYen            NumberFormat = "yen"
	NumberFormatRuble          NumberFormat = "ruble"
	NumberFormatRupee          NumberFormat = "rupee"
	NumberFormatWon            NumberFormat = "won"
	NumberFormatCanadianDollar NumberFormat = "canadianDollar"
	NumberFormatFranc          NumberFormat = "franc"
)

type Relation

type Relation struct {
	AvID      string `json:"avID"`      // 关联的属性视图 ID
	IsTwoWay  bool   `json:"isTwoWay"`  // 是否双向关联
	BackKeyID string `json:"backKeyID"` // 双向关联时回链关联列的 ID
}

type RelativeDate

type RelativeDate struct {
	Count     int                   `json:"count"`     // 数量
	Unit      RelativeDateUnit      `json:"unit"`      // 单位:0 天、1 周、2 月、3 年
	Direction RelativeDateDirection `json:"direction"` // 方向:-1 前、0 当前、1 后
}

type RelativeDateDirection

type RelativeDateDirection int

type RelativeDateUnit

type RelativeDateUnit int

type Rollup

type Rollup struct {
	RelationKeyID string      `json:"relationKeyID"` // 关联列 ID
	KeyID         string      `json:"keyID"`         // 目标列 ID
	Calc          *RollupCalc `json:"calc"`          // 计算方式
}

type RollupCalc

type RollupCalc struct {
	Operator CalcOperator `json:"operator"`
	Result   *Value       `json:"result"`
}

type SelectOption

type SelectOption struct {
	Name  string `json:"name"`
	Color string `json:"color"`
}

type SortOrder

type SortOrder string
const (
	SortOrderAsc  SortOrder = "ASC"
	SortOrderDesc SortOrder = "DESC"
)

type Sortable

type Sortable interface {
	SortRows(attrView *AttributeView)
}

type Table

type Table struct {
	ID               string         `json:"id"`               // 表格布局 ID
	Icon             string         `json:"icon"`             // 表格图标
	Name             string         `json:"name"`             // 表格名称
	HideAttrViewName bool           `json:"hideAttrViewName"` // 是否隐藏属性视图名称
	Filters          []*ViewFilter  `json:"filters"`          // 过滤规则
	Sorts            []*ViewSort    `json:"sorts"`            // 排序规则
	Columns          []*TableColumn `json:"columns"`          // 表格列
	Rows             []*TableRow    `json:"rows"`             // 表格行
	RowCount         int            `json:"rowCount"`         // 表格总行数
	PageSize         int            `json:"pageSize"`         // 每页行数
}

Table 描述了表格实例的结构。

func (*Table) CalcCols

func (table *Table) CalcCols()

func (*Table) FilterRows

func (table *Table) FilterRows(attrView *AttributeView)

func (*Table) GetID

func (table *Table) GetID() string

func (*Table) GetType

func (table *Table) GetType() LayoutType

func (*Table) SortRows

func (table *Table) SortRows(attrView *AttributeView)

type TableCell

type TableCell struct {
	ID        string  `json:"id"`
	Value     *Value  `json:"value"`
	ValueType KeyType `json:"valueType"`
	Color     string  `json:"color"`
	BgColor   string  `json:"bgColor"`
}

type TableColumn

type TableColumn struct {
	ID     string      `json:"id"`     // 列 ID
	Name   string      `json:"name"`   // 列名
	Type   KeyType     `json:"type"`   // 列类型
	Icon   string      `json:"icon"`   // 列图标
	Wrap   bool        `json:"wrap"`   // 是否换行
	Hidden bool        `json:"hidden"` // 是否隐藏
	Pin    bool        `json:"pin"`    // 是否固定
	Width  string      `json:"width"`  // 列宽度
	Calc   *ColumnCalc `json:"calc"`   // 计算

	Options      []*SelectOption `json:"options,omitempty"`  // 选项列表
	NumberFormat NumberFormat    `json:"numberFormat"`       // 数字列格式化
	Template     string          `json:"template"`           // 模板列内容
	Relation     *Relation       `json:"relation,omitempty"` // 关联列
	Rollup       *Rollup         `json:"rollup,omitempty"`   // 汇总列
	Date         *Date           `json:"date,omitempty"`     // 日期设置
}

type TableRow

type TableRow struct {
	ID    string       `json:"id"`
	Cells []*TableCell `json:"cells"`
}

func (*TableRow) GetBlockValue

func (row *TableRow) GetBlockValue() (ret *Value)

func (*TableRow) GetValue

func (row *TableRow) GetValue(keyID string) (ret *Value)

type UpdatedFormat

type UpdatedFormat string
const (
	UpdatedFormatNone     UpdatedFormat = "" // 2006-01-02 15:04
	UpdatedFormatDuration UpdatedFormat = "duration"
)

type Value

type Value struct {
	ID         string  `json:"id,omitempty"`
	KeyID      string  `json:"keyID,omitempty"`
	BlockID    string  `json:"blockID,omitempty"`
	Type       KeyType `json:"type,omitempty"`
	IsDetached bool    `json:"isDetached,omitempty"`

	CreatedAt int64 `json:"createdAt,omitempty"`
	UpdatedAt int64 `json:"updatedAt,omitempty"`

	Block    *ValueBlock    `json:"block,omitempty"`
	Text     *ValueText     `json:"text,omitempty"`
	Number   *ValueNumber   `json:"number,omitempty"`
	Date     *ValueDate     `json:"date,omitempty"`
	MSelect  []*ValueSelect `json:"mSelect,omitempty"`
	URL      *ValueURL      `json:"url,omitempty"`
	Email    *ValueEmail    `json:"email,omitempty"`
	Phone    *ValuePhone    `json:"phone,omitempty"`
	MAsset   []*ValueAsset  `json:"mAsset,omitempty"`
	Template *ValueTemplate `json:"template,omitempty"`
	Created  *ValueCreated  `json:"created,omitempty"`
	Updated  *ValueUpdated  `json:"updated,omitempty"`
	Checkbox *ValueCheckbox `json:"checkbox,omitempty"`
	Relation *ValueRelation `json:"relation,omitempty"`
	Rollup   *ValueRollup   `json:"rollup,omitempty"`
}

func GetAttributeViewDefaultValue

func GetAttributeViewDefaultValue(valueID, keyID, blockID string, typ KeyType) (ret *Value)

func (*Value) Clone

func (value *Value) Clone() (ret *Value)

func (*Value) Compare

func (value *Value) Compare(other *Value, attrView *AttributeView) int

func (*Value) Filter

func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID string) bool

func (*Value) GetValByType

func (value *Value) GetValByType(typ KeyType) (ret interface{})

func (*Value) IsEdited

func (value *Value) IsEdited() bool

func (*Value) IsEmpty

func (value *Value) IsEmpty() bool

func (*Value) SetUpdatedAt

func (value *Value) SetUpdatedAt(mills int64)

func (*Value) SetValByType

func (value *Value) SetValByType(typ KeyType, val interface{})

func (*Value) String

func (value *Value) String(format bool) string

func (*Value) ToJSONString

func (value *Value) ToJSONString() string

type ValueAsset

type ValueAsset struct {
	Type    AssetType `json:"type"`
	Name    string    `json:"name"`
	Content string    `json:"content"`
}

type ValueBlock

type ValueBlock struct {
	ID      string `json:"id"`
	Content string `json:"content"`
	Created int64  `json:"created"`
	Updated int64  `json:"updated"`
}

type ValueCheckbox

type ValueCheckbox struct {
	Checked bool `json:"checked"`
}

type ValueCreated

type ValueCreated struct {
	Content          int64  `json:"content"`
	IsNotEmpty       bool   `json:"isNotEmpty"`
	Content2         int64  `json:"content2"`
	IsNotEmpty2      bool   `json:"isNotEmpty2"`
	FormattedContent string `json:"formattedContent"`
}

func NewFormattedValueCreated

func NewFormattedValueCreated(content, content2 int64, format CreatedFormat) (ret *ValueCreated)

type ValueDate

type ValueDate struct {
	Content          int64  `json:"content"`
	IsNotEmpty       bool   `json:"isNotEmpty"`
	HasEndDate       bool   `json:"hasEndDate"`
	IsNotTime        bool   `json:"isNotTime"`
	Content2         int64  `json:"content2"`
	IsNotEmpty2      bool   `json:"isNotEmpty2"`
	FormattedContent string `json:"formattedContent"`
}

func NewFormattedValueDate

func NewFormattedValueDate(content, content2 int64, format DateFormat, isNotTime, hasEndDate bool) (ret *ValueDate)

type ValueEmail

type ValueEmail struct {
	Content string `json:"content"`
}

type ValueNumber

type ValueNumber struct {
	Content          float64      `json:"content"`
	IsNotEmpty       bool         `json:"isNotEmpty"`
	Format           NumberFormat `json:"format"`
	FormattedContent string       `json:"formattedContent"`
}

func NewFormattedValueNumber

func NewFormattedValueNumber(content float64, format NumberFormat) (ret *ValueNumber)

func (*ValueNumber) FormatNumber

func (number *ValueNumber) FormatNumber()

type ValuePhone

type ValuePhone struct {
	Content string `json:"content"`
}

type ValueRelation

type ValueRelation struct {
	BlockIDs []string `json:"blockIDs"`
	Contents []*Value `json:"contents"`
}

type ValueRollup

type ValueRollup struct {
	Contents []*Value `json:"contents"`
}

func (*ValueRollup) RenderContents

func (r *ValueRollup) RenderContents(calc *RollupCalc, destKey *Key)

type ValueSelect

type ValueSelect struct {
	Content string `json:"content"`
	Color   string `json:"color"`
}

type ValueTemplate

type ValueTemplate struct {
	Content string `json:"content"`
}

type ValueText

type ValueText struct {
	Content string `json:"content"`
}

type ValueURL

type ValueURL struct {
	Content string `json:"content"`
}

type ValueUpdated

type ValueUpdated struct {
	Content          int64  `json:"content"`
	IsNotEmpty       bool   `json:"isNotEmpty"`
	Content2         int64  `json:"content2"`
	IsNotEmpty2      bool   `json:"isNotEmpty2"`
	FormattedContent string `json:"formattedContent"`
}

func NewFormattedValueUpdated

func NewFormattedValueUpdated(content, content2 int64, format UpdatedFormat) (ret *ValueUpdated)

type View

type View struct {
	ID               string `json:"id"`               // 视图 ID
	Icon             string `json:"icon"`             // 视图图标
	Name             string `json:"name"`             // 视图名称
	HideAttrViewName bool   `json:"hideAttrViewName"` // 是否隐藏属性视图名称

	LayoutType LayoutType   `json:"type"`            // 当前布局类型
	Table      *LayoutTable `json:"table,omitempty"` // 表格布局
}

View 描述了视图的结构。

func NewTableView

func NewTableView() (ret *View)

type ViewFilter

type ViewFilter struct {
	Column        string         `json:"column"`
	Operator      FilterOperator `json:"operator"`
	Value         *Value         `json:"value"`
	RelativeDate  *RelativeDate  `json:"relativeDate"`
	RelativeDate2 *RelativeDate  `json:"relativeDate2"`
}

func (*ViewFilter) GetAffectValue

func (filter *ViewFilter) GetAffectValue(key *Key, defaultVal *Value) (ret *Value)

type ViewSort

type ViewSort struct {
	Column string    `json:"column"` // 列 ID
	Order  SortOrder `json:"order"`  // 排序顺序
}

type ViewTableColumn

type ViewTableColumn struct {
	ID string `json:"id"` // 列 ID

	Wrap   bool        `json:"wrap"`           // 是否换行
	Hidden bool        `json:"hidden"`         // 是否隐藏
	Pin    bool        `json:"pin"`            // 是否固定
	Width  string      `json:"width"`          // 列宽度
	Calc   *ColumnCalc `json:"calc,omitempty"` // 计算
}

type Viewable

type Viewable interface {
	Filterable
	Sortable
	Calculable

	GetType() LayoutType
	GetID() string
}

Viewable 描述了视图的接口。

Jump to

Keyboard shortcuts

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