Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Oct 13, 2023
2 parents ed31305 + 3de7781 commit 3b87a0d
Show file tree
Hide file tree
Showing 6 changed files with 465 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Properties": {
"id": "20221223221636-ms2b4w9",
"title": "Flashcards",
"updated": "20230820185231"
"updated": "20231013104018"
},
"Children": [
{
Expand Down Expand Up @@ -87,7 +87,7 @@
"ListData": {},
"Properties": {
"id": "20230219092249-yzjjb1o",
"updated": "20230219092854"
"updated": "20231013104018"
},
"Children": [
{
Expand Down Expand Up @@ -132,20 +132,20 @@
},
"Properties": {
"id": "20230219092249-xdxmusm",
"updated": "20230219092407"
"updated": "20231013103949"
},
"Children": [
{
"ID": "20230219092249-04pxvxk",
"Type": "NodeParagraph",
"Properties": {
"id": "20230219092249-04pxvxk",
"updated": "20230219092407"
"updated": "20231013103949"
},
"Children": [
{
"Type": "NodeText",
"Data": "If the super block is set as a flashcard, the first sub-block of the super block will be regarded as a question, and the rest of the sub-blocks will be regarded as an answer"
"Data": "If a super block is set as a flashcard, the first sub-block of the super block will be regarded as a question, and the rest of the sub-blocks will be regarded as an answer"
}
]
}
Expand Down Expand Up @@ -178,6 +178,34 @@
]
}
]
},
{
"ID": "20231013103926-u4hxd38",
"Type": "NodeListItem",
"ListData": {
"BulletChar": 42,
"Marker": "Kg=="
},
"Properties": {
"id": "20231013103926-u4hxd38",
"updated": "20231013104018"
},
"Children": [
{
"ID": "20231013103926-o3y1n5a",
"Type": "NodeParagraph",
"Properties": {
"id": "20231013103926-o3y1n5a",
"updated": "20231013104018"
},
"Children": [
{
"Type": "NodeText",
"Data": "If a heading block is set as an flashcard, the heading block will be treated as a question and the blocks below it will be treated answers"
}
]
}
]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Properties": {
"id": "20221223215557-o6gfsoy",
"title": "闪卡",
"updated": "20230820185147"
"updated": "20231013103850"
},
"Children": [
{
Expand Down Expand Up @@ -87,7 +87,7 @@
"ListData": {},
"Properties": {
"id": "20230219085658-xnrf7rf",
"updated": "20230219092140"
"updated": "20231013103850"
},
"Children": [
{
Expand All @@ -112,11 +112,7 @@
"Children": [
{
"Type": "NodeText",
"Data": "内容块"
},
{
"Type": "NodeText",
"Data": "中的 "
"Data": "内容块中的 "
},
{
"Type": "NodeTextMark",
Expand Down Expand Up @@ -186,6 +182,34 @@
]
}
]
},
{
"ID": "20231013103816-b0k440b",
"Type": "NodeListItem",
"ListData": {
"BulletChar": 42,
"Marker": "Kg=="
},
"Properties": {
"id": "20231013103816-b0k440b",
"updated": "20231013103850"
},
"Children": [
{
"ID": "20231013103816-sx34w1r",
"Type": "NodeParagraph",
"Properties": {
"id": "20231013103816-sx34w1r",
"updated": "20231013103850"
},
"Children": [
{
"Type": "NodeText",
"Data": "如果将标题块设置为上卡,则该标题块会被视作问题,其下方块会被视作答案"
}
]
}
]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Properties": {
"id": "20221223221501-mops33i",
"title": "閃卡",
"updated": "20230820185212"
"updated": "20231013104052"
},
"Children": [
{
Expand Down Expand Up @@ -87,7 +87,7 @@
"ListData": {},
"Properties": {
"id": "20230219092911-8074ovh",
"updated": "20230219092911"
"updated": "20231013104052"
},
"Children": [
{
Expand Down Expand Up @@ -182,6 +182,34 @@
]
}
]
},
{
"ID": "20231013104042-7impulf",
"Type": "NodeListItem",
"ListData": {
"BulletChar": 42,
"Marker": "Kg=="
},
"Properties": {
"id": "20231013104042-7impulf",
"updated": "20231013104052"
},
"Children": [
{
"ID": "20231013104042-wzwhxmr",
"Type": "NodeParagraph",
"Properties": {
"id": "20231013104042-wzwhxmr",
"updated": "20231013104052"
},
"Children": [
{
"Type": "NodeText",
"Data": "如果將標題塊設為上卡,則該標題塊會被視為問題,其下方塊會被視為答案"
}
]
}
]
}
]
},
Expand Down
16 changes: 8 additions & 8 deletions kernel/av/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ const (
CalcOperatorLatest CalcOperator = "Latest"
)

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

func (value *Value) Compare(other *Value) int {
if nil == value {
return -1
Expand Down Expand Up @@ -566,6 +558,14 @@ type TableColumn struct {
Template string `json:"template"` // 模板内容
}

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

type TableRow struct {
ID string `json:"id"`
Cells []*TableCell `json:"cells"`
Expand Down
118 changes: 59 additions & 59 deletions kernel/model/attribute_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,65 +39,6 @@ type BlockAttributeViewKeys struct {
KeyValues []*av.KeyValues `json:"keyValues"`
}

func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av.KeyValues) string {
if "" == ial["id"] {
block := getRowBlockValue(rowValues)
ial["id"] = block.Block.ID
}
if "" == ial["updated"] {
block := getRowBlockValue(rowValues)
ial["updated"] = time.UnixMilli(block.Block.Updated).Format("20060102150405")
}

funcMap := sprig.TxtFuncMap()
goTpl := template.New("").Delims(".action{", "}")
tpl, tplErr := goTpl.Funcs(funcMap).Parse(tplContent)
if nil != tplErr {
logging.LogWarnf("parse template [%s] failed: %s", tplContent, tplErr)
return ""
}

buf := &bytes.Buffer{}
dataModel := map[string]interface{}{} // 复制一份 IAL 以避免修改原始数据
for k, v := range ial {
dataModel[k] = v

// Database template column supports `created` and `updated` built-in variables https://github.com/siyuan-note/siyuan/issues/9364
createdStr := ial["id"]
if "" != createdStr {
createdStr = createdStr[:len("20060102150405")]
}
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
if nil == parseErr {
dataModel["created"] = created
} else {
logging.LogWarnf("parse created [%s] failed: %s", createdStr, parseErr)
dataModel["created"] = time.Now()
}
updatedStr := ial["updated"]
updated, parseErr := time.ParseInLocation("20060102150405", updatedStr, time.Local)
if nil == parseErr {
dataModel["updated"] = updated
} else {
dataModel["updated"] = time.Now()
}
}
for _, rowValue := range rowValues {
if 0 < len(rowValue.Values) {
v := rowValue.Values[0]
if av.KeyTypeNumber == v.Type {
dataModel[rowValue.Key.Name] = v.Number.Content
} else {
dataModel[rowValue.Key.Name] = v.String()
}
}
}
if err := tpl.Execute(buf, dataModel); nil != err {
logging.LogWarnf("execute template [%s] failed: %s", tplContent, err)
}
return buf.String()
}

func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
waitForSyncingStorages()

Expand Down Expand Up @@ -292,6 +233,65 @@ func RenderAttributeView(avID string) (viewable av.Viewable, attrView *av.Attrib
return
}

func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av.KeyValues) string {
if "" == ial["id"] {
block := getRowBlockValue(rowValues)
ial["id"] = block.Block.ID
}
if "" == ial["updated"] {
block := getRowBlockValue(rowValues)
ial["updated"] = time.UnixMilli(block.Block.Updated).Format("20060102150405")
}

funcMap := sprig.TxtFuncMap()
goTpl := template.New("").Delims(".action{", "}")
tpl, tplErr := goTpl.Funcs(funcMap).Parse(tplContent)
if nil != tplErr {
logging.LogWarnf("parse template [%s] failed: %s", tplContent, tplErr)
return ""
}

buf := &bytes.Buffer{}
dataModel := map[string]interface{}{} // 复制一份 IAL 以避免修改原始数据
for k, v := range ial {
dataModel[k] = v

// Database template column supports `created` and `updated` built-in variables https://github.com/siyuan-note/siyuan/issues/9364
createdStr := ial["id"]
if "" != createdStr {
createdStr = createdStr[:len("20060102150405")]
}
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
if nil == parseErr {
dataModel["created"] = created
} else {
logging.LogWarnf("parse created [%s] failed: %s", createdStr, parseErr)
dataModel["created"] = time.Now()
}
updatedStr := ial["updated"]
updated, parseErr := time.ParseInLocation("20060102150405", updatedStr, time.Local)
if nil == parseErr {
dataModel["updated"] = updated
} else {
dataModel["updated"] = time.Now()
}
}
for _, rowValue := range rowValues {
if 0 < len(rowValue.Values) {
v := rowValue.Values[0]
if av.KeyTypeNumber == v.Type {
dataModel[rowValue.Key.Name] = v.Number.Content
} else {
dataModel[rowValue.Key.Name] = v.String()
}
}
}
if err := tpl.Execute(buf, dataModel); nil != err {
logging.LogWarnf("execute template [%s] failed: %s", tplContent, err)
}
return buf.String()
}

func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *av.Table, err error) {
ret = &av.Table{
ID: view.ID,
Expand Down
Loading

0 comments on commit 3b87a0d

Please sign in to comment.