mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Improve database date fields to automatically fill in creation time https://github.com/siyuan-note/siyuan/issues/15828
🎨 Improve database date fields to automatically fill in creation time https://github.com/siyuan-note/siyuan/issues/15828
This commit is contained in:
parent
72c84f5f3d
commit
6cc6ef66f9
5 changed files with 38 additions and 11 deletions
|
@ -221,6 +221,10 @@ type View struct {
|
||||||
GroupSort int `json:"groupSort"` // 分组排序值,用于手动排序
|
GroupSort int `json:"groupSort"` // 分组排序值,用于手动排序
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (view *View) IsGroupView() bool {
|
||||||
|
return nil != view.Group && "" != view.Group.Field
|
||||||
|
}
|
||||||
|
|
||||||
// GetGroupValue 获取分组视图的分组值。
|
// GetGroupValue 获取分组视图的分组值。
|
||||||
func (view *View) GetGroupValue() string {
|
func (view *View) GetGroupValue() string {
|
||||||
if nil == view.GroupVal {
|
if nil == view.GroupVal {
|
||||||
|
@ -270,7 +274,7 @@ func (view *View) RemoveGroupByID(groupID string) {
|
||||||
|
|
||||||
// GetGroupKey 获取分组视图的分组字段。
|
// GetGroupKey 获取分组视图的分组字段。
|
||||||
func (view *View) GetGroupKey(attrView *AttributeView) (ret *Key) {
|
func (view *View) GetGroupKey(attrView *AttributeView) (ret *Key) {
|
||||||
if nil == view.Group || "" == view.Group.Field {
|
if !view.IsGroupView() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,6 +299,7 @@ type LayoutType string
|
||||||
const (
|
const (
|
||||||
LayoutTypeTable LayoutType = "table" // 属性视图类型 - 表格
|
LayoutTypeTable LayoutType = "table" // 属性视图类型 - 表格
|
||||||
LayoutTypeGallery LayoutType = "gallery" // 属性视图类型 - 卡片
|
LayoutTypeGallery LayoutType = "gallery" // 属性视图类型 - 卡片
|
||||||
|
LayoutTypeKanban LayoutType = "kanban" // 属性视图类型 - 看板
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -530,6 +535,15 @@ func SaveAttributeView(av *AttributeView) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清理渲染回填值
|
||||||
|
for _, kv := range av.KeyValues {
|
||||||
|
for i := len(kv.Values) - 1; i >= 0; i-- {
|
||||||
|
if kv.Values[i].IsRenderAutoFill {
|
||||||
|
kv.Values = append(kv.Values[:i], kv.Values[i+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
if util.UseSingleLineSave {
|
if util.UseSingleLineSave {
|
||||||
data, err = gulu.JSON.MarshalJSON(av)
|
data, err = gulu.JSON.MarshalJSON(av)
|
||||||
|
|
|
@ -57,6 +57,8 @@ type Value struct {
|
||||||
Checkbox *ValueCheckbox `json:"checkbox,omitempty"`
|
Checkbox *ValueCheckbox `json:"checkbox,omitempty"`
|
||||||
Relation *ValueRelation `json:"relation,omitempty"`
|
Relation *ValueRelation `json:"relation,omitempty"`
|
||||||
Rollup *ValueRollup `json:"rollup,omitempty"`
|
Rollup *ValueRollup `json:"rollup,omitempty"`
|
||||||
|
|
||||||
|
IsRenderAutoFill bool `json:"-"` // 标识是否是渲染阶段自动填充的值,保存数据的时候要删掉
|
||||||
}
|
}
|
||||||
|
|
||||||
func (value *Value) SetUpdatedAt(mills int64) {
|
func (value *Value) SetUpdatedAt(mills int64) {
|
||||||
|
|
|
@ -101,7 +101,7 @@ func GetAttrViewAddingBlockDefaultValues(avID, viewID, groupID, previousBlockID,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if 1 > len(view.Filters) && nil == view.Group {
|
if 1 > len(view.Filters) && !view.IsGroupView() {
|
||||||
// 没有过滤条件也没有分组条件时忽略
|
// 没有过滤条件也没有分组条件时忽略
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func GetAttrViewAddingBlockDefaultValues(avID, viewID, groupID, previousBlockID,
|
||||||
func getAttrViewAddingBlockDefaultValues(attrView *av.AttributeView, view, groupView *av.View, previousItemID, addingItemID string) (ret map[string]*av.Value) {
|
func getAttrViewAddingBlockDefaultValues(attrView *av.AttributeView, view, groupView *av.View, previousItemID, addingItemID string) (ret map[string]*av.Value) {
|
||||||
ret = map[string]*av.Value{}
|
ret = map[string]*av.Value{}
|
||||||
|
|
||||||
if 1 > len(view.Filters) && nil == view.Group {
|
if 1 > len(view.Filters) && !view.IsGroupView() {
|
||||||
// 没有过滤条件也没有分组条件时忽略
|
// 没有过滤条件也没有分组条件时忽略
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -533,7 +533,7 @@ func foldAttrViewGroup(avID, blockID, groupID string, folded bool) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil == view.Group {
|
if !view.IsGroupView() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1032,7 +1032,7 @@ func AppendAttributeViewDetachedBlocksWithValues(avID string, blocksValues [][]*
|
||||||
v.IsDetached = true
|
v.IsDetached = true
|
||||||
v.CreatedAt = now
|
v.CreatedAt = now
|
||||||
v.UpdatedAt = now
|
v.UpdatedAt = now
|
||||||
|
v.IsRenderAutoFill = false
|
||||||
keyValues.Values = append(keyValues.Values, v)
|
keyValues.Values = append(keyValues.Values, v)
|
||||||
|
|
||||||
if av.KeyTypeSelect == v.Type || av.KeyTypeMSelect == v.Type {
|
if av.KeyTypeSelect == v.Type || av.KeyTypeMSelect == v.Type {
|
||||||
|
@ -1725,7 +1725,7 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func genAttrViewGroups(view *av.View, attrView *av.AttributeView) {
|
func genAttrViewGroups(view *av.View, attrView *av.AttributeView) {
|
||||||
if nil == view.Group {
|
if !view.IsGroupView() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1969,7 +1969,7 @@ type GroupState struct {
|
||||||
|
|
||||||
func getAttrViewGroupStates(view *av.View) (groupStates map[string]*GroupState) {
|
func getAttrViewGroupStates(view *av.View) (groupStates map[string]*GroupState) {
|
||||||
groupStates = map[string]*GroupState{}
|
groupStates = map[string]*GroupState{}
|
||||||
if nil == view.Group {
|
if !view.IsGroupView() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2329,6 +2329,7 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
|
||||||
destVal.Relation = &av.ValueRelation{}
|
destVal.Relation = &av.ValueRelation{}
|
||||||
}
|
}
|
||||||
destVal.UpdatedAt = now
|
destVal.UpdatedAt = now
|
||||||
|
destVal.IsRenderAutoFill = false
|
||||||
}
|
}
|
||||||
destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, srcVal.BlockID)
|
destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, srcVal.BlockID)
|
||||||
destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs)
|
destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs)
|
||||||
|
@ -3145,12 +3146,19 @@ func addAttributeViewBlock(now int64, avID, dbBlockID, viewID, groupID, previous
|
||||||
// The database date field supports filling the current time by default https://github.com/siyuan-note/siyuan/issues/10823
|
// The database date field supports filling the current time by default https://github.com/siyuan-note/siyuan/issues/10823
|
||||||
for _, keyValues := range attrView.KeyValues {
|
for _, keyValues := range attrView.KeyValues {
|
||||||
if av.KeyTypeDate == keyValues.Key.Type && nil != keyValues.Key.Date && keyValues.Key.Date.AutoFillNow {
|
if av.KeyTypeDate == keyValues.Key.Type && nil != keyValues.Key.Date && keyValues.Key.Date.AutoFillNow {
|
||||||
if nil == keyValues.GetValue(addingItemID) { // 避免覆盖已有值(可能前面已经通过过滤或者分组条件填充了值)
|
val := keyValues.GetValue(addingItemID)
|
||||||
|
if nil == val { // 避免覆盖已有值(可能前面已经通过过滤或者分组条件填充了值)
|
||||||
dateVal := &av.Value{
|
dateVal := &av.Value{
|
||||||
ID: ast.NewNodeID(), KeyID: keyValues.Key.ID, BlockID: addingItemID, Type: av.KeyTypeDate, IsDetached: isDetached, CreatedAt: now, UpdatedAt: now + 1000,
|
ID: ast.NewNodeID(), KeyID: keyValues.Key.ID, BlockID: addingItemID, Type: av.KeyTypeDate, IsDetached: isDetached, CreatedAt: now, UpdatedAt: now + 1000,
|
||||||
Date: &av.ValueDate{Content: now, IsNotEmpty: true},
|
Date: &av.ValueDate{Content: now, IsNotEmpty: true},
|
||||||
}
|
}
|
||||||
keyValues.Values = append(keyValues.Values, dateVal)
|
keyValues.Values = append(keyValues.Values, dateVal)
|
||||||
|
} else {
|
||||||
|
if val.IsRenderAutoFill {
|
||||||
|
val.CreatedAt, val.UpdatedAt = now, now+1000
|
||||||
|
val.Date.Content, val.Date.IsNotEmpty = now, true
|
||||||
|
val.IsRenderAutoFill = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3230,11 +3238,13 @@ func fillDefaultValue(attrView *av.AttributeView, view, groupView *av.View, prev
|
||||||
|
|
||||||
existingVal := keyValues.GetValue(addingItemID)
|
existingVal := keyValues.GetValue(addingItemID)
|
||||||
if nil == existingVal {
|
if nil == existingVal {
|
||||||
|
newValue.IsRenderAutoFill = false
|
||||||
keyValues.Values = append(keyValues.Values, newValue)
|
keyValues.Values = append(keyValues.Values, newValue)
|
||||||
} else {
|
} else {
|
||||||
newValueRaw := newValue.GetValByType(keyValues.Key.Type)
|
newValueRaw := newValue.GetValByType(keyValues.Key.Type)
|
||||||
if av.KeyTypeBlock != existingVal.Type || (av.KeyTypeBlock == existingVal.Type && existingVal.IsDetached) {
|
if av.KeyTypeBlock != existingVal.Type || (av.KeyTypeBlock == existingVal.Type && existingVal.IsDetached) {
|
||||||
// 非主键的值直接覆盖,主键的值只覆盖非绑定块
|
// 非主键的值直接覆盖,主键的值只覆盖非绑定块
|
||||||
|
existingVal.IsRenderAutoFill = false
|
||||||
existingVal.SetValByType(keyValues.Key.Type, newValueRaw)
|
existingVal.SetValByType(keyValues.Key.Type, newValueRaw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ func renderAttributeViewGroups(viewable av.Viewable, attrView *av.AttributeView,
|
||||||
}
|
}
|
||||||
|
|
||||||
func hideEmptyGroupViews(view *av.View, viewable av.Viewable) {
|
func hideEmptyGroupViews(view *av.View, viewable av.Viewable) {
|
||||||
if nil == view.Group {
|
if !view.IsGroupView() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,14 +343,14 @@ func sortGroupsBySelectOption(view *av.View, groupKey *av.Key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isGroupByDate(view *av.View) bool {
|
func isGroupByDate(view *av.View) bool {
|
||||||
if nil == view.Group {
|
if !view.IsGroupView() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return av.GroupMethodDateDay == view.Group.Method || av.GroupMethodDateWeek == view.Group.Method || av.GroupMethodDateMonth == view.Group.Method || av.GroupMethodDateYear == view.Group.Method || av.GroupMethodDateRelative == view.Group.Method
|
return av.GroupMethodDateDay == view.Group.Method || av.GroupMethodDateWeek == view.Group.Method || av.GroupMethodDateMonth == view.Group.Method || av.GroupMethodDateYear == view.Group.Method || av.GroupMethodDateRelative == view.Group.Method
|
||||||
}
|
}
|
||||||
|
|
||||||
func isGroupByTemplate(attrView *av.AttributeView, view *av.View) bool {
|
func isGroupByTemplate(attrView *av.AttributeView, view *av.View) bool {
|
||||||
if nil == view.Group {
|
if !view.IsGroupView() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -624,6 +624,7 @@ func fillAttributeViewKeyValues(attrView *av.AttributeView, collection av.Collec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !exist {
|
if !exist {
|
||||||
|
val.IsRenderAutoFill = true
|
||||||
keyValues.Values = append(keyValues.Values, val)
|
keyValues.Values = append(keyValues.Values, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue