mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
e6a88e2ad2
2 changed files with 83 additions and 19 deletions
|
@ -726,6 +726,20 @@ func (av *AttributeView) Clone() (ret *AttributeView) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (av *AttributeView) GetTemplateKeyRelevantKeys(templateKey *Key) (ret []*Key) {
|
||||||
|
ret = []*Key{}
|
||||||
|
if nil == templateKey || "" == templateKey.Template {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, kValues := range av.KeyValues {
|
||||||
|
if strings.Contains(templateKey.Template, "."+kValues.Key.Name) {
|
||||||
|
ret = append(ret, kValues.Key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func GetAttributeViewDataPath(avID string) (ret string) {
|
func GetAttributeViewDataPath(avID string) (ret string) {
|
||||||
av := filepath.Join(util.DataDir, "storage", "av")
|
av := filepath.Join(util.DataDir, "storage", "av")
|
||||||
ret = filepath.Join(av, avID+".json")
|
ret = filepath.Join(av, avID+".json")
|
||||||
|
|
|
@ -87,23 +87,26 @@ func getAttrViewAddingBlockDefaultValues(attrView *av.AttributeView, view, group
|
||||||
|
|
||||||
nearItem := getNearItem(attrView, view, groupView, previousItemID)
|
nearItem := getNearItem(attrView, view, groupView, previousItemID)
|
||||||
|
|
||||||
// 对库中存在模板字段和汇总字段的情况进行处理(尽量从临近项获取新值,获取不到的话直接返回)
|
// 使用模板或汇总进行过滤或分组时,需要解析涉及到的其他字段
|
||||||
existSpecialField := false
|
templateRelevantKeys, rollupRelevantKeys := map[string][]*av.Key{}, map[string]*av.Key{}
|
||||||
for _, keyValues := range attrView.KeyValues {
|
for _, keyValues := range attrView.KeyValues {
|
||||||
if av.KeyTypeTemplate == keyValues.Key.Type || av.KeyTypeRollup == keyValues.Key.Type {
|
if av.KeyTypeTemplate == keyValues.Key.Type {
|
||||||
existSpecialField = true
|
if tplRelevantKeys := attrView.GetTemplateKeyRelevantKeys(keyValues.Key); 0 < len(tplRelevantKeys) {
|
||||||
break
|
for _, k := range tplRelevantKeys {
|
||||||
}
|
templateRelevantKeys[keyValues.Key.ID] = append(templateRelevantKeys[keyValues.Key.ID], k)
|
||||||
}
|
}
|
||||||
if existSpecialField {
|
}
|
||||||
if nil != nearItem {
|
} else if av.KeyTypeRollup == keyValues.Key.Type {
|
||||||
// 存在临近项时从临近项获取新值
|
if nil != keyValues.Key.Rollup {
|
||||||
for _, keyValues := range attrView.KeyValues {
|
relKey, _ := attrView.GetKey(keyValues.Key.Rollup.RelationKeyID)
|
||||||
newValue := getNewValueByNearItem(nearItem, keyValues.Key, addingItemID)
|
if nil != relKey && nil != relKey.Relation {
|
||||||
ret[keyValues.Key.ID] = newValue
|
if attrView.ID == relKey.Relation.AvID {
|
||||||
|
if k, _ := attrView.GetKey(keyValues.Key.Rollup.KeyID); nil != k {
|
||||||
|
rollupRelevantKeys[k.ID] = k
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else { // 不存在临近项时不生成任何新值
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +118,26 @@ func getAttrViewAddingBlockDefaultValues(attrView *av.AttributeView, view, group
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if av.KeyTypeTemplate == keyValues.Key.Type && nil != nearItem {
|
||||||
|
if keys := templateRelevantKeys[keyValues.Key.ID]; 0 < len(keys) {
|
||||||
|
for _, k := range keys {
|
||||||
|
if nil == ret[k.ID] {
|
||||||
|
ret[k.ID] = getNewValueByNearItem(nearItem, k, addingItemID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if av.KeyTypeRollup == keyValues.Key.Type && nil != nearItem {
|
||||||
|
if relKey, ok := rollupRelevantKeys[keyValues.Key.ID]; ok {
|
||||||
|
if nil == ret[relKey.ID] {
|
||||||
|
ret[relKey.ID] = getNewValueByNearItem(nearItem, relKey, addingItemID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
newValue := filter.GetAffectValue(keyValues.Key, addingItemID)
|
newValue := filter.GetAffectValue(keyValues.Key, addingItemID)
|
||||||
if nil == newValue {
|
if nil == newValue {
|
||||||
newValue = getNewValueByNearItem(nearItem, keyValues.Key, addingItemID)
|
newValue = getNewValueByNearItem(nearItem, keyValues.Key, addingItemID)
|
||||||
|
@ -135,7 +158,7 @@ func getAttrViewAddingBlockDefaultValues(attrView *av.AttributeView, view, group
|
||||||
}
|
}
|
||||||
|
|
||||||
newValue := getNewValueByNearItem(nearItem, groupKey, addingItemID)
|
newValue := getNewValueByNearItem(nearItem, groupKey, addingItemID)
|
||||||
if av.KeyTypeSelect == groupKey.Type || av.KeyTypeMSelect == groupKey.Type { // 单独处理单选或多选
|
if av.KeyTypeSelect == groupKey.Type || av.KeyTypeMSelect == groupKey.Type {
|
||||||
// 因为单选或多选只能按选项分组,并且可能存在空白分组(找不到临近项),所以单选或多选类型的分组字段使用分组值内容对应的选项
|
// 因为单选或多选只能按选项分组,并且可能存在空白分组(找不到临近项),所以单选或多选类型的分组字段使用分组值内容对应的选项
|
||||||
if opt := groupKey.GetOption(groupView.GetGroupValue()); nil != opt && groupValueDefault != groupView.GetGroupValue() {
|
if opt := groupKey.GetOption(groupView.GetGroupValue()); nil != opt && groupValueDefault != groupView.GetGroupValue() {
|
||||||
if nil == newValue {
|
if nil == newValue {
|
||||||
|
@ -159,6 +182,26 @@ func getAttrViewAddingBlockDefaultValues(attrView *av.AttributeView, view, group
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if av.KeyTypeTemplate == keyValues.Key.Type && nil != nearItem {
|
||||||
|
if keys := templateRelevantKeys[keyValues.Key.ID]; 0 < len(keys) {
|
||||||
|
for _, k := range keys {
|
||||||
|
if nil == ret[k.ID] {
|
||||||
|
ret[k.ID] = getNewValueByNearItem(nearItem, k, addingItemID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if av.KeyTypeRollup == keyValues.Key.Type && nil != nearItem {
|
||||||
|
if relKey, ok := rollupRelevantKeys[keyValues.Key.ID]; ok {
|
||||||
|
if nil == ret[relKey.ID] {
|
||||||
|
ret[relKey.ID] = getNewValueByNearItem(nearItem, relKey, addingItemID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if nil != newValue && !filterKeyIDs[groupKey.ID] /* 命中了过滤条件的话就不重复处理了 */ {
|
if nil != newValue && !filterKeyIDs[groupKey.ID] /* 命中了过滤条件的话就不重复处理了 */ {
|
||||||
ret[groupKey.ID] = newValue
|
ret[groupKey.ID] = newValue
|
||||||
}
|
}
|
||||||
|
@ -3480,6 +3523,13 @@ func sortAttributeViewRow(operation *Operation) (err error) {
|
||||||
|
|
||||||
if nil != view.Group && "" != operation.GroupID {
|
if nil != view.Group && "" != operation.GroupID {
|
||||||
if groupView := view.GetGroupByID(operation.GroupID); nil != groupView {
|
if groupView := view.GetGroupByID(operation.GroupID); nil != groupView {
|
||||||
|
groupKey := view.GetGroupKey(attrView)
|
||||||
|
isAcrossGroup := operation.GroupID != operation.TargetGroupID
|
||||||
|
if isAcrossGroup && (av.KeyTypeTemplate == groupKey.Type || av.KeyTypeRollup == groupKey.Type || av.KeyTypeCreated == groupKey.Type || av.KeyTypeUpdated == groupKey.Type) {
|
||||||
|
// 这些字段类型不支持跨分组移动,因为它们的值是自动计算生成的
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for i, id := range groupView.GroupItemIDs {
|
for i, id := range groupView.GroupItemIDs {
|
||||||
if id == operation.ID {
|
if id == operation.ID {
|
||||||
itemID = id
|
itemID = id
|
||||||
|
@ -3494,7 +3544,7 @@ func sortAttributeViewRow(operation *Operation) (err error) {
|
||||||
}
|
}
|
||||||
groupView.GroupItemIDs = append(groupView.GroupItemIDs[:idx], groupView.GroupItemIDs[idx+1:]...)
|
groupView.GroupItemIDs = append(groupView.GroupItemIDs[:idx], groupView.GroupItemIDs[idx+1:]...)
|
||||||
|
|
||||||
if operation.GroupID != operation.TargetGroupID { // 跨分组排序
|
if isAcrossGroup {
|
||||||
if targetGroupView := view.GetGroupByID(operation.TargetGroupID); nil != targetGroupView && !gulu.Str.Contains(itemID, targetGroupView.GroupItemIDs) {
|
if targetGroupView := view.GetGroupByID(operation.TargetGroupID); nil != targetGroupView && !gulu.Str.Contains(itemID, targetGroupView.GroupItemIDs) {
|
||||||
fillDefaultValue(attrView, view, targetGroupView, operation.PreviousID, itemID)
|
fillDefaultValue(attrView, view, targetGroupView, operation.PreviousID, itemID)
|
||||||
|
|
||||||
|
@ -3506,7 +3556,7 @@ func sortAttributeViewRow(operation *Operation) (err error) {
|
||||||
}
|
}
|
||||||
targetGroupView.GroupItemIDs = util.InsertElem(targetGroupView.GroupItemIDs, previousIndex, itemID)
|
targetGroupView.GroupItemIDs = util.InsertElem(targetGroupView.GroupItemIDs, previousIndex, itemID)
|
||||||
|
|
||||||
if groupKey := view.GetGroupKey(attrView); av.KeyTypeMSelect == groupKey.Type {
|
if av.KeyTypeMSelect == groupKey.Type {
|
||||||
// 跨多选分组时一个项目可能会同时存在于多个分组中,需要重新生成分组
|
// 跨多选分组时一个项目可能会同时存在于多个分组中,需要重新生成分组
|
||||||
regenAttrViewGroups(attrView, "force")
|
regenAttrViewGroups(attrView, "force")
|
||||||
}
|
}
|
||||||
|
@ -4447,7 +4497,7 @@ func regenAttrViewGroups(attrView *av.AttributeView, keyID string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if "force" != keyID {
|
if "force" != keyID {
|
||||||
if av.KeyTypeTemplate != groupKey.Type && av.KeyTypeCreated != groupKey.Type && av.KeyTypeUpdated != groupKey.Type &&
|
if av.KeyTypeTemplate != groupKey.Type && av.KeyTypeRollup != groupKey.Type && av.KeyTypeCreated != groupKey.Type && av.KeyTypeUpdated != groupKey.Type &&
|
||||||
view.Group.Field != keyID {
|
view.Group.Field != keyID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue