mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-30 13:28:48 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
7973499b63
7 changed files with 79 additions and 31 deletions
|
|
@ -189,6 +189,26 @@ type View struct {
|
|||
Gallery *LayoutGallery `json:"gallery,omitempty"` // 画廊布局
|
||||
}
|
||||
|
||||
func (view *View) GetFilters() (ret []*ViewFilter) {
|
||||
switch view.LayoutType {
|
||||
case LayoutTypeTable:
|
||||
return view.Table.Filters
|
||||
case LayoutTypeGallery:
|
||||
return view.Gallery.Filters
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (view *View) GetSorts() (ret []*ViewSort) {
|
||||
switch view.LayoutType {
|
||||
case LayoutTypeTable:
|
||||
return view.Table.Sorts
|
||||
case LayoutTypeGallery:
|
||||
return view.Gallery.Sorts
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// LayoutType 描述了视图布局类型。
|
||||
type LayoutType string
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,9 @@ type Item interface {
|
|||
// GetValues 返回项目的所有字段值。
|
||||
GetValues() []*Value
|
||||
|
||||
// GetValue 返回指定键 ID 的字段值。
|
||||
GetValue(keyID string) (ret *Value)
|
||||
|
||||
// GetID 返回项目的 ID。
|
||||
GetID() string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,6 +138,16 @@ func (card *GalleryCard) GetValues() (ret []*Value) {
|
|||
return
|
||||
}
|
||||
|
||||
func (card *GalleryCard) GetValue(keyID string) (ret *Value) {
|
||||
for _, value := range card.Values {
|
||||
if nil != value.Value && keyID == value.Value.KeyID {
|
||||
ret = value.Value
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (gallery *Gallery) GetItems() (ret []Item) {
|
||||
ret = []Item{}
|
||||
for _, card := range gallery.Cards {
|
||||
|
|
|
|||
|
|
@ -91,16 +91,6 @@ type TableCell struct {
|
|||
BgColor string `json:"bgColor"` // 单元格背景颜色
|
||||
}
|
||||
|
||||
func (row *TableRow) GetValue(keyID string) (ret *Value) {
|
||||
for _, cell := range row.Cells {
|
||||
if nil != cell.Value && keyID == cell.Value.KeyID {
|
||||
ret = cell.Value
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (table *Table) GetColumn(id string) *TableColumn {
|
||||
for _, column := range table.Columns {
|
||||
if column.ID == id {
|
||||
|
|
@ -134,6 +124,16 @@ func (row *TableRow) GetValues() (ret []*Value) {
|
|||
return
|
||||
}
|
||||
|
||||
func (row *TableRow) GetValue(keyID string) (ret *Value) {
|
||||
for _, cell := range row.Cells {
|
||||
if nil != cell.Value && keyID == cell.Value.KeyID {
|
||||
ret = cell.Value
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (table *Table) GetItems() (ret []Item) {
|
||||
ret = []Item{}
|
||||
for _, row := range table.Rows {
|
||||
|
|
|
|||
|
|
@ -1266,7 +1266,7 @@ func GetCurrentAttributeViewImages(avID, viewID, query string) (ret []string, er
|
|||
view = attrView.GetView(attrView.ViewID)
|
||||
}
|
||||
|
||||
table := sql.RenderAttributeViewTable(attrView, view, query)
|
||||
table := getAttrViewTable(attrView, view, query)
|
||||
table.Filter(attrView)
|
||||
table.Sort(attrView)
|
||||
|
||||
|
|
@ -2418,34 +2418,49 @@ func addAttributeViewBlock(now int64, avID, blockID, previousBlockID, addingBloc
|
|||
|
||||
// 如果存在过滤条件,则将过滤条件应用到新添加的块上
|
||||
view, _ := getAttrViewViewByBlockID(attrView, blockID)
|
||||
if nil != view && 0 < len(view.Table.Filters) && !ignoreFillFilter {
|
||||
viewable := sql.RenderAttributeViewTable(attrView, view, "")
|
||||
var filters []*av.ViewFilter
|
||||
if nil != view {
|
||||
filters = view.GetFilters()
|
||||
}
|
||||
|
||||
if nil != view && 0 < len(filters) && !ignoreFillFilter {
|
||||
var viewable av.Viewable
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
viewable = sql.RenderAttributeViewTable(attrView, view, "")
|
||||
case av.LayoutTypeGallery:
|
||||
viewable = sql.RenderAttributeViewGallery(attrView, view, "")
|
||||
}
|
||||
viewable.Filter(attrView)
|
||||
viewable.Sort(attrView)
|
||||
|
||||
var nearRow *av.TableRow
|
||||
if 0 < len(viewable.Rows) {
|
||||
collection := viewable.(av.Collection)
|
||||
items := collection.GetItems()
|
||||
|
||||
var nearItem av.Item
|
||||
if 0 < len(items) {
|
||||
if "" != previousBlockID {
|
||||
for _, row := range viewable.Rows {
|
||||
if row.ID == previousBlockID {
|
||||
nearRow = row
|
||||
for _, row := range items {
|
||||
if row.GetID() == previousBlockID {
|
||||
nearItem = row
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if 0 < len(viewable.Rows) {
|
||||
nearRow = viewable.Rows[0]
|
||||
if 0 < len(items) {
|
||||
nearItem = items[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sameKeyFilterSort := false // 是否在同一个字段上同时存在过滤和排序
|
||||
if 0 < len(viewable.Sorts) {
|
||||
sorts := view.GetSorts()
|
||||
if 0 < len(sorts) {
|
||||
filterKeys, sortKeys := map[string]bool{}, map[string]bool{}
|
||||
for _, f := range view.Table.Filters {
|
||||
for _, f := range filters {
|
||||
filterKeys[f.Column] = true
|
||||
}
|
||||
for _, s := range view.Table.Sorts {
|
||||
for _, s := range sorts {
|
||||
sortKeys[s.Column] = true
|
||||
}
|
||||
|
||||
|
|
@ -2459,12 +2474,12 @@ func addAttributeViewBlock(now int64, avID, blockID, previousBlockID, addingBloc
|
|||
|
||||
if !sameKeyFilterSort {
|
||||
// 如果在同一个字段上仅存在过滤条件,则将过滤条件应用到新添加的块上
|
||||
for _, filter := range view.Table.Filters {
|
||||
for _, filter := range filters {
|
||||
for _, keyValues := range attrView.KeyValues {
|
||||
if keyValues.Key.ID == filter.Column {
|
||||
var defaultVal *av.Value
|
||||
if nil != nearRow {
|
||||
defaultVal = nearRow.GetValue(filter.Column)
|
||||
if nil != nearItem {
|
||||
defaultVal = nearItem.GetValue(filter.Column)
|
||||
}
|
||||
|
||||
newValue := filter.GetAffectValue(keyValues.Key, defaultVal)
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
}
|
||||
|
||||
name := util.FilterFileName(getAttrViewName(attrView))
|
||||
table := getAttrViewTable(attrView, view)
|
||||
table := getAttrViewTable(attrView, view, "")
|
||||
|
||||
// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
|
||||
table.Filter(attrView)
|
||||
|
|
@ -2492,7 +2492,7 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool,
|
|||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
table := getAttrViewTable(attrView, view)
|
||||
table := getAttrViewTable(attrView, view, "")
|
||||
|
||||
// 遵循视图过滤和排序规则 Use filtering and sorting of current view settings when exporting database blocks https://github.com/siyuan-note/siyuan/issues/10474
|
||||
table.Filter(attrView)
|
||||
|
|
@ -3394,7 +3394,7 @@ func loadTreeWithCache(id string, treeCache *map[string]*parse.Tree) (tree *pars
|
|||
return
|
||||
}
|
||||
|
||||
func getAttrViewTable(attrView *av.AttributeView, view *av.View) (ret *av.Table) {
|
||||
func getAttrViewTable(attrView *av.AttributeView, view *av.View, query string) (ret *av.Table) {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeGallery:
|
||||
view.Table = av.NewLayoutTable()
|
||||
|
|
@ -3405,6 +3405,6 @@ func getAttrViewTable(attrView *av.AttributeView, view *av.View) (ret *av.Table)
|
|||
view.Table.RowIDs = append(view.Table.RowIDs, cardID)
|
||||
}
|
||||
}
|
||||
ret = sql.RenderAttributeViewTable(attrView, view, "")
|
||||
ret = sql.RenderAttributeViewTable(attrView, view, query)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ func RenderTemplate(p, id string, preview bool) (tree *parse.Tree, dom string, e
|
|||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
table := sql.RenderAttributeViewTable(attrView, view, "")
|
||||
table := getAttrViewTable(attrView, view, "")
|
||||
|
||||
var aligns []int
|
||||
for range table.Columns {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue