🎨 Support modifying database column types Fix https://github.com/siyuan-note/siyuan/issues/9513

This commit is contained in:
Daniel 2023-10-27 22:28:56 +08:00
parent f273e0af19
commit a57c258fce
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 61 additions and 0 deletions

View file

@ -415,6 +415,8 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
tableCell.Value = &av.Value{ID: tableCell.ID, KeyID: col.ID, BlockID: rowID, Type: av.KeyTypeUpdated}
}
treenode.FillAttributeViewTableCellNilValue(tableCell, rowID, col.ID)
tableRow.Cells = append(tableRow.Cells, tableCell)
}
ret.Rows = append(ret.Rows, &tableRow)

View file

@ -663,6 +663,8 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
tableCell.Value = &av.Value{ID: tableCell.ID, KeyID: col.ID, BlockID: rowID, Type: av.KeyTypeUpdated}
}
FillAttributeViewTableCellNilValue(tableCell, rowID, col.ID)
tableRow.Cells = append(tableRow.Cells, tableCell)
}
ret.Rows = append(ret.Rows, &tableRow)
@ -722,6 +724,63 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
return
}
func FillAttributeViewTableCellNilValue(tableCell *av.TableCell, rowID, colID string) {
if nil == tableCell.Value {
tableCell.Value = &av.Value{ID: tableCell.ID, KeyID: colID, BlockID: rowID, Type: tableCell.ValueType}
}
tableCell.Value.Type = tableCell.ValueType
switch tableCell.ValueType {
case av.KeyTypeText:
if nil == tableCell.Value.Text {
tableCell.Value.Text = &av.ValueText{}
}
case av.KeyTypeNumber:
if nil == tableCell.Value.Number {
tableCell.Value.Number = &av.ValueNumber{}
}
case av.KeyTypeDate:
if nil == tableCell.Value.Date {
tableCell.Value.Date = &av.ValueDate{}
}
case av.KeyTypeSelect:
if 1 > len(tableCell.Value.MSelect) {
tableCell.Value.MSelect = []*av.ValueSelect{}
}
case av.KeyTypeMSelect:
if 1 > len(tableCell.Value.MSelect) {
tableCell.Value.MSelect = []*av.ValueSelect{}
}
case av.KeyTypeURL:
if nil == tableCell.Value.URL {
tableCell.Value.URL = &av.ValueURL{}
}
case av.KeyTypeEmail:
if nil == tableCell.Value.Email {
tableCell.Value.Email = &av.ValueEmail{}
}
case av.KeyTypePhone:
if nil == tableCell.Value.Phone {
tableCell.Value.Phone = &av.ValuePhone{}
}
case av.KeyTypeMAsset:
if 1 > len(tableCell.Value.MAsset) {
tableCell.Value.MAsset = []*av.ValueAsset{}
}
case av.KeyTypeTemplate:
if nil == tableCell.Value.Template {
tableCell.Value.Template = &av.ValueTemplate{}
}
case av.KeyTypeCreated:
if nil == tableCell.Value.Created {
tableCell.Value.Created = &av.ValueCreated{}
}
case av.KeyTypeUpdated:
if nil == tableCell.Value.Updated {
tableCell.Value.Updated = &av.ValueUpdated{}
}
}
}
func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av.KeyValues) string {
if "" == ial["id"] {
block := getRowBlockValue(rowValues)