Documentation
¶
Overview ¶
Package av 包含了属性视图(Attribute View)相关的实现。
Index ¶
- Constants
- Variables
- func BatchUpsertBlockRel(nodes []*ast.Node)
- func GetAttributeViewDataPath(avID string) (ret string)
- func GetAttributeViewName(avID string) (ret string, err error)
- func GetAttributeViewNameByPath(avJSONPath string) (ret string, err error)
- func GetBlockRels() (ret map[string][]string)
- func GetSrcAvIDs(destAvID string) []string
- func IsAttributeViewExist(avID string) bool
- func IsMirror(avID string) bool
- func NewTableViewWithBlockKey(blockKeyID string) (view *View, blockKey, selectKey *Key)
- func RemoveAvRel(srcAvID, destAvID string)
- func RemoveBlockRel(avID, blockID string, existBlockTree func(string) bool) (ret bool)
- func Round(val float64, precision int) float64
- func RoundDown(val float64, precision int) float64
- func RoundUp(val float64, precision int) float64
- func SaveAttributeView(av *AttributeView) (err error)
- func UpgradeSpec(av *AttributeView)
- func UpsertAvBackRel(srcAvID, destAvID string)
- func UpsertBlockRel(avID, blockID string) (ret bool)
- type AssetType
- type AttributeView
- func (av *AttributeView) ExistBlock(blockID string) bool
- func (av *AttributeView) GetBlockKey() (ret *Key)
- func (av *AttributeView) GetBlockKeyValues() (ret *KeyValues)
- func (av *AttributeView) GetCurrentView(viewID string) (ret *View, err error)
- func (av *AttributeView) GetKey(keyID string) (ret *Key, err error)
- func (av *AttributeView) GetKeyValues(keyID string) (ret *KeyValues, err error)
- func (av *AttributeView) GetValue(keyID, blockID string) (ret *Value)
- func (av *AttributeView) GetView(viewID string) (ret *View)
- func (av *AttributeView) ShallowClone() (ret *AttributeView)
- type CalcOperator
- type Calculable
- type ColumnCalc
- type CreatedFormat
- type Date
- type DateFormat
- type FilterOperator
- type Filterable
- type Key
- type KeyType
- type KeyValues
- type LayoutTable
- type LayoutType
- type NumberFormat
- type Relation
- type RelativeDate
- type RelativeDateDirection
- type RelativeDateUnit
- type Rollup
- type RollupCalc
- type SelectOption
- type SortOrder
- type Sortable
- type Table
- type TableCell
- type TableColumn
- type TableRow
- type UpdatedFormat
- type Value
- func (value *Value) Clone() (ret *Value)
- func (value *Value) Compare(other *Value, attrView *AttributeView) int
- func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID string, ...) bool
- func (value *Value) GetValByType(typ KeyType) (ret interface{})
- func (value *Value) IsEdited() bool
- func (value *Value) IsEmpty() bool
- func (value *Value) SetUpdatedAt(mills int64)
- func (value *Value) SetValByType(typ KeyType, val interface{})
- func (value *Value) String(format bool) string
- func (value *Value) ToJSONString() string
- type ValueAsset
- type ValueBlock
- type ValueCheckbox
- type ValueCreated
- type ValueDate
- type ValueEmail
- type ValueNumber
- type ValuePhone
- type ValueRelation
- type ValueRollup
- type ValueSelect
- type ValueTemplate
- type ValueText
- type ValueURL
- type ValueUpdated
- type View
- type ViewFilter
- type ViewSort
- type ViewTableColumn
- type Viewable
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 NodeAttrViewStaticText = "custom-sy-av-s-text" // 用于标记块所属的属性视图静态文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049 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 GetAttributeViewName ¶
func GetBlockRels ¶
func GetSrcAvIDs ¶
func IsAttributeViewExist ¶
func RemoveAvRel ¶
func RemoveAvRel(srcAvID, destAvID string)
func RemoveBlockRel ¶
func SaveAttributeView ¶
func SaveAttributeView(av *AttributeView) (err error)
func UpgradeSpec ¶
func UpgradeSpec(av *AttributeView)
func UpsertAvBackRel ¶
func UpsertAvBackRel(srcAvID, destAvID string)
func UpsertBlockRel ¶
Types ¶
type AttributeView ¶
type AttributeView struct { Spec int `json:"spec"` // 格式版本 ID string `json:"id"` // 属性视图 ID Name string `json:"name"` // 属性视图名称 KeyValues []*KeyValues `json:"keyValues"` // 属性视图属性键值 KeyIDs []string `json:"keyIDs"` // 属性视图属性键 ID,用于排序 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) 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" CalcOperatorPercentUniqueValues CalcOperator = "Percent unique values" 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"` // 字段图标 Desc string `json:"desc"` // 字段描述 // 单选/多选 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 (*Key) GetOption ¶
func (k *Key) GetOption(name string) (ret *SelectOption)
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) GetBlockValue ¶
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 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 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"` // 表格名称 Desc string `json:"desc"` // 表格描述 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) FilterRows ¶
func (table *Table) FilterRows(attrView *AttributeView)
func (*Table) GetColumn ¶
func (table *Table) GetColumn(id string) *TableColumn
func (*Table) GetType ¶
func (table *Table) GetType() LayoutType
func (*Table) SortRows ¶
func (table *Table) SortRows(attrView *AttributeView)
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"` // 列宽度 Desc string `json:"desc"` // 列描述 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 ¶
func (*TableRow) GetBlockValue ¶
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 GetKeyBlockValue ¶
func (*Value) Filter ¶
func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, rowID string, attrViewCache *map[string]*AttributeView) bool
func (*Value) GetValByType ¶
func (*Value) SetUpdatedAt ¶
func (*Value) SetValByType ¶
func (*Value) ToJSONString ¶
type ValueAsset ¶
type ValueBlock ¶
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 ValueRollup ¶
type ValueRollup struct {
Contents []*Value `json:"contents"`
}
func (*ValueRollup) RenderContents ¶
func (r *ValueRollup) RenderContents(calc *RollupCalc, destKey *Key)
type ValueSelect ¶
type ValueTemplate ¶
type ValueTemplate 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"` // 是否隐藏属性视图名称 Desc string `json:"desc"` // 视图描述 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 ViewTableColumn ¶
type Viewable ¶
type Viewable interface { Filterable Sortable Calculable GetType() LayoutType GetID() string }
Viewable 描述了视图的接口。
Click to show internal directories.
Click to hide internal directories.