Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-12-17 12:17:59 +08:00
commit 9d639e8ff0
6 changed files with 96 additions and 16 deletions

View file

@ -313,6 +313,17 @@ func (av *AttributeView) GetBlockKeyValues() (ret *KeyValues) {
return
}
func (av *AttributeView) GetKeyValues(keyID string) (ret *KeyValues, err error) {
for _, kv := range av.KeyValues {
if kv.Key.ID == keyID {
ret = kv
return
}
}
err = ErrKeyNotFound
return
}
func (av *AttributeView) GetBlockKey() (ret *Key) {
for _, kv := range av.KeyValues {
if KeyTypeBlock == kv.Key.Type {

View file

@ -160,6 +160,18 @@ func (value *Value) ToJSONString() string {
return string(data)
}
func (value *Value) Clone() (ret *Value) {
data, err := gulu.JSON.MarshalJSON(value)
if nil != err {
return
}
err = gulu.JSON.UnmarshalJSON(data, &ret)
if nil != err {
return
}
return
}
type ValueBlock struct {
ID string `json:"id"`
Content string `json:"content"`

View file

@ -372,7 +372,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID string, page, pageSi
}
view.Table.Sorts = tmpSorts
viewable, err = renderAttributeViewTable(attrView, view, page, pageSize)
viewable, err = renderAttributeViewTable(attrView, view)
}
viewable.FilterRows()
@ -463,7 +463,7 @@ func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av
return buf.String()
}
func renderAttributeViewTable(attrView *av.AttributeView, view *av.View, page, pageSize int) (ret *av.Table, err error) {
func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *av.Table, err error) {
ret = &av.Table{
ID: view.ID,
Icon: view.Icon,
@ -1104,8 +1104,38 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
content = getNodeRefText(node)
}
now := time.Now().UnixMilli()
value := &av.Value{ID: ast.NewNodeID(), KeyID: blockValues.Key.ID, BlockID: blockID, Type: av.KeyTypeBlock, IsDetached: operation.IsDetached, IsInitialized: false, Block: &av.ValueBlock{ID: blockID, Content: content, Created: now, Updated: now}}
blockValues.Values = append(blockValues.Values, value)
blockValue := &av.Value{ID: ast.NewNodeID(), KeyID: blockValues.Key.ID, BlockID: blockID, Type: av.KeyTypeBlock, IsDetached: operation.IsDetached, IsInitialized: false, Block: &av.ValueBlock{ID: blockID, Content: content, Created: now, Updated: now}}
blockValues.Values = append(blockValues.Values, blockValue)
// 如果存在过滤条件,则将过滤条件应用到新添加的块上
view, _ := attrView.GetCurrentView()
if nil != view && 0 < len(view.Table.Filters) {
viewable, _ := renderAttributeViewTable(attrView, view)
viewable.FilterRows()
viewable.SortRows()
if 0 < len(viewable.Rows) {
row := viewable.Rows[len(viewable.Rows)-1]
for _, filter := range view.Table.Filters {
for _, cell := range row.Cells {
if nil != cell.Value && cell.Value.KeyID == filter.Column {
if av.KeyTypeBlock == cell.ValueType {
blockValue.Block.Content = cell.Value.Block.Content
continue
}
newValue := cell.Value.Clone()
newValue.ID = ast.NewNodeID()
newValue.BlockID = blockID
newValue.IsDetached = operation.IsDetached
newValue.IsInitialized = false
values, _ := attrView.GetKeyValues(filter.Column)
values.Values = append(values.Values, newValue)
}
}
}
}
}
if !operation.IsDetached {
attrs := parse.IAL2Map(node.KramdownIAL)

View file

@ -1916,7 +1916,7 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
return ast.WalkContinue
}
table, err := renderAttributeViewTable(attrView, view, 1, -1)
table, err := renderAttributeViewTable(attrView, view)
if nil != err {
logging.LogErrorf("render attribute view [%s] table failed: %s", avID, err)
return ast.WalkContinue

View file

@ -160,16 +160,17 @@ func getRecentDocs() (ret []*RecentDoc, err error) {
}
type Criterion struct {
Name string `json:"name"`
Sort int `json:"sort"` // 0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时
Group int `json:"group"` // 0不分组1按文档分组
HasReplace bool `json:"hasReplace"` // 是否有替换
Method int `json:"method"` // 0文本1查询语法2SQL3正则表达式
HPath string `json:"hPath"`
IDPath []string `json:"idPath"`
K string `json:"k"` // 搜索关键字
R string `json:"r"` // 替换关键字
Types *CriterionTypes `json:"types"` // 类型过滤选项
Name string `json:"name"`
Sort int `json:"sort"` // 0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时
Group int `json:"group"` // 0不分组1按文档分组
HasReplace bool `json:"hasReplace"` // 是否有替换
Method int `json:"method"` // 0文本1查询语法2SQL3正则表达式
HPath string `json:"hPath"`
IDPath []string `json:"idPath"`
K string `json:"k"` // 搜索关键字
R string `json:"r"` // 替换关键字
Types *CriterionTypes `json:"types"` // 类型过滤选项
ReplaceTypes *CriterionReplaceTypes `json:"replaceTypes"` // 替换类型过滤选项
}
type CriterionTypes struct {
@ -187,6 +188,32 @@ type CriterionTypes struct {
EmbedBlock bool `json:"embedBlock"`
}
type CriterionReplaceTypes struct {
Text bool `json:"text"`
ImgText bool `json:"img-text"`
ImgTitle bool `json:"img-title"`
ImgSrc bool `json:"img-src"`
AText bool `json:"a-text"`
ATitle bool `json:"a-title"`
AHref bool `json:"a-href"`
Code bool `json:"code"`
Em bool `json:"em"`
Strong bool `json:"strong"`
InlineMath bool `json:"inline-math"`
InlineMemo bool `json:"inline-memo"`
Kbd bool `json:"kbd"`
Mark bool `json:"mark"`
S bool `json:"s"`
Sub bool `json:"sub"`
Sup bool `json:"sup"`
Tag bool `json:"tag"`
U bool `json:"u"`
DocTitle bool `json:"doc-title"`
CodeBlock bool `json:"code-block"`
MathBlock bool `json:"math-block"`
HtmlBlock bool `json:"html-block"`
}
var criteriaLock = sync.Mutex{}
func RemoveCriterion(name string) (err error) {

View file

@ -333,7 +333,7 @@ func renderTemplate(p, id string, preview bool) (string, error) {
return ast.WalkContinue
}
table, renderErr := renderAttributeViewTable(attrView, view, 1, -1)
table, renderErr := renderAttributeViewTable(attrView, view)
if nil != renderErr {
logging.LogErrorf("render attribute view [%s] table failed: %s", n.AttributeViewID, renderErr)
return ast.WalkContinue